We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Sorry I didn't see this thread earlier. I would think you'd want the list as a CSV file and just run a simple utility snippet to import the new values. I could give you an example if you'd care to post a sample showing the format of the data in the list.

      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
      • 18608
      • 112 Posts
      Thank you for your reply Bob! I solved it by importing directly through phpmyadmin, but it would be interesting to see your example if you don't mind?

      The data was formated in a csv like this: id;tv1;tv2;tv3
        Mathias Dannevang | Webdesigner at dannevang.org | Tweets @dannevang
        • 3749
        • 24,544 Posts
        It would look something like this (untested):

        <?php
        $fp = fopen('csvFile', 'r');
        
        $i = 0;
        $output = '';
        
        while (!feof($fp)) {
            $currentLine = fgets($fp);
            $values = explode(';', $currentLine);
        
            if (count($values) != 4) {
                $output .= '<br/>Badly formatted line: ' . implode(';', $values);
                /* don't use line */
                continue;
            }
            if (!empty($currentLine)) {
                $i++;
                $resourceId = (integer)$values[0];
                unset($values[0]);
                /* renumber array indexes */
                $values = array_values($values);
        
                /* get the resource */
                $resourceObj = $modx->getObject('modResource', $resourceId);
        
                /* set TV names */
                $tvs = array(
                    'tv1Name',
                    'tv2Name',
                    'tv3Name'
                );
        
                /* loop to set TV values */
                if ($resourceObj) {
                    for ($i = 0; $i < 2; $i++) {
                        $resourceObj->setTVValue($tvs[$i], trim($values[$i]));
                    }
                }
            }
        }
        fclose($fp);
        
        $output .= '<br/>Processed ' . $i . ' lines';
        
        return $output;


        [ed. note: BobRay last edited this post 12 years, 2 months ago.]
          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
          • 18608
          • 112 Posts
          Thank you for that, Bob! Will definitely try that one next time it needs updating.
            Mathias Dannevang | Webdesigner at dannevang.org | Tweets @dannevang
            • 3749
            • 24,544 Posts
            You'll have to correct the TV names in the code -- don't forget that they're case-sensitive (and the name of the file).

            I've added a small test for the parsed lines' integrity, empty lines, and a final report to the code above.


            [ed. note: BobRay last edited this post 13 years, 9 months ago.]
              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
              • 18608
              • 112 Posts
              Hi Bob,

              After a long time I went back to this one to try it out - I get the following errors in my log when I try to run the snippet:

              [23-Jul-2014 10:44:22 Europe/Copenhagen] PHP Fatal error:  Call to a member function setTVValue() on a non-object in /paas/c0058/www/core/cache/includes/elements/modsnippet/91.include.cache.php on line 41
              [23-Jul-2014 10:44:22 Europe/Copenhagen] PHP Fatal error:  Undefined class constant 'LOG_LEVEL_ERROR' in /paas/c0058/www/core/model/modx/error/moderrorhandler.class.php on line 111
              


              Do you have any idea on where I'm going wrong?
                Mathias Dannevang | Webdesigner at dannevang.org | Tweets @dannevang
                • 3749
                • 24,544 Posts
                It's a mistake in the code - I've corrected it above.

                $resource->setTVValue($tvs[$i], trim($values[$i]));


                should be:

                $resourceObj->setTVValue($tvs[$i], trim($values[$i]));


                IOW, $resource-> should be $resourceObj->
                  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
                  • 18608
                  • 112 Posts
                  Thank you Bob, that did the trick.

                  Now it's importing as it should - only thing i'm wondering is, that the last of the three tv's doesn't get imported. Only the first two? But I can work around that by changing the file...
                    Mathias Dannevang | Webdesigner at dannevang.org | Tweets @dannevang
                    • 3749
                    • 24,544 Posts
                    Change this:

                    for ($i = 0; $i < 2; $i++) {


                    to this:

                    for ($i = 0; $i <= 2; $i++) {


                    That will give you three.
                      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
                      • 37242 ☆ A M B ☆
                      • 339 Posts
                      By the way: importX does it all. I do all my data updates with it (map data with svg and additional data): http://breitband.nrw.de/informieren/breitbandatlas-nrw.html

                      I asked mark and importX does update TV values indeed.