We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19036
    • 119 Posts
    Hello everybody !

    I spent time searching a similar topic on this forum, but without success...

    So has anybody an idea how to move documents (articles and news) automatically from the `A` folder to the `B`folder ?

    I would like to do it month by month - to show a result like this:

    <see picture>

    Is it something possible with the API ?

    Thanks for your help.

    Mehdi

      Scuse my english...I&#39;m swiss
      • 19036
      • 119 Posts
      Do you think ditto can work for it ?
        Scuse my english...I&#39;m swiss
        • 19036
        • 119 Posts
        Perhaps I wasn’t clear, sorry !

        But the problem is that I still have 400 news (so 400 documents in the same folder).

        We write many news per day so how could I automatically move by date my documents in a "monthly" folder ?

        Mehdi
          Scuse my english...I&#39;m swiss
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You could make a plugin using the "onDocFormSave" event to check the dates of the documents in the news folder, and move any that are from a different month into a folder with that month’s name. If the folder doesn’t exist, the plugin can create it.

          For example, you’re making a news document for May. You want all of April’s documents moved into a folder/document named May2008. The plugin would see documents with a create date of May 2008, so it would look for a folder/document named May2008. If it doesn’t find it it will create it. Then it uses the folder’s document ID (whether it found it or had to create it) and updates the records for all document with create dates in April whose parents are the active news folder, and changes their parents to the ID of the May2008 folder.

          If your monthly folders are children of the active news folder, you would need to have an extra filter in your query to only update documents that are not folders (to prevent the attempt to make the monthly folder its own parent).
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 19036
            • 119 Posts
            Hey thanks Sottwell,

            It’s pretty like Chinese for me to understand how to create a plugin with only "onDocFormSave" ?!

            But it already means that’s possible ! And that’s nice !

            I fund this: http://wiki.modxcms.com/index.php/API:Document_%28System_Event%29#OnDocFormSave (but I’m not sure to understand the usefulness)

            I fund docs how to create a snippet, but not for a plugin...

            Does it requires strong technical skills to create something like that ?

            Thanks,
            Mehdi



              Scuse my english...I&#39;m swiss
              • 3749
              • 24,544 Posts
              Quote from: mehdi at May 04, 2008, 10:52 AM

              Perhaps I wasn’t clear, sorry !

              But the problem is that I still have 400 news (so 400 documents in the same folder).

              We write many news per day so how could I automatically move by date my documents in a "monthly" folder ?

              Mehdi

              I’m still not absolutely sure what you want to do but here are some thoughts that might help.

              Could you create the container documents that hold each month’s stories ahead of time (1-08, 2-08 or jan08, feb08 etc) and just have the users create each news item in the appropriate folder? Each document would be a child document under its month. Ditto could still pull the most recent n news items out for display after searching all the folders and you could have a separate page with a menu that let users browse each month’s articles.

              A big advantage of this method is that if users create links to your articles, they would remain good. If you move articles (automatically or by hand), there will be links all over the web with dead links to your site unless you create a complicated "permalink" system.

              Bob
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 19036
                • 119 Posts
                I’m not using simple url, so I don’t know why I would have problems (with dead links) if I move documents ??
                Does it change something ?

                If it’s possible I really want to carry on with the idea of Sottwell...so if someone can help me:

                I’m looking for an example of code (a plugin) to automatically move my documents with "onDocFormSave" ? -move from a folder to an other

                Thanks in advance !

                Mehdi
                  Scuse my english...I&#39;m swiss
                  • 3749
                  • 24,544 Posts
                  Sorry, you’re right. As long as you don’t change the Document ID or title/alias you won’t have dead links. I was thinking of a case where I search a particular folder the old-fashioned way to display documents by month.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting