We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43374
    • 39 Posts
    I have inserted a huge table into site_content via phpmyadmin to create over 1.000.000 resources. I managed it by splitting it in packages a 100.000 entries via "id BETWEEN 0 AND 100000" and so on.

    INSERT INTO  site_content (pagetitle, menutitle, description, introtext, content, longtitle ) SELECT value0, value1, value2, value3, value4, value5 FROM huge_table WHERE id BETWEEN 1 AND 100000
    


    The problem I have now is that neither 'alias' nor 'uri' are generated since it did not went through the modx API.

    I allready tried a few things but all failed due to the huge table size and the long script runtime:

    1. I place all recources as a child of one resource by setting the default value of 'parent' to the resource id before the sql INSERT INTO. Than I moved the parent in the modx manager to another position in the site tree but this way the API is not able to recalculate all resources and stop after a certain amount of changed URIs

    2.I executed a script i found in the forum from OPENGEEK in the root folder of my site
    <?php
    include 'config.core.php';
    include MODX_CORE_PATH . 'model/modx/modx.class.php';
    $modx = new modX();

    $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
    $modx->initialize('mgr');

    $modx->setLogLevel(modX::LOG_LEVEL_INFO);

    $modx->exec("UPDATE {$modx->getTableName('modResource')} SET uri = '' WHERE uri_override = 0");

    $modx->call('modResource', 'refreshURIs', array(&$modx));

    same problem here the table is just to big to run completly through within the given time set by my provider

    Has anyone an idea? Maybe a limitation in the php script so I can split it into smaler packages. I am unfortunately not that experienced with SQL or PHP to write it by myself.

    This question has been answered by multiple community members. See the first response.

    [ed. note: sh0ck23 last edited this post 10 years, 10 months ago.]
    • Do the created resources have something in their "uri" field at all? If not, comment out the $modx->exec() line and see if that helps.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 43374
        • 39 Posts
        Not sure what you mean whith "created resources".

        After I first import the data into site_content the URI has of course no entry or NULL since i didnt import anything via phpmyadmin

        When I run the script it is able to create the URI for approx the first 1400 lines, after this I get a time out since the script runtime is limited to something about 90sec from my provider. I deleted the $modx->exec() check testwise anyway but makes no diference.
        • I meant the imported data into site_content with "created resources".

          Maybe adding the below to the top of the script helps to increase the limit, but that's very dependant on your host and I have no idea how long it should take with a million resources:

          set_time_limit(3600); // 1hr
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 43374
            • 39 Posts
            jsut tried it but doesnt work either. Longer script runtime is prohibited by the provider in general. Also tried something similar before with
            ini_set('max_execution_time', 1000000000); 


            how would the correct syntax be if I would tell this script...
            <?php
            include 'config.core.php';
            include MODX_CORE_PATH . 'model/modx/modx.class.php';
            $modx = new modX();

            $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
            $modx->initialize('mgr');

            $modx->setLogLevel(modX::LOG_LEVEL_INFO);

            $modx->call('modResource', 'refreshURIs', array(&$modx));
            ... to execute the script only for the IDs between 1000 and 2000 so something like ( WHERE id BETWEEN 1000 AND 2000 )?
              • 43374
              • 39 Posts
              I think i found a dirty but at least a solution that might work but I can not figure out the correct SQL syntax to update it via phpmyadmin

              In this SQL the id is not added:
              UPDATE `site_content` SET `uri` = '/test-parent/' id '.html' WHERE id BETWEEN 1000 AND 100000




              I can only do:
              UPDATE `site_content` SET `uri` = '/test-parent/' '.html' WHERE id BETWEEN 1000 AND 100000


              or:
              UPDATE `site_content` SET `uri` = id WHERE id BETWEEN 1000 AND 100000


              but combining words and the id from the row doesn't work

              can anyone tell me the correct syntax? [ed. note: sh0ck23 last edited this post 10 years, 10 months ago.]
              • You really need to run this from PHP CLI (which does not have execution time restrictions) with that large of a site. Or you could try and find a way to break the original script up into small pieces, perhaps starting with each top-level parent.
                • discuss.answer
                  • 43374
                  • 39 Posts
                  thanks all

                  how i finally solved it was to hardcode URI based on the document id via phpmyadmin
                  first remove the NULL from URI
                  UPDATE `site_content` SET `uri` = '.html' WHERE parent = 1001
                  

                  than update with variables:
                  UPDATE `site_content` SET `uri` = CONCAT('test-parent/',id, uri) WHERE parent = 1001
                  [ed. note: sh0ck23 last edited this post 10 years, 10 months ago.]
                    • 42191
                    • 6 Posts
                    Hello.

                    I've just got similar issue: if you have more than 10000 resources and trying to call 'refreshURIs' the script will reach the max_execution_time limit (120 seconds on my server). Is there any way to speed up this operation? Have somebody found out any workaruond?
                      • 3749
                      • 24,544 Posts
                      There are several suggestions in the posts above. OpenGeek's method would be the most reliable.

                        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