Skip to content

Commit

Permalink
update old placeholder images on upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: matdave <[email protected]>
  • Loading branch information
matdave committed Oct 23, 2024
1 parent e1213c0 commit fd8b8f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _build/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
"after": [
"resolve.synctables.php",
"resolve.defaulttheme.php",
"resolve.migration.php"
"resolve.migration.php",
"resolve.placehold.php"
]
}
}
Expand Down
30 changes: 30 additions & 0 deletions _build/resolvers/resolve.placehold.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

if ($object->xpdo) {
switch ($options[xPDOTransport::PACKAGE_ACTION]) {
case xPDOTransport::ACTION_UPGRADE:
/** @var modX $modx */
$modx =& $object->xpdo;
$c = $modx->newQuery('FredElement');
$c->where(['image:LIKE' => 'https://via.placeholder.com/%']);
$elements = $modx->getCollection('FredElement', $c);
foreach ($elements as $element) {
$image = $element->get('image');
$image = str_replace('https://via.placeholder.com/', 'https://placehold.co/', $image);
$element->set('image', $image);
$element->save();
}

$c = $modx->newQuery('FredBlueprint');
$c->where(['image:LIKE' => 'https://via.placeholder.com/%']);
$blueprints = $modx->getCollection('FredBlueprint', $c);
foreach ($blueprints as $blueprint) {
$image = $blueprint->get('image');
$image = str_replace('https://via.placeholder.com/', 'https://placehold.co/', $image);
$blueprint->set('image', $image);
$blueprint->save();
}
break;
}
}
return true;

0 comments on commit fd8b8f4

Please sign in to comment.