Skip to content

Instantly share code, notes, and snippets.

@christianseel
Created October 5, 2014 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianseel/9ef49c1a2f225c337909 to your computer and use it in GitHub Desktop.
Save christianseel/9ef49c1a2f225c337909 to your computer and use it in GitHub Desktop.
Replace ContentBlocks values with new values
<?
$c = $modx->newQuery('modResource');
$resources = $modx->getCollection('modResource', $c);
foreach ($resources as $res) {
$properties = $res->getProperties('contentblocks');
if (empty($properties)) continue;
if (empty($properties['content'])) continue;
$content = $properties['content'];
$content = str_replace('"color":"blue"', '"color":"secondarytext"', $content);
$content = str_replace('"color":"red"', '"color":"primarytext"', $content);
$properties['content'] = $content;
$res->setProperties($properties, 'contentblocks', true);
$res->save();
echo $res->get('pagetitle')." REPLACED<br>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment