Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_management.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
18 
28 {
29 
30 
35  function Trigger_Management(&$pm)
36  {
37  $this->Asset_Management($pm);
38 
39  $this->vars = Array(
40  'name' => Array(
41  'added' => '0.1',
42  'type' => 'text',
43  'default' => '',
44  'description' => 'The name of the trigger',
45  ),
46  'description' => Array(
47  'added' => '0.1',
48  'type' => 'text',
49  'default' => '',
50  'description' => 'A description of the trigger',
51  'parameters' => Array(
52  'max_length' => 255,
53  ),
54  ),
55  'category' => Array(
56  'added' => '0.2',
57  'type' => 'text',
58  'default' => '',
59  'description' => 'Category of the trigger',
60  'parameters' => Array(
61  'max_length' => 255,
62  ),
63  ),
64  'events' => Array(
65  'added' => '0.1',
66  'type' => 'serialise',
67  'default' => Array(),
68  'description' => 'Events when trigger will be executed',
69  ),
70  'conditions' => Array(
71  'added' => '0.1',
72  'type' => 'serialise',
73  'default' => Array(),
74  'description' => 'Conditions that must be met for trigger to execute',
75  ),
76  'actions' => Array(
77  'added' => '0.1',
78  'type' => 'serialise',
79  'default' => Array(),
80  'description' => 'Actions that will be performed when the trigger executes',
81  ),
82  'active' => Array(
83  'added' => '0.1',
84  'type' => 'boolean',
85  'default' => FALSE,
86  'parameters' => Array(
87  'allow_empty' => FALSE,
88  ),
89  'description' => 'If this trigger is active or not',
90  ),
91  'blocking' => Array(
92  'added' => '0.1',
93  'type' => 'boolean',
94  'default' => FALSE,
95  'parameters' => Array(
96  'allow_empty' => FALSE,
97  ),
98  'description' => 'If this trigger will prevent further trigger execution upon error',
99  ),
100  );
101 
102  }//end constructor
103 
104 
114  function _upgrade($current_version)
115  {
116  if (!parent::_upgrade($current_version)) return FALSE;
117 
118  if (version_compare($current_version, '0.3', '<')) {
119  pre_echo('UPGRADING TRIGGER ASSETS - FROM VERSION '.$current_version);
120  $trigger_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('trigger_manager');
121  $children = $trigger_manager->getTriggerList();
122  foreach ($children as $trigger_data) {
123  $trigger = $trigger_manager->getAsset($trigger_data['id']);
124  $conditions = $trigger->attr('conditions');
125  foreach ($conditions as &$condition) {
126  if (!isset($condition['inverse_condition'])) {
127  $condition['inverse_condition'] = FALSE;
128  }
129  }
130  $trigger->setAttrValue('conditions', $conditions);
131  $trigger->saveAttributes();
132  }
133  }//end if version 0.3
134 
135  if (version_compare($current_version, '0.4', '<')) {
136  pre_echo('UPGRADING TRIGGER ASSETS - FROM VERSION '.$current_version);
137  $trigger_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('trigger_manager');
138  $children = $trigger_manager->getTriggerList();
139  foreach ($children as $trigger_data) {
140  $trigger = $trigger_manager->getAsset($trigger_data['id']);
141  $actions = $trigger->attr('actions');
142  foreach ($actions as $index => $action) {
143  if (isset($action['type']) && $action['type'] == 'trigger_action_set_thumbnail') {
144  $data = array_get_index($action, 'data', Array());
145  if (isset($data['index'])) {
146  $parameter_map = Array( 'thumbnail' => Array( Array( 'source' => 'GLOBALS', 'index' => 'thumbnail') ) );
147  $data['thumbnail'] = serialize($parameter_map);
148  unset($data['index']);
149  $actions[$index]['data'] = $data;
150  }//end if
151  }//end if
152  }//end foreach
153  $trigger->setAttrValue('actions', $actions);
154  $trigger->saveAttributes();
155  }
156  }//end if version 0.4
157 
158  return TRUE;
159 
160  }//end _upgrade()
161 
162 
163 }//end class
164 
165 ?>