Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save snakebird/6992643 to your computer and use it in GitHub Desktop.
Save snakebird/6992643 to your computer and use it in GitHub Desktop.
<?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