Last active
December 15, 2017 09:43
-
-
Save christianhanvey/5522932 to your computer and use it in GitHub Desktop.
MODX utility snippet: replace absolute formed links in site content eg www.xxx.com/99 -> [[~99]]
note: backing up modx_site_content table is a good idea before running this :)
(original author: BobRay)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$docs = $modx->getCollection('modDocument'); | |
$pattern = '/www.xxx.com/(\d+)/'; | |
$replacement = '[[~$1]]'; | |
$count = 0; | |
foreach ($docs as $doc) { | |
$content = $doc->getContent(); | |
$hash1 = sha1($content); | |
$content = preg_replace($pattern, $replacement, $content); | |
$hash2 = sha1($content); | |
if ($hash1 === $hash2) { /* no change */. | |
continue; | |
} | |
$doc->setContent($content); | |
$doc->save(); | |
$count++; | |
} | |
return 'Modified ' . $count . ' Resources' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment