53 public $short_name =
'';
65 public $languages =
'';
80 public $force_secure =
'0';
92 public $created_userid;
104 public $updated_userid;
116 public $published_userid;
122 public $status_changed;
128 public $status_changed_userid;
134 public $_is_cacheable = FALSE;
140 public $vars = Array();
146 public $_available_keywords = Array();
153 public $data_path_suffix =
'';
162 public $data_path =
'';
171 public $data_path_public =
'';
179 public $_ser_attrs = FALSE;
195 $this->
load($assetid);
230 trigger_localised_error(
'CORE0268', E_USER_WARNING, $this->
type());
234 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
235 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
238 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_DATA_VALIDATION)) {
246 assert_isset_array_index($link,
'asset',
'Cannot create asset without an asset to link to');
247 assert_isset_array_index($link,
'link_type',
'Cannot create asset without a link type');
248 assert_not_empty(($link[
'link_type'] & SQ_SC_LINK_SIGNIFICANT),
'Cannot create asset with an insignificant link type');
253 $trigger_level_changed = FALSE;
254 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_TRIGGERS)) {
255 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($GLOBALS[
'SQ_SYSTEM']->getRunLevel() - SQ_SECURITY_TRIGGERS);
256 $trigger_level_changed = TRUE;
259 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
263 $this->_tmp[
'__creating__'] = TRUE;
266 $name = ucwords(str_replace(
'_',
' ', $this->
type())).
' #'.$assetid;
268 $userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
269 $initial_version =
'0.0.1';
270 $initial_status = SQ_STATUS_UNDER_CONSTRUCTION;
271 if (array_get_index($link,
'is_dependant') && ($link[
'asset']->status != SQ_STATUS_UNDER_CONSTRUCTION)) {
272 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
273 if (0 == count($wfm->getSchemas($link[
'asset']->id, TRUE))) {
275 $initial_status = $link[
'asset']->status;
280 $now_iso = ts_iso8601($now);
282 'assetid' => $assetid,
283 'version' => $initial_version,
284 'type_code' => $this->
type(),
286 'short_name' => $name,
287 'status' => $initial_status,
288 'created' => $now_iso,
289 'created_userid' => $userid,
290 'updated' => $now_iso,
291 'updated_userid' => $userid,
293 'published_userid' => NULL,
294 'status_changed' => $now_iso,
295 'status_changed_userid' => $userid,
298 }
catch (Exception $e) {
299 throw new Exception(
'Unable to create new asset "'.$name.
'" (# "'.$assetid.
'") due to database error: '.$e->getMessage());
302 $this->
id = $assetid;
303 $this->version = $initial_version;
305 $this->short_name = $name;
306 $this->status = $initial_status;
307 $this->created = $now;
308 $this->created_userid = $userid;
309 $this->updated = $now;
310 $this->updated_userid = $userid;
311 $this->published = NULL;
312 $this->published_userid = NULL;
313 $this->status_changed = $now;
314 $this->status_changed_userid = $userid;
317 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
321 $GLOBALS[
'SQ_SYSTEM']->am->rememberAsset($this);
324 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_LOCKING)) {
325 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->id,
'permissions')) {
331 $message_body =
'New '.$this->type().
' "'.$this->name.
'" created';
333 'type_code' => $this->
type(),
334 'asset_name' => $this->name,
336 $message = $ms->newMessage(Array(),
'asset', $msg_reps);
337 $message->parameters[
'assetid'] = $this->id;
341 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($GLOBALS[
'SQ_SYSTEM']->getRunLevel() & SQ_RUN_LEVEL_FORCED);
343 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
351 if (!isset($link[
'value'])) $link[
'value'] =
'';
352 if (!isset($link[
'sort_order'])) {
353 $link[
'sort_order'] = -1;
355 if (!isset($link[
'is_dependant'])) {
356 $link[
'is_dependant'] = 0;
358 if (!isset($link[
'is_exclusive'])) {
359 $link[
'is_exclusive'] = 0;
361 if (!isset($link[
'is_locked'])) {
362 $link[
'is_locked'] = 0;
365 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_LOCKING)) {
367 $lock_result = $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($link[
'asset']->
id,
'links');
371 $parent_was_locked = ($lock_result == 2);
378 if ($link[
'is_dependant']) {
379 $lock = $GLOBALS[
'SQ_SYSTEM']->am->getLockInfo($link[
'asset']->
id,
'links');
380 $source_assetid = $lock[
'source_assetid'];
382 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->id,
'links', $source_assetid)) {
387 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_INTEGRITY)) {
390 $this->_tmp[__CLASS__.
'_in_create_cascading'] = TRUE;
391 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($GLOBALS[
'SQ_SYSTEM']->getRunLevel() & SQ_RUN_LEVEL_FORCED);
393 if (!$link[
'asset']->
cloneComponents($this, Array(
'permissions',
'metadata_schemas',
'workflow',
'content_tags',
'roles'))) {
394 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
398 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
399 unset($this->_tmp[__CLASS__.
'_in_create_cascading']);
403 $linkid = $link[
'asset']->createLink($this, $link[
'link_type'], $link[
'value'], $link[
'sort_order'], $link[
'is_dependant'], $link[
'is_exclusive'], FALSE, $link[
'is_locked']);
405 if (!$parent_was_locked) {
406 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($link[
'asset']->
id,
'links');
415 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_LOCKING)) {
417 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($this->id,
'permissions')) {
418 return $this->
_abortCreate($trigger_level_changed, $linkid);
423 $new_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid, $this->
id,
'minor');
426 if (!$parent_was_locked) {
427 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($link[
'asset']->id,
'links')) {
428 return $this->
_abortCreate($trigger_level_changed, $linkid);
430 }
else if ($new_link[
'is_dependant']) {
433 $parent_lock_info = $GLOBALS[
'SQ_SYSTEM']->am->getLockInfo($link[
'asset']->
id,
'all');
434 foreach (array_values($parent_lock_info) as $lock_details) {
435 if (empty($lock_details))
continue;
436 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->id, $lock_details[
'lock_type'], $lock_details[
'source_assetid'])) {
437 return $this->
_abortCreate($trigger_level_changed, $linkid);
441 if (!$new_link[
'is_dependant']) {
442 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($this->id,
'links')) {
443 return $this->
_abortCreate($trigger_level_changed, $linkid);
452 if ($trigger_level_changed) {
453 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
457 $modified_runlevel = FALSE;
458 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_LOCKING)) {
459 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($GLOBALS[
'SQ_SYSTEM']->getRunLevel() - SQ_SECURITY_LOCKING);
460 $modified_runlevel = TRUE;
464 $event_result = $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_before_asset_created', $this);
466 if ($modified_runlevel) {
467 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
470 if (!$event_result)
return $this->
_abortCreate(FALSE, $linkid);
473 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_INTEGRITY)) {
485 $current_user = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
486 if (!empty($current_user) && !$GLOBALS[
'SQ_SYSTEM']->am->setPermission($this->id, $current_user, SQ_PERMISSION_WRITE, TRUE)) {
491 unset($this->_tmp[
'__creating__']);
493 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
494 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
497 if ($this->status == SQ_STATUS_EDITING) {
502 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_asset_created', $this);
503 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
519 'status_changed_userid',
522 $em->broadcastEvent($this,
'AssetCreate', $vars);
526 return (
int) $linkid;
598 protected function _abortCreate($trigger_level_changed=FALSE, $linkid = 0)
600 if ($trigger_level_changed) {
601 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
604 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
608 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
610 $children_assets = Array();
611 if (isset($link[
'minorid'])) {
612 $children_assets = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($link[
'minorid'],
'', TRUE, NULL, NULL, NULL, TRUE, NULL, 1);
616 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
617 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
619 if (!empty($link) && isset($link[
'linkid']) && isset($link[
'majorid'])) {
621 $GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLinkByLink($link, TRUE, TRUE);
626 foreach($children_assets as $child_assetid => $val) {
627 $child_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($link[
'minorid'], $child_assetid);
629 if (isset($child_link[
'linkid'])) {
630 $child_link[
'majorid'] = $link[
'minorid'];
631 $child_link[
'major_type_code'] = $this->
type();
632 $GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLinkByLink($child_link, TRUE, TRUE);
638 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($this);
639 unset($this->_tmp[
'__creating__']);
641 @$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($this->
id,
'all');
662 $sql =
'SELECT assetid, type_code, version, name, short_name, status, languages,
663 charset, force_secure, created, created_userid, updated, updated_userid,
664 published, published_userid, status_changed, status_changed_userid
665 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast ';
666 $where =
'assetid = :assetid';
667 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
673 if (!empty($result)) {
674 $result = $result[0];
676 }
catch (Exception $e) {
677 throw new Exception(
'Unable to get asset info for asset ID #'.$assetid.
' due to database error: '.$e->getMessage());
680 if (empty($result)) {
681 trigger_localised_error(
'SYS0087', E_USER_WARNING, $assetid);
685 $this->
id = $result[
'assetid'];
686 $type_code = $result[
'type_code'];
687 $this->version = $result[
'version'];
688 $this->name = $result[
'name'];
689 $this->short_name = $result[
'short_name'];
690 $this->status = $result[
'status'];
691 $this->languages = $result[
'languages'];
692 $this->charset = $result[
'charset'];
693 $this->force_secure = $result[
'force_secure'];
694 $this->created = iso8601_ts($result[
'created']);
695 $this->created_userid = $result[
'created_userid'];
696 $this->updated = iso8601_ts($result[
'updated']);
697 $this->updated_userid = $result[
'updated_userid'];
698 $this->published = $result[
'published'];
699 $this->published_userid = $result[
'published_userid'];
700 $this->status_changed = $result[
'status_changed'];
701 $this->status_changed_userid = $result[
'status_changed_userid'];
703 if (!is_null($this->status_changed)) {
704 $this->status_changed = iso8601_ts($this->status_changed);
706 if (!is_null($this->published)) {
707 $this->published = iso8601_ts($this->published);
712 if ($type_code != $this->
type()) {
713 trigger_localised_error(
'SYS0089', E_USER_WARNING, $assetid, $this->
type());
715 $this->created = NULL;
716 $this->created_userid = NULL;
717 $this->updated = NULL;
718 $this->updated_userid = NULL;
719 $this->published = NULL;
720 $this->published_userid = NULL;
721 $this->status_changed = NULL;
722 $this->status_changed_userid = NULL;
729 trigger_localised_error(
'SYS0088', E_USER_WARNING, $assetid);
750 $this->data_path_suffix = asset_data_path_suffix($this->
type(), $this->
id);
751 $this->data_path = SQ_DATA_PATH.
'/private/'.$this->data_path_suffix;
752 $this->data_path_public = SQ_DATA_PATH.
'/public/'.$this->data_path_suffix;
754 $this->data_path .=
'/.sq_system';
774 $this->vars = Array();
781 $sql =
'SELECT atr.name, atr.attrid, atr.type, COALESCE(v.custom_val, atr.default_val) AS value, atr.is_contextable, v.use_default
782 FROM (sq_ast_attr atr
783 LEFT OUTER JOIN (SELECT * FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_attr_val WHERE contextid = :contextid) v
784 ON (atr.attrid = v.attrid AND v.assetid = :assetid'
785 .$GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause(
'',
'v',
'AND').
'))
786 WHERE atr.type_code = :type_code';
789 $sql =
'SELECT atr.name, atr.attrid, atr.type, atr.default_val AS value, atr.is_contextable, \'1\' as use_default
791 WHERE atr.type_code = :type_code';
804 if (empty($result)) {
805 $this->vars = Array();
807 $this->vars = $result;
808 foreach (array_keys($this->vars) as $name) {
809 $this->vars[$name] = $this->vars[$name][0];
810 unset($this->vars[$name][0]);
815 }
catch (Exception $e) {
816 throw new Exception(
'Unable to load variables of asset #'.$this->
id.
' ('.$this->
type().
') due to database error: '.$e->getMessage());
819 if ($this->_ser_attrs && $this->vars) {
820 for (reset($this->vars); NULL !== ($name = key($this->vars)); next($this->vars)) {
821 if ($this->vars[$name][
'type'] !=
'serialise') {
824 $this->vars[$name][
'value'] = @unserialize($this->vars[$name][
'value']);
839 $this->_tmp = Array();
840 $this->
load($this->
id);
871 public function delete($release_lock=TRUE, $check_locked=TRUE)
874 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetInTrash($this->id)) {
875 trigger_localised_error(
'SYS0103', E_USER_WARNING, $this->name, $this->
id);
879 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
881 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
883 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_ALL,
'', TRUE,
'minor');
884 foreach ($links as $link) {
885 $major = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'majorid'], $link[
'major_type_code']);
886 if (!is_null($major)) {
887 $major->deleteLink($link[
'linkid'], $check_locked);
889 trigger_localised_error(
'SYS0128', E_USER_WARNING, $link[
'majorid']);
890 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
891 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
899 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($this->id,
'all')) {
900 trigger_localised_error(
'SYS0131', E_USER_WARNING, $this->name);
901 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
902 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
909 trigger_localised_error(
'SYS0133', E_USER_WARNING, $this->name);
910 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
911 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
918 trigger_localised_error(
'SYS0132', E_USER_WARNING, $this->name);
919 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
920 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
924 $bind_vars[
'assetid'] = $this->id;
932 }
catch (Exception $e) {
933 throw new Exception(
"Failed to delete asset (#$this->id): ".$e->getMessage());
937 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
938 if (!$mm->purgeMetadata($this->id)) {
939 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
940 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
945 $wm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
946 if (!$wm->purgeWorkflow($this->id)) {
947 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
948 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
953 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
954 if (is_dir($this->data_path)) {
955 if (!delete_directory($this->data_path)) {
956 trigger_localised_error(
'SYS0151', E_USER_WARNING, $this->name);
957 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
958 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
963 if (is_dir($this->data_path_public)) {
964 if (!delete_directory($this->data_path_public)) {
965 trigger_localised_error(
'SYS0151', E_USER_WARNING, $this->name);
966 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
967 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
972 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
973 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
975 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
976 $em->broadcastEvent($this,
'assetDeleted', Array());
977 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($this, TRUE);
995 if (!isset($this->_tmp[
'use_system_version'])) {
996 if (!($this->status & SQ_SC_STATUS_SAFE_EDITING)) {
997 $this->_tmp[
'use_system_version'] = FALSE;
999 if ($GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'force_system_version')) {
1000 $this->_tmp[
'use_system_version'] = TRUE;
1002 if (SQ_ROLLBACK_VIEW) {
1003 $usv = (!$this->
checkAccess(SQ_PERMISSION_WRITE,
''));
1007 if ($usv && !$GLOBALS[
'SQ_SYSTEM']->userPublic()) {
1008 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
1009 $publishers = $wfm->whoCanPublish($this->
id);
1010 if (!empty($publishers) && in_array($GLOBALS[
'SQ_SYSTEM']->currentUserId(), $publishers)) {
1014 $this->_tmp[
'use_system_version'] = $usv;
1018 return $this->_tmp[
'use_system_version'];
1033 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1036 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
1037 $filename =
'.object_data'.(($contextid === 0) ?
'' :
'.'.$contextid);
1038 if (file_exists($this->data_path.
'/'.$filename) === TRUE) {
1039 $use_filename = $this->data_path.
'/'.$filename;
1040 }
else if (file_exists($this->data_path.
'/.object_data') === TRUE) {
1043 $use_filename = $this->data_path.
'/.object_data';
1045 trigger_localised_error(
'SYS0159', E_USER_WARNING, $this->
id, $this->data_path);
1049 $real_status = $this->status;
1051 foreach (get_object_vars(unserialize(file_to_string($use_filename))) as $key => $value) {
1052 $this->$key = $value;
1054 $this->status = $real_status;
1070 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1073 if (!create_directory($this->data_path)) {
1074 trigger_localised_error(
'CORE0049', E_USER_WARNING, $this->name);
1079 if (!create_directory($this->data_path.
'/.sq_system')) {
1080 trigger_localised_error(
'CORE0050', E_USER_WARNING, $this->name);
1085 if (!clear_directory($this->data_path.
'/.sq_system')) {
1086 trigger_localised_error(
'CORE0050', E_USER_WARNING, $this->name);
1094 $current_vars = $this->vars;
1095 $contextids = array_keys($GLOBALS[
'SQ_SYSTEM']->getAllContexts());
1096 foreach ($contextids as $contextid) {
1098 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
1101 $filename =
'.object_data'.(($contextid === 0) ?
'' :
'.'.$contextid);
1102 if (!string_to_file(serialize($this), $this->data_path.
'/.sq_system/'.$filename)) {
1103 trigger_localised_error(
'CORE0051', E_USER_WARNING, $this->name);
1107 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
1111 $this->vars = $current_vars;
1115 $files_to_copy = list_files($this->data_path);
1116 foreach ($files_to_copy as $filename) {
1117 if (!copy_file($this->data_path.
'/'.$filename, $this->data_path.
'/.sq_system/'.$filename)) {
1118 trigger_localised_error(
'SYS0166', E_USER_WARNING, $this->name, $filename);
1124 $replace_assetids = Array();
1125 $notice_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE);
1128 $links_to_preserve = Array(
1130 'paint_with_layout',
1135 foreach ($notice_links as $link) {
1136 if (in_array($link[
'value'], $links_to_preserve)) {
1137 $replace_assetids[] = $link;
1142 if (!string_to_file(serialize($replace_assetids), $this->data_path.
'/.sq_system/.sq_notice_links')) {
1143 trigger_localised_error(
'CORE0048', E_USER_WARNING, $this->name);
1160 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1163 if (!create_directory($this->data_path)) {
1164 trigger_localised_error(
'SYS0148', E_USER_WARNING, $this->name);
1169 if (!create_directory($this->data_path.
'/.sq_system')) {
1170 trigger_localised_error(
'SYS0299', E_USER_WARNING, $this->name);
1174 if (!clear_directory($this->data_path.
'/.sq_system')) {
1175 trigger_localised_error(
'SYS0147', E_USER_WARNING, $this->name);
1195 $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] = TRUE;
1196 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1199 $files_to_copy = list_files($this->data_path.
'/.sq_system');
1200 foreach ($files_to_copy as $filename) {
1202 if (strpos($filename,
'.') === 0)
continue;
1204 if (!copy_file($this->data_path.
'/.sq_system/'.$filename, $this->data_path.
'/'.$filename)) {
1205 trigger_localised_error(
'SYS0162', E_USER_WARNING, $this->name, $filename);
1206 $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] = FALSE;
1212 $current_contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
1213 $contextids = array_keys($GLOBALS[
'SQ_SYSTEM']->getAllContexts());
1214 foreach ($contextids as $contextid) {
1215 if ($contextid !== $current_contextid) {
1216 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
1217 $contexted_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id);
1219 $contexted_asset = $this;
1223 $filename =
'.object_data'.(($contextid === 0) ?
'' :
'.'.$contextid);
1224 if (is_file($this->data_path.
'/.sq_system/'.$filename)) {
1225 $old_version = unserialize(file_to_string($this->data_path.
'/.sq_system/'.$filename));
1226 }
else if (is_file($this->data_path.
'/.sq_system/.object_data')) {
1229 $old_version = unserialize(file_to_string($this->data_path.
'/.sq_system/.object_data'));
1231 trigger_localised_error(
'SYS0163', E_USER_WARNING, $this->name);
1232 $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] = FALSE;
1237 foreach ($old_version->vars as $var_name => $var_data) {
1238 if (!$contexted_asset->setAttrValue($var_name, $var_data[
'value'], TRUE)) {
1239 trigger_localised_error(
'SYS0165', E_USER_WARNING, $this->name, $var_name);
1240 $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] = FALSE;
1245 if (!$contexted_asset->saveAttributes()) {
1246 trigger_localised_error(
'SYS0164', E_USER_WARNING, $this->name);
1247 $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] = FALSE;
1251 if ($contextid !== $current_contextid) {
1252 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
1253 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($contexted_asset);
1254 unset($contexted_asset);
1262 $metadata_filename = $this->data_path.
'/.sq_system/metadata_field_values.php';
1263 if (is_file($metadata_filename)) {
1264 $old_metadata = unserialize(file_to_string($metadata_filename));
1267 $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->
id,
'metadata');
1269 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
1272 if (!$mm->setMetadata($this->id, $old_metadata)) {
1273 trigger_localised_error(
'SYS0331', E_USER_WARNING, $this->name);
1274 $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] = FALSE;
1279 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($this->
id,
'metadata');
1283 trigger_localised_error(
'SYS0161', E_USER_WARNING, $this->name);
1284 $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] = FALSE;
1289 foreach (get_object_vars($old_version) as $key => $value) {
1290 $this->$key = $value;
1295 $this->_tmp[
'reverting_to_system_version'] = TRUE;
1300 $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] = FALSE;
1316 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1317 $notice_links_file = file_to_string($this->data_path.
'/.sq_system/.sq_notice_links');
1321 if (!empty($notice_links_file)) {
1322 $system_ver_notice_links = unserialize($notice_links_file);
1323 $notice_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE);
1325 $links_to_preserve = Array(
1327 'paint_with_layout',
1332 foreach ($notice_links as $index => $info) {
1333 if (in_array($info[
'value'], $links_to_preserve)) {
1334 foreach($system_ver_notice_links as $prev_index => $prev_info) {
1335 if (array_diff($info, $prev_info) == Array()) {
1336 unset($system_ver_notice_links[$prev_index]);
1337 unset($notice_links[$index]);
1341 unset($notice_links[$index]);
1344 if (empty($system_ver_notice_links) && empty($notice_links))
return TRUE;
1346 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1347 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1349 $run_level_changed = FALSE;
1350 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_LOCKING)) {
1351 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($GLOBALS[
'SQ_SYSTEM']->getRunLevel() - SQ_SECURITY_LOCKING);
1352 $run_level_changed = TRUE;
1358 foreach ($notice_links as $link_data) {
1359 if (!$this->
deleteLink($link_data[
'linkid'])) {
1360 if ($run_level_changed) {
1361 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1363 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1364 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1370 foreach ($system_ver_notice_links as $link_info) {
1372 if (!isset($link_info[
'minorid']) || !assert_valid_assetid($link_info[
'minorid'],
'', FALSE, FALSE)) {
1375 $minor_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link_info[
'minorid']);
1376 if (is_null($minor_asset))
continue;
1380 if (isset($link_info[
'value'])) {
1381 $link_val = $link_info[
'value'];
1383 $this->
createLink($minor_asset, SQ_LINK_NOTICE, $link_val);
1387 if ($run_level_changed) {
1388 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1390 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1391 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1397 if ($run_level_changed) {
1398 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1401 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1402 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1428 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
1429 require_once SQ_FUDGE_PATH.
'/general/general.inc';
1431 if (isset($this->_tmp[
'__creating__']) && $this->_tmp[
'__creating__']) {
1436 $updated_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1437 $default_context = 0;
1438 $name = check_char_encoding(substr($this->
_getName(FALSE, $default_context), 0, 255));
1439 $short_name = check_char_encoding(substr($this->
_getName(TRUE, $default_context), 0, 255));
1446 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1447 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1448 $bind_vars = Array();
1454 if (($name ===
'0') || (!empty($name))) {
1455 $bind_vars[
'name'] = $name;
1456 $sql .=
'name = :name,';
1458 if (($short_name ===
'0') || (!empty($short_name))) {
1459 $bind_vars[
'short_name'] = $short_name;
1460 $sql .=
'short_name = :short_name,';
1464 languages = :languages,
1466 force_secure = :force_secure,
1468 updated_userid = :updated_userid
1470 assetid = :assetid';
1472 $bind_vars[
'languages'] = $this->languages;
1473 $bind_vars[
'charset'] = $this->charset;
1474 $bind_vars[
'force_secure'] = $this->force_secure;
1475 $bind_vars[
'updated'] = ts_iso8601($updated);
1476 $bind_vars[
'updated_userid'] = $updated_userid;
1477 $bind_vars[
'assetid'] = $this->id;
1481 foreach ($bind_vars as $bind_var => $bind_value) {
1485 }
catch (Exception $e) {
1486 throw new Exception(
'Unable to update asset "'.$this->
_getName().
'" (#'.$this->
id.
') due to database error: '.$e->getMessage());
1489 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
1498 $changed_data = Array(
'updated');
1499 foreach ($fields as $field) {
1500 if ($this->$field != $$field) {
1501 $changed_data[] = $field;
1506 $this->name = $name;
1507 $this->short_name = $short_name;
1508 $this->updated = $updated;
1509 $this->updated_userid = $updated_userid;
1513 trigger_localised_error(
'SYS0183', E_USER_WARNING, $this->name);
1514 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1515 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1519 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1520 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1522 $em->broadcastEvent($this,
'AssetUpdate', $changed_data);
1524 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_asset_updated', $this);
1546 protected function _getName($short_name=FALSE, $contextid=NULL)
1548 return $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->
type(),
'name').
' #'.$this->id;
1565 return strtolower(get_class($this));
1582 return $GLOBALS[
'SQ_SYSTEM']->am->getTypeAncestors($this->
type(), $include_asset);
1600 if (!$this->
id)
return FALSE;
1613 trigger_localised_error(
'SYS0157', E_USER_WARNING, $this->name, $this->
id, $number);
1620 $version_parts = explode(
'.', $this->version);
1621 for (reset($version_parts); NULL !== ($k = key($version_parts)); next($version_parts)) {
1622 $value =& $version_parts[$k];
1623 $value = (int)$value;
1624 if ($k == $part_num) {
1626 }
else if ($k > $part_num) {
1632 $new_version = implode(
'.', $version_parts);
1634 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1635 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1643 assetid = :assetid';
1650 }
catch (Exception $e) {
1651 throw new Exception(
'Unable to increment version of "'.$this->
_getName().
'" (#'.$this->
id.
') due to database error: '.$e->getMessage());
1654 if ($update_parents) {
1657 $dependant_parents = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($this->
id);
1658 foreach ($dependant_parents as $parentid) {
1659 $dep_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parentid);
1660 if (!is_null($dep_parent)) {
1661 if (!$dep_parent->_updated(FALSE)) {
1662 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1663 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1664 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($dep_parent);
1665 trigger_localised_error(
'SYS0158', E_USER_WARNING, $this->name, $this->
id, $dep_parent->name, $dep_parent->id);
1669 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($dep_parent);
1673 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
1674 $em->broadcastEvent($this,
'AssetVersionUpdate', Array(
1675 'old_version' => $this->version,
1676 'new_version' => $new_version,
1680 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1681 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1683 $this->version = $new_version;
1697 $langs = trim($this->languages,
', ');
1698 if ($langs ==
'')
return Array();
1699 return explode(
',', $langs);
1714 $set_languages = implode(
',', $languages);
1715 if ($set_languages == $this->languages)
return FALSE;
1717 $old_languages = $this->languages;
1718 $this->languages = $set_languages;
1720 trigger_localised_error(
'SYS0172', E_USER_WARNING, $this->name);
1721 $this->languages = $old_languages;
1725 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
1726 $em->broadcastEvent($this,
'AssetLanguageUpdate', Array(
1727 'old_languages' => $old_languages,
1728 'new_languages' => $this->languages,
1746 if ($charset == $this->charset)
return FALSE;
1747 $old_charset = $this->charset;
1748 $this->charset = $charset;
1750 trigger_localised_error(
'SYS0170', E_USER_WARNING, $this->name);
1751 $this->charset = $old_charset;
1755 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
1756 $em->broadcastEvent($this,
'AssetCharsetUpdate', Array(
1757 'old_charset' => $old_charset,
1758 'new_charset' => $this->charset,
1789 trigger_localised_error(
'SYS0252', E_USER_WARNING);
1793 if ($force_secure !==
'-') {
1794 $force_secure = ($force_secure) ?
'1' :
'0';
1796 if ($force_secure == $this->force_secure)
return FALSE;
1797 $old_force_secure = $this->force_secure;
1798 $this->force_secure = $force_secure;
1800 trigger_localised_error(
'SYS0169', E_USER_WARNING, $this->name, $this->
id);
1801 $this->force_secure = $old_force_secure;
1805 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
1806 $em->broadcastEvent($this,
'AssetForceSecureUpdate', Array(
1807 'old_force_secure' => $old_force_secure,
1808 'old_force_secure' => $this->force_secure,
1827 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1828 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1830 $dependant_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_SIGNIFICANT,
'', TRUE,
'major', NULL, 1);
1831 if (!empty($dependant_links)) {
1832 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1833 foreach ($dependant_links as $link) {
1834 $asset = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
1835 if (!$asset->remapAssetids($map)) {
1836 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1837 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1843 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1844 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1864 $new_type_code = strtolower($new_type_code);
1865 $old_type_code = $this->
type();
1867 if ($this->
type() == $new_type_code)
return $this;
1869 if (!$GLOBALS[
'SQ_SYSTEM']->am->installed($new_type_code)) {
1870 trigger_localised_error(
'SYS0085', E_USER_WARNING, $new_type_code);
1874 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1877 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1878 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1882 $sql =
'SELECT COUNT(*)
1883 FROM sq_ast_typ_inhd
1884 WHERE (inhd_type_code = :type1 AND type_code = :type2)
1885 OR (inhd_type_code = :type2 AND type_code = :type1)';
1891 }
catch (Exception $e) {
1892 throw new Exception(
'Unable to get number of inherited type codes for this inherited type code: '.$this->
type().
' and this type code: '.$new_type_code.
' due to database error: '.$e->getMessage());
1896 trigger_localised_error(
'SYS0234', E_USER_WARNING, $this->name, $new_type_code, $this->
type());
1897 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1898 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1902 $am->includeAsset($new_type_code);
1903 $tmp =
new $new_type_code();
1908 if ($num_links = $GLOBALS[
'SQ_SYSTEM']->am->countLinks($this->id,
'major')) {
1910 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_ALL);
1911 foreach ($links as $link) {
1914 if (strpos($link[
'minorid'],
':') !== FALSE) {
1917 if ($GLOBALS[
'SQ_SYSTEM']->am->canLinkToType($tmp, $link[
'minor_type_code'], $link[
'link_type'], 0, $link[
'is_exclusive']) !== TRUE) {
1918 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
1919 trigger_localised_error(
'SYS0236', E_USER_WARNING, $this->name, $new_type_code, $link[
'minor_type_code'], link_type_name($link[
'link_type']), $new_type_code);
1920 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1921 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1929 $num_links = $GLOBALS[
'SQ_SYSTEM']->am->countLinks($this->
id,
'minor');
1932 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_ALL,
'', TRUE,
'minor');
1933 foreach ($links as $link) {
1934 $parent = $am->getAsset($link[
'majorid'], $link[
'major_type_code']);
1935 if (is_null($parent))
continue;
1936 if (($err_msg = $GLOBALS[
'SQ_SYSTEM']->am->canLinkToType($parent, $new_type_code, $link[
'link_type'], $link[
'linkid'], $link[
'is_exclusive'])) !== TRUE) {
1937 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
1938 trigger_localised_error(
'SYS0235', E_USER_WARNING, $this->name, $new_type_code, $parent->name, $parent->id, $err_msg);
1939 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1940 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1948 $current_var_list = array_keys($this->vars);
1949 $new_var_list = array_keys($tmp->vars);
1953 $common_var_list = array_intersect($current_var_list, $new_var_list);
1955 if ($common_var_list) {
1956 foreach ($common_var_list as $var_name) {
1958 $current_id = $this->vars[$var_name][
'attrid'];
1959 $new_id = $tmp->vars[$var_name][
'attrid'];
1963 $bind_vars = Array (
1964 'newattrid' => $new_id,
1965 'assetid' => $this->
id,
1966 'currentattrid' => $current_id,
1969 }
catch (Exception $e) {
1970 throw new Exception(
'Unable to update attribute id for asset: '.$this->
id.
' from current attribute id: '.$current_id.
' to new attribute id: '.$new_id.
' due to database error: '.$e->getMessage());
1976 $deletes_var_list = array_diff($current_var_list, $new_var_list);
1978 if ($deletes_var_list) {
1979 $deletes_attributeids =
'';
1980 foreach ($deletes_var_list as $var_name) {
1981 $deletes_attributeids .= (($deletes_attributeids) ?
',' :
'').MatrixDAL::quote($this->vars[$var_name][
'attrid']);
1990 '.$deletes_attributeids.
'
1997 }
catch (Exception $e) {
1998 throw new Exception(
'Unable to delete attribute values for asset: '.$this->
id.
' due to database error: '.$e->getMessage());
2004 $bind_vars = Array (
2005 'type_code' => $new_type_code,
2006 'assetid' => $this->
id,
2009 }
catch (Exception $e) {
2010 throw new Exception(
'Unable to update type code for asset: '.$this->
id.
' due to database error: '.$e->getMessage());
2014 $tmp->load($this->
id);
2018 if (is_dir($this->data_path)) {
2019 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
2021 if (create_directory(dirname($tmp->data_path)) && rename($this->data_path, $tmp->data_path)) {
2038 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2039 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2041 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
2042 $em->broadcastEvent($this,
'AssetTypeUpdate', Array(
2043 'old_type' => $old_type_code,
2044 'new_type' => $new_type_code,
2052 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($tmp, TRUE);
2053 return $GLOBALS[
'SQ_SYSTEM']->am->getAsset($tmp->id, $tmp->type());
2056 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2057 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2095 if (!isset($vars[
'keywords']))
return;
2150 if (!is_array($components) || empty($components)) {
2153 if (is_null($clone))
return FALSE;
2155 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2156 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2158 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = TRUE;
2160 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
2165 if (in_array(
'attributes', $components) || in_array(
'all', $components)) {
2166 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS) || $clone->
writeAccess(
'attributes')) {
2168 $current_vars = $this->vars;
2170 foreach ($all_contexts as $contextid => $context_data) {
2174 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
2178 foreach ($this->vars as $name => $data) {
2179 if (($contextid === 0) || ((
boolean)$data[
'use_default'] === FALSE)) {
2181 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2182 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2183 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = FALSE;
2189 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2190 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2191 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = FALSE;
2195 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
2199 $this->vars = $current_vars;
2201 trigger_localised_error(
'SYS0328', E_USER_WARNING, $clone->name);
2210 if (in_array(
'permissions', $components) || in_array(
'all', $components)) {
2211 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS) || $clone->
adminAccess(
'permissions')) {
2212 $this->_tmp[__CLASS__.
'_in_create_cascading'] = TRUE;
2213 foreach (Array(SQ_PERMISSION_READ, SQ_PERMISSION_WRITE, SQ_PERMISSION_ADMIN) as $perm) {
2214 $set_perms = $GLOBALS[
'SQ_SYSTEM']->am->getAssetPermissionByCascade($this->
id, $perm, NULL, TRUE);
2215 foreach ($set_perms as $perm_info) {
2216 if (!$GLOBALS[
'SQ_SYSTEM']->am->setPermission($clone->id, $perm_info[
'userid'], $perm, $perm_info[
'granted'], TRUE, $override)) {
2217 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2218 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2219 unset($this->_tmp[__CLASS__.
'_in_create_cascading']);
2220 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = FALSE;
2225 unset($this->_tmp[__CLASS__.
'_in_create_cascading']);
2227 trigger_localised_error(
'SYS0322', E_USER_WARNING, $clone->name);
2236 if (in_array(
'roles', $components) || in_array(
'all', $components)) {
2237 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS) || $clone->
adminAccess(
'roles')) {
2238 $roles = $GLOBALS[
'SQ_SYSTEM']->am->getRole($this->
id);
2239 foreach ($roles as $roleid => $ids) {
2240 foreach ($ids as $row => $userid) {
2241 if (!$GLOBALS[
'SQ_SYSTEM']->am->setRole($clone->id, $roleid, $userid)) {
2242 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2243 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2244 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = FALSE;
2250 trigger_localised_error(
'SYS0325', E_USER_WARNING, $clone->name);
2260 if (in_array(
'metadata_schemas', $components) || in_array(
'all', $components)) {
2261 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS) || $clone->
adminAccess(
'metadata')) {
2262 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
2263 if ($mm->allowsMetadata($clone->id)) {
2266 $schemas = $mm->getSchemas($this->
id, NULL, TRUE);
2269 $metadata = Array();
2270 foreach ($schemas as $schemaid => $granted) {
2271 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetExists($schemaid)) {
2276 if (++$schema_count == count($schemas)) {
2277 $clone->
unFastTrack(
'metadata_manager_generate_content_file');
2279 $clone->
fastTrack(
'metadata_manager_generate_content_file');
2282 if (!$mm->setSchema($clone->id, $schemaid, $granted, TRUE, $override)) {
2283 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2284 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2285 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = FALSE;
2291 trigger_localised_error(
'SYS0323', E_USER_WARNING, $clone->name);
2296 if (in_array(
'metadata', $components) || in_array(
'all', $components)) {
2297 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
2298 if ($mm->allowsMetadata($clone->id)) {
2299 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS) || $clone->
writeAccess(
'metadata')) {
2303 foreach ($all_contexts as $contextid => $context_data) {
2307 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
2309 $metadata = $mm->getMetadata($this->
id);
2310 if (!empty($metadata)) {
2314 if (!$mm->setMetadata($clone->id, $metadata) || !$mm->regenerateMetadata($clone->id)) {
2319 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
2321 if ($ok === FALSE)
break;
2326 if ($ok === FALSE) {
2327 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2328 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2329 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = FALSE;
2334 trigger_localised_error(
'SYS0327', E_USER_WARNING, $clone->name);
2344 if (in_array(
'workflow', $components) || in_array(
'all', $components)) {
2345 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS) || $clone->
adminAccess(
'workflow')) {
2346 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
2348 $schemas = $wfm->getSchemas($this->
id, NULL, FALSE, TRUE);
2349 foreach ($schemas as $schemaid => $granted) {
2350 if (!$wfm->setSchema($clone->id, $schemaid, $granted, TRUE, $override)) {
2351 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2352 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2353 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = FALSE;
2358 trigger_localised_error(
'SYS0324', E_USER_WARNING, $clone->name);
2367 if (in_array(
'data', $components) || in_array(
'all', $components)) {
2369 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS) && !$clone->
writeAccess(
'attributes')) {
2371 trigger_localised_error(
'SYS0321', E_USER_WARNING, $clone->name);
2374 if (is_dir($this->data_path)) {
2375 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
2377 if (!copy_directory($this->data_path, $clone->data_path)) {
2378 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2379 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2380 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = FALSE;
2392 if (in_array(
'content_tags', $components) || in_array(
'all', $components)) {
2393 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS) || ($clone->
writeAccess(
'attributes') && $clone->
writeAccess(
'links'))) {
2394 $tag_manager = $GLOBALS[
'SQ_SYSTEM']->getTagManager();
2397 if (!is_null($tag_manager)) {
2398 $current_tag_links = $tag_manager->getTagLinks($this->
id);
2399 foreach ($current_tag_links as $link) {
2400 $tag_manager->setTag($clone->id, $link[
'minorid'], $link[
'value']);
2404 trigger_localised_error(
'SYS0326', E_USER_WARNING, $clone->name);
2408 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2409 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2410 $GLOBALS[
'SQ_CLONE_COMPONENTS'] = FALSE;
2460 $orig_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_3 | SQ_LINK_NOTICE,
'', TRUE,
'major', NULL, FALSE, NULL);
2461 foreach ($orig_links as $orig_link) {
2462 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($orig_link[
'minorid'], $orig_link[
'minor_type_code']);
2463 if ($asset->canCloneLink()) {
2464 $linkid = $clone->
createLink($asset, $orig_link[
'link_type'], $orig_link[
'value'], $orig_link[
'sort_order'], $orig_link[
'is_dependant'], $orig_link[
'is_exclusive']);
2465 if (!$linkid)
return FALSE;
2485 if (!isset($this->_tmp[
'status_object'])) {
2487 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
2488 $status_code = get_bit_names(
'SQ_STATUS_', $this->status);
2489 $status_code =
'asset_status_'.strtolower($status_code);
2490 require_once SQ_INCLUDE_PATH.
'/asset_status/'.$status_code.
'.inc';
2491 $this->_tmp[
'status_object'] =
new $status_code($this);
2493 return $this->_tmp[
'status_object'];
2508 $statii = $status->getAvailableStatii();
2509 ksort($statii, SORT_NUMERIC);
2510 return array_reverse($statii, TRUE);
2524 return $status->getDescription();
2541 $old_status = $this->status;
2547 if ($this->status > $new_status) {
2550 if ($this->status & ~(SQ_SC_STATUS_PENDING | SQ_SC_STATUS_ALL_APPROVED)) {
2551 $dependant_parents = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_SIGNIFICANT,
'', TRUE,
'minor', NULL, 1);
2552 if (!empty($dependant_parents)) {
2553 $am = $GLOBALS[
'SQ_SYSTEM']->am;
2554 foreach ($dependant_parents as $link) {
2555 $asset = $am->getAsset($link[
'majorid'], $link[
'major_type_code']);
2556 if ($asset->status > $new_status) {
2567 if (!$status->processStatusChange($new_status)) {
2571 if ($new_status != $old_status) {
2573 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2574 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2575 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
2582 status_changed = :status_changed_date,
2583 status_changed_userid = :userid
2585 assetid = :assetid';
2594 }
catch (Exception $e) {
2595 throw new Exception(
'Unable to update status of asset "'.$this->name.
'" (#'.$this->id.
'), due to database error: '.$e->getMessage());
2598 $this->status = $new_status;
2599 unset($this->_tmp[
'status_object']);
2601 if ($run_updated) $this->
_updated($update_parents);
2604 if ($new_status == SQ_STATUS_LIVE) {
2606 trigger_localised_error(
'SYS0271', E_USER_WARNING, $this->name);
2607 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
2608 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2613 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2614 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2617 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
2619 'old_status' => $old_status,
2620 'new_status' => $new_status,
2622 $em->broadcastEvent($this,
'AssetStatusUpdate', $data);
2625 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
2626 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
2628 'asset_name' => $this->name,
2629 'old_status' => get_status_description($old_status),
2630 'new_status' => get_status_description($new_status),
2632 $message = $ms->newMessage(Array(),
'asset.status', $msg_reps);
2633 $message->parameters[
'assetid'] = $this->id;
2637 $event_data[
'old_status'] = $old_status;
2638 $event_data[
'new_status'] = $new_status;
2639 if (isset($this->_tmp[
'old_urls'])) {
2640 $event_data[
'old_urls'] = $this->_tmp[
'old_urls'];
2642 if (isset($this->_tmp[
'allow_unrestricted'])) {
2643 $event_data[
'allow_unrestricted'] = $this->_tmp[
'allow_unrestricted'];
2645 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_status_changed', $this, $event_data);
2666 public function setDate($date_type, $time=NULL, $userid=NULL)
2668 if (!in_array($date_type, Array(
'published' ,
'created'))) {
2669 trigger_localised_error(
'SYS0198', E_USER_WARNING);
2673 if (is_null($userid)) {
2674 $userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
2676 if (is_null($time)) {
2677 if ($date_type ==
'created') {
2686 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
2687 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
2690 if ($this->$date_type != NULL) {
2691 $old_date_string = readable_datetime($this->$date_type);
2692 $current_user = $date_type.
'_userid';
2693 if ($this->$current_user != NULL) {
2694 $old_date_string .=
' by user #'.$this->$current_user;
2696 $old_date_string .=
' by [unknown user]';
2699 $old_date_string =
'never '.$date_type;
2703 if ($time != NULL) {
2704 $new_date_string = readable_datetime($time);
2705 if ($userid != NULL) {
2706 $new_date_string .=
' by user #'.$userid;
2708 $new_date_string .=
' by [unknown user]';
2711 $new_date_string =
'never '.$date_type;
2715 if ($this->$date_type == $time) {
2717 $user_type = $date_type.
'_userid';
2718 if ($this->$user_type == $userid)
return TRUE;
2722 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2723 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2729 '.$date_type.
' = :'.$date_type.
'_date,
2730 '.$date_type.
'_userid = :userid
2732 assetid = :assetid';
2740 }
catch (Exception $e) {
2741 throw new Exception(
'Unable to update '.str_replace(
'_',
' ', $date_type).
' date of asset "'.$this->name.
'" (#'.$this->id.
'), due to database error: '.$e->getMessage());
2744 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2745 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2747 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
2749 'date_type' => $date_type,
2750 'asset_name' => $this->name,
2751 'old_date' => $old_date_string,
2752 'new_date' => $new_date_string,
2754 $message = $ms->newMessage(Array(),
'asset.dates', $msg_reps);
2755 $message->parameters[
'assetid'] = $this->id;
2758 eval(
'$this->'.$date_type.
' = $time;');
2759 eval(
'$this->'.$date_type.
'_userid = $userid;');
2761 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
2762 $em->broadcastEvent($this,
'AssetUpdate', Array($date_type));
2781 $lock_types = Array(
2794 foreach ($lock_types as $lock_type) {
2795 $all = $all | $lock_type;
2797 $lock_types[
'all'] = $all;
2801 $lock_types[
'menu'] = $lock_types[
'attributes'] | $lock_types[
'links'];
2802 $lock_types[
'lookupValues'] = $lock_types[
'attributes'] | $lock_types[
'links'] | $lock_types[
'lookups'];
2820 $current_locks = $GLOBALS[
'SQ_SYSTEM']->am->getLockInfo($this->
id, $lock_type, TRUE, FALSE);
2823 if (empty($current_locks))
return FALSE;
2825 foreach ($current_locks as $lock) {
2826 if (empty($lock))
continue;
2828 if ($lock[
'userid']) {
2829 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($lock[
'userid']);
2833 if (!is_null($user)) {
2835 if ($GLOBALS[
'SQ_SYSTEM']->userRoot($user)) {
2840 if ($GLOBALS[
'SQ_SYSTEM']->userSystemAdmin($user) && !$GLOBALS[
'SQ_SYSTEM']->userRoot()) {
2846 if (!$GLOBALS[
'SQ_SYSTEM']->userRoot() && !$GLOBALS[
'SQ_SYSTEM']->userSystemAdmin()) {
2890 SQ_LINK_TYPE_1 => Array(),
2891 SQ_LINK_TYPE_2 => Array(),
2892 SQ_LINK_TYPE_3 => Array(),
2893 SQ_LINK_NOTICE => Array(
2894 'image' => Array(
'card' =>
'M',
'exclusive' => FALSE),
2895 'design' => Array(
'card' =>
'M',
'exclusive' => FALSE),
2896 'paint_layout_page' => Array(
'card' =>
'M',
'exclusive' => FALSE),
2923 public function createLink(
Asset $minor, $link_type, $value=
'', $sort_order=NULL, $dependant=
'0', $exclusive=
'0', $moving=FALSE, $locked=0)
2925 if (!$this->
id)
return 0;
2926 return $GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($this, $minor, $link_type, $value, $sort_order, $dependant, $exclusive, $moving, $locked);
2951 public function prepareLink(
Asset $asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
2970 if (!$this->
id)
return translate(
'asset_not_created');
2971 return $GLOBALS[
'SQ_SYSTEM']->am->canCreateLink($this, $minor, $link_type, $exclusive);
3043 if (!$this->
id)
return translate(
'asset_not_created');
3049 return translate(
'permission_denied');
3068 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid, $this->
id);
3070 trigger_localised_error(
'SYS0243', E_USER_NOTICE, $linkid);
3073 return $GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($linkid, $check_locked);
3125 if (!$this->
id)
return TRUE;
3126 if (empty($this->_tmp[
'vars_set']))
return TRUE;
3128 if (!$GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] && !$this->
writeAccess(
'attributes')) {
3129 trigger_localised_error(
'CORE0121', E_USER_WARNING, $this->name, $this->
id);
3133 $save_vars = Array();
3134 $attr_ids = Array();
3135 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
3140 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
3143 $changed_array = Array();
3145 foreach ($this->_tmp[
'vars_set'] as $var_name => $var_data) {
3146 $attr_id = $this->vars[$var_name][
'attrid'];
3147 $is_contextable = array_get_index($this->vars[$var_name],
'is_contextable', FALSE) ? TRUE : FALSE;
3150 $owning_attributeid = 0;
3152 if ($attribute->uniq) {
3154 $sql =
'SELECT oa.attrid
3156 INNER JOIN sq_ast_attr oa ON (a.owning_type_code = oa.type_code AND a.name = oa.name)
3157 WHERE a.name = :name
3158 AND a.type_code = :type_code';
3165 }
catch (Exception $e) {
3166 throw new Exception(
'Cannot check for attribute value "'.$name.
'" of type code "'.$this->type().
'" due to database error: '.$e->getMessage());
3171 $attr_value = $this->vars[$var_name][
'value'];
3172 if ($this->vars[$var_name][
'type'] ==
'serialise') {
3173 $attr_value = serialize($attr_value);
3175 $save_vars[$attr_id][
'value'] = $attr_value;
3176 $save_vars[$attr_id][
'name'] = $var_name;
3177 $save_vars[$attr_id][
'owning_attrid'] = $owning_attributeid;
3178 $attr_ids[] = $attr_id;
3183 'asset_name' => $this->name,
3184 'attr_name' => $attribute->name,
3186 $msg_type =
'asset.attributes.fulllog';
3187 if (is_scalar($var_data[
'old_value']) && is_scalar($attr_value)) {
3188 $msg_reps[
'old_value'] = $var_data[
'old_value'];
3189 $msg_reps[
'new_value'] = $attr_value;
3190 $msg_type .=
'.scalar';
3192 $message = $ms->newMessage(Array(), $msg_type, $msg_reps);
3193 $message->parameters[
'assetid'] = $this->id;
3194 $ms->logMessage($message);
3197 require_once SQ_FUDGE_PATH.
'/general/general.inc';
3198 $msg_type =
'asset.attributes';
3199 if (is_scalar($var_data[
'old_value']) && is_scalar($attr_value)) {
3200 $msg_reps[
'old_value'] = ellipsisize($var_data[
'old_value'],30);
3201 $msg_reps[
'new_value'] = ellipsisize($attr_value,30);
3202 $msg_type .=
'.scalar';
3205 $sml_message = $ms->newMessage(Array(), $msg_type, $msg_reps);
3206 $sml_message->parameters[
'assetid'] = $this->id;
3207 $ms->logMessage($sml_message);
3213 $changed_array[] = $attribute->name;
3217 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
3218 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
3222 $atrr_id_cond =
'IN ('.implode(
', ', $attr_ids).
')';
3223 $sql =
'SELECT attrid FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_attr_val ';
3224 $where =
'assetid = :assetid
3225 AND attrid '.$atrr_id_cond.
'
3226 AND contextid = :contextid';
3227 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
3234 }
catch (Exception $e) {
3235 throw new Exception(
'Unable to get attributes for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
3238 $new = array_diff($attr_ids, $existing);
3241 if (!empty($existing)) {
3243 foreach ($existing as $attr_id) {
3244 $attr_id = (int) $attr_id;
3245 $attr_value = $save_vars[$attr_id][
'value'];
3248 $attribute = $this->
getAttribute($save_vars[$attr_id][
'name']);
3249 $is_contextable = array_get_index($this->vars[$save_vars[$attr_id][
'name']],
'is_contextable', FALSE) ? TRUE : FALSE;
3252 if (($contextid === 0) || ($is_contextable === FALSE) || (array_key_exists(
'__creating__', $this->_tmp) === TRUE)) {
3256 $unique_query_name =
'updateDefaultContextUniqueAttrValue';
3257 $query_name =
'updateDefaultContextAttrValue';
3259 'custom_val' => $attr_value,
3260 'assetid' => $this->
id,
3265 $unique_query_name =
'updateAlternateContextUniqueAttrValue';
3266 $query_name =
'updateAlternateContextAttrValue';
3268 'custom_val' => $attr_value,
3269 'contextid' => $contextid,
3270 'assetid' => $this->
id,
3272 $this->vars[$save_vars[$attr_id][
'name']][
'use_default'] = 0;
3274 if ((
boolean)$attribute->uniq === TRUE) {
3275 $bind_vars[
'attrid'] = $save_vars[$attr_id][
'owning_attrid'];
3278 $bind_vars[
'attrid'] = $attr_id;
3280 }
catch (Exception $e) {
3281 throw new Exception(
'Unable to update attribute values for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
3291 foreach ($new as $attr_id) {
3292 $attr_id = (int) $attr_id;
3293 $attr_value = $save_vars[$attr_id][
'value'];
3296 $attribute = $this->
getAttribute($save_vars[$attr_id][
'name']);
3297 $is_contextable = array_get_index($this->vars[$save_vars[$attr_id][
'name']],
'is_contextable', FALSE) ? TRUE : FALSE;
3300 if (($contextid === 0) || ($is_contextable === FALSE) || (array_key_exists(
'__creating__', $this->_tmp) === TRUE)) {
3304 $unique_query_name =
'insertDefaultContextUniqueAttrValue';
3305 $query_name =
'insertDefaultContextAttrValue';
3307 'custom_val' => $attr_value,
3308 'assetid' => $this->
id,
3317 if ((
boolean)$attribute->uniq === TRUE) {
3319 $lob1->writeTemporary($bind_vars[
'custom_val'], OCI_TEMP_CLOB);
3322 $lob2->writeTemporary($bind_vars[
'custom_val'], OCI_TEMP_CLOB);
3327 $unique_query_name =
'insertAlternateContextUniqueAttrValue';
3328 $query_name =
'insertAlternateContextAttrValue';
3330 'custom_val' => $attr_value,
3331 'contextid' => $contextid,
3332 'assetid' => $this->
id,
3334 $this->vars[$save_vars[$attr_id][
'name']][
'use_default'] = 0;
3336 if ((
boolean)$attribute->uniq === TRUE) {
3337 if (isset($lob1) === TRUE) $bind_vars[
'custom_val'] = $lob1;
3338 $bind_vars[
'attrid'] = $save_vars[$attr_id][
'owning_attrid'];
3341 if (isset($lob2) === TRUE) $bind_vars[
'custom_val'] = $lob2;
3342 $bind_vars[
'attrid'] = $attr_id;
3344 }
catch (Exception $e) {
3345 throw new Exception(
'Unable to insert new attribute values for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
3353 if (!$dont_run_updated && !$this->
_updated()) {
3354 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
3355 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
3361 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
3362 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
3365 if (!empty($this->_tmp[
'vars_set'])) {
3367 foreach ($this->_tmp[
'vars_set'] as $attr => $details) {
3368 $changed_vars[$attr] = Array(
3369 'type' => $this->vars[$attr][
'type'],
3370 'old_value' => $details[
'old_value'],
3371 'new_value' => $this->
attr($attr),
3374 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_attributes_changed', $this, $changed_vars);
3377 unset($this->_tmp[
'vars_set']);
3380 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
3381 $em->broadcastEvent($this,
'attributeChange', $changed_array);
3382 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_attributes_saved', $this);
3404 if (empty($this->vars[$name])) {
3405 trigger_localised_error(
'SYS0093', E_USER_WARNING, $name, $this->
type());
3409 if(!SQ_IN_BACKEND && !SQ_IN_LIMBO && !SQ_IN_LOGIN && !SQ_IN_CRON && !SQ_PHP_CLI) {
3410 $filter_enabled = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'user',
'SQ_USER_FILTER_FRONT_END_INPUT');
3411 if(isset($GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'] ) && $GLOBALS[
'SQ_REVERT_TO_SYSTEM_VERSION'])
3412 $filter_enabled = FALSE;
3413 else if (isset($GLOBALS[
'SQ_CLONE_COMPONENTS'] ) && $GLOBALS[
'SQ_CLONE_COMPONENTS'])
3414 $filter_enabled = FALSE;
3417 $type_excl = Array (
'form_submission');
3418 $attr_excl = Array (
'xml');
3419 if ($filter_enabled && !(in_array($this->
type(), $type_excl) && in_array($name, $attr_excl))){
3420 if (!empty($value)) {
3421 $value = filter_content($value);
3422 if ($value === FALSE){
3423 trigger_localised_error(
'SYS0346', E_USER_WARNING, $name, $this->
type());
3431 if (!$attribute->setValue($value)) {
3432 trigger_localised_error(
'SYS0073', E_USER_WARNING, $value, $name);
3433 $attribute->setValue($this->vars[$name][
'value']);
3437 if ($this->vars[$name][
'type'] ==
'serialise') {
3438 $value = unserialize($value);
3444 if (($this->vars[$name][
'value'] === $value) || (is_null($this->vars[$name][
'value']) && $value ===
'')) {
3449 if ($attribute->uniq) {
3452 $sql =
'SELECT COUNT(*)
3453 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_attr_uniq_val uv
3454 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_attr oa ON uv.owning_attrid = oa.attrid
3455 INNER JOIN sq_ast_attr a ON (oa.type_code = a.owning_type_code AND oa.name = a.name)
3457 $where =
' uv.custom_val = :custom_val
3459 AND a.type_code = :type_code
3460 AND uv.contextid = :contextid';
3461 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'uv');
3470 }
catch (Exception $e) {
3471 throw new Exception(
'Cannot check for unique attribute value "'.$name.
'" of type code "'.$this->type().
'" due to database error: '.$e->getMessage());
3474 if ((
int) $result > 0) {
3475 trigger_localised_error(
'SYS0251', E_USER_WARNING, $name, $value);
3476 $attribute->setValue($this->vars[$name][
'value']);
3482 if (!isset($this->_tmp[
'vars_set'])) {
3483 $this->_tmp[
'vars_set'] = Array();
3485 if (is_scalar($this->vars[$name][
'value'])) {
3486 $this->_tmp[
'vars_set'][$name][
'old_value'] = $this->vars[$name][
'value'];
3488 $this->_tmp[
'vars_set'][$name][
'old_value'] =
'__(old value)__';
3491 $this->vars[$name][
'value'] = $value;
3510 if (!isset($this->vars[$name])) {
3511 trigger_localised_error(
'SYS0092', E_USER_WARNING, $name, $this->name, $this->
id);
3514 return $this->vars[$name][
'value'];
3529 if (!isset($this->vars[$name])) {
3530 trigger_localised_error(
'SYS0092', E_USER_WARNING, $name, $this->name, $this->
id);
3533 return $this->vars[$name][
'value'];
3551 if (!isset($this->_tmp[
'attributes'][$name]) || !is_object($this->_tmp[
'attributes'][$name])) {
3553 if (empty($this->_tmp[
'attributes'])) {
3554 $this->_tmp[
'attributes'] = Array();
3557 if (empty($this->vars[$name])) {
3558 if (!$mute_errors) {
3559 trigger_localised_error(
'SYS0094', E_USER_WARNING, $name, $this->
type());
3562 $this->_tmp[
'attributes'][$name] = NULL;
3565 require_once SQ_ATTRIBUTES_PATH.
'/'.$this->vars[$name][
'type'].
'/'.$this->vars[$name][
'type'].
'.inc';
3566 $attr_class =
'Asset_Attribute_'.$this->vars[$name][
'type'];
3567 $this->_tmp[
'attributes'][$name] =
new $attr_class($this->vars[$name][
'attrid'], $this->vars[$name][
'value']);
3573 return $this->_tmp[
'attributes'][$name];
3601 $keywords = Array();
3602 $default_keywords = Array(
3607 'asset_version_major',
3608 'asset_version_minor',
3609 'asset_version_micro',
3612 'asset_created_short',
3613 'asset_updated_short',
3614 'asset_created_readable',
3615 'asset_updated_readable',
3616 'asset_created_iso8601',
3617 'asset_updated_iso8601',
3618 'asset_created_rfc2822',
3619 'asset_updated_rfc2822',
3620 'asset_created_ical',
3621 'asset_updated_ical',
3622 'asset_created_by_name',
3623 'asset_updated_by_name',
3625 'asset_published_short',
3626 'asset_published_readable',
3627 'asset_published_iso8601',
3628 'asset_published_rfc2822',
3629 'asset_published_ical',
3630 'asset_published_by_name',
3631 'asset_status_changed',
3632 'asset_status_changed_short',
3633 'asset_status_changed_readable',
3634 'asset_status_changed_iso8601',
3635 'asset_status_changed_rfc2822',
3636 'asset_status_changed_ical',
3637 'asset_status_changed_by_name',
3641 'asset_thumbnail_url',
3642 'asset_thumbnail_caption',
3643 'asset_thumbnail_assetid',
3644 'asset_thumbnail_title',
3645 'asset_thumbnail_name',
3648 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3649 $mm_keywords = $mm->generateKeywordReplacements($this, $default_keywords, FALSE);
3650 foreach ($default_keywords as $keyword) {
3653 if(isset($mm_keywords[$keyword])) $keywords[$keyword][
'value'] = $mm_keywords[$keyword];
3656 foreach ($this->vars as $name => $info) {
3657 if ($info[
'type'] ==
'serialise')
continue;
3658 $keywords[
'asset_attribute_'.$name][
'value'] = $info[
'value'];
3660 if ($descriptions) {
3662 $keywords[
'asset_attribute_'.$name][
'description'] = $attr->description;
3666 $keywords[
'asset_assetid'][
'value'] = $this->id;
3668 if ($descriptions) {
3669 $keywords[
'asset_assetid'][
'description'] =
'The ID of the asset';
3670 $keywords[
'asset_name'][
'description'] =
'Full name of the asset';
3671 $keywords[
'asset_type'][
'description'] =
'Asset\'s type';
3672 $keywords[
'asset_short_name'][
'description'] =
'Short name of the asset';
3673 $keywords[
'asset_version'][
'description'] =
'Version of the asset being displayed';
3674 $keywords[
'asset_version_major'][
'description'] =
'Major version number of the asset being displayed';
3675 $keywords[
'asset_version_minor'][
'description'] =
'Minor version number of the asset being displayed';
3676 $keywords[
'asset_version_micro'][
'description'] =
'Micro version number of the asset being displayed';
3677 $keywords[
'asset_created'][
'description'] =
'The date and time the asset was created (yyyy-mm-dd hh:mm:ss)';
3678 $keywords[
'asset_updated'][
'description'] =
'The date and time the asset was last updated (yyyy-mm-dd hh:mm:ss)';
3679 $keywords[
'asset_status_updated'][
'description'] =
'The date and time the asset\'s status was last updated (yyyy-mm-dd hh:mm:ss)';
3680 $keywords[
'asset_published'][
'description'] =
'The date and time the asset was last published (yyyy-mm-dd hh:mm:ss)';
3681 $keywords[
'asset_created_short'][
'description'] =
'The date when the asset was created (yyyy-mm-dd)';
3682 $keywords[
'asset_updated_short'][
'description'] =
'The date when the asset was last updated (yyyy-mm-dd)';
3683 $keywords[
'asset_published_short'][
'description'] =
'The date when the asset was last published (yyyy-mm-dd)';
3684 $keywords[
'asset_status_updated_short'][
'description'] =
'The date when the asset\'s status was last changed (yyyy-mm-dd)';
3685 $keywords[
'asset_created_readable'][
'description'] =
'The date when the asset was created (dd m yyyy h:mm[am pm])';
3686 $keywords[
'asset_updated_readable'][
'description'] =
'The date when the asset was last updated (dd m yyyy h:mm[am pm])';
3687 $keywords[
'asset_created_readabledate'][
'description'] =
'The date when the asset was created (date only - dd m yyyy)';
3688 $keywords[
'asset_updated_readabledate'][
'description'] =
'The date when the asset was last updated (date only - dd m yyyy)';
3689 $keywords[
'asset_created_readabletime'][
'description'] =
'The date when the asset was created (time only - h:mm[am pm])';
3690 $keywords[
'asset_updated_readabletime'][
'description'] =
'The date when the asset was last updated (time only - h:mm[am pm])';
3691 $keywords[
'asset_created_iso8601'][
'description'] =
'The date when the asset was created (ISO8601 format)';
3692 $keywords[
'asset_updated_iso8601'][
'description'] =
'The date when the asset was last updated (ISO8601 format)';
3693 $keywords[
'asset_published_iso8601'][
'description'] =
'The date when the asset was last published (ISO8601 format)';
3694 $keywords[
'asset_created_rfc2822'][
'description'] =
'The date when the asset was created (RFC2822 format)';
3695 $keywords[
'asset_updated_rfc2822'][
'description'] =
'The date when the asset was last updated (RFC2822 format)';
3696 $keywords[
'asset_published_rfc2822'][
'description'] =
'The date when the asset was last published (RFC2822 format)';
3697 $keywords[
'asset_created_ical'][
'description'] =
'The date when the asset was created (iCalendar format)';
3698 $keywords[
'asset_updated_ical'][
'description'] =
'The date when the asset was last updated (iCalendar format)';
3699 $keywords[
'asset_published_ical'][
'description'] =
'The date when the asset was last published (iCalendar format)';
3700 $keywords[
'asset_published_readable'][
'description'] =
'The date when the asset was last published (dd m yyyy h:mm[am pm])';
3701 $keywords[
'asset_status_changed_readable'][
'description'] =
'The date when the asset\'s status was last changed (dd m yyyy h:mm[am pm])';
3702 $keywords[
'asset_published_readabledate'][
'description'] =
'The date when the asset was last published (date only - dd m yyyy)';
3703 $keywords[
'asset_status_changed_readabledate'][
'description'] =
'The date when the asset\'s status was last changed (date only - dd m yyyy)';
3704 $keywords[
'asset_published_readabletime'][
'description'] =
'The date when the asset was last published (time only - h:mm[am pm])';
3705 $keywords[
'asset_status_changed_readabletime'][
'description'] =
'The date when the asset\'s status was last changed (time only - h:mm[am pm])';
3706 $keywords[
'asset_created_by_name'][
'description'] =
'The name of the user who created this asset';
3707 $keywords[
'asset_updated_by_name'][
'description'] =
'The name of the user who last updated this asset';
3708 $keywords[
'asset_published_by_name'][
'description'] =
'The name of the user who last published this asset';
3709 $keywords[
'asset_status_changed_by_name'][
'description'] =
'The name of the user who last changed the status of this asset';
3710 $keywords[
'asset_url'][
'description'] =
'The absolute url to the asset';
3711 $keywords[
'asset_href'][
'description'] =
'The relative href to the asset';
3712 $keywords[
'asset_thumbnail'][
'description'] =
'The img tag for the thumbnail attached to the asset';
3713 $keywords[
'asset_thumbnail_url'][
'description'] =
'The URL only for the thumbnail attached to the asset';
3714 $keywords[
'asset_thumbnail_caption'][
'description'] =
'The caption for the thumbnail attached to the asset';
3715 $keywords[
'asset_thumbnail_assetid'][
'description'] =
'The asset id for the thumbnail attached to the asset';
3716 $keywords[
'asset_thumbnail_title'][
'description'] =
'The friendly name for the thumbnail attached to the asset';
3717 $keywords[
'asset_thumbnail_name'][
'description'] =
'The file name for the thumbnail attached to the asset';
3743 $keywords = Array();
3744 $default_keywords = Array(
3750 'asset_version_major',
3751 'asset_version_minor',
3752 'asset_version_micro',
3755 'asset_created_short',
3756 'asset_updated_short',
3757 'asset_created_readable',
3758 'asset_updated_readable',
3759 'asset_created_readabledate',
3760 'asset_updated_readabledate',
3761 'asset_created_readabletime',
3762 'asset_updated_readabletime',
3763 'asset_created_iso8601',
3764 'asset_updated_iso8601',
3765 'asset_created_rfc2822',
3766 'asset_updated_rfc2822',
3767 'asset_created_ical',
3768 'asset_updated_ical',
3769 'asset_created_by_name',
3770 'asset_updated_by_name',
3772 'asset_published_short',
3773 'asset_published_readable',
3774 'asset_published_readabledate',
3775 'asset_published_readabletime',
3776 'asset_published_iso8601',
3777 'asset_published_rfc2822',
3778 'asset_published_ical',
3779 'asset_published_by_name',
3780 'asset_status_changed',
3781 'asset_status_changed_short',
3782 'asset_status_changed_readable',
3783 'asset_status_changed_readabledate',
3784 'asset_status_changed_readabletime',
3785 'asset_status_changed_iso8601',
3786 'asset_status_changed_rfc2822',
3787 'asset_status_changed_ical',
3788 'asset_status_changed_by_name',
3792 'asset_thumbnail_url',
3793 'asset_thumbnail_caption',
3794 'asset_thumbnail_assetid',
3795 'asset_thumbnail_title',
3796 'asset_thumbnail_name',
3797 'asset_status_description',
3798 'asset_status_colour',
3802 foreach ($default_keywords as $keyword) {
3803 $keywords[$keyword] = translate($keyword);
3807 foreach ($this->vars as $name => $info) {
3809 if (!$attr->is_admin) {
3810 $keywords[
'asset_attribute_'.$name] = empty($attr->description) ?
'Asset Attribute: '.$name : $attr->description;
3839 return $replacement;
3862 if (empty($keyword))
return '';
3864 if (($keyword ==
'asset_contents') || (0 === strpos($keyword,
'globals_'))) {
3865 return "%$keyword%";
3869 $keyword = parse_keyword($keyword, $modifiers);
3870 $contextid = extract_context_modifier($modifiers);
3872 if ($contextid !== NULL) {
3877 if ((
int)$contextid !== $GLOBALS[
'SQ_SYSTEM']->getContextId()) {
3878 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
3879 $contexted_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id);
3882 $replacement = $contexted_asset->getKeywordReplacement($keyword);
3885 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $contexted_asset->id));
3887 unset($contexted_asset);
3888 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
3889 return $replacement;
3895 $replacement = NULL;
3896 $tmp_keyword = strtr($keyword,
'_',
' ');
3897 $tmp_keyword = ucwords($tmp_keyword);
3898 $tmp_keyword = preg_replace(
'/\s+/',
'', $tmp_keyword);
3899 $func_name =
'get'.$tmp_keyword.
'KeywordReplacement';
3903 $possible_func_name =
'';
3904 if (0 === strpos($keyword,
'asset_')) {
3906 $possible_tmp_keyword = substr($tmp_keyword, 5);
3907 if ($possible_tmp_keyword !=
'') {
3908 $possible_func_name =
'get'.$possible_tmp_keyword.
'KeywordReplacement';
3912 if (method_exists($this, $func_name)) {
3913 $replacement = $this->$func_name();
3914 }
else if (($possible_func_name !=
'') && method_exists($this, $possible_func_name)) {
3917 $replacement = $this->$possible_func_name();
3918 }
else if (strcmp(
'asset_assetid', $keyword) == 0) {
3919 $replacement = $this->id;
3920 }
else if (strcmp(
'asset_name', $keyword) == 0) {
3921 $replacement = $this->name;
3922 $replacement = str_replace(
'&',
'&', $replacement);
3923 }
else if (strcmp(
'asset_name_linked', $keyword) == 0) {
3924 $name = str_replace(
'&',
'&', $this->name);
3925 $replacement =
'<a href="'.$this->getURL().
'">'.$name.
'</a>';
3926 }
else if (strcmp(
'asset_short_name', $keyword) == 0) {
3927 $replacement = $this->short_name;
3928 $replacement = str_replace(
'&',
'&', $replacement);
3929 }
else if (strcmp(
'asset_type', $keyword) == 0) {
3930 $replacement = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->
type(),
'name');
3931 }
else if (strcmp(
'asset_type_icon', $keyword) == 0) {
3932 $replacement = sq_get_icon($GLOBALS[
'SQ_SYSTEM']->am->getAssetIconURL($this->type()), 16, 16,
'');
3933 }
else if (strcmp(
'asset_type_icon_url', $keyword) == 0) {
3934 $replacement = $GLOBALS[
'SQ_SYSTEM']->am->getAssetIconURL($this->
type());
3935 }
else if (0 === strpos($keyword,
'asset_attribute_')) {
3936 $attr_name = substr($keyword, strlen(
'asset_attribute_'));
3937 if (array_key_exists($attr_name, $this->vars)) {
3939 if (!is_null($attr) && !$attr->is_admin) {
3940 $replacement = $attr->getKeywordValue();
3943 preg_match(
'/(_([^_]*)){0,1}$/', $attr_name, $matches);
3944 if (!empty($matches[1])) {
3945 $attr_name = substr($attr_name, 0, (strlen($attr_name) - strlen($matches[1])));
3946 $format = $matches[2];
3948 if (!is_null($attr)) {
3949 $replacement = $attr->getKeywordValue($format);
3953 }
else if (substr($keyword, 0, 15) ==
'asset_metadata_') {
3954 $metadata_keyword = substr($keyword, 15);
3955 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3957 $current_context = $GLOBALS[
'SQ_SYSTEM']->getContextId();
3958 if ($current_context === NULL) {
3959 $current_context = 0;
3962 if (!isset($this->_tmp[
'mm_replacements'][$current_context])) {
3964 $this->_tmp[
'mm_replacements'][$current_context] = $mm->getMetadataFieldValues($this->
id);
3966 $additional_keyword =
'';
3967 $replacement = NULL;
3972 while (strlen($metadata_keyword) > 0) {
3973 $spaced_metadata_keyword = str_replace(
'_',
' ', $metadata_keyword);
3975 if (isset($this->_tmp[
'mm_replacements'][$current_context][$metadata_keyword]) === TRUE) {
3976 if ($additional_keyword !==
'') {
3977 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3978 $field_assetid = $mm->getFieldAssetIdFromName($this->
id, $metadata_keyword);
3980 if ($field_assetid !== FALSE) {
3981 $field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($field_assetid);
3982 $replacement = $field->getAdditionalKeywordReplacement($this->
id, $additional_keyword, NULL);
3983 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($field);
3987 $replacement = $this->_tmp[
'mm_replacements'][$current_context][$metadata_keyword];
3990 }
else if (isset($this->_tmp[
'mm_replacements'][$current_context][$spaced_metadata_keyword]) === TRUE) {
3995 if ($additional_keyword !==
'') {
3996 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3997 $field_assetid = $mm->getFieldAssetIdFromName($this->
id, $spaced_metadata_keyword);
3998 if ($field_assetid !== FALSE) {
3999 $field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($field_assetid);
4000 $replacement = $field->getAdditionalKeywordReplacement($this->
id, $additional_keyword, NULL);
4001 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($field);
4005 $replacement = $this->_tmp[
'mm_replacements'][$current_context][$spaced_metadata_keyword];
4011 if ($replacement !== NULL)
break;
4015 $underscore_pos = strrpos($metadata_keyword,
'_');
4016 if ($underscore_pos === FALSE)
break;
4018 if (strlen($additional_keyword) > 0) {
4019 $additional_keyword =
'_'.$additional_keyword;
4022 $additional_keyword = substr($metadata_keyword, $underscore_pos + 1).$additional_keyword;
4023 $metadata_keyword = substr($metadata_keyword, 0, $underscore_pos);
4027 if ($replacement === NULL) {
4028 $metadata_keyword = substr($keyword, 15);
4030 $related_assetids = $this->_tmp[
'mm_replacements'][$current_context];
4031 array_sort_by_length($related_assetids, FALSE, FALSE);
4033 foreach($related_assetids as $field_name => $related_assetid) {
4034 if (strpos($metadata_keyword, $field_name.
'_') !== FALSE) {
4035 $asset_keyword = substr($metadata_keyword, strlen($field_name)+1, strlen($metadata_keyword) - strlen($field_name));
4036 if ($GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($related_assetid)) {
4037 $related_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($related_assetid);
4038 $replacement = $related_asset->getKeywordReplacement($asset_keyword);
4039 $this->_tmp[
'mm_replacements'][$current_context][$metadata_keyword] = $replacement;
4047 if ($replacement === NULL) {
4048 unset($replacement);
4051 }
else if (0 === strpos($keyword,
'asset_charset')) {
4052 $replacement = ($this->charset) ? $this->charset : SQ_CONF_DEFAULT_CHARACTER_SET;
4054 }
else if (0 === strpos($keyword,
'asset_languages')) {
4055 $replacement = ($this->languages) ? $this->languages : SQ_CONF_DEFAULT_FRONTEND_LANGUAGE;
4057 }
else if (0 === strpos($keyword,
'asset_summary')) {
4058 $temp_assetid = substr($keyword, 14);
4059 $temp_assetid = trim($temp_assetid);
4060 $temp_asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($temp_assetid);
4061 if (!empty($temp_asset_info)) {
4062 $temp_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($temp_assetid);
4063 if (method_exists($temp_asset,
'getAssetSummary')) {
4064 $replacement = $temp_asset->getAssetSummary();
4066 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($temp_asset);
4068 }
else if (0 === strpos($keyword,
'asset_paint_layout_id')) {
4069 $replacement = $GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'SQ_PAINT_LAYOUT_ID', 0);
4070 if (empty($replacement)) {
4071 $url = strip_url(current_url(FALSE, TRUE));
4073 $replacement = $GLOBALS[
'SQ_SYSTEM']->am->getValueFromURL($url, $layout_name);
4077 if (empty($replacement) && $layout_name !=
'paint_layout::system::frontend') {
4078 $replacement = $GLOBALS[
'SQ_SYSTEM']->am->getValueFromURL($url,
'paint_layout::system::frontend');
4081 }
else if (0 === strpos($keyword,
'asset_workflow_')) {
4082 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
4084 if (!isset($this->_tmp[
'wfm_schema_workflows'])) {
4085 $schema_workflows = $wfm->getSchemaWorkflows($this->
id);
4086 $this->_tmp[
'wfm_schema_workflows'] = $schema_workflows;
4088 $schema_workflows = $this->_tmp[
'wfm_schema_workflows'];
4091 if (0 === strpos($keyword,
'asset_workflow_current_')){
4092 $workflow_keyword = substr($keyword, strlen(
'asset_workflow_current_'));
4093 $workflow_keyword_parts = explode(
':', $workflow_keyword);
4095 $schema_ids = Array();
4096 $wf_replacements = Array();
4098 if (isset($workflow_keyword_parts[1])) {
4099 $workflow_keyword = $workflow_keyword_parts[0];
4100 $schema_ids[] = $workflow_keyword_parts[1];
4102 $schema_ids = array_keys($schema_workflows);
4105 foreach($schema_ids as $schema_id) {
4107 if (empty($schema_workflows[$schema_id]))
continue;
4109 if (0 === strpos($workflow_keyword,
'step_')){
4111 if (empty($schema_workflows[$schema_id][
'steps']) || empty($schema_workflows[$schema_id][
'current_step']))
continue;
4113 $current_step = $wfm->getCurrentStep($schema_workflows[$schema_id]);
4114 switch ($workflow_keyword) {
4116 $wf_replacements[] = $current_step[
'step_name'];
4118 case 'step_start_time':
4119 $wf_replacements[] = date(
'd-m-Y H:i:s', $current_step[
'started']);
4121 case 'step_expiry_time':
4122 $wf_replacements[] = (!empty($current_step[
'expiry_time'])) ? date(
'd-m-Y H:i:s', $current_step[
'started'] + $current_step[
'expiry_time']) :
'';
4124 case 'step_conditions':
4125 $asset_names = Array();
4126 foreach (array_keys($current_step[
'conditions']) as $assetid){
4127 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
4128 if ($asset instanceof
User) {
4129 $asset_names[] = $asset->_getName();
4131 $asset_names[] = $asset->name;
4133 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
4136 $wf_replacements[] = implode(
', ', $asset_names);
4138 case 'step_condition_ids':
4139 $wf_replacements[] = implode(
', ', array_keys($current_step[
'conditions']));
4143 switch ($workflow_keyword) {
4145 $wf_replacements[] = date(
'd-m-Y H:i:s', $schema_workflows[$schema_id][
'started']);
4148 $wf_replacements[] = $schema_workflows[$schema_id][
'stream_name'];
4154 $replacement = implode(
', ', $wf_replacements);
4155 if (empty($replacement))
return NULL;
4158 $workflow_keyword = substr($keyword, strlen(
'asset_workflow_'));
4159 switch ($workflow_keyword) {
4160 case 'applied_schemas':
4161 $replacement = implode(
', ', array_keys($schema_workflows));
4164 return $replacement;
4168 }
else if (0 === strpos($keyword,
'asset_frontend_metadata')) {
4170 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
4171 $metadata_default_name =
'metadata.php';
4172 $metadata_basename = ($contextid === 0) ?
'metadata.php' :
'metadata.'.$contextid.
'.php';
4175 if (file_exists($this->data_path.
'/'.$metadata_basename)) {
4176 require $this->data_path.
'/'.$metadata_basename;
4177 }
else if (file_exists($this->data_path.
'/'.$metadata_default_name)) {
4178 require $this->data_path.
'/'.$metadata_default_name;
4180 $replacement = ob_get_clean();
4183 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
4184 $mm_keyword = $mm->generateKeywordReplacements($this, Array($keyword), FALSE);
4185 if (isset($mm_keyword[$keyword])) {
4186 $replacement = $mm_keyword[$keyword];
4191 if (count($modifiers) > 1) {
4196 return "%$keyword%";
4201 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
4203 return $replacement;
4219 if (empty($webpaths)) {
4223 $shortest_wp = $webpaths[0];
4225 foreach($webpaths as $webpath) {
4227 $wp_len = strlen($webpath);
4228 $shortest_wp_len = strlen($shortest_wp);
4230 if ($wp_len <= $shortest_wp_len) {
4231 $shortest_wp = ($wp_len == $shortest_wp_len) ? min($shortest_wp, $webpath) : $webpath;
4235 return $shortest_wp;
4314 $assetids[] = $this->id;
4317 foreach ($assetids as $key => $assetid) {
4318 $id_parts = explode(
':', $assetid);
4319 if (isset($id_parts[1])) {
4320 unset($assetids[$key]);
4327 if (empty($assetids))
return 0;
4330 $in_clauses = Array();
4331 foreach (array_chunk($assetids, 999) as $chunk) {
4332 $in_clauses[] =
' (assetid IN ('.implode(
', ', $chunk).
'))';
4334 $where =
'('.implode(
' OR ', $in_clauses).
')';
4338 $sql =
'SELECT MAX(updated)
4339 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast
4342 }
catch (Exception $e) {
4343 throw new Exception(
'Can not get updated time for asset due to the following database error:'.$e->getMessage());
4346 return (!is_null($most_recent)) ? strtotime($most_recent) : 0;
4365 if (!$this->
id)
return TRUE;
4366 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
4371 if ($this->status < SQ_STATUS_LIVE) {
4374 if (SQ_ROLLBACK_VIEW) {
4382 }
else if ($this->status & SQ_SC_STATUS_PENDING) {
4385 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
4386 $publishers = $wfm->whoCanPublish($this->
id);
4387 if (!empty($publishers) && in_array($GLOBALS[
'SQ_SYSTEM']->currentUserId(), $publishers)) {
4415 public function writeAccess($lock_type=
'', Array $assetids=Array(), $only_workflow=TRUE)
4417 if (SQ_ROLLBACK_VIEW)
return FALSE;
4419 if (!$this->
id)
return TRUE;
4420 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
4424 if ($this->status == SQ_STATUS_LIVE) {
4427 return $this->
checkAccess(SQ_PERMISSION_WRITE, $lock_type, $assetids, $only_workflow);
4446 if (SQ_ROLLBACK_VIEW)
return FALSE;
4448 if (!$this->
id || !empty($this->_tmp[__CLASS__.
'_in_create_cascading'])) {
4451 if (!$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
4455 $access = $this->
checkAccess(SQ_PERMISSION_ADMIN, $lock_type, $assetids);
4456 if ($access && $this->status == SQ_STATUS_LIVE) {
4472 return $GLOBALS[
'SQ_SYSTEM']->user->canAccessBackend();
4491 if (empty($lock_type) || $this->canLiveEdit($lock_type)) {
4492 return $this->
checkAccess(SQ_PERMISSION_WRITE, $lock_type);
4513 if (SQ_ROLLBACK_VIEW)
return FALSE;
4514 if (!$this->
id)
return TRUE;
4515 if (!($this->status & SQ_SC_STATUS_LIVE_EDIT)) {
4519 if (!empty($lock_type)) {
4520 if ($lock_type !=
'attributes') {
4521 $locks = $GLOBALS[
'SQ_SYSTEM']->am->getLockInfo($this->
id, $lock_type, TRUE);
4524 if (!in_array(
'attributes', array_keys($locks))) {
4530 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
4531 $schemas = $wfm->getSchemas($this->
id, TRUE);
4533 if (empty($schemas))
return TRUE;
4537 $wf_complete = $wfm->testPublish($this->
id, $GLOBALS[
'SQ_SYSTEM']->currentUserId());
4538 if ($wf_complete)
return TRUE;
4554 $public_userid = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
4555 return ($this->status >= SQ_STATUS_LIVE && $this->
_checkPermissionAccess(SQ_PERMISSION_READ, Array($public_userid)));
4577 public function checkAccess($perm, $lock_type, Array $assetids=Array(), $only_workflow=TRUE)
4579 if ($perm == SQ_PERMISSION_READ) {
4580 trigger_localised_error(
'SYS0272', E_USER_ERROR, __CLASS__, __FUNCTION__);
4582 if ($lock_type ==
'') {
4587 if (!empty($assetids))
return FALSE;
4589 $locks = $GLOBALS[
'SQ_SYSTEM']->am->getLockInfo($this->
id, $lock_type, TRUE);
4591 if (empty($locks))
return FALSE;
4593 foreach ($locks as $lock) {
4595 if (empty($lock) || $lock[
'userid'] != $GLOBALS[
'SQ_SYSTEM']->currentUserId()) {
4603 if (!($GLOBALS[
'SQ_PURGING_TRASH'] || $lock_type ==
'links')) {
4628 if ($this->status & SQ_SC_STATUS_ALL_APPROVED) {
4633 if ($this->status & SQ_STATUS_ARCHIVED) {
4655 if (empty($assetids)) {
4656 if (!$GLOBALS[
'SQ_SYSTEM']->userPublic()) {
4658 if ($GLOBALS[
'SQ_SYSTEM']->userRoot())
return TRUE;
4662 if ($GLOBALS[
'SQ_SYSTEM']->userSystemAdmin()) {
4668 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
4669 $assetids = $user->getUserGroups();
4670 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($user);
4672 $assetids[] = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
4675 if (!$GLOBALS[
'SQ_PURGING_TRASH']) {
4678 if ($this->status & SQ_SC_STATUS_PENDING) {
4679 if ($perm == SQ_PERMISSION_WRITE) {
4680 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
4681 $publishers = $wfm->whoCanPublish($this->
id);
4682 if (in_array($GLOBALS[
'SQ_SYSTEM']->currentUserId(), $publishers)) {
4692 if ($only_workflow)
return FALSE;
4697 $grants = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($this->
id, $perm, TRUE, TRUE, FALSE, FALSE, FALSE);
4698 $revokes = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($this->
id, $perm, FALSE, FALSE, FALSE, FALSE, FALSE);
4701 if (!empty($revokes)) {
4702 $revoked = array_intersect($assetids, $revokes);
4703 if (!empty($revoked))
return FALSE;
4709 $assetids[] = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
4711 $common = array_intersect($assetids, $grants);
4713 return (!empty($common));
4762 if (!is_null($design)) {
4763 assert_is_a($design,
'design');
4767 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', $asset->name));
4771 $current_protocol = current_protocol();
4773 if (!empty($valid_protocols) && !in_array($current_protocol, $valid_protocols)) {
4774 $new_url = (($current_protocol ==
'http') ?
'https' :
'http').
'://'.current_url(FALSE);
4775 do_redirect($new_url);
4778 if (!headers_sent()) {
4779 if ($asset->charset) {
4780 header(
'Content-type: text/html; charset='.$asset->charset);
4782 header(
'Content-type: text/html; charset='.SQ_CONF_DEFAULT_CHARACTER_SET);
4785 if ($asset->languages) {
4786 header(
'Content-language: '.$asset->languages);
4790 $original_asset = NULL;
4791 if (is_null($GLOBALS[
'SQ_SYSTEM']->frontend_asset) || $asset->id != $GLOBALS[
'SQ_SYSTEM']->frontend_asset->id) {
4792 $original_asset = $GLOBALS[
'SQ_SYSTEM']->frontend_asset;
4793 $GLOBALS[
'SQ_SYSTEM']->frontend_asset = &$asset;
4797 $url = strip_url(current_url(FALSE, TRUE));
4800 if (is_null($design)) {
4802 $result = $GLOBALS[
'SQ_SYSTEM']->am->getDesignFromURL($url, $design_name);
4806 if (empty($result) && $design_name !=
'design::system::frontend') {
4807 $result = $GLOBALS[
'SQ_SYSTEM']->am->getDesignFromURL($url,
'design::system::frontend');
4811 if (empty($result)) {
4812 $url = strip_url($asset->getUrl(), TRUE);
4813 $result = $GLOBALS[
'SQ_SYSTEM']->am->getDesignFromURL($url, $design_name);
4814 if (empty($result) && $design_name !=
'design::system::frontend') {
4815 $result = $GLOBALS[
'SQ_SYSTEM']->am->getDesignFromURL($url,
'design::system::frontend');
4822 if (!is_null($design) || $result) {
4823 if (is_null($design)) {
4825 $design = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($result[
'designid'], $result[
'type_code']);
4827 $design->paint($asset);
4833 if (!is_null($original_asset)) {
4834 $GLOBALS[
'SQ_SYSTEM']->frontend_asset = &$original_asset;
4848 if (!isset($this->_tmp[
'valid_protocols'])) {
4849 $protocol = current_protocol();
4852 $bind_vars = Array (
4853 'assetid' => $this->
id,
4854 'url' => strip_url(current_url(FALSE)),
4857 if (isset($result[0])) {
4861 }
catch (Exception $e) {
4862 throw new Exception(
'Unable to get valid protocols for asset: '.$this->
id.
' with this URL: '.strip_url(current_url(FALSE)).
' due to database error: '.$e->getMessage());
4865 $this->_tmp[
'valid_protocols'] = Array();
4866 if (is_array($res)) {
4867 foreach ($res as $protocol => $valid) {
4869 if (($this->force_secure ===
'1') && ($protocol ==
'http')) {
4873 if (($this->force_secure ===
'-') && ($protocol ==
'https')) {
4877 $this->_tmp[
'valid_protocols'][] = $protocol;
4882 return $this->_tmp[
'valid_protocols'];
4923 if (!empty($_GET[
'SQ_PAINT_LAYOUT_NAME'])) {
4924 $layout_name =
'paint_layout::user::'.$_GET[
'SQ_PAINT_LAYOUT_NAME'];
4925 }
else if (!empty($_SESSION[
'SQ_PAINT_LAYOUT_NAME'])) {
4927 $layout_name =
'paint_layout::user::'.$_SESSION[
'SQ_PAINT_LAYOUT_NAME'];
4928 }
else if (!empty($_GET[
'SQ_DESIGN_NAME'])) {
4930 $layout_name =
'paint_layout::user::'.$_GET[
'SQ_DESIGN_NAME'];
4931 }
else if (!empty($_SESSION[
'SQ_DESIGN_NAME'])) {
4932 $layout_name =
'paint_layout::user::'.$_SESSION[
'SQ_DESIGN_NAME'];
4934 $layout_name =
'paint_layout::system::frontend';
4936 return $layout_name;
4950 if (!empty($_GET[
'SQ_DESIGN_NAME'])) {
4951 $design_name =
'design::user::'.$_GET[
'SQ_DESIGN_NAME'];
4952 }
else if (!empty($_SESSION[
'SQ_DESIGN_NAME'])) {
4953 $design_name =
'design::user::'.$_SESSION[
'SQ_DESIGN_NAME'];
4955 $design_name =
'design::system::frontend';
4957 return $design_name;
4972 if (empty($layout_id)) {
4973 $layout_id = $GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'SQ_PAINT_LAYOUT_ID', 0);
4975 if (empty($layout_id)) {
4976 $url = strip_url(current_url(FALSE, TRUE));
4978 $layout_id = $GLOBALS[
'SQ_SYSTEM']->am->getValueFromURL($url, $layout_name);
4982 if (empty($layout_id) && $layout_name !=
'paint_layout::system::frontend') {
4983 $layout_id = $GLOBALS[
'SQ_SYSTEM']->am->getValueFromURL($url,
'paint_layout::system::frontend');
4988 $replacement = $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'SQ_PAINT_LAYOUT_ID', $layout_id);
4991 $switched_frontend = FALSE;
4994 if (isset($GLOBALS[
'SQ_SYSTEM']->frontend_asset) && $GLOBALS[
'SQ_SYSTEM']->frontend_asset->id !== $this->id) {
4995 $current_frontend_asset = &$GLOBALS[
'SQ_SYSTEM']->frontend_asset;
4996 $GLOBALS[
'SQ_SYSTEM']->frontend_asset = &$this;
4997 $switched_frontend = TRUE;
5000 $layout = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($layout_id);
5001 $layout->paint($this);
5003 if ($switched_frontend) {
5004 $GLOBALS[
'SQ_SYSTEM']->frontend_asset = &$current_frontend_asset;
5007 if (!is_null($replacement)) {
5008 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'SQ_PAINT_LAYOUT_ID', $replacement);
5010 $GLOBALS[
'SQ_SYSTEM']->unsetGlobalDefine(
'SQ_PAINT_LAYOUT_ID');
5032 $o = $GLOBALS[
'SQ_SYSTEM']->backend->out;
5033 $o->addHiddenField(
'asset_action',
'limbo');
5054 $o = $GLOBALS[
'SQ_SYSTEM']->backend->out;
5056 trigger_localised_error(
'SYS0245', E_USER_ERROR, current_url());
5074 $o->
addHiddenField(
'asset_action', (($this->
id) ?
'edit' :
'create'));
5075 if ($this->charset) $o->
setCharset($this->charset);
5076 $ei = $this->
getEI();
5077 if ($this->
id !== 0) {
5078 $owner = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id);
5082 $ei->paint($owner, $o, empty($this->
id));
5095 return str_replace(
':',
'_', str_replace(
' ',
'_', $this->
type().
'_'.$this->
id));
5112 $ei = $this->
getEI();
5114 switch ($_POST[
'asset_action']) {
5116 if ($ei->process($this, $o, TRUE)) {
5117 return (
bool) $this->
create($link);
5124 if ($this->
id !== 0) {
5125 $owner = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id);
5129 return $ei->process($owner, $o, FALSE);
5144 if (empty($this->_tmp[
'ei']) || get_class($this->_tmp[
'ei']) !=
'asset_edit_interface') {
5145 require_once SQ_INCLUDE_PATH.
'/asset_edit_interface.inc';
5148 return $this->_tmp[
'ei'];
5161 if (!isset($this->_tmp[
'edit_fns'])) {
5162 $class_name = $this->
type().
'_edit_fns';
5163 require_once SQ_SYSTEM_ROOT.
'/'.$GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->
type(),
'dir').
'/'.$class_name.
'.inc';
5164 $this->_tmp[
'edit_fns'] =
new $class_name();
5167 return $this->_tmp[
'edit_fns'];
5188 $href = $GLOBALS[
'SQ_SYSTEM']->am->getAssetBackendHref(Array($this->
id => $screen), $backend_page);
5189 return $href[$this->id];
5205 public function getURL($base_url=NULL, $ignore_rollback=FALSE, $base_contextid = NULL)
5207 return $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($this->
id, $base_url, $ignore_rollback, $base_contextid);
5220 return $GLOBALS[
'SQ_SYSTEM']->am->getURLs($this->
id);
5235 public function getHref($base_url=NULL, $ignore_rollback=FALSE)
5237 return $GLOBALS[
'SQ_SYSTEM']->am->getAssetHref($this->
id, $base_url, $ignore_rollback);
5250 return sq_web_path(
'data').
'/assets/'.$this->
type().
'/'.get_asset_hash($this->
id).
'/'.$this->id;
5263 if (!isset($this->_tmp[
'paths'])) {
5265 $where =
'assetid = :assetid';
5266 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
5268 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_path '.$where.
'
5269 ORDER BY sort_order';
5275 }
catch (Exception $e) {
5276 throw new Exception(
'Unable to get web paths for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
5279 $this->_tmp[
'paths'] = $result;
5283 return $this->_tmp[
'paths'];
5301 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
5302 $valid_paths = make_valid_web_paths(Array($path), $this->
id);
5305 if (!empty($parent_link[
'asset'])) {
5306 $valid_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($parent_link[
'asset'], $valid_paths, $this->
id, TRUE);
5326 $save_paths = Array();
5329 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
5330 $save_paths = make_valid_web_paths($paths, $this->
id ? $this->
id :
'');
5333 foreach ($paths as $orig_path) {
5334 if (preg_match(
'/^__/', $orig_path) || $orig_path == SQ_CONF_BACKEND_SUFFIX || $orig_path == SQ_CONF_LIMBO_SUFFIX || $orig_path == SQ_CONF_NOCACHE_SUFFIX) {
5341 if (!array_diff_assoc($save_paths, $current_paths) && !array_diff_assoc($current_paths, $save_paths)) {
5348 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
5351 $inserts = array_diff($save_paths, $current_paths);
5352 if (!empty($inserts)) {
5355 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_WEB_PATHS,
'', NULL,
'minor');
5356 for ($i = 0; $i < count($parents); $i++) {
5357 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parents[$i][
'majorid'], $parents[$i][
'major_type_code']);
5358 if (is_null($parent))
continue;
5359 $bad_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($parent, $inserts, $this->
id);
5360 if (!empty($bad_paths)) {
5361 trigger_localised_error(
'SYS0201', E_USER_WARNING, implode(
'", "', $bad_paths), $parent->name);
5362 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5368 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
5375 assetid = :assetid';
5381 }
catch (Exception $e) {
5382 throw new Exception(
'Unable to delete web paths for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
5385 foreach ($save_paths as $sort_order => $path) {
5406 }
catch (Exception $e) {
5407 throw new Exception(
'Unable to insert web paths for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
5411 unset($this->_tmp[
'paths']);
5412 unset($this->_tmp[
'lookups']);
5415 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
5416 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5419 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
5420 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5441 if (!isset($this->_tmp[
'lookups'])) {
5444 $sql =
'SELECT url, http, https, root_urlid
5445 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup ';
5446 $where =
'assetid = :assetid';
5447 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
5453 }
catch (Exception $e) {
5454 throw new Exception(
'Unable to get lookups for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
5457 $this->_tmp[
'lookups'] = $result;
5462 return $this->_tmp[
'lookups'];
5465 foreach ($this->_tmp[
'lookups'] as $data) {
5466 $ret_val[] = $data[$field];
5482 if (!isset($this->_tmp[
'design_lookups'])) {
5483 $this->_tmp[
'design_lookups'] = Array();
5487 $sql =
'SELECT l.url, lv.name, lv.value as designid
5488 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup l
5489 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup_value lv ON ((l.url LIKE lv.url || \'/%\')
5491 OR (l.url || \'/\' = lv.url))
5493 $where =
'l.assetid = :assetid
5494 AND lv.name LIKE '.MatrixDAL::quote(
'design::%');
5497 $order_by =
' ORDER BY lv.depth ASC';
5498 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'l');
5499 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'lv');
5505 }
catch (Exception $e) {
5506 throw new Exception(
'Unable to get design lookup information for asset: '.$this->
id.
' due to database error: '.$e->getMessage());
5509 foreach ($result as $row) {
5510 if (!isset($this->_tmp[
'design_lookups'][$row[
'url']])) {
5511 $this->_tmp[
'design_lookups'][$row[
'url']] = Array();
5513 $this->_tmp[
'design_lookups'][$row[
'url']][$row[
'name']] = $row[
'designid'];
5518 return $this->_tmp[
'design_lookups'];
5548 public function getLookupValues($inherited=NULL, $prefix=
'', $like_search=TRUE, $ignore_override=FALSE)
5556 $sql_default =
'SELECT lv.url, lv.name, lv.value, \'0\' as inhd, lv.depth
5557 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup l
5558 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup_value lv ON (l.url = lv.url)
5561 $include_override =
' OR (l.url || \'/\' = lv.url)';
5563 $where =
' l.assetid = :assetid';
5567 $sql_inherited =
'SELECT l.url, lv.name, lv.value, \'1\' as inhd, lv.depth
5568 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup l
5569 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup_value lv ON (l.url LIKE lv.url || \'/%\')
5572 if ($prefix !==
'') {
5573 $where .=
' AND lv.name '.((!$like_search) ?
'NOT' :
'').
' LIKE :lookup_value';
5576 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'l');
5577 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'lv');
5579 $sql_order_by =
' ORDER BY depth ASC ';
5582 if (!is_null($inherited) && $inherited) {
5583 $full_sql = $sql_inherited.$where.
' UNION '.$sql_default.$include_override.$where.$sql_order_by;
5585 else if ($ignore_override) {
5586 $full_sql = $sql_default.$where;
5589 $full_sql = $sql_default.$include_override.$where;
5594 if ($prefix !==
'') {
5598 }
catch (Exception $e) {
5599 throw new Exception(
'Unable to get lookup values for asset: '.$this->
id.
' due to database error: '.$e->getMessage());
5603 foreach ($result as $row) {
5604 if (!isset($ret_val[$row[
'url']])) {
5605 $ret_val[$row[
'url']] = Array();
5607 $ret_val[$row[
'url']][$row[
'name']] = Array(
'value' => $row[
'value'],
'inhd' => $row[
'inhd']);
5629 foreach ($lookup_values as $resource => $data) {
5630 foreach ($data as $name => $value) {
5631 if (strstr($layout_name,
'override::')) {
5632 if (preg_match(
'/.+\/$/', $resource)) {
5634 if ((str_replace(
'override::',
'', $layout_name) === $name) && ($layout_value === $value[
'value'])) {
5635 unset($lookup_values[$resource][$name]);
5639 if (preg_match(
'/.+\/{0}$/', $resource)) {
5641 if (($layout_name === $name) && ($layout_value === $value[
'value'])) {
5642 unset($lookup_values[$resource][$name]);
5649 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
5650 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
5653 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
5654 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5658 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
5659 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5661 return $lookup_values;
5683 if (!is_array($layouts))
return FALSE;
5684 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
5685 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
5689 foreach ($layouts as $layout_name => $assetid) {
5690 if (!empty($assetid)) {
5691 $layout = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
5694 $create_link = FALSE;
5695 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'paint_layout_page', TRUE, $layout_name);
5696 if (isset($link[
'minorid'])) {
5698 if ($link[
'minorid'] !== $assetid) {
5701 trigger_localised_error(
'CORE0283', E_USER_WARNING, $link[
'linkid'], $layout_name, $this->
id);
5702 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
5703 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5710 trigger_localised_error(
'CORE0284', E_USER_WARNING, $layout_name, $this->
id);
5711 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
5712 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5716 $create_link = TRUE;
5720 $create_link = TRUE;
5725 if (!$GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($this, $layout, SQ_LINK_NOTICE, $layout_name)) {
5726 trigger_localised_error(
'CORE0285', E_USER_WARNING, $layout->id, $layout_name, $this->id);
5727 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
5728 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5736 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
5737 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5741 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
5742 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
5763 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
5766 unset($this->_tmp[
'lookups']);
5767 unset($this->_tmp[
'design_lookups']);
5768 $GLOBALS[
'SQ_SYSTEM']->am->clearLookupsCache($this->
id);
5770 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
5771 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
5772 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
5777 $sql =
'SELECT l.url, l.http, l.https, u.urlid
5778 FROM sq_ast_lookup l
5779 LEFT OUTER JOIN sq_ast_url u ON l.root_urlid = u.urlid
5780 LEFT OUTER JOIN sq_ast_path p ON l.assetid = p.assetid
5781 WHERE l.assetid = :assetid
5782 ORDER BY p.sort_order DESC';
5788 }
catch (Exception $e) {
5789 throw new Exception(
'Unable to get old lookups for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
5793 $this->_tmp[
'old_urls'] = $old_urls;
5794 $parameter[
'old_urls'] = $old_urls;
5797 $our_lookup_values = $this->
getLookupValues(FALSE, $prefix=
'design::', FALSE);
5800 $tmp_old_urls = Array();
5802 $current_urls = Array();
5803 $old_web_paths = Array();
5804 foreach ($old_urls as $url_data) {
5805 $url = $url_data[
'url'];
5806 $current_urls[] = $url;
5807 if ((strpos($url,
'__data') === FALSE) && ($url_data[
'urlid']) && !empty($paths)) {
5809 $url_lineage = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromURL(NULL, $url);
5810 $url_assetids = Array();
5811 foreach ($url_lineage as $url_lineage_item) {
5812 $url_assetids[] = $url_lineage_item[
'assetid'];
5815 $parent_url = substr($url, 0, strrpos($url,
'/'));
5816 $web_path = substr($url, strrpos($url,
'/') + 1);
5818 $tmp_old_urls[] = Array(
5820 'parent_url' => $parent_url,
5821 'web_path' => $web_path,
5822 'lineage' => $url_assetids,
5824 $old_web_paths[] = $web_path;
5827 $old_web_paths = array_unique($old_web_paths);
5831 $old_to_new = array_values(array_diff($old_web_paths, $paths));
5832 $new_to_old = array_values(array_diff($paths, $old_web_paths));
5834 $web_path_changes = Array();
5836 if ((count($old_to_new) == 1) && (count($new_to_old) == 1)) {
5837 $web_path_changes[$old_to_new[0]] = $new_to_old[0];
5838 }
else if ((count($old_to_new) > 1) && (count($new_to_old) > 1)) {
5841 for ($i = 0; $i < min(count($old_to_new), count($new_to_old)); $i++) {
5842 $web_path_changes[$old_to_new[$i]] = $new_to_old[$i];
5846 if (!empty($current_urls)) {
5848 $url_chunks = array_chunk($current_urls, 1000, TRUE);
5849 foreach ($url_chunks as $url_chunk) {
5852 'urls' => $url_chunk,
5855 }
catch (Exception $e) {
5856 throw new Exception(
'Unable to delete URLs from lookup value table due to database error: '.$e->getMessage());
5861 for ($i=0; $i<count($current_urls); $i++) {
5862 $current_urls[$i] .=
'/';
5864 $url_chunks = array_chunk($current_urls, 1000, TRUE);
5865 foreach ($url_chunks as $url_chunk) {
5868 'urls' => $url_chunk,
5871 }
catch (Exception $e) {
5872 throw new Exception(
'Unable to delete URLs with override values from lookup value table due to database error: '.$e->getMessage());
5877 $bind_vars = Array(
'assetid' => $this->
id);
5879 }
catch (Exception $e) {
5880 throw new Exception(
'Unable to delete lookup information for asset: '.$this->
id.
' due to database error: '.$e->getMessage());
5884 if (!empty($paths)) {
5886 $num_paths = count($paths);
5888 $our_design_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE,
'design', FALSE);
5889 $our_designs = Array();
5890 foreach ($our_design_links as $link) {
5891 if (preg_match(
'/^design::(system|user)::.*$/', $link[
'value'])) {
5892 $our_designs[$link[
'value']] = Array(
5893 'value' => $link[
'minorid'],
5899 $override_designs = Array();
5900 foreach ($our_design_links as $link) {
5901 if (preg_match(
'/^override::design::(system|user)::.*$/', $link[
'value'])) {
5902 $name = preg_replace(
'/^override::(.*)$/',
'$1', $link[
'value']);
5903 $override_designs[$name] = Array(
5904 'value' => $link[
'minorid'],
5908 unset($our_design_links);
5910 $our_layout_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE,
'paint_layout_page', FALSE);
5912 foreach ($our_layout_links as $link) {
5913 if (preg_match(
'/^paint_layout::(system|user)::.*$/', $link[
'value'])) {
5914 $layouts[$link[
'value']] = Array(
5915 'value' => $link[
'minorid'],
5921 $override_layouts = Array();
5922 foreach ($our_layout_links as $link) {
5923 if (preg_match(
'/^override::paint_layout::system::.*$/', $link[
'value'])) {
5924 $name = preg_replace(
'/^override::(.*)$/',
'$1', $link[
'value']);
5925 $override_layouts[$name] = Array(
5926 'value' => $link[
'minorid'],
5931 unset($our_layout_links);
5934 $edit_layouts = Array();
5935 foreach($our_edit_layouts as $layout_url => $layouts) {
5936 foreach($layouts as $name => $layout_data) {
5937 if (!isset($edit_layouts[$name])) {
5938 $edit_layouts[$name] = Array(
5939 'value' => $layout_data[
'value'],
5944 unset($our_edit_layouts);
5946 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_WEB_PATHS,
'', NULL,
'minor');
5948 $done_urls = Array();
5949 $done_parents = Array();
5950 for ($i = 0; $i < count($parents); $i++) {
5951 if (in_array($parents[$i][
'majorid'], $done_parents)) {
5954 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parents[$i][
'majorid'], $parents[$i][
'major_type_code']);
5955 if (is_null($parent) || !is_object($parent)) {
5958 $done_parents[] = $parent->id;
5960 $parent_urls = $parent->getLookups();
5962 for ($j = 0, $num_parent_urls = count($parent_urls); $j < $num_parent_urls; $j++) {
5964 for ($k = 0; $k < $num_paths; $k++) {
5965 $new_url = $parent_urls[$j][
'url'].
'/'.$paths[$k];
5966 if (isset($done_urls[$new_url]))
continue;
5969 $site_url_info = $GLOBALS[
'SQ_SYSTEM']->am->getRootURL($new_url);
5971 $site_https = isset($site_url_info[
'https']) ? $site_url_info[
'https'] : 0;
5972 $site_http = isset($site_url_info[
'http']) ? $site_url_info[
'http'] : 0;
5974 $https = ($this->force_secure ===
'-') ?
'0' : $site_https;
5975 $http = ($this->force_secure ===
'1') ?
'0' : $site_http;
5977 if (!$http && !$https) {
5978 $https = $site_https;
5983 if (!$http && !$https) {
5988 $sql =
'SELECT assetid FROM sq_ast_lookup WHERE url = :new_url';
5989 $existing_asset_with_url_id = NULL;
5994 }
catch (Exception $e) {
5995 throw new Exception(
'Cannot check if another asset is already using URL "'.$new_url.
'": '.$e->getMessage());
5997 if (!empty($existing_asset_with_url_id)) {
5999 $existing_asset_with_url_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($existing_asset_with_url_id);
6000 trigger_localised_error(
'CORE0081', E_USER_WARNING, $new_url, $existing_asset_with_url_info[$existing_asset_with_url_id[0]][
'name'], $existing_asset_with_url_id[0]);
6001 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
6002 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
6007 $bind_vars = Array (
6009 'assetid' => $this->
id,
6012 'root_urlid' => $parent_urls[$j][
'root_urlid'],
6015 }
catch (Exception $e) {
6016 throw new Exception(
'Unable to insert lookups for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
6019 $done_urls[] = $new_url;
6022 $url_lineage = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromURL(NULL, $parent_urls[$j][
'url']);
6023 $new_url_assetids = Array();
6024 foreach ($url_lineage as $url_lineage_item) {
6025 $new_url_assetids[] = $url_lineage_item[
'assetid'];
6027 $new_url_assetids[] = $this->id;
6030 $lookup_values = Array();
6032 $override_lookup_values = Array();
6035 foreach ($tmp_old_urls as $tmp_old_url) {
6036 if ($tmp_old_url[
'url'] == $new_url) {
6038 $lookup_values = isset($our_lookup_values[$tmp_old_url[
'url']]) ? $our_lookup_values[$tmp_old_url[
'url']] : Array();
6040 $override_lookup_values = isset($our_lookup_values[$tmp_old_url[
'url'].
'/']) ? $our_lookup_values[$tmp_old_url[
'url'].
'/'] : Array();
6042 }
else if (($tmp_old_url[
'parent_url'] == $parent_urls[$j][
'url']) && ($tmp_old_url[
'web_path'] == $paths[$k])) {
6044 $lookup_values = isset($our_lookup_values[$tmp_old_url[
'url']]) ? $our_lookup_values[$tmp_old_url[
'url']] : Array();
6046 $override_lookup_values = isset($our_lookup_values[$tmp_old_url[
'url'].
'/']) ? $our_lookup_values[$tmp_old_url[
'url'].
'/'] : Array();
6048 }
else if ($tmp_old_url[
'parent_url'] == $parent_urls[$j][
'url']) {
6052 if (isset($web_path_changes[$tmp_old_url[
'web_path']]) && $web_path_changes[$tmp_old_url[
'web_path']] == $paths[$k]) {
6054 $lookup_values = isset($our_lookup_values[$tmp_old_url[
'url']]) ? $our_lookup_values[$tmp_old_url[
'url']] : Array();
6056 $override_lookup_values = isset($our_lookup_values[$tmp_old_url[
'url'].
'/']) ? $our_lookup_values[$tmp_old_url[
'url'].
'/'] : Array();
6060 $bind_vars = Array (
6061 'url' => $tmp_old_url[
'url'].
'%',
6062 'name' =>
'paint_layout::%',
6065 }
catch (Exception $e) {
6066 throw new Exception(
'Unable to get paint layouts for URL pattern: '.$tmp_old_url[
'url'].
'%'.
' due to database error: '.$e->getMessage());
6069 foreach ($applied_layout as $key => $old_layout_url) {
6070 $new_layout_url = str_replace($tmp_old_url[
'url'], $new_url, $old_layout_url);
6072 $bind_vars = Array (
6073 'seturl' => $new_layout_url,
6074 'whereurl' => $old_layout_url,
6077 }
catch (Exception $e) {
6078 throw new Exception(
'Unable to update lookup value table for existing URL: '.$old_layout_url.
' with new URL: '.$new_layout_url.
' due to database error: '.$e->getMessage());
6087 foreach ($our_designs as $name => $data) {
6088 $lookup_values[$name] = $data;
6090 foreach ($override_designs as $name => $data) {
6091 $override_lookup_values[$name] = $data;
6095 foreach ($layouts as $name => $data) {
6096 if (!in_array($name, array_keys($lookup_values))) {
6097 $lookup_values[$name] = $data;
6100 foreach ($override_layouts as $name => $data) {
6101 if (!in_array($name, array_keys($override_lookup_values))) {
6102 $override_lookup_values[$name] = $data;
6107 foreach($edit_layouts as $name => $data) {
6108 if (!in_array($name, array_keys($lookup_values))) {
6109 $lookup_values[$name] = $data;
6114 $exploded_url = explode(
'/', $new_url);
6115 $page_depth = count($exploded_url)-1;
6117 foreach ($lookup_values as $name => $data) {
6119 $bind_vars = Array (
6124 if (isset($result[0])) {
6125 $result = $result[0];
6127 }
catch (Exception $e) {
6128 throw new Exception(
'Unable to get lookup value URL for specified URL: '.$new_url.
' due to database error: '.$e->getMessage());
6133 if (empty($result)) {
6135 $bind_vars = Array (
6138 'value' => $data[
'value'],
6139 'depth' => $page_depth,
6142 }
catch (Exception $e) {
6143 throw new Exception(
'Unable to insert new lookup value for specified URL: '.$new_url.
' due to database error: '.$e->getMessage());
6147 $bind_vars = Array (
6148 'value' => $data[
'value'],
6153 }
catch (Exception $e) {
6154 throw new Exception(
'Unable to update lookup value for specified URL: '.$new_url.
' due to database error: '.$e->getMessage());
6161 foreach ($override_lookup_values as $name => $data) {
6163 $bind_vars = Array (
6164 'url' => $new_url.
'/',
6168 if (isset($result[0])) {
6169 $result = $result[0];
6171 }
catch (Exception $e) {
6172 throw new Exception(
'Unable to get lookup value URL for specified URL: '.$new_url.
' due to database error: '.$e->getMessage());
6177 if (empty($result)) {
6179 $bind_vars = Array (
6180 'url' => $new_url.
'/',
6182 'value' => $data[
'value'],
6183 'depth' => $page_depth+1,
6186 }
catch (Exception $e) {
6187 throw new Exception(
'Unable to insert new lookup value for specified URL: '.$new_url.
' due to database error: '.$e->getMessage());
6191 $bind_vars = Array (
6192 'value' => $data[
'value'],
6197 }
catch (Exception $e) {
6198 throw new Exception(
'Unable to update lookup value for specified URL: '.$new_url.
' due to database error: '.$e->getMessage());
6211 $msg = $ms->newMessage();
6212 $msg->subject =
'Asset Lookups Updated';
6213 $msg->type =
'asset.lookups.updated';
6216 'asset_name' => $this->name,
6218 $msg->replacements = $msg_reps;
6219 $msg->parameters[
'assetid'] = $this->id;
6222 if (!empty($old_urls)) {
6223 if ($auto_add_remaps) {
6224 $rm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'remap_manager');
6228 if (count($done_urls) > 0) {
6229 foreach ($old_urls as $url_data) {
6230 $old_url = $url_data[
'url'];
6234 $closest_url = NULL;
6235 $most_bits_matched = -1;
6237 foreach ($done_urls as $new_url) {
6238 $new_url = strip_url($new_url, TRUE);
6239 $new_url_bits = explode(
'/', $new_url);
6240 $old_url_bits = explode(
'/', $old_url);
6242 for ($bits = 0; $bits < count($old_url_bits); $bits++) {
6243 if ((
string)$old_url_bits[$bits] !== (string)$new_url_bits[$bits]) {
6248 if ($bits > $most_bits_matched) {
6249 $closest_url = $new_url;
6250 $most_bits_matched = $bits;
6257 if (!in_array($old_url, $done_urls)) {
6259 foreach (explode(
"\n", SQ_CONF_SYSTEM_ROOT_URLS) as $root_url) {
6260 $data_url = $root_url.
'/__data';
6261 if (substr($old_url, 0, strlen($data_url)) == $data_url) {
6265 if ($url_data[
'http']) {
6266 $rm->addRemapURL(
'http://'.$old_url,
'http://'.$closest_url);
6268 if ($url_data[
'https']) {
6269 $rm->addRemapURL(
'https://'.$old_url,
'https://'.$closest_url);
6279 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
6280 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
6283 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
6284 $em->broadcastEvent($this,
'LookupsUpdated', Array(
'asset_name' => $this->name));
6285 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_lookups_updated', $this, $parameter);
6312 trigger_localised_error(
'SYS0265', E_USER_WARNING, $this->name, $this->
id);
6317 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
6318 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
6331 assetid = :assetid_1)
6338 assetid = :assetid_2)
6345 }
catch (Exception $e) {
6346 throw new Exception(
'Unable to delete lookup values for asset: '.$this->
id.
' due to database error: '.$e->getMessage());
6351 foreach ($values as $url => $values_data) {
6354 foreach ($lookups as $lookup_url) {
6355 if ($url === $lookup_url) {
6358 }
else if ($url === $lookup_url.
'/') {
6363 if (!$valid_url)
continue;
6364 if (empty($values_data))
continue;
6367 $exploded_url = explode(
'/', $url);
6368 $page_depth = count($exploded_url)-1;
6370 foreach ($values_data as $value_name => $value_data) {
6372 $bind_vars = Array (
6374 'name' => $value_name,
6375 'value' => $value_data[
'value'],
6376 'depth' => $page_depth,
6379 }
catch (Exception $e) {
6380 throw new Exception(
'Unable to insert new lookup value for specified URL: '.$url.
' due to database error: '.$e->getMessage());
6385 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
6386 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
6401 return get_status_description($this->status);
6416 return '#'.get_status_colour($this->status);
6433 $replacements = Array();
6434 $keyword_list = extract_keywords($string);
6435 if (empty($keyword_list) || !is_array($keyword_list)) {
6439 foreach ($keyword_list as $keyword) {
6443 replace_keywords($string, $replacements);
6484 if (!is_array($tasks)) $tasks = Array($tasks);
6485 if (!isset($this->_tmp[
'fast_track'])) $this->_tmp[
'fast_track'] = Array();
6487 foreach($tasks as $task) {
6490 if (!isset($this->_tmp[
'fast_track'][$task.
'_assetids']) || !isset($this->_tmp[
'fast_track'][$task]) || !$this->_tmp[
'fast_track'][$task]) {
6491 $this->_tmp[
'fast_track'][$task.
'_assetids'] = Array();
6494 $this->_tmp[
'fast_track'][$task] = TRUE;
6512 if (!is_array($tasks)) $tasks = Array($tasks);
6513 if (!isset($this->_tmp[
'fast_track'])) $this->_tmp[
'fast_track'] = Array();
6515 foreach($tasks as $task) {
6516 $this->_tmp[
'fast_track'][$task] = FALSE;
6536 if (isset($this->_tmp[
'fast_track'][$task]) && $this->_tmp[
'fast_track'][$task]) {
6538 if (!is_null($assetid)) {
6539 $this->_tmp[
'fast_track'][$task.
'_assetids'][] = $assetid;
6560 return !empty($this->_tmp[
'fast_track'][$task.
'_assetids']) ? $this->_tmp[
'fast_track'][$task.
'_assetids'] : Array();
6573 $asset_url = $this->
getURL();
6574 if (empty($asset_url)) {
6575 $dependant_parents = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($this->
id,
'', TRUE, FALSE);
6577 $dependant_parent = isset($dependant_parents[0]) ? $GLOBALS[
'SQ_SYSTEM']->am->getAsset($dependant_parents[0]) : NULL;
6578 if (!is_null($dependant_parent)) {
6579 $asset_url = $dependant_parent->getURL();
6580 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($dependant_parent);