25 echo
'Comment the code that stops this script from working. Protection against accidental execution.';
30 $to_process = Array();
33 $search_for =
'NOTHING';
34 $replace_with =
'SOMETHING';
36 $attribute_name =
'html';
42 $search_for =
'/'.preg_quote($search_for,
'/').
'/';
43 $replace_with = $replace_with;
45 error_reporting(E_ALL);
46 if ((php_sapi_name() !=
'cli')) {
47 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
50 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
51 if (empty($SYSTEM_ROOT) || !is_dir($SYSTEM_ROOT)) {
52 echo
"You need to supply the path to the System Root as the first argument\n";
56 define(
'SQ_SYSTEM_ROOT', $SYSTEM_ROOT);
57 require_once SQ_SYSTEM_ROOT.
'/core/include/init.inc';
60 $root_user =& $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
63 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
64 echo
"Failed logging in as root user\n";
68 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
69 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
71 $db =& $GLOBALS[
'SQ_SYSTEM']->db;
72 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
74 $start = microtime(TRUE);
76 $total = count($to_process);
77 foreach ($to_process as $assetid) {
80 if ($done % 50 == 0) {
81 $elapsed = microtime(TRUE) - $start;
83 $frac = $done / $total;
84 $remain = $elapsed / $frac - $elapsed;
86 printf(
"%.2f%%: %d assets checked in %.2f seconds, %.2f remaining.\n", $pct, $done, $elapsed, $remain);
90 $asset =& $am->getAsset($assetid);
91 $attr_content = $asset->attr($attribute_name);
93 $result_content = preg_replace($search_for, $replace_with, $attr_content);
94 if ($result_content === $attr_content) {
96 echo
"No change: $assetid\n";
97 $am->forgetAsset($asset);
101 $lock_success = $am->acquireLock($assetid,
'attributes');
102 if (!$lock_success) {
103 echo
"\n".
'FAILED Processing asset: '.$assetid.
"\n";
105 $asset->setAttrValue($attribute_name, $result_content);
107 $asset->saveAttributes();
108 $am->releaseLock($assetid,
'attributes');
110 $am->forgetAsset($asset);
112 echo
"DONE: $assetid\n";
116 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
117 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();