We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24168
    • 45 Posts
    Hi all,

    I am trying to move content from an old CMS based in MSSQL to MODX. I have created a snippet that logs into the MSSQL DB and uses the data to create new objects in MODx. A sample of my code is below:

    $object = $modx->newObject('modDocument');
    $object->set('name', 'MyDocument');
    $object->set('pagetitle', tidy($row['headline']));
    $object->set('longtitle', tidy($row['headline']));
    $object->set('description', tidy($row['summary']));
    $object->set('introtext', tidy($row['summary']));
    $object->set('parent', $containerID);
    $object->set('alias', URLFriendlyFilename(tidy($row['headline'])));
    $object->set('published', '1');
    $object->set('publishedon', date('U', $row['posted']));
    $object->set('richtext', '1');
    $object->set('template', $templateID);
    $object->set('menuindex', '0');
    $object->set('searchable', '1');
    $object->set('cacheable', '1');
    $object->set('createdby', '1');
    $object->set('createdon', date('U', $row['posted']));
    $object->set('editedby', '1');
    $object->set('editedon', date('U', $row['lastupdate']));
    $object->set('uri', '');
    $object->set('menuindex', $menuindex);
    $object->setContent(tidy($row['article']));
    // Save article
    $object->save();


    This SEEMS to work OK but I am finding that there are some problems. When I try and edit the pages in MODX the content (TinyMCE) areas are almost always blank. When I view the page (front-end) the content displays with some character encoding problems.

    I'm not sure if this is related to character encoding?
    Some of the old articles are plain text or very OLD HTML (<font> tags etc)

    Do you have any thoughts on this?

    Thanks,
      Stewart
      Freelance Web Designer & Developer:
      http://www.qodo.co.uk

      My extras:
      TwitterX http://modx.com/extras/package/twitterx
      TableOfContentsX http://modx.com/extras/package/tableofcontentsx
      • 32316
      • 387 Posts
      Just one quick one - I would turn off tinyMCE before importing because tiny is very good at editing the content without asking. Turn it off and then see what is in the content section.

      Well a couple more thoughts - I wouldn't think old html would matter, though it would be nice to clean it up. Never tried it or had it happen to me but it would not surprise me if tinymce did something strange with old tags

      character encoding is whole other can of worms and I would think could easily be causing all your problems...

      but try turning off tinymce first, it is quick and easy to do and can't hurt! [ed. note: whistlemaker last edited this post 14 years, 10 months ago.]
        • 24168
        • 45 Posts
        I removed TinyMCE to see if that would help but STILL some content loads and others don't. They are stored in the database correctly and can view them using phpmyadmin but not via manager in MODX.

        I am going to try character conversion to see if I can fix it. Any other suggestions welcome!
          Stewart
          Freelance Web Designer & Developer:
          http://www.qodo.co.uk

          My extras:
          TwitterX http://modx.com/extras/package/twitterx
          TableOfContentsX http://modx.com/extras/package/tableofcontentsx
          • 22303 MODX Staff
          • 10,725 Posts
          I assume this is content in a Windows character set, so you will likely have to use a latin1 encoding/collation for your database and tables when you set it up. Converting all that content to UTF8 is another option, but can be much more difficult to achieve.
            • 3749
            • 24,544 Posts
              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
              • 24168
              • 45 Posts
              Fixed this by adding the following formatting: smiley

              // Convert characters
              $str = iconv("CP1252", "UTF-8", $str);
                Stewart
                Freelance Web Designer & Developer:
                http://www.qodo.co.uk

                My extras:
                TwitterX http://modx.com/extras/package/twitterx
                TableOfContentsX http://modx.com/extras/package/tableofcontentsx
                • 24168
                • 45 Posts
                My next job is to try import these into Articles so will report back! smiley
                  Stewart
                  Freelance Web Designer & Developer:
                  http://www.qodo.co.uk

                  My extras:
                  TwitterX http://modx.com/extras/package/twitterx
                  TableOfContentsX http://modx.com/extras/package/tableofcontentsx