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

    I'm sure I found the fix for this somewhere on the forums a long time ago, but my google-foo is letting me down.

    Description of Problem:

    I've got a test/dev copy of a site at http://new.home which is on a local VM at home and I copied it to a public box at http://test.livedomain.com and I found that modx / TinymceWrapper is putting http://new.home/ in front of all of my image URLs.

    I'd either like a handy-dandy script to run over the DB to fix it after moving the site and editing the config, or to change the behaviour of modx / TinymceWrapper to just write the image urls as assets/img/blah.jpg instead of adding the full URL when they are written to the DB.

    Steps to Reproduce:

    Edit a resource (page) on http://new.home, insert an image, save the resource and the URL in the DB is absolute, including http://new.home.

    Expected Outcome:

    Remove the http://new.home so moving the site to another URL will 'just work' once the config.inc.php is edited and cache flushed etc.

    (Alternately a script / tool to fix the URLs after the move is fine as well.)


    • MODX Version: 2.7.0-pl
    • PHP Version: 7.2
    • Database (MySQL, SQL Server, etc) Version: Mysql 5.7
    • Additional Server Info: Ubuntu 18.04
    • Installed MODX Add-ons: TinymceWrapper

    To be fair I've come back to modx after not using it in a new project for a few years and I'm sure this was an easy to fix thing last time but I didn't take notes and I seem to suck a search today. smiley

    Thanks, Chris H.

    This question has been answered by donshakespeare. See the first response.

      • 54796
      • 5 Posts
      FYI..

      Just wrote a quick'n'dirty script to modify the modx_site_content table to fix this for the moment, although a I'm still looking for a fix in the CMS, I know it's there just escaping me (or I've gone mad, one of the two). smiley

      My script, just in case anyone else finds this via search:
      (Normal disclaimers apply, this was a quick-fix for me, it may kill your site, or cause issues with gravity).
      <?php
      // connect to DB.
      $db=new mysqli('localhost','dbuser','superpassword','databasename');
      
      // get the data
      $query = "select * from modx_site_content";
      $result = $db->query($query);
      
      echo $result->num_rows . " records to check\n";
      $count=0;
      
      // iterate through it, replace and smash back into DB.
      while ( $entry = $result->fetch_assoc())
      {
      	$content=str_replace('http://home_url.home/','https://public_url.com/',$entry['content']);
      	if($content != $entry['content']) 
      	{
      		$content=addslashes($content);
      		$query="update modx_site_content set content='{$content}' where id={$entry['id']}";
      		$db->query($query) or die("$query\nfailed\n");
      		$count++;
      	}
      }
      echo "$count updated\n";
      echo "Don't forget to clear the cache now\n";
      

      • discuss.answer
        • 42562
        • 1,145 Posts
        I know it's there just escaping me (or I've gone mad, one of the two).
        It's usually both, as the average MODX Dev's life will testify.


        Looking for this maybe?
        https://forums.modx.com/thread/101460/need-help-using-tinymce-in-a-staging-enviroment-multiple-domain

        Official TinyMCE doc
        https://www.tinymce.com/docs/configure/url-handling/


        tinymce.init({
          ...
          //find this bit of code in your TinymceWrapperCommonCode chunk (if using TinymceWrapper), or wherever your code is
          relative_urls: false,
          remove_script_host: false, // change to true
          document_base_url: MODx.config.site_url,
          ...
        });
          TinymceWrapper: Complete back/frontend content solution.
          Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
          5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • 54796
          • 5 Posts
          Quote from: donshakespeare at Dec 24, 2018, 08:46 PM
          I know it's there just escaping me (or I've gone mad, one of the two).
          It's usually both, as the average MODX Dev's life will testify.

          I think that goes for web devs in general now that I think of it. smiley

          Quote from: donshakespeare at Dec 24, 2018, 08:46 PM

          Looking for this maybe?
          https://forums.modx.com/thread/101460/need-help-using-tinymce-in-a-staging-enviroment-multiple-domain

          That's the one.. Thanks.

          I hope you have a good new years, and the fat guy in red was good to you. ;-)
            • 42562
            • 1,145 Posts
            Blessed Christmas! and cheers for the upcoming 365!
              TinymceWrapper: Complete back/frontend content solution.
              Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
              5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.