17 require_once SQ_INCLUDE_PATH.
'/asset.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/interfaces/bridge/bridge.inc';
47 parent::__construct($assetid);
62 return $this->
attr(
'name');
77 SQ_LINK_NOTICE => Array(
104 public function getAsset($shadowid, $type_code=
'', $mute_errors=FALSE)
132 public function getLinks($assetid, $link_types, $type_code=
'', $strict_type_code=TRUE, $side_of_link=
'major', $sort_by=NULL)
152 public function getParents($assetid, $type_code=
'', $strict_type_code=TRUE)
185 public function getChildren($assetid, $type_code=
'', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL)
232 public function countLinks($assetid, $side_of_link=
'major', $link_types=0, $type_code=
'', $strict_type_code=TRUE, $ignore_linkid=0)
266 $links_query = $GLOBALS[
'SQ_SYSTEM']->am->generateGetLinksQuery($this->
id, SQ_LINK_NOTICE,
'asset', FALSE);
267 if (empty($links_query))
return Array();
273 foreach ($links_query[
'bind_vars'] as $bind_var => $bind_value) {
277 }
catch (Exception $e) {
278 throw new Exception(
'Unable to get links for asset: '.$assetid.
' due to database error: '.$e->getMessage());
282 $bundled_assets = Array();
284 foreach ($db_links as $db_link) {
285 $bundled_assets[] = $db_link[
'minorid'];
286 $linkids[$db_link[
'minorid']] = $db_link[
'linkid'];
289 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($bundled_assets);
293 foreach ($asset_info as $bundled_assetid => $info) {
295 'majorid' => $this->
id,
296 'minorid' => $bundled_assetid,
297 'assetid' => $bundled_assetid,
298 'type_code' => $info[
'type_code'],
299 'linkid' => $linkids[$bundled_assetid],
301 'name' => $info[
'name'],
302 'short_name' => $info[
'short_name'],
303 'status' => $info[
'status'],
304 'link_type' => SQ_LINK_TYPE_2,
305 'sort_order' => $sort_order,
345 if ((
string)$assetid === (
string)$this->
id) {
346 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE);
347 foreach ($links as $link) {
348 $linked_assetid = $links[
'minorid'];
349 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($linked_assetid);
351 'assetid' => $linked_assetid,
352 'name' => $asset_info[$linked_assetid][
'name'],
353 'short_name' => $asset_info[$linked_assetid][
'short_name'],
354 'version' => $asset_info[$linked_assetid][
'version'],
355 'status' => $asset_info[$linked_assetid][
'status'],
356 'type_code' => $asset_info[$linked_assetid][
'type_code'],
358 'accessible' => TRUE,
390 public function prepareLink(
Asset $asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
394 if ($side_of_link ===
'major') {
395 $link_type = SQ_LINK_NOTICE;
415 if (!isset($this->_tmp[
'status_object'])) {
417 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
418 $status_code = get_bit_names(
'SQ_STATUS_', $this->status);
419 $status_code =
'asset_status_bundle_'.strtolower($status_code);
420 require_once dirname(__FILE__).
'/asset_status/'.$status_code.
'.inc';
421 $this->_tmp[
'status_object'] =
new $status_code($this);
423 return $this->_tmp[
'status_object'];
446 $old_status = (int)$event_vars[
'old_status'];
447 $new_status = (int)$event_vars[
'new_status'];
449 if ((($old_status & SQ_SC_STATUS_PENDING) !== 0) && (($new_status & SQ_SC_STATUS_ALL_APPROVED) !== 0)) {
450 if ((
int)$this->status !== SQ_STATUS_PENDING_APPROVAL)
return;
452 $hipo_herder = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
454 if (array_key_exists(
'completing_workflow', $this->_tmp) === FALSE) {
455 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
457 $links_query = $GLOBALS[
'SQ_SYSTEM']->am->generateGetLinksQuery($this->
id, SQ_LINK_NOTICE,
'asset', FALSE);
458 if (empty($links_query))
return Array();
462 $links_query[
'sql_array'][
'where'] .=
' AND minorid IN (SELECT assetid FROM sq_ast WHERE '.db_extras_bitand(
MatrixDAL::getDbType(),
'status',
':all_status').
' > 0)';
463 $links_query[
'bind_vars'][
'all_status'] = SQ_SC_STATUS_PENDING;
467 foreach ($links_query[
'bind_vars'] as $bind_var => $bind_value) {
471 }
catch (Exception $e) {
472 throw new Exception(
'Unable to get links for asset: '.$assetid.
' due to database error: '.$e->getMessage());
477 if (count($db_links) === 0) {
478 $this->_tmp[
'completing_workflow'] = 1;
480 $run_level = $GLOBALS[
'SQ_SYSTEM']->getRunLevel();
481 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($run_level ^ SQ_SECURITY_STATUS_INTEGRITY);
483 'assetid' => $this->
id,
484 'new_status' => SQ_STATUS_APPROVED,
485 'dependants_only' => TRUE,
487 $errors = $hipo_herder->freestyleHipo(
'hipo_job_edit_status', $vars);
488 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
493 }
else if ((($old_status & (SQ_SC_STATUS_PENDING | SQ_SC_STATUS_ALL_APPROVED)) !== 0) && (($new_status & SQ_SC_STATUS_CAN_APPROVE) !== 0)) {
495 if ((($this->status & (SQ_STATUS_PENDING_APPROVAL | SQ_STATUS_APPROVED)) === 0)) {
499 $hipo_herder = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
501 $run_level = $GLOBALS[
'SQ_SYSTEM']->getRunLevel();
502 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($run_level ^ SQ_SECURITY_STATUS_INTEGRITY);
504 'bundle_assetid' => $this->
id,
505 'new_status' => SQ_STATUS_UNDER_CONSTRUCTION,
507 $hipo_herder->freestyleHipo(
'hipo_job_edit_bundled_assets_status', $vars);
508 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
510 }
else if (((
int)$new_status === SQ_STATUS_LIVE) && ((
int)$old_status !== SQ_STATUS_EDITING)) {
514 if ((
int)$this->status === SQ_STATUS_PENDING_APPROVAL)
return;
516 $hipo_herder = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
518 if (array_key_exists(
'completing_workflow', $this->_tmp) === FALSE) {
519 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
521 $links_query = $GLOBALS[
'SQ_SYSTEM']->am->generateGetLinksQuery($this->
id, SQ_LINK_NOTICE,
'asset', FALSE);
522 if (empty($links_query))
return Array();
526 $links_query[
'sql_array'][
'where'] .=
' AND minorid IN (SELECT assetid FROM sq_ast WHERE '.db_extras_bitand(
MatrixDAL::getDbType(),
'status',
':all_status').
' = 0)';
527 $links_query[
'bind_vars'][
'all_status'] = SQ_STATUS_LIVE;
531 foreach ($links_query[
'bind_vars'] as $bind_var => $bind_value) {
535 }
catch (Exception $e) {
536 throw new Exception(
'Unable to get links for asset: '.$assetid.
' due to database error: '.$e->getMessage());
540 if (count($db_links) === 0) {
541 $run_level = $GLOBALS[
'SQ_SYSTEM']->getRunLevel();
542 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($run_level ^ SQ_SECURITY_STATUS_INTEGRITY);
544 'assetid' => $this->
id,
545 'new_status' => SQ_STATUS_LIVE,
546 'dependants_only' => TRUE,
548 $hipo_herder->freestyleHipo(
'hipo_job_edit_status', $vars);
549 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
572 if (!$this->
id)
return TRUE;
573 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
582 if ($edit_fns->showIfCanApprove($this)) {
603 if (!$this->
id)
return translate(
'asset_not_created');
606 $minor_asset_id_parts = explode(
':', $minor->id);
607 if (isset($minor_asset_id_parts[1])) {
611 return parent::canCreateLink($minor, $link_type, $exclusive);
635 public function createLink(
Asset $minor, $link_type, $value=
'', $sort_order=NULL, $dependant=
'0', $exclusive=
'0', $moving=FALSE)
637 if (!$this->
id)
return 0;
640 $minor_asset_id_parts = explode(
':', $minor->id);
641 if (isset($minor_asset_id_parts[1])) {
645 return parent::createLink($minor, $link_type, $value, $sort_order, $dependant, $exclusive, $moving);
659 $bundled_asset_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE);
660 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
662 $all_schemas = Array();
663 foreach ($bundled_asset_links as $linkid => $bundled_asset_link) {
664 $bundled_assetid = $bundled_asset_link[
'minorid'];
665 $bundled_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bundled_assetid);
667 if ($bundled_asset->adminAccess() === TRUE) {
668 $all_schemas = array_merge($all_schemas, $wfm->getSchemas($bundled_assetid, TRUE));
670 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($bundled_asset);
671 unset($bundled_asset);
674 $all_schemas = array_unique($all_schemas);
675 $all_streams = Array();
677 foreach ($all_schemas as $schemaid) {
678 $all_streams += $wfm->getStreams($schemaid, TRUE);
694 $bundled_asset_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE);
695 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
698 foreach ($bundled_asset_links as $linkid => $bundled_asset_link) {
699 $bundled_assetid = $bundled_asset_link[
'minorid'];
700 $schemas = $wfm->getSchemas($bundled_assetid, TRUE);
701 foreach ($schemas as $schemaid) {
702 $all_streams = array_intersect($all_streams, $wfm->getBypassableStreams($bundled_assetid, $schemaid));
718 $bundled_asset_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE);
719 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
721 foreach ($bundled_asset_links as $linkid => $bundled_asset_link) {
722 $bundled_assetid = $bundled_asset_link[
'minorid'];
723 if ($wfm->testPublish($bundled_assetid, $GLOBALS[
'SQ_SYSTEM']->user->id,
'') === FALSE) {