Backup and Restore WordPress – WPBackItUp Backup Plugin - Version 1.14.6

Version Description

*Release Date - July 15, 2017

  • FIX: Fix issues with cleanup processor causing jobs fail
  • FIX: Fix CSS causing UI issues for certain themes
Download this release

Release Info

Developer cssimmon
Plugin Icon 128x128 Backup and Restore WordPress – WPBackItUp Backup Plugin
Version 1.14.6
Comparing to
See all releases

Code changes from version 1.14.5 to 1.14.6

css/wp-backitup-admin.min.css CHANGED
@@ -1 +1 @@
1
- .error{color:red}.warning{color:#feefb3}.wpbackitup-warning{color:#ff8000}.isa_cancelled,.isa_error,.isa_info,.isa_success,.isa_warning{border:1px solid;margin:10px 0;padding:15px 10px 15px 50px;background-repeat:no-repeat;background-position:10px center;-moz-border-radius:.5em;-webkit-border-radius:.5em;border-radius:.5em}.isa_info{color:#00529b;background-color:#bde5f8;background-image:url(../images/info.png)}.isa_success{color:#4f8a10;background-color:#dff2bf;background-image:url(../images/success.png)}.isa_warning{color:#9f6000;background-color:#feefb3;background-image:url(../images/warning.png)}.isa_error{color:#d8000c;background-color:#ffbaba;background-image:url(../images/error.png)}.isa_cancelled{color:#9f6000;background-color:#feefb3;background-image:url(../images/warning.png)}p{line-height:1.4em}td{padding:0}h3{margin:0;padding:0;border-bottom:1px solid #eee}.wp-backitup-iframe{height:0;margin:0;padding:0;position:absolute;top:0;right:0;width:0;z-index:-1}.submit{padding:0}.notice-error,.notice-success,.notice-warning{background-repeat:no-repeat;margin:10px 20px 2px!important;padding:15px 10px 15px 50px;background-repeat:no-repeat;background-position:10px center}.notice-error{border-color:#d8000c;background-image:url(../images/error.png)}.notice-success{border-color:#7ad03a;background-image:url(../images/success.png)}.notice-warning{border-color:#9f6000;background-image:url(../images/warning.png)}#wp-backitup-notification-widget-close{cursor:pointer}.wpbackitup-get-premium{color:#d54e21}#content{float:left;width:65%}#content input[type=file],#content input[type=text]{padding:0}.status-icon{display:inline;height:16px;position:relative;top:3px;left:5px;visibility:hidden;width:16px}.backup-cancelled,.backup-error,.backup-errors,.backup-errors div,.backup-status,.backup-status span,.backup-success,.backup-success div,.backup-warning,.backup-warning div,.restore-errors,.restore-errors div,.restore-status,.restore-status span,.restore-success,.restore-success div,.upload-status,.upload-status span{display:none}#sidebar{float:right;width:30%}.widget{padding:1em;background-color:#fff;margin:20px}.cancel-hidden{display:none!important}.filters p label{display:block}ul.tagit{padding:1px 5px;overflow:auto;margin-left:inherit;margin-right:inherit}ul.tagit li{display:block;float:left;margin:2px 5px 2px 0}ul.tagit li.tagit-choice{position:relative;line-height:inherit}input.tagit-hidden-field{display:none}ul.tagit li.tagit-choice-read-only{padding:.2em .5em .2em .5em}ul.tagit li.tagit-choice-editable{padding:.2em 18px .2em .5em}ul.tagit li.tagit-new{padding:.25em 4px .25em 0}ul.tagit li.tagit-choice a.tagit-label{cursor:pointer;text-decoration:none}ul.tagit li.tagit-choice .tagit-close{cursor:pointer;position:absolute;right:.1em;top:50%;margin-top:-8px;line-height:17px}ul.tagit li.tagit-choice .tagit-close .text-icon{display:none}ul.tagit li.tagit-choice input{display:block;float:left;margin:2px 5px 2px 0}ul.tagit input[type=text]{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;border:none;margin:0;padding:0;width:inherit;background-color:inherit;outline:0}.dbfilters_section{overflow:hidden;clear:both;margin-top:-20px}.dbfilters_section h4{margin-bottom:2px}.dbfilters_section_left,.dbfilters_section_right{float:left;width:302px;margin-right:10px}.wpbackitup_connectedSortable{border:1px solid #eee;width:100%;min-height:20px;list-style-type:none;margin:0;padding:5px 0 0 0}.wpbackitup_connectedSortable li{margin:0 5px 5px 5px;padding:5px;font-size:1.2em;width:280px}.word-capitalize{text-transform:capitalize}.wpb-badge{position:absolute;right:0;top:0;background:url(../images/wpbackitup-logo.png) center top no-repeat;color:#32828b;display:inline-block;font-size:14px;font-weight:600;height:40px;margin:5px 0 0;padding-top:132px;text-align:center;text-rendering:optimizelegibility;width:150px}.success-grid{color:#4f8a10;background-color:#dff2bf;font-weight:700}.wpbackitup-topbar{position:relative;top:20px;overflow:hidden;clear:both;margin:0;width:98%;min-width:255px;padding:10px;background:#ddd none repeat scroll 0 0;border-radius:15px}.wpbackitup-topbar a,.wpbackitup-topbar h2{float:left;margin-left:5px;margin-right:25px}.wpbackitup-topbar h2{font-size:25px;font-weight:600}.wpbiu-button{float:right!important;margin-right:15px!important;margin-top:10px!important;margin-top:15px!important}#import-uploads{display:none}#import-uploads.button-secondary{margin-top:12px;background:#42b8dd!important;color:#fff!important}#import-uploads.button-secondary:hover{background:#45bce4!important;border-color:#aaa!important}.wpbiu-notes{overflow:hidden}.wpbiu-notes textarea{width:100%;height:60px;padding:5px}.wpbiu-notes button{width:15%;margin:5px 0!important}.wpbiu-notes span{margin-left:10px;color:green;display:none}.wpbiu-select-box select{display:block;margin:10px 0;width:15%}.wpbiu-support-textarea{width:270px;height:100px}.wpbiu-form-input{padding:3px!important}.downloadbackuplink>i{margin-left:10px}@media only screen and (max-width :767px){#content{width:100%}.wpbiu-select-box select{width:40%}.wpbackitup-topbar h2{font-size:18px}.wpbiu-button{float:left!important}.wpbackitup-topbar{width:86%;padding:20px}.widefat thead{display:none}.widefat tbody td{display:block;padding:.6rem;margin-left:.4rem}.widefat td:before{content:attr(data-th);font-weight:700;display:inline-block;width:100%;margin-bottom:.3rem;margin-left:-.3rem}#TB_window{margin-left:-50%!important;width:100%!important}#TB_ajaxContent{width:95%!important;padding:10px}#sidebar{width:100%}.restoreRow{margin-top:-50px;display:block}#wpbackitup-plupload-modal{width:100%!important;margin:0!important}.wpbiu-support-textarea{width:95%}.wpbiu-form-input{width:95%}}@media only screen and (min-width :768px) and (max-width:1024px){#content{width:100%}.wpbiu-select-box select{width:40%}#sidebar{width:100%}}
1
+ .wpb-main .error{color:red}.wpb-main .warning{color:#feefb3}.wpb-main .wpbackitup-warning{color:#ff8000}.wpb-main .isa_cancelled,.wpb-main .isa_error,.wpb-main .isa_info,.wpb-main .isa_success,.wpb-main .isa_warning{border:1px solid;margin:10px 0;padding:15px 10px 15px 50px;background-repeat:no-repeat;background-position:10px center;-moz-border-radius:.5em;-webkit-border-radius:.5em;border-radius:.5em}.wpb-main .isa_info{color:#00529b;background-color:#bde5f8;background-image:url(../images/info.png)}.wpb-main .isa_success{color:#4f8a10;background-color:#dff2bf;background-image:url(../images/success.png)}.wpb-main .isa_warning{color:#9f6000;background-color:#feefb3;background-image:url(../images/warning.png)}.wpb-main .isa_error{color:#d8000c;background-color:#ffbaba;background-image:url(../images/error.png)}.wpb-main .isa_cancelled{color:#9f6000;background-color:#feefb3;background-image:url(../images/warning.png)}.wpb-main p{line-height:1.4em}.wpb-main h3{margin:0;padding:0;border-bottom:1px solid #eee}.wpb-main .wp-backitup-iframe{height:0;margin:0;padding:0;position:absolute;top:0;right:0;width:0;z-index:-1}.wpb-main .submit{padding:0}.wpb-main .notice-error,.wpb-main .notice-success,.wpb-main .notice-warning{background-repeat:no-repeat;margin:10px 20px 2px!important;padding:15px 10px 15px 50px;background-repeat:no-repeat;background-position:10px center}.wpb-main .notice-error{border-color:#d8000c;background-image:url(../images/error.png)}.wpb-main .notice-success{border-color:#7ad03a;background-image:url(../images/success.png)}.wpb-main .notice-warning{border-color:#9f6000;background-image:url(../images/warning.png)}#wp-backitup-notification-widget-close{cursor:pointer}.wpbackitup-get-premium{color:#d54e21}.wpb-main #content{float:left;width:65%}#content input[type=file],.wpb-main #content input[type=text]{padding:0}.wpb-main .status-icon{display:inline;height:16px;position:relative;top:3px;left:5px;visibility:hidden;width:16px}.wpb-main .backup-cancelled,.wpb-main .backup-error,.wpb-main .backup-errors,.wpb-main .backup-errors div,.wpb-main .backup-status,.wpb-main .backup-status span,.wpb-main .backup-success,.wpb-main .backup-success div,.wpb-main .backup-warning,.wpb-main .backup-warning div,.wpb-main .restore-errors,.wpb-main .restore-errors div,.wpb-main .restore-status,.wpb-main .restore-status span,.wpb-main .restore-success,.wpb-main .restore-success div,.wpb-main .upload-status,.wpb-main .upload-status span{display:none}.wpb-main #sidebar{float:right;width:30%}.wpb-main .widget{padding:1em;background-color:#fff;margin:20px}.wpb-main .cancel-hidden{display:none!important}.wpb-main .filters p label{display:block}.wpb-main ul.tagit{padding:1px 5px;overflow:auto;margin-left:inherit;margin-right:inherit}.wpb-main ul.tagit li{display:block;float:left;margin:2px 5px 2px 0}.wpb-main ul.tagit li.tagit-choice{position:relative;line-height:inherit}.wpb-main input.tagit-hidden-field{display:none}.wpb-main ul.tagit li.tagit-choice-read-only{padding:.2em .5em .2em .5em}.wpb-main ul.tagit li.tagit-choice-editable{padding:.2em 18px .2em .5em}.wpb-main ul.tagit li.tagit-new{padding:.25em 4px .25em 0}.wpb-main ul.tagit li.tagit-choice a.tagit-label{cursor:pointer;text-decoration:none}.wpb-main ul.tagit li.tagit-choice .tagit-close{cursor:pointer;position:absolute;right:.1em;top:50%;margin-top:-8px;line-height:17px}.wpb-main ul.tagit li.tagit-choice .tagit-close .text-icon{display:none}.wpb-main ul.tagit li.tagit-choice input{display:block;float:left;margin:2px 5px 2px 0}.wpb-main ul.tagit input[type=text]{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;border:none;margin:0;padding:0;width:inherit;background-color:inherit;outline:0}.wpb-main .dbfilters_section{overflow:hidden;clear:both;margin-top:-20px}.wpb-main .dbfilters_section h4{margin-bottom:2px}.dbfilters_section_right,.wpb-main .dbfilters_section_left{float:left;width:302px;margin-right:10px}.wpb-main .wpbackitup_connectedSortable{border:1px solid #eee;width:100%;min-height:20px;list-style-type:none;margin:0;padding:5px 0 0 0}.wpb-main .wpbackitup_connectedSortable li{margin:0 5px 5px 5px;padding:5px;font-size:1.2em;width:280px}.wpb-main .word-capitalize{text-transform:capitalize}.wpb-badge{position:absolute;right:0;top:0;background:url(../images/wpbackitup-logo.png) center top no-repeat;color:#32828b;display:inline-block;font-size:14px;font-weight:600;height:40px;margin:5px 0 0;padding-top:132px;text-align:center;text-rendering:optimizelegibility;width:150px}.wpb-main .success-grid{color:#4f8a10;background-color:#dff2bf;font-weight:700}.wpbackitup-topbar{position:relative;top:20px;overflow:hidden;clear:both;margin:0;width:98%;min-width:255px;padding:10px;background:#ddd none repeat scroll 0 0;border-radius:15px}.wpbackitup-topbar a,.wpbackitup-topbar h2{float:left;margin-left:5px;margin-right:25px}.wpbackitup-topbar h2{font-size:25px;font-weight:600}.wpbiu-button{float:right!important;margin-right:15px!important;margin-top:10px!important;margin-top:15px!important}.wpb-main #import-uploads{display:none}.wpb-main #import-uploads.button-secondary{margin-top:12px;background:#42b8dd!important;color:#fff!important}.wpb-main #import-uploads.button-secondary:hover{background:#45bce4!important;border-color:#aaa!important}.wpbiu-notes{overflow:hidden}.wpbiu-notes textarea{width:100%;height:60px;padding:5px}.wpbiu-notes button{width:15%;margin:5px 0!important}.wpbiu-notes span{margin-left:10px;color:green;display:none}.wpbiu-select-box select{display:block;margin:10px 0;width:15%}.wpbiu-support-textarea{width:270px;height:100px}.wpbiu-form-input{padding:3px!important}.wpb-main .downloadbackuplink>i{margin-left:10px}@media only screen and (max-width :767px){.wpb-main #content{width:100%}.wpbiu-select-box select{width:40%}.wpbackitup-topbar h2{font-size:18px}.wpbiu-button{float:left!important}.wpbackitup-topbar{width:86%;padding:20px}.wpb-main .widefat thead{display:none}.wpb-main .widefat tbody td{display:block;padding:.6rem;margin-left:.4rem}.wpb-main .widefat td:before{content:attr(data-th);font-weight:700;display:inline-block;width:100%;margin-bottom:.3rem;margin-left:-.3rem}.wpb-main #TB_window{margin-left:-50%!important;width:100%!important}.wpb-main #TB_ajaxContent{width:95%!important;padding:10px}.wpb-main #sidebar{width:100%}.wpb-main .restoreRow{margin-top:-50px;display:block}#wpbackitup-plupload-modal{width:100%!important;margin:0!important}.wpbiu-support-textarea{width:95%}.wpbiu-form-input{width:95%}}@media only screen and (min-width :768px) and (max-width:1024px){.wpb-main #content{width:100%}.wpbiu-select-box select{width:40%}.wpb-main #sidebar{width:100%}}
lib/background-processing/class-cleanup-processor.php CHANGED
@@ -33,21 +33,28 @@ class WPBackItUp_Cleanup_Processor extends WPBackItUp_Background_Process {
33
  * Cleanup tasks are handled here.
34
  * Each item is a different task. This handler will handle all cleanup tasks.
35
  *
36
- * @param mixed $item Queue item to iterate over
37
  *
38
  * @return mixed False when task is complete|return updated item for further processing
39
  */
40
- protected function task( $item ) {
 
 
 
 
 
 
 
41
 
42
  // method need to be triggered.
43
- $hook_name = sprintf('wpbackitup_cleanup_%s', $item);
44
  WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME,__METHOD__, 'Cleanup task - method to be triggered: '. $hook_name);
45
 
46
  if(has_action($hook_name)) {
47
- do_action($hook_name);
48
  WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME, __METHOD__, 'Hook should be triggered');
49
  }else{
50
- WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME, __METHOD__, 'Hook is not available');
51
  }
52
 
53
  return false;
33
  * Cleanup tasks are handled here.
34
  * Each item is a different task. This handler will handle all cleanup tasks.
35
  *
36
+ * @param mixed $task_id Queue item to iterate over
37
  *
38
  * @return mixed False when task is complete|return updated item for further processing
39
  */
40
+ protected function task( $task_id ) {
41
+
42
+ //get task by id
43
+ $task = WPBackItUp_Job_Task::get_task_by_id($task_id);
44
+ if (false===$task) {
45
+ WPBackItUp_Logger::log_error(self::CLEANUP_LOG_NAME, __METHOD__, 'Task not found:'. var_export($task,true));
46
+ return false;
47
+ }
48
 
49
  // method need to be triggered.
50
+ $hook_name = str_replace ('task','wpbackitup_cleanup', $task->getTaskName());
51
  WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME,__METHOD__, 'Cleanup task - method to be triggered: '. $hook_name);
52
 
53
  if(has_action($hook_name)) {
54
+ do_action($hook_name,$task);
55
  WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME, __METHOD__, 'Hook should be triggered');
56
  }else{
57
+ WPBackItUp_Logger::log_error(self::CLEANUP_LOG_NAME, __METHOD__, 'Hook is not available');
58
  }
