Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
system_parse_designs.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 define('SQ_SYSTEM_ROOT', realpath($SYSTEM_ROOT));
40 require_once $SYSTEM_ROOT.'/core/include/init.inc';
41 
42 $root_user = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
43 
44 // log in as root
45 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
46  echo "ERROR: Failed logging in as root user\n";
47  exit();
48 }
49 
50 
51 $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
52 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_OPEN);
53 
54 $parse_asset_types = Array(
55  'design' => TRUE,
56  'design_css' => TRUE,
57  );
58 $designs = Array();
59 foreach ($parse_asset_types as $type_code => $strict) {
60  $designs = array_merge($designs, $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($type_code, $strict));
61 }
62 
63 foreach ($designs as $designid) {
64 
65  $design = $GLOBALS['SQ_SYSTEM']->am->getAsset($designid);
66  if (is_null($design)) exit();
67  if (!($design instanceof Design)) {
68  trigger_error('Asset #'.$design->id.' is not a design', E_USER_ERROR);
69  }
70 
71  printName('Checking Parse files "'.$design->name.'" (#'.$design->id.')');
72 
73  $parse_file = $design->data_path.'/parse.txt';
74  // add a new version to the repository
75  $file_status = $fv->upToDate($parse_file);
76  if (FUDGE_FV_MODIFIED & $file_status) {
77  if (!$fv->commit($parse_file, '', false)) {
78  trigger_error('Failed committing file version', E_USER_ERROR);
79  printUpdateStatus('UNABLE TO COMMIT PARSE FILE');
80  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($design);
81  exit();
82  }
83  }
84 
85  printUpdateStatus('OK');
86 
87  printName('Reparse '.$design->type().' "'.$design->name.'" (#'.$design->id.')');
88 
89  $edit_fns = $design->getEditFns();
90  if (!$edit_fns->parseAndProcessFile($design)) {
91  printUpdateStatus('FAILED');
92  exit();
93  }
94  $design->generateDesignFile(false);
95 
96  printUpdateStatus('OK');
97 
98 
99  $customisation_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($design->id, SQ_LINK_TYPE_2, 'design_customisation', true, 'major', 'customisation');
100  foreach($customisation_links as $link) {
101  $customisation = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], $link['minor_type_code']);
102  if (is_null($customisation)) continue;
103  printName('Reparse design customisation "'.$customisation->name.'"');
104 
105  if (!$customisation->updateFromParent($design)) {
106  printUpdateStatus('FAILED');
107  continue;
108  } else {
109  printUpdateStatus('OK');
110  }
111  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($customisation);
112 
113  }// end foreach
114 
115  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($design);
116 
117 }//end foreach
118 
119 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
120 
122  // HELPER FUNCTIONS //
124 function printName($name)
125 {
126  printf ('%s%'.(50 - strlen($name)).'s', $name, '');
127 
128 }//end printName()
129 
130 
131 function printUpdateStatus($status)
132 {
133  echo "[ $status ]\n";
134 
135 }//end printUpdateStatus()
136 
137 ?>