18 define(
'SQ_TRIG_TREE_PROPAGATE',
'01');
19 define(
'SQ_TRIG_TREE_NO_PROPAGATE',
'00');
22 define(
'SQ_TRIG_STATUS_ACTIVE',
'1');
23 define(
'SQ_TRIG_STATUS_INACTIVE',
'0');
24 define(
'SQ_TRIG_STATUS_DEFAULT', SQ_TRIG_STATUS_INACTIVE);
27 define(
'SQ_TRIG_RESULT_SUCCESS', 1);
28 define(
'SQ_TRIG_RESULT_FALSE', -1);
29 define(
'SQ_TRIG_RESULT_INVALID', -2);
30 define(
'SQ_TRIG_RESULT_FAILURE', 0);
32 require_once SQ_INCLUDE_PATH.
'/asset.inc';
33 require_once SQ_CORE_PACKAGE_PATH.
'/interfaces/bridge/bridge.inc';
34 require_once
'hash.inc';
36 register_implementation(
'trigger_manager',
'bridge');
68 $this->
Asset($assetid);
107 require_once SQ_CORE_PACKAGE_PATH.
'/system/system_asset_fns.inc';
108 if (!system_asset_fns_create_pre_check($this)) {
112 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
113 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
115 if ($linkid = parent::create($link)) {
116 if (!system_asset_fns_create_cleanup($this)) {
122 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
124 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
127 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
144 $tm_links[SQ_LINK_TYPE_2][
'trigger'] = Array(
146 'exclusive' => FALSE,
178 return $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->
type(),
'name');
193 $name = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type,
'name');
209 return $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type,
'description');
230 function getAsset($shadowid, $type_code=
'', $mute_errors=FALSE)
236 if (empty($type_code)) $type_code =
'trigger';
238 $id_parts = explode(
':', $shadowid);
239 $id_part = $id_parts[count($id_parts)-1];
242 if(is_numeric($id_part)){
243 if (!empty($id_part) && $type_code ==
'trigger') {
247 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'trigger');
248 $asset =
new Trigger($this->
id, $id);
250 $asset->short_name = ($asset->vars[
'active'][
'value'] ==
'1') ? $asset->vars[
'name'][
'value'] : $asset->vars[
'name'][
'value'].
' (disabled)';
251 $asset->name = ($asset->vars[
'active'][
'value'] ==
'1') ? $asset->vars[
'name'][
'value'] : $asset->vars[
'name'][
'value'].
' (disabled)';
252 $asset->status = ($asset->vars[
'active'][
'value'] ==
'1') ? SQ_STATUS_LIVE : SQ_STATUS_UNDER_CONSTRUCTION;
255 if (empty($asset->id)) $asset = NULL;
260 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'trigger_folder');
262 $asset->status = SQ_STATUS_UNDER_CONSTRUCTION;
263 $asset->short_name = $id_part;
285 foreach ($triggers as $trigger) {
287 $my_result = &$results;
289 if(empty($trigger[
'category']) || !preg_match(
'/^[a-zA-Z][a-zA-Z0-9_\- ]*(\/[a-zA-Z][a-zA-Z0-9_\- ]*)*$/',$trigger[
'category'])){
293 $categories = explode(
'/',$trigger[
'category']);
294 foreach ($categories as $i => $cate) {
295 $my_result = &$my_result[$cate];
299 $my_result [] = $trigger;
319 $id_parts = explode(
':', $assetid);
320 array_shift($id_parts);
323 $new_assetid = implode(
':', $id_parts);
324 if(count($id_parts) == 0 || !array_key_exists($id_parts[0],$trigger_tree)){
327 else if(count($id_parts)==1) {
328 return $trigger_tree[$id_parts[0]];
349 $links_unsorted = Array();
351 $sort_index = Array();
353 if (!isset($trigger_tree) || !is_array($trigger_tree))
return NULL;
354 foreach ($trigger_tree as $cate => $trigger) {
358 if(is_numeric($cate)){
362 $link[
'num_kids'] = 0;
363 $link[
'accessible'] = 1;
365 $link[
'majorid'] = $this->id;
367 $link[
'minorid'] = implode(
':', Array($this->
id, $trigger[
'id']));
368 $link[
'assetid'] = implode(
':', Array($this->
id, $trigger[
'id']));
369 $link[
'minor_type_code'] =
'trigger';
370 $link[
'type_code'] =
'trigger';
371 $link[
'linkid'] = implode(
':', Array($this->
id, $trigger[
'id']));
374 $link[
'name'] = $trigger[
'name'];
375 $link[
'short_name'] = $trigger[
'active'] ? $trigger[
'name'] : $trigger[
'name'].
' (disabled)';
376 $link[
'status'] = $trigger[
'active'] ? SQ_STATUS_LIVE : SQ_STATUS_UNDER_CONSTRUCTION;
377 $link[
'sort_order'] = NULL;
378 $link[
'link_type'] = SQ_LINK_TYPE_1;
380 $link[
'is_dependant'] = 0;
382 $sort_index [
'trigger'][] = $link[
'name'];
383 $links_unsorted[
'trigger'][] = $link;
386 else if(isset ($cate) && !empty($cate)) {
390 $link[
'num_kids'] = -1;
391 $link[
'accessible'] = 1;
393 $link[
'majorid'] = $parentid;
394 $link[
'minorid'] = implode(
':', Array($parentid, $cate));
395 $link[
'assetid'] = implode(
':', Array($parentid, $cate));
396 $link[
'minor_type_code'] =
'trigger_folder';
397 $link[
'type_code'] =
'trigger_folder';
399 $link[
'linkid'] = implode(
':', Array($parentid, $cate));
402 $link[
'name'] = $cate;
403 $link[
'short_name'] = $cate;
404 $link[
'status'] = SQ_STATUS_UNDER_CONSTRUCTION;
405 $link[
'sort_order'] = NULL;
406 $link[
'link_type'] = SQ_LINK_TYPE_1;
408 $link[
'is_dependant'] = 0;
410 $sort_index [
'folder'][] = $link[
'name'];
411 $links_unsorted [
'folder'][] = $link;
421 if(!empty($sort_index)){
428 foreach(array_keys($sort_index) as $type){
429 asort($sort_index[$type]);
430 foreach ($sort_index[$type] as $index => $name) {
432 $links[] = $links_unsorted[$type][$index];
453 if(!isset($linked_triggers))
return NULL;
476 $asset_info = Array();
478 $id_parts = explode(
':', $assetid);
479 $id_part = $id_parts[count($id_parts)-1];
480 if (empty($id_part))
return $asset_info;
483 if(is_numeric($id_part)){
485 if (empty($trigger))
return $asset_info;
487 $asset_info[
'assetid'] = $assetid;
488 $asset_info[
'name'] = $trigger[
'active'] ? $trigger[
'name'] : $trigger[
'name'].
' (disabled)';
489 $asset_info[
'short_name'] = $trigger[
'active'] ? $trigger[
'name'] : $trigger[
'name'].
' (disabled)';
490 $asset_info[
'version'] = $this->version;
491 $asset_info[
'status'] = $trigger[
'active'] ? SQ_STATUS_LIVE : SQ_STATUS_UNDER_CONSTRUCTION;
492 $asset_info[
'type_code'] =
'trigger';
493 $asset_info[
'num_kids'] = 0;
494 $asset_info[
'accessible'] = 1;
495 $asset_info[
'url'] =
'';
496 $asset_info[
'web_path'] =
'';
500 $asset_info[
'assetid'] = $id_part;
501 $asset_info[
'name'] = $id_part;
502 $asset_info[
'short_name'] = $id_part;
504 $asset_info[
'status'] = SQ_STATUS_UNDER_CONSTRUCTION;
505 $asset_info[
'type_code'] =
'folder';
507 $asset_info[
'num_kids'] = -1;
508 $asset_info[
'accessible'] = 1;
509 $asset_info[
'url'] =
'';
510 $asset_info[
'web_path'] =
'';
540 function getLinks($assetid, $link_types, $type_code=
'', $strict_type_code=TRUE, $side_of_link=
'major', $sort_by=NULL, $dependant=NULL, $exclusive=NULL)
542 $id_parts = explode(
':', $assetid);
544 $id_part = $id_parts[count($id_parts)-1];
546 if (empty($id_part) || is_numeric($id_part))
return Array();
579 function getParents($assetid, $type_code=
'', $strict_type_code=TRUE)
606 function getChildren($assetid, $type_code=
'', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL)
650 function getPermission($assetid, $permission, $granted=NULL, $and_greater=TRUE, $expand_groups=FALSE, $all_info=FALSE)
707 function getAssetInfo($assetids, $type_code=Array(), $strict_type_code=TRUE, $field=
'')
709 $info_array = Array();
711 foreach ($assetids as $id) {
713 $GLOBALS[
'SQ_SYSTEM']->am->setPermission($id, $GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user'), SQ_PERMISSION_READ, 0, TRUE, TRUE);
714 $id_parts = explode(
':', $id);
716 $id_part = $id_parts[count($id_parts)-1];
717 if (is_null($id_part))
continue;
719 if(is_numeric($id_part)){
723 if (empty($trigger_info))
continue;
725 $info_array[$id][
'assetid'] = $id;
726 $info_array[$id][
'name'] = $trigger_info[
'name'];
727 $info_array[$id][
'short_name'] = $trigger_info[
'active'] ? $trigger_info[
'name'] : $trigger_info[
'name'].
' (disabled)';
728 $info_array[$id][
'version'] = $this->version;
729 $info_array[$id][
'status'] = $this->status;
730 $info_array[$id][
'type_code'] =
'trigger';
731 $info_array[$id][
'num_kids'] = 0;
732 $info_array[$id][
'accessible'] = 1;
733 $info_array[$id][
'url'] =
'';
734 $info_array[$id][
'web_path'] =
'';
736 if (!empty($field)) {
737 $info_array[$id] = array_get_index($info_array[$id], $field);
742 $info_array[$id][
'assetid'] = $id;
743 $info_array[$id][
'name'] = $id_part;
744 $info_array[$id][
'short_name'] = $id_part;
745 $info_array[$id][
'version'] = $this->version;
746 $info_array[$id][
'status'] = $this->status;
747 $info_array[$id][
'type_code'] =
'trigger_folder';
748 $info_array[$id][
'num_kids'] = -1;
749 $info_array[$id][
'force_secure'] =$this->force_secure;
750 $info_array[$id][
'accessible'] = 1;
751 $info_array[$id][
'url'] =
'';
752 $info_array[$id][
'web_path'] =
'';
800 function getLink($assetid, $link_type=NULL, $type_code=
'', $strict_type_code=TRUE, $value=NULL, $side_of_link=
'major', $exclusive=NULL)
821 $link_parts = explode(
':', $linkid);
822 $trigger_id = $link_parts[count($link_parts)-1];
823 if (is_null($trigger_id))
return NULL;
826 if(is_numeric($trigger_id)){
831 'majorid' => $this->
id,
832 'minorid' => $trigger_id,
833 'link_type' => SQ_LINK_TYPE_1,
834 'major_type_code' =>
'trigger_manager',
835 'minor_type_code' =>
'trigger',
837 'linkid' => $this->
id.
':'.$trigger_id,
838 'sort_order' => $trigger_info[
'id'],
847 foreach($link_parts as $node){
848 $parent_parts [] = $node;
850 array_pop($parent_parts);
851 $parent_id = implode(
':',$parent_parts);
855 'majorid' => $parent_id,
856 'minorid' => $trigger_id,
857 'link_type' => count($parent_parts) == 1 ?
'trigger_manager' :
'trigger_folder',
858 'minor_type_code' =>
'trigger_folder',
860 'linkid' => $trigger_id,
861 'sort_order' => NULL,
896 function countLinks($assetid, $side_of_link=
'major', $link_types=0, $type_code=
'', $strict_type_code=TRUE, $ignore_linkid=0)
923 function getLinkByAsset($assetid, $other_assetid, $link_types=NULL, $value=NULL, $side_of_link=
'major', $force_array=FALSE, $dependant=NULL, $exclusive=NULL)
960 function updateLink($linkid, $link_type=NULL, $value=NULL, $sort_order=NULL)
980 $link_parts = explode(
':', $linkid);
982 $trigger_id = $link_parts[count($link_parts)-1];
983 if (is_null($trigger_id))
return FALSE;
986 if (is_numeric($trigger_id))
return $this->
_deleteTrigger($trigger_id);
991 trigger_localised_error(
'SYS0069', E_USER_WARNING, $trigger_id);
1034 function createAssetLink(&$major, &$minor, $link_type, $value=
'', $sort_order=NULL, $dependant=
'0', $exclusive=
'0', $moving=FALSE)
1058 if (SQ_ROLLBACK_VIEW)
return TRUE;
1059 if (!$this->
attr(
'enabled'))
return TRUE;
1061 if ($broadcaster->shouldFastTrack($event_name))
return FALSE;
1063 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
1067 trigger_localised_error(
'CORE0219', E_USER_WARNING, $event_name);
1077 $state = $this->
_calculateState($event_name, $broadcaster, $parameters);
1080 $broadcast_status = TRUE;
1086 $specified_trigger_ids = !empty($parameters[
'specified_trigger_ids']) ? $parameters[
'specified_trigger_ids'] : $candidate_trigger_ids;
1087 $candidate_trigger_ids = array_intersect($candidate_trigger_ids, $specified_trigger_ids);
1090 foreach ($candidate_trigger_ids as $trigger_id) {
1092 $status_message = NULL;
1099 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this, $trigger[
'name']);
1102 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this, $trigger[
'name']);
1106 $trigger_settings =& $trigger[
'data'][
'settings'];
1107 $is_blocking = array_get_index($trigger[
'data'][
'settings'],
'blocking', FALSE);
1111 'trigger_name' => $trigger[
'name'],
1112 'triggerid' => $trigger[
'id'],
1113 'event' => $event_name,
1114 'asset_name' => $broadcaster->name,
1115 'assetid' => $broadcaster->id,
1119 case SQ_TRIG_RESULT_FAILURE:
1124 $broadcast_status = FALSE;
1127 trigger_localised_error(
'CORE0127', E_USER_WARNING, $trigger[
'id'], $trigger[
'name'], $event_name, $broadcaster->id, $broadcaster->name);
1132 case SQ_TRIG_RESULT_SUCCESS:
1133 $msg_type =
'trigger.success';
1136 case SQ_TRIG_RESULT_INVALID:
1137 $msg_type =
'trigger.invalid';
1143 if (!empty($msg_type)) {
1145 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
1147 $message = $ms->newMessage(Array(), $msg_type, $msg_reps);
1154 $this->_tmp[
'running_triggers'] = Array();
1156 return $broadcast_status;
1174 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
1177 $state[
'event'][
'name'] = $event_type;
1178 $state[
'event'][
'data'] = $parameters;
1180 $state[
'asset'] =& $event_broadcaster;
1181 $state[
'assetid'] = $event_broadcaster->id;
1182 $state[
'asset_type'] = $event_broadcaster->type();
1185 $parent_links = $am->getLinks($state[
'assetid'], SQ_SC_LINK_ALL, NULL, TRUE,
'minor');
1186 $new_parent_links = Array();
1187 $parent_assets = Array();
1188 $parent_link_map = Array();
1189 foreach ($parent_links as $link) {
1190 $new_parent_links[$link[
'linkid']] = $link;
1191 $parent_assets[$link[
'majorid']] = $link[
'major_type_code'];
1192 $parent_link_map[$link[
'majorid']][] = $link[
'linkid'];
1194 $state[
'immediate_parent_link_map'] = $parent_link_map;
1195 $state[
'immediate_parent_links'] = $new_parent_links;
1196 $state[
'immediate_parents'] = $parent_assets;
1200 $child_links = $am->getLinks($state[
'assetid'], SQ_SC_LINK_ALL, NULL, TRUE,
'major');
1201 $new_child_links = Array();
1202 $child_assets = Array();
1203 $child_link_map = Array();
1204 foreach ($child_links as $link) {
1205 $new_child_links[$link[
'linkid']] = $link;
1206 $child_assets[$link[
'minorid']] = $link[
'minor_type_code'];
1207 $child_link_map[$link[
'minorid']][] = $link[
'linkid'];
1209 $state[
'immediate_child_link_map'] = $child_link_map;
1210 $state[
'immediate_child_links'] = $new_child_links;
1211 $state[
'immediate_children'] = $child_assets;
1214 $tmp_treeid = $am->getAssetTreeids($state[
'assetid']);
1217 $state[
'treeid'] = $tmp_treeid;
1219 $state[
'treeid'] = Array();
1237 $state_hash[
'event'] = $state[
'event'][
'name'];
1238 $state_hash[
'assetid'] = $state[
'assetid'];
1239 $state_hash[
'asset_type'] = $state[
'asset_type'];
1240 $state_hash[
'treeid'] = $state[
'treeid'];
1241 $state_hash[
'parents'] = $state[
'immediate_parents'];
1242 $state_hash[
'children'] = $state[
'immediate_children'];
1260 if (empty($state_hash))
return Array();
1262 $bind_vars = Array();
1265 $treeid_sql_array[] =
'treeid = :null_treeid';
1266 $bind_vars[
'null_treeid'] = (string)
'-1';
1267 if (empty($state_hash[
'treeid'])) {
1268 $state_hash[
'treeid'] = Array();
1272 $propagate_flag_count = 0;
1273 $no_propagate_flag_count = 0;
1274 $current_tree_length_count = 0;
1275 foreach ($state_hash[
'treeid'] as $current_treeid) {
1276 if (empty($current_treeid))
continue;
1278 $treeid_sql_array[] =
'
1280 (treeid != :current_treeid'.
'_'.++$treeid_count.
' AND SUBSTR(:current_treeid'.
'_'.++$treeid_count.
', 1, LENGTH(treeid)) = treeid)
1282 tree_propagate = :propagate_flag'.
'_'.++$propagate_flag_count.
'
1283 OR (tree_propagate = :no_propagate_flag'.
'_'.++$no_propagate_flag_count.
' AND LENGTH(treeid) = :current_tree_length'.
'_'.++$current_tree_length_count.
')
1287 for ($i=$treeid_count-1; $i<=$treeid_count; $i++) {
1288 $bind_vars[
'current_treeid_'.$i] = $current_treeid;
1290 $bind_vars[
'propagate_flag_'.$propagate_flag_count] = SQ_TRIG_TREE_PROPAGATE;
1291 $bind_vars[
'no_propagate_flag_'.$no_propagate_flag_count] = SQ_TRIG_TREE_NO_PROPAGATE;
1292 $bind_vars[
'current_tree_length_'.$current_tree_length_count] = strlen($current_treeid) - SQ_CONF_ASSET_TREE_SIZE;
1295 $treeid_sql = implode($treeid_sql_array,
' OR ');
1298 $parent_id_array = Array();
1299 $parent_type_array = Array();
1301 $parents = $state_hash[
'parents'];
1302 foreach ($parents as $id => $type) {
1303 $parent_id_array[] = $id;
1304 $parent_type_array[$type] =
'\''.$type.
'\'';
1308 $parent_id_sql =
'parentid = :null_parentid';
1309 $bind_vars[
'null_parentid'] = (string)
'-1';
1310 if (!empty($parent_id_array)) {
1311 for (reset($parent_id_array); NULL !== ($k = key($parent_id_array)); next($parent_id_array)) {
1312 $parent_id_array[$k] =
'\''.(string) $parent_id_array[$k].
'\'';
1315 foreach (array_chunk($parent_id_array, 200) as $chunk) {
1316 $parent_id_sql .=
' OR parentid IN ('.implode(
',', $chunk).
')';
1321 $parent_type_sql =
'parent_type = :null_parent_type';
1322 $bind_vars[
'null_parent_type'] = (string)
'-1';
1323 if (!empty($parent_type_array)) {
1324 $parent_type_sql .=
' OR parent_type IN ('.implode(
',', $parent_type_array).
')';
1329 $child_id_sql =
'childid = :null_childid';
1330 $child_type_sql =
'child_type = :null_child_type';
1331 $bind_vars[
'null_childid'] = (string)
'-1';
1332 $bind_vars[
'null_child_type'] = (string)
'-1';
1334 if (!empty($state_hash[
'treeid'])) {
1336 $treeid = reset($state_hash[
'treeid']);
1341 $child_fromwhere_sql =
'
1343 (sq_ast_lnk_tree t INNER JOIN sq_ast_lnk l ON t.linkid = l.linkid)
1344 INNER JOIN sq_ast a ON l.minorid = a.assetid
1346 t.treeid LIKE :childsql_treeid_wildcard
1347 AND t.treeid > :childsql_treeid
1348 AND LENGTH(t.treeid) <= :childsql_treeid_length
1350 $bind_vars[
'childsql_treeid_wildcard'] = $treeid.
'%';
1351 $bind_vars[
'childsql_treeid'] = $treeid;
1352 $bind_vars[
'childsql_treeid_length'] = strlen($treeid) + SQ_CONF_ASSET_TREE_SIZE;
1357 SELECT DISTINCT l.minorid
1358 '.$child_fromwhere_sql.
'
1362 $child_type_sql .=
'
1365 SELECT DISTINCT a.type_code
1366 '.$child_fromwhere_sql.
'
1372 $event_sql =
'event = :null_event_id';
1373 $bind_vars[
'null_event_id'] = (string)
'-1';
1374 if (!is_null($state_hash[
'event'])) {
1375 $event_sql .=
' OR event = :event_id';
1376 $bind_vars[
'event_id'] = $state_hash[
'event'];
1380 $assetid_sql =
'assetid = :null_bc_assetid';
1381 $bind_vars[
'null_bc_assetid'] = (string)
'-1';
1382 if (!is_null($state_hash[
'assetid'])) {
1383 $assetid_sql .=
' OR assetid = :bc_assetid';
1384 $bind_vars[
'bc_assetid'] = $state_hash[
'assetid'];
1388 $asset_type_sql =
'asset_type = :null_bc_asset_type';
1389 $bind_vars[
'null_bc_asset_type'] = (string)
'-1';
1390 if (!is_null($state_hash[
'asset_type'])) {
1391 $asset_type_sql .=
' OR asset_type = :bc_asset_type';
1392 $bind_vars[
'bc_asset_type'] = $state_hash[
'asset_type'];
1396 $sql =
'SELECT DISTINCT triggerid
1398 WHERE ('.$event_sql.
')
1399 AND ('.$assetid_sql.
')
1400 AND ('.$asset_type_sql.
')
1401 AND ('.$treeid_sql.
')
1402 AND ('.$parent_id_sql.
')
1403 AND ('.$parent_type_sql.
')
1404 AND ('.$child_id_sql.
')
1405 AND ('.$child_type_sql.
')';
1410 foreach ($bind_vars as $bind_var => $bind_value) {
1414 }
catch (Exception $e) {
1415 throw new Exception(
'unable to get the candidate triggers: '.$e->getMessage());
1436 $status = SQ_TRIG_RESULT_SUCCESS;
1439 $conditions = $trigger_data[
'conditions'];
1440 $actions = $trigger_data[
'actions'];
1442 if (isset($trigger_data[
'settings'])) {
1443 $is_blocking = array_get_index($trigger_data[
'settings'],
'blocking', FALSE);
1445 $is_blocking = FALSE;
1448 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
1451 foreach ($conditions as $condition) {
1454 return SQ_TRIG_RESULT_INVALID;
1459 $condition_success = call_user_func_array(Array($condition[
'type'],
'evaluate'), Array($condition[
'data'], &$state_data));
1463 if ($condition_success == $condition[
'inverse_condition']) {
1464 return SQ_TRIG_RESULT_FALSE;
1478 foreach ($actions as $action) {
1480 return SQ_TRIG_RESULT_INVALID;
1485 $locks_held = Array();
1488 foreach ($actions as $action) {
1489 $not_required = array_get_index($action,
'not_required', FALSE);
1490 $ignore_permissions = array_get_index($action,
'ignore_permissions', FALSE);
1492 if ($ignore_permissions || !$GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_LOCKING)) {
1495 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
1496 $action_success = call_user_func_array(Array($action[
'type'],
'execute'), Array($action[
'data'], &$state_data));
1497 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1500 $lock_success = TRUE;
1503 $action_locks = call_user_func_array(Array($action[
'type'],
'getLocks'), Array($action[
'data'], &$state_data));
1505 foreach ($action_locks as $lock_assetid => $lock_types) {
1506 foreach ($lock_types as $lock_type) {
1507 $lock_success = $am->acquireLock($lock_assetid, $lock_type);
1509 if ($lock_success==1) {
1510 $locks_held[$lock_assetid][$lock_type] = TRUE;
1511 }
else if ($lock_success==0) {
1518 if (!$lock_success) {
1519 if ($not_required) {
1523 $status = SQ_TRIG_RESULT_FAILURE;
1529 $action_success = call_user_func_array(Array($action[
'type'],
'execute'), Array($action[
'data'], &$state_data));
1532 if ($action_success === FALSE) {
1533 if ($not_required) {
1534 if (!$is_blocking) {
1535 trigger_localised_error(
'CORE0134', E_USER_NOTICE, $action[
'type']);
1539 $status = SQ_TRIG_RESULT_FAILURE;
1540 if (!$is_blocking) {
1541 trigger_localised_error(
'CORE0135', E_USER_NOTICE, $action[
'type']);
1547 $status = SQ_TRIG_RESULT_SUCCESS;
1552 foreach ($locks_held as $lock_assetid => $lock_types) {
1553 foreach ($lock_types as $lock_type => $lock_true) {
1555 $am->releaseLock($lock_assetid, $lock_type);
1589 $trigger[
'name'] =
'';
1590 $trigger[
'description'] =
'';
1591 $trigger[
'category'] =
'';
1592 $trigger[
'data'] = NULL;
1593 $trigger[
'active'] = SQ_TRIG_STATUS_INACTIVE;
1614 if (SQ_ROLLBACK_VIEW)
return TRUE;
1615 if (empty($trigger))
return FALSE;
1619 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1620 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1627 if (!isset($trigger[
'id'])) {
1630 $trigger[
'id'] = $tr_id;
1671 description = :description,
1672 category = :category,
1692 if ($status && array_get_index($trigger,
'save_hash', TRUE) && $trigger[
'active']) {
1695 $hash->setTriggerId($trigger[
'id']);
1698 if (isset($trigger[
'data'])) {
1699 if (isset($trigger[
'data'][
'events'])) {
1700 foreach ($trigger[
'data'][
'events'] as $event) {
1701 $hash->setEvent($event);
1704 if (isset($trigger[
'data'][
'conditions'])) {
1705 foreach ($trigger[
'data'][
'conditions'] as $condition) {
1706 if ($GLOBALS[
'SQ_SYSTEM']->am->installed(array_get_index($condition,
'type',
''))) {
1708 if (isset($condition[
'data'])) {
1709 if (!$condition[
'inverse_condition']) {
1710 $settings =& $condition[
'data'];
1712 $settings = Array();
1714 call_user_func_array(Array($condition[
'type'],
'setHash'), Array(&$settings, &$hash));
1727 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1728 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1729 return $trigger[
'id'];
1731 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1732 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1736 }
catch (Exception $e)
1738 throw new Exception(
'Unable to save the trigger due to database error: '.$e->getMessage());
1754 if (empty($hash))
return FALSE;
1756 $hash_combinations = $hash->getHashCombinations();
1757 if (empty($hash_combinations))
return FALSE;
1759 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1761 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1763 foreach ($hash_combinations as $combination) {
1765 $field_array = Array();
1766 $value_array = Array();
1768 foreach ($combination as $hash_id => $hash_data) {
1769 $field_array[] = $hash_id;
1770 $value_array[] =
'\''.($hash_data).
'\'';
1776 '.implode($field_array,
', ').
'
1780 '.implode($value_array,
', ').
'
1787 }
catch (Exception $e) {
1788 throw new Exception(
'could not create the trigger hash due to database error: '.$e->getMessage());
1792 if ($result === FALSE) {
1793 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1794 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1800 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1801 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1820 if (empty($state_hash) || !is_array($state_hash)) {
1821 $state_hash = Array();
1825 $state_hash_defaults = Array(
1830 'tree_propagate' => SQ_TRIG_TREE_NO_PROPAGATE,
1835 foreach ($state_hash_defaults as $defaults_id => $defaults_data) {
1836 if (empty($state_hash[$defaults_id])) {
1837 $state_hash[$defaults_id] = $defaults_data;
1859 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1860 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1864 $bind_vars = Array (
1865 'trigger_id' => $trigger_id,
1868 }
catch (Exception $e) {
1869 throw new Exception(
'Unable delete the Trigger'.$trigger_id.
': due to database error: '.$e->getMessage());
1873 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1874 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1891 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1894 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1899 triggerid = :triggerid';
1905 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1906 }
catch(Exception $e) {
1907 throw new Exception(
"Failed to delete the hash (#$trigger_id): ".$e->getMessage());
1909 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1933 if (empty($trigger_db)) {
1934 foreach ($trigger_db as $trigger_data) {
1935 $trigger_data[
'data'] = (isset($trigger_data[
'data']) && !empty($trigger_data[
'data'])) ? unserialize($trigger_data[
'data']) :
'';
1986 if (is_numeric($triggerid)) {
2012 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
2015 $s = $s && isset($trigger[
'name']);
2016 $s = $s && isset($trigger[
'description']);
2017 $s = $s && isset($trigger[
'active']);
2018 $s = $s && isset($trigger[
'data']);
2021 $s = $s && isset($trigger[
'data'][
'events']);
2024 $s = $s && isset($trigger[
'data'][
'conditions']);
2025 if ($s && !empty($trigger[
'data'][
'conditions'])) {
2026 foreach ($trigger[
'data'][
'conditions'] as $condition) {
2027 $s = $s && isset($condition[
'type']) && $am->installed($condition[
'type']);
2028 $s = $s && isset($condition[
'data']);
2029 $s = $s && isset($condition[
'inverse_condition']);
2034 $s = $s && isset($trigger[
'data'][
'actions']);
2035 if ($s && !empty($trigger[
'data'][
'actions'])) {
2036 foreach ($trigger[
'data'][
'actions'] as $action) {
2037 $s = $s && isset($action[
'type']) && $am->installed($action[
'type']);
2038 $s = $s && isset($action[
'data']);
2039 $s = $s && isset($action[
'not_required']);
2040 $s = $s && isset($action[
'ignore_permissions']);
2047 trigger_localised_error(
'CORE0232', E_USER_WARNING);
2064 if (!isset($trigger_id))
return NULL;
2077 '.SQ_TABLE_RUNNING_PREFIX.
'trig';
2079 $where =
'id = :id';
2080 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
2084 if (!empty($trigger_db)) {
2085 $trigger_db = $trigger_db[0];
2087 }
catch (Exception $e) {
2088 throw new Exception(
'Unable get the information from the trigger table due to database error: '.$e->getMessage());
2091 if (empty($trigger_db)) {
2096 $trigger_db[
'data'] = (isset($trigger_db[
'data']) && !empty($trigger_db[
'data'])) ? unserialize($trigger_db[
'data']) :
'';
2099 if (!isset($trigger_db[
'data'][
'events'])) {
2100 $trigger_db[
'data'][
'events'] = Array();
2102 if (!isset($trigger_db[
'data'][
'conditions'])) {
2103 $trigger_db[
'data'][
'conditions'] = Array();
2105 if (!isset($trigger_db[
'data'][
'actions'])) {
2106 $trigger_db[
'data'][
'actions'] = Array();
2108 if (!isset($trigger_db[
'data'][
'settings'])) {
2109 $trigger_db[
'data'][
'settings'] = Array();
2135 '.SQ_TABLE_RUNNING_PREFIX.
'trig';
2137 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause();
2138 $order =
'ORDER BY active DESC , name ASC';
2142 }
catch (Exception $e) {
2143 throw new Exception(
'Unable to get trigger info list due to the following database error:'.$e->getMessage());
2161 if (empty($type))
return Array();
2163 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
2165 $component_types = $am->getTypeDescendants($type);
2166 $component_info = $am->getTypeInfo($component_types,
'name');
2168 return $component_info;
2231 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
2233 if ($am->installed($type_code)) {
2234 $am->includeAsset($type_code);
2258 $interface = call_user_func_array(Array($type_code,
'getInterface'), Array($data, $prefix, $write_access, &$trigger, $action_id));
2276 $status = call_user_func(Array($type_code,
'allowMultiple'));
2293 $trigger_count = NULL;
2295 $bind_vars = Array (
2299 }
catch (Exception $e) {
2300 throw new Exception(
'Unable get the number of trigger hashes: due to database error: '.$e->getMessage());
2304 return !empty($trigger_count);