28 error_reporting(E_ALL);
29 if ((php_sapi_name() !=
'cli')) {
30 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
33 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
34 if (empty($SYSTEM_ROOT)) {
35 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
39 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
40 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
44 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
45 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
48 $root_user = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
49 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
50 echo
"ERROR: Failed logging in as root user\n";
55 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
57 $am = $GLOBALS[
'SQ_SYSTEM']->am;
60 $bad_assetids = Array();
63 $sql =
"SELECT assetid from sq_ast where status = '64' and assetid IN (select majorid from sq_ast_lnk where value = 'thumbnail')";
66 echo
"Found ".count($results).
" assets that are in 'Safe Editing' status and has thumbnail applied.\n";
68 foreach ($results as $result) {
70 echo
"Updating $done_asset of ".count($results).
" Assets\r";
71 $assetid = $result[
'assetid'];
72 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
73 $notice_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($assetid, SQ_LINK_NOTICE,
'', TRUE,
'thumbnail');
76 if (file_exists($asset->data_path.
'/.sq_system/.sq_notice_links')) {
77 $content = unserialize(file_to_string($asset->data_path.
'/.sq_system/.sq_notice_links'));
79 $thumbnail_exists = FALSE;
80 foreach ($content as $link) {
81 if ($link[
'value'] ==
'thumbnail') {
82 $thumbnail_exists = TRUE;
87 $content[] = $notice_link;
88 if (!$thumbnail_exists && !string_to_file(serialize($content), $asset->data_path.
'/.sq_system/.sq_notice_links')) {
89 print_r(
'Still writing :(');
91 $bad_assetids[] = $assetid;
94 $content[] = $notice_link;
95 if (!string_to_file(serialize($content), $asset->data_path.
'/.sq_system/.sq_notice_links')) {
97 $bad_assetids[] = $assetid;
107 if (!empty($count)) {
108 echo
"There were $count errors in creating .sq_notice_links files.\nThese assets may need to be reviewed manually.\n";
109 echo
"Assetids that need to be looked into (These are in error.log too):\n";
110 print_r($bad_assetids);
113 log_dump(
"There were ".$count.
" errors in creating .sq_notice_links files.\nThese assets may need to be reviewed manually.");
114 log_dump(
"Assetids that need to be looked into :");
115 log_dump($bad_assetids);
117 echo
"Successfully upgraded ".count($results).
" assets.\n";
120 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();