17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
18 require_once SQ_INCLUDE_PATH.
'/rollback_management.inc';
50 $this->uses_trans = FALSE;
66 public static function paintConfig(&$o, $class, $write_access)
81 'SQ_HIPO_ROLLBACK_MANAGEMENT_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
95 return translate(
'hipo_name_rollback_management');
111 'name' => translate(
'hipo_job_rollback_changing_rb_config'),
112 'function_call' => Array(
113 'process_function' =>
'changeRollbackSetting',
115 'running_mode' =>
'server',
117 'allow_cancel' => FALSE,
123 'name' => translate(
'hipo_job_rollback_configuring_db_triggers'),
124 'function_call' => Array(
125 'process_function' =>
'configureDBTriggers',
127 'running_mode' =>
'server',
129 'allow_cancel' => FALSE,
135 'name' => translate(
'hipo_job_rollback_opening_db_transaction'),
136 'function_call' => Array(
137 'process_function' =>
'openTransaction',
139 'running_mode' =>
'server',
141 'allow_cancel' => FALSE,
147 'name' => translate(
'hipo_job_rollback_purging_file_versioning'),
148 'function_call' => Array(
149 'process_function' =>
'purgeFileVersioning',
151 'running_mode' =>
'server',
153 'allow_cancel' => TRUE,
159 'name' => translate(
'hipo_job_rollback_resetting_rollback'),
160 'function_call' => Array(
161 'process_function' =>
'resetRollback',
163 'running_mode' =>
'server',
165 'allow_cancel' => TRUE,
171 'name' => translate(
'hipo_job_rollback_toggling_rb_state'),
172 'function_call' => Array(
173 'process_function' =>
'toggleRollbackState',
175 'running_mode' =>
'server',
177 'allow_cancel' => TRUE,
183 'name' => translate(
'hipo_job_rollback_deleting_rb_entries'),
184 'function_call' => Array(
185 'process_function' =>
'deleteRollbackEntries',
187 'running_mode' =>
'server',
189 'allow_cancel' => TRUE,
195 'name' => translate(
'hipo_job_rollback_aligning_rb_entries'),
196 'function_call' => Array(
197 'process_function' =>
'alignRollbackEntries',
199 'running_mode' =>
'server',
201 'allow_cancel' => TRUE,
207 'name' => translate(
'hipo_job_rollback_delete_redundant_rb_entries'),
208 'function_call' => Array(
209 'process_function' =>
'deleteRedundantRollbackEntries',
211 'running_mode' =>
'server',
213 'allow_cancel' => TRUE,
219 'name' => translate(
'hipo_job_rollback_completing_db_transaction'),
220 'function_call' => Array(
221 'process_function' =>
'completeTransaction',
223 'running_mode' =>
'server',
225 'allow_cancel' => FALSE,
259 require SQ_DATA_PATH.
'/private/db/table_columns.inc';
261 $this->_running_vars[
'rollback_table_columns'] = $tables;
262 $this->_running_vars[
'rollback_table_names'] = get_rollback_table_names();
263 $this->_running_vars[
'start_job'] = TRUE;
265 return parent::prepare();
337 if (($this->_running_vars[
'enable_rollback']) || ($this->_running_vars[
'disable_rollback'])) {
340 include_once(SQ_INCLUDE_PATH.
'/system_config.inc');
342 if (!$system_conf->canAcquireLock()) {
343 trigger_localised_error(
'CORE0233', E_USER_NOTICE);
348 $enable_rollback = (($this->_running_vars[
'enable_rollback']) ?
'1' :
'0');
350 $system_conf->acquireLock();
351 $saved = $system_conf->save(Array(
'SQ_CONF_ROLLBACK_ENABLED' => $enable_rollback), FALSE, FALSE);
352 $system_conf->releaseLock();
357 $step_data[
'percent_done'] = 100;
358 $step_data[
'complete'] = TRUE;
379 if (($this->_running_vars[
'enable_rollback']) || ($this->_running_vars[
'disable_rollback'])) {
384 require_once SQ_SYSTEM_ROOT.
'/install/install.inc';
385 require_once SQ_LIB_PATH.
'/db_install/db_install.inc';
386 require_once SQ_INCLUDE_PATH.
'/system_config.inc';
387 require_once SQ_LIB_PATH.
'/file_versioning/file_versioning.inc';
388 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
390 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
392 $cached_table_columns = Array();
394 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
395 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
397 install_stored_relations(
'functions');
399 if (file_exists(SQ_DATA_PATH.
'/private/db/table_columns.inc')) {
400 unlink(SQ_DATA_PATH.
'/private/db/table_columns.inc');
403 if (!db_install(SQ_CORE_PACKAGE_PATH.
'/tables.xml')) {
404 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
405 trigger_error(
'TABLE INSTALL FAILURE', E_USER_ERROR);
409 $packages = get_package_list();
411 foreach ($packages as $package) {
412 $xml_file = SQ_PACKAGES_PATH.
'/'.$package.
'/tables.xml';
413 if (file_exists($xml_file)) {
414 if (!db_install($xml_file)) {
415 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
416 trigger_error(
'TABLE INSTALL FAILURE', E_USER_ERROR);
418 install_stored_relations(
'functions', $package);
422 install_stored_relations(
'views');
425 grant_secondary_user_perms();
427 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
429 if (!$fv->initRepository()) {
430 trigger_error(
'Unable to initialise File Versioning Repository', E_USER_ERROR);
435 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
436 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
437 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
442 $step_data[
'percent_done'] = 100;
443 $step_data[
'complete'] = TRUE;
461 $step_data[
'percent_done'] = 100;
462 $step_data[
'complete'] = TRUE;
465 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
466 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
484 if (!empty($this->_running_vars[
'purge_fv_date'])) {
485 if ($this->_running_vars[
'start_job']) {
486 $this->_running_vars[
'start_job'] = FALSE;
490 $affected_rows = purge_file_versioning($this->_running_vars[
'purge_fv_date'], 50);
492 if ($affected_rows == 0) {
493 $step_data[
'percent_done'] = 100;
494 $step_data[
'complete'] = TRUE;
495 $this->_running_vars[
'start_job'] = TRUE;
501 $step_data[
'percent_done'] = 50;
502 $step_data[
'complete'] = FALSE;
505 $step_data[
'percent_done'] = 100;
506 $step_data[
'complete'] = TRUE;
507 $this->_running_vars[
'start_job'] = TRUE;
526 if ($this->_running_vars[
'reset_rollback']) {
527 if ($this->_running_vars[
'start_job']) {
528 $this->_running_vars[
'start_job'] = FALSE;
529 $this->_running_vars[
'to_check'] = $this->_running_vars[
'rollback_table_names'];
532 if (!empty($this->_running_vars[
'to_check'])) {
533 reset($this->_running_vars[
'to_check']);
534 list($key, $table_name) = each($this->_running_vars[
'to_check']);
535 unset($this->_running_vars[
'to_check'][$key]);
537 $step_data[
'message'] = translate(
'hipo_job_rollback_truncating_rb_entries_in', $table_name);
538 truncate_rollback_entries($table_name);
541 if (empty($this->_running_vars[
'to_check'])) {
542 $step_data[
'percent_done'] = 100;
543 $step_data[
'complete'] = TRUE;
544 $this->_running_vars[
'start_job'] = TRUE;
546 $step_data[
'percent_done'] = (int)(((count($this->_running_vars[
'rollback_table_names']) - count($this->_running_vars[
'to_check'])) / count($this->_running_vars[
'rollback_table_names'])) * 100);
547 $step_data[
'complete'] = FALSE;
550 $step_data[
'percent_done'] = 100;
551 $step_data[
'complete'] = TRUE;
552 $this->_running_vars[
'start_job'] = TRUE;
571 if ($this->_running_vars[
'start_job']) {
572 $this->_running_vars[
'start_job'] = FALSE;
573 $this->_running_vars[
'to_check'] = $this->_running_vars[
'rollback_table_names'];
575 if ($this->_running_vars[
'enable_rollback']) {
576 $rbfound = rollback_found($this->_running_vars[
'to_check']);
578 $step_data[
'percent_done'] = 100;
579 $step_data[
'complete'] = TRUE;
580 $this->_running_vars[
'start_job'] = TRUE;
588 if ((!empty($this->_running_vars[
'to_check'])) && (($this->_running_vars[
'enable_rollback']) || ($this->_running_vars[
'disable_rollback']))) {
589 reset($this->_running_vars[
'to_check']);
590 list($key, $table_name) = each($this->_running_vars[
'to_check']);
591 unset($this->_running_vars[
'to_check'][$key]);
593 if ($this->_running_vars[
'enable_rollback']) {
594 $step_data[
'message'] = translate(
'hipo_job_rollback_opening_rb_entries_in', $table_name);
595 open_rollback_entries($table_name, $this->_running_vars[
'rollback_table_columns'], $this->_running_vars[
'rollback_date']);
596 }
else if ($this->_running_vars[
'disable_rollback']) {
597 $step_data[
'message'] = translate(
'hipo_job_rollback_closing_rb_entries_in', $table_name);
598 close_rollback_entries($table_name, $this->_running_vars[
'rollback_date']);
601 if (empty($this->_running_vars[
'to_check'])) {
602 $step_data[
'percent_done'] = 100;
603 $step_data[
'complete'] = TRUE;
604 $this->_running_vars[
'start_job'] = TRUE;
608 $step_data[
'percent_done'] = (int)(((count($this->_running_vars[
'rollback_table_names']) - count($this->_running_vars[
'to_check'])) / count($this->_running_vars[
'rollback_table_names'])) * 100);
609 $step_data[
'complete'] = FALSE;
612 $step_data[
'percent_done'] = 100;
613 $step_data[
'complete'] = TRUE;
614 $this->_running_vars[
'start_job'] = TRUE;
633 if (!empty($this->_running_vars[
'purge_rb_date'])) {
634 if ($this->_running_vars[
'start_job']) {
635 $this->_running_vars[
'start_job'] = FALSE;
636 $this->_running_vars[
'to_check'] = $this->_running_vars[
'rollback_table_names'];
639 reset($this->_running_vars[
'to_check']);
640 list($key, $table_name) = each($this->_running_vars[
'to_check']);
641 unset($this->_running_vars[
'to_check'][$key]);
644 $step_data[
'message'] = translate(
'hipo_job_rollback_deleting_rb_entries_from', $table_name);
645 $affected_rows = delete_rollback_entries($table_name, $this->_running_vars[
'purge_rb_date']);
648 if (empty($this->_running_vars[
'to_check'])) {
649 $step_data[
'percent_done'] = 100;
650 $step_data[
'complete'] = TRUE;
651 $this->_running_vars[
'start_job'] = TRUE;
654 $step_data[
'percent_done'] = (int)(((count($this->_running_vars[
'rollback_table_names']) - count($this->_running_vars[
'to_check'])) / count($this->_running_vars[
'rollback_table_names'])) * 100);
656 $step_data[
'complete'] = FALSE;
659 $step_data[
'percent_done'] = 100;
660 $step_data[
'complete'] = TRUE;
661 $this->_running_vars[
'start_job'] = TRUE;
680 if (!empty($this->_running_vars[
'purge_rb_date'])) {
681 if ($this->_running_vars[
'start_job']) {
682 $this->_running_vars[
'start_job'] = FALSE;
683 $this->_running_vars[
'to_check'] = $this->_running_vars[
'rollback_table_names'];
686 reset($this->_running_vars[
'to_check']);
687 list($key, $table_name) = each($this->_running_vars[
'to_check']);
688 unset($this->_running_vars[
'to_check'][$key]);
691 $affected_rows = align_rollback_entries($table_name, $this->_running_vars[
'purge_rb_date']);
692 $step_data[
'message'] = translate(
'hipo_job_rollback_aligning_rb_entries_in', $table_name);
695 if (empty($this->_running_vars[
'to_check'])) {
696 $step_data[
'percent_done'] = 100;
697 $step_data[
'complete'] = TRUE;
698 $this->_running_vars[
'start_job'] = TRUE;
701 $step_data[
'percent_done'] = (int)(((count($this->_running_vars[
'rollback_table_names']) - count($this->_running_vars[
'to_check'])) / count($this->_running_vars[
'rollback_table_names'])) * 100);
703 $step_data[
'complete'] = FALSE;
706 $step_data[
'percent_done'] = 100;
707 $step_data[
'complete'] = TRUE;
708 $this->_running_vars[
'start_job'] = TRUE;
727 if (!empty($this->_running_vars[
'delete_redundant_entries'])) {
728 if ($this->_running_vars[
'start_job']) {
729 $this->_running_vars[
'start_job'] = FALSE;
730 $this->_running_vars[
'to_check'] = $this->_running_vars[
'rollback_table_names'];
733 if (!empty($this->_running_vars[
'to_check'])) {
734 reset($this->_running_vars[
'to_check']);
735 list($key, $table_name) = each($this->_running_vars[
'to_check']);
736 unset($this->_running_vars[
'to_check'][$key]);
738 $step_data[
'message'] = translate(
'hipo_job_rollback_delete_redundant_rb_entries_in', $table_name);
739 delete_redundant_rollback_entries($table_name);
743 if (empty($this->_running_vars[
'to_check'])) {
744 $step_data[
'percent_done'] = 100;
745 $step_data[
'complete'] = TRUE;
746 $this->_running_vars[
'start_job'] = TRUE;
748 $step_data[
'percent_done'] = (int)(((count($this->_running_vars[
'rollback_table_names']) - count($this->_running_vars[
'to_check'])) / count($this->_running_vars[
'rollback_table_names'])) * 100);
749 $step_data[
'complete'] = FALSE;
752 $step_data[
'percent_done'] = 100;
753 $step_data[
'complete'] = TRUE;
754 $this->_running_vars[
'start_job'] = TRUE;
773 $step_data[
'percent_done'] = 100;
774 $step_data[
'complete'] = TRUE;
777 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
778 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();