24 if (ini_get(
'memory_limit') !=
'-1') ini_set(
'memory_limit',
'-1');
25 error_reporting(E_ALL);
26 if ((php_sapi_name() !=
'cli')) trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
28 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
29 if (empty($SYSTEM_ROOT)) {
30 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
34 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
35 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
39 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
41 $root_user = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
44 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
45 echo
"ERROR: Failed logging in as root user\n";
50 $DESIGNID = (isset($_SERVER[
'argv'][2])) ? $_SERVER[
'argv'][2] :
'';
51 if (empty($DESIGNID)) {
52 echo
"ERROR: You need to supply the assetid for the design to reparse as the second argument \n";
56 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
57 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
58 $design = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($DESIGNID);
59 if (is_null($design)) exit();
60 if (!($design instanceof
Design)) {
61 trigger_error(
'Asset #'.$design->id.
' is not a design', E_USER_ERROR);
64 printName(
'Acquiring Locks for design "'.$design->name.
'"');
67 $vars = Array(
'assetids' => Array($design->id),
'lock_type' =>
'all',
'forceably_acquire' =>
false);
68 $errors = $hh->freestyleHipo(
'hipo_job_acquire_locks', $vars);
69 if (!empty($errors)) {
70 printUpdateStatus(
'LOCK FAILED');
71 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($design);
75 printUpdateStatus(
'OK');
77 printName(
'Checking Parse files "'.$design->name.
'"');
79 $parse_file = $design->data_path.
'/parse.txt';
81 $file_status = $fv->upToDate($parse_file);
82 if (FUDGE_FV_MODIFIED & $file_status) {
83 if (!$fv->commit($parse_file,
'')) {
84 trigger_error(
'Failed committing file version', E_USER_ERROR);
85 printUpdateStatus(
'UNABLE TO COMMIT PARSE FILE');
86 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($design);
91 printUpdateStatus(
'OK');
93 printName(
'Reparse design "'.$design->name.
'"');
95 $edit_fns = $design->getEditFns();
96 if (!$edit_fns->parseAndProcessFile($design)) {
97 printUpdateStatus(
'FAILED');
100 $design->generateDesignFile(
false);
102 printUpdateStatus(
'OK');
105 $customisation_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($design->id, SQ_LINK_TYPE_2,
'design_customisation',
true,
'major',
'customisation');
106 foreach($customisation_links as $link) {
107 $customisation = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
108 if (is_null($customisation))
continue;
109 printName(
'Reparse design customisation "'.$customisation->name.
'"');
110 $vars = Array(
'assetids' => Array($customisation->id),
'lock_type' =>
'all',
'forceably_acquire' =>
false);
111 $errors = $hh->freestyleHipo(
'hipo_job_acquire_locks', $vars);
112 if (!empty($errors)) {
113 printUpdateStatus(
'LOCK FAILED');
114 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($design);
117 if ($acquired = $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($customisation->id,
'all')) {
118 if (!$customisation->updateFromParent($design)) {
119 printUpdateStatus(
'FAILED');
122 if ($acquired != 2) $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($customisation->id,
'all');
123 printUpdateStatus(
'OK');
125 printUpdateStatus(
'LOCK FAILED');
128 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($customisation);
134 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($design->id,
'all')) {
135 printUpdateStatus(
'RELEASE LOCK FAILED');
136 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($design);
138 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($design);
144 function printName($name)
146 printf (
'%s%'.(50 - strlen($name)).
's', $name,
'');
151 function printUpdateStatus($status)
153 echo
"[ $status ]\n";