Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trim_saved_search_management.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 require_once SQ_PACKAGES_PATH.'/trim/lib/trim_common.inc';
20 
32 {
33 
34 
40  {
41  $this->Asset_Management($pm);
42  $this->vars = Array(
43  'wsdl' => Array (
44  'added' => '0.1',
45  'type' => 'text',
46  'default' => '',
47  ),
48  'cached_result' => Array (
49  'added' => '0.1',
50  'type' => 'serialise',
51  'default' => Array(),
52  'parameters' => Array (
53  'allow_empty' => FALSE,
54  ),
55  ),
56  'trim_connector_id' => Array(
57  'added' => '0.1',
58  'type' => 'assetid',
59  'default' => '',
60  'description' => 'The asset we will be using as content in the email',
61  ),
62  'download_files' => Array(
63  'added' => '0.1',
64  'type' => 'boolean',
65  'default' => FALSE,
66  'description' => 'Whether to download the files attached with documents or not',
67  'parameters' => Array(
68  'allow_empty' => FALSE,
69  ),
70  ),
71  'use_downloader' => Array(
72  'added' => '0.1',
73  'type' => 'selection',
74  'default' => 'No',
75  'description' => 'Whether to create the helper downloader asset',
76  'is_admin' => FALSE,
77  'parameters' => Array(
78  'allow_empty' => FALSE,
79  'multiple' => FALSE,
80  'options' => Array (
81  'Yes' => 'Yes',
82  'No' => 'No',
83  ),
84  ),
85  ),
86  'username' => Array(
87  'added' => '0.1',
88  'type' => 'text',
89  'default' => '',
90  ),
91  'password' => Array(
92  'added' => '0.1',
93  'type' => 'password',
94  'default' => '',
95  ),
96  'download_limit' => Array(
97  'added' => '0.1',
98  'type' => 'int',
99  'default' => 4194304,
100  'parameters' => Array (
101  'allow_empty' => FALSE,
102  'allow_negative' => FALSE,
103  ),
104  ),
105  'record_search_type' => Array (
106  'added' => '0.1',
107  'type' => 'serialise',
108  'default' => Array(
109  'StringSearch' => 'StringSearch',
110  ),
111  'parameters' => Array (
112  'allow_empty' => FALSE,
113  ),
114  ),
115 
116  'dynamic_vars' => Array(
117  'added' => '0.2',
118  'type' => 'serialise',
119  'default' => Array (
120  'search_parent_container' => '',
121  'search_clauses' => Array(
122  'search_groups' => Array(),
123  'global_logic' => 'AND',
124  ),
125  'result_fields' => Array (
126  'recTitle' => 'Title',
127  'recNumber' => 'Record Number',
128  'recRecordType' => 'Record Type',
129  'recDocumentType' => 'Document Type',
130  'recCreatorLoc' => 'Creator',
131  ),
132  'fileTypes' => '',
133  'limit' => 30,
134  'search_sort_1' => 'None',
135  'search_sort_2' => 'None',
136  'search_sort_3' => 'None',
137  'sort_1_descending' => FALSE,
138  'sort_2_descending' => FALSE,
139  'sort_3_descending' => FALSE,
140  'record_type_filter' => Array(),
141  ),
142  ),
143  'parameter_map' => Array (
144  'added' => '0.1',
145  'type' => 'parameter_map',
146  'default' => Array(),
147  'parameters' => Array (
148  'parameters' => Array(),
149  ),
150  ),
151  'retrieved_fields' => Array (
152  'added' => '0.1',
153  'type' => 'serialise',
154  'default' => Array(),
155  'parameters' => Array (
156  'allow_empty' => TRUE,
157  ),
158  ),
159  'classification' => Array (
160  'added' => '0.2',
161  'type' => 'text',
162  'default' => '',
163  ),
164  'classification_sub' => Array (
165  'added' => '0.2',
166  'type' => 'boolean',
167  'default' => FALSE,
168  'description' => 'Whether to include records in sub classifications',
169  'parameters' => Array(
170  'allow_empty' => FALSE,
171  ),
172  ),
173  'convert_timezone' => Array(
174  'added' => '0.2',
175  'type' => 'boolean',
176  'default' => TRUE,
177  'description' => 'Whether to convert GMT datetime to local timezone',
178  'parameters' => Array(
179  'allow_empty' => FALSE,
180  ),
181  ),
182  );
183 
184  }//end constructor
185 
186 
193  function _getFileList()
194  {
195  return Array(
196  'js/ajax.js',
197  'images/loader.gif',
198  );
199 
200  }//end _getFileList()
201 
202 
211  function _upgrade($current_version)
212  {
213  if (!parent::_upgrade($current_version)) return FALSE;
214 
215  $asset_name = strtoupper($this->_pm->getTypeInfo($this->getAssetType(), 'name'));
216 
217  if (version_compare($current_version, '0.2', '<')) {
218  pre_echo('STARTING UPGRADE OF '.$asset_name.' FROM VERSION '.$current_version.' TO VERSION 0.2');
219  $saved_search_ids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('trim_saved_search', FALSE, TRUE);
220 
221  $count = 0;
222 
223  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
224  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
225 
226  pre_echo('Updating TRIM Saved Search...');
227 
228  $available_fields = TRIM_Common::getRecordProperties();
229  $available_search_type = TRIM_Common::getRecordStringSearchClauseType();
230 
231  // find every trim saved search asset and update the var list
232  foreach ($saved_search_ids as $id => $blank) {
233  $saved_search = $GLOBALS['SQ_SYSTEM']->am->getAsset($id, $blank['type_code']);
234  $var_list = $saved_search->attr('dynamic_vars');
235  if(isset($var_list['fields'])) {
236  $result_fields = Array();
237  foreach ($var_list['fields'] as $field_name) {
238  if(isset($available_fields[$field_name]))
239  $result_fields[$field_name] = $available_fields[$field_name];
240  }
241  $var_list['result_fields'] = $result_fields;
242  unset ($var_list['fields']);
243  }
244  if(isset($var_list['string_search_type'][0]) && isset($var_list['search_keyword'])) {
245 
246  $search_name = $var_list['string_search_type'][0];
247  $search_caption = $available_search_type[$search_name];
248  $search_keyword = $var_list['search_keyword'];
249  $var_list['search_clauses'] = Array(
250  'search_groups' => Array (
251  Array(
252  'content' => Array (
253  Array (
254  'name' => $search_name,
255  'caption' => $search_caption,
256  'keyword' => $search_keyword,
257  )
258  ),
259  'group_logic' => 'AND',
260  ),
261  ),
262  'global_logic' => 'AND',
263  );
264  unset ($var_list['string_search_type']);
265  unset ($var_list['search_keyword']);
266  }
267 
268  // Save the attribute
269  $saved_search->setAttrValue('dynamic_vars', $var_list);
270 
271  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
272 
273  if (!$saved_search->saveAttributes()) {
274  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
275  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
276 
277  pre_echo($asset_name.' UPGRADE FAILED - Could not save attributes');
278  return FALSE;
279  }
280 
281  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
282 
283  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($saved_search);
284  unset($saved_search);
285 
286  $count++;
287  }
288 
289  pre_echo('Updated TRIM Saved Search - '.$count.' assets(s)...');
290 
291 
292  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
293  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
294 
295  pre_echo($asset_name.' SUCCESSFULLY UPGRADED TO VERSION 0.2');
296 
297  $current_version = '0.2';
298  }//end if
299 
300 
301 
302  if (version_compare($current_version, '0.3', '<')) {
303  pre_echo('STARTING UPGRADE OF '.$asset_name.' FROM VERSION '.$current_version.' TO VERSION 0.3');
304  $saved_search_ids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('trim_saved_search', FALSE, TRUE);
305 
306  $count = 0;
307 
308  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
309  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
310 
311  pre_echo('Updating TRIM Saved Search...');
312 
313 
314  // find every trim saved search asset and update the var list
315  foreach ($saved_search_ids as $id => $blank) {
316  $saved_search = $GLOBALS['SQ_SYSTEM']->am->getAsset($id, $blank['type_code']);
317  $var_list = $saved_search->attr('dynamic_vars');
318  if(!isset($var_list['record_type_filter'])) {
319  $var_list['record_type_filter'] = Array();
320  }
321 
322  // Save the attribute
323  $saved_search->setAttrValue('dynamic_vars', $var_list);
324 
325  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
326 
327  if (!$saved_search->saveAttributes()) {
328  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
329  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
330 
331  pre_echo($asset_name.' UPGRADE FAILED - Could not save attributes');
332  return FALSE;
333  }
334 
335  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
336 
337  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($saved_search);
338  unset($saved_search);
339 
340  $count++;
341  }
342 
343  pre_echo('Updated TRIM Saved Search - '.$count.' assets(s)...');
344 
345  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
346  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
347 
348  pre_echo($asset_name.' SUCCESSFULLY UPGRADED TO VERSION 0.3');
349  }//end if
350 
351  return TRUE;
352 
353  }//end _upgrade()
354 
355 }//end class
356 
357 ?>