We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26401
    • 247 Posts
    I was wondering if anyone has in idea how best to go about importing a bunch of entries from an xls file as resources.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Create a snippet (PHP has some pretty nice XML handling functions) to parse the file and insert the various fields into the proper fields in the database. You’ll need to become intimately familiar with the relevant database tables, at least the site_content table. You can even use PHP to typecast or convert the fields if the XML is using text and the site_content table is expecting something else (like a date where MODx expects a UNIX timestamp)
        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
        • 16278
        • 928 Posts
        OTOH, if it’s Excel rather than XML shocked you can use save your files in CSV format, import into your database as a custom table with PHPmyAdmin, and use ur001’s Docmanager class to create MODx documents. I’m in the process of transferring a database-driven site to MODx, and cobbled together a quick module to do this for news and events items, lifting some code from pkBlog. The module just reads:
        include_once $modx->config['base_path'] . '/assets/modules/docConvert/document.class.inc.php';
        include_once $modx->config['base_path'] . '/assets/modules/docConvert/docconvert.inc.php';
        

        and the PHP files are attached (too scrappy to put on immediate public show!). You may be able to adapt this to your needs.
        smiley KP
          • 26401
          • 247 Posts
          ha !!!
          I didn’t even think of doing this directly through phpAdmin.

          This will be for a product database, and though I haven’t decided whether to use the resources or a separate table, importing straight into the database makes the most sense.

          Thanks for sharing your code, I’ll give it a try