Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
tool_rollback_management.inc
1 <?php
18 require_once SQ_SYSTEM_ROOT.'/core/assets/system/tool/tool.inc';
19 require_once SQ_INCLUDE_PATH.'/rollback_management.inc';
20 
34 {
35 
36 
43  function Tool_Rollback_Management($assetid=0)
44  {
45  $this->Tool($assetid);
46 
47  }//end constructor
48 
49 
60  public static function paintTool(&$o, $type_code)
61  {
62  $tool_info = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_code);
63 
64  $o->openSection($tool_info['name']);
65 
66  // Allow System Admins to run this tool
67  if (!$GLOBALS['SQ_SYSTEM']->userSystemAdmin() && !$GLOBALS['SQ_SYSTEM']->userRoot()) {
68  $o->openField('');
69  $o->note('Access denied to run this tool');
70  $o->closeField();
71  return;
72  }
73 
74  $o->openField(translate('tool_rollback_rb_status'));
75  $options = Array(
76  '0' => 'Disabled',
77  '1' => 'Enabled',
78  );
79 
80  hidden_field($type_code.'_rollback_status_old', (SQ_CONF_ROLLBACK_ENABLED) ? '1' : '0');
81  combo_box($type_code.'_rollback_status', $options, FALSE, (SQ_CONF_ROLLBACK_ENABLED) ? '1' : '0');
82  $o->closeField();
83 
84 
85 
86  $o->openField('');
87  $o->closeField();
88 
89  $o->openField(translate('tool_rollback_reset_all_rb_entries'));
90  $options = Array(
91  '0' => translate('no'),
92  '1' => translate('yes'),
93  );
94  combo_box($type_code.'_reset_rollback_entries', $options, FALSE, '');
95  $o->note('<b>'.translate('tool_rollback_reset_all_note').'</b>');
96  $o->closeField();
97 
98  $o->openField(translate('tool_rollback_purge_rb_entries_before'));
99  text_box($type_code.'_purge_rollback_entries_period_amount', '', 4, 4);
100 
101  $options = Array(
102  'h' => 'hours',
103  'd' => 'days',
104  'w' => 'weeks',
105  'm' => 'months',
106  'y' => 'years',
107  );
108 
109  combo_box($type_code.'_purge_rollback_entries_period_timeframe', $options, FALSE, '');
110  $o->closeField();
111 
112  $o->openField(translate('tool_rollback_purge_file_versioning_entries_before'));
113  text_box($type_code.'_purge_file_entries_period_amount', '', 4, 4);
114 
115  $options = Array(
116  'h' => 'hours',
117  'd' => 'days',
118  'w' => 'weeks',
119  'm' => 'months',
120  'y' => 'years',
121  );
122 
123  combo_box($type_code.'_purge_file_entries_period_timeframe', $options, FALSE, '');
124  $o->closeField();
125 
126  $o->openField(translate('tool_delete_redundant_entries'));
127  $options = Array(
128  '0' => 'No',
129  '1' => 'Yes',
130  );
131  combo_box($type_code.'_delete_redundant_entries', $options, FALSE, 0, 0, "onChange=\"Javascript: if (this.value == 1) { if(!confirm(js_translate('tool_delete_redundant_entries_confirm'))) { this.value = 0; } } \"");
132  $o->note(translate('tool_delete_redundant_entries_note'));
133  $o->closeField();
134 
135  $o->openField('');
136  if (isset($_REQUEST['redirect_to_sys_maintenance'])) {
137  $redirect_to_system_maintenance = (int)$_REQUEST['redirect_to_sys_maintenance'];
138  if ($redirect_to_system_maintenance) {
139  hidden_field('redirect_to_sys_maintenance', $redirect_to_system_maintenance);
140  }
141  }
142  $o->closeField();
143 
144  $o->openField(translate('note'));
145  $o->note(translate('tool_rollback_usage_note'));
146  $o->closeField();
147 
148 
149  $o->closeSection();
150 
151  }//end paintTool()
152 
153 
164  public static function processTool(&$o, $type_code)
165  {
166  // Allow System Admins to run this tool
167  if (!$GLOBALS['SQ_SYSTEM']->userSystemAdmin() && !$GLOBALS['SQ_SYSTEM']->userRoot()) {
168  return FALSE;
169  }
170 
171  $settings = Array();
172 
173  $redirect_url = '';
174 
175  if (isset($_REQUEST['redirect_to_sys_maintenance'])) {
176  $redirect_to_system_maintenance = (int)$_REQUEST['redirect_to_sys_maintenance'];
177  if ($redirect_to_system_maintenance) {
178  $redirect_url = sq_web_path('admin').'/?SQ_BACKEND_PAGE=main&backend_section=sys_maintenance&expand=rollback';
179  }
180  }
181 
182  $time_units = Array(
183  'h' => 'hour',
184  'd' => 'day',
185  'w' => 'week',
186  'm' => 'month',
187  'y' => 'year',
188  );
189 
190  $rollback_date = date('Y-m-d H:i:s');
191  $purge_rb_date = '';
192  $purge_fv_date = '';
193 
194  $reset_rollback_entries = $_REQUEST[$type_code.'_reset_rollback_entries'];
195 
196 
197 
198  $purge_rb_period = (int) $_REQUEST[$type_code.'_purge_rollback_entries_period_amount'];
199  $purge_fv_period = (int) $_REQUEST[$type_code.'_purge_file_entries_period_amount'];
200 
201  $purge_rb_time_unit = $_REQUEST[$type_code.'_purge_rollback_entries_period_timeframe'];
202  $purge_fv_time_unit = $_REQUEST[$type_code.'_purge_file_entries_period_timeframe'];
203 
204  if ($purge_rb_period > 0) {
205  $time_unit = $time_units[$purge_rb_time_unit];
206  if ($purge_rb_period > 1) $time_unit .= 's';
207  $purge_rb_date = date('Y-m-d H:i:s', strtotime('-'.$purge_rb_period.' '.$time_unit));
208  }
209 
210  if ($purge_fv_period > 0) {
211  $time_unit = $time_units[$purge_fv_time_unit];
212  if ($purge_fv_period > 1) $time_unit .= 's';
213  $purge_fv_date = date('Y-m-d H:i:s', strtotime('-'.$purge_fv_period.' '.$time_unit));
214  }
215 
216  $rollback_status = $_REQUEST[$type_code.'_rollback_status'];
217  $enable_rollback = FALSE;
218  $disable_rollback = FALSE;
219 
220  if ($rollback_status != $_REQUEST[$type_code.'_rollback_status_old']) {
221  $enable_rollback = ($rollback_status == '1');
222  $disable_rollback = ($rollback_status == '0');
223  }
224 
225  $reset_rollback = ($_REQUEST[$type_code.'_reset_rollback_entries'] == '1');
226  $delete_redundant_entries = ($_REQUEST[$type_code.'_delete_redundant_entries'] == '1');
227 
228  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
229  $vars = Array(
230  'enable_rollback' => $enable_rollback,
231  'disable_rollback' => $disable_rollback,
232  'rollback_date' => $rollback_date,
233  'purge_fv_date' => $purge_fv_date,
234  'purge_rb_date' => $purge_rb_date,
235  'reset_rollback' => $reset_rollback,
236  'delete_redundant_entries' => $delete_redundant_entries,
237  'fail_on_error' => TRUE,
238  );
239 
240  $hh->queueHipo('hipo_job_rollback_management', $vars, $redirect_url);
241 
242  $url = $hh->runQueuedJobs();
243  if (!empty($url)) $o->setRedirect($url);
244 
245  return TRUE;
246 
247  }//end processTool()
248 
249 
250 }//end class
251 ?>