We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45613
    • 45 Posts
    Is there a way to export a set of resources or maybe a context, create a file that could be ftp'd to another server and the import this file and resources into an existing installation of MODX?

    I don't need the whole system, just 15-20 pages. It would save a bunch of time, if I did not have to recreate it.

    Depending on how it was exported, and how much is exported, there may be some things that would have to be fixed, but I could possibly use batcher to fix templates and some other things.

    Any suggestions?
      • 10484
      • 32 Posts
      It would probably be easier to export the database and import it to the new install... though you could also use Provisioner to import directly from one install to another. (It can also be used to import from Evo to Revo.) Just a note about it, it will overwrite things, so make sure you do it on a clean installation.

      As always, backup everything before tinkering.
        Garret Overstreet
        Business and Marketing Consultant
        • 3749
        • 24,544 Posts
        PackMan would be the perfect tool for this if it could package Resources, sadly, it won't.

        I would use MyComponent for that. It would create a transport package with the resources that you could install in Package Manager. It might not be worth getting up to speed with MyComponent just to do 15-20 pages.

        These would be the steps (more or less):


        • Install MyComponent
        • View the MyComponent resource
        • Enter a name for the project ("MoveResources") next to the "New Project" button and click on the button
        • Edit the project config file in the core/components/mycomponent/_build/config/ directory
        • Delete or disable all the stuff you don't need and add the resources to the "Export Resources" list.
        • Run Bootstrap on the MyComponent form
        • Run ExportObject on the MyComponent form
        • Run Build on the MyComponent form

        At that point you should have a file called something like moveresources-1.0.0-beta1.transport.zip in the core/packages directory. Just copy that file to the core/packages directory on the target site, then go to Pacakge Manager, click on the down arrow next to "Download Packages" and select "Search Locally for Packages."

        The package will appear in the tree and you can install all the resources by clicking on the "Install" button.

        The advantage of this method is that you can then modify the resources at the original site, change the version number in the project config file, run ExportObjects and Build again, and have a new package you can install to update the resources at the target site.
          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
          • 45613
          • 45 Posts
          I am really going to have to learn MyComponent. I have been looking at this a little and right now because I am still so new to MODX the project config file is pretty complex. I don't know what I need or don't need. Once I have done a few projects I am sure this will become clearer, but for a newbie this is a little overwhelming.

          I don't see any option but to just jump right in, and start playing.

          Thanks again for the help!
            • 3749
            • 24,544 Posts
            I know the config file is scary at first, but you can't go too far wrong as long as it stays as valid PHP code. The only danger is that you'll have a few extra pieces that you don't need. The only things you really need to change at the top are your name and the package name.

            About 90% of it can be deleted and it will still work. Except for the name of the package, the author, and the paths (which you don't have to touch), pretty much everything else is optional.

            If you have no elements, for example, the whole elements section can be replaced with this:

            $elements = array(),


            (Actually, I think you can just delete it, but I'm not positive.)

            I've been meaning to add some config file templates for simpler packages but just haven't had the time. The current Example config contains an example of everything that you can possibly do so whatever you need will already be there.

            Someday, there will be a CMP Wizard to create the config file for you.

            Here's something to get you started:

            Create a new project called MoveResources.

            Paste the following code into core/components/mycomponent/_build/config/moveresources.config.php file (replacing everything that's there):

            <?php
            
            $packageNameLower = 'moveresources'; /* No spaces, no dashes */
            
            $components = array(
                /* These are used to define the package and set values for placeholders */
                'packageName' => 'MoveResources',  /* No spaces, no dashes */
                'packageNameLower' => $packageNameLower,
                'packageDescription' => 'Move Resources from one site to another',
                'version' => '1.0.0',
                'release' => 'beta1',
                'author' => 'Your Name',
                'email' => '<your@email>',
                'authorUrl' => 'your site',
                'authorSiteName' => "your sitename",
                'packageDocumentationUrl' => '',
                'copyright' => '2013',
            
                /* no need to edit this except to change format */
                'createdon' => strftime('%m-%d-%Y'),
            
                //'gitHubUsername' => 'BobRay',
                // 'gitHubRepository' => 'MoveResources',
            
                /* two-letter code of your primary language */
                'primaryLanguage' => 'en',
            
                /* Set directory and file permissions for project directories */
                'dirPermission' => 0755,  /* No quotes!! */
                'filePermission' => 0644, /* No quotes!! */
            
                /* Define source and target directories */
            
                /* path to MyComponent source files */
                'mycomponentRoot' => $this->modx->getOption('mc.root', null,
                    MODX_CORE_PATH . 'components/mycomponent/'),
            
                /* path to new project root */
                'targetRoot' => MODX_ASSETS_PATH . 'mycomponents/' . $packageNameLower . '/',
            
            
            
                /* ************************* RESOURCES ****************************
                 Important: This list only affects Bootstrap. There is another
                 list of resources below that controls ExportObjects.
                 * ************************************************************** */
                /* Array of Resource pagetitles for your Extra; All other fields optional.
                   You can set any resource field here */
            
                /* If the resources already exist, you don't need this section */
                'resources' => array(
                    /*'Resource1' => array(
                        'pagetitle' => 'Resource1',
                        'alias' => 'resource1',
                        'context_key' => 'web',
                    ),
                    'Resource2' => array(
                        'pagetitle' => 'Resource2',
                        'alias' => 'resource2',
                        'context_key' => 'web',
                        'parent' => 'Resource1',
                        'template' => 'Template2',
                        'richtext' => false,
                        'published' => true,
                        'tvValues' => array(
                            'Tv1' => 'SomeValue',
                            'Tv2' => 'SomeOtherValue',
                        ),
                    ),*/
                ),
            
            
                'hasAssets' => false,
            
                'assetsDirs' => array(
            /*        'css' => true, */
                ),
            
                /* ********************************************* */
                /* Define basic directories and files to be created in project*/
            
                'docs' => array(
                    'readme.txt',
                    'license.txt',
                    'changelog.txt',
                    'tutorial.html'
                ),
            
                /* (optional) Description file for GitHub project home page */
                'readme.md' => false,
                /* assume every package has a core directory */
                'hasCore' => false,
            
                'createCmpFiles' => false,
            
            
            
                /* *******************************************
                 * These settings control exportObjects.php  *
                 ******************************************* */
                /* ExportObjects will update existing files. If you set dryRun
                   to '1', ExportObjects will report what it would have done
                   without changing anything. Note: On some platforms,
                   dryRun is *very* slow  */
            
                'dryRun' => '0',
            
                /* Array of elements to export. All elements set below will be handled.
                 *
                 * To export resources, be sure to list pagetitles and/or IDs of parents
                 * of desired resources
                */
                'process' => array(
                    'resources',
                ),
                /*  Array  of resources to process. You can specify specific resources
                    or parent (container) resources, or both.
            
                    They can be specified by pagetitle or ID, but you must use the same method
                    for all settings and specify it here. Important: use IDs if you have
                    duplicate pagetitles */
                'getResourcesById' => false,
            
                'exportResources' => array(
                    'Resource1',
                    'Resource2',
                    /* Add more here */
                ),
                /* Array of resource parent IDs to get children of. */
                'parents' => array(),
                /* Also export the listed parent resources
                  (set to false to include just the children) */
                'includeParents' => false,
            
            );
            
            return $components;



            List your resources in the 'exportResources' array just above.

            Run Bootstrap
            Run ExportObject
            Run Build

            Your package will be in core/packages -- be sure the transfer the one that ends in transport.zip.

            One drawback: no TV values will be transferred. I don't think there's a way to do that at this point.
              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
              • 45613
              • 45 Posts
              Sweet. I will definitely have to play with this.

              Thanks for all the help!
              • Will this then actually overwrite any resources with the ids in the target website? I ask because I am looking for a way to export the resources including TV values from one version of a website to another version of the same website on a subdomain with a different database.

                I just want to clone all content and inject it into another version of the website - similar to the MODX cloud, but this project is not on the cloud.
                  Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
                • Another option for my needs would be to export the whole elements section of one website and inject it into the second.
                    Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
                  • I have a site however with around 2000 resources. When you write "List your resources in the 'exportResources' array just above." You mean you would have to manually write the pagetitles there? I guess I would have to write a php script that would create the array for me.
                      Benjamin Davis: American web designer living in Munich, Germany and a MODX Ambassador. I am also co-founder of SEDA.digital, a MODX Agency.
                      • 3749
                      • 24,544 Posts

                      Here you go: wink

                      $resourceArray = array();
                      $docs = $modx->getCollection('modResource');
                      foreach($docs as $doc) {
                         $resourceArray = $doc->get('pagetitle');
                      }
                      
                      return $docs = "'" . implode("," , $resourceArray) . "';";


                      In the config file:

                      paste the results above the exportResources array and change that array to this:

                      'exportResources' => explode(",", $docs),


                      No resources on the target site will be overwritten -- the transferred files will all get new IDs -- though there could be collisions if a transferred resources has the same pagetitle or alias as an existing one.

                      Link tags that use resource IDs or any other references to resources by ID will be off for the new resources. As I mentioned above, the TV values won't transfer. It's theoretically possible for MyComponent to transfer them, but you'd have to enter all the resources, the TVs, and the TV values in the 'resources' section above by hand.



                        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