Created
November 12, 2021 00:36
-
-
Save nnhubbard/9aca47fc4346ed82a2685164592f7dfa to your computer and use it in GitHub Desktop.
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 | |
// Assets you want to modify are here | |
$to_process = Array(101000, 101019, 101053, 101055, 101057, 101264, 103257, 103260, 104472, 104477, 104480, 104554, 105726, 105882, 106166, 107639, 107702, 107877,); | |
// Supply Your Strings Here | |
$search_for = 'http://explore.puc.edu/applynow/inquiryform'; | |
$replace_with = '%globals_asset_attribute_link_url:196905%'; | |
$attribute_name = 'html'; | |
$dry_run = false; | |
// -- | |
// No configuration options below this comment | |
// -- | |
$search_for = '/'.preg_quote($search_for, '/').'/'; | |
$replace_with = $replace_with; | |
error_reporting(E_ALL); | |
if ((php_sapi_name() != 'cli')) { | |
trigger_error("You can only run this script from the command line\n", E_USER_ERROR); | |
} | |
$SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : ''; | |
if (empty($SYSTEM_ROOT) || !is_dir($SYSTEM_ROOT)) { | |
echo "You need to supply the path to the System Root as the first argument\n"; | |
exit(); | |
} | |
define('SQ_SYSTEM_ROOT', $SYSTEM_ROOT); | |
require_once SQ_SYSTEM_ROOT.'/core/include/init.inc'; | |
$root_user =& $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user'); | |
// log in as root | |
if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) { | |
echo "Failed logging in as root user\n"; | |
exit(); | |
} | |
$GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2'); | |
$GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN'); | |
$db =& $GLOBALS['SQ_SYSTEM']->db; | |
$am =& $GLOBALS['SQ_SYSTEM']->am; | |
$start = microtime(TRUE); | |
$done = 0; | |
$total = count($to_process); | |
foreach ($to_process as $assetid) { | |
// display progress | |
$done++; | |
if ($done % 50 == 0) { | |
$elapsed = microtime(TRUE) - $start; | |
if ($elapsed > 0) { | |
$frac = $done / $total; | |
$remain = $elapsed / $frac - $elapsed; | |
$pct = $frac * 100; | |
//printf("%.2f%%: %d assets checked in %.2f seconds, %.2f remaining.\n", $pct, $done, $elapsed, $remain); | |
} | |
} | |
$asset =& $am->getAsset($assetid); | |
$attr_content = $asset->attr($attribute_name); | |
$result_content = preg_replace($search_for, $replace_with, $attr_content); | |
if ($result_content === $attr_content) { | |
// No change - don't bother saving. | |
//echo "No change: $assetid\n"; | |
$am->forgetAsset($asset); | |
continue; | |
} | |
if (!$dry_run) { | |
$lock_success = $am->acquireLock($assetid, 'attributes'); | |
if (!$lock_success) { | |
echo "\n".'FAILED Processing asset: '.$assetid."\n"; | |
} | |
$asset->setAttrValue($attribute_name, $result_content); | |
$asset->saveAttributes(); | |
$am->releaseLock($assetid, 'attributes'); | |
} else { | |
echo "Needs change: $assetid\n"; | |
} | |
$am->forgetAsset($asset); | |
echo "DONE: $assetid\n"; | |
} | |
$GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT'); | |
$GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection(); | |
echo "\n"; | |
echo 'DONE'; | |
echo "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment