Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
system_parse_design.php
1 <?php
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);
27 
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";
31  exit();
32 }
33 
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";
36  exit();
37 }
38 
39 require_once $SYSTEM_ROOT.'/core/include/init.inc';
40 
41 $root_user = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
42 
43 // log in as root
44 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
45  echo "ERROR: Failed logging in as root user\n";
46  exit();
47 }
48 
49 
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";
53  exit();
54 }
55 
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);
62 }
63 
64 printName('Acquiring Locks for design "'.$design->name.'"');
65 
66 // try to lock the design
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);
72  exit();
73 }
74 
75 printUpdateStatus('OK');
76 
77 printName('Checking Parse files "'.$design->name.'"');
78 
79 $parse_file = $design->data_path.'/parse.txt';
80 // add a new version to the repository
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);
87  exit();
88  }
89 }
90 
91 printUpdateStatus('OK');
92 
93 printName('Reparse design "'.$design->name.'"');
94 
95 $edit_fns = $design->getEditFns();
96 if (!$edit_fns->parseAndProcessFile($design)) {
97  printUpdateStatus('FAILED');
98  exit();
99 }
100 $design->generateDesignFile(false);
101 
102 printUpdateStatus('OK');
103 
104 
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);
115  exit();
116  }
117  if ($acquired = $GLOBALS['SQ_SYSTEM']->am->acquireLock($customisation->id, 'all')) {
118  if (!$customisation->updateFromParent($design)) {
119  printUpdateStatus('FAILED');
120  continue;
121  }
122  if ($acquired != 2) $GLOBALS['SQ_SYSTEM']->am->releaseLock($customisation->id, 'all');
123  printUpdateStatus('OK');
124  } else {
125  printUpdateStatus('LOCK FAILED');
126  continue;
127  }
128  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($customisation);
129 
130 }// end foreach
131 
132 
133 // try to unlock the design
134 if (!$GLOBALS['SQ_SYSTEM']->am->releaseLock($design->id, 'all')) {
135  printUpdateStatus('RELEASE LOCK FAILED');
136  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($design);
137 }
138 $GLOBALS['SQ_SYSTEM']->am->forgetAsset($design);
139 
140 
142  // HELPER FUNCTIONS //
144 function printName($name)
145 {
146  printf ('%s%'.(50 - strlen($name)).'s', $name, '');
147 
148 }//end printName()
149 
150 
151 function printUpdateStatus($status)
152 {
153  echo "[ $status ]\n";
154 
155 }//end printUpdateStatus()
156 
157 ?>
158