59
 
60
  return false;
lib/background-processing/class-db-cleanup-processor.php DELETED
@@ -1,59 +0,0 @@
1
- <?php
2
-
3
- if( ! class_exists( 'WPBackItUp_Job' ) ) {
4
- include_once WPBACKITUP__PLUGIN_PATH . '/lib/includes/class-job.php';
5
- }
6
-
7
-
8
- /**
9
- * Handles database cleanup task processing for WPBackItUp
10
- *
11
- * This class will be called by the cleanup task processor
12
- *
13
- * @link http://www.wpbackitup.com
14
- * @since 1.14.3
15
- *
16
- */
17
-
18
- class WPBackItUp_DB_Cleanup_Processor extends WPBackItUp_Background_Process {
19
-
20
- //override prefix
21
- protected $prefix = 'wpbackitup';
22
-
23
- /**
24
- * @var string
25
- */
26
- protected $action = 'db_cleanup_process';
27
-
28
- const CLEANUP_LOG_NAME = 'debug_db_cleanup_processor';
29
-
30
- /**
31
- * Task
32
- *
33
- * Database cleanup tasks are handled here.
34
- * Each item is a different task. This handler will handle all cleanup tasks.
35
- *
36
- * @param mixed $item Queue item to iterate over
37
- *
38
- * @return mixed False when task is complete|return updated item for further processing
39
- */
40
- protected function task( $item ) {
41
- WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME,__METHOD__,'Job to be purged: ' . $item);
42
- if($item) {
43
- WPBackItUp_Job::delete_job_records($item);
44
- }
45
- return false;
46
-
47
- }
48
-
49
- /**
50
- * Complete
51
- *
52
- * Override if applicable, but ensure that the below actions are
53
- * performed, or, call parent::complete().
54
- */
55
- protected function complete() {
56
- parent::complete();
57
- }
58
-
59
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/includes/class-backup.php CHANGED
@@ -47,6 +47,15 @@ class WPBackItUp_Backup {
47
 
48
  //-------------END STATIC FUNCTIONS-------------------//
49
 
 
 
 
 
 
 
 
 
 
50
  function __construct($log_name,$backup_name, $backup_type) {
51
  global $WPBackitup;
52
  try {
@@ -72,6 +81,7 @@ class WPBackItUp_Backup {
72
 
73
  $this->backup_project_path=$backup_project_path;
74
  $this->backup_folder_root=$backup_folder_root;
 
75
  $this->restore_folder_root=$restore_folder_root;
76
 
77
  $this->backup_retained_number = $WPBackitup->backup_retained_number();
@@ -131,21 +141,25 @@ class WPBackItUp_Backup {
131
  * Delete backup folders by prefix
132
  * @param $prefix
133
  */
134
- public function cleanup_backups_by_prefix_async($prefix) {
135
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin' );
136
- $backup_root_path=$this->backup_folder_root;
137
 
138
  //get a list of all the temps
139
  $work_folder_list = glob($backup_root_path. $prefix .'*', GLOB_ONLYDIR);
140
 
141
- //If any folder were found
142
- if (count( $work_folder_list )>1){
143
-
144
- // push items to background processor
145
- global $WPBackitup;
146
- $WPBackitup->handle_async_task_queue(Processors::DIRECTORY_CLEANUP, $work_folder_list);
147
- WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Directory Cleanup job dispatched.');
148
-
 
 
 
 
149
  }
150
 
151
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End' );
@@ -156,10 +170,8 @@ class WPBackItUp_Backup {
156
  * - job control records are purged first so orphaned folders should be deleted.
157
  *
158
  */
159
- public function purge_orphaned_backups_async() {
160
 
161
- //initiate background processor
162
- $cleanup_processor = new WPBackItUp_Directory_Cleanup_Processor();
163
 
164
  // --PURGE BACKUP FOLDER
165
  $folder_list = glob($this->backup_folder_root . '*', GLOB_ONLYDIR);
@@ -168,23 +180,25 @@ class WPBackItUp_Backup {
168
 
169
  //Check for job control record
170
  $folder_name = basename($folder);
171
- $folder_name_parts = explode('_',$folder_name);
172
- $job_id = end($folder_name_parts);
173
  $job = WPBackItUp_Job::get_jobs_by_job_name(WPBackItUp_Job::BACKUP,$folder_name);
174
- //$job = WPBackItUp_Job::get_job_by_id($job_id);
175
 
176
  //If no jobs found then purge
177
  if(false===$job){
178
  if (file_exists($folder)) {
179
- $cleanup_processor->push_to_queue( $folder );
 
 
 
 
 
 
 
 
180
  }
181
  }
182
  }
183
 
184
- $cleanup_processor->save()->dispatch();
185
- WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Directory Cleanup job dispatched.');
186
-
187
- return true;
188
  }
189
 
190
  /**
@@ -208,7 +222,7 @@ class WPBackItUp_Backup {
208
  if (count( $file_list )>1){
209
 
210
  global $WPBackitup;
211
- $WPBackitup->handle_async_task_queue(Processors::FILE_CLEANUP, $file_list);
212
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Cleanup job dispatched.');
213
 
214
  }
@@ -225,8 +239,7 @@ class WPBackItUp_Backup {
225
  /**
226
  * Purge old backup files
227
  */
228
- public function purge_old_files_async(){
229
- // Todo:: convert purge_files to return a list of files to push in background cleanup queue.
230
 
231
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
232
  $fileSystem = new WPBackItUp_FileSystem( $this->log_name);
@@ -1169,7 +1182,7 @@ class WPBackItUp_Backup {
1169
  if (true===$backupset_found) {
1170
 
1171
  global $WPBackitup;
1172
- $WPBackitup->handle_async_task_queue(Processors::FILE_CLEANUP, $file_list);
1173
 
1174
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Cleanup support zips job dispatched.');
1175
  }
47
 
48
  //-------------END STATIC FUNCTIONS-------------------//
49
 
50
+ /**
51
+ * WPBackItUp_Backup constructor.
52
+ *
53
+ * @param $log_name
54
+ * @param string $backup_name
55
+ * @param string $backup_type
56
+ *
57
+ * @throws Exception
58
+ */
59
  function __construct($log_name,$backup_name, $backup_type) {
60
  global $WPBackitup;
61
  try {
81
 
82
  $this->backup_project_path=$backup_project_path;
83
  $this->backup_folder_root=$backup_folder_root;
84
+
85
  $this->restore_folder_root=$restore_folder_root;
86
 
87
  $this->backup_retained_number = $WPBackitup->backup_retained_number();
141
  * Delete backup folders by prefix
142
  * @param $prefix
143
  */
144
+ public function cleanup_backups_by_prefix($prefix) {
145
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin' );
146
+ $backup_root_path=$this->backup_folder_root;
147
 
148
  //get a list of all the temps
149
  $work_folder_list = glob($backup_root_path. $prefix .'*', GLOB_ONLYDIR);
150
 
151
+ //If any folders were found
152
+ if (count( $work_folder_list )>=1){
153
+
154
+ foreach ($work_folder_list as $folder){
155
+ $file_system = new WPBackItUp_FileSystem($this->log_name);
156
+ if(file_exists($folder)) {
157
+ $file_system->recursive_delete($folder);
158
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Directory Cleanup completed:' . $folder);
159
+ }else{
160
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Folder was not found:' . $folder);
161
+ }
162
+ }
163
  }
164
 
165
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End' );
170
  * - job control records are purged first so orphaned folders should be deleted.
171
  *
172
  */
173
+ public function purge_orphaned_backups() {
174
 
 
 
175
 
176
  // --PURGE BACKUP FOLDER
177
  $folder_list = glob($this->backup_folder_root . '*', GLOB_ONLYDIR);
180
 
181
  //Check for job control record
182
  $folder_name = basename($folder);
 
 
183
  $job = WPBackItUp_Job::get_jobs_by_job_name(WPBackItUp_Job::BACKUP,$folder_name);
 
184
 
185
  //If no jobs found then purge
186
  if(false===$job){
187
  if (file_exists($folder)) {
188
+
189
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Directory to be deleted: ' . $folder);
190
+
191
+ $file_system = new WPBackItUp_FileSystem($this->log_name);
192
+ if(file_exists($folder)) {
193
+ $file_system->recursive_delete($folder);
194
+ }else{
195
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Folder was not found:' . $folder);
196
+ }
197
  }
198
  }
199
  }
200
 
201
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Directory Cleanup job completed.');
 
 
 
202
  }
203
 
204
  /**
222
  if (count( $file_list )>1){
223
 
224
  global $WPBackitup;
225
+ $WPBackitup->dispatch_async_tasks(Processors::FILE_CLEANUP, $file_list);
226
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Cleanup job dispatched.');
227
 
228
  }
239
  /**
240
  * Purge old backup files
241
  */
242
+ public function purge_old_files(){
 
243
 
244
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
245
  $fileSystem = new WPBackItUp_FileSystem( $this->log_name);
1182
  if (true===$backupset_found) {
1183
 
1184
  global $WPBackitup;
1185
+ $WPBackitup->dispatch_async_tasks(Processors::FILE_CLEANUP, $file_list);
1186
 
1187
  WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Cleanup support zips job dispatched.');
1188
  }
lib/includes/class-cleanup.php CHANGED
@@ -25,211 +25,345 @@ if( !class_exists( 'WPBackItUp_Backup' ) ) {
25
  }
26
 
27
 
 
28
  class WPBackItUp_Cleanup {
29
 
30
- /**
31
- * @var array
32
- */
33
- public static $TASK_ITEMS = array(
34
- 'init',
35
- 'purge_job_control',
36
- 'purge_prefixed_folder_and_files',
37
- 'purge_orphan_folder_and_files',
38
- 'purge_old_files',
39
- 'secure_folders',
40
- 'end'
41
- );
42
 
43
- /**
44
- * @var string
45
- */
46
- private $cleanup_logname;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- /**
49
- * @var mixed
50
- */
51
- private $job;
52
 
53
- /**
54
- * @var string
55
- */
56
- private $job_name;
 
 
 
57
 
58
- /**
59
- * @var string
60
- */
61
- private $job_id;
62
 
63
- /**
64
- * @var string
65
- */
66
- private $job_type;
67
 
68
- /**
69
- * action init
70
- */
71
- public function init(){
72
- add_action( 'wpbackitup_cleanup_init', array( $this, 'wpbackitup_cleanup_init' ) );
73
- add_action( 'wpbackitup_cleanup_purge_job_control', array( $this, 'wpbackitup_cleanup_purge_job_control' ) );
74
- add_action( 'wpbackitup_cleanup_purge_prefixed_folder_and_files', array( $this, 'wpbackitup_cleanup_purge_prefixed_folder_and_files' ) );
75
- add_action( 'wpbackitup_cleanup_purge_orphan_folder_and_files', array( $this, 'wpbackitup_cleanup_purge_orphan_folder_and_files' ) );
76
- add_action( 'wpbackitup_cleanup_purge_old_files', array( $this, 'wpbackitup_cleanup_purge_old_files' ) );
77
- add_action( 'wpbackitup_cleanup_secure_folders', array( $this, 'wpbackitup_cleanup_secure_folders' ) );
78
- add_action( 'wpbackitup_cleanup_end', array( $this, 'wpbackitup_cleanup_end' ) );
79
- }
80
 
81
- /**
82
- * Cleanup init
83
- */
84
- public function wpbackitup_cleanup_init(){
85
- global $WPBackitup;
86
 
87
- $this->job_type= WPBackItUp_Job::CLEANUP;
88
- $this->job_id= current_time('timestamp');
89
- $this->job_name = sprintf('%s_%s',$this->job_type, $this->job_id);
90
- $this->cleanup_logname = sprintf('JobLog_%s', $this->job_name);
91
- $backup_retention = $WPBackitup->backup_retained_number();
92
- $job_tasks = WPBackItUp_Job::get_job_tasks($this->job_type);
93
 
94
- $this->job = WPBackItUp_Job::queue_job($this->job_name,$this->job_id, $this->job_type, WPBackItUp_Job::SCHEDULED,$job_tasks);
 
95
 
96
- WPBackItUp_Logger::log($this->cleanup_logname,'***BEGIN JOB***');
97
- WPBackItUp_Logger::log_sysinfo($this->cleanup_logname);
98
 
99
- WPBackItUp_Logger::log($this->cleanup_logname,'Backup Retention:' .$backup_retention);
100
 
101
- //Check License
102
- WPBackItUp_Logger::log($this->cleanup_logname,'**CHECK LICENSE**');
103
- do_action( 'wpbackitup_check_license');
104
- WPBackItUp_Logger::log($this->cleanup_logname,'**END CHECK LICENSE**');
105
  }
106
 
 
 
 
 
 
 
 
107
 
108
- /**
109
- * purge job control
110
- */
111
- public function wpbackitup_cleanup_purge_job_control(){
112
- global $WPBackitup;
113
- $backup_retention = $WPBackitup->backup_retained_number();
114
 
115
- // Purge post and post meta
116
- WPBackItUp_Logger::log($this->cleanup_logname,'**CLEANUP JOB CONTROL RECORDS**' );
117
 
118
- $backup_job_purge_count = WPBackItUp_Job::purge_jobs_async( WPBackItUp_Job::BACKUP,$backup_retention);
119
- WPBackItUp_Logger::log($this->cleanup_logname,'Backup job control records purged:' .$backup_job_purge_count );
120
 
121
- $cleanup_job_purge_count = WPBackItUp_Job::purge_jobs_async( WPBackItUp_Job::CLEANUP,2);
122
- WPBackItUp_Logger::log_info($this->cleanup_logname,__METHOD__,'Cleanup job control records purged:' .$cleanup_job_purge_count );
 
123
 
124
- WPBackItUp_Logger::log($this->cleanup_logname,'**END CLEANUP JOB CONTROL RECORDS**' );
 
 
 
 
 
 
 
 
 
 
125
  }
126
 
127
  /**
128
- * purge prefixed folders and files.
 
 
129
  */
130
- public function wpbackitup_cleanup_purge_prefixed_folder_and_files(){
131
- global $WPBackitup;
132
  global $wp_backup;
133
- $wp_backup = new WPBackItUp_Backup($this->cleanup_logname,$this->job_name,$WPBackitup->backup_type);
134
 
135
- WPBackItUp_Logger::log($this->cleanup_logname,'**CLEAN UNFINISHED BACKUPS**' );
 
136
 
137
- //cleanup any folders that have the TMP_ prefix
138
- $wp_backup->cleanup_backups_by_prefix_async('TMP_');
139
- WPBackItUp_Logger::log($this->cleanup_logname,'**END CLEAN UNFINISHED BACKUPS**' );
140
 
141
- WPBackItUp_Logger::log($this->cleanup_logname,'**CLEAN DELETED BACKUPS**' );
142
- //cleanup any folders that have the DLT_ prefix
143
- $wp_backup->cleanup_backups_by_prefix_async('DLT_');
 
144
 
145
- WPBackItUp_Logger::log($this->cleanup_logname,'**END CLEAN DELETED BACKUPS**' );
146
- }
147
 
148
- /**
149
- * purge orphan folder and files.
150
- */
151
- public function wpbackitup_cleanup_purge_orphan_folder_and_files(){
152
- global $WPBackitup;
153
- global $wp_backup;
154
- $wp_backup = new WPBackItUp_Backup($this->cleanup_logname,$this->job_name,$WPBackitup->backup_type);
155
 
156
- //Purge orphaned backup folders - folders with no job control record
157
- WPBackItUp_Logger::log($this->cleanup_logname,'**CLEAN OLD BACKUPS**' );
158
- $wp_backup->purge_orphaned_backups_async();
159
- WPBackItUp_Logger::log($this->cleanup_logname,'**END CLEAN OLD BACKUPS**' );
 
 
160
 
 
161
 
162
- //remove all the old restore folders
163
- if( class_exists( 'WPBackItUp_Premium_Restore' ) ) {
164
- WPBackItUp_Logger::log($this->cleanup_logname,'**CLEAN OLD RESTORES**' );
165
- $wp_restore = new WPBackItUp_Premium_Restore($this->cleanup_logname,$this->job_name,null);
166
- $wp_restore->delete_restore_folder_async();
167
- WPBackItUp_Logger::log($this->cleanup_logname,'**END CLEAN OLD RESTORES**' );
168
  }
169
  }
170
 
171
  /**
172
  * purge old files
 
173
  */
174
- public function wpbackitup_cleanup_purge_old_files(){
175
  global $wp_backup;
176
 
177
- WPBackItUp_Logger::log($this->cleanup_logname,'**PURGE OLD FILES**' );
 
 
 
 
 
 
178
 
179
- // purge old files from the backup and logs folders - this is NOT for backups
180
- $wp_backup->purge_old_files_async();
 
 
 
 
 
 
 
 
 
 
181
 
182
- WPBackItUp_Logger::log($this->cleanup_logname,'**END PURGE OLD FILES**' );
 
 
 
 
 
 
 
183
  }
184
 
185
  /**
186
  * Secure folders
 
 
187
  */
188
- public function wpbackitup_cleanup_secure_folders(){
189
- WPBackItUp_Logger::log($this->cleanup_logname,'**SECURE FOLDERS**' );
190
- $file_system = new WPBackItUp_FileSystem($this->cleanup_logname);
 
191
 
192
- //Make sure backup folder is secured
193
- $backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
194
- $file_system->secure_folder( $backup_dir);
195
 
196
- //--Check restore folder folders
197
- $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
198
- $file_system->secure_folder( $restore_dir);
199
 
200
- //Make sure logs folder is secured
201
- $logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs/';
202
- $file_system->secure_folder( $logs_dir);
203
 
204
- WPBackItUp_Logger::log($this->cleanup_logname,'**END SECURE FOLDERS**' );
 
 
 
 
 
 
 
 
 
 
205
  }
206
 
207
  /**
208
- * end
 
 
209
  */
210
- public function wpbackitup_cleanup_end(){
211
  global $WPBackitup;
212
- $success=99;
213
 
214
- $this->job->setStatus(WPBackItUp_Job::COMPLETE);
 
 
 
215
 
216
- WPBackItUp_Logger::log_info($this->cleanup_logname,__METHOD__,'Begin');
 
 
217
 
218
- $current_datetime = current_time( 'timestamp' );
219
- $WPBackitup->set_cleanup_lastrun_date($current_datetime);
220
 
221
- $util = new WPBackItUp_Utility($this->cleanup_logname);
222
- $seconds = $util->timestamp_diff_seconds($this->job->getJobStartTimeTimeStamp(),$this->job->getJobEndTimeTimeStamp());
223
 
224
- $processing_minutes = round($seconds / 60);
225
- $processing_seconds = $seconds % 60;
226
 
227
- WPBackItUp_Logger::log_info($this->cleanup_logname,__METHOD__,'Script Processing Time:' .$processing_minutes .' Minutes ' .$processing_seconds .' Seconds');
 
228
 
229
- if (true===$success) WPBackItUp_Logger::log($this->cleanup_logname,'Cleanup completed: SUCCESS');
230
- if (false===$success) WPBackItUp_Logger::log($this->cleanup_logname,'Cleanup completed: ERROR');
231
- WPBackItUp_Logger::log($this->cleanup_logname,'*** END JOB ***');
 
 
 
 
 
232
  }
233
 
234
 
 
 
 
235
  }
25
  }
26
 
27
 
28
+
29
  class WPBackItUp_Cleanup {
30
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ public static $CLEANUP_TASKS = array(
33
+ 'task_begin',
34
+ 'task_purge_job_control',
35
+ 'task_purge_prefixed_folder_and_files',
36
+ 'task_purge_orphan_folder_and_files',
37
+ 'task_purge_old_files',
38
+ 'task_secure_folders',
39
+ 'task_end'
40
+ );
41
+
42
+ const DEFAULT_LOG_NAME ='debug_cleanup';
43
+ private $log_name = self::DEFAULT_LOG_NAME;
44
+
45
+ /**
46
+ * WPBackItUp_Cleanup constructor.
47
+ */
48
+ function __construct() {
49
+
50
+ try{
51
+
52
+
53
+ } catch(Exception $e) {
54
+ error_log(var_export($e,true));
55
+ WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .var_export($e,true));
56
+ }
57
+
58
+ }
59
+
60
+ /**
61
+ * action init
62
+ */
63
+ public function init(){
64
+ add_action( 'wpbackitup_cleanup_begin', array( $this, 'begin_job' ));
65
+ add_action( 'wpbackitup_cleanup_purge_job_control', array( $this, 'purge_job_control'));
66
+ add_action( 'wpbackitup_cleanup_purge_prefixed_folder_and_files', array( $this,'purge_prefixed_folder_and_files'));
67
+ add_action( 'wpbackitup_cleanup_purge_orphan_folder_and_files', array( $this, 'purge_orphan_folder_and_files'));
68
+ add_action( 'wpbackitup_cleanup_purge_old_files', array( $this, 'purge_old_files' ) );
69
+ add_action( 'wpbackitup_cleanup_secure_folders', array( $this, 'secure_folders' ) );
70
+ add_action( 'wpbackitup_cleanup_end', array( $this, 'end' ) );
71
+ }
72
+
73
+ /**
74
+ * Queue Cleanup Job
75
+ *
76
+ * @return bool|WPBackItUp_Job
77
+ */
78
+ public static function queue_job(){
79
+
80
+ try {
81
+ $job_type= WPBackItUp_Job::CLEANUP;
82
+ $job_id= current_time('timestamp');
83
+ $job_name = sprintf('%s_%s',$job_type, $job_id);
84
+
85
+ $job_tasks = WPBackItUp_Job::get_job_tasks($job_type);
86
+ return WPBackItUp_Job::queue_job($job_name,$job_id, $job_type, WPBackItUp_Job::SCHEDULED,$job_tasks);
87
+
88
+ } catch(Exception $e) {
89
+ WPBackItUp_Logger::log_error(self::DEFAULT_LOG_NAME,__METHOD__,'Constructor Exception: ' .var_export($e,true));
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Get log name
95
+ *
96
+ * @param WPBackItUp_Job_Task $task
97
+ *
98
+ * @return string
99
+ */
100
+ private function set_job_log($task){
101
+
102
+ try {
103
+
104
+ //default logname is set already
105
+ if (is_object($task)) {
106
+ $this->log_name = sprintf( 'JobLog_%s_%s', WPBackItUp_Job::CLEANUP, $task->getJobId() );
107
+ }
108
+
109
+ } catch(Exception $e) {
110
+ WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .var_export($e,true));
111
+ }
112
+ }
113
+
114
+
115
+ /**
116
+ * Cleanup init
117
+ *
118
+ * @param WPBackItUp_Job_Task $task
119
+ *
120
+ */
121
+ public function begin_job($task){
122
+
123
+ try{
124
+
125
+ $this->set_job_log($task);
126
+
127
+ WPBackItUp_Logger::log($this->log_name,'***BEGIN JOB***');
128
+ $job_id = $task->getJobId();
129
+ $job = WPBackItUp_Job::get_job_by_id($job_id);
130
+ $job->setStatus(WPBackItUp_Job::ACTIVE);
131
+
132
+ WPBackItUp_Logger::log_sysinfo($this->log_name);
133
+
134
+ //Check License
135
+ WPBackItUp_Logger::log($this->log_name,'**CHECK LICENSE**');
136
+ do_action( 'wpbackitup_check_license');
137
+ WPBackItUp_Logger::log($this->log_name,'**END CHECK LICENSE**');
138
+
139
+ $task->setStatus(WPBackItUp_Job_Task::COMPLETE);
140
+
141
+ }catch(Exception $e) {
142
+ WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .var_export($e,true));
143
+ $task->setStatus(WPBackItUp_Job_Task::ERROR);
144
+ }
145
+ }
146
 
 
 
 
 
147
 
148
+ /**
149
+ * purge job control
150
+ *
151
+ * @param WPBackItUp_Job_Task $task
152
+ */
153
+ public function purge_job_control($task){
154
+ global $WPBackitup;
155
 
156
+ try {
 
 
 
157
 
158
+ $this->set_job_log($task);
 
 
 
159
 
160
+ $backup_retention = $WPBackitup->backup_retained_number();
161
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Backup Retention:' .$WPBackitup->backup_retained_number());
 
 
 
 
 
 
 
 
 
 
162
 
163
+ // Purge post and post meta
164
+ WPBackItUp_Logger::log($this->log_name,'**CLEANUP JOB CONTROL RECORDS**' );
 
 
 
165
 
166
+ $backup_job_purge_count = WPBackItUp_Job::purge_jobs( WPBackItUp_Job::BACKUP,$backup_retention);
167
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Backup job control records purged:' .$backup_job_purge_count );
 
 
 
 
168
 
169
+ $cleanup_job_purge_count = WPBackItUp_Job::purge_jobs( WPBackItUp_Job::CLEANUP,2);
170
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Cleanup job control records purged:' .$cleanup_job_purge_count );
171
 
172
+ WPBackItUp_Logger::log($this->log_name,'**END CLEANUP JOB CONTROL RECORDS**' );
 
173
 
174
+ $task->setStatus(WPBackItUp_Job_Task::COMPLETE);
175
 
176
+ }catch(Exception $e) {
177
+ WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .var_export($e,true));
178
+ $task->setStatus(WPBackItUp_Job_Task::ERROR);
179
+ }
180
  }
181
 
182
+ /**
183
+ * purge prefixed folders and files.
184
+ *
185
+ * @param WPBackItUp_Job_Task $task
186
+ */
187
+ public function purge_prefixed_folder_and_files($task){
188
+ global $wp_backup;
189
 
190
+ try {
191
+
192
+ $this->set_job_log($task);
 
 
 
193
 
194
+ $wp_backup = new WPBackItUp_Backup($this->log_name,'not_used',WPBackItUp_Job::SCHEDULED);
 
195
 
196
+ WPBackItUp_Logger::log($this->log_name,'**CLEAN UNFINISHED BACKUPS**' );
 
197
 
198
+ //cleanup any folders that have the TMP_ prefix
199
+ $wp_backup->cleanup_backups_by_prefix('TMP_');
200
+ WPBackItUp_Logger::log($this->log_name,'**END CLEAN UNFINISHED BACKUPS**' );
201
 
202
+ WPBackItUp_Logger::log($this->log_name,'**CLEAN DELETED BACKUPS**' );
203
+ //cleanup any folders that have the DLT_ prefix
204
+ $wp_backup->cleanup_backups_by_prefix('DLT_');
205
+
206
+ WPBackItUp_Logger::log($this->log_name,'**END CLEAN DELETED BACKUPS**' );
207
+ $task->setStatus(WPBackItUp_Job_Task::COMPLETE);
208
+
209
+ } catch(Exception $e) {
210
+ WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .var_export($e,true));
211
+ $task->setStatus(WPBackItUp_Job_Task::ERROR);
212
+ }
213
  }
214
 
215
  /**
216
+ * purge orphan folder and files.
217
+ *
218
+ * @param WPBackItUp_Job_Task $task
219
  */
220
+ public function purge_orphan_folder_and_files($task){
 
221
  global $wp_backup;
 
222
 
223
+ try {
224
+ $this->set_job_log($task);
225
 
226
+ $wp_backup = new WPBackItUp_Backup($this->log_name,'not_used',WPBackItUp_Job::SCHEDULED);
 
 
227
 
228
+ //Purge orphaned backup folders - folders with no job control record
229
+ WPBackItUp_Logger::log($this->log_name,'**CLEAN OLD BACKUPS**' );
230
+ $wp_backup->purge_orphaned_backups();
231
+ WPBackItUp_Logger::log($this->log_name,'**END CLEAN OLD BACKUPS**' );
232
 
 
 
233
 
234
+ //remove all the old restore folders
235
+ if( class_exists( 'WPBackItUp_Premium_Restore' ) ) {
236
+ WPBackItUp_Logger::log($this->log_name,'**CLEAN OLD RESTORES**' );
237
+ $wp_restore = new WPBackItUp_Premium_Restore($this->log_name,'not_used',null);
 
 
 
238
 
239
+ //Only available premium 1.14.6+
240
+ if (method_exists($wp_restore,'delete_restore_folders')) {
241
+ $wp_restore->delete_restore_folders();
242
+ WPBackItUp_Logger::log($this->log_name,'**END CLEAN OLD RESTORES**' );
243
+ }
244
+ }
245
 
246
+ $task->setStatus(WPBackItUp_Job_Task::COMPLETE);
247
 
248
+ }catch(Exception $e) {
249
+ WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .var_export($e,true));
250
+ $task->setStatus(WPBackItUp_Job_Task::ERROR);
 
 
 
251
  }
252
  }
253
 
254
  /**
255
  * purge old files
256
+ * @param WPBackItUp_Job_Task $task
257
  */
258
+ public function purge_old_files($task){
259
  global $wp_backup;
260
 
261
+ try {
262
+ $this->set_job_log($task);
263
+
264
+ WPBackItUp_Logger::log($this->log_name,'**PURGE OLD FILES**' );
265
+
266
+ // purge old files from the backup and logs folders - this is NOT for backups
267
+ $wp_backup->purge_old_files();
268
 
269
+ //check debug.log
270
+ //TODO: Add UI for setting to purge debug.log when gets too big - use MB in UI - 104857600(100mb)
271
+ $max_size_bytes = WPBackItUp_Utility::get_option('max_log_size',false);
272
+ $debug_log_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
273
+ if (false!== $max_size_bytes && file_exists($debug_log_path)){
274
+ $debug_log_size = filesize($debug_log_path);
275
+ WPBackItUp_Logger::log($this->log_name,'Checking debug.log file size:'. $debug_log_size );
276
+ if ($debug_log_size>$max_size_bytes){
277
+ @unlink($debug_log_path);
278
+ WPBackItUp_Logger::log($this->log_name,'debug.log purged.' );
279
+ }
280
+ }
281
 
282
+ WPBackItUp_Logger::log($this->log_name,'**END PURGE OLD FILES**' );
283
+
284
+ $task->setStatus(WPBackItUp_Job_Task::COMPLETE);
285
+
286
+ }catch(Exception $e) {
287
+ WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .var_export($e,true));
288
+ $task->setStatus(WPBackItUp_Job_Task::ERROR);
289
+ }
290
  }
291
 
292
  /**
293
  * Secure folders
294
+ *
295
+ * @param WPBackItUp_Job_Task $task
296
  */
297
+ public function secure_folders($task){
298
+
299
+ try {
300
+ $this->set_job_log($task);
301
 
302
+ WPBackItUp_Logger::log($this->log_name,'**SECURE FOLDERS**' );
303
+ $file_system = new WPBackItUp_FileSystem($this->log_name);
 
304
 
305
+ //Make sure backup folder is secured
306
+ $backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
307
+ $file_system->secure_folder( $backup_dir);
308
 
309
+ //--Check restore folder folders
310
+ $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
311
+ $file_system->secure_folder( $restore_dir);
312
 
313
+ //Make sure logs folder is secured
314
+ $logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs/';
315
+ $file_system->secure_folder( $logs_dir);
316
+
317
+ WPBackItUp_Logger::log($this->log_name,'**END SECURE FOLDERS**' );
318
+ $task->setStatus(WPBackItUp_Job_Task::COMPLETE);
319
+
320
+ }catch(Exception $e) {
321
+ WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .var_export($e,true));
322
+ $task->setStatus(WPBackItUp_Job_Task::ERROR);
323
+ }
324
  }
325
 
326
  /**
327
+ * Finish & update job
328
+ *
329
+ * @param WPBackItUp_Job_Task $task
330
  */
331
+ public function end($task){
332
  global $WPBackitup;
 
333
 
334
+ try {
335
+ $this->set_job_log($task);
336
+
337
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
338
 
339
+ //upadate the last run datetime
340
+ $current_datetime = current_time( 'timestamp' );
341
+ $WPBackitup->set_cleanup_lastrun_date($current_datetime);
342
 
343
+ $job_id = $task->getJobId();
344
+ $job = WPBackItUp_Job::get_job_by_id($job_id);
345
 
346
+ $task->setStatus(WPBackItUp_Job_Task::COMPLETE);
347
+ $job->setStatus(WPBackItUp_Job::COMPLETE);
348
 
349
+ $util = new WPBackItUp_Utility($this->log_name);
350
+ $seconds = $util->timestamp_diff_seconds($job->getJobStartTimeTimeStamp(),$job->getJobEndTimeTimeStamp());
351
 
352
+ $processing_minutes = round($seconds / 60);
353
+ $processing_seconds = $seconds % 60;
354
 
355
+ WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Script Processing Time:' .$processing_minutes .' Minutes ' .$processing_seconds .' Seconds');
356
+
357
+ WPBackItUp_Logger::log($this->log_name,'*** END JOB ***');
358
+
359
+ }catch(Exception $e) {
360
+ WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .var_export($e,true));
361
+ $task->setStatus(WPBackItUp_Job_Task::ERROR);
362
+ }
363
  }
364
 
365
 
366
+
367
+
368
+
369
  }
lib/includes/class-job.php CHANGED
@@ -106,9 +106,6 @@ class WPBackItUp_Job {
106
  'task_restore_database',
107
  );
108
 
109
- public static $CLEANUP_TASKS = array(
110
- 'task_scheduled_cleanup'
111
- );
112
 
113
  // ** END JOB TASK CONSTANTS **
114
 
@@ -522,7 +519,6 @@ class WPBackItUp_Job {
522
  return false;
523
  }
524
 
525
-
526
  /**
527
  * Is there at least 1 job queued or active?
528
  *
@@ -621,7 +617,7 @@ class WPBackItUp_Job {
621
  *
622
  * @return int
623
  */
624
- public static function purge_jobs_async($job_type,$dont_purge=5) {
625
  $log_name='debug_purge_jobs';
626
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Begin - Purge Jobs:'.$job_type );
627
 
@@ -631,8 +627,6 @@ class WPBackItUp_Job {
631
  // Purge jobs with status: cancelled, error, deleted
632
  /*------------------------------------------------------*/
633
 
634
- //Initiate background processor
635
- $cleanup_processor = new WPBackItUp_DB_Cleanup_Processor();
636
 
637
  $jobs = self::get_jobs_by_status($job_type,array(WPBackItUp_Job::DELETED,WPBackItUp_Job::ERROR,WPBackItUp_Job::CANCELLED));
638
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Total finished jobs found:' .count($jobs));
@@ -641,7 +635,9 @@ class WPBackItUp_Job {
641
  if (is_array($jobs) && count($jobs)>0) {
642
 
643
  foreach ($jobs as $key=>$job){
644
- $cleanup_processor->push_to_queue($job->getJobId());
 
 
645
  $jobs_purged+=1;
646
 
647
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Queued the Job for delete:');
@@ -681,7 +677,8 @@ class WPBackItUp_Job {
681
  if (false===$backups_exist) {
682
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'No backups found for job:'. $job->getJobId());
683
 
684
- $cleanup_processor->push_to_queue($job->getJobId());
 
685
  $jobs_purged+=1;
686
 
687
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Backups Missing - Queued the job for delete:');
@@ -713,7 +710,8 @@ class WPBackItUp_Job {
713
  WPBackItUp_Logger::log_info($log_name,__METHOD__,var_export($jobs,true));
714
  foreach ($purge_jobs as $key=>$job){
715
 
716
- $cleanup_processor->push_to_queue($job->getJobId());
 
717
  $jobs_purged+=1;
718
 
719
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Queued the Job for delete:');
@@ -723,7 +721,12 @@ class WPBackItUp_Job {
723
 
724
  }
725
 
726
- $cleanup_processor->save()->dispatch();
 
 
 
 
 
727
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Job purge queue dispatched.');
728
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'End - No of job will be Purged:' .$jobs_purged);
729
 
@@ -912,7 +915,7 @@ class WPBackItUp_Job {
912
  break;
913
 
914
  case self::CLEANUP:
915
- return self::$CLEANUP_TASKS;
916
  break;
917
 
918
  default:
106
  'task_restore_database',
107
  );
108
 
 
 
 
109
 
110
  // ** END JOB TASK CONSTANTS **
111
 
519
  return false;
520
  }
521
 
 
522
  /**
523
  * Is there at least 1 job queued or active?
524
  *
617
  *
618
  * @return int
619
  */
620
+ public static function purge_jobs($job_type,$dont_purge=5) {
621
  $log_name='debug_purge_jobs';
622
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Begin - Purge Jobs:'.$job_type );
623
 
627
  // Purge jobs with status: cancelled, error, deleted
628
  /*------------------------------------------------------*/
629
 
 
 
630
 
631
  $jobs = self::get_jobs_by_status($job_type,array(WPBackItUp_Job::DELETED,WPBackItUp_Job::ERROR,WPBackItUp_Job::CANCELLED));
632
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Total finished jobs found:' .count($jobs));
635
  if (is_array($jobs) && count($jobs)>0) {
636
 
637
  foreach ($jobs as $key=>$job){
638
+ //$cleanup_processor->push_to_queue($job->getJobId());
639
+
640
+ WPBackItUp_Job::delete_job_records($job->getJobId());
641
  $jobs_purged+=1;
642
 
643
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Queued the Job for delete:');
677
  if (false===$backups_exist) {
678
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'No backups found for job:'. $job->getJobId());
679
 
680
+ //$cleanup_processor->push_to_queue($job->getJobId());
681
+ WPBackItUp_Job::delete_job_records($job->getJobId());
682
  $jobs_purged+=1;
683
 
684
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Backups Missing - Queued the job for delete:');
710
  WPBackItUp_Logger::log_info($log_name,__METHOD__,var_export($jobs,true));
711
  foreach ($purge_jobs as $key=>$job){
712
 
713
+ //$cleanup_processor->push_to_queue($job->getJobId());
714
+ WPBackItUp_Job::delete_job_records($job->getJobId());
715
  $jobs_purged+=1;
716
 
717
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Queued the Job for delete:');
721
 
722
  }
723
 
724
+ /*------------------------------------------------------*/
725
+ //Purge jobs > 60 days no matter what the status
726
+ /*------------------------------------------------------*/
727
+ //TODO: add code to purge any job > 60 days no matter what status.
728
+
729
+
730
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'Job purge queue dispatched.');
731
  WPBackItUp_Logger::log_info($log_name,__METHOD__,'End - No of job will be Purged:' .$jobs_purged);
732
 
915
  break;
916
 
917
  case self::CLEANUP:
918
+ return WPBackItUp_Cleanup::$CLEANUP_TASKS;
919
  break;
920
 
921
  default:
lib/includes/class-wpbackitup-admin.php CHANGED
@@ -39,11 +39,6 @@ class WPBackitup_Admin {
39
  */
40
  protected $dir_cleanup_processor;
41
 
42
- /**
43
- * @var WPBackItUp_DB_Cleanup_Processor
44
- */
45
- protected $db_cleanup_processor;
46
-
47
  // Default plugin options
48
  public $defaults = array(
49
  'logging' => false,
@@ -227,6 +222,12 @@ class WPBackitup_Admin {
227
  //Only load the JS and CSS when plugin is active
228
  if( !empty($_REQUEST['page']) && substr($_REQUEST['page'], 0, 11) === 'wp-backitup') {
229
 
 
 
 
 
 
 
230
  // Admin JavaScript
231
  wp_register_script("{$this->namespace}-jquery-tagit", WPBACKITUP__PLUGIN_URL."js/tag-it.min.js", array('jquery'), $this->version, true);
232
  wp_register_script( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "js/wp-backitup-admin.min.js", array( 'jquery' ), $this->version, true );
@@ -441,7 +442,6 @@ class WPBackitup_Admin {
441
  require_once(WPBACKITUP__PLUGIN_PATH . '/lib/background-processing/class-task-processor.php');
442
  require_once(WPBACKITUP__PLUGIN_PATH . '/lib/background-processing/class-cleanup-processor.php');
443
  require_once(WPBACKITUP__PLUGIN_PATH . '/lib/background-processing/class-file-cleanup-processor.php');
444
- require_once(WPBACKITUP__PLUGIN_PATH . '/lib/background-processing/class-db-cleanup-processor.php');
445
  require_once(WPBACKITUP__PLUGIN_PATH . '/lib/background-processing/class-directory-cleanup-processor.php');
446
 
447
  require_once( WPBACKITUP__PLUGIN_PATH . '/lib/includes/class-logger.php' );
@@ -480,7 +480,6 @@ class WPBackitup_Admin {
480
  $this->cleanup_processor = new WPBackItUp_Cleanup_Processor();
481
  $this->file_cleanup_processor = new WPBackItUp_File_Cleanup_Processor();
482
  $this->dir_cleanup_processor = new WPBackItUp_Directory_Cleanup_Processor();
483
- $this->db_cleanup_processor = new WPBackItUp_DB_Cleanup_Processor();
484
 
485
  $cleanup = new WPBackItUp_Cleanup();
486
  $cleanup->init();
@@ -488,12 +487,12 @@ class WPBackitup_Admin {
488
  }
489
 
490
  /**
491
- * Handle task queue.
492
  *
493
  * @param $task_type
494
  * @param @task_list
495
  */
496
- public function handle_async_task_queue($task_type, $task_list){
497
  $processor = $this->get_async_task_processor($task_type);
498
 
499
  if( !is_null($processor) ){
@@ -597,14 +596,37 @@ class WPBackitup_Admin {
597
 
598
  }
599
 
600
- //CLEANUP
601
- //If no cleanup queued or active & its time to run on then kick it off
602
- if ( ! WPBackItUp_Job::is_job_queued_active(WPBackItUp_Job::CLEANUP) &&
603
- $scheduler->isJobScheduled(WPBackItUp_Job::CLEANUP)){
 
 
604
 
605
- //add cleanup tasks to list
606
- $this->handle_async_task_queue(Processors::CLEANUP, WPBackItUp_Cleanup::$TASK_ITEMS);
 
607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
  }
609
 
610
  //Are there any wpbackitup add ons that need to be kicked off?
39
  */
40
  protected $dir_cleanup_processor;
41
 
 
 
 
 
 
42
  // Default plugin options
43
  public $defaults = array(
44
  'logging' => false,
222
  //Only load the JS and CSS when plugin is active
223
  if( !empty($_REQUEST['page']) && substr($_REQUEST['page'], 0, 11) === 'wp-backitup') {
224
 
225
+ // update body class
226
+ add_filter( 'admin_body_class', function( $classes ) {
227
+ $classes .= ' wpb-main';
228
+ return $classes;
229
+ });
230
+
231
  // Admin JavaScript
232
  wp_register_script("{$this->namespace}-jquery-tagit", WPBACKITUP__PLUGIN_URL."js/tag-it.min.js", array('jquery'), $this->version, true);
233
  wp_register_script( "{$this->namespace}-admin", WPBACKITUP__PLUGIN_URL . "js/wp-backitup-admin.min.js", array( 'jquery' ), $this->version, true );
442
  require_once(WPBACKITUP__PLUGIN_PATH . '/lib/background-processing/class-task-processor.php');
443
  require_once(WPBACKITUP__PLUGIN_PATH . '/lib/background-processing/class-cleanup-processor.php');
444
  require_once(WPBACKITUP__PLUGIN_PATH . '/lib/background-processing/class-file-cleanup-processor.php');
 
445
  require_once(WPBACKITUP__PLUGIN_PATH . '/lib/background-processing/class-directory-cleanup-processor.php');
446
 
447
  require_once( WPBACKITUP__PLUGIN_PATH . '/lib/includes/class-logger.php' );
480
  $this->cleanup_processor = new WPBackItUp_Cleanup_Processor();
481
  $this->file_cleanup_processor = new WPBackItUp_File_Cleanup_Processor();
482
  $this->dir_cleanup_processor = new WPBackItUp_Directory_Cleanup_Processor();
 
483
 
484
  $cleanup = new WPBackItUp_Cleanup();
485
  $cleanup->init();
487
  }
488
 
489
  /**
490
+ * Dispatch Async tasks
491
  *
492
  * @param $task_type
493
  * @param @task_list
494
  */
495
+ public function dispatch_async_tasks($task_type, $task_list){
496
  $processor = $this->get_async_task_processor($task_type);
497
 
498
  if( !is_null($processor) ){
596
 
597
  }
598
 
599
+ //if backup job is queued or active then exit
600
+ $backup_job = WPBackItUp_Job::is_job_queued_active(WPBackItUp_Job::BACKUP);
601
+ if (false!==$backup_job){
602
+ WPBackItUp_Logger::log_info($scheduled_jobs_logname,__METHOD__,'Backup Job Queued:'. $backup_job->getJobId());
603
+ exit;
604
+ }
605
 
606
+ //CLEANUP
607
+ //Run Cleanup every hour
608
+ if ( $scheduler->isJobScheduled(WPBackItUp_Job::CLEANUP) ) {
609
 
610
+ //queue job
611
+ $cleanup_job = WPBackItUp_Cleanup::queue_job();
612
+ if (false===$cleanup_job) {
613
+ WPBackItUp_Logger::log_error( $scheduled_jobs_logname, __METHOD__, 'Cleanup could not be queued.' );
614
+ } else {
615
+ //dispatch tasks
616
+ $cleanup_tasks = WPBackItUp_Job_Task::get_job_tasks($cleanup_job->getJobId(),WPBackItUp_Job_Task::QUEUED);
617
+ if (false===$cleanup_tasks) {
618
+ WPBackItUp_Logger::log_error( $scheduled_jobs_logname, __METHOD__, 'Cleanup tasks could not dispatched.' );
619
+ }else {
620
+ $processor = $this->get_async_task_processor(Processors::CLEANUP);
621
+ if( !is_null($processor) ){
622
+ foreach ( $cleanup_tasks as $task ) {
623
+ //add tasks queue
624
+ $processor->push_to_queue( $task->getTaskId());
625
+ }
626
+ $processor->save()->dispatch();
627
+ }
628
+ }
629
+ }
630
  }
631
 
632
  //Are there any wpbackitup add ons that need to be kicked off?
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: wpbackitup, cssimmon, alaminopu, imranshuvo
3
  Tags: backup, backups, back up, backup plugin, database backup, multisite backup, full backup, database, restore, migrate, clone, malware
4
  Requires at least: 3.8.0
5
  Tested up to: 4.8
6
- Stable tag: 1.14.4
7
  Author URI: https://www.wpbackitup.com
8
  Donate link: https://www.wpbackitup.com
9
  License: GPLv2 or later
@@ -197,8 +197,14 @@ Our online documentation and full list of FAQs can be found at [support.wpbackit
197
 
198
 
199
  == Changelog ==
 
 
 
 
 
 
200
  = 1.14.5 =
201
- *Release Date - June 7, 2017
202
 
203
  * UPDATE: Updates to support WordPress 4.8 release
204
  * UPDATE: Enhancements to cleanup processor and job engine
3
  Tags: backup, backups, back up, backup plugin, database backup, multisite backup, full backup, database, restore, migrate, clone, malware
4
  Requires at least: 3.8.0
5
  Tested up to: 4.8
6
+ Stable tag: 1.14.5
7
  Author URI: https://www.wpbackitup.com
8
  Donate link: https://www.wpbackitup.com
9
  License: GPLv2 or later
197
 
198
 
199
  == Changelog ==
200
+ = 1.14.6 =
201
+ *Release Date - July 15, 2017
202
+
203
+ * FIX: Fix issues with cleanup processor causing jobs fail
204
+ * FIX: Fix CSS causing UI issues for certain themes
205
+
206
  = 1.14.5 =
207
+ *Release Date - June 8, 2017
208
 
209
  * UPDATE: Updates to support WordPress 4.8 release
210
  * UPDATE: Enhancements to cleanup processor and job engine
wp-backitup.php CHANGED
@@ -6,7 +6,7 @@
6
  * Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
7
  * Author: WPBackItUp
8
  * Author URI: https://www.wpbackitup.com
9
- * Version: 1.14.5
10
  * Text Domain: wp-backitup
11
  * Domain Path: /languages
12
  *
@@ -34,7 +34,7 @@ define( 'WPBACKITUP__CLASSNAMESPACE', 'WPBackItUp' );
34
 
35
  define( 'WPBACKITUP__MAJOR_VERSION', 1);
36
  define( 'WPBACKITUP__MINOR_VERSION', 14);
37
- define( 'WPBACKITUP__MAINTENANCE_VERSION', 5); //Dont forget to update version in header on WP release
38
  define( 'WPBACKITUP__BUILD_VERSION', 0); //Used for hotfix releases
39
 
40
  define( 'WPBACKITUP__VERSION',sprintf("%d.%d.%d.%d", WPBACKITUP__MAJOR_VERSION, WPBACKITUP__MINOR_VERSION,WPBACKITUP__MAINTENANCE_VERSION,WPBACKITUP__BUILD_VERSION));
6
  * Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
7
  * Author: WPBackItUp
8
  * Author URI: https://www.wpbackitup.com
9
+ * Version: 1.14.6
10
  * Text Domain: wp-backitup
11
  * Domain Path: /languages
12
  *
34
 
35
  define( 'WPBACKITUP__MAJOR_VERSION', 1);
36
  define( 'WPBACKITUP__MINOR_VERSION', 14);
37
+ define( 'WPBACKITUP__MAINTENANCE_VERSION', 6); //Dont forget to update version in header on WP release
38
  define( 'WPBACKITUP__BUILD_VERSION', 0); //Used for hotfix releases
39
 
40
  define( 'WPBACKITUP__VERSION',sprintf("%d.%d.%d.%d", WPBACKITUP__MAJOR_VERSION, WPBACKITUP__MINOR_VERSION,WPBACKITUP__MAINTENANCE_VERSION,WPBACKITUP__BUILD_VERSION));