Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
package_manager.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 require_once SQ_INCLUDE_PATH.'/asset_edit_interface.inc';
20 
33 {
34 
40  var $name = '';
41 
47  var $version = '';
48 
54  var $description = '';
55 
61  var $assets = Array();
62 
68  var $_base_path = '';
69 
75  var $_full_path = '';
76 
77 
82  function Package_Manager()
83  {
84  $this->MySource_Object();
85 
86  if (!isset($this->_full_path) || !is_dir($this->_full_path)) {
87  trigger_localised_error('SYS0238', E_USER_ERROR, get_class($this));
88  }
89 
90  // make sure that this package is in our system rootm, otherwise the base path won't work
91  if (substr($this->_full_path, 0, strlen(SQ_SYSTEM_ROOT)) != SQ_SYSTEM_ROOT) {
92  trigger_localised_error('SYS0239', E_USER_ERROR, get_class($this));
93  }
94 
95  // OK, if this is the "core" package then we just need to fiddle with the path
96  $this->_base_path = substr($this->_full_path, strlen(SQ_SYSTEM_ROOT) + 1);
97  $package_path = $this->_full_path.'/package.xml';
98 
99  if (file_exists($package_path)) {
100  try {
101  $info = new SimpleXMLElement($package_path, NULL, TRUE);
102  } catch (Exception $e) {
103  throw new Exception('Unable to parse package definition file "'.$package_path.'": '.$e->getMessage());
104  }
105 
106  if ($this->getPackageName() != $info->{'code_name'}) {
107  throw new Exception('Unable to parse package definition file "'.$package_path.'": package manager name "'.$this->getPackageName().'" does not match package name in definition file "'.$info->{'code_name'}.'"');
108  }
109  $this->name = (string)$info->name;
110  $this->version = (string)$info->version;
111  $this->description = (string)$info->description;
112 
113  $GLOBALS['SQ_SYSTEM']->lm->includePackageStrings($this->name);
114  $this->_loadPackageAssets();
115 
116  } else {
117  trigger_localised_error('SYS0199', E_USER_ERROR, $this->getPackageName());
118  }
119 
120  }//end constructor
121 
122 
128  function getPackageName()
129  {
130  return strtolower(substr(get_class($this), 16));
131 
132  }//end getPackageName()
133 
134 
147  function checkPackageDetails($update_assets=Array(), $deferred_assets=Array())
148  {
149  $am = $GLOBALS['SQ_SYSTEM']->am;
150 
151  for (reset($this->assets); null !== ($type_code = key($this->assets)); next($this->assets)) {
152  // Don't bother checking an asset that's not defined in the array.
153  if (!empty($update_assets) && !in_array($type_code, $update_assets)) {
154  continue;
155  }
156  if (!isset($install_reqs[$type_code])) {
157  $install_reqs[$type_code] = Array();
158  }
159 
160  // make sure all requirements are met
161  $file = SQ_SYSTEM_ROOT.'/'.$this->assets[$type_code]['dir'].'/asset.xml';
162  list($result, $req) = $this->checkRequirementsFromFile($file, $deferred_assets, true);
163 
164  if (!$result) {
165  // It failed the requirement, so we want to let the caller know what asset
166  // failed so that it can be revisited at a later date if needbe
167  if (!in_array($type_code, $deferred_assets)) {
168  pre_echo('Asset "'.$type_code.'" fails the "'.$req['type'].'" requirement for "'.$req['code'].' v'.$req['version'].'"'."\n".'As specified by '.$file.' and will be deferred');
169  $deferred_assets[] = $type_code;
170  }
171  continue;
172  }
173 
174  // OK, let's check that this asset is of an available type,
175  // or that the type is in this package that we are checking
176  $parent_type = $this->assets[$type_code]['parent_type'];
177  if ($parent_type != 'asset' && !$am->installed($parent_type) && !isset($this->assets[$parent_type])) {
178  // It failed the requirement, so we want to let the caller know what asset
179  // failed so that it can be revisited at a later date if needbe
180  if (!in_array($type_code, $deferred_assets)) {
181  pre_echo('Asset "'.$type_code.'" attempts to inherit from the unknown type "'.$parent_type.'"'."\n".'As specified by '.$file);
182  $deferred_assets[] = $type_code;
183  }
184  continue;
185  }
186  }//end for
187 
188  return count($deferred_assets) ? $deferred_assets : true;
189 
190  }//end checkPackageDetails()
191 
192 
203  function updatePackageDetails($update_assets=Array())
204  {
205  $em = $GLOBALS['SQ_SYSTEM']->getEventManager();
206 
207  // If there were some type codes that failed the requirements, save
208  // them in the deferred array so that they don't get installed later
209  // on in the process
210  $last_deferred = false;
211  $deferred = true;
212 
213  // We need to run this function over until no more deferred assets are
214  // detected - because of the order of checking the package details, we
215  // may not pick everything up first go
216  while ($last_deferred !== $deferred) {
217  $last_deferred = $deferred;
218  $deferred = $this->checkPackageDetails($update_assets, is_array($deferred) ? $deferred : Array());
219  if (is_bool($deferred) && !$deferred) {
220  return $deferred;
221  }
222  }
223 
224  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
225  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
226 
227  // Make sure deferred is an array.
228  $deferred = is_array($deferred) ? $deferred : Array();
229 
230  $install_order = $this->_getInstallOrder($update_assets, $deferred);
231  if (!empty($install_order)) {
232 
233  pre_echo('Installing '.get_class($this).':');
234 
235  $package_name = $this->getPackageName();
236 
237  $db = MatrixDAL::getDb();
238 
239  $sql = 'SELECT code_name FROM sq_pkg WHERE code_name = :code_name';
240  try {
241  $query = MatrixDAL::preparePdoQuery($sql);
242  MatrixDAL::bindValueToPdo($query, 'code_name', $package_name);
243  $exists = MatrixDAL::executePdoOne($query);
244  } catch (Exception $e) {
245  throw new Exception('Failed to get package information for package "'.$package_name.'" due to database error: '.$e->getMessage());
246  }
247 
248  try {
249  // DAL query
250  $bind_vars = Array(
251  'version' => $this->version,
252  'name' => $this->name,
253  'description' => $this->description,
254  'package_name' => $package_name,
255  );
256 
257  if (!$exists) {
258  $query_name = 'installPackage';
259  } else {
260  $query_name = 'updatePackage';
261  }
262  MatrixDAL::executeQuery('core', $query_name, $bind_vars);
263  } catch (Exception $e) {
264  // In case it needs to be localised, split the two messages
265  // instead of doing one with a ?: switch in the middle
266  if ($exists) {
267  throw new Exception('Failed to update package information for package "'.$package_name.'" due to database error: '.$e->getMessage());
268  } else {
269  throw new Exception('Failed to add package information for new package "'.$package_name.'" due to database error: '.$e->getMessage());
270  }
271  }
272 
273  for (reset($install_order); null !== ($k = key($install_order)); next($install_order)) {
274  $type_code = $install_order[$k];
275 
276  // Don't bother checking an asset that's not defined in the update_assets array.
277  if (!empty($update_assets) && !in_array($type_code, $update_assets)) {
278  continue;
279  }
280 
281  // If the asset was found in the list of failed dependencies,
282  // then don't try installing it just yet, but install
283  // all other types as they may be vital to the dependency
284  // resolution.
285  if (in_array($type_code, $deferred)) continue;
286 
287  echo "$k => $type_code \n";
288 
289  // now we simply call the management class for this object
290  $class = $type_code.'_management';
291  $file = SQ_SYSTEM_ROOT.'/'.$this->assets[$type_code]['dir'].'/'.$class.'.inc';
292  // include rather that require so that if it doesn't exist we can kill the transaction
293  require_once $file;
294  // make sure the class exists
295  if (!class_exists($class)) {
296  trigger_localised_error('SYS0083', E_USER_WARNING, $type_code, $file);
297  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
298  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
299  return false;
300  }
301 
302  // now just create an instance of it, and run update()
303  $management = new $class($this);
304  if (!$management->update()) {
305  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
306  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
307  return false;
308  }
309 
310  // generate the temporary list of event listeners
311  $events = $management->getEventList();
312  if (!is_array($events)) {
313  trigger_localised_error('SYS0142', E_USER_WARNING, $type_code, gettype($events));
314  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
315  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
316  return false;
317  }
318 
319  if (!empty($events)) {
320  // register the event to be installed later
321  $em->installStaticEvents($events, $type_code);
322  }
323 
324 
325  // fire assetInstall event to signal asset installation or update
326  // sends the type_code of the installed asset
327  $em->broadcastEvent($this, 'assetInstall', Array('type_code' => $type_code));
328 
329  }//end for
330 
331  // fire PackageInstall event to signal package installation or update
332  // sends a list of all the assets in the installed package
333  $em->broadcastEvent($this, 'packageInstall', $install_order);
334 
335  }//end if asset types to install
336 
337  // create the xml summarys of screens info for the asset map
338  if (!$this->_createAssetMapScreensXML($deferred)) {
339  trigger_localised_error('SYS0242', E_USER_WARNING);
340  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
341  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
342  return false;
343  }
344 
345  $this->_postInstall();
346 
347  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
348  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
349 
350  return count($deferred) ? $deferred : true;
351 
352  }//end updatePackageDetails()
353 
354 
361  function _loadPackageAssets()
362  {
363  $this->assets = Array();
364  $this->_recurseLoadPackageAssets($this->assets, $this->_full_path, $this->_base_path);
365 
366  // reload the asset types here :/
367  // otherwise any changes in asset locations will not be picked up by the asset manager
368  $GLOBALS['SQ_SYSTEM']->am->_loadAssetTypes();
369 
370  }//end _loadPackageAssets()
371 
372 
383  function _recurseLoadPackageAssets(Array &$assets, $full_path, $base_path)
384  {
385  $package = $this->getPackageName();
386  $d = new DirectoryIterator($full_path);
387  foreach ($d as $entry) {
388  $entry = (string)$entry;
389  if ($entry === '.' || $entry === '..') {
390  continue;
391  }
392 
393  if ($entry === 'asset.xml') {
394  // we have an asset process it
395  $mgt = new Asset_Management($this);
396  $info = $mgt->getAssetInfo($full_path.'/asset.xml');
397  if (empty($info)) continue;
398 
399  if ($package != $info['package']) {
400  trigger_localised_error('SYS0210', E_USER_ERROR, $full_path, $package, $info['package']);
401  }
402 
403  $info['dir'] = $base_path;
404 
405  // check the path of this type in db we may need to update it here incase it was moved
406  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
407  $db = MatrixDAL::getDb();
408  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
409 
410  $sql = 'SELECT dir FROM sq_ast_typ WHERE type_code = :type_code';
411 
412  try {
413  $query = MatrixDAL::preparePdoQuery($sql);
414  MatrixDAL::bindValueToPdo($query, 'type_code', $info['type_code']);
415  $result = MatrixDAL::executePdoOne($query);
416  } catch (DALException $e) {
417  throw new Exception ('Unable to get directory of type code '.$info['type_code'].' due to database error: '.$e->getMessage());
418  }
419 
420  if (!empty($result) && ($result != $info['dir'])) {
421  // update path
422  $sql = 'UPDATE
423  sq_ast_typ
424  SET
425  dir = :dir
426  WHERE
427  type_code = :type_code';
428 
429  try {
430  $query = MatrixDAL::preparePdoQuery($sql);
431  MatrixDAL::bindValueToPdo($query, 'dir', $info['dir']);
432  MatrixDAL::bindValueToPdo($query, 'type_code', $info['type_code']);
433  MatrixDAL::execPdoQuery($query);
434  } catch (DALException $e) {
435  throw new Exception ('Unable to update directory of type code '.$info['type_code'].' due to database error: '.$e->getMessage());
436  }
437  }
438 
439  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
440  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
441 
442  $assets[$info['type_code']] = $info;
443 
444  } else if (is_dir($full_path.'/'.$entry)) {
445  // if this is a directory, recursively search it
446  $this->_recurseLoadPackageAssets($assets, $full_path.'/'.$entry, $base_path.'/'.$entry);
447  }//end if
448  }//end foreach
449  $d = NULL;
450 
451  }//end _recurseLoadPackageAssets()
452 
453 
463  function _getInstallOrder($update_assets=Array(), $deferred=Array())
464  {
465  $asset_types = array_keys($this->assets);
466  $install_order = Array();
467 
468  while ($last_count = count($asset_types)) {
469 
470  for ($i = 0; $i < count($asset_types); $i++) {
471 
472  $type_code = $asset_types[$i];
473 
474  if (!empty($update_assets) && !in_array($type_code, $update_assets)) {
475  unset($asset_types[$i]);
476  $asset_types = array_values($asset_types);
477  $i--;
478  continue;
479  }
480 
481  if (in_array($type_code, $deferred)) {
482  unset($asset_types[$i]);
483  $asset_types = array_values($asset_types);
484  $i--;
485  continue;
486  }
487 
488  $parent = $this->assets[$type_code]['parent_type'];
489 
490  $remove = false;
491 
492  // if this type is inheritted from an existing type, then all OK
493  // but not if this type is in this package
494  if (($parent == 'asset' || $GLOBALS['SQ_SYSTEM']->am->installed($parent)) && !in_array($parent, $asset_types)) {
495  $install_order[] = $type_code;
496  $remove = true;
497 
498  // if this type is inheriting from a type that will be installed before it, then all OK
499  } else if (in_array($parent, $install_order)) {
500  $install_order[] = $type_code;
501  $remove = true;
502 
503 
504  // if this type is not inheriting from a type that is yet to be dealt with, then
505  // the type is in heriting from something that doesn't exist
506  } else if (!in_array($parent, $asset_types) && !in_array($parent, $deferred)) {
507  trigger_localised_error('SYS0080', E_USER_WARNING, $type_code, $parent);
508  $remove = true;
509  }
510  // else we do nothing with the asset_type
511 
512  if ($remove) {
513  unset($asset_types[$i]);
514  $asset_types = array_values($asset_types);
515  $i--;
516  }
517 
518  }//end for
519 
520  if ($last_count == count($asset_types)) {
521  trigger_localised_error('SYS0216', E_USER_WARNING, $this->getPackageName(), implode(', ', $asset_types));
522  return Array();
523  }
524 
525 
526  }//end while
527 
528  return $install_order;
529 
530  }//end _getInstallOrder()
531 
532 
541  function _createAssetMapScreensXML($deferred=Array())
542  {
543  $root = new SimpleXMLElement('<tmp />');
544  $str = '';
545 
546  for (reset($this->assets); null !== ($type_code = key($this->assets)); next($this->assets)) {
547  if (in_array($type_code, $deferred)) continue;
548 
549  $attrs = Array(
550  'type_code' => $type_code,
551  'name' => $this->assets[$type_code]['name'],
552  'version' => $this->assets[$type_code]['version'],
553  'instantiable' => $this->assets[$type_code]['instantiable'],
554  'allowed_access' => $this->assets[$type_code]['allowed_access'],
555  'parent_type' => $this->assets[$type_code]['parent_type'],
556  'flash_menu_path' => $this->assets[$type_code]['flash_menu_path'],
557  );
558 
559  $type_node = $root->addChild('type');
560  foreach ($attrs as $attr_name => $attr_value) {
561  if ($attr_value !== '') {
562  $type_node->addAttribute($attr_name, $attr_value);
563  }
564  }
565 
566  $GLOBALS['SQ_SYSTEM']->am->includeAsset($type_code);
567  $as = new $type_code();
568  $ef = $as->getEditFns();
569 
570  // Ensure that the Details screen is first
571  if (!empty($ef->static_screens['details'])) {
572  $screen_node = $type_node->addChild('screen', $ef->static_screens['details']['name']);
573  $screen_node->addAttribute('code_name', 'details');
574  }
575 
576  // Asset-specific custom inteface screens next
577  $ei = new Asset_Edit_Interface($type_code);
578  $screens = $ei->getScreens();
579  for (reset($screens); null !== ($code_name = key($screens)); next($screens)) {
580  if ($screens[$code_name]['invisible']) continue;
581  $screen_node = $type_node->addChild('screen', $screens[$code_name]['name']);
582  $screen_node->addAttribute('code_name', $code_name);
583  }
584 
585  // Static screens finally (other than Details -we already have that)
586  $GLOBALS['SQ_SYSTEM']->am->includeAsset($type_code);
587  $as = new $type_code();
588  $ef = $as->getEditFns();
589  for (reset($ef->static_screens); null !== ($code_name = key($ef->static_screens)); next($ef->static_screens)) {
590  if ($code_name == 'details') continue;
591  $screen_node = $type_node->addChild('screen', $ef->static_screens[$code_name]['name']);
592  $screen_node->addAttribute('code_name', $code_name);
593  }
594 
595  $str .= $type_node->asXml();
596 
597  }// end for
598 
599  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
600  return string_to_file($str, SQ_DATA_PATH.'/private/asset_map/'.$this->getPackageName().'.xml');
601 
602  }//end _createAssetMapScreensXML()
603 
604 
624  function checkRequirementsFromFile($file, $deferred_assets=Array(), $need_feedback=false)
625  {
626  $db = MatrixDAL::getDb();
627 
628  try {
629  $info = new SimpleXMLElement($file, NULL, TRUE);
630  } catch (Exception $e) {
631  throw new Exception('Could not parse asset definition file "'.$file.'": '.$e->getMessage());
632  }
633 
634  // if there are no requirements, return true
635  if (!isset($info->requirements->requirement)) {
636  return ($need_feedback) ? Array(true, null) : true;
637  }
638 
639  foreach ($info->requirements->requirement as $req) {
640  $required_type = (string)$req->attributes()->type;
641  $required_code = (string)$req->code;
642  $required_version = (string)$req->version;
643 
644  $ok = false;
645  switch ($required_type) {
646  case 'package':
647  $sql = 'SELECT version FROM sq_pkg WHERE code_name = :code_name';
648 
649  try {
650  $query = MatrixDAL::preparePdoQuery($sql);
651  MatrixDAL::bindValueToPdo($query, 'code_name', $required_code);
652  $installed_version = MatrixDAL::executePdoOne($query);
653  } catch (DALException $e) {
654  throw new Exception('Unable to get version of package "'.$required_code.'" due to database error: '.$e->getMessage());
655  }
656 
657  if ($installed_version) {
658  $ok = version_compare($installed_version, $required_version, '>=');
659  }
660  break;
661 
662  case 'system_asset':
663  case 'asset':
664  if (in_array($required_code, $deferred_assets)) {
665  // we have to defer an asset that depends on another deferred asset
666  $ok = false;
667  } else {
668  if ($GLOBALS['SQ_SYSTEM']->am->installed($required_code)) {
669  $ok = version_compare($GLOBALS['SQ_SYSTEM']->am->getTypeInfo($required_code, 'version'), $required_version, '>=');
670  }
671  // if the test failed, but this asset is in this package, check it's version from that
672  if (!$ok && isset($this->assets[$required_code])) {
673  $ok = version_compare($this->assets[$required_code]['version'], $required_version, '>=');
674  }
675  // If it's a system_asset check AND it has already passed the other checks,
676  // make sure the system_asset is actually available.
677  if ($required_type === 'system_asset' && $ok) {
678  $ok = $GLOBALS['SQ_SYSTEM']->am->isSystemAssetType($required_code);
679  }
680  }
681  break;
682 
683  case 'system':
684  switch ($required_code) {
685  case 'System' :
686  $ok = version_compare(SQ_SYSTEM_VERSION, $required_version, '>=');
687  break;
688  case 'PHP' :
689  $ok = version_compare(PHP_VERSION, $required_version, '>=');
690  break;
691  }
692  break;
693 
694  }//end switch
695 
696  // this requirement failed
697  if (!$ok) {
698 
699  if ($need_feedback) {
700  $ret_arr = Array(
701  'type' => $required_type,
702  'code' => $required_code,
703  'version' => $required_version,
704  );
705  return Array(false, $ret_arr);
706 
707  } else {
708  return false;
709 
710  }//end if
711 
712  }//end if
713 
714  }//end for
715 
716  // if we got this far everything is OK
717  return ($need_feedback) ? Array(true, null) : true;
718 
719  }//end checkRequirementsFromFile()
720 
721 
731  function getTypeAncestors($type_code)
732  {
733  if (!isset($this->assets[$type_code])) {
734  throw new Exception('Asset type "'.$type_code.'" does not exist in the "'.$this->getPackageName().'" package.');
735  trigger_localised_error('SYS0082', E_USER_ERROR, $type_code, $this->getPackageName());
736  return Array();
737  }
738 
739  $arr = Array();
740 
741  while (isset($this->assets[$type_code]) && $this->assets[$type_code]['parent_type'] != 'asset') {
742  $type_code = $this->assets[$type_code]['parent_type'];
743  $arr[] = $type_code;
744  }
745 
746  // if we are inheriting from something else then go find it from the installed list
747  if (!isset($this->assets[$type_code])) {
748  $new_arr = $GLOBALS['SQ_SYSTEM']->am->getTypeAncestors($type_code, TRUE, TRUE);
749  foreach ($new_arr as $type_code) {
750  $arr[] = $type_code;
751  }
752 
753  } else {
754  $arr[] = 'asset';
755 
756  }
757 
758  return $arr;
759 
760  }//end getTypeAncestors()
761 
762 
772  function getTypeInfo($type_code, $field='')
773  {
774  if (!isset($this->assets[$type_code])) {
775  throw new Exception('Asset type "'.$type_code.'" does not exist in the "'.$this->getPackageName().'" package.');
776  trigger_localised_error('SYS0082', E_USER_ERROR, $type_code, $this->getPackageName());
777  return ($field) ? null : Array();
778  }
779 
780  return ($field) ? $this->assets[$type_code][$field] : $this->assets[$type_code];
781 
782  }//end getTypeInfo()
783 
784 
791  function installUserPreferences(&$preferences)
792  {
793  foreach (array_keys($this->assets) as $type_code) {
794  $file = SQ_SYSTEM_ROOT.'/'.$this->assets[$type_code]['dir'].'/'.$type_code.'_prefs.inc';
795  if (!is_file($file)) continue;
796  require_once $file;
797  $class = $type_code.'_prefs';
798 
799  // make sure the class exists
800  if (class_exists($class)) {
801  $prefs = new $class();
802  if (!isset($preferences[$type_code])) {
803  $preferences[$type_code] = $prefs->pref_vars;
804  } else {
805  foreach ($preferences[$type_code] as $var => $data) {
806  if (!isset($prefs->pref_vars[$var])) {
807  unset($preferences[$type_code][$var]);
808  } else {
809  if ($preferences[$type_code][$var]['name'] != $prefs->pref_vars[$var]['name']) {
810  ($preferences[$type_code][$var]['name'] = $prefs->pref_vars[$var]['name']);
811  }
812  }
813  }
814  foreach ($prefs->pref_vars as $var => $data) {
815  if (!isset($preferences[$type_code][$var])) {
816  $preferences[$type_code][$var] = $data;
817  }
818  }
819  }
820  }
821  }//end foreach
822 
823  }//end installUserPreferences()
824 
825 
834  function getSystemAssetTypes()
835  {
836  return Array();
837 
838  }//end getSystemAssetTypes()
839 
840 
847  function installSystemAssets()
848  {
849  // check for any system assets that have not yet been installed and install them if required
850  $updated = false;
851  $assets_created = 0;
852 
853  foreach ($this->getSystemAssetTypes() as $type) {
854  if (!$GLOBALS['SQ_SYSTEM']->am->isSystemAssetType($type)) {
855  $function = 'create'.str_replace('_','',$type);
856  $new_system_asset = $this->$function();
857  if (!is_null($new_system_asset)) {
858  if ($new_system_asset->id) $updated = true;
859  $assets_created++;
860  } else {
861  // could not create the asset?!?
862  return -1;
863  }
864  }
865  }
866 
867  // regen the system assets file if needed
868  if ($updated) {
869  require_once SQ_INCLUDE_PATH.'/system_asset_config.inc';
870  $sys_asset_cfg = new System_Asset_Config();
871  $sys_asset_cfg->save(Array(), false);
872  }
873 
874  return $assets_created;
875 
876  }//end installSystemAssets()
877 
878 
885  function _postInstall()
886  {
887 
888  }//end _postInstall()
889 
890 
897  function _installDALQueries()
898  {
899  $name = $this->getPackageName();
900  if ($name == '__core__') $name = 'core';
901  $old_path = ini_get('include_path');
902  ini_set('include_path', SQ_LIB_PATH);
903  require_once SQ_LIB_PATH.'/MatrixDAL/MatrixDALBaker.inc';
904  $queries_found = MatrixDALBaker::addPackageQueries($name);
905  if ($queries_found) {
906  MatrixDALBaker::bakeQueriesFile($name.'_package');
907  }
908  ini_set('include_path', $old_path);
909 
910  }//end _installDALQueries()
911 
912 
913 }//end class
914 
915 ?>