Version Description
*Release Date - March 16,2017
- UPDATE: Added new admin notice class
- UPDATE: Added new logging class
- UPDATE: WPBDEV-134 Add support for extremely large databases(500+ SQL files)
Download this release
Release Info
Developer | cssimmon |
Plugin | Backup and Restore WordPress – WPBackItUp Backup Plugin |
Version | 1.14.3 |
Comparing to | |
See all releases |
Code changes from version 1.14.2 to 1.14.3
- images/email_notifications.png +0 -0
- lib/background-processing/class-async-request.php +1 -1
- lib/background-processing/class-cleanup-processor.php +9 -9
- lib/background-processing/class-task-processor.php +19 -19
- lib/includes/class-admin-notice.php +599 -0
- lib/includes/class-backup.php +193 -146
- lib/includes/class-database.php +103 -103
- lib/includes/class-encryption.php +7 -7
- lib/includes/class-filesystem.php +88 -88
- lib/includes/class-job-item.php +7 -7
- lib/includes/class-job-task.php +11 -11
- lib/includes/class-job.php +79 -81
- lib/includes/class-license.php +23 -23
- lib/includes/class-logger.php +287 -207
- lib/includes/class-loggerV2.php +197 -42
- lib/includes/class-mutex.php +8 -8
- lib/includes/class-scheduler.php +11 -11
- lib/includes/class-sql.php +55 -55
- lib/includes/class-utility.php +10 -10
- lib/includes/class-wpbackitup-admin.php +100 -68
- lib/includes/class-zip.php +1 -1
- lib/includes/handler_download.php +10 -10
- lib/includes/handler_upload.php +17 -17
- lib/includes/job_backup.php +210 -166
- lib/includes/job_cleanup.php +31 -31
- lib/includes/job_restore.php +117 -117
- lib/includes/update_database.php +47 -47
- lib/includes/update_plugin.php +24 -24
- readme.txt +9 -2
- vendor/KLogger/LogLevel.php +16 -0
- vendor/KLogger/Logger.php +463 -0
- views/backup.php +16 -16
- views/settings.php +16 -4
- wp-backitup.php +4 -2
images/email_notifications.png
ADDED
Binary file
|
lib/background-processing/class-async-request.php
CHANGED
@@ -103,7 +103,7 @@ if ( ! class_exists( 'WPBackItUp_Async_Request' ) ) {
|
|
103 |
|
104 |
$response = wp_remote_post( esc_url_raw( $url ), $args );
|
105 |
if ( is_wp_error( $response ) ) { //timeout error is ok
|
106 |
-
|
107 |
}
|
108 |
|
109 |
return $response;
|
103 |
|
104 |
$response = wp_remote_post( esc_url_raw( $url ), $args );
|
105 |
if ( is_wp_error( $response ) ) { //timeout error is ok
|
106 |
+
WPBackItUp_Logger::log_info( self::$logname, __METHOD__, sprintf( 'Error on WP Remote Post Request: %s ', var_export( $response, true )));
|
107 |
}
|
108 |
|
109 |
return $response;
|
lib/background-processing/class-cleanup-processor.php
CHANGED
@@ -40,11 +40,11 @@ class WPBackItUp_Cleanup_Processor extends WPBackItUp_Background_Process {
|
|
40 |
* @return mixed False when task is complete|return updated item for further processing
|
41 |
*/
|
42 |
protected function task( $item ) {
|
43 |
-
|
44 |
|
45 |
//Items should always be array
|
46 |
if (! is_array($item )){
|
47 |
-
|
48 |
return false;
|
49 |
}
|
50 |
|
@@ -52,7 +52,7 @@ class WPBackItUp_Cleanup_Processor extends WPBackItUp_Background_Process {
|
|
52 |
case "cleanup-zip":
|
53 |
//if only one left then all are deleted
|
54 |
if (count($item)<=1) {
|
55 |
-
|
56 |
return false;
|
57 |
}
|
58 |
|
@@ -60,9 +60,9 @@ class WPBackItUp_Cleanup_Processor extends WPBackItUp_Background_Process {
|
|
60 |
|
61 |
$file_system = new WPBackItUp_FileSystem();
|
62 |
if (true===$file_system->delete_files( $item )){
|
63 |
-
|
64 |
} else {
|
65 |
-
|
66 |
}
|
67 |
|
68 |
return false;
|
@@ -71,7 +71,7 @@ class WPBackItUp_Cleanup_Processor extends WPBackItUp_Background_Process {
|
|
71 |
case "cleanup-files":
|
72 |
//if only one left then all are deleted
|
73 |
if (count($item)<=1) {
|
74 |
-
|
75 |
return false;
|
76 |
}
|
77 |
|
@@ -79,9 +79,9 @@ class WPBackItUp_Cleanup_Processor extends WPBackItUp_Background_Process {
|
|
79 |
|
80 |
$file_system = new WPBackItUp_FileSystem();
|
81 |
if (true===$file_system->delete_files( $item )){
|
82 |
-
|
83 |
} else {
|
84 |
-
|
85 |
}
|
86 |
|
87 |
return false;
|
@@ -89,7 +89,7 @@ class WPBackItUp_Cleanup_Processor extends WPBackItUp_Background_Process {
|
|
89 |
|
90 |
|
91 |
default: //task not defined
|
92 |
-
|
93 |
return false;
|
94 |
}
|
95 |
|
40 |
* @return mixed False when task is complete|return updated item for further processing
|
41 |
*/
|
42 |
protected function task( $item ) {
|
43 |
+
WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME,__METHOD__,'Task to process:'. var_export( $item,true ));
|
44 |
|
45 |
//Items should always be array
|
46 |
if (! is_array($item )){
|
47 |
+
WPBackItUp_Logger::log_error(self::CLEANUP_LOG_NAME,__METHOD__,'Task was not array:'. var_export( $item,true ));
|
48 |
return false;
|
49 |
}
|
50 |
|
52 |
case "cleanup-zip":
|
53 |
//if only one left then all are deleted
|
54 |
if (count($item)<=1) {
|
55 |
+
WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME,__METHOD__,'No more files to delete.');
|
56 |
return false;
|
57 |
}
|
58 |
|
60 |
|
61 |
$file_system = new WPBackItUp_FileSystem();
|
62 |
if (true===$file_system->delete_files( $item )){
|
63 |
+
WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME,__METHOD__,'Files deleted successfully.');
|
64 |
} else {
|
65 |
+
WPBackItUp_Logger::log_error(self::CLEANUP_LOG_NAME,__METHOD__,'File delete error');
|
66 |
}
|
67 |
|
68 |
return false;
|
71 |
case "cleanup-files":
|
72 |
//if only one left then all are deleted
|
73 |
if (count($item)<=1) {
|
74 |
+
WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME,__METHOD__,'No more files to delete.');
|
75 |
return false;
|
76 |
}
|
77 |
|
79 |
|
80 |
$file_system = new WPBackItUp_FileSystem();
|
81 |
if (true===$file_system->delete_files( $item )){
|
82 |
+
WPBackItUp_Logger::log_info(self::CLEANUP_LOG_NAME,__METHOD__,'Files deleted successfully.');
|
83 |
} else {
|
84 |
+
WPBackItUp_Logger::log_error(self::CLEANUP_LOG_NAME,__METHOD__,'File delete error');
|
85 |
}
|
86 |
|
87 |
return false;
|
89 |
|
90 |
|
91 |
default: //task not defined
|
92 |
+
WPBackItUp_Logger::log_error(self::CLEANUP_LOG_NAME,__METHOD__,'Task Undefined.');
|
93 |
return false;
|
94 |
}
|
95 |
|
lib/background-processing/class-task-processor.php
CHANGED
@@ -38,35 +38,35 @@ class WPBackItUp_Task_Processor extends WPBackItUp_Background_Process {
|
|
38 |
protected function task( $item ) {
|
39 |
$logname = 'debug_task_processor';
|
40 |
|
41 |
-
|
42 |
|
43 |
try {
|
44 |
|
45 |
if (empty($item)){
|
46 |
-
|
47 |
return false;
|
48 |
}
|
49 |
|
50 |
$item_parts = explode('_',$item);
|
51 |
if (false===$item_parts){
|
52 |
-
|
53 |
return false;
|
54 |
}
|
55 |
|
56 |
$job_id = end($item_parts);
|
57 |
if (empty($job_id)){
|
58 |
-
|
59 |
return false;
|
60 |
}
|
61 |
|
62 |
//Get the job info
|
63 |
$job = WPBackItUp_Job::get_job_by_id($job_id);
|
64 |
if (false===$job){
|
65 |
-
|
66 |
return false;
|
67 |
}
|
68 |
|
69 |
-
|
70 |
|
71 |
//If job is active or queued then fire task
|
72 |
if (WPBackItUp_Job::ACTIVE == $job->getJobStatus() || WPBackItUp_Job::QUEUED == $job->getJobStatus()) {
|
@@ -93,22 +93,22 @@ class WPBackItUp_Task_Processor extends WPBackItUp_Background_Process {
|
|
93 |
);
|
94 |
|
95 |
|
96 |
-
|
97 |
|
98 |
$url = add_query_arg( $query_args, admin_url( 'admin-ajax.php' ));
|
99 |
-
|
100 |
|
101 |
$response = wp_remote_post( esc_url_raw( $url ), $post_args );
|
102 |
-
|
103 |
|
104 |
if( is_wp_error( $response ) ) { //timeout error is ok
|
105 |
-
|
106 |
}
|
107 |
|
108 |
-
|
109 |
sleep(WPBACKITUP__TASK_WAIT_SECONDS);//wait N seconds then check again
|
110 |
|
111 |
-
|
112 |
return $item;
|
113 |
}
|
114 |
|
@@ -116,40 +116,40 @@ class WPBackItUp_Task_Processor extends WPBackItUp_Background_Process {
|
|
116 |
|
117 |
//get task info
|
118 |
$task = $job->get_next_task();
|
119 |
-
|
120 |
if ( false === $task ) {
|
121 |
//no tasks ready for processing
|
122 |
//If task is still processing, will timeout in 1 minutes
|
123 |
//review get_next_task to understand timeout/error
|
124 |
$wait_seconds= 2;
|
125 |
-
|
126 |
sleep($wait_seconds);//wait 5 seconds then check again
|
127 |
return $item;
|
128 |
}
|
129 |
|
130 |
//Was there an error on the previous run
|
131 |
if ( WPBackItUp_Job::ERROR == $task->getStatus() ) {
|
132 |
-
|
133 |
return false;
|
134 |
}
|
135 |
|
136 |
//Get task Name + add wpb prefix for hook
|
137 |
$hook_name = 'wpbackitup_' . $task->getTaskName();
|
138 |
|
139 |
-
|
140 |
$task->increment_retry_count();
|
141 |
do_action( $hook_name, $task );// RUN TASK
|
142 |
-
|
143 |
|
144 |
return $item;
|
145 |
|
146 |
} else {
|
147 |
-
|
148 |
return false; //job has completed
|
149 |
}
|
150 |
|
151 |
} catch (Exception $e) {
|
152 |
-
|
153 |
return false;
|
154 |
}
|
155 |
}
|
38 |
protected function task( $item ) {
|
39 |
$logname = 'debug_task_processor';
|
40 |
|
41 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__,'Task Processor Event:'. var_export( $item, true ) );
|
42 |
|
43 |
try {
|
44 |
|
45 |
if (empty($item)){
|
46 |
+
WPBackItUp_Logger::log_error($logname,__METHOD__,'NO item passed to task processor.');
|
47 |
return false;
|
48 |
}
|
49 |
|
50 |
$item_parts = explode('_',$item);
|
51 |
if (false===$item_parts){
|
52 |
+
WPBackItUp_Logger::log_error($logname,__METHOD__,'NO job id passed to task processor.');
|
53 |
return false;
|
54 |
}
|
55 |
|
56 |
$job_id = end($item_parts);
|
57 |
if (empty($job_id)){
|
58 |
+
WPBackItUp_Logger::log_error($logname,__METHOD__,'NO JOB ID found.');
|
59 |
return false;
|
60 |
}
|
61 |
|
62 |
//Get the job info
|
63 |
$job = WPBackItUp_Job::get_job_by_id($job_id);
|
64 |
if (false===$job){
|
65 |
+
WPBackItUp_Logger::log_error($logname,__METHOD__,'NO JOB found:'.$job_id);
|
66 |
return false;
|
67 |
}
|
68 |
|
69 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__, sprintf('Job found:(%s)',var_export($job,true)));
|
70 |
|
71 |
//If job is active or queued then fire task
|
72 |
if (WPBackItUp_Job::ACTIVE == $job->getJobStatus() || WPBackItUp_Job::QUEUED == $job->getJobStatus()) {
|
93 |
);
|
94 |
|
95 |
|
96 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__,'Before Fire Action:wp-backitup_run_task');
|
97 |
|
98 |
$url = add_query_arg( $query_args, admin_url( 'admin-ajax.php' ));
|
99 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__, sprintf('Request: %s ',var_export($url,true)));
|
100 |
|
101 |
$response = wp_remote_post( esc_url_raw( $url ), $post_args );
|
102 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__, sprintf('Remote Get Response:: %s ',var_export($response,true)));
|
103 |
|
104 |
if( is_wp_error( $response ) ) { //timeout error is ok
|
105 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__, sprintf('Error on Remote Post Request:: %s ',var_export($response,true)));
|
106 |
}
|
107 |
|
108 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__, sprintf('Wait %s seconds.',WPBACKITUP__TASK_WAIT_SECONDS));
|
109 |
sleep(WPBACKITUP__TASK_WAIT_SECONDS);//wait N seconds then check again
|
110 |
|
111 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__,'After Fire Action:wp-backitup_run_task');
|
112 |
return $item;
|
113 |
}
|
114 |
|
116 |
|
117 |
//get task info
|
118 |
$task = $job->get_next_task();
|
119 |
+
WPBackItUp_Logger::log_info( $logname, __METHOD__, sprintf( '(%s) Task Found: %s', $job->getJobType(), var_export($task,true)));
|
120 |
if ( false === $task ) {
|
121 |
//no tasks ready for processing
|
122 |
//If task is still processing, will timeout in 1 minutes
|
123 |
//review get_next_task to understand timeout/error
|
124 |
$wait_seconds= 2;
|
125 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__, sprintf('No task ready for processing. Wait %s seconds.',$wait_seconds));
|
126 |
sleep($wait_seconds);//wait 5 seconds then check again
|
127 |
return $item;
|
128 |
}
|
129 |
|
130 |
//Was there an error on the previous run
|
131 |
if ( WPBackItUp_Job::ERROR == $task->getStatus() ) {
|
132 |
+
WPBackItUp_Logger::log_error($logname,__METHOD__,'Previous Task Error.');
|
133 |
return false;
|
134 |
}
|
135 |
|
136 |
//Get task Name + add wpb prefix for hook
|
137 |
$hook_name = 'wpbackitup_' . $task->getTaskName();
|
138 |
|
139 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__,sprintf('Before Fire Action:(%s)%s',$job_id,$hook_name));
|
140 |
$task->increment_retry_count();
|
141 |
do_action( $hook_name, $task );// RUN TASK
|
142 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__, sprintf('After Fire Action:(%s)%s',$job_id ,$hook_name));
|
143 |
|
144 |
return $item;
|
145 |
|
146 |
} else {
|
147 |
+
WPBackItUp_Logger::log_info($logname,__METHOD__,'Job Completed:' . $job_id);
|
148 |
return false; //job has completed
|
149 |
}
|
150 |
|
151 |
} catch (Exception $e) {
|
152 |
+
WPBackItUp_Logger::log_error($logname,__METHOD__, $e->getMessage());
|
153 |
return false;
|
154 |
}
|
155 |
}
|
lib/includes/class-admin-notice.php
ADDED
@@ -0,0 +1,599 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
+
|
3 |
+
/**
|
4 |
+
* WP BackItUp - Admin Review Nag Class
|
5 |
+
*
|
6 |
+
* @since 1.14.2
|
7 |
+
* @package WP BackItUp
|
8 |
+
* @author Chris Simmons <chris.simmons@wpbackitup.com>
|
9 |
+
* @link http://www.wpbackitup.com
|
10 |
+
*
|
11 |
+
*/
|
12 |
+
|
13 |
+
if ( ! class_exists( 'WPBackitup_Admin_Notice' ) ) {
|
14 |
+
|
15 |
+
class WPBackitup_Admin_Notice {
|
16 |
+
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Minimum required version of PHP.
|
20 |
+
*
|
21 |
+
*/
|
22 |
+
public $php_version_required = '5.2';
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Minimum version of WordPress required to use the library
|
26 |
+
*
|
27 |
+
*/
|
28 |
+
public $wordpress_version_required = '3.8';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* @var array Holds all our registered notices
|
32 |
+
*
|
33 |
+
*/
|
34 |
+
private $notices;
|
35 |
+
|
36 |
+
|
37 |
+
protected $initial_time_key; //unique identifier key for an initial timestamp
|
38 |
+
public $link_id; //link unique id
|
39 |
+
public $link_label; //Label of the link
|
40 |
+
public $is_wpbackitup_page; //Check whether admin is in backitup pages.
|
41 |
+
|
42 |
+
|
43 |
+
public function __construct($args){
|
44 |
+
|
45 |
+
$args = wp_parse_args( $args, $this->default_args() );
|
46 |
+
$this->id = $args['id'];
|
47 |
+
$this->days = $args['days_after'];
|
48 |
+
$this->type = $args['type'];
|
49 |
+
$this->message = $args['message'];
|
50 |
+
$this->link_label = $args['link_label'];
|
51 |
+
$this->rating = $args['rating'];
|
52 |
+
$this->slug = $args['slug'];
|
53 |
+
$this->cap = $args['cap'];
|
54 |
+
$this->scope = $args['scope'];
|
55 |
+
|
56 |
+
$this->initial_time_key = 'wp-backitup_notice_' . substr( md5( plugin_basename( __FILE__ ) ), 0, 20 );
|
57 |
+
$this->link_id = 'wpbackitup-review-link-' . $this->initial_time_key;
|
58 |
+
|
59 |
+
//Register a new notice on instantiate
|
60 |
+
$this->register_notice($args);
|
61 |
+
|
62 |
+
$this->init();
|
63 |
+
}
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Get the default arguments for a notice
|
69 |
+
*
|
70 |
+
* @since 1.0
|
71 |
+
* @return array
|
72 |
+
*/
|
73 |
+
private function default_args() {
|
74 |
+
|
75 |
+
$defaults = array(
|
76 |
+
'id' => 'wpbackitup_initial_id',
|
77 |
+
'days_after' => 10,
|
78 |
+
'type' => '',
|
79 |
+
'message' => sprintf( esc_html__( 'Hey! You've been using WPBackItUp for a little while now and we really hope it's helped you make backing up your site simple. You might not realize it, but user reviews are such a great help to us. We would be so grateful if you could take a minute to leave a review on WordPress.org. Many thanks in advance :)', 'wp-backitup' ) ),
|
80 |
+
'link_label' => esc_html__( 'Click here to leave your review', 'wp-backitup' ),
|
81 |
+
'rating' => 5,
|
82 |
+
'slug' => 'wp-backitup',
|
83 |
+
|
84 |
+
// Parameters used in WP Dismissible Notices Handler
|
85 |
+
'cap' => 'administrator',
|
86 |
+
'scope' => 'global',
|
87 |
+
'class' => '',
|
88 |
+
);
|
89 |
+
|
90 |
+
return apply_filters( 'wpbackitup_default_args', $defaults );
|
91 |
+
|
92 |
+
}
|
93 |
+
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Initialize the library
|
97 |
+
*
|
98 |
+
* @return void
|
99 |
+
*/
|
100 |
+
private function init() {
|
101 |
+
|
102 |
+
// Make sure WordPress is compatible
|
103 |
+
if ( ! $this->is_wp_compatible() ) {
|
104 |
+
$this->spit_error(
|
105 |
+
sprintf(
|
106 |
+
/* translators: %s: required wordpress version */
|
107 |
+
esc_html__( 'WPBackItUp can not be used on your site because it requires WordPress Version %s or later.', 'wp-backitup' ),
|
108 |
+
$this->wordpress_version_required
|
109 |
+
)
|
110 |
+
);
|
111 |
+
|
112 |
+
return;
|
113 |
+
}
|
114 |
+
|
115 |
+
// Make sure PHP is compatible
|
116 |
+
if ( ! $this->is_php_compatible() ) {
|
117 |
+
$this->spit_error(
|
118 |
+
sprintf(
|
119 |
+
/* translators: %s: required php version */
|
120 |
+
esc_html__( 'WPBackItUp can not be used on your site because it requires PHP Version %s or later.', 'wp-backitup' ),
|
121 |
+
$this->php_version_required
|
122 |
+
)
|
123 |
+
);
|
124 |
+
|
125 |
+
return;
|
126 |
+
}
|
127 |
+
|
128 |
+
add_action( 'admin_notices', array( $this, 'display' ) );
|
129 |
+
add_action( 'admin_footer', array( $this, 'load_script' ) );
|
130 |
+
add_action( 'wp_ajax_wpbackitup_dismiss_notice', array( $this, 'dismiss_notice_ajax' ) );
|
131 |
+
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Check if the current WordPress version fits the requirements
|
136 |
+
*
|
137 |
+
* @return boolean
|
138 |
+
*/
|
139 |
+
private function is_wp_compatible() {
|
140 |
+
|
141 |
+
if ( version_compare( get_bloginfo( 'version' ), $this->wordpress_version_required, '<' ) ) {
|
142 |
+
return false;
|
143 |
+
}
|
144 |
+
|
145 |
+
return true;
|
146 |
+
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Check if the version of PHP is compatible with this class
|
151 |
+
*
|
152 |
+
* @return boolean
|
153 |
+
*/
|
154 |
+
private function is_php_compatible() {
|
155 |
+
|
156 |
+
if ( version_compare( phpversion(), $this->php_version_required, '<' ) ) {
|
157 |
+
return false;
|
158 |
+
}
|
159 |
+
|
160 |
+
return true;
|
161 |
+
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Display all the registered notices
|
166 |
+
*
|
167 |
+
* @return void
|
168 |
+
*/
|
169 |
+
public function display() {
|
170 |
+
|
171 |
+
if ( is_null( $this->notices ) || empty( $this->notices ) ) {
|
172 |
+
return;
|
173 |
+
}
|
174 |
+
|
175 |
+
if(!$this->is_time()){
|
176 |
+
return;
|
177 |
+
}
|
178 |
+
|
179 |
+
//Display messages on plugins AND wp-backitup only
|
180 |
+
|
181 |
+
if( $this->is_notice_pages() ){
|
182 |
+
|
183 |
+
foreach ( $this->notices as $id => $notice ) {
|
184 |
+
|
185 |
+
$id = $this->get_id( $id );
|
186 |
+
|
187 |
+
// Check if the notice was dismissed
|
188 |
+
if ( $this->is_dismissed( $id ) ) {
|
189 |
+
continue;
|
190 |
+
}
|
191 |
+
|
192 |
+
// Check if the current user has required capability
|
193 |
+
if ( ! empty( $notice['cap'] ) && ! current_user_can( $notice['cap'] ) ) {
|
194 |
+
continue;
|
195 |
+
}
|
196 |
+
|
197 |
+
$class = array(
|
198 |
+
'wpbackitup-notice',
|
199 |
+
'notice',
|
200 |
+
$notice['type'],
|
201 |
+
'is-dismissible',
|
202 |
+
$notice['class'],
|
203 |
+
);
|
204 |
+
|
205 |
+
printf( '<div id="%3$s" class="%1$s"><p>%2$s</p></div>', trim( implode( ' ', $class ) ), $notice['content'], "wpbackitup-$id" );
|
206 |
+
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Spits an error message at the top of the admin screen
|
214 |
+
*
|
215 |
+
* @param string $error Error message to spit
|
216 |
+
*
|
217 |
+
* @return void
|
218 |
+
*/
|
219 |
+
protected function spit_error( $error ) {
|
220 |
+
|
221 |
+
if( $this->is_notice_pages() ){
|
222 |
+
printf(
|
223 |
+
'<div class="notice notice-error is-dismissible"><p><strong>%1$s</strong> %2$s</pre></p></div>',
|
224 |
+
esc_html__( 'WPBackitUp Error:', 'wp-backitup' ),
|
225 |
+
wp_kses_post( $error )
|
226 |
+
);
|
227 |
+
}
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Checks whether this is plugins page or wpbackitup pages
|
232 |
+
*
|
233 |
+
* @return boolean
|
234 |
+
*
|
235 |
+
*/
|
236 |
+
public function is_notice_pages(){
|
237 |
+
global $pagenow;
|
238 |
+
|
239 |
+
if(isset($_GET['page'])){
|
240 |
+
if ( false !== strpos($_GET['page'],'wp-backitup')){
|
241 |
+
$this->is_wpbackitup_page = true;
|
242 |
+
}
|
243 |
+
}
|
244 |
+
|
245 |
+
if( $pagenow == 'plugins.php' || $this->is_wpbackitup_page != false ){
|
246 |
+
return true;
|
247 |
+
}
|
248 |
+
|
249 |
+
return false;
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Sanitize a notice ID and return it
|
254 |
+
*
|
255 |
+
* @param string $id
|
256 |
+
*
|
257 |
+
* @return string
|
258 |
+
*/
|
259 |
+
public function get_id( $id ) {
|
260 |
+
return sanitize_key( $id );
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Get available notice types
|
265 |
+
*
|
266 |
+
* @return array
|
267 |
+
*/
|
268 |
+
public function get_types() {
|
269 |
+
|
270 |
+
$types = array(
|
271 |
+
'error',
|
272 |
+
'updated',
|
273 |
+
);
|
274 |
+
|
275 |
+
return apply_filters( 'wpbackitup_notice_types', $types );
|
276 |
+
|
277 |
+
}
|
278 |
+
|
279 |
+
|
280 |
+
/**
|
281 |
+
* Register a new notice
|
282 |
+
*
|
283 |
+
* @param string $id Notice ID, used to identify it
|
284 |
+
* @param string $type Type of notice to display
|
285 |
+
* @param string $content Notice content
|
286 |
+
* @param array $args Additional parameters
|
287 |
+
*
|
288 |
+
* @return bool
|
289 |
+
*/
|
290 |
+
public function register_notice( $args = array() ) {
|
291 |
+
|
292 |
+
if ( is_null( $this->notices ) ) {
|
293 |
+
$this->notices = array();
|
294 |
+
}
|
295 |
+
|
296 |
+
$id = $this->get_id( $args['id'] );
|
297 |
+
$type = in_array( $t = sanitize_text_field( $args['type'] ), $this->get_types() ) ? $t : 'updated';
|
298 |
+
$content = $this->get_message();
|
299 |
+
$args = wp_parse_args( $args, $this->default_args() );
|
300 |
+
|
301 |
+
if ( array_key_exists( $id, $this->notices ) ) {
|
302 |
+
|
303 |
+
$this->spit_error(
|
304 |
+
sprintf(
|
305 |
+
/* translators: %s: required php version */
|
306 |
+
esc_html__( 'A notice with the ID %s has already been registered.', 'wp-backitup' ),
|
307 |
+
"<code>$id</code>"
|
308 |
+
)
|
309 |
+
);
|
310 |
+
|
311 |
+
return false;
|
312 |
+
}
|
313 |
+
|
314 |
+
$notice = array(
|
315 |
+
'type' => $type,
|
316 |
+
'content' => $content,
|
317 |
+
);
|
318 |
+
|
319 |
+
$notice = array_merge( $notice, $args );
|
320 |
+
|
321 |
+
$this->notices[ $id ] = $notice;
|
322 |
+
|
323 |
+
return true;
|
324 |
+
|
325 |
+
}
|
326 |
+
|
327 |
+
/**
|
328 |
+
* Check if it is time to ask for a review
|
329 |
+
*
|
330 |
+
* @return boolean
|
331 |
+
*/
|
332 |
+
public function is_time() {
|
333 |
+
$installed = (int) get_option( $this->initial_time_key);
|
334 |
+
if ( $installed == false || $installed == null ) {
|
335 |
+
$this->setup_date();
|
336 |
+
$installed = time();
|
337 |
+
}
|
338 |
+
if ( $installed + ( $this->days * 86400 ) >= time() ) {
|
339 |
+
return false;
|
340 |
+
}
|
341 |
+
return true;
|
342 |
+
}
|
343 |
+
|
344 |
+
|
345 |
+
/**
|
346 |
+
* Save the current date as the installation date
|
347 |
+
*
|
348 |
+
*/
|
349 |
+
|
350 |
+
protected function setup_date() {
|
351 |
+
update_option( $this->initial_time_key, time() );
|
352 |
+
}
|
353 |
+
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Get the review prompt message
|
357 |
+
*
|
358 |
+
* @return string
|
359 |
+
*/
|
360 |
+
protected function get_message() {
|
361 |
+
$message = $this->message;
|
362 |
+
$link = $this->get_review_link_tag();
|
363 |
+
$message = $message . ' ' . $link;
|
364 |
+
return wp_kses_post( $message );
|
365 |
+
}
|
366 |
+
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Get the complete link tag
|
370 |
+
*
|
371 |
+
* @return string
|
372 |
+
*/
|
373 |
+
protected function get_review_link_tag() {
|
374 |
+
$link = $this->get_review_link();
|
375 |
+
return "<a href='$link' target='_blank' id='$this->link_id'>$this->link_label</a>";
|
376 |
+
}
|
377 |
+
|
378 |
+
/**
|
379 |
+
* Get the review link
|
380 |
+
*
|
381 |
+
* @return string
|
382 |
+
*/
|
383 |
+
|
384 |
+
protected function get_review_link() {
|
385 |
+
$link = 'https://wordpress.org/support/plugin/';
|
386 |
+
$link .= $this->slug . '/reviews';
|
387 |
+
$link = add_query_arg( 'rate', $this->rating, $link );
|
388 |
+
$link = esc_url( $link . '#new-post' );
|
389 |
+
return $link;
|
390 |
+
}
|
391 |
+
|
392 |
+
|
393 |
+
/**
|
394 |
+
* Notice dismissal triggered by Ajax
|
395 |
+
*
|
396 |
+
* @return void
|
397 |
+
*/
|
398 |
+
public function dismiss_notice_ajax() {
|
399 |
+
|
400 |
+
if ( ! isset( $_POST['id'] ) ) {
|
401 |
+
echo 0;
|
402 |
+
exit;
|
403 |
+
}
|
404 |
+
|
405 |
+
if ( empty( $_POST['id'] ) || false === strpos( $_POST['id'], 'wpbackitup-' ) ) {
|
406 |
+
echo 0;
|
407 |
+
exit;
|
408 |
+
}
|
409 |
+
|
410 |
+
$id = $this->get_id( str_replace( 'wpbackitup-', '', $_POST['id'] ) );
|
411 |
+
|
412 |
+
echo $this->dismiss_notice( $id );
|
413 |
+
exit;
|
414 |
+
|
415 |
+
}
|
416 |
+
|
417 |
+
/**
|
418 |
+
* Dismiss a notice
|
419 |
+
*
|
420 |
+
* @param string $id ID of the notice to dismiss
|
421 |
+
*
|
422 |
+
* @return bool
|
423 |
+
*/
|
424 |
+
public function dismiss_notice( $id ) {
|
425 |
+
|
426 |
+
$notice = $this->get_notice( $this->get_id( $id ) );
|
427 |
+
|
428 |
+
if ( false === $notice ) {
|
429 |
+
return false;
|
430 |
+
}
|
431 |
+
|
432 |
+
if ( $this->is_dismissed( $id ) ) {
|
433 |
+
return false;
|
434 |
+
}
|
435 |
+
|
436 |
+
return 'user' === $notice['scope'] ? $this->dismiss_user( $id ) : $this->dismiss_global( $id );
|
437 |
+
|
438 |
+
}
|
439 |
+
|
440 |
+
/**
|
441 |
+
* Dismiss notice for the current user
|
442 |
+
*
|
443 |
+
* @param string $id Notice ID
|
444 |
+
*
|
445 |
+
* @return int|bool
|
446 |
+
*/
|
447 |
+
private function dismiss_user( $id ) {
|
448 |
+
|
449 |
+
$dismissed = $this->dismissed_user();
|
450 |
+
|
451 |
+
if ( in_array( $id, $dismissed ) ) {
|
452 |
+
return false;
|
453 |
+
}
|
454 |
+
|
455 |
+
array_push( $dismissed, $id );
|
456 |
+
|
457 |
+
return update_user_meta( get_current_user_id(), 'wpbackitup_dismissed_notices', $dismissed );
|
458 |
+
|
459 |
+
}
|
460 |
+
|
461 |
+
/**
|
462 |
+
* Dismiss notice globally on the site
|
463 |
+
*
|
464 |
+
* @param string $id Notice ID
|
465 |
+
*
|
466 |
+
* @return bool
|
467 |
+
*/
|
468 |
+
private function dismiss_global( $id ) {
|
469 |
+
|
470 |
+
$dismissed = $this->dismissed_global();
|
471 |
+
|
472 |
+
if ( in_array( $id, $dismissed ) ) {
|
473 |
+
return false;
|
474 |
+
}
|
475 |
+
|
476 |
+
array_push( $dismissed, $id );
|
477 |
+
|
478 |
+
return update_option( 'wpbackitup_dismissed_notices', $dismissed );
|
479 |
+
|
480 |
+
}
|
481 |
+
|
482 |
+
/**
|
483 |
+
* Get all dismissed notices
|
484 |
+
*
|
485 |
+
* This includes notices dismissed globally or per user.
|
486 |
+
*
|
487 |
+
* @return array
|
488 |
+
*/
|
489 |
+
public function dismissed_notices() {
|
490 |
+
|
491 |
+
$user = $this->dismissed_user();
|
492 |
+
$global = $this->dismissed_global();
|
493 |
+
|
494 |
+
return array_merge( $user, $global );
|
495 |
+
|
496 |
+
}
|
497 |
+
|
498 |
+
/**
|
499 |
+
* Get user dismissed notices
|
500 |
+
*
|
501 |
+
* @return array
|
502 |
+
*/
|
503 |
+
private function dismissed_user() {
|
504 |
+
|
505 |
+
$dismissed = get_user_meta( get_current_user_id(), 'wpbackitup_dismissed_notices', true );
|
506 |
+
|
507 |
+
if ( '' === $dismissed ) {
|
508 |
+
$dismissed = array();
|
509 |
+
}
|
510 |
+
|
511 |
+
return $dismissed;
|
512 |
+
|
513 |
+
}
|
514 |
+
|
515 |
+
/**
|
516 |
+
* Get globally dismissed notices
|
517 |
+
*
|
518 |
+
* @return array
|
519 |
+
*/
|
520 |
+
private function dismissed_global() {
|
521 |
+
return get_option( 'wpbackitup_dismissed_notices', array() );
|
522 |
+
}
|
523 |
+
|
524 |
+
/**
|
525 |
+
* Check if a notice has been dismissed
|
526 |
+
*
|
527 |
+
* @param string $id Notice ID
|
528 |
+
*
|
529 |
+
* @return bool
|
530 |
+
*/
|
531 |
+
public function is_dismissed( $id ) {
|
532 |
+
|
533 |
+
$dismissed = $this->dismissed_notices();
|
534 |
+
|
535 |
+
if ( ! in_array( $this->get_id( $id ), $dismissed ) ) {
|
536 |
+
return false;
|
537 |
+
}
|
538 |
+
|
539 |
+
return true;
|
540 |
+
|
541 |
+
}
|
542 |
+
|
543 |
+
/**
|
544 |
+
* Get all the registered notices
|
545 |
+
*
|
546 |
+
* @return array|null
|
547 |
+
*/
|
548 |
+
public function get_notices() {
|
549 |
+
return $this->notices;
|
550 |
+
}
|
551 |
+
|
552 |
+
/**
|
553 |
+
* Return a specific notice
|
554 |
+
*
|
555 |
+
* @param string $id Notice ID
|
556 |
+
*
|
557 |
+
* @return array|false
|
558 |
+
*/
|
559 |
+
public function get_notice( $id ) {
|
560 |
+
|
561 |
+
$id = $this->get_id( $id );
|
562 |
+
|
563 |
+
if ( ! is_array( $this->notices ) || ! array_key_exists( $id, $this->notices ) ) {
|
564 |
+
return false;
|
565 |
+
}
|
566 |
+
|
567 |
+
return $this->notices[ $id ];
|
568 |
+
|
569 |
+
}
|
570 |
+
|
571 |
+
|
572 |
+
//
|
573 |
+
public function load_script(){
|
574 |
+
?>
|
575 |
+
|
576 |
+
<script>
|
577 |
+
jQuery(document).ready(function($) {
|
578 |
+
$( '.wpbackitup-notice.notice.is-dismissible' ).on('click', '.notice-dismiss', function ( event ) {
|
579 |
+
event.preventDefault();
|
580 |
+
var $this = $(this);
|
581 |
+
if( 'undefined' == $this.parent().attr('id') ){
|
582 |
+
return;
|
583 |
+
}
|
584 |
+
$.post( ajaxurl, {
|
585 |
+
action: 'wpbackitup_dismiss_notice',
|
586 |
+
url: ajaxurl,
|
587 |
+
id: $this.parent().attr('id')
|
588 |
+
});
|
589 |
+
|
590 |
+
});
|
591 |
+
});
|
592 |
+
</script>
|
593 |
+
|
594 |
+
<?php
|
595 |
+
}
|
596 |
+
|
597 |
+
}
|
598 |
+
|
599 |
+
}
|
lib/includes/class-backup.php
CHANGED
@@ -79,7 +79,7 @@ class WPBackItUp_Backup {
|
|
79 |
|
80 |
} catch(Exception $e) {
|
81 |
error_log($e);
|
82 |
-
|
83 |
throw $e;
|
84 |
}
|
85 |
}
|
@@ -103,7 +103,7 @@ class WPBackItUp_Backup {
|
|
103 |
|
104 |
|
105 |
} catch(Exception $e) {
|
106 |
-
//
|
107 |
return false;
|
108 |
}
|
109 |
|
@@ -115,14 +115,14 @@ class WPBackItUp_Backup {
|
|
115 |
* @return bool
|
116 |
*/
|
117 |
public static function end (){
|
118 |
-
//
|
119 |
|
120 |
try{
|
121 |
//locking handled in mutex now
|
122 |
return true;
|
123 |
|
124 |
}catch(Exception $e) {
|
125 |
-
//
|
126 |
return false;
|
127 |
}
|
128 |
}
|
@@ -132,7 +132,7 @@ class WPBackItUp_Backup {
|
|
132 |
* @param $prefix
|
133 |
*/
|
134 |
public function cleanup_backups_by_prefix($prefix) {
|
135 |
-
|
136 |
$backup_root_path=$this->backup_folder_root;
|
137 |
|
138 |
//get a list of all the temps
|
@@ -142,7 +142,7 @@ class WPBackItUp_Backup {
|
|
142 |
$file_system->recursive_delete($folder);
|
143 |
}
|
144 |
|
145 |
-
|
146 |
}
|
147 |
|
148 |
/**
|
@@ -152,7 +152,7 @@ class WPBackItUp_Backup {
|
|
152 |
*/
|
153 |
public function purge_orphaned_backups() {
|
154 |
$log_name = 'debug_purge_folders';
|
155 |
-
|
156 |
|
157 |
// --PURGE BACKUP FOLDER
|
158 |
$folder_list = glob($this->backup_folder_root . '*', GLOB_ONLYDIR);
|
@@ -171,15 +171,15 @@ class WPBackItUp_Backup {
|
|
171 |
if (file_exists($folder)) {
|
172 |
$file_system = new WPBackItUp_FileSystem($log_name);
|
173 |
if (true===$file_system->recursive_delete($folder)){
|
174 |
-
|
175 |
} else{
|
176 |
-
|
177 |
}
|
178 |
}
|
179 |
}
|
180 |
}
|
181 |
|
182 |
-
|
183 |
return true;
|
184 |
}
|
185 |
|
@@ -193,7 +193,7 @@ class WPBackItUp_Backup {
|
|
193 |
*/
|
194 |
public function cleanup_current_backup_async($file_extension_list){
|
195 |
$path= $this->getBackupProjectPath();
|
196 |
-
|
197 |
|
198 |
try {
|
199 |
|
@@ -215,15 +215,15 @@ class WPBackItUp_Backup {
|
|
215 |
}
|
216 |
|
217 |
$cleanup_processor->save()->dispatch();
|
218 |
-
|
219 |
|
220 |
}
|
221 |
|
222 |
-
|
223 |
return true;
|
224 |
|
225 |
} catch(Exception $e) {
|
226 |
-
|
227 |
return false;
|
228 |
}
|
229 |
}
|
@@ -232,7 +232,7 @@ class WPBackItUp_Backup {
|
|
232 |
* Purge old backup files
|
233 |
*/
|
234 |
public function purge_old_files(){
|
235 |
-
|
236 |
$fileSystem = new WPBackItUp_FileSystem( $this->log_name);
|
237 |
|
238 |
//Check the retention
|
@@ -255,7 +255,7 @@ class WPBackItUp_Backup {
|
|
255 |
//Purge Zipped logs in logs older than 5 days
|
256 |
$fileSystem->purge_files($logs_path,'*.zip',$this->backup_retained_days);
|
257 |
|
258 |
-
|
259 |
|
260 |
}
|
261 |
|
@@ -265,10 +265,10 @@ class WPBackItUp_Backup {
|
|
265 |
* @return bool
|
266 |
*/
|
267 |
public function backup_root_folder_exists(){
|
268 |
-
|
269 |
$fileSystem = new WPBackItUp_FileSystem($this->log_name);
|
270 |
if(!$fileSystem->create_dir($this->backup_folder_root)) {
|
271 |
-
|
272 |
return false;
|
273 |
}
|
274 |
|
@@ -279,7 +279,7 @@ class WPBackItUp_Backup {
|
|
279 |
$fileSystem->secure_folder( $logs_dir);
|
280 |
|
281 |
|
282 |
-
|
283 |
return true;
|
284 |
}
|
285 |
|
@@ -289,14 +289,14 @@ class WPBackItUp_Backup {
|
|
289 |
* @return bool
|
290 |
*/
|
291 |
public function create_current_backup_folder(){
|
292 |
-
|
293 |
$fileSystem = new WPBackItUp_FileSystem($this->log_name);
|
294 |
if(!$fileSystem->create_dir($this->backup_project_path)) {
|
295 |
-
|
296 |
return false;
|
297 |
}
|
298 |
|
299 |
-
|
300 |
return true;
|
301 |
}
|
302 |
|
@@ -307,13 +307,13 @@ class WPBackItUp_Backup {
|
|
307 |
*/
|
308 |
public function backup_folder_exists(){
|
309 |
$path=$this->backup_project_path;
|
310 |
-
|
311 |
if(is_writeable($path)) {
|
312 |
-
|
313 |
return true;
|
314 |
}
|
315 |
|
316 |
-
|
317 |
return false;
|
318 |
}
|
319 |
|
@@ -331,7 +331,7 @@ class WPBackItUp_Backup {
|
|
331 |
* @return bool|mixed
|
332 |
*/
|
333 |
public function export_database_mysqldump($current_job,$content_type, $batch_size, $with_mysqlpath=false){
|
334 |
-
|
335 |
|
336 |
$job_id = $current_job->getJobId();
|
337 |
$sqlUtil = new WPBackItUp_SQL($this->log_name);
|
@@ -341,7 +341,7 @@ class WPBackItUp_Backup {
|
|
341 |
|
342 |
//Get one item at a time because batch is split on inventory
|
343 |
$item_batch = $db->get_batch_open_items($batch_id,1,$job_id,$content_type);
|
344 |
-
|
345 |
|
346 |
//It is possible that there are no file to backup so return count or false
|
347 |
if($item_batch == false || $item_batch==0) return $item_batch;
|
@@ -357,7 +357,7 @@ class WPBackItUp_Backup {
|
|
357 |
//Generate the sql name - break up by offset so restore will also work in batches
|
358 |
$sql_data_file_name=$this->backup_project_path. sprintf('db-%s-%d.sql',$table,$offset);
|
359 |
if (false===$sqlUtil->mysqldump_export_data($sql_data_file_name,$table,$offset,$batch_size,$create_table,$with_mysqlpath)){
|
360 |
-
|
361 |
return false;
|
362 |
}
|
363 |
$db->update_item_batch_complete($job_id,$batch_id,1);
|
@@ -365,7 +365,7 @@ class WPBackItUp_Backup {
|
|
365 |
//get count of remaining items
|
366 |
$remaining_count = $db->get_open_item_count($job_id,$content_type);
|
367 |
|
368 |
-
|
369 |
return $remaining_count; //return count;
|
370 |
}
|
371 |
|
@@ -382,7 +382,7 @@ class WPBackItUp_Backup {
|
|
382 |
*/
|
383 |
public function export_database_wpbackitup($current_job,$content_type,$batch_size){
|
384 |
global $wpdb;
|
385 |
-
|
386 |
|
387 |
$job_id = $current_job->getJobId();
|
388 |
$sqlUtil = new WPBackItUp_SQL($this->log_name);
|
@@ -392,7 +392,7 @@ class WPBackItUp_Backup {
|
|
392 |
|
393 |
//Get one item at a time because batch is split on inventory
|
394 |
$item_batch = $db->get_batch_open_items($batch_id,1,$job_id,$content_type);
|
395 |
-
|
396 |
|
397 |
//It is possible that there are no file to backup so return count or false
|
398 |
if($item_batch == false || $item_batch==0) return $item_batch;
|
@@ -409,7 +409,7 @@ class WPBackItUp_Backup {
|
|
409 |
//Generate the sql name - break up by offset so restore will also work in batches
|
410 |
$sql_data_file_name=$this->backup_project_path. sprintf('db-%s-%d.sql',$table,$offset);
|
411 |
if (false===$sqlUtil->wpbackitup_export_data($job_id,$sql_data_file_name,$table,$offset,$batch_size,$create_table)){
|
412 |
-
|
413 |
return false;
|
414 |
}
|
415 |
|
@@ -419,10 +419,58 @@ class WPBackItUp_Backup {
|
|
419 |
//get count of remaining items
|
420 |
$remaining_count = $db->get_open_item_count($job_id,$content_type);
|
421 |
|
422 |
-
|
423 |
return $remaining_count; //return count;
|
424 |
}
|
425 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
/**
|
427 |
* Create siteinfo in project dir
|
428 |
*
|
@@ -433,7 +481,7 @@ class WPBackItUp_Backup {
|
|
433 |
$path=$this->backup_project_path;
|
434 |
$siteinfo_file = $path ."backupsiteinfo.config";
|
435 |
|
436 |
-
|
437 |
try {
|
438 |
|
439 |
$outbut_buffer=array(
|
@@ -446,14 +494,14 @@ class WPBackItUp_Backup {
|
|
446 |
|
447 |
file_put_contents($siteinfo_file,json_encode($outbut_buffer));
|
448 |
if (! file_exists($siteinfo_file)){
|
449 |
-
|
450 |
return false;
|
451 |
}
|
452 |
|
453 |
return true;
|
454 |
|
455 |
}catch(Exception $e) {
|
456 |
-
|
457 |
return false;
|
458 |
}
|
459 |
}
|
@@ -469,13 +517,13 @@ class WPBackItUp_Backup {
|
|
469 |
* @return bool
|
470 |
*/
|
471 |
public function save_database_inventory($job_id,$group_id,$batch_size,$exclude=null) {
|
472 |
-
|
473 |
|
474 |
//create a separate log file for inventory
|
475 |
$inventory_logname = sprintf('debug_inventory_%s_%s',$group_id,$job_id);
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
try {
|
480 |
|
481 |
//get the list of tables and row sizes
|
@@ -498,20 +546,20 @@ class WPBackItUp_Backup {
|
|
498 |
|
499 |
//filter tables on exclude
|
500 |
if (!empty($exclude) && in_array($table_name, $exclude)) {
|
501 |
-
|
502 |
continue;
|
503 |
}
|
504 |
|
505 |
//BATCH records that should be written
|
506 |
$batch_items = ceil($table_rows/$batch_size);
|
507 |
if ($batch_items<=0) $batch_items = 1;//always write at least 1 batch record
|
508 |
-
|
509 |
|
510 |
//generate the sql for all the batches
|
511 |
$offset=0;
|
512 |
for ($i=1; $i <= $batch_items; $i++){
|
513 |
$sql.= "(".$job_id .", '" .$group_id."', '" .$table_name ."', " .$table_size_kb ."," .$offset .",'" .current_time('mysql') ."'),";
|
514 |
-
|
515 |
$offset+=$batch_size;
|
516 |
$total_counter++;
|
517 |
}
|
@@ -519,31 +567,31 @@ class WPBackItUp_Backup {
|
|
519 |
|
520 |
//write all the batch records at one time
|
521 |
if ($total_counter>0) {
|
522 |
-
|
523 |
if (! $db->insert_job_items_with_offset($sql)) {
|
524 |
return false;
|
525 |
}
|
526 |
-
|
527 |
}
|
528 |
|
529 |
$datetime2 = new DateTime('now');
|
530 |
|
531 |
-
|
532 |
|
533 |
if(method_exists($datetime2, 'diff')) {
|
534 |
$interval = $datetime1->diff($datetime2);
|
535 |
-
|
536 |
} else {
|
537 |
$util = new WPBackItUp_Utility($this->log_name);
|
538 |
$interval = $util->date_diff_array($datetime1, $datetime2);
|
539 |
-
|
540 |
}
|
541 |
|
542 |
|
543 |
return true;
|
544 |
|
545 |
} catch(Exception $e) {
|
546 |
-
|
547 |
return false;
|
548 |
}
|
549 |
}
|
@@ -560,21 +608,21 @@ class WPBackItUp_Backup {
|
|
560 |
* @return bool
|
561 |
*/
|
562 |
public function save_folder_inventory($batch_insert_size,$job_id,$group_id,$root_path,$exclude=null) {
|
563 |
-
|
564 |
|
565 |
//create a separate log file for inventory
|
566 |
$inventory_logname = sprintf('debug_inventory_%s_%s',$group_id,$job_id);
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
try {
|
572 |
$batch_counter = 0;
|
573 |
$total_counter=0;
|
574 |
|
575 |
//IF the path is not valid then cant create inventory
|
576 |
if (! is_dir($root_path)){
|
577 |
-
|
578 |
return false;
|
579 |
}
|
580 |
|
@@ -602,56 +650,56 @@ class WPBackItUp_Backup {
|
|
602 |
mb_regex_encoding("UTF-8");
|
603 |
$temp_file_name = mb_ereg_replace(WPBACKITUP__VALID_FILENAME_REGEX, '', basename($file));
|
604 |
if(strcmp($temp_file_name, basename($file)) != 0){
|
605 |
-
|
606 |
-
|
607 |
continue;
|
608 |
}
|
609 |
}
|
610 |
|
611 |
if ( $file->isFile()) {
|
612 |
if ($batch_counter>=$batch_insert_size){
|
613 |
-
|
614 |
if (! $db->insert_job_items($sql)) {
|
615 |
return false;
|
616 |
}
|
617 |
-
|
618 |
$sql="";
|
619 |
$batch_counter=0;
|
620 |
}
|
621 |
$total_counter++;
|
622 |
$batch_counter++;
|
623 |
$file_size=ceil($file->getSize()/1024);//round up
|
624 |
-
|
625 |
$sql.= "(".$job_id .", '" .$group_id."', '" .utf8_encode($file_path) ."', ".$file_size .",'" . current_time('mysql') ."'),";
|
626 |
}
|
627 |
}
|
628 |
|
629 |
if ($batch_counter>0) {
|
630 |
-
|
631 |
if (! $db->insert_job_items($sql)) {
|
632 |
return false;
|
633 |
}
|
634 |
-
|
635 |
}
|
636 |
|
637 |
$datetime2 = new DateTime('now');
|
638 |
|
639 |
-
|
640 |
|
641 |
if(method_exists($datetime2, 'diff')) {
|
642 |
$interval = $datetime1->diff($datetime2);
|
643 |
-
|
644 |
} else {
|
645 |
$util = new WPBackItUp_Utility($this->log_name);
|
646 |
$interval = $util->date_diff_array($datetime1, $datetime2);
|
647 |
-
|
648 |
}
|
649 |
|
650 |
|
651 |
return true;
|
652 |
|
653 |
} catch(Exception $e) {
|
654 |
-
|
655 |
return false;
|
656 |
}
|
657 |
}
|
@@ -668,11 +716,11 @@ class WPBackItUp_Backup {
|
|
668 |
* @return bool
|
669 |
*/
|
670 |
public function save_file_list_inventory($batch_insert_size,$job_id,$group_id,$root_path,$file_list) {
|
671 |
-
|
672 |
|
673 |
//check is array list
|
674 |
if (! is_array($file_list)) {
|
675 |
-
|
676 |
return false;
|
677 |
}
|
678 |
|
@@ -687,7 +735,7 @@ class WPBackItUp_Backup {
|
|
687 |
|
688 |
//skip if folder
|
689 |
if ( is_dir( $file_path ) ) {
|
690 |
-
|
691 |
continue;
|
692 |
}
|
693 |
|
@@ -706,7 +754,7 @@ class WPBackItUp_Backup {
|
|
706 |
//get rid of root path and utf8 encode
|
707 |
$file_path = utf8_encode(str_replace($root_path,'',$file_path));
|
708 |
|
709 |
-
|
710 |
$sql.= "(".$job_id .", '" .$group_id."', '" .$file_path ."', ".$file_size .",'" . current_time('mysql') . "' ),";
|
711 |
}
|
712 |
|
@@ -720,17 +768,17 @@ class WPBackItUp_Backup {
|
|
720 |
|
721 |
if(method_exists($datetime2, 'diff')) {
|
722 |
$interval = $datetime1->diff($datetime2);
|
723 |
-
|
724 |
} else {
|
725 |
$util = new WPBackItUp_Utility($this->log_name);
|
726 |
$interval = $util->date_diff_array($datetime1, $datetime2);
|
727 |
-
|
728 |
}
|
729 |
|
730 |
return true;
|
731 |
|
732 |
} catch(Exception $e) {
|
733 |
-
|
734 |
return false;
|
735 |
}
|
736 |
}
|
@@ -748,7 +796,7 @@ class WPBackItUp_Backup {
|
|
748 |
*/
|
749 |
public function backup_files($job_id,$source_root,$content_type){
|
750 |
global $WPBackitup;
|
751 |
-
|
752 |
|
753 |
//get files to backup
|
754 |
$db = new WPBackItUp_DataAccess();
|
@@ -772,12 +820,12 @@ class WPBackItUp_Backup {
|
|
772 |
$batch_size=$WPBackitup->backup_others_batch_size();
|
773 |
break;
|
774 |
default:
|
775 |
-
|
776 |
return false;
|
777 |
|
778 |
}
|
779 |
|
780 |
-
|
781 |
|
782 |
//get a timestamp for the batch id
|
783 |
$batch_id=current_time( 'timestamp' );
|
@@ -786,7 +834,7 @@ class WPBackItUp_Backup {
|
|
786 |
// sometimes file list is an empty, still couldn't figure out why.
|
787 |
if(is_array($file_list)){
|
788 |
if(empty($file_list)){
|
789 |
-
|
790 |
return 0;
|
791 |
}
|
792 |
}
|
@@ -795,11 +843,11 @@ class WPBackItUp_Backup {
|
|
795 |
|
796 |
//$zip_file_path = $this->backup_project_path . $this->backup_name .'-'.$content_type .'.zip';
|
797 |
$zip_file_path = sprintf('%s%s-%s-%s.zip',$this->backup_project_path,$this->backup_name,$content_type,$batch_id);
|
798 |
-
|
799 |
|
800 |
//IF false error happened
|
801 |
$file_count=$this->backup_files_to_zip($source_root,$target_root,$file_list,$zip_file_path);
|
802 |
-
|
803 |
if (false===$file_count){
|
804 |
return false;
|
805 |
}
|
@@ -809,16 +857,16 @@ class WPBackItUp_Backup {
|
|
809 |
|
810 |
//Check to see if the file exists, it is possible that it does not if only empty folders were contained
|
811 |
if(! file_exists($zip_file_path) ) {
|
812 |
-
|
813 |
|
814 |
$file_system = new WPBackItUp_FileSystem($this->log_name);
|
815 |
$files_in_temp_directory = $file_system->get_fileonly_list($this->backup_project_path, 'zip');
|
816 |
-
|
817 |
-
|
818 |
return false;
|
819 |
}
|
820 |
|
821 |
-
|
822 |
|
823 |
//update the batch with the number of files in the added count
|
824 |
$db->update_item_batch_complete($job_id,$batch_id,$file_count);
|
@@ -831,7 +879,7 @@ class WPBackItUp_Backup {
|
|
831 |
//if any files werent backed up then return false
|
832 |
$error_count = $db->get_error_item_count($job_id,$content_type);
|
833 |
if ($error_count>0){
|
834 |
-
|
835 |
return false;
|
836 |
}
|
837 |
}
|
@@ -851,7 +899,7 @@ class WPBackItUp_Backup {
|
|
851 |
* @return bool
|
852 |
*/
|
853 |
public function validate_backup_files_by_batch_id($job_id,$content_type,$batch_id){
|
854 |
-
|
855 |
|
856 |
//get files to backup
|
857 |
$db = new WPBackItUp_DataAccess();
|
@@ -877,7 +925,7 @@ class WPBackItUp_Backup {
|
|
877 |
|
878 |
//It is possible that there were no files backed up
|
879 |
if( $file_list == false || $file_list==0 ) {
|
880 |
-
|
881 |
return true;
|
882 |
}
|
883 |
|
@@ -887,35 +935,35 @@ class WPBackItUp_Backup {
|
|
887 |
|
888 |
//get zip path
|
889 |
$zip_file_path = sprintf('%s-%s-%s.zip',$this->backup_project_path . $this->backup_name, $content_type,$batch_id);
|
890 |
-
|
891 |
|
892 |
if ( ! file_exists($zip_file_path) ) {
|
893 |
-
|
894 |
// Scanning Temp Directory.
|
895 |
$files_on_temp_directory = scandir($this->backup_project_path);
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
return false;
|
900 |
}
|
901 |
|
902 |
$current_zip_file = $zip_file_path;
|
903 |
$zip = new WPBackItUp_Zip($this->log_name,$current_zip_file);
|
904 |
-
|
905 |
|
906 |
foreach($file_list as $file) {
|
907 |
$item = $target_root .'/' .utf8_decode( $file->item );
|
908 |
|
909 |
//validate file exists in zip
|
910 |
if (false===$zip->validate_file($item)) {
|
911 |
-
|
912 |
$zip->close();
|
913 |
return false;
|
914 |
}
|
915 |
$file_counter++;
|
916 |
}
|
917 |
|
918 |
-
|
919 |
if (null!=$zip) $zip->close();
|
920 |
return true;
|
921 |
}
|
@@ -935,30 +983,30 @@ class WPBackItUp_Backup {
|
|
935 |
private function backup_files_to_zip($source_root,$target_root,$file_list, $zip_file_path){
|
936 |
global $WPBackitup;
|
937 |
|
938 |
-
|
939 |
|
940 |
if (empty($file_list) || !isset($file_list)) {
|
941 |
-
|
942 |
-
|
943 |
return false;
|
944 |
}
|
945 |
|
946 |
$zip_max_file_size = $WPBackitup->max_zip_size();
|
947 |
|
948 |
-
|
949 |
-
|
950 |
$zip = new WPBackItUp_Zip($this->log_name,$zip_file_path);
|
951 |
|
952 |
$file_size_counter = 0;
|
953 |
foreach($file_list as $file) {
|
954 |
$item = $source_root. '/' .utf8_decode($file->item);
|
955 |
-
|
956 |
|
957 |
clearstatcache();
|
958 |
$file_size_counter += filesize($item);
|
959 |
-
|
960 |
if($file_size_counter >= $zip_max_file_size){
|
961 |
-
|
962 |
break;//jump out of the for loop
|
963 |
}
|
964 |
|
@@ -967,11 +1015,11 @@ class WPBackItUp_Backup {
|
|
967 |
$target_item_path= str_replace('//','/',$target_item_path);
|
968 |
$target_item_path= str_replace('\\','/',$target_item_path);
|
969 |
|
970 |
-
//
|
971 |
if ( $zip->add_file($item,$target_item_path)) {
|
972 |
-
|
973 |
} else {
|
974 |
-
|
975 |
return false;
|
976 |
}
|
977 |
}
|
@@ -979,11 +1027,11 @@ class WPBackItUp_Backup {
|
|
979 |
$files_count = $zip->get_files_in_zip();
|
980 |
|
981 |
//if we get here then close the zip
|
982 |
-
|
983 |
-
|
984 |
$zip_closed = $zip->close();//close the zip - true for success/false error
|
985 |
|
986 |
-
|
987 |
|
988 |
//return filecount on success and false on close error
|
989 |
return true===$zip_closed? $files_count: false;
|
@@ -994,50 +1042,49 @@ class WPBackItUp_Backup {
|
|
994 |
* @param $source_root
|
995 |
* @param $target_root
|
996 |
* @param $suffix
|
997 |
-
* @param $file_list
|
998 |
* @param $batch_size
|
|
|
999 |
*
|
1000 |
* @return bool|int false on error OR count
|
1001 |
*/
|
1002 |
-
public function backup_file_list($source_root,$target_root,$suffix
|
1003 |
-
|
1004 |
|
1005 |
if (! is_array($file_list)) {
|
1006 |
-
|
1007 |
-
|
1008 |
return false;
|
1009 |
}
|
1010 |
|
1011 |
-
$batch_id=current_time( 'timestamp' );
|
1012 |
-
|
1013 |
//$zip_file_path = $this->backup_project_path . $this->backup_name .'-'.$suffix .'.tmp';
|
1014 |
$zip_file_path = sprintf('%s%s-%s-%s.zip',$this->backup_project_path,$this->backup_name,$suffix,$batch_id);
|
1015 |
$zip = new WPBackItUp_Zip($this->log_name,$zip_file_path);
|
1016 |
foreach($file_list as $item) {
|
1017 |
$item = utf8_decode($item);
|
1018 |
-
|
1019 |
|
1020 |
//skip it if folder
|
1021 |
if ( is_dir( $item ) ) {
|
1022 |
-
|
1023 |
array_shift( $file_list ); //remove from list
|
1024 |
continue;
|
1025 |
}
|
1026 |
|
1027 |
//replace the source path with the target
|
1028 |
$target_item_path = str_replace(rtrim($source_root, '/'),rtrim($target_root,'/'),$item);
|
1029 |
-
|
1030 |
if ( $zip->add_file($item,$target_item_path)) {
|
1031 |
array_shift($file_list);
|
1032 |
-
|
1033 |
//If we have added X# of files or hit the size limit then lets close the zip and finish on the next pass
|
1034 |
if( $zip->get_zip_file_count()>=$batch_size){
|
1035 |
$zip->close();//close the zip
|
1036 |
-
|
1037 |
return count($file_list);
|
1038 |
}
|
1039 |
} else {
|
1040 |
-
|
1041 |
return false;
|
1042 |
}
|
1043 |
}
|
@@ -1046,28 +1093,28 @@ class WPBackItUp_Backup {
|
|
1046 |
$zip->close();//close the zip
|
1047 |
|
1048 |
if( ! file_exists($zip_file_path) ){
|
1049 |
-
|
1050 |
return false;
|
1051 |
}
|
1052 |
|
1053 |
-
|
1054 |
return count($file_list);
|
1055 |
}
|
1056 |
|
1057 |
|
1058 |
|
1059 |
public function backup_file_to_zip($source_root,$target_root,$file_path, $zip_file_path){
|
1060 |
-
|
1061 |
|
1062 |
if ( empty($file_path)) {
|
1063 |
-
|
1064 |
-
|
1065 |
return false;
|
1066 |
}
|
1067 |
|
1068 |
if ( !file_exists($file_path)) {
|
1069 |
-
|
1070 |
-
|
1071 |
return false;
|
1072 |
}
|
1073 |
|
@@ -1075,15 +1122,15 @@ class WPBackItUp_Backup {
|
|
1075 |
$zip = new WPBackItUp_Zip($this->log_name,$zip_file_path);
|
1076 |
|
1077 |
$file_path = utf8_decode($file_path);
|
1078 |
-
|
1079 |
|
1080 |
//replace the source path with the target
|
1081 |
$target_item_path = str_replace(rtrim($source_root, '/'),rtrim($target_root,'/'),$file_path);
|
1082 |
-
|
1083 |
if ( $zip->add_file($file_path,$target_item_path)) {
|
1084 |
-
|
1085 |
} else {
|
1086 |
-
|
1087 |
return false;
|
1088 |
}
|
1089 |
|
@@ -1103,7 +1150,7 @@ class WPBackItUp_Backup {
|
|
1103 |
public function remove_supporting_zips($zip_files){
|
1104 |
|
1105 |
if (!is_array($zip_files) || count($zip_files)<=0) {
|
1106 |
-
|
1107 |
return false;
|
1108 |
}
|
1109 |
|
@@ -1134,14 +1181,14 @@ class WPBackItUp_Backup {
|
|
1134 |
}
|
1135 |
|
1136 |
$cleanup_processor->save()->dispatch();
|
1137 |
-
|
1138 |
}
|
1139 |
|
1140 |
|
1141 |
return true;
|
1142 |
|
1143 |
} catch(Exception $e) {
|
1144 |
-
|
1145 |
return false;
|
1146 |
}
|
1147 |
}
|
@@ -1152,11 +1199,11 @@ class WPBackItUp_Backup {
|
|
1152 |
* @return bool
|
1153 |
*/
|
1154 |
public function create_backup_manifest(){
|
1155 |
-
|
1156 |
|
1157 |
//get a list of all the zips
|
1158 |
$backup_files_path = array_filter(glob($this->backup_project_path. '*.zip'), 'is_file');
|
1159 |
-
|
1160 |
if (is_array($backup_files_path) && count($backup_files_path)>0){
|
1161 |
|
1162 |
//build the manifest with file size
|
@@ -1174,7 +1221,7 @@ class WPBackItUp_Backup {
|
|
1174 |
|
1175 |
$bytes = file_put_contents($manifest_file,json_encode($backup_file_list));
|
1176 |
if ( $bytes===false || $bytes<=0){
|
1177 |
-
|
1178 |
return false;
|
1179 |
}
|
1180 |
|
@@ -1188,17 +1235,17 @@ class WPBackItUp_Backup {
|
|
1188 |
$target_item_path = str_replace(rtrim($this->backup_project_path, '/'),rtrim('site-data','/'),$manifest_file);
|
1189 |
if ($zip->add_file($manifest_file,$target_item_path)) {
|
1190 |
$zip->close();//close the zip
|
1191 |
-
|
1192 |
@unlink($manifest_file);
|
1193 |
return true;
|
1194 |
}
|
1195 |
}else{
|
1196 |
-
|
1197 |
}
|
1198 |
}
|
1199 |
|
1200 |
@unlink($manifest_file);
|
1201 |
-
|
1202 |
return false;
|
1203 |
}
|
1204 |
|
@@ -1228,7 +1275,7 @@ class WPBackItUp_Backup {
|
|
1228 |
* @return bool
|
1229 |
*/
|
1230 |
public function rename_backup_folder() {
|
1231 |
-
|
1232 |
|
1233 |
$backup_project_path = $this->backup_project_path;
|
1234 |
//remove the 4 character prefix
|
@@ -1236,13 +1283,13 @@ class WPBackItUp_Backup {
|
|
1236 |
|
1237 |
$file_system = new WPBackItUp_FileSystem($this->log_name);
|
1238 |
if (! $file_system->rename_file($backup_project_path,$new_backup_path)){
|
1239 |
-
|
1240 |
return false;
|
1241 |
}
|
1242 |
|
1243 |
$this->set_final_backup_path();
|
1244 |
|
1245 |
-
|
1246 |
return true;
|
1247 |
}
|
1248 |
|
@@ -1251,7 +1298,7 @@ class WPBackItUp_Backup {
|
|
1251 |
*
|
1252 |
*/
|
1253 |
public function set_final_backup_path(){
|
1254 |
-
|
1255 |
|
1256 |
$backup_project_path = $this->backup_project_path;
|
1257 |
$new_backup_path = str_replace('TMP_','',$backup_project_path);
|
@@ -1259,7 +1306,7 @@ class WPBackItUp_Backup {
|
|
1259 |
//set the path to the new path
|
1260 |
$this->backup_project_path=$new_backup_path;
|
1261 |
|
1262 |
-
|
1263 |
}
|
1264 |
|
1265 |
/**
|
79 |
|
80 |
} catch(Exception $e) {
|
81 |
error_log($e);
|
82 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .$e);
|
83 |
throw $e;
|
84 |
}
|
85 |
}
|
103 |
|
104 |
|
105 |
} catch(Exception $e) {
|
106 |
+
// WPBackItUp_Logger::log_error($lockfile_logname,__METHOD__,'Process Lock error: ' .$e);
|
107 |
return false;
|
108 |
}
|
109 |
|
115 |
* @return bool
|
116 |
*/
|
117 |
public static function end (){
|
118 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin - Unlock File:' . $this->lockFileName);
|
119 |
|
120 |
try{
|
121 |
//locking handled in mutex now
|
122 |
return true;
|
123 |
|
124 |
}catch(Exception $e) {
|
125 |
+
//WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Cant unlock file: ' .$e);
|
126 |
return false;
|
127 |
}
|
128 |
}
|
132 |
* @param $prefix
|
133 |
*/
|
134 |
public function cleanup_backups_by_prefix($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
|
142 |
$file_system->recursive_delete($folder);
|
143 |
}
|
144 |
|
145 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End' );
|
146 |
}
|
147 |
|
148 |
/**
|
152 |
*/
|
153 |
public function purge_orphaned_backups() {
|
154 |
$log_name = 'debug_purge_folders';
|
155 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Begin' );
|
156 |
|
157 |
// --PURGE BACKUP FOLDER
|
158 |
$folder_list = glob($this->backup_folder_root . '*', GLOB_ONLYDIR);
|
171 |
if (file_exists($folder)) {
|
172 |
$file_system = new WPBackItUp_FileSystem($log_name);
|
173 |
if (true===$file_system->recursive_delete($folder)){
|
174 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Folder Deleted:'.$folder);
|
175 |
} else{
|
176 |
+
WPBackItUp_Logger::log_error($log_name,__METHOD__,'Folder NOT Deleted:'.$folder);
|
177 |
}
|
178 |
}
|
179 |
}
|
180 |
}
|
181 |
|
182 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'End');
|
183 |
return true;
|
184 |
}
|
185 |
|
193 |
*/
|
194 |
public function cleanup_current_backup_async($file_extension_list){
|
195 |
$path= $this->getBackupProjectPath();
|
196 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin - Cleanup Backup Folder:' . $path);
|
197 |
|
198 |
try {
|
199 |
|
215 |
}
|
216 |
|
217 |
$cleanup_processor->save()->dispatch();
|
218 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Cleanup job dispatched.');
|
219 |
|
220 |
}
|
221 |
|
222 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End - Work Files Deleted');
|
223 |
return true;
|
224 |
|
225 |
} catch(Exception $e) {
|
226 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Error Occurred: ' .$e);
|
227 |
return false;
|
228 |
}
|
229 |
}
|
232 |
* Purge old backup files
|
233 |
*/
|
234 |
public function purge_old_files(){
|
235 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
236 |
$fileSystem = new WPBackItUp_FileSystem( $this->log_name);
|
237 |
|
238 |
//Check the retention
|
255 |
//Purge Zipped logs in logs older than 5 days
|
256 |
$fileSystem->purge_files($logs_path,'*.zip',$this->backup_retained_days);
|
257 |
|
258 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
259 |
|
260 |
}
|
261 |
|
265 |
* @return bool
|
266 |
*/
|
267 |
public function backup_root_folder_exists(){
|
268 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin: ' .$this->backup_folder_root);
|
269 |
$fileSystem = new WPBackItUp_FileSystem($this->log_name);
|
270 |
if(!$fileSystem->create_dir($this->backup_folder_root)) {
|
271 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Cant create backup folder :'. $this->backup_folder_root);
|
272 |
return false;
|
273 |
}
|
274 |
|
279 |
$fileSystem->secure_folder( $logs_dir);
|
280 |
|
281 |
|
282 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
283 |
return true;
|
284 |
}
|
285 |
|
289 |
* @return bool
|
290 |
*/
|
291 |
public function create_current_backup_folder(){
|
292 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin: ' .$this->backup_project_path);
|
293 |
$fileSystem = new WPBackItUp_FileSystem($this->log_name);
|
294 |
if(!$fileSystem->create_dir($this->backup_project_path)) {
|
295 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Cant create backup folder :'. $this->backup_project_path);
|
296 |
return false;
|
297 |
}
|
298 |
|
299 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
300 |
return true;
|
301 |
}
|
302 |
|
307 |
*/
|
308 |
public function backup_folder_exists(){
|
309 |
$path=$this->backup_project_path;
|
310 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Is folder writeable: ' .$path);
|
311 |
if(is_writeable($path)) {
|
312 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Folder IS writeable');
|
313 |
return true;
|
314 |
}
|
315 |
|
316 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Folder NOT writeable');
|
317 |
return false;
|
318 |
}
|
319 |
|
331 |
* @return bool|mixed
|
332 |
*/
|
333 |
public function export_database_mysqldump($current_job,$content_type, $batch_size, $with_mysqlpath=false){
|
334 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin MYSQLDUMP Database Export.');
|
335 |
|
336 |
$job_id = $current_job->getJobId();
|
337 |
$sqlUtil = new WPBackItUp_SQL($this->log_name);
|
341 |
|
342 |
//Get one item at a time because batch is split on inventory
|
343 |
$item_batch = $db->get_batch_open_items($batch_id,1,$job_id,$content_type);
|
344 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,var_export($item_batch,true));
|
345 |
|
346 |
//It is possible that there are no file to backup so return count or false
|
347 |
if($item_batch == false || $item_batch==0) return $item_batch;
|
357 |
//Generate the sql name - break up by offset so restore will also work in batches
|
358 |
$sql_data_file_name=$this->backup_project_path. sprintf('db-%s-%d.sql',$table,$offset);
|
359 |
if (false===$sqlUtil->mysqldump_export_data($sql_data_file_name,$table,$offset,$batch_size,$create_table,$with_mysqlpath)){
|
360 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'SQL EXPORT FAILED');
|
361 |
return false;
|
362 |
}
|
363 |
$db->update_item_batch_complete($job_id,$batch_id,1);
|
365 |
//get count of remaining items
|
366 |
$remaining_count = $db->get_open_item_count($job_id,$content_type);
|
367 |
|
368 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End MYSQLDUMP Database Export');
|
369 |
return $remaining_count; //return count;
|
370 |
}
|
371 |
|
382 |
*/
|
383 |
public function export_database_wpbackitup($current_job,$content_type,$batch_size){
|
384 |
global $wpdb;
|
385 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin WPBackItUp Database Export.');
|
386 |
|
387 |
$job_id = $current_job->getJobId();
|
388 |
$sqlUtil = new WPBackItUp_SQL($this->log_name);
|
392 |
|
393 |
//Get one item at a time because batch is split on inventory
|
394 |
$item_batch = $db->get_batch_open_items($batch_id,1,$job_id,$content_type);
|
395 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,var_export($item_batch,true));
|
396 |
|
397 |
//It is possible that there are no file to backup so return count or false
|
398 |
if($item_batch == false || $item_batch==0) return $item_batch;
|
409 |
//Generate the sql name - break up by offset so restore will also work in batches
|
410 |
$sql_data_file_name=$this->backup_project_path. sprintf('db-%s-%d.sql',$table,$offset);
|
411 |
if (false===$sqlUtil->wpbackitup_export_data($job_id,$sql_data_file_name,$table,$offset,$batch_size,$create_table)){
|
412 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'SQL EXPORT FAILED');
|
413 |
return false;
|
414 |
}
|
415 |
|
419 |
//get count of remaining items
|
420 |
$remaining_count = $db->get_open_item_count($job_id,$content_type);
|
421 |
|
422 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End WPBackItUp Database Export');
|
423 |
return $remaining_count; //return count;
|
424 |
}
|
425 |
|
426 |
+
/**
|
427 |
+
* Get sql file list and merge into a single file
|
428 |
+
*
|
429 |
+
* @param $task
|
430 |
+
* @param $batch_size
|
431 |
+
* @param $search_path
|
432 |
+
* @param $toFile_path
|
433 |
+
* @param $file_type
|
434 |
+
*
|
435 |
+
* @return bool|mixed
|
436 |
+
*/
|
437 |
+
public function merge_sql_files_to_path($task, $batch_size, $search_path, $toFile_path, $file_type){
|
438 |
+
|
439 |
+
$sql_files = $task->getTaskMetaValue('sql_files_to_merge', array());
|
440 |
+
$file_system = new WPBackItUp_FileSystem();
|
441 |
+
$counter = 0;
|
442 |
+
|
443 |
+
if(empty($sql_files)){
|
444 |
+
$sql_files = $file_system->get_fileonly_list($search_path, $file_type);
|
445 |
+
// delete DB file if exist for first time.
|
446 |
+
@unlink($toFile_path);
|
447 |
+
}
|
448 |
+
|
449 |
+
foreach ( $sql_files as $i => $file ) {
|
450 |
+
if($counter===$batch_size){
|
451 |
+
$task->setTaskMetaValue('sql_files_to_merge',$sql_files);
|
452 |
+
return count($sql_files);
|
453 |
+
}
|
454 |
+
if ( false === $file_system->append_file_chunked($file,$toFile_path)){
|
455 |
+
@unlink($toFile_path); //delete DB file
|
456 |
+
WPBackItUp_Logger::log_warning($this->log_name,__METHOD__, 'Could not merge SQL file:' . $file);
|
457 |
+
|
458 |
+
return false;
|
459 |
+
};
|
460 |
+
|
461 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__, 'File Appended:' . $file);
|
462 |
+
|
463 |
+
$counter++;
|
464 |
+
// removing already appended file from the array.
|
465 |
+
unset($sql_files[$i]);
|
466 |
+
}
|
467 |
+
|
468 |
+
$task->setTaskMetaValue('sql_files_to_merge',$sql_files);
|
469 |
+
return count($sql_files);
|
470 |
+
|
471 |
+
}
|
472 |
+
|
473 |
+
|
474 |
/**
|
475 |
* Create siteinfo in project dir
|
476 |
*
|
481 |
$path=$this->backup_project_path;
|
482 |
$siteinfo_file = $path ."backupsiteinfo.config";
|
483 |
|
484 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Create Site Info File:'.$siteinfo_file);
|
485 |
try {
|
486 |
|
487 |
$outbut_buffer=array(
|
494 |
|
495 |
file_put_contents($siteinfo_file,json_encode($outbut_buffer));
|
496 |
if (! file_exists($siteinfo_file)){
|
497 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Site Info file was not created successfully.');
|
498 |
return false;
|
499 |
}
|
500 |
|
501 |
return true;
|
502 |
|
503 |
}catch(Exception $e) {
|
504 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,' Exception: ' .$e);
|
505 |
return false;
|
506 |
}
|
507 |
}
|
517 |
* @return bool
|
518 |
*/
|
519 |
public function save_database_inventory($job_id,$group_id,$batch_size,$exclude=null) {
|
520 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin:' .$group_id);
|
521 |
|
522 |
//create a separate log file for inventory
|
523 |
$inventory_logname = sprintf('debug_inventory_%s_%s',$group_id,$job_id);
|
524 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '**BEGIN**');
|
525 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, 'Exclude: ' .var_export($exclude,true));
|
526 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '***');
|
527 |
try {
|
528 |
|
529 |
//get the list of tables and row sizes
|
546 |
|
547 |
//filter tables on exclude
|
548 |
if (!empty($exclude) && in_array($table_name, $exclude)) {
|
549 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, sprintf('EXCLUDE table:%s %s %s kb ',$table_name,$table_rows,$table_size_kb));
|
550 |
continue;
|
551 |
}
|
552 |
|
553 |
//BATCH records that should be written
|
554 |
$batch_items = ceil($table_rows/$batch_size);
|
555 |
if ($batch_items<=0) $batch_items = 1;//always write at least 1 batch record
|
556 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, sprintf('ROW_COUNT/BATCH_SIZE=BATCH RECORDS:%s %d/%d=%d ',$table_name,$table_rows,$batch_size,$batch_items));
|
557 |
|
558 |
//generate the sql for all the batches
|
559 |
$offset=0;
|
560 |
for ($i=1; $i <= $batch_items; $i++){
|
561 |
$sql.= "(".$job_id .", '" .$group_id."', '" .$table_name ."', " .$table_size_kb ."," .$offset .",'" .current_time('mysql') ."'),";
|
562 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, sprintf('Add table:%s Offset:%s',$table_name,$offset));
|
563 |
$offset+=$batch_size;
|
564 |
$total_counter++;
|
565 |
}
|
567 |
|
568 |
//write all the batch records at one time
|
569 |
if ($total_counter>0) {
|
570 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '*Try Write Batch*');
|
571 |
if (! $db->insert_job_items_with_offset($sql)) {
|
572 |
return false;
|
573 |
}
|
574 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '*Write Batch SUCCESS*');
|
575 |
}
|
576 |
|
577 |
$datetime2 = new DateTime('now');
|
578 |
|
579 |
+
WPBackItUp_Logger::log_info($inventory_logname, __METHOD__, '**END**');
|
580 |
|
581 |
if(method_exists($datetime2, 'diff')) {
|
582 |
$interval = $datetime1->diff($datetime2);
|
583 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Count/Time: ' .$total_counter . '-' . $interval->format('%s seconds'));
|
584 |
} else {
|
585 |
$util = new WPBackItUp_Utility($this->log_name);
|
586 |
$interval = $util->date_diff_array($datetime1, $datetime2);
|
587 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Count/Time: ' .$total_counter . '-' . $interval['second'] . ' seconds');
|
588 |
}
|
589 |
|
590 |
|
591 |
return true;
|
592 |
|
593 |
} catch(Exception $e) {
|
594 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .$e);
|
595 |
return false;
|
596 |
}
|
597 |
}
|
608 |
* @return bool
|
609 |
*/
|
610 |
public function save_folder_inventory($batch_insert_size,$job_id,$group_id,$root_path,$exclude=null) {
|
611 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin:' .$group_id);
|
612 |
|
613 |
//create a separate log file for inventory
|
614 |
$inventory_logname = sprintf('debug_inventory_%s_%s',$group_id,$job_id);
|
615 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '**BEGIN**');
|
616 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, 'Root Path: ' .$root_path);
|
617 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, 'Exclude: ' .var_export($exclude,true));
|
618 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '***');
|
619 |
try {
|
620 |
$batch_counter = 0;
|
621 |
$total_counter=0;
|
622 |
|
623 |
//IF the path is not valid then cant create inventory
|
624 |
if (! is_dir($root_path)){
|
625 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Folder does not exist: ' .$root_path);
|
626 |
return false;
|
627 |
}
|
628 |
|
650 |
mb_regex_encoding("UTF-8");
|
651 |
$temp_file_name = mb_ereg_replace(WPBACKITUP__VALID_FILENAME_REGEX, '', basename($file));
|
652 |
if(strcmp($temp_file_name, basename($file)) != 0){
|
653 |
+
WPBackItUp_Logger::log_error($inventory_logname,__METHOD__,'Skipping file: ' . $file );
|
654 |
+
WPBackItUp_Logger::log_error($inventory_logname,__METHOD__,'Filename after removing illegal character: ' . $temp_file_name );
|
655 |
continue;
|
656 |
}
|
657 |
}
|
658 |
|
659 |
if ( $file->isFile()) {
|
660 |
if ($batch_counter>=$batch_insert_size){
|
661 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '*Try Write Batch*');
|
662 |
if (! $db->insert_job_items($sql)) {
|
663 |
return false;
|
664 |
}
|
665 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '*Write Batch SUCCESS*');
|
666 |
$sql="";
|
667 |
$batch_counter=0;
|
668 |
}
|
669 |
$total_counter++;
|
670 |
$batch_counter++;
|
671 |
$file_size=ceil($file->getSize()/1024);//round up
|
672 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, 'Add File: ' .$batch_counter . ' ' .$file_path);
|
673 |
$sql.= "(".$job_id .", '" .$group_id."', '" .utf8_encode($file_path) ."', ".$file_size .",'" . current_time('mysql') ."'),";
|
674 |
}
|
675 |
}
|
676 |
|
677 |
if ($batch_counter>0) {
|
678 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '*Try Write Batch*');
|
679 |
if (! $db->insert_job_items($sql)) {
|
680 |
return false;
|
681 |
}
|
682 |
+
WPBackItUp_Logger::log_info($inventory_logname,__METHOD__, '*Write Batch SUCCESS*');
|
683 |
}
|
684 |
|
685 |
$datetime2 = new DateTime('now');
|
686 |
|
687 |
+
WPBackItUp_Logger::log_info($inventory_logname, __METHOD__, '**END**');
|
688 |
|
689 |
if(method_exists($datetime2, 'diff')) {
|
690 |
$interval = $datetime1->diff($datetime2);
|
691 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Count/Time: ' .$total_counter . '-' . $interval->format('%s seconds'));
|
692 |
} else {
|
693 |
$util = new WPBackItUp_Utility($this->log_name);
|
694 |
$interval = $util->date_diff_array($datetime1, $datetime2);
|
695 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Count/Time: ' .$total_counter . '-' . $interval['second'] . ' seconds');
|
696 |
}
|
697 |
|
698 |
|
699 |
return true;
|
700 |
|
701 |
} catch(Exception $e) {
|
702 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .$e);
|
703 |
return false;
|
704 |
}
|
705 |
}
|
716 |
* @return bool
|
717 |
*/
|
718 |
public function save_file_list_inventory($batch_insert_size,$job_id,$group_id,$root_path,$file_list) {
|
719 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin:' .var_export($file_list,true));
|
720 |
|
721 |
//check is array list
|
722 |
if (! is_array($file_list)) {
|
723 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Array expected in file list:');
|
724 |
return false;
|
725 |
}
|
726 |
|
735 |
|
736 |
//skip if folder
|
737 |
if ( is_dir( $file_path ) ) {
|
738 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Skip folder:' . $file_path );
|
739 |
continue;
|
740 |
}
|
741 |
|
754 |
//get rid of root path and utf8 encode
|
755 |
$file_path = utf8_encode(str_replace($root_path,'',$file_path));
|
756 |
|
757 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Add File: ' .$batch_counter . ' ' .$file_path);
|
758 |
$sql.= "(".$job_id .", '" .$group_id."', '" .$file_path ."', ".$file_size .",'" . current_time('mysql') . "' ),";
|
759 |
}
|
760 |
|
768 |
|
769 |
if(method_exists($datetime2, 'diff')) {
|
770 |
$interval = $datetime1->diff($datetime2);
|
771 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Count/Time: ' .$total_counter . '-' . $interval->format('%s seconds'));
|
772 |
} else {
|
773 |
$util = new WPBackItUp_Utility($this->log_name);
|
774 |
$interval = $util->date_diff_array($datetime1, $datetime2);
|
775 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Count/Time: ' .$total_counter . '-' . $interval['second'] . ' seconds');
|
776 |
}
|
777 |
|
778 |
return true;
|
779 |
|
780 |
} catch(Exception $e) {
|
781 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .$e);
|
782 |
return false;
|
783 |
}
|
784 |
}
|
796 |
*/
|
797 |
public function backup_files($job_id,$source_root,$content_type){
|
798 |
global $WPBackitup;
|
799 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin ');
|
800 |
|
801 |
//get files to backup
|
802 |
$db = new WPBackItUp_DataAccess();
|
820 |
$batch_size=$WPBackitup->backup_others_batch_size();
|
821 |
break;
|
822 |
default:
|
823 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Content type not recognized:'.$content_type);
|
824 |
return false;
|
825 |
|
826 |
}
|
827 |
|
828 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Batch Size: '. $batch_size);
|
829 |
|
830 |
//get a timestamp for the batch id
|
831 |
$batch_id=current_time( 'timestamp' );
|
834 |
// sometimes file list is an empty, still couldn't figure out why.
|
835 |
if(is_array($file_list)){
|
836 |
if(empty($file_list)){
|
837 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Upload Folder is Empty');
|
838 |
return 0;
|
839 |
}
|
840 |
}
|
843 |
|
844 |
//$zip_file_path = $this->backup_project_path . $this->backup_name .'-'.$content_type .'.zip';
|
845 |
$zip_file_path = sprintf('%s%s-%s-%s.zip',$this->backup_project_path,$this->backup_name,$content_type,$batch_id);
|
846 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Zip file path: '. $zip_file_path);
|
847 |
|
848 |
//IF false error happened
|
849 |
$file_count=$this->backup_files_to_zip($source_root,$target_root,$file_list,$zip_file_path);
|
850 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Files added to zip:'.$file_count);
|
851 |
if (false===$file_count){
|
852 |
return false;
|
853 |
}
|
857 |
|
858 |
//Check to see if the file exists, it is possible that it does not if only empty folders were contained
|
859 |
if(! file_exists($zip_file_path) ) {
|
860 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Zip File NOT found:'.$zip_file_path);
|
861 |
|
862 |
$file_system = new WPBackItUp_FileSystem($this->log_name);
|
863 |
$files_in_temp_directory = $file_system->get_fileonly_list($this->backup_project_path, 'zip');
|
864 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Files In Temp Folder:');
|
865 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,$files_in_temp_directory);
|
866 |
return false;
|
867 |
}
|
868 |
|
869 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Zip file FOUND:'.$zip_file_path);
|
870 |
|
871 |
//update the batch with the number of files in the added count
|
872 |
$db->update_item_batch_complete($job_id,$batch_id,$file_count);
|
879 |
//if any files werent backed up then return false
|
880 |
$error_count = $db->get_error_item_count($job_id,$content_type);
|
881 |
if ($error_count>0){
|
882 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Item Error count:'.$error_count);
|
883 |
return false;
|
884 |
}
|
885 |
}
|
899 |
* @return bool
|
900 |
*/
|
901 |
public function validate_backup_files_by_batch_id($job_id,$content_type,$batch_id){
|
902 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin: '.$content_type . ' Batch ID: ' . $batch_id);
|
903 |
|
904 |
//get files to backup
|
905 |
$db = new WPBackItUp_DataAccess();
|
925 |
|
926 |
//It is possible that there were no files backed up
|
927 |
if( $file_list == false || $file_list==0 ) {
|
928 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__, 'No files found to validate.');
|
929 |
return true;
|
930 |
}
|
931 |
|
935 |
|
936 |
//get zip path
|
937 |
$zip_file_path = sprintf('%s-%s-%s.zip',$this->backup_project_path . $this->backup_name, $content_type,$batch_id);
|
938 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Zip file: '. $zip_file_path);
|
939 |
|
940 |
if ( ! file_exists($zip_file_path) ) {
|
941 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Zip File not found:' . $zip_file_path );
|
942 |
// Scanning Temp Directory.
|
943 |
$files_on_temp_directory = scandir($this->backup_project_path);
|
944 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin::Files on TMP Directory');
|
945 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,$files_on_temp_directory);
|
946 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End::Files on TMP Directory');
|
947 |
return false;
|
948 |
}
|
949 |
|
950 |
$current_zip_file = $zip_file_path;
|
951 |
$zip = new WPBackItUp_Zip($this->log_name,$current_zip_file);
|
952 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Current Zip File:' . $current_zip_file );
|
953 |
|
954 |
foreach($file_list as $file) {
|
955 |
$item = $target_root .'/' .utf8_decode( $file->item );
|
956 |
|
957 |
//validate file exists in zip
|
958 |
if (false===$zip->validate_file($item)) {
|
959 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File NOT found in zip :' . $item );
|
960 |
$zip->close();
|
961 |
return false;
|
962 |
}
|
963 |
$file_counter++;
|
964 |
}
|
965 |
|
966 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Validation Successful:'.$content_type . '-' .$file_counter);
|
967 |
if (null!=$zip) $zip->close();
|
968 |
return true;
|
969 |
}
|
983 |
private function backup_files_to_zip($source_root,$target_root,$file_list, $zip_file_path){
|
984 |
global $WPBackitup;
|
985 |
|
986 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin ');
|
987 |
|
988 |
if (empty($file_list) || !isset($file_list)) {
|
989 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File list is not valid:');
|
990 |
+
WPBackItUp_Logger::log($this->log_name,var_export($file_list,true));
|
991 |
return false;
|
992 |
}
|
993 |
|
994 |
$zip_max_file_size = $WPBackitup->max_zip_size();
|
995 |
|
996 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin - Item Count: '. count($file_list));
|
997 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'ZIP MAX FILE SIZE:' .WPBackItUp_FileSystem::format_file_size($zip_max_file_size));
|
998 |
$zip = new WPBackItUp_Zip($this->log_name,$zip_file_path);
|
999 |
|
1000 |
$file_size_counter = 0;
|
1001 |
foreach($file_list as $file) {
|
1002 |
$item = $source_root. '/' .utf8_decode($file->item);
|
1003 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File:' .$item);
|
1004 |
|
1005 |
clearstatcache();
|
1006 |
$file_size_counter += filesize($item);
|
1007 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Size Counter:' .WPBackItUp_FileSystem::format_file_size($file_size_counter));
|
1008 |
if($file_size_counter >= $zip_max_file_size){
|
1009 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Exceeded Max Zip Size.');
|
1010 |
break;//jump out of the for loop
|
1011 |
}
|
1012 |
|
1015 |
$target_item_path= str_replace('//','/',$target_item_path);
|
1016 |
$target_item_path= str_replace('\\','/',$target_item_path);
|
1017 |
|
1018 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Add File:' .$target_item_path );
|
1019 |
if ( $zip->add_file($item,$target_item_path)) {
|
1020 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,sprintf('(%s)File Added:%s', $zip->get_zip_file_count(),$target_item_path));
|
1021 |
} else {
|
1022 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File NOT added:' . $target_item_path );
|
1023 |
return false;
|
1024 |
}
|
1025 |
}
|
1027 |
$files_count = $zip->get_files_in_zip();
|
1028 |
|
1029 |
//if we get here then close the zip
|
1030 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,sprintf('Zip File Status BEFORE Close:%s', $zip->get_zip_status()));
|
1031 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,sprintf('Number of files in zip:%s',$files_count ));
|
1032 |
$zip_closed = $zip->close();//close the zip - true for success/false error
|
1033 |
|
1034 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
1035 |
|
1036 |
//return filecount on success and false on close error
|
1037 |
return true===$zip_closed? $files_count: false;
|
1042 |
* @param $source_root
|
1043 |
* @param $target_root
|
1044 |
* @param $suffix
|
1045 |
+
* @param $file_list array reference value
|
1046 |
* @param $batch_size
|
1047 |
+
* @param $batch_id
|
1048 |
*
|
1049 |
* @return bool|int false on error OR count
|
1050 |
*/
|
1051 |
+
public function backup_file_list($source_root,$target_root,$suffix,&$file_list,$batch_size, $batch_id){
|
1052 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1053 |
|
1054 |
if (! is_array($file_list)) {
|
1055 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Array expected in file list:');
|
1056 |
+
WPBackItUp_Logger::log($this->log_name,var_export($file_list,true));
|
1057 |
return false;
|
1058 |
}
|
1059 |
|
|
|
|
|
1060 |
//$zip_file_path = $this->backup_project_path . $this->backup_name .'-'.$suffix .'.tmp';
|
1061 |
$zip_file_path = sprintf('%s%s-%s-%s.zip',$this->backup_project_path,$this->backup_name,$suffix,$batch_id);
|
1062 |
$zip = new WPBackItUp_Zip($this->log_name,$zip_file_path);
|
1063 |
foreach($file_list as $item) {
|
1064 |
$item = utf8_decode($item);
|
1065 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File:' . $item );
|
1066 |
|
1067 |
//skip it if folder
|
1068 |
if ( is_dir( $item ) ) {
|
1069 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Skip folder:' . $item );
|
1070 |
array_shift( $file_list ); //remove from list
|
1071 |
continue;
|
1072 |
}
|
1073 |
|
1074 |
//replace the source path with the target
|
1075 |
$target_item_path = str_replace(rtrim($source_root, '/'),rtrim($target_root,'/'),$item);
|
1076 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Add File:' .$target_item_path );
|
1077 |
if ( $zip->add_file($item,$target_item_path)) {
|
1078 |
array_shift($file_list);
|
1079 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Added:' . $target_item_path );
|
1080 |
//If we have added X# of files or hit the size limit then lets close the zip and finish on the next pass
|
1081 |
if( $zip->get_zip_file_count()>=$batch_size){
|
1082 |
$zip->close();//close the zip
|
1083 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End - Item Count:' . count($file_list));
|
1084 |
return count($file_list);
|
1085 |
}
|
1086 |
} else {
|
1087 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File NOT added:' . $target_item_path );
|
1088 |
return false;
|
1089 |
}
|
1090 |
}
|
1093 |
$zip->close();//close the zip
|
1094 |
|
1095 |
if( ! file_exists($zip_file_path) ){
|
1096 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Zip file was not created.');
|
1097 |
return false;
|
1098 |
}
|
1099 |
|
1100 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End - Item Count:' . count($file_list));
|
1101 |
return count($file_list);
|
1102 |
}
|
1103 |
|
1104 |
|
1105 |
|
1106 |
public function backup_file_to_zip($source_root,$target_root,$file_path, $zip_file_path){
|
1107 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1108 |
|
1109 |
if ( empty($file_path)) {
|
1110 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File path expected:');
|
1111 |
+
WPBackItUp_Logger::log($this->log_name,var_export($file_path,true));
|
1112 |
return false;
|
1113 |
}
|
1114 |
|
1115 |
if ( !file_exists($file_path)) {
|
1116 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File not found:');
|
1117 |
+
WPBackItUp_Logger::log($this->log_name,var_export($file_path,true));
|
1118 |
return false;
|
1119 |
}
|
1120 |
|
1122 |
$zip = new WPBackItUp_Zip($this->log_name,$zip_file_path);
|
1123 |
|
1124 |
$file_path = utf8_decode($file_path);
|
1125 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File:' . $file_path );
|
1126 |
|
1127 |
//replace the source path with the target
|
1128 |
$target_item_path = str_replace(rtrim($source_root, '/'),rtrim($target_root,'/'),$file_path);
|
1129 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Add File:' .$target_item_path );
|
1130 |
if ( $zip->add_file($file_path,$target_item_path)) {
|
1131 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Added:' . $target_item_path );
|
1132 |
} else {
|
1133 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File NOT added:' . $target_item_path );
|
1134 |
return false;
|
1135 |
}
|
1136 |
|
1150 |
public function remove_supporting_zips($zip_files){
|
1151 |
|
1152 |
if (!is_array($zip_files) || count($zip_files)<=0) {
|
1153 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Zip file list was not array ' .var_export( $zip_files,true));
|
1154 |
return false;
|
1155 |
}
|
1156 |
|
1181 |
}
|
1182 |
|
1183 |
$cleanup_processor->save()->dispatch();
|
1184 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Cleanup support zips job dispatched.');
|
1185 |
}
|
1186 |
|
1187 |
|
1188 |
return true;
|
1189 |
|
1190 |
} catch(Exception $e) {
|
1191 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Error Occurred: ' .$e);
|
1192 |
return false;
|
1193 |
}
|
1194 |
}
|
1199 |
* @return bool
|
1200 |
*/
|
1201 |
public function create_backup_manifest(){
|
1202 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1203 |
|
1204 |
//get a list of all the zips
|
1205 |
$backup_files_path = array_filter(glob($this->backup_project_path. '*.zip'), 'is_file');
|
1206 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Zip files found:'. var_export($backup_files_path,true));
|
1207 |
if (is_array($backup_files_path) && count($backup_files_path)>0){
|
1208 |
|
1209 |
//build the manifest with file size
|
1221 |
|
1222 |
$bytes = file_put_contents($manifest_file,json_encode($backup_file_list));
|
1223 |
if ( $bytes===false || $bytes<=0){
|
1224 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Manifest file was not created successfully.');
|
1225 |
return false;
|
1226 |
}
|
1227 |
|
1235 |
$target_item_path = str_replace(rtrim($this->backup_project_path, '/'),rtrim('site-data','/'),$manifest_file);
|
1236 |
if ($zip->add_file($manifest_file,$target_item_path)) {
|
1237 |
$zip->close();//close the zip
|
1238 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End - Manifest created.');
|
1239 |
@unlink($manifest_file);
|
1240 |
return true;
|
1241 |
}
|
1242 |
}else{
|
1243 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Main zip not found.');
|
1244 |
}
|
1245 |
}
|
1246 |
|
1247 |
@unlink($manifest_file);
|
1248 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'End - Manifest not created.');
|
1249 |
return false;
|
1250 |
}
|
1251 |
|
1275 |
* @return bool
|
1276 |
*/
|
1277 |
public function rename_backup_folder() {
|
1278 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1279 |
|
1280 |
$backup_project_path = $this->backup_project_path;
|
1281 |
//remove the 4 character prefix
|
1283 |
|
1284 |
$file_system = new WPBackItUp_FileSystem($this->log_name);
|
1285 |
if (! $file_system->rename_file($backup_project_path,$new_backup_path)){
|
1286 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Folder could not be renamed');
|
1287 |
return false;
|
1288 |
}
|
1289 |
|
1290 |
$this->set_final_backup_path();
|
1291 |
|
1292 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
1293 |
return true;
|
1294 |
}
|
1295 |
|
1298 |
*
|
1299 |
*/
|
1300 |
public function set_final_backup_path(){
|
1301 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1302 |
|
1303 |
$backup_project_path = $this->backup_project_path;
|
1304 |
$new_backup_path = str_replace('TMP_','',$backup_project_path);
|
1306 |
//set the path to the new path
|
1307 |
$this->backup_project_path=$new_backup_path;
|
1308 |
|
1309 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
1310 |
}
|
1311 |
|
1312 |
/**
|
lib/includes/class-database.php
CHANGED
@@ -22,7 +22,7 @@ class WPBackItUp_DataAccess {
|
|
22 |
|
23 |
} catch(Exception $e) {
|
24 |
error_log($e);
|
25 |
-
|
26 |
}
|
27 |
}
|
28 |
|
@@ -63,7 +63,7 @@ class WPBackItUp_DataAccess {
|
|
63 |
* @return bool
|
64 |
*/
|
65 |
public function insert_job_items($sql_values) {
|
66 |
-
|
67 |
global $wpdb;
|
68 |
|
69 |
$sql_insert = "INSERT INTO $wpdb->wpbackitup_job_item
|
@@ -86,7 +86,7 @@ class WPBackItUp_DataAccess {
|
|
86 |
* @return bool
|
87 |
*/
|
88 |
public function insert_job_item($job_id, $group_id, $item, $size_kb, $create_date) {
|
89 |
-
|
90 |
global $wpdb;
|
91 |
|
92 |
$sql = $wpdb->prepare(
|
@@ -121,7 +121,7 @@ class WPBackItUp_DataAccess {
|
|
121 |
* @return bool
|
122 |
*/
|
123 |
public function insert_job_items_with_offset($sql_values) {
|
124 |
-
|
125 |
global $wpdb;
|
126 |
|
127 |
$sql_insert = "INSERT INTO $wpdb->wpbackitup_job_item
|
@@ -148,7 +148,7 @@ class WPBackItUp_DataAccess {
|
|
148 |
*/
|
149 |
public function get_queued_active_job_count( $job_types ) {
|
150 |
global $wpdb;
|
151 |
-
|
152 |
|
153 |
$job_types_list = self::get_delimited_list($job_types);
|
154 |
|
@@ -178,7 +178,7 @@ class WPBackItUp_DataAccess {
|
|
178 |
*/
|
179 |
public function get_jobs_by_status( $job_type,$job_status_array, $limit=100 ) {
|
180 |
global $wpdb;
|
181 |
-
|
182 |
|
183 |
$job_status_list = self::get_delimited_list($job_status_array);
|
184 |
|
@@ -193,7 +193,7 @@ class WPBackItUp_DataAccess {
|
|
193 |
",$job_type, $limit);
|
194 |
|
195 |
$query_result=$this->get_rows($sql);
|
196 |
-
|
197 |
|
198 |
return $query_result;
|
199 |
}
|
@@ -209,7 +209,7 @@ class WPBackItUp_DataAccess {
|
|
209 |
*/
|
210 |
public function get_jobs_by_name( $job_type, $job_name,$job_status_array=null ) {
|
211 |
global $wpdb;
|
212 |
-
|
213 |
|
214 |
if ( ! empty( $job_status_array ) ) {
|
215 |
|
@@ -238,7 +238,7 @@ class WPBackItUp_DataAccess {
|
|
238 |
}
|
239 |
|
240 |
$query_result=$this->get_rows($sql);
|
241 |
-
|
242 |
|
243 |
return $query_result;
|
244 |
}
|
@@ -255,7 +255,7 @@ class WPBackItUp_DataAccess {
|
|
255 |
* @return bool true on success/ false on error
|
256 |
*/
|
257 |
public function create_job($job_id,$job_type,$job_run_type,$job_name,$job_status) {
|
258 |
-
|
259 |
global $wpdb;
|
260 |
|
261 |
$sql = $wpdb->prepare(
|
@@ -279,7 +279,7 @@ class WPBackItUp_DataAccess {
|
|
279 |
*/
|
280 |
public function get_job_by_id( $job_id ) {
|
281 |
global $wpdb;
|
282 |
-
|
283 |
|
284 |
$sql = $wpdb->prepare(
|
285 |
"SELECT *
|
@@ -289,7 +289,7 @@ class WPBackItUp_DataAccess {
|
|
289 |
",$job_id);
|
290 |
|
291 |
$query_result=$this->get_row($sql);
|
292 |
-
|
293 |
|
294 |
return $query_result;
|
295 |
}
|
@@ -304,7 +304,7 @@ class WPBackItUp_DataAccess {
|
|
304 |
* @return bool
|
305 |
*/
|
306 |
public function update_job_status( $job_id, $job_status ) {
|
307 |
-
|
308 |
global $wpdb;
|
309 |
|
310 |
$sql = $wpdb->prepare(
|
@@ -330,7 +330,7 @@ class WPBackItUp_DataAccess {
|
|
330 |
* @return bool
|
331 |
*/
|
332 |
public function update_job_run_type( $job_id, $job_run_type ) {
|
333 |
-
|
334 |
global $wpdb;
|
335 |
|
336 |
$sql = $wpdb->prepare(
|
@@ -355,7 +355,7 @@ class WPBackItUp_DataAccess {
|
|
355 |
* @return bool
|
356 |
*/
|
357 |
public function update_job_meta( $job_id, $job_meta ) {
|
358 |
-
|
359 |
global $wpdb;
|
360 |
|
361 |
$sql = $wpdb->prepare(
|
@@ -383,7 +383,7 @@ class WPBackItUp_DataAccess {
|
|
383 |
* @return bool|int ID on success/ false on error
|
384 |
*/
|
385 |
public function create_task( $job_id, $task_name) {
|
386 |
-
|
387 |
global $wpdb;
|
388 |
|
389 |
$sql = $wpdb->prepare(
|
@@ -408,7 +408,7 @@ class WPBackItUp_DataAccess {
|
|
408 |
*/
|
409 |
public function get_job_tasks( $job_id, $status_array ) {
|
410 |
global $wpdb;
|
411 |
-
|
412 |
|
413 |
$status_list = self::get_delimited_list($status_array);
|
414 |
|
@@ -422,7 +422,7 @@ class WPBackItUp_DataAccess {
|
|
422 |
",$job_id);
|
423 |
|
424 |
$query_result=$this->get_rows($sql);
|
425 |
-
|
426 |
|
427 |
return $query_result;
|
428 |
|
@@ -438,7 +438,7 @@ class WPBackItUp_DataAccess {
|
|
438 |
* @return bool true on allocated, false on not allocated,
|
439 |
*/
|
440 |
public function allocate_task( $task_id ) {
|
441 |
-
|
442 |
global $wpdb;
|
443 |
|
444 |
$allocation_id = current_time('timestamp');
|
@@ -476,7 +476,7 @@ class WPBackItUp_DataAccess {
|
|
476 |
*/
|
477 |
public function get_task_by_id( $task_id ) {
|
478 |
global $wpdb;
|
479 |
-
|
480 |
|
481 |
$sql = $wpdb->prepare(
|
482 |
"SELECT *
|
@@ -486,7 +486,7 @@ class WPBackItUp_DataAccess {
|
|
486 |
",$task_id);
|
487 |
|
488 |
$query_result=$this->get_row($sql);
|
489 |
-
|
490 |
|
491 |
return $query_result;
|
492 |
}
|
@@ -500,7 +500,7 @@ class WPBackItUp_DataAccess {
|
|
500 |
* @return bool true on success, false on failure
|
501 |
*/
|
502 |
public function update_task( $task ) {
|
503 |
-
|
504 |
global $wpdb;
|
505 |
|
506 |
$sql = $wpdb->prepare(
|
@@ -538,7 +538,7 @@ class WPBackItUp_DataAccess {
|
|
538 |
*/
|
539 |
public function get_job_item_job_list(){
|
540 |
global $wpdb;
|
541 |
-
|
542 |
$sql_select = "SELECT DISTINCT job_id FROM $wpdb->wpbackitup_job_item";
|
543 |
return $this->get_rows($sql_select);
|
544 |
}
|
@@ -557,7 +557,7 @@ class WPBackItUp_DataAccess {
|
|
557 |
*/
|
558 |
function get_batch_open_items($batch_id,$batch_size,$job_id,$group_id){
|
559 |
global $wpdb;
|
560 |
-
|
561 |
|
562 |
$item_status_list = self::get_delimited_list(array(WPBackItUp_Job_Item::OPEN,WPBackItUp_Job_Item::QUEUED,WPBackItUp_Job_Item::ERROR));
|
563 |
|
@@ -606,7 +606,7 @@ class WPBackItUp_DataAccess {
|
|
606 |
*/
|
607 |
function get_completed_items_by_batch_id($job_id,$group_id,$batch_id){
|
608 |
global $wpdb;
|
609 |
-
|
610 |
|
611 |
$sql_select = $wpdb->prepare(
|
612 |
"SELECT * FROM $wpdb->wpbackitup_job_item
|
@@ -633,7 +633,7 @@ class WPBackItUp_DataAccess {
|
|
633 |
*/
|
634 |
function get_item_batch_ids($job_id,$group_id) {
|
635 |
global $wpdb;
|
636 |
-
|
637 |
|
638 |
$sql_select = $wpdb->prepare(
|
639 |
"SELECT DISTINCT batch_id FROM $wpdb->wpbackitup_job_item
|
@@ -660,7 +660,7 @@ class WPBackItUp_DataAccess {
|
|
660 |
*/
|
661 |
public function get_item_by_id( $item_id ) {
|
662 |
global $wpdb;
|
663 |
-
|
664 |
|
665 |
$sql = $wpdb->prepare(
|
666 |
"SELECT *
|
@@ -670,7 +670,7 @@ class WPBackItUp_DataAccess {
|
|
670 |
",$item_id);
|
671 |
|
672 |
$query_result=$this->get_row($sql);
|
673 |
-
|
674 |
|
675 |
return $query_result;
|
676 |
}
|
@@ -685,7 +685,7 @@ class WPBackItUp_DataAccess {
|
|
685 |
*/
|
686 |
public function delete_job_by_id( $job_id ) {
|
687 |
global $wpdb;
|
688 |
-
|
689 |
|
690 |
$sql_update = $wpdb->prepare(
|
691 |
"DELETE FROM $wpdb->wpbackitup_job_control
|
@@ -713,7 +713,7 @@ class WPBackItUp_DataAccess {
|
|
713 |
*/
|
714 |
public function delete_job_tasks( $job_id,$limit=9999999 ) {
|
715 |
global $wpdb;
|
716 |
-
|
717 |
|
718 |
$sql = $wpdb->prepare(
|
719 |
"DELETE FROM $wpdb->wpbackitup_job_task
|
@@ -741,7 +741,7 @@ class WPBackItUp_DataAccess {
|
|
741 |
*/
|
742 |
function delete_job_items($job_id, $limit=9999999){
|
743 |
global $wpdb;
|
744 |
-
|
745 |
|
746 |
$sql = $wpdb->prepare(
|
747 |
"DELETE FROM $wpdb->wpbackitup_job_item
|
@@ -767,7 +767,7 @@ class WPBackItUp_DataAccess {
|
|
767 |
*/
|
768 |
function get_open_item_count($job_id,$group_id){
|
769 |
global $wpdb;
|
770 |
-
|
771 |
|
772 |
$item_status_list = self::get_delimited_list(array(WPBackItUp_Job_Item::OPEN,WPBackItUp_Job_Item::QUEUED,WPBackItUp_Job_Item::ERROR));
|
773 |
|
@@ -782,7 +782,7 @@ class WPBackItUp_DataAccess {
|
|
782 |
",WPBackItUp_Job_Item::JOB_ITEM_RECORD,$job_id,$group_id);
|
783 |
|
784 |
$row=$this->get_row($sql);
|
785 |
-
|
786 |
|
787 |
return $row->item_count;
|
788 |
}
|
@@ -798,7 +798,7 @@ class WPBackItUp_DataAccess {
|
|
798 |
*/
|
799 |
function get_error_item_count($job_id,$group_id){
|
800 |
global $wpdb;
|
801 |
-
|
802 |
|
803 |
$sql = $wpdb->prepare(
|
804 |
"SELECT count(*) as item_count FROM $wpdb->wpbackitup_job_item
|
@@ -810,7 +810,7 @@ class WPBackItUp_DataAccess {
|
|
810 |
",WPBackItUp_Job_Item::JOB_ITEM_RECORD,$job_id,$group_id,WPBackItUp_Job_Item::COMPLETE);
|
811 |
|
812 |
$row=$this->get_row($sql);
|
813 |
-
|
814 |
|
815 |
return $row->item_count;
|
816 |
}
|
@@ -826,7 +826,7 @@ class WPBackItUp_DataAccess {
|
|
826 |
*/
|
827 |
function update_item_batch_complete($job_id,$batch_id,$file_count){
|
828 |
global $wpdb;
|
829 |
-
|
830 |
|
831 |
$sql = $wpdb->prepare(
|
832 |
"UPDATE $wpdb->wpbackitup_job_item
|
@@ -853,7 +853,7 @@ class WPBackItUp_DataAccess {
|
|
853 |
* @return bool
|
854 |
*/
|
855 |
public function update_item_status( $item_id, $item_status ) {
|
856 |
-
|
857 |
global $wpdb;
|
858 |
|
859 |
$sql = $wpdb->prepare(
|
@@ -880,7 +880,7 @@ class WPBackItUp_DataAccess {
|
|
880 |
*/
|
881 |
public function update_job_start_time( $job_id, $job_start_time ) {
|
882 |
global $wpdb;
|
883 |
-
|
884 |
|
885 |
$sql = $wpdb->prepare(
|
886 |
"UPDATE $wpdb->wpbackitup_job_control
|
@@ -904,7 +904,7 @@ class WPBackItUp_DataAccess {
|
|
904 |
* @return bool
|
905 |
*/
|
906 |
public function update_job_end_time( $job_id, $job_end_time ) {
|
907 |
-
|
908 |
global $wpdb;
|
909 |
|
910 |
$sql = $wpdb->prepare(
|
@@ -930,7 +930,7 @@ class WPBackItUp_DataAccess {
|
|
930 |
*/
|
931 |
public function get_user_by_login( $user_login,$table_prefix=null ) {
|
932 |
global $wpdb;
|
933 |
-
|
934 |
|
935 |
$users_table = $wpdb->users;
|
936 |
if (!is_null( $table_prefix )){
|
@@ -945,7 +945,7 @@ class WPBackItUp_DataAccess {
|
|
945 |
",$user_login);
|
946 |
|
947 |
$query_result=$this->get_row($sql);
|
948 |
-
|
949 |
|
950 |
return $query_result;
|
951 |
}
|
@@ -957,7 +957,7 @@ class WPBackItUp_DataAccess {
|
|
957 |
*/
|
958 |
public function get_user_by_id( $user_id ) {
|
959 |
global $wpdb;
|
960 |
-
|
961 |
|
962 |
$sql = $wpdb->prepare(
|
963 |
"SELECT *
|
@@ -967,7 +967,7 @@ class WPBackItUp_DataAccess {
|
|
967 |
",$user_id);
|
968 |
|
969 |
$query_result=$this->get_row($sql);
|
970 |
-
|
971 |
|
972 |
return $query_result;
|
973 |
}
|
@@ -983,7 +983,7 @@ class WPBackItUp_DataAccess {
|
|
983 |
*/
|
984 |
public function get_duplicate_users( $user_id, $user_login ) {
|
985 |
global $wpdb;
|
986 |
-
|
987 |
|
988 |
$sql = $wpdb->prepare(
|
989 |
"SELECT *
|
@@ -994,7 +994,7 @@ class WPBackItUp_DataAccess {
|
|
994 |
",$user_id,$user_login);
|
995 |
|
996 |
$query_result=$this->get_rows($sql);
|
997 |
-
|
998 |
|
999 |
return $query_result;
|
1000 |
}
|
@@ -1010,10 +1010,10 @@ class WPBackItUp_DataAccess {
|
|
1010 |
*/
|
1011 |
public function update_snapshot_currentuser( $current_user, $table_prefix) {
|
1012 |
global $wpdb;
|
1013 |
-
|
1014 |
|
1015 |
if ( empty( $current_user )) {
|
1016 |
-
|
1017 |
return false;
|
1018 |
}
|
1019 |
|
@@ -1031,7 +1031,7 @@ class WPBackItUp_DataAccess {
|
|
1031 |
);
|
1032 |
|
1033 |
$snapshot_user_id = $this->get_scalar($sql);
|
1034 |
-
|
1035 |
|
1036 |
//Delete user and user meta if exists in snapshot DB
|
1037 |
if (! empty($snapshot_user_id)) {
|
@@ -1046,7 +1046,7 @@ class WPBackItUp_DataAccess {
|
|
1046 |
|
1047 |
$sql_rtn = $this->query($sql);
|
1048 |
if (false=== $sql_rtn ) {
|
1049 |
-
|
1050 |
return false;
|
1051 |
}
|
1052 |
|
@@ -1060,7 +1060,7 @@ class WPBackItUp_DataAccess {
|
|
1060 |
|
1061 |
$sql_rtn = $this->query($sql);
|
1062 |
if (false=== $sql_rtn ) {
|
1063 |
-
|
1064 |
return false;
|
1065 |
}
|
1066 |
|
@@ -1097,7 +1097,7 @@ class WPBackItUp_DataAccess {
|
|
1097 |
|
1098 |
$sql_rtn = $this->query($sql);
|
1099 |
if (false=== $sql_rtn ) {
|
1100 |
-
|
1101 |
return false;
|
1102 |
}
|
1103 |
|
@@ -1109,11 +1109,11 @@ class WPBackItUp_DataAccess {
|
|
1109 |
);
|
1110 |
|
1111 |
$snapshot_user_id = $this->get_scalar($sql);
|
1112 |
-
|
1113 |
|
1114 |
//Delete user and user meta if exists in snapshot DB
|
1115 |
if ( empty($snapshot_user_id)) {
|
1116 |
-
|
1117 |
return false;
|
1118 |
}
|
1119 |
|
@@ -1137,12 +1137,12 @@ class WPBackItUp_DataAccess {
|
|
1137 |
|
1138 |
$sql_rtn = $this->query($sql);
|
1139 |
if (false=== $sql_rtn ) {
|
1140 |
-
|
1141 |
return false;
|
1142 |
}
|
1143 |
|
1144 |
|
1145 |
-
|
1146 |
return true;
|
1147 |
|
1148 |
}
|
@@ -1158,15 +1158,15 @@ class WPBackItUp_DataAccess {
|
|
1158 |
*/
|
1159 |
public function update_snapshot_table_prefix( $snapshot_prefix, $backup_table_prefix) {
|
1160 |
global $wpdb;
|
1161 |
-
|
1162 |
|
1163 |
if ( empty( $snapshot_prefix )) {
|
1164 |
-
|
1165 |
return false;
|
1166 |
}
|
1167 |
|
1168 |
if ( empty( $backup_table_prefix )) {
|
1169 |
-
|
1170 |
return false;
|
1171 |
}
|
1172 |
|
@@ -1184,7 +1184,7 @@ class WPBackItUp_DataAccess {
|
|
1184 |
|
1185 |
$sql_rtn = $this->query($sql);
|
1186 |
if (false=== $sql_rtn ) {
|
1187 |
-
|
1188 |
return false;
|
1189 |
}
|
1190 |
|
@@ -1203,12 +1203,12 @@ class WPBackItUp_DataAccess {
|
|
1203 |
|
1204 |
$sql_rtn = $this->query($sql);
|
1205 |
if (false=== $sql_rtn ) {
|
1206 |
-
|
1207 |
return false;
|
1208 |
}
|
1209 |
|
1210 |
|
1211 |
-
|
1212 |
return true;
|
1213 |
|
1214 |
}
|
@@ -1224,7 +1224,7 @@ class WPBackItUp_DataAccess {
|
|
1224 |
*/
|
1225 |
public function update_create_user_by_login( $db_user, $table_prefix=null) {
|
1226 |
global $wpdb;
|
1227 |
-
|
1228 |
|
1229 |
$users_table = $wpdb->users;
|
1230 |
if (!is_null( $table_prefix )){
|
@@ -1307,7 +1307,7 @@ class WPBackItUp_DataAccess {
|
|
1307 |
*/
|
1308 |
public function create_user( $db_user ) {
|
1309 |
global $wpdb;
|
1310 |
-
|
1311 |
|
1312 |
$sql = $wpdb->prepare(
|
1313 |
"INSERT INTO $wpdb->users
|
@@ -1352,7 +1352,7 @@ class WPBackItUp_DataAccess {
|
|
1352 |
*/
|
1353 |
public function delete_users_except( $id, $limit=5000 ) {
|
1354 |
global $wpdb;
|
1355 |
-
|
1356 |
|
1357 |
$sql = $wpdb->prepare(
|
1358 |
"DELETE FROM $wpdb->users
|
@@ -1375,7 +1375,7 @@ class WPBackItUp_DataAccess {
|
|
1375 |
*/
|
1376 |
public function get_user_count() {
|
1377 |
global $wpdb;
|
1378 |
-
|
1379 |
|
1380 |
$sql = "SELECT count(*) as user_count FROM $wpdb->users";
|
1381 |
$result = $this->get_row($sql);
|
@@ -1390,7 +1390,7 @@ class WPBackItUp_DataAccess {
|
|
1390 |
*/
|
1391 |
public function get_usermeta_count() {
|
1392 |
global $wpdb;
|
1393 |
-
|
1394 |
|
1395 |
$sql = "SELECT count(distinct user_id) as user_count FROM $wpdb->usermeta";
|
1396 |
$result = $this->get_row($sql);
|
@@ -1408,7 +1408,7 @@ class WPBackItUp_DataAccess {
|
|
1408 |
*/
|
1409 |
public function delete_usermeta_except( $id, $limit=5000 ) {
|
1410 |
global $wpdb;
|
1411 |
-
|
1412 |
|
1413 |
$sql = $wpdb->prepare(
|
1414 |
"DELETE FROM $wpdb->usermeta
|
@@ -1425,12 +1425,12 @@ class WPBackItUp_DataAccess {
|
|
1425 |
|
1426 |
public function get_options_wpbackitup() {
|
1427 |
global $wpdb;
|
1428 |
-
|
1429 |
|
1430 |
$sql ="SELECT * FROM $wpdb->options WHERE option_name LIKE 'wp-backitup%' ";
|
1431 |
|
1432 |
$query_result=$this->get_rows($sql);
|
1433 |
-
|
1434 |
|
1435 |
return $query_result;
|
1436 |
|
@@ -1439,7 +1439,7 @@ class WPBackItUp_DataAccess {
|
|
1439 |
|
1440 |
public function update_create_option($option_name,$option_value,$autoload,$table_prefix=null) {
|
1441 |
global $wpdb;
|
1442 |
-
|
1443 |
|
1444 |
//does option already exist
|
1445 |
$option = $this->get_option_by_name($option_name,$table_prefix);
|
@@ -1503,7 +1503,7 @@ class WPBackItUp_DataAccess {
|
|
1503 |
*/
|
1504 |
public function update_option($option_name,$option_value,$table_prefix=null) {
|
1505 |
global $wpdb;
|
1506 |
-
|
1507 |
|
1508 |
//does option already exist
|
1509 |
$option = $this->get_option_by_name($option_name,$table_prefix);
|
@@ -1538,7 +1538,7 @@ class WPBackItUp_DataAccess {
|
|
1538 |
|
1539 |
public function get_option_by_name( $option_name,$table_prefix=null ) {
|
1540 |
global $wpdb;
|
1541 |
-
|
1542 |
|
1543 |
//replace the table prefix with the job_id
|
1544 |
$options_table = $wpdb->options;
|
@@ -1555,7 +1555,7 @@ class WPBackItUp_DataAccess {
|
|
1555 |
",$option_name);
|
1556 |
|
1557 |
$query_result=$this->get_rows($sql);
|
1558 |
-
|
1559 |
|
1560 |
return $query_result;
|
1561 |
}
|
@@ -1583,7 +1583,7 @@ class WPBackItUp_DataAccess {
|
|
1583 |
|
1584 |
$value = $this->get_scalar($sql);
|
1585 |
if (empty($value)) {
|
1586 |
-
|
1587 |
}
|
1588 |
|
1589 |
return $value;
|
@@ -1598,7 +1598,7 @@ class WPBackItUp_DataAccess {
|
|
1598 |
*/
|
1599 |
public function get_usermeta_by_id( $user_id ) {
|
1600 |
global $wpdb;
|
1601 |
-
|
1602 |
|
1603 |
$sql = $wpdb->prepare(
|
1604 |
"SELECT *
|
@@ -1608,14 +1608,14 @@ class WPBackItUp_DataAccess {
|
|
1608 |
",$user_id);
|
1609 |
|
1610 |
$query_result=$this->get_rows($sql);
|
1611 |
-
|
1612 |
|
1613 |
return $query_result;
|
1614 |
}
|
1615 |
|
1616 |
public function get_usermeta_by_id_metakey( $user_id,$meta_key ) {
|
1617 |
global $wpdb;
|
1618 |
-
|
1619 |
|
1620 |
$sql = $wpdb->prepare(
|
1621 |
"SELECT *
|
@@ -1626,7 +1626,7 @@ class WPBackItUp_DataAccess {
|
|
1626 |
",$user_id,$meta_key);
|
1627 |
|
1628 |
$query_result=$this->get_row($sql);
|
1629 |
-
|
1630 |
|
1631 |
return $query_result;
|
1632 |
}
|
@@ -1642,7 +1642,7 @@ class WPBackItUp_DataAccess {
|
|
1642 |
*/
|
1643 |
public function update_create_usermeta($user_id,$meta_key,$meta_value) {
|
1644 |
global $wpdb;
|
1645 |
-
|
1646 |
|
1647 |
//does usermeta already exist
|
1648 |
$user_meta = $this->get_usermeta_by_id_metakey($user_id,$meta_key);
|
@@ -1694,7 +1694,7 @@ class WPBackItUp_DataAccess {
|
|
1694 |
*/
|
1695 |
function get_tables($table_prefix=null){
|
1696 |
global $wpdb;
|
1697 |
-
|
1698 |
|
1699 |
$sql = "SHOW TABLES";
|
1700 |
if (! is_null($table_prefix)){
|
@@ -1727,7 +1727,7 @@ class WPBackItUp_DataAccess {
|
|
1727 |
|
1728 |
public function get_table_rows() {
|
1729 |
global $wpdb;
|
1730 |
-
|
1731 |
|
1732 |
$sql = $wpdb->prepare(
|
1733 |
"SELECT
|
@@ -1751,7 +1751,7 @@ class WPBackItUp_DataAccess {
|
|
1751 |
}
|
1752 |
|
1753 |
|
1754 |
-
|
1755 |
return $tables;
|
1756 |
|
1757 |
}
|
@@ -1766,10 +1766,10 @@ class WPBackItUp_DataAccess {
|
|
1766 |
|
1767 |
if (!empty($base_directory)){
|
1768 |
$base_directory.='/bin/';
|
1769 |
-
|
1770 |
return $base_directory;
|
1771 |
}
|
1772 |
-
|
1773 |
return false;
|
1774 |
}
|
1775 |
|
@@ -1790,18 +1790,18 @@ class WPBackItUp_DataAccess {
|
|
1790 |
*/
|
1791 |
public function query($sql){
|
1792 |
global $wpdb;
|
1793 |
-
|
1794 |
|
1795 |
-
|
1796 |
$wpdb_result = $wpdb->query($sql);
|
1797 |
//$last_query = $wpdb->last_query;
|
1798 |
$last_error = $wpdb->last_error;
|
1799 |
|
1800 |
-
//
|
1801 |
-
|
1802 |
|
1803 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
1804 |
-
|
1805 |
}
|
1806 |
|
1807 |
return $wpdb_result;
|
@@ -1815,18 +1815,18 @@ class WPBackItUp_DataAccess {
|
|
1815 |
*/
|
1816 |
public function get_row($sql){
|
1817 |
global $wpdb;
|
1818 |
-
|
1819 |
|
1820 |
-
|
1821 |
$wpdb_result = $wpdb->get_row($sql);
|
1822 |
$last_query = $wpdb->last_query;
|
1823 |
$last_error = $wpdb->last_error;
|
1824 |
|
1825 |
-
//
|
1826 |
-
|
1827 |
|
1828 |
if (null == $wpdb_result && !empty($last_error)) {
|
1829 |
-
|
1830 |
}
|
1831 |
|
1832 |
return $wpdb_result;
|
@@ -1841,18 +1841,18 @@ class WPBackItUp_DataAccess {
|
|
1841 |
*/
|
1842 |
public function get_rows($sql,$output=OBJECT){
|
1843 |
global $wpdb;
|
1844 |
-
|
1845 |
|
1846 |
-
|
1847 |
$wpdb_result = $wpdb->get_results($sql,$output);
|
1848 |
//$last_query = $wpdb->last_query;
|
1849 |
$last_error = $wpdb->last_error;
|
1850 |
|
1851 |
-
//
|
1852 |
-
|
1853 |
|
1854 |
if (null == $wpdb_result && ! empty($last_error)) {
|
1855 |
-
|
1856 |
}
|
1857 |
|
1858 |
return $wpdb_result;
|
@@ -1867,16 +1867,16 @@ class WPBackItUp_DataAccess {
|
|
1867 |
*/
|
1868 |
private function get_col($sql,$column_index=0){
|
1869 |
global $wpdb;
|
1870 |
-
|
1871 |
|
1872 |
-
|
1873 |
$wpdb_result = $wpdb->get_col($sql,$column_index);
|
1874 |
$last_error = $wpdb->last_error;
|
1875 |
|
1876 |
-
|
1877 |
|
1878 |
if (null == $wpdb_result && ! empty($last_error)) {
|
1879 |
-
|
1880 |
}
|
1881 |
|
1882 |
return $wpdb_result;
|
22 |
|
23 |
} catch(Exception $e) {
|
24 |
error_log($e);
|
25 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .$e);
|
26 |
}
|
27 |
}
|
28 |
|
63 |
* @return bool
|
64 |
*/
|
65 |
public function insert_job_items($sql_values) {
|
66 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
67 |
global $wpdb;
|
68 |
|
69 |
$sql_insert = "INSERT INTO $wpdb->wpbackitup_job_item
|
86 |
* @return bool
|
87 |
*/
|
88 |
public function insert_job_item($job_id, $group_id, $item, $size_kb, $create_date) {
|
89 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
90 |
global $wpdb;
|
91 |
|
92 |
$sql = $wpdb->prepare(
|
121 |
* @return bool
|
122 |
*/
|
123 |
public function insert_job_items_with_offset($sql_values) {
|
124 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
125 |
global $wpdb;
|
126 |
|
127 |
$sql_insert = "INSERT INTO $wpdb->wpbackitup_job_item
|
148 |
*/
|
149 |
public function get_queued_active_job_count( $job_types ) {
|
150 |
global $wpdb;
|
151 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
152 |
|
153 |
$job_types_list = self::get_delimited_list($job_types);
|
154 |
|
178 |
*/
|
179 |
public function get_jobs_by_status( $job_type,$job_status_array, $limit=100 ) {
|
180 |
global $wpdb;
|
181 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
182 |
|
183 |
$job_status_list = self::get_delimited_list($job_status_array);
|
184 |
|
193 |
",$job_type, $limit);
|
194 |
|
195 |
$query_result=$this->get_rows($sql);
|
196 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
197 |
|
198 |
return $query_result;
|
199 |
}
|
209 |
*/
|
210 |
public function get_jobs_by_name( $job_type, $job_name,$job_status_array=null ) {
|
211 |
global $wpdb;
|
212 |
+
WPBackItUp_Logger::log_info( $this->log_name, __METHOD__, 'Begin' );
|
213 |
|
214 |
if ( ! empty( $job_status_array ) ) {
|
215 |
|
238 |
}
|
239 |
|
240 |
$query_result=$this->get_rows($sql);
|
241 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
242 |
|
243 |
return $query_result;
|
244 |
}
|
255 |
* @return bool true on success/ false on error
|
256 |
*/
|
257 |
public function create_job($job_id,$job_type,$job_run_type,$job_name,$job_status) {
|
258 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
259 |
global $wpdb;
|
260 |
|
261 |
$sql = $wpdb->prepare(
|
279 |
*/
|
280 |
public function get_job_by_id( $job_id ) {
|
281 |
global $wpdb;
|
282 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
283 |
|
284 |
$sql = $wpdb->prepare(
|
285 |
"SELECT *
|
289 |
",$job_id);
|
290 |
|
291 |
$query_result=$this->get_row($sql);
|
292 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
293 |
|
294 |
return $query_result;
|
295 |
}
|
304 |
* @return bool
|
305 |
*/
|
306 |
public function update_job_status( $job_id, $job_status ) {
|
307 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
308 |
global $wpdb;
|
309 |
|
310 |
$sql = $wpdb->prepare(
|
330 |
* @return bool
|
331 |
*/
|
332 |
public function update_job_run_type( $job_id, $job_run_type ) {
|
333 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
334 |
global $wpdb;
|
335 |
|
336 |
$sql = $wpdb->prepare(
|
355 |
* @return bool
|
356 |
*/
|
357 |
public function update_job_meta( $job_id, $job_meta ) {
|
358 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
359 |
global $wpdb;
|
360 |
|
361 |
$sql = $wpdb->prepare(
|
383 |
* @return bool|int ID on success/ false on error
|
384 |
*/
|
385 |
public function create_task( $job_id, $task_name) {
|
386 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
387 |
global $wpdb;
|
388 |
|
389 |
$sql = $wpdb->prepare(
|
408 |
*/
|
409 |
public function get_job_tasks( $job_id, $status_array ) {
|
410 |
global $wpdb;
|
411 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
412 |
|
413 |
$status_list = self::get_delimited_list($status_array);
|
414 |
|
422 |
",$job_id);
|
423 |
|
424 |
$query_result=$this->get_rows($sql);
|
425 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
426 |
|
427 |
return $query_result;
|
428 |
|
438 |
* @return bool true on allocated, false on not allocated,
|
439 |
*/
|
440 |
public function allocate_task( $task_id ) {
|
441 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
442 |
global $wpdb;
|
443 |
|
444 |
$allocation_id = current_time('timestamp');
|
476 |
*/
|
477 |
public function get_task_by_id( $task_id ) {
|
478 |
global $wpdb;
|
479 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
480 |
|
481 |
$sql = $wpdb->prepare(
|
482 |
"SELECT *
|
486 |
",$task_id);
|
487 |
|
488 |
$query_result=$this->get_row($sql);
|
489 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
490 |
|
491 |
return $query_result;
|
492 |
}
|
500 |
* @return bool true on success, false on failure
|
501 |
*/
|
502 |
public function update_task( $task ) {
|
503 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
504 |
global $wpdb;
|
505 |
|
506 |
$sql = $wpdb->prepare(
|
538 |
*/
|
539 |
public function get_job_item_job_list(){
|
540 |
global $wpdb;
|
541 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
542 |
$sql_select = "SELECT DISTINCT job_id FROM $wpdb->wpbackitup_job_item";
|
543 |
return $this->get_rows($sql_select);
|
544 |
}
|
557 |
*/
|
558 |
function get_batch_open_items($batch_id,$batch_size,$job_id,$group_id){
|
559 |
global $wpdb;
|
560 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
561 |
|
562 |
$item_status_list = self::get_delimited_list(array(WPBackItUp_Job_Item::OPEN,WPBackItUp_Job_Item::QUEUED,WPBackItUp_Job_Item::ERROR));
|
563 |
|
606 |
*/
|
607 |
function get_completed_items_by_batch_id($job_id,$group_id,$batch_id){
|
608 |
global $wpdb;
|
609 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
610 |
|
611 |
$sql_select = $wpdb->prepare(
|
612 |
"SELECT * FROM $wpdb->wpbackitup_job_item
|
633 |
*/
|
634 |
function get_item_batch_ids($job_id,$group_id) {
|
635 |
global $wpdb;
|
636 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
637 |
|
638 |
$sql_select = $wpdb->prepare(
|
639 |
"SELECT DISTINCT batch_id FROM $wpdb->wpbackitup_job_item
|
660 |
*/
|
661 |
public function get_item_by_id( $item_id ) {
|
662 |
global $wpdb;
|
663 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
664 |
|
665 |
$sql = $wpdb->prepare(
|
666 |
"SELECT *
|
670 |
",$item_id);
|
671 |
|
672 |
$query_result=$this->get_row($sql);
|
673 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
674 |
|
675 |
return $query_result;
|
676 |
}
|
685 |
*/
|
686 |
public function delete_job_by_id( $job_id ) {
|
687 |
global $wpdb;
|
688 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
689 |
|
690 |
$sql_update = $wpdb->prepare(
|
691 |
"DELETE FROM $wpdb->wpbackitup_job_control
|
713 |
*/
|
714 |
public function delete_job_tasks( $job_id,$limit=9999999 ) {
|
715 |
global $wpdb;
|
716 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
717 |
|
718 |
$sql = $wpdb->prepare(
|
719 |
"DELETE FROM $wpdb->wpbackitup_job_task
|
741 |
*/
|
742 |
function delete_job_items($job_id, $limit=9999999){
|
743 |
global $wpdb;
|
744 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
745 |
|
746 |
$sql = $wpdb->prepare(
|
747 |
"DELETE FROM $wpdb->wpbackitup_job_item
|
767 |
*/
|
768 |
function get_open_item_count($job_id,$group_id){
|
769 |
global $wpdb;
|
770 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
771 |
|
772 |
$item_status_list = self::get_delimited_list(array(WPBackItUp_Job_Item::OPEN,WPBackItUp_Job_Item::QUEUED,WPBackItUp_Job_Item::ERROR));
|
773 |
|
782 |
",WPBackItUp_Job_Item::JOB_ITEM_RECORD,$job_id,$group_id);
|
783 |
|
784 |
$row=$this->get_row($sql);
|
785 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($row,true));
|
786 |
|
787 |
return $row->item_count;
|
788 |
}
|
798 |
*/
|
799 |
function get_error_item_count($job_id,$group_id){
|
800 |
global $wpdb;
|
801 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
802 |
|
803 |
$sql = $wpdb->prepare(
|
804 |
"SELECT count(*) as item_count FROM $wpdb->wpbackitup_job_item
|
810 |
",WPBackItUp_Job_Item::JOB_ITEM_RECORD,$job_id,$group_id,WPBackItUp_Job_Item::COMPLETE);
|
811 |
|
812 |
$row=$this->get_row($sql);
|
813 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($row,true));
|
814 |
|
815 |
return $row->item_count;
|
816 |
}
|
826 |
*/
|
827 |
function update_item_batch_complete($job_id,$batch_id,$file_count){
|
828 |
global $wpdb;
|
829 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
830 |
|
831 |
$sql = $wpdb->prepare(
|
832 |
"UPDATE $wpdb->wpbackitup_job_item
|
853 |
* @return bool
|
854 |
*/
|
855 |
public function update_item_status( $item_id, $item_status ) {
|
856 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
857 |
global $wpdb;
|
858 |
|
859 |
$sql = $wpdb->prepare(
|
880 |
*/
|
881 |
public function update_job_start_time( $job_id, $job_start_time ) {
|
882 |
global $wpdb;
|
883 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
884 |
|
885 |
$sql = $wpdb->prepare(
|
886 |
"UPDATE $wpdb->wpbackitup_job_control
|
904 |
* @return bool
|
905 |
*/
|
906 |
public function update_job_end_time( $job_id, $job_end_time ) {
|
907 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
908 |
global $wpdb;
|
909 |
|
910 |
$sql = $wpdb->prepare(
|
930 |
*/
|
931 |
public function get_user_by_login( $user_login,$table_prefix=null ) {
|
932 |
global $wpdb;
|
933 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin.');
|
934 |
|
935 |
$users_table = $wpdb->users;
|
936 |
if (!is_null( $table_prefix )){
|
945 |
",$user_login);
|
946 |
|
947 |
$query_result=$this->get_row($sql);
|
948 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
949 |
|
950 |
return $query_result;
|
951 |
}
|
957 |
*/
|
958 |
public function get_user_by_id( $user_id ) {
|
959 |
global $wpdb;
|
960 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
961 |
|
962 |
$sql = $wpdb->prepare(
|
963 |
"SELECT *
|
967 |
",$user_id);
|
968 |
|
969 |
$query_result=$this->get_row($sql);
|
970 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
971 |
|
972 |
return $query_result;
|
973 |
}
|
983 |
*/
|
984 |
public function get_duplicate_users( $user_id, $user_login ) {
|
985 |
global $wpdb;
|
986 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
987 |
|
988 |
$sql = $wpdb->prepare(
|
989 |
"SELECT *
|
994 |
",$user_id,$user_login);
|
995 |
|
996 |
$query_result=$this->get_rows($sql);
|
997 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
998 |
|
999 |
return $query_result;
|
1000 |
}
|
1010 |
*/
|
1011 |
public function update_snapshot_currentuser( $current_user, $table_prefix) {
|
1012 |
global $wpdb;
|
1013 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1014 |
|
1015 |
if ( empty( $current_user )) {
|
1016 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__, 'User login is not valid:' . var_export( $current_user,true));
|
1017 |
return false;
|
1018 |
}
|
1019 |
|
1031 |
);
|
1032 |
|
1033 |
$snapshot_user_id = $this->get_scalar($sql);
|
1034 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Snapshot User Id (null means doesnt exist):'. var_export( $snapshot_user_id,true));
|
1035 |
|
1036 |
//Delete user and user meta if exists in snapshot DB
|
1037 |
if (! empty($snapshot_user_id)) {
|
1046 |
|
1047 |
$sql_rtn = $this->query($sql);
|
1048 |
if (false=== $sql_rtn ) {
|
1049 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Could not delete usermeta from snapshot table.');
|
1050 |
return false;
|
1051 |
}
|
1052 |
|
1060 |
|
1061 |
$sql_rtn = $this->query($sql);
|
1062 |
if (false=== $sql_rtn ) {
|
1063 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Could not delete users from snapshot table.');
|
1064 |
return false;
|
1065 |
}
|
1066 |
|
1097 |
|
1098 |
$sql_rtn = $this->query($sql);
|
1099 |
if (false=== $sql_rtn ) {
|
1100 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Could not add users into snapshot table.');
|
1101 |
return false;
|
1102 |
}
|
1103 |
|
1109 |
);
|
1110 |
|
1111 |
$snapshot_user_id = $this->get_scalar($sql);
|
1112 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Snapshot User Id (null means doesnt exist):'. var_export( $snapshot_user_id,true));
|
1113 |
|
1114 |
//Delete user and user meta if exists in snapshot DB
|
1115 |
if ( empty($snapshot_user_id)) {
|
1116 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Could not find new user ID in snapshot table.');
|
1117 |
return false;
|
1118 |
}
|
1119 |
|
1137 |
|
1138 |
$sql_rtn = $this->query($sql);
|
1139 |
if (false=== $sql_rtn ) {
|
1140 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Could add user meta into snapshot table.');
|
1141 |
return false;
|
1142 |
}
|
1143 |
|
1144 |
|
1145 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Current user added to snapshot table.');
|
1146 |
return true;
|
1147 |
|
1148 |
}
|
1158 |
*/
|
1159 |
public function update_snapshot_table_prefix( $snapshot_prefix, $backup_table_prefix) {
|
1160 |
global $wpdb;
|
1161 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1162 |
|
1163 |
if ( empty( $snapshot_prefix )) {
|
1164 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__, 'Snapshot prefix is not valid:' . var_export( $snapshot_prefix,true));
|
1165 |
return false;
|
1166 |
}
|
1167 |
|
1168 |
if ( empty( $backup_table_prefix )) {
|
1169 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__, 'Backup table prefix is not valid:' . var_export( $backup_table_prefix,true));
|
1170 |
return false;
|
1171 |
}
|
1172 |
|
1184 |
|
1185 |
$sql_rtn = $this->query($sql);
|
1186 |
if (false=== $sql_rtn ) {
|
1187 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Could update table prefix in options snapshot table.');
|
1188 |
return false;
|
1189 |
}
|
1190 |
|
1203 |
|
1204 |
$sql_rtn = $this->query($sql);
|
1205 |
if (false=== $sql_rtn ) {
|
1206 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Could not delete users from snapshot table.');
|
1207 |
return false;
|
1208 |
}
|
1209 |
|
1210 |
|
1211 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Current user added to snapshot table.');
|
1212 |
return true;
|
1213 |
|
1214 |
}
|
1224 |
*/
|
1225 |
public function update_create_user_by_login( $db_user, $table_prefix=null) {
|
1226 |
global $wpdb;
|
1227 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1228 |
|
1229 |
$users_table = $wpdb->users;
|
1230 |
if (!is_null( $table_prefix )){
|
1307 |
*/
|
1308 |
public function create_user( $db_user ) {
|
1309 |
global $wpdb;
|
1310 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1311 |
|
1312 |
$sql = $wpdb->prepare(
|
1313 |
"INSERT INTO $wpdb->users
|
1352 |
*/
|
1353 |
public function delete_users_except( $id, $limit=5000 ) {
|
1354 |
global $wpdb;
|
1355 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1356 |
|
1357 |
$sql = $wpdb->prepare(
|
1358 |
"DELETE FROM $wpdb->users
|
1375 |
*/
|
1376 |
public function get_user_count() {
|
1377 |
global $wpdb;
|
1378 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1379 |
|
1380 |
$sql = "SELECT count(*) as user_count FROM $wpdb->users";
|
1381 |
$result = $this->get_row($sql);
|
1390 |
*/
|
1391 |
public function get_usermeta_count() {
|
1392 |
global $wpdb;
|
1393 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1394 |
|
1395 |
$sql = "SELECT count(distinct user_id) as user_count FROM $wpdb->usermeta";
|
1396 |
$result = $this->get_row($sql);
|
1408 |
*/
|
1409 |
public function delete_usermeta_except( $id, $limit=5000 ) {
|
1410 |
global $wpdb;
|
1411 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1412 |
|
1413 |
$sql = $wpdb->prepare(
|
1414 |
"DELETE FROM $wpdb->usermeta
|
1425 |
|
1426 |
public function get_options_wpbackitup() {
|
1427 |
global $wpdb;
|
1428 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1429 |
|
1430 |
$sql ="SELECT * FROM $wpdb->options WHERE option_name LIKE 'wp-backitup%' ";
|
1431 |
|
1432 |
$query_result=$this->get_rows($sql);
|
1433 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
1434 |
|
1435 |
return $query_result;
|
1436 |
|
1439 |
|
1440 |
public function update_create_option($option_name,$option_value,$autoload,$table_prefix=null) {
|
1441 |
global $wpdb;
|
1442 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1443 |
|
1444 |
//does option already exist
|
1445 |
$option = $this->get_option_by_name($option_name,$table_prefix);
|
1503 |
*/
|
1504 |
public function update_option($option_name,$option_value,$table_prefix=null) {
|
1505 |
global $wpdb;
|
1506 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1507 |
|
1508 |
//does option already exist
|
1509 |
$option = $this->get_option_by_name($option_name,$table_prefix);
|
1538 |
|
1539 |
public function get_option_by_name( $option_name,$table_prefix=null ) {
|
1540 |
global $wpdb;
|
1541 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1542 |
|
1543 |
//replace the table prefix with the job_id
|
1544 |
$options_table = $wpdb->options;
|
1555 |
",$option_name);
|
1556 |
|
1557 |
$query_result=$this->get_rows($sql);
|
1558 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
1559 |
|
1560 |
return $query_result;
|
1561 |
}
|
1583 |
|
1584 |
$value = $this->get_scalar($sql);
|
1585 |
if (empty($value)) {
|
1586 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Option not found:'. $option_name);
|
1587 |
}
|
1588 |
|
1589 |
return $value;
|
1598 |
*/
|
1599 |
public function get_usermeta_by_id( $user_id ) {
|
1600 |
global $wpdb;
|
1601 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1602 |
|
1603 |
$sql = $wpdb->prepare(
|
1604 |
"SELECT *
|
1608 |
",$user_id);
|
1609 |
|
1610 |
$query_result=$this->get_rows($sql);
|
1611 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
1612 |
|
1613 |
return $query_result;
|
1614 |
}
|
1615 |
|
1616 |
public function get_usermeta_by_id_metakey( $user_id,$meta_key ) {
|
1617 |
global $wpdb;
|
1618 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1619 |
|
1620 |
$sql = $wpdb->prepare(
|
1621 |
"SELECT *
|
1626 |
",$user_id,$meta_key);
|
1627 |
|
1628 |
$query_result=$this->get_row($sql);
|
1629 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($query_result,true));
|
1630 |
|
1631 |
return $query_result;
|
1632 |
}
|
1642 |
*/
|
1643 |
public function update_create_usermeta($user_id,$meta_key,$meta_value) {
|
1644 |
global $wpdb;
|
1645 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1646 |
|
1647 |
//does usermeta already exist
|
1648 |
$user_meta = $this->get_usermeta_by_id_metakey($user_id,$meta_key);
|
1694 |
*/
|
1695 |
function get_tables($table_prefix=null){
|
1696 |
global $wpdb;
|
1697 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1698 |
|
1699 |
$sql = "SHOW TABLES";
|
1700 |
if (! is_null($table_prefix)){
|
1727 |
|
1728 |
public function get_table_rows() {
|
1729 |
global $wpdb;
|
1730 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1731 |
|
1732 |
$sql = $wpdb->prepare(
|
1733 |
"SELECT
|
1751 |
}
|
1752 |
|
1753 |
|
1754 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Results:'.var_export($table_list,true));
|
1755 |
return $tables;
|
1756 |
|
1757 |
}
|
1766 |
|
1767 |
if (!empty($base_directory)){
|
1768 |
$base_directory.='/bin/';
|
1769 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'MySQL install path found:' .$base_directory);
|
1770 |
return $base_directory;
|
1771 |
}
|
1772 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'MySQL install path NOT found');
|
1773 |
return false;
|
1774 |
}
|
1775 |
|
1790 |
*/
|
1791 |
public function query($sql){
|
1792 |
global $wpdb;
|
1793 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1794 |
|
1795 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,$sql);
|
1796 |
$wpdb_result = $wpdb->query($sql);
|
1797 |
//$last_query = $wpdb->last_query;
|
1798 |
$last_error = $wpdb->last_error;
|
1799 |
|
1800 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Last Query:' .var_export( $last_query,true ) );
|
1801 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Query Result: ' .($wpdb_result=== FALSE?'Query Error': $wpdb_result));
|
1802 |
|
1803 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
1804 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Last Error:' .var_export( $last_error,true ) );
|
1805 |
}
|
1806 |
|
1807 |
return $wpdb_result;
|
1815 |
*/
|
1816 |
public function get_row($sql){
|
1817 |
global $wpdb;
|
1818 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1819 |
|
1820 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,$sql);
|
1821 |
$wpdb_result = $wpdb->get_row($sql);
|
1822 |
$last_query = $wpdb->last_query;
|
1823 |
$last_error = $wpdb->last_error;
|
1824 |
|
1825 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Last Query:' .var_export( $last_query,true ));
|
1826 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Query Result: ' .($wpdb_result==null?'NULL': $wpdb->num_rows));
|
1827 |
|
1828 |
if (null == $wpdb_result && !empty($last_error)) {
|
1829 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Last Error:' .var_export( $last_query,true ));
|
1830 |
}
|
1831 |
|
1832 |
return $wpdb_result;
|
1841 |
*/
|
1842 |
public function get_rows($sql,$output=OBJECT){
|
1843 |
global $wpdb;
|
1844 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1845 |
|
1846 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,$sql);
|
1847 |
$wpdb_result = $wpdb->get_results($sql,$output);
|
1848 |
//$last_query = $wpdb->last_query;
|
1849 |
$last_error = $wpdb->last_error;
|
1850 |
|
1851 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Last Query:' .var_export( $last_query,true ));
|
1852 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Query Result: ' .($wpdb_result==null?'NULL': $wpdb->num_rows));
|
1853 |
|
1854 |
if (null == $wpdb_result && ! empty($last_error)) {
|
1855 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Last Error:' .var_export( $last_error,true ));
|
1856 |
}
|
1857 |
|
1858 |
return $wpdb_result;
|
1867 |
*/
|
1868 |
private function get_col($sql,$column_index=0){
|
1869 |
global $wpdb;
|
1870 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
1871 |
|
1872 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,$sql);
|
1873 |
$wpdb_result = $wpdb->get_col($sql,$column_index);
|
1874 |
$last_error = $wpdb->last_error;
|
1875 |
|
1876 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Query Result: ' .($wpdb_result==null?'NULL': $wpdb->num_rows));
|
1877 |
|
1878 |
if (null == $wpdb_result && ! empty($last_error)) {
|
1879 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Last Error:' .var_export( $last_error,true ));
|
1880 |
}
|
1881 |
|
1882 |
return $wpdb_result;
|
lib/includes/class-encryption.php
CHANGED
@@ -55,7 +55,7 @@ class WPBackItUp_Encryption {
|
|
55 |
$this->passphrase = $passphrase;
|
56 |
|
57 |
} catch ( Exception $e ) {
|
58 |
-
|
59 |
throw $e;
|
60 |
}
|
61 |
}
|
@@ -76,7 +76,7 @@ class WPBackItUp_Encryption {
|
|
76 |
|
77 |
//check version dependency
|
78 |
if (version_compare(PHP_VERSION, self::$php_required, '<')) {
|
79 |
-
|
80 |
return false;
|
81 |
}
|
82 |
|
@@ -90,7 +90,7 @@ class WPBackItUp_Encryption {
|
|
90 |
|
91 |
//mcrypt is just for testing...
|
92 |
if (! extension_loaded('mcrypt')) {
|
93 |
-
|
94 |
return false;
|
95 |
}
|
96 |
|
@@ -114,14 +114,14 @@ class WPBackItUp_Encryption {
|
|
114 |
File::encryptFileWithPassword($source_file,$target_file, $this->passphrase);
|
115 |
|
116 |
if ( ! file_exists( $target_file ) || filesize( $target_file ) <= 0 ){
|
117 |
-
|
118 |
return false;
|
119 |
}
|
120 |
|
121 |
@unlink ($source_file); //remove original file
|
122 |
|
123 |
} catch (Exception $ex) {
|
124 |
-
|
125 |
|
126 |
return false;
|
127 |
}
|
@@ -146,14 +146,14 @@ class WPBackItUp_Encryption {
|
|
146 |
File::decryptFileWithPassword($source_file, $target_file, $this->passphrase);
|
147 |
|
148 |
if ( ! file_exists( $target_file ) || filesize( $target_file ) <= 0 ){
|
149 |
-
|
150 |
return false;
|
151 |
}
|
152 |
|
153 |
@unlink ($source_file); //remove original file
|
154 |
|
155 |
} catch (Exception $ex) {
|
156 |
-
|
157 |
|
158 |
return false;
|
159 |
}
|
55 |
$this->passphrase = $passphrase;
|
56 |
|
57 |
} catch ( Exception $e ) {
|
58 |
+
WPBackItUp_Logger::log_error( $this->log_name, __METHOD__, 'Constructor Exception: ' . $e );
|
59 |
throw $e;
|
60 |
}
|
61 |
}
|
76 |
|
77 |
//check version dependency
|
78 |
if (version_compare(PHP_VERSION, self::$php_required, '<')) {
|
79 |
+
WPBackItUp_Logger::log_error( self::$default_log, __METHOD__,sprintf( 'PHP Version less than %s. Current PHP version is: %s ',self::$php_required,PHP_VERSION));
|
80 |
return false;
|
81 |
}
|
82 |
|
90 |
|
91 |
//mcrypt is just for testing...
|
92 |
if (! extension_loaded('mcrypt')) {
|
93 |
+
WPBackItUp_Logger::log_error( self::$default_log, __METHOD__, 'mcrypt is not installed');
|
94 |
return false;
|
95 |
}
|
96 |
|
114 |
File::encryptFileWithPassword($source_file,$target_file, $this->passphrase);
|
115 |
|
116 |
if ( ! file_exists( $target_file ) || filesize( $target_file ) <= 0 ){
|
117 |
+
WPBackItUp_Logger::log_error( $this->log_name, __METHOD__, 'File was not encrypted : ' . $target_file );
|
118 |
return false;
|
119 |
}
|
120 |
|
121 |
@unlink ($source_file); //remove original file
|
122 |
|
123 |
} catch (Exception $ex) {
|
124 |
+
WPBackItUp_Logger::log_error( $this->log_name, __METHOD__, 'File was not encrypted : ' . $ex );
|
125 |
|
126 |
return false;
|
127 |
}
|
146 |
File::decryptFileWithPassword($source_file, $target_file, $this->passphrase);
|
147 |
|
148 |
if ( ! file_exists( $target_file ) || filesize( $target_file ) <= 0 ){
|
149 |
+
WPBackItUp_Logger::log_error( $this->log_name, __METHOD__, 'File was not encrypted : ' . $target_file );
|
150 |
return false;
|
151 |
}
|
152 |
|
153 |
@unlink ($source_file); //remove original file
|
154 |
|
155 |
} catch (Exception $ex) {
|
156 |
+
WPBackItUp_Logger::log_error( $this->log_name, __METHOD__, 'File was not decrypted : ' . $ex );
|
157 |
|
158 |
return false;
|
159 |
}
|
lib/includes/class-filesystem.php
CHANGED
@@ -31,7 +31,7 @@ class WPBackItUp_FileSystem {
|
|
31 |
|
32 |
} catch(Exception $e) {
|
33 |
error_log($e);
|
34 |
-
|
35 |
}
|
36 |
}
|
37 |
|
@@ -40,11 +40,11 @@ class WPBackItUp_FileSystem {
|
|
40 |
}
|
41 |
|
42 |
public function create_dir($dir) {
|
43 |
-
|
44 |
if( !is_dir($dir) ) {
|
45 |
@mkdir($dir, 0755);
|
46 |
}
|
47 |
-
|
48 |
return true;
|
49 |
}
|
50 |
|
@@ -58,9 +58,9 @@ class WPBackItUp_FileSystem {
|
|
58 |
* @return bool false if all files and folders could NOT be deleted
|
59 |
*/
|
60 |
public function recursive_delete($dir, $ignore = array('') ){
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
$success=true;
|
66 |
if( is_dir($dir) ){
|
@@ -73,10 +73,10 @@ class WPBackItUp_FileSystem {
|
|
73 |
if(!is_dir($dir .'/'. $file)) {
|
74 |
//delete the file
|
75 |
if (unlink($dir .'/'. $file)){
|
76 |
-
|
77 |
} else {
|
78 |
$success=false;
|
79 |
-
|
80 |
}
|
81 |
} else {
|
82 |
//This is a dir so delete the files first
|
@@ -85,29 +85,29 @@ class WPBackItUp_FileSystem {
|
|
85 |
}
|
86 |
}
|
87 |
} else{
|
88 |
-
|
89 |
$success=false;
|
90 |
}
|
91 |
//Remove the directory
|
92 |
if (true===rmdir($dir)){
|
93 |
-
|
94 |
} else{
|
95 |
-
|
96 |
$success=false;
|
97 |
}
|
98 |
|
99 |
closedir($dh);
|
100 |
}
|
101 |
}
|
102 |
-
|
103 |
return $success;
|
104 |
}
|
105 |
|
106 |
public function recursive_copy($dir, $target_path, $ignore = array('') ) {
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
|
112 |
if( is_dir($dir) ) { //If the directory exists
|
113 |
//Exclude all the OTHER backup folders under wp-content
|
@@ -124,17 +124,17 @@ class WPBackItUp_FileSystem {
|
|
124 |
fclose($fsrc);
|
125 |
fclose($fdest);
|
126 |
} catch(Exception $e) {
|
127 |
-
|
128 |
return false;
|
129 |
}
|
130 |
} else { //If $file is a directory
|
131 |
$destdir = $target_path .$file; //Modify the destination dir
|
132 |
if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
|
133 |
-
|
134 |
try {
|
135 |
@mkdir($destdir, 0755);
|
136 |
} catch(Exception $e) {
|
137 |
-
|
138 |
return false;
|
139 |
}
|
140 |
}
|
@@ -147,7 +147,7 @@ class WPBackItUp_FileSystem {
|
|
147 |
}
|
148 |
}
|
149 |
|
150 |
-
|
151 |
return true;
|
152 |
}
|
153 |
|
@@ -165,7 +165,7 @@ class WPBackItUp_FileSystem {
|
|
165 |
$target_file = $target_path .$file;
|
166 |
|
167 |
if (!file_exists($target_file)) {
|
168 |
-
|
169 |
$rtnVal=false;
|
170 |
continue;
|
171 |
}
|
@@ -174,21 +174,21 @@ class WPBackItUp_FileSystem {
|
|
174 |
$target_file_size = filesize ($target_file);
|
175 |
|
176 |
if ($source_file_size != $target_file_size){
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
$rtnVal=false;
|
181 |
continue;
|
182 |
}
|
183 |
|
184 |
} catch(Exception $e) {
|
185 |
-
|
186 |
return false;
|
187 |
}
|
188 |
} else { //If $file is a directory
|
189 |
$destdir = $target_path .$file; //Modify the destination dir
|
190 |
if(!is_dir($destdir)) {
|
191 |
-
|
192 |
$rtnVal= false;
|
193 |
}else{
|
194 |
$dir_rtnVal=$this->recursive_validate($source_path .$file .'/', $target_path .$file .'/', $ignore);
|
@@ -248,7 +248,7 @@ class WPBackItUp_FileSystem {
|
|
248 |
strpos(strtolower($dir),'/wp-content/uploads/backupwordpress')!== false
|
249 |
){
|
250 |
|
251 |
-
|
252 |
return true;
|
253 |
|
254 |
}else{
|
@@ -259,7 +259,7 @@ class WPBackItUp_FileSystem {
|
|
259 |
|
260 |
public function purge_FilesByDate($number_Files_Allowed,$path)
|
261 |
{
|
262 |
-
|
263 |
|
264 |
if (is_numeric($number_Files_Allowed) && $number_Files_Allowed> 0){
|
265 |
$FileList = glob($path . "*.zip");
|
@@ -270,8 +270,8 @@ class WPBackItUp_FileSystem {
|
|
270 |
$i = 1;
|
271 |
foreach ($FileList as $key => $val)
|
272 |
{
|
273 |
-
|
274 |
-
|
275 |
|
276 |
if($i <= $number_Files_Allowed)
|
277 |
{
|
@@ -282,23 +282,23 @@ class WPBackItUp_FileSystem {
|
|
282 |
$log_file_path = str_replace('.zip','.log',$val);
|
283 |
if (file_exists($val)) unlink($val);
|
284 |
if (file_exists($log_file_path)) unlink($log_file_path);
|
285 |
-
|
286 |
|
287 |
}
|
288 |
}
|
289 |
}
|
290 |
-
|
291 |
}
|
292 |
|
293 |
public function purge_files($path, $file_pattern, $days)
|
294 |
{
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
|
299 |
//Check Parms
|
300 |
if (empty($path) || empty($file_pattern) || !is_numeric($days)){
|
301 |
-
|
302 |
return false;
|
303 |
}
|
304 |
|
@@ -309,8 +309,8 @@ class WPBackItUp_FileSystem {
|
|
309 |
|
310 |
foreach ($FileList as $key => $file)
|
311 |
{
|
312 |
-
|
313 |
-
|
314 |
|
315 |
$current_date = new DateTime('now');
|
316 |
$file_mod_date = new DateTime(date('Y-m-d',filemtime($file)));
|
@@ -324,13 +324,13 @@ class WPBackItUp_FileSystem {
|
|
324 |
|
325 |
if($date_diff_days>=$days){
|
326 |
if (file_exists($file)) unlink($file);
|
327 |
-
|
328 |
}
|
329 |
else{
|
330 |
break; //Exit for
|
331 |
}
|
332 |
}
|
333 |
-
|
334 |
return true;
|
335 |
}
|
336 |
|
@@ -346,13 +346,13 @@ class WPBackItUp_FileSystem {
|
|
346 |
// */
|
347 |
// public function purge_folders($path, $pattern, $retention_limit)
|
348 |
// {
|
349 |
-
//
|
350 |
-
//
|
351 |
-
//
|
352 |
//
|
353 |
// //Check Parms
|
354 |
// if (empty($path) || empty($pattern) || !is_numeric($retention_limit)){
|
355 |
-
//
|
356 |
// return false;
|
357 |
// }
|
358 |
//
|
@@ -365,8 +365,8 @@ class WPBackItUp_FileSystem {
|
|
365 |
// $backup_count=0;
|
366 |
// foreach (array_reverse($folder_list) as $key => $folder)
|
367 |
// {
|
368 |
-
//
|
369 |
-
//
|
370 |
//
|
371 |
// ++$backup_count;
|
372 |
// if($backup_count>$retention_limit){
|
@@ -375,13 +375,13 @@ class WPBackItUp_FileSystem {
|
|
375 |
// }
|
376 |
// }
|
377 |
// }
|
378 |
-
//
|
379 |
// return true;
|
380 |
// }
|
381 |
|
382 |
public function delete_files($file_list)
|
383 |
{
|
384 |
-
|
385 |
try {
|
386 |
$rtn_val = true;
|
387 |
foreach ($file_list as $key => $file)
|
@@ -390,53 +390,53 @@ class WPBackItUp_FileSystem {
|
|
390 |
|
391 |
//if any delete fails keep on going but return false
|
392 |
if (false===unlink($file)){
|
393 |
-
|
394 |
$rtn_val=false;
|
395 |
}
|
396 |
|
397 |
-
|
398 |
} else {
|
399 |
//not an error
|
400 |
-
|
401 |
}
|
402 |
}
|
403 |
|
404 |
-
|
405 |
return $rtn_val;
|
406 |
|
407 |
} catch(Exception $e) {
|
408 |
-
|
409 |
return false;
|
410 |
}
|
411 |
}
|
412 |
|
413 |
|
414 |
function get_file_handle($path,$newFile=false) {
|
415 |
-
|
416 |
|
417 |
try {
|
418 |
|
419 |
if ($newFile && file_exists($path)){
|
420 |
if (unlink($path)){
|
421 |
-
|
422 |
}
|
423 |
else{
|
424 |
-
|
425 |
-
|
426 |
}
|
427 |
}
|
428 |
|
429 |
$fh= fopen($path, 'w');
|
430 |
if (false===$fh){
|
431 |
-
|
432 |
-
|
433 |
return false;
|
434 |
}
|
435 |
|
436 |
return $fh;
|
437 |
|
438 |
} catch(Exception $e) {
|
439 |
-
|
440 |
return false;
|
441 |
}
|
442 |
}
|
@@ -449,28 +449,28 @@ class WPBackItUp_FileSystem {
|
|
449 |
* @return bool
|
450 |
*/
|
451 |
function copy_file($from_file,$to_file) {
|
452 |
-
|
453 |
-
|
454 |
|
455 |
try {
|
456 |
if (file_exists($from_file)){
|
457 |
if (copy($from_file,$to_file)){
|
458 |
-
|
459 |
return true;
|
460 |
}
|
461 |
else{
|
462 |
-
|
463 |
-
|
464 |
return false;
|
465 |
}
|
466 |
}
|
467 |
else{
|
468 |
-
|
469 |
return false;
|
470 |
}
|
471 |
|
472 |
} catch(Exception $e) {
|
473 |
-
|
474 |
return false;
|
475 |
}
|
476 |
}
|
@@ -483,28 +483,28 @@ class WPBackItUp_FileSystem {
|
|
483 |
* @return bool
|
484 |
*/
|
485 |
function rename_file($from_file,$to_file_name) {
|
486 |
-
|
487 |
-
|
488 |
|
489 |
try {
|
490 |
if (file_exists($from_file)){
|
491 |
if (rename($from_file,$to_file_name)){
|
492 |
-
|
493 |
return true;
|
494 |
}
|
495 |
else{
|
496 |
-
|
497 |
-
|
498 |
return false;
|
499 |
}
|
500 |
}
|
501 |
else{
|
502 |
-
|
503 |
return false;
|
504 |
}
|
505 |
|
506 |
} catch(Exception $e) {
|
507 |
-
|
508 |
return false;
|
509 |
}
|
510 |
}
|
@@ -515,22 +515,22 @@ class WPBackItUp_FileSystem {
|
|
515 |
* @param $path
|
516 |
*/
|
517 |
function secure_folder($path){
|
518 |
-
|
519 |
|
520 |
$path = rtrim($path,"/");
|
521 |
|
522 |
if( !is_dir($path) ) {
|
523 |
@mkdir($path, 0755);
|
524 |
-
|
525 |
}
|
526 |
|
527 |
if (!is_file($path.'/index.html')) @file_put_contents($path.'/index.html',"<html><body><a href=\"http://www.wpbackitup.com\">WPBackItUp - The simplest way to backup WordPress</a></body></html>");
|
528 |
if (!is_file($path.'/.htaccess')) @file_put_contents($path.'/.htaccess','deny from all');
|
529 |
if (!is_file($path.'/web.config')) @file_put_contents($path.'/web.config', "<configuration>\n<system.webServer>\n<authorization>\n<deny users=\"*\" />\n</authorization>\n</system.webServer>\n</configuration>\n");
|
530 |
-
|
531 |
|
532 |
|
533 |
-
|
534 |
}
|
535 |
|
536 |
|
@@ -569,16 +569,16 @@ class WPBackItUp_FileSystem {
|
|
569 |
* @return array Array of files
|
570 |
*/
|
571 |
function get_fileonly_list($path,$extensions=null){
|
572 |
-
//
|
573 |
-
//
|
574 |
|
575 |
//Remove trailing slashes
|
576 |
$path = rtrim($path,"\\");
|
577 |
$path = rtrim($path,"/");
|
578 |
-
//
|
579 |
|
580 |
$all_files = glob($path .'/*.*');
|
581 |
-
//
|
582 |
|
583 |
//If a file pattern is passed then filter
|
584 |
if(isset($extensions)){
|
@@ -588,7 +588,7 @@ class WPBackItUp_FileSystem {
|
|
588 |
$filtered_files =array_filter($all_files, 'is_file');
|
589 |
}
|
590 |
|
591 |
-
//
|
592 |
return $filtered_files;
|
593 |
}
|
594 |
|
@@ -613,7 +613,7 @@ class WPBackItUp_FileSystem {
|
|
613 |
//Open output file
|
614 |
$toFile_handle = @fopen( $to_filepath, 'a');
|
615 |
if (false===$toFile_handle) {
|
616 |
-
|
617 |
return false;
|
618 |
}
|
619 |
|
@@ -635,7 +635,7 @@ class WPBackItUp_FileSystem {
|
|
635 |
$offset += $chunkSize; //Get next offset
|
636 |
} else{
|
637 |
//should never get here
|
638 |
-
|
639 |
@fclose( $fromFile_handle);
|
640 |
return false;
|
641 |
}
|
@@ -648,13 +648,13 @@ class WPBackItUp_FileSystem {
|
|
648 |
return true;
|
649 |
|
650 |
} else {
|
651 |
-
|
652 |
return false;
|
653 |
}
|
654 |
|
655 |
|
656 |
} catch (Exception $e) {
|
657 |
-
|
658 |
return false;
|
659 |
}
|
660 |
|
@@ -757,7 +757,7 @@ class WPBackItUp_FileSystem {
|
|
757 |
return $bytes;
|
758 |
|
759 |
} catch(Exception $e) {
|
760 |
-
|
761 |
return '0 bytes';
|
762 |
}
|
763 |
|
31 |
|
32 |
} catch(Exception $e) {
|
33 |
error_log($e);
|
34 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .$e);
|
35 |
}
|
36 |
}
|
37 |
|
40 |
}
|
41 |
|
42 |
public function create_dir($dir) {
|
43 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Create Directory: ' .$dir);
|
44 |
if( !is_dir($dir) ) {
|
45 |
@mkdir($dir, 0755);
|
46 |
}
|
47 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Directory created: ' .$dir);
|
48 |
return true;
|
49 |
}
|
50 |
|
58 |
* @return bool false if all files and folders could NOT be deleted
|
59 |
*/
|
60 |
public function recursive_delete($dir, $ignore = array('') ){
|
61 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Recursively Delete: ' .$dir);
|
62 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Ignore:');
|
63 |
+
WPBackItUp_Logger::log($this->log_name,$ignore);
|
64 |
|
65 |
$success=true;
|
66 |
if( is_dir($dir) ){
|
73 |
if(!is_dir($dir .'/'. $file)) {
|
74 |
//delete the file
|
75 |
if (unlink($dir .'/'. $file)){
|
76 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Deleted:' .$dir .'/'. $file);
|
77 |
} else {
|
78 |
$success=false;
|
79 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File NOT Deleted:' .$dir .'/'. $file);
|
80 |
}
|
81 |
} else {
|
82 |
//This is a dir so delete the files first
|
85 |
}
|
86 |
}
|
87 |
} else{
|
88 |
+
WPBackItUp_Logger::log_error( $this->log_name, __METHOD__, 'Folder could not be opened:' . $dir );
|
89 |
$success=false;
|
90 |
}
|
91 |
//Remove the directory
|
92 |
if (true===rmdir($dir)){
|
93 |
+
WPBackItUp_Logger::log_info( $this->log_name, __METHOD__, 'Folder Deleted:' . $dir );
|
94 |
} else{
|
95 |
+
WPBackItUp_Logger::log_error( $this->log_name, __METHOD__, 'Folder could not be deleted:' . $dir );
|
96 |
$success=false;
|
97 |
}
|
98 |
|
99 |
closedir($dh);
|
100 |
}
|
101 |
}
|
102 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Recursive Delete Completed:'.var_export($success,true));
|
103 |
return $success;
|
104 |
}
|
105 |
|
106 |
public function recursive_copy($dir, $target_path, $ignore = array('') ) {
|
107 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Recursive copy FROM: ' .$dir);
|
108 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Recursive Copy TO: '.$target_path);
|
109 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'IGNORE:');
|
110 |
+
WPBackItUp_Logger::log($this->log_name,$ignore);
|
111 |
|
112 |
if( is_dir($dir) ) { //If the directory exists
|
113 |
//Exclude all the OTHER backup folders under wp-content
|
124 |
fclose($fsrc);
|
125 |
fclose($fdest);
|
126 |
} catch(Exception $e) {
|
127 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File Copy Exception: ' .$e);
|
128 |
return false;
|
129 |
}
|
130 |
} else { //If $file is a directory
|
131 |
$destdir = $target_path .$file; //Modify the destination dir
|
132 |
if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
|
133 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Create Folder: ' .$destdir);
|
134 |
try {
|
135 |
@mkdir($destdir, 0755);
|
136 |
} catch(Exception $e) {
|
137 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Create Folder Exception: ' .$e);
|
138 |
return false;
|
139 |
}
|
140 |
}
|
147 |
}
|
148 |
}
|
149 |
|
150 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Completed');
|
151 |
return true;
|
152 |
}
|
153 |
|
165 |
$target_file = $target_path .$file;
|
166 |
|
167 |
if (!file_exists($target_file)) {
|
168 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Files DIFF - Target file doesnt exist:' . $target_file);
|
169 |
$rtnVal=false;
|
170 |
continue;
|
171 |
}
|
174 |
$target_file_size = filesize ($target_file);
|
175 |
|
176 |
if ($source_file_size != $target_file_size){
|
177 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Files DIFF Source:' . $source_file);
|
178 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Files DIFF Target:' . $target_file);
|
179 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Files DIFF Size:' . $source_file_size .':' . $target_file_size);
|
180 |
$rtnVal=false;
|
181 |
continue;
|
182 |
}
|
183 |
|
184 |
} catch(Exception $e) {
|
185 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .$e);
|
186 |
return false;
|
187 |
}
|
188 |
} else { //If $file is a directory
|
189 |
$destdir = $target_path .$file; //Modify the destination dir
|
190 |
if(!is_dir($destdir)) {
|
191 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'DIFF Folder doesnt exist: ' .$destdir);
|
192 |
$rtnVal= false;
|
193 |
}else{
|
194 |
$dir_rtnVal=$this->recursive_validate($source_path .$file .'/', $target_path .$file .'/', $ignore);
|
248 |
strpos(strtolower($dir),'/wp-content/uploads/backupwordpress')!== false
|
249 |
){
|
250 |
|
251 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'SKIP Backup Folder: ' .$dir);
|
252 |
return true;
|
253 |
|
254 |
}else{
|
259 |
|
260 |
public function purge_FilesByDate($number_Files_Allowed,$path)
|
261 |
{
|
262 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Purge files by date:' .$number_Files_Allowed .':'.$path);
|
263 |
|
264 |
if (is_numeric($number_Files_Allowed) && $number_Files_Allowed> 0){
|
265 |
$FileList = glob($path . "*.zip");
|
270 |
$i = 1;
|
271 |
foreach ($FileList as $key => $val)
|
272 |
{
|
273 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,' File:'.$val);
|
274 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,' File Date Time:'.filemtime($val));
|
275 |
|
276 |
if($i <= $number_Files_Allowed)
|
277 |
{
|
282 |
$log_file_path = str_replace('.zip','.log',$val);
|
283 |
if (file_exists($val)) unlink($val);
|
284 |
if (file_exists($log_file_path)) unlink($log_file_path);
|
285 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Delete File:)' .$val);
|
286 |
|
287 |
}
|
288 |
}
|
289 |
}
|
290 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Completed.');
|
291 |
}
|
292 |
|
293 |
public function purge_files($path, $file_pattern, $days)
|
294 |
{
|
295 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Purge files days:' . $days);
|
296 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Purge files path:' . $path);
|
297 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Purge files extension:' . $file_pattern);
|
298 |
|
299 |
//Check Parms
|
300 |
if (empty($path) || empty($file_pattern) || !is_numeric($days)){
|
301 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Invalid Parm values');
|
302 |
return false;
|
303 |
}
|
304 |
|
309 |
|
310 |
foreach ($FileList as $key => $file)
|
311 |
{
|
312 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File:'.$file);
|
313 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Date Time:'.filemtime($file));
|
314 |
|
315 |
$current_date = new DateTime('now');
|
316 |
$file_mod_date = new DateTime(date('Y-m-d',filemtime($file)));
|
324 |
|
325 |
if($date_diff_days>=$days){
|
326 |
if (file_exists($file)) unlink($file);
|
327 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Delete:' . $file);
|
328 |
}
|
329 |
else{
|
330 |
break; //Exit for
|
331 |
}
|
332 |
}
|
333 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Completed.');
|
334 |
return true;
|
335 |
}
|
336 |
|
346 |
// */
|
347 |
// public function purge_folders($path, $pattern, $retention_limit)
|
348 |
// {
|
349 |
+
// WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Purge folders retained number:' . $retention_limit);
|
350 |
+
// WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Purge folder path:' . $path);
|
351 |
+
// WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Purge pattern:' . $pattern);
|
352 |
//
|
353 |
// //Check Parms
|
354 |
// if (empty($path) || empty($pattern) || !is_numeric($retention_limit)){
|
355 |
+
// WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Invalid Parm values');
|
356 |
// return false;
|
357 |
// }
|
358 |
//
|
365 |
// $backup_count=0;
|
366 |
// foreach (array_reverse($folder_list) as $key => $folder)
|
367 |
// {
|
368 |
+
// WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Folder:'.$folder);
|
369 |
+
// WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Folder Date Time:'. date("F d Y H:i:s", filemtime($folder)));
|
370 |
//
|
371 |
// ++$backup_count;
|
372 |
// if($backup_count>$retention_limit){
|
375 |
// }
|
376 |
// }
|
377 |
// }
|
378 |
+
// WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
379 |
// return true;
|
380 |
// }
|
381 |
|
382 |
public function delete_files($file_list)
|
383 |
{
|
384 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
385 |
try {
|
386 |
$rtn_val = true;
|
387 |
foreach ($file_list as $key => $file)
|
390 |
|
391 |
//if any delete fails keep on going but return false
|
392 |
if (false===unlink($file)){
|
393 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File was NOT Deleted:' . $file);
|
394 |
$rtn_val=false;
|
395 |
}
|
396 |
|
397 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Deleted:' . $file);
|
398 |
} else {
|
399 |
//not an error
|
400 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File was not found:' . $file);
|
401 |
}
|
402 |
}
|
403 |
|
404 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
405 |
return $rtn_val;
|
406 |
|
407 |
} catch(Exception $e) {
|
408 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception:' . $e);
|
409 |
return false;
|
410 |
}
|
411 |
}
|
412 |
|
413 |
|
414 |
function get_file_handle($path,$newFile=false) {
|
415 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Path:' . $path);
|
416 |
|
417 |
try {
|
418 |
|
419 |
if ($newFile && file_exists($path)){
|
420 |
if (unlink($path)){
|
421 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Deleted:' . $path);
|
422 |
}
|
423 |
else{
|
424 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File could not be deleted:');
|
425 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,var_export(error_get_last(),true));
|
426 |
}
|
427 |
}
|
428 |
|
429 |
$fh= fopen($path, 'w');
|
430 |
if (false===$fh){
|
431 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File could not be opened:');
|
432 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,var_export(error_get_last(),true));
|
433 |
return false;
|
434 |
}
|
435 |
|
436 |
return $fh;
|
437 |
|
438 |
} catch(Exception $e) {
|
439 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception:' . $e);
|
440 |
return false;
|
441 |
}
|
442 |
}
|
449 |
* @return bool
|
450 |
*/
|
451 |
function copy_file($from_file,$to_file) {
|
452 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'FROM Path:' . $from_file);
|
453 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'TO Path:' . $to_file);
|
454 |
|
455 |
try {
|
456 |
if (file_exists($from_file)){
|
457 |
if (copy($from_file,$to_file)){
|
458 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File copied successfully.');
|
459 |
return true;
|
460 |
}
|
461 |
else{
|
462 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File could not be copied:');
|
463 |
+
WPBackItUp_Logger::error($this->log_name,__METHOD__,var_export(error_get_last(),true));
|
464 |
return false;
|
465 |
}
|
466 |
}
|
467 |
else{
|
468 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'FROM File doesnt exist');
|
469 |
return false;
|
470 |
}
|
471 |
|
472 |
} catch(Exception $e) {
|
473 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception:' . $e);
|
474 |
return false;
|
475 |
}
|
476 |
}
|
483 |
* @return bool
|
484 |
*/
|
485 |
function rename_file($from_file,$to_file_name) {
|
486 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'FROM Path:' . $from_file);
|
487 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'TO Path:' . $to_file_name);
|
488 |
|
489 |
try {
|
490 |
if (file_exists($from_file)){
|
491 |
if (rename($from_file,$to_file_name)){
|
492 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File renamed successfully.');
|
493 |
return true;
|
494 |
}
|
495 |
else{
|
496 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File could not be renamed:');
|
497 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,var_export(error_get_last(),true));
|
498 |
return false;
|
499 |
}
|
500 |
}
|
501 |
else{
|
502 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'FROM File doesnt exist');
|
503 |
return false;
|
504 |
}
|
505 |
|
506 |
} catch(Exception $e) {
|
507 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception:' . $e);
|
508 |
return false;
|
509 |
}
|
510 |
}
|
515 |
* @param $path
|
516 |
*/
|
517 |
function secure_folder($path){
|
518 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
519 |
|
520 |
$path = rtrim($path,"/");
|
521 |
|
522 |
if( !is_dir($path) ) {
|
523 |
@mkdir($path, 0755);
|
524 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Folder Created:' .$path);
|
525 |
}
|
526 |
|
527 |
if (!is_file($path.'/index.html')) @file_put_contents($path.'/index.html',"<html><body><a href=\"http://www.wpbackitup.com\">WPBackItUp - The simplest way to backup WordPress</a></body></html>");
|
528 |
if (!is_file($path.'/.htaccess')) @file_put_contents($path.'/.htaccess','deny from all');
|
529 |
if (!is_file($path.'/web.config')) @file_put_contents($path.'/web.config', "<configuration>\n<system.webServer>\n<authorization>\n<deny users=\"*\" />\n</authorization>\n</system.webServer>\n</configuration>\n");
|
530 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Secure files exist or were created.');
|
531 |
|
532 |
|
533 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
534 |
}
|
535 |
|
536 |
|
569 |
* @return array Array of files
|
570 |
*/
|
571 |
function get_fileonly_list($path,$extensions=null){
|
572 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,"Begin:" .$path);
|
573 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,"Pattern:" .$extensions);//txt|sql'
|
574 |
|
575 |
//Remove trailing slashes
|
576 |
$path = rtrim($path,"\\");
|
577 |
$path = rtrim($path,"/");
|
578 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,"Path:" .$path);
|
579 |
|
580 |
$all_files = glob($path .'/*.*');
|
581 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,"All Files:" .var_export($all_files,true));
|
582 |
|
583 |
//If a file pattern is passed then filter
|
584 |
if(isset($extensions)){
|
588 |
$filtered_files =array_filter($all_files, 'is_file');
|
589 |
}
|
590 |
|
591 |
+
//WPBackItUp_Logger::log_info($this->log_name,__METHOD__,"Filtered Files:" .var_export($filtered_files,true));
|
592 |
return $filtered_files;
|
593 |
}
|
594 |
|
613 |
//Open output file
|
614 |
$toFile_handle = @fopen( $to_filepath, 'a');
|
615 |
if (false===$toFile_handle) {
|
616 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,sprintf("Output file error, file could not be created: %s", $toFile_handle));
|
617 |
return false;
|
618 |
}
|
619 |
|
635 |
$offset += $chunkSize; //Get next offset
|
636 |
} else{
|
637 |
//should never get here
|
638 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,sprintf("Unable to read file-offset : %s-%s", $from_filepath,$offset));
|
639 |
@fclose( $fromFile_handle);
|
640 |
return false;
|
641 |
}
|
648 |
return true;
|
649 |
|
650 |
} else {
|
651 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Read file error');
|
652 |
return false;
|
653 |
}
|
654 |
|
655 |
|
656 |
} catch (Exception $e) {
|
657 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception:' . $e->getMessage());
|
658 |
return false;
|
659 |
}
|
660 |
|
757 |
return $bytes;
|
758 |
|
759 |
} catch(Exception $e) {
|
760 |
+
WPBackItUp_Logger::log_error(self::FILESYSTEM_LOG_NAME,__METHOD__,'Exception:' . $e);
|
761 |
return '0 bytes';
|
762 |
}
|
763 |
|
lib/includes/class-job-item.php
CHANGED
@@ -56,14 +56,14 @@ class WPBackItUp_Job_Item {
|
|
56 |
|
57 |
} catch(Exception $e) {
|
58 |
error_log($e); //Log to debug
|
59 |
-
|
60 |
}
|
61 |
}
|
62 |
|
63 |
function __destruct() {
|
64 |
-
|
65 |
|
66 |
-
|
67 |
}
|
68 |
|
69 |
/**
|
@@ -102,7 +102,7 @@ class WPBackItUp_Job_Item {
|
|
102 |
*
|
103 |
*/
|
104 |
public static function get_item_by_id($item_id) {
|
105 |
-
|
106 |
|
107 |
$db = new WPBackItUp_DataAccess();
|
108 |
$db_item = $db->get_item_by_id( $item_id);
|
@@ -123,7 +123,7 @@ class WPBackItUp_Job_Item {
|
|
123 |
* @return array|bool
|
124 |
*/
|
125 |
public static function get_item_batch_by_group($job_id,$batch_size,$group_id) {
|
126 |
-
|
127 |
|
128 |
$batch_id=current_time( 'timestamp' );
|
129 |
|
@@ -150,7 +150,7 @@ class WPBackItUp_Job_Item {
|
|
150 |
* @return mixed
|
151 |
*/
|
152 |
public static function get_open_item_count($job_id,$group_id) {
|
153 |
-
|
154 |
|
155 |
$db = new WPBackItUp_DataAccess();
|
156 |
$remaining_count = $db->get_open_item_count($job_id,$group_id);
|
@@ -167,7 +167,7 @@ class WPBackItUp_Job_Item {
|
|
167 |
* @return mixed
|
168 |
*/
|
169 |
public function setStatus($item_status){
|
170 |
-
|
171 |
|
172 |
$db = new WPBackItUp_DataAccess();
|
173 |
$updated = $db->update_item_status($this->item_id,$item_status);
|
56 |
|
57 |
} catch(Exception $e) {
|
58 |
error_log($e); //Log to debug
|
59 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .$e);
|
60 |
}
|
61 |
}
|
62 |
|
63 |
function __destruct() {
|
64 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
65 |
|
66 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End');
|
67 |
}
|
68 |
|
69 |
/**
|
102 |
*
|
103 |
*/
|
104 |
public static function get_item_by_id($item_id) {
|
105 |
+
WPBackItUp_Logger::log_info( self::DEFAULT_LOG_NAME, __METHOD__, 'Begin' );
|
106 |
|
107 |
$db = new WPBackItUp_DataAccess();
|
108 |
$db_item = $db->get_item_by_id( $item_id);
|
123 |
* @return array|bool
|
124 |
*/
|
125 |
public static function get_item_batch_by_group($job_id,$batch_size,$group_id) {
|
126 |
+
WPBackItUp_Logger::log_info( self::DEFAULT_LOG_NAME, __METHOD__, 'Begin' );
|
127 |
|
128 |
$batch_id=current_time( 'timestamp' );
|
129 |
|
150 |
* @return mixed
|
151 |
*/
|
152 |
public static function get_open_item_count($job_id,$group_id) {
|
153 |
+
WPBackItUp_Logger::log_info( self::DEFAULT_LOG_NAME, __METHOD__, 'Begin' );
|
154 |
|
155 |
$db = new WPBackItUp_DataAccess();
|
156 |
$remaining_count = $db->get_open_item_count($job_id,$group_id);
|
167 |
* @return mixed
|
168 |
*/
|
169 |
public function setStatus($item_status){
|
170 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
171 |
|
172 |
$db = new WPBackItUp_DataAccess();
|
173 |
$updated = $db->update_item_status($this->item_id,$item_status);
|
lib/includes/class-job-task.php
CHANGED
@@ -38,7 +38,7 @@ class WPBackItUp_Job_Task {
|
|
38 |
|
39 |
} catch(Exception $e) {
|
40 |
error_log($e);
|
41 |
-
|
42 |
}
|
43 |
}
|
44 |
|
@@ -90,12 +90,12 @@ class WPBackItUp_Job_Task {
|
|
90 |
* @return bool|WPBackItUp_Job_Task
|
91 |
*/
|
92 |
public static function get_task_by_id($task_id){
|
93 |
-
|
94 |
|
95 |
$db = new WPBackItUp_DataAccess();
|
96 |
$task = $db->get_task_by_id($task_id);
|
97 |
if (false===$task){
|
98 |
-
|
99 |
return false;
|
100 |
}
|
101 |
|
@@ -113,7 +113,7 @@ class WPBackItUp_Job_Task {
|
|
113 |
* @return array|bool
|
114 |
*/
|
115 |
public static function get_job_tasks($job_id,$status_list){
|
116 |
-
|
117 |
|
118 |
//get all the queued and active
|
119 |
$db = new WPBackItUp_DataAccess();
|
@@ -137,13 +137,13 @@ class WPBackItUp_Job_Task {
|
|
137 |
*
|
138 |
*/
|
139 |
private function save(){
|
140 |
-
|
141 |
|
142 |
$db = new WPBackItUp_DataAccess();
|
143 |
$task_updated = $db->update_task($this);
|
144 |
|
145 |
if (! $task_updated){
|
146 |
-
|
147 |
}
|
148 |
|
149 |
$this->set_properties($db->get_task_by_id($this->task_id));
|
@@ -159,16 +159,16 @@ class WPBackItUp_Job_Task {
|
|
159 |
* @return bool
|
160 |
*/
|
161 |
public function try_allocate_task(){
|
162 |
-
|
163 |
|
164 |
$db = new WPBackItUp_DataAccess();
|
165 |
$allocated_task = $db->allocate_task($this->task_id);
|
166 |
if (true===$allocated_task){
|
167 |
$this->setStatus( WPBackItUp_Job_Task::ACTIVE);
|
168 |
-
|
169 |
return true;
|
170 |
}else{
|
171 |
-
|
172 |
return false;
|
173 |
}
|
174 |
|
@@ -182,7 +182,7 @@ class WPBackItUp_Job_Task {
|
|
182 |
* Increment the task retry count
|
183 |
*/
|
184 |
public function increment_retry_count(){
|
185 |
-
|
186 |
$this->retry_count++;
|
187 |
|
188 |
return $this->save();
|
@@ -198,7 +198,7 @@ class WPBackItUp_Job_Task {
|
|
198 |
* @return mixed
|
199 |
*/
|
200 |
public function setStatus($status,$error=null){
|
201 |
-
|
202 |
$this->status=$status;
|
203 |
|
204 |
$now = current_time('mysql');
|
38 |
|
39 |
} catch(Exception $e) {
|
40 |
error_log($e);
|
41 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .$e);
|
42 |
}
|
43 |
}
|
44 |
|
90 |
* @return bool|WPBackItUp_Job_Task
|
91 |
*/
|
92 |
public static function get_task_by_id($task_id){
|
93 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin');
|
94 |
|
95 |
$db = new WPBackItUp_DataAccess();
|
96 |
$task = $db->get_task_by_id($task_id);
|
97 |
if (false===$task){
|
98 |
+
WPBackItUp_Logger::log_error(self::DEFAULT_LOG_NAME,__METHOD__,'Task not found:'. $task_id);
|
99 |
return false;
|
100 |
}
|
101 |
|
113 |
* @return array|bool
|
114 |
*/
|
115 |
public static function get_job_tasks($job_id,$status_list){
|
116 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin');
|
117 |
|
118 |
//get all the queued and active
|
119 |
$db = new WPBackItUp_DataAccess();
|
137 |
*
|
138 |
*/
|
139 |
private function save(){
|
140 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
141 |
|
142 |
$db = new WPBackItUp_DataAccess();
|
143 |
$task_updated = $db->update_task($this);
|
144 |
|
145 |
if (! $task_updated){
|
146 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Task was not updated:' .var_export($this,true));
|
147 |
}
|
148 |
|
149 |
$this->set_properties($db->get_task_by_id($this->task_id));
|
159 |
* @return bool
|
160 |
*/
|
161 |
public function try_allocate_task(){
|
162 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
163 |
|
164 |
$db = new WPBackItUp_DataAccess();
|
165 |
$allocated_task = $db->allocate_task($this->task_id);
|
166 |
if (true===$allocated_task){
|
167 |
$this->setStatus( WPBackItUp_Job_Task::ACTIVE);
|
168 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End - Task allocated');
|
169 |
return true;
|
170 |
}else{
|
171 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End - Task was not allocated');
|
172 |
return false;
|
173 |
}
|
174 |
|
182 |
* Increment the task retry count
|
183 |
*/
|
184 |
public function increment_retry_count(){
|
185 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
186 |
$this->retry_count++;
|
187 |
|
188 |
return $this->save();
|
198 |
* @return mixed
|
199 |
*/
|
200 |
public function setStatus($status,$error=null){
|
201 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
202 |
$this->status=$status;
|
203 |
|
204 |
$now = current_time('mysql');
|
lib/includes/class-job.php
CHANGED
@@ -120,19 +120,17 @@ class WPBackItUp_Job {
|
|
120 |
|
121 |
} catch(Exception $e) {
|
122 |
error_log($e); //Log to debug
|
123 |
-
|
124 |
}
|
125 |
}
|
126 |
|
127 |
function __destruct() {
|
128 |
-
WPBackItUp_LoggerV2::log_info($this->log_name,__METHOD__,'Begin');
|
129 |
|
130 |
//Release lock
|
131 |
if (true===$this->locked){
|
132 |
$this->release_lock();
|
133 |
}
|
134 |
|
135 |
-
WPBackItUp_LoggerV2::log_info($this->log_name,__METHOD__,'End');
|
136 |
}
|
137 |
|
138 |
private function set_properties($db_job){
|
@@ -173,24 +171,24 @@ class WPBackItUp_Job {
|
|
173 |
*
|
174 |
*/
|
175 |
public function get_lock ($lock_name){
|
176 |
-
|
177 |
|
178 |
try {
|
179 |
$lock_file_path = WPBACKITUP__PLUGIN_PATH .'/logs';
|
180 |
$this->mutex = new WPBackItUp_Mutex($lock_name,$lock_file_path);
|
181 |
if ($this->mutex->lock(false)) {
|
182 |
-
|
183 |
$this->locked=true;
|
184 |
} else {
|
185 |
//This is not an error, just means another process has it allocated
|
186 |
-
|
187 |
$this->locked=false;
|
188 |
}
|
189 |
|
190 |
return $this->locked;
|
191 |
|
192 |
} catch(Exception $e) {
|
193 |
-
|
194 |
$this->locked=false;
|
195 |
return $this->locked;
|
196 |
}
|
@@ -202,19 +200,19 @@ class WPBackItUp_Job {
|
|
202 |
* @return bool
|
203 |
*/
|
204 |
public function release_lock (){
|
205 |
-
|
206 |
|
207 |
try{
|
208 |
-
|
209 |
if (null!=$this->mutex) {
|
210 |
$this->mutex->releaseLock();
|
211 |
$this->mutex = null;
|
212 |
}
|
213 |
|
214 |
-
|
215 |
$this->locked=false;
|
216 |
}catch(Exception $e) {
|
217 |
-
|
218 |
}
|
219 |
}
|
220 |
|
@@ -226,10 +224,10 @@ class WPBackItUp_Job {
|
|
226 |
* @return bool
|
227 |
*/
|
228 |
public function is_job_complete() {
|
229 |
-
|
230 |
|
231 |
$error_tasks = WPBackItUp_Job_Task::get_job_tasks($this->job_id,array(WPBackItUp_Job::ERROR));
|
232 |
-
|
233 |
if (count($error_tasks)>0) {
|
234 |
$this->setStatus(WPBackItUp_Job::ERROR);
|
235 |
return false;
|
@@ -237,7 +235,7 @@ class WPBackItUp_Job {
|
|
237 |
|
238 |
//get all the queued, active
|
239 |
$queues_active_tasks = WPBackItUp_Job_Task::get_job_tasks($this->job_id,array(WPBackItUp_Job::ACTIVE, WPBackItUp_Job::QUEUED));
|
240 |
-
|
241 |
if (count($queues_active_tasks)>0) {
|
242 |
return false;
|
243 |
}
|
@@ -254,7 +252,7 @@ class WPBackItUp_Job {
|
|
254 |
* @return bool|object False on try again, task object on success
|
255 |
*/
|
256 |
public function get_next_task(){
|
257 |
-
|
258 |
|
259 |
//get all the queued, active. error tasks
|
260 |
$tasks = WPBackItUp_Job_Task::get_job_tasks($this->job_id,array(WPBackItUp_Job::ACTIVE, WPBackItUp_Job::QUEUED,WPBackItUp_Job::ERROR));
|
@@ -292,7 +290,7 @@ class WPBackItUp_Job {
|
|
292 |
|
293 |
}else {
|
294 |
|
295 |
-
|
296 |
//if its been less than 3 minutes then wait
|
297 |
return false;
|
298 |
}
|
@@ -309,7 +307,7 @@ class WPBackItUp_Job {
|
|
309 |
//If no more tasks then job must be done
|
310 |
$this->setStatus(WPBackItUp_Job::COMPLETE);
|
311 |
|
312 |
-
|
313 |
return false; //no tasks to allocate now but job should be complete next time
|
314 |
}
|
315 |
|
@@ -324,7 +322,7 @@ class WPBackItUp_Job {
|
|
324 |
* @return bool
|
325 |
*/
|
326 |
public function setJobMetaValue($meta_name,$meta_value){
|
327 |
-
|
328 |
|
329 |
$this->job_meta[$meta_name]=$meta_value;
|
330 |
|
@@ -340,11 +338,11 @@ class WPBackItUp_Job {
|
|
340 |
* @return bool true on success/false on error
|
341 |
*/
|
342 |
public function setStatus( $status ) {
|
343 |
-
|
344 |
|
345 |
$db= new WPBackItUp_DataAccess();
|
346 |
if (! $db->update_job_status($this->job_id,$status)) {
|
347 |
-
|
348 |
return false;
|
349 |
}
|
350 |
|
@@ -368,7 +366,7 @@ class WPBackItUp_Job {
|
|
368 |
}
|
369 |
|
370 |
|
371 |
-
|
372 |
return true;
|
373 |
|
374 |
}
|
@@ -380,7 +378,7 @@ class WPBackItUp_Job {
|
|
380 |
* @return bool
|
381 |
*/
|
382 |
private function setJobStartTime() {
|
383 |
-
|
384 |
|
385 |
if($this->job_start_time == null) {
|
386 |
$job_start_time= current_time('mysql');
|
@@ -388,10 +386,10 @@ class WPBackItUp_Job {
|
|
388 |
$db = new WPBackItUp_DataAccess();
|
389 |
if ($db->update_job_start_time($this->job_id,$job_start_time)){
|
390 |
$this->job_start_time= $job_start_time;
|
391 |
-
|
392 |
return true;
|
393 |
} else{
|
394 |
-
|
395 |
return false;
|
396 |
}
|
397 |
}
|
@@ -404,18 +402,18 @@ class WPBackItUp_Job {
|
|
404 |
* @return bool
|
405 |
*/
|
406 |
private function setJobEndTime() {
|
407 |
-
|
408 |
|
409 |
if($this->job_end_time == null) {
|
410 |
$job_end_time = current_time('mysql');
|
411 |
$db = new WPBackItUp_DataAccess();
|
412 |
|
413 |
if ( $db->update_job_end_time( $this->job_id, $job_end_time ) ) {
|
414 |
-
|
415 |
$this->job_end_time = $job_end_time;
|
416 |
return true;
|
417 |
} else {
|
418 |
-
|
419 |
return false;
|
420 |
}
|
421 |
}
|
@@ -506,21 +504,21 @@ class WPBackItUp_Job {
|
|
506 |
* @return bool|job
|
507 |
*/
|
508 |
public static function is_job_queued_active($job_type) {
|
509 |
-
|
510 |
|
511 |
|
512 |
$jobs = WPBackItUp_Job::get_jobs_by_status($job_type,array(WPBackItUp_Job::QUEUED,WPBackItUp_Job::ACTIVE));
|
513 |
-
|
514 |
|
515 |
if (is_array($jobs) && count($jobs)>0) {
|
516 |
//if more than one get first one in stack
|
517 |
$job=current($jobs);
|
518 |
-
|
519 |
return $job;
|
520 |
}
|
521 |
|
522 |
-
|
523 |
-
|
524 |
return false;
|
525 |
}
|
526 |
|
@@ -531,16 +529,16 @@ class WPBackItUp_Job {
|
|
531 |
* @return bool
|
532 |
*/
|
533 |
public static function is_any_job_queued_active() {
|
534 |
-
|
535 |
|
536 |
$db = new WPBackItUp_DataAccess();
|
537 |
|
538 |
$queued_active_job_count = $db->get_queued_active_job_count(array(WPBackItUp_Job::BACKUP,WPBackItUp_Job::RESTORE,WPBackItUp_Job::CLEANUP));
|
539 |
-
|
540 |
|
541 |
if ($queued_active_job_count>0) return true;
|
542 |
|
543 |
-
|
544 |
return false;
|
545 |
}
|
546 |
|
@@ -553,11 +551,11 @@ class WPBackItUp_Job {
|
|
553 |
* @return bool
|
554 |
*/
|
555 |
public static function get_finished_jobs_by_type($job_type) {
|
556 |
-
|
557 |
|
558 |
$db= new WPBackItUp_DataAccess();
|
559 |
$jobs=$db->get_jobs_by_status($job_type,array(WPBackItUp_Job::COMPLETE,WPBackItUp_Job::CANCELLED,WPBackItUp_Job::ERROR, WPBackItUp_Job::DELETED));
|
560 |
-
|
561 |
|
562 |
return count( $jobs ) > 0 ? $jobs : false;
|
563 |
}
|
@@ -570,7 +568,7 @@ class WPBackItUp_Job {
|
|
570 |
* @return int Count of jobs cancelled
|
571 |
*/
|
572 |
public static function cancel_all_jobs($job_type) {
|
573 |
-
|
574 |
|
575 |
$counter=0;
|
576 |
$jobs=self::get_jobs_by_status($job_type,array(WPBackItUp_Job::QUEUED,WPBackItUp_Job::ACTIVE));
|
@@ -578,11 +576,11 @@ class WPBackItUp_Job {
|
|
578 |
foreach($jobs as $job){
|
579 |
$counter++;
|
580 |
$job->setStatus(WPBackItUp_Job::CANCELLED);
|
581 |
-
|
582 |
}
|
583 |
}
|
584 |
|
585 |
-
|
586 |
return $counter;
|
587 |
}
|
588 |
|
@@ -598,18 +596,18 @@ class WPBackItUp_Job {
|
|
598 |
|
599 |
//delete items
|
600 |
$items_deleted = $db->delete_job_items($job_id);
|
601 |
-
|
602 |
|
603 |
|
604 |
//delete tasks
|
605 |
$tasks_deleted = $db->delete_job_tasks($job_id);
|
606 |
-
|
607 |
|
608 |
//delete job
|
609 |
$jobs_deleted = $db->delete_job_by_id($job_id);
|
610 |
-
|
611 |
|
612 |
-
|
613 |
|
614 |
}
|
615 |
|
@@ -625,7 +623,7 @@ class WPBackItUp_Job {
|
|
625 |
*/
|
626 |
public static function purge_jobs($job_type,$dont_purge=5) {
|
627 |
$log_name='debug_purge_jobs';
|
628 |
-
|
629 |
|
630 |
$jobs_purged=0;
|
631 |
|
@@ -634,7 +632,7 @@ class WPBackItUp_Job {
|
|
634 |
/*------------------------------------------------------*/
|
635 |
|
636 |
$jobs = self::get_jobs_by_status($job_type,array(WPBackItUp_Job::DELETED,WPBackItUp_Job::ERROR,WPBackItUp_Job::CANCELLED));
|
637 |
-
|
638 |
|
639 |
/* Delete everything but the successfully completed jobs */
|
640 |
if (is_array($jobs) && count($jobs)>0) {
|
@@ -644,8 +642,8 @@ class WPBackItUp_Job {
|
|
644 |
self::delete_job_records($job->getJobId());
|
645 |
$jobs_purged+=1;
|
646 |
|
647 |
-
|
648 |
-
|
649 |
}
|
650 |
}
|
651 |
|
@@ -655,12 +653,12 @@ class WPBackItUp_Job {
|
|
655 |
|
656 |
if (WPBackItUp_Job::BACKUP==$job_type) {
|
657 |
$jobs = self::get_jobs_by_status($job_type,array(WPBackItUp_Job::COMPLETE));
|
658 |
-
|
659 |
|
660 |
/* Check all remaining to make sure there is a backup folder associated with each */
|
661 |
if (is_array($jobs) && count($jobs)>0) {
|
662 |
foreach ($jobs as $key=>$job){
|
663 |
-
|
664 |
|
665 |
$backups_exist = false;
|
666 |
|
@@ -679,13 +677,13 @@ class WPBackItUp_Job {
|
|
679 |
|
680 |
//Delete the job control if backups dont exist
|
681 |
if (false===$backups_exist) {
|
682 |
-
|
683 |
|
684 |
self::delete_job_records($job->getJobId());
|
685 |
$jobs_purged+=1;
|
686 |
|
687 |
-
|
688 |
-
|
689 |
}
|
690 |
}
|
691 |
}
|
@@ -695,7 +693,7 @@ class WPBackItUp_Job {
|
|
695 |
//Now purge the ones that exceed the retention limit
|
696 |
/*------------------------------------------------------*/
|
697 |
$jobs = self::get_jobs_by_status($job_type,array(WPBackItUp_Job::COMPLETE));
|
698 |
-
|
699 |
|
700 |
if (is_array($jobs) && count($jobs)>0) {
|
701 |
|
@@ -708,22 +706,22 @@ class WPBackItUp_Job {
|
|
708 |
}
|
709 |
|
710 |
$purge_count=count($purge_jobs);
|
711 |
-
|
712 |
if ($purge_count>0){
|
713 |
-
|
714 |
foreach ($purge_jobs as $key=>$job){
|
715 |
|
716 |
self::delete_job_records($job->getJobId());
|
717 |
$jobs_purged+=1;
|
718 |
|
719 |
-
|
720 |
-
|
721 |
}
|
722 |
}
|
723 |
|
724 |
}
|
725 |
|
726 |
-
|
727 |
|
728 |
return $jobs_purged;
|
729 |
}
|
@@ -737,18 +735,18 @@ class WPBackItUp_Job {
|
|
737 |
* @return bool|WPBackItUp_Job
|
738 |
*/
|
739 |
public static function get_job_by_id($job_id) {
|
740 |
-
|
741 |
|
742 |
$db = new WPBackItUp_DataAccess();
|
743 |
$job = $db->get_job_by_id($job_id);
|
744 |
|
745 |
if (null!=$job) {
|
746 |
-
|
747 |
return new WPBackItUp_Job($job);
|
748 |
}
|
749 |
|
750 |
-
|
751 |
-
|
752 |
return false;
|
753 |
}
|
754 |
|
@@ -763,11 +761,11 @@ class WPBackItUp_Job {
|
|
763 |
* @return mixed Array of jobs or false when no jobs found
|
764 |
*/
|
765 |
public static function get_jobs_by_status($job_type,$job_status, $limit=100) {
|
766 |
-
|
767 |
|
768 |
$db = new WPBackItUp_DataAccess();
|
769 |
$job_rows = $db->get_jobs_by_status($job_type,$job_status,$limit);
|
770 |
-
|
771 |
|
772 |
if (false===$job_rows) return false;
|
773 |
|
@@ -776,7 +774,7 @@ class WPBackItUp_Job {
|
|
776 |
$jobs_list[] = new WPBackItUp_Job($row);
|
777 |
}
|
778 |
|
779 |
-
|
780 |
return count( $jobs_list ) > 0 ? $jobs_list : false;
|
781 |
}
|
782 |
|
@@ -790,18 +788,18 @@ class WPBackItUp_Job {
|
|
790 |
* @return array|bool Returns jobs or false when none found
|
791 |
*/
|
792 |
public static function get_jobs_by_job_name($job_type,$job_name, $job_status=null) {
|
793 |
-
|
794 |
|
795 |
$db = new WPBackItUp_DataAccess();
|
796 |
$db_jobs = $db->get_jobs_by_name($job_type,$job_name, $job_status);
|
797 |
-
|
798 |
|
799 |
$job_list = array();
|
800 |
foreach ($db_jobs as $key => $row) {
|
801 |
$job_list[] = new WPBackItUp_Job($row);
|
802 |
}
|
803 |
|
804 |
-
|
805 |
return count( $job_list ) > 0 ? $job_list : false;
|
806 |
}
|
807 |
|
@@ -818,23 +816,23 @@ class WPBackItUp_Job {
|
|
818 |
* @return bool|WPBackItUp_Job
|
819 |
*/
|
820 |
public static function queue_job($job_name, $job_id,$job_type,$job_run_type,$tasks){
|
821 |
-
|
822 |
|
823 |
$db = new WPBackItUp_DataAccess();
|
824 |
if (! $db->create_job($job_id,$job_type,$job_run_type,$job_name,self::QUEUED)){
|
825 |
-
|
826 |
return false;
|
827 |
}
|
828 |
-
|
829 |
|
830 |
//add the tasks
|
831 |
if ( false === self::create_tasks( $job_id,$tasks ) ) {
|
832 |
-
|
833 |
$db->update_job_status($job_id,WPBackItUp_Job::DELETED);
|
834 |
return false;
|
835 |
}
|
836 |
|
837 |
-
|
838 |
return self::get_job_by_id($job_id);
|
839 |
}
|
840 |
|
@@ -848,15 +846,15 @@ class WPBackItUp_Job {
|
|
848 |
* @return bool|WPBackItUp_Job false on failure/Job on success
|
849 |
*/
|
850 |
public static function import_completed_job($job_name, $job_id,$job_type){
|
851 |
-
|
852 |
|
853 |
$db= new WPBackItUp_DataAccess();
|
854 |
if (false=== $db->create_job($job_id,WPBackItUp_Job::BACKUP,WPBackItUp_Job::IMPORTED,$job_name,WPBackItUp_Job::COMPLETE)){
|
855 |
-
|
856 |
return false;
|
857 |
}
|
858 |
|
859 |
-
|
860 |
return self::get_job_by_id($job_id);
|
861 |
}
|
862 |
|
@@ -870,7 +868,7 @@ class WPBackItUp_Job {
|
|
870 |
* @return bool
|
871 |
*/
|
872 |
private static function create_tasks($job_id, $tasks){
|
873 |
-
|
874 |
|
875 |
$db = new WPBackItUp_DataAccess();
|
876 |
|
@@ -879,13 +877,13 @@ class WPBackItUp_Job {
|
|
879 |
|
880 |
$task_created = $db->create_task($job_id,$task_name);
|
881 |
if (false===$task_created){
|
882 |
-
|
883 |
return false;
|
884 |
}
|
885 |
-
|
886 |
}
|
887 |
|
888 |
-
|
889 |
return true;
|
890 |
|
891 |
}
|
120 |
|
121 |
} catch(Exception $e) {
|
122 |
error_log($e); //Log to debug
|
123 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .$e);
|
124 |
}
|
125 |
}
|
126 |
|
127 |
function __destruct() {
|
|
|
128 |
|
129 |
//Release lock
|
130 |
if (true===$this->locked){
|
131 |
$this->release_lock();
|
132 |
}
|
133 |
|
|
|
134 |
}
|
135 |
|
136 |
private function set_properties($db_job){
|
171 |
*
|
172 |
*/
|
173 |
public function get_lock ($lock_name){
|
174 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin:'.$lock_name);
|
175 |
|
176 |
try {
|
177 |
$lock_file_path = WPBACKITUP__PLUGIN_PATH .'/logs';
|
178 |
$this->mutex = new WPBackItUp_Mutex($lock_name,$lock_file_path);
|
179 |
if ($this->mutex->lock(false)) {
|
180 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Process LOCK acquired');
|
181 |
$this->locked=true;
|
182 |
} else {
|
183 |
//This is not an error, just means another process has it allocated
|
184 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Process LOCK Failed');
|
185 |
$this->locked=false;
|
186 |
}
|
187 |
|
188 |
return $this->locked;
|
189 |
|
190 |
} catch(Exception $e) {
|
191 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Process Lock error: ' .$e);
|
192 |
$this->locked=false;
|
193 |
return $this->locked;
|
194 |
}
|
200 |
* @return bool
|
201 |
*/
|
202 |
public function release_lock (){
|
203 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
204 |
|
205 |
try{
|
206 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Mutex:'.var_export($this->mutex,true));
|
207 |
if (null!=$this->mutex) {
|
208 |
$this->mutex->releaseLock();
|
209 |
$this->mutex = null;
|
210 |
}
|
211 |
|
212 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Lock released');
|
213 |
$this->locked=false;
|
214 |
}catch(Exception $e) {
|
215 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Process UNLOCK error: ' .$e);
|
216 |
}
|
217 |
}
|
218 |
|
224 |
* @return bool
|
225 |
*/
|
226 |
public function is_job_complete() {
|
227 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin' );
|
228 |
|
229 |
$error_tasks = WPBackItUp_Job_Task::get_job_tasks($this->job_id,array(WPBackItUp_Job::ERROR));
|
230 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Active or Queued Tasks found' .count($error_tasks) );
|
231 |
if (count($error_tasks)>0) {
|
232 |
$this->setStatus(WPBackItUp_Job::ERROR);
|
233 |
return false;
|
235 |
|
236 |
//get all the queued, active
|
237 |
$queues_active_tasks = WPBackItUp_Job_Task::get_job_tasks($this->job_id,array(WPBackItUp_Job::ACTIVE, WPBackItUp_Job::QUEUED));
|
238 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Active or Queued Tasks found' .count($queues_active_tasks) );
|
239 |
if (count($queues_active_tasks)>0) {
|
240 |
return false;
|
241 |
}
|
252 |
* @return bool|object False on try again, task object on success
|
253 |
*/
|
254 |
public function get_next_task(){
|
255 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
256 |
|
257 |
//get all the queued, active. error tasks
|
258 |
$tasks = WPBackItUp_Job_Task::get_job_tasks($this->job_id,array(WPBackItUp_Job::ACTIVE, WPBackItUp_Job::QUEUED,WPBackItUp_Job::ERROR));
|
290 |
|
291 |
}else {
|
292 |
|
293 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Job:' .$task->getJobId() .'-' . $task->getTaskName() . ' is still active' );
|
294 |
//if its been less than 3 minutes then wait
|
295 |
return false;
|
296 |
}
|
307 |
//If no more tasks then job must be done
|
308 |
$this->setStatus(WPBackItUp_Job::COMPLETE);
|
309 |
|
310 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End - no tasks to allocate');
|
311 |
return false; //no tasks to allocate now but job should be complete next time
|
312 |
}
|
313 |
|
322 |
* @return bool
|
323 |
*/
|
324 |
public function setJobMetaValue($meta_name,$meta_value){
|
325 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin - Update job meta:' .$this->job_id .'-'. $meta_name);
|
326 |
|
327 |
$this->job_meta[$meta_name]=$meta_value;
|
328 |
|
338 |
* @return bool true on success/false on error
|
339 |
*/
|
340 |
public function setStatus( $status ) {
|
341 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
342 |
|
343 |
$db= new WPBackItUp_DataAccess();
|
344 |
if (! $db->update_job_status($this->job_id,$status)) {
|
345 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'End - Job status NOT set.');
|
346 |
return false;
|
347 |
}
|
348 |
|
366 |
}
|
367 |
|
368 |
|
369 |
+
WPBackItUp_Logger::log_info( $this->log_name, __METHOD__, 'End - Backup Job status set to:' . $this->job_id . '-' . $status );
|
370 |
return true;
|
371 |
|
372 |
}
|
378 |
* @return bool
|
379 |
*/
|
380 |
private function setJobStartTime() {
|
381 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
382 |
|
383 |
if($this->job_start_time == null) {
|
384 |
$job_start_time= current_time('mysql');
|
386 |
$db = new WPBackItUp_DataAccess();
|
387 |
if ($db->update_job_start_time($this->job_id,$job_start_time)){
|
388 |
$this->job_start_time= $job_start_time;
|
389 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'End - Backup Job start time set');
|
390 |
return true;
|
391 |
} else{
|
392 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'End - Backup Job start time NOT set.');
|
393 |
return false;
|
394 |
}
|
395 |
}
|
402 |
* @return bool
|
403 |
*/
|
404 |
private function setJobEndTime() {
|
405 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
406 |
|
407 |
if($this->job_end_time == null) {
|
408 |
$job_end_time = current_time('mysql');
|
409 |
$db = new WPBackItUp_DataAccess();
|
410 |
|
411 |
if ( $db->update_job_end_time( $this->job_id, $job_end_time ) ) {
|
412 |
+
WPBackItUp_Logger::log_info( $this->log_name, __METHOD__, 'End - Backup Job end time set' );
|
413 |
$this->job_end_time = $job_end_time;
|
414 |
return true;
|
415 |
} else {
|
416 |
+
WPBackItUp_Logger::log_error( $this->log_name, __METHOD__, 'End - Backup Job end time NOT set.' );
|
417 |
return false;
|
418 |
}
|
419 |
}
|
504 |
* @return bool|job
|
505 |
*/
|
506 |
public static function is_job_queued_active($job_type) {
|
507 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin - Check Job Queue:' . $job_type);
|
508 |
|
509 |
|
510 |
$jobs = WPBackItUp_Job::get_jobs_by_status($job_type,array(WPBackItUp_Job::QUEUED,WPBackItUp_Job::ACTIVE));
|
511 |
+
WPBackItUp_Logger::log(self::DEFAULT_LOG_NAME,$jobs);
|
512 |
|
513 |
if (is_array($jobs) && count($jobs)>0) {
|
514 |
//if more than one get first one in stack
|
515 |
$job=current($jobs);
|
516 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Jobs found:' . count($jobs) );
|
517 |
return $job;
|
518 |
}
|
519 |
|
520 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'No jobs found:' . $job_type);
|
521 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'End');
|
522 |
return false;
|
523 |
}
|
524 |
|
529 |
* @return bool
|
530 |
*/
|
531 |
public static function is_any_job_queued_active() {
|
532 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin - Check Job Queue');
|
533 |
|
534 |
$db = new WPBackItUp_DataAccess();
|
535 |
|
536 |
$queued_active_job_count = $db->get_queued_active_job_count(array(WPBackItUp_Job::BACKUP,WPBackItUp_Job::RESTORE,WPBackItUp_Job::CLEANUP));
|
537 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Jobs found:' . $queued_active_job_count );
|
538 |
|
539 |
if ($queued_active_job_count>0) return true;
|
540 |
|
541 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'End');
|
542 |
return false;
|
543 |
}
|
544 |
|
551 |
* @return bool
|
552 |
*/
|
553 |
public static function get_finished_jobs_by_type($job_type) {
|
554 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin');
|
555 |
|
556 |
$db= new WPBackItUp_DataAccess();
|
557 |
$jobs=$db->get_jobs_by_status($job_type,array(WPBackItUp_Job::COMPLETE,WPBackItUp_Job::CANCELLED,WPBackItUp_Job::ERROR, WPBackItUp_Job::DELETED));
|
558 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Jobs found:' . count($jobs));
|
559 |
|
560 |
return count( $jobs ) > 0 ? $jobs : false;
|
561 |
}
|
568 |
* @return int Count of jobs cancelled
|
569 |
*/
|
570 |
public static function cancel_all_jobs($job_type) {
|
571 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin - Cancel all jobs:'.$job_type);
|
572 |
|
573 |
$counter=0;
|
574 |
$jobs=self::get_jobs_by_status($job_type,array(WPBackItUp_Job::QUEUED,WPBackItUp_Job::ACTIVE));
|
576 |
foreach($jobs as $job){
|
577 |
$counter++;
|
578 |
$job->setStatus(WPBackItUp_Job::CANCELLED);
|
579 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Job Cancelled:' . $job->getJobId());
|
580 |
}
|
581 |
}
|
582 |
|
583 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'End - Jobs cancelled:' .$counter);
|
584 |
return $counter;
|
585 |
}
|
586 |
|
596 |
|
597 |
//delete items
|
598 |
$items_deleted = $db->delete_job_items($job_id);
|
599 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Deleted items:'.$items_deleted);
|
600 |
|
601 |
|
602 |
//delete tasks
|
603 |
$tasks_deleted = $db->delete_job_tasks($job_id);
|
604 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Deleted Tasks:'.$tasks_deleted);
|
605 |
|
606 |
//delete job
|
607 |
$jobs_deleted = $db->delete_job_by_id($job_id);
|
608 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Deleted Jobs:'.$jobs_deleted);
|
609 |
|
610 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Deleted Job:' .$job_id);
|
611 |
|
612 |
}
|
613 |
|
623 |
*/
|
624 |
public static function purge_jobs($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 |
|
628 |
$jobs_purged=0;
|
629 |
|
632 |
/*------------------------------------------------------*/
|
633 |
|
634 |
$jobs = self::get_jobs_by_status($job_type,array(WPBackItUp_Job::DELETED,WPBackItUp_Job::ERROR,WPBackItUp_Job::CANCELLED));
|
635 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Total finished jobs found:' .count($jobs));
|
636 |
|
637 |
/* Delete everything but the successfully completed jobs */
|
638 |
if (is_array($jobs) && count($jobs)>0) {
|
642 |
self::delete_job_records($job->getJobId());
|
643 |
$jobs_purged+=1;
|
644 |
|
645 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Deleted Job:');
|
646 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,var_export($job,true));
|
647 |
}
|
648 |
}
|
649 |
|
653 |
|
654 |
if (WPBackItUp_Job::BACKUP==$job_type) {
|
655 |
$jobs = self::get_jobs_by_status($job_type,array(WPBackItUp_Job::COMPLETE));
|
656 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Total finished jobs found:' .count($jobs));
|
657 |
|
658 |
/* Check all remaining to make sure there is a backup folder associated with each */
|
659 |
if (is_array($jobs) && count($jobs)>0) {
|
660 |
foreach ($jobs as $key=>$job){
|
661 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,var_export($job,true));
|
662 |
|
663 |
$backups_exist = false;
|
664 |
|
677 |
|
678 |
//Delete the job control if backups dont exist
|
679 |
if (false===$backups_exist) {
|
680 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'No backups found for job:'. $job->getJobId());
|
681 |
|
682 |
self::delete_job_records($job->getJobId());
|
683 |
$jobs_purged+=1;
|
684 |
|
685 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Backups Missing - Deleted Job:');
|
686 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,var_export($job,true));
|
687 |
}
|
688 |
}
|
689 |
}
|
693 |
//Now purge the ones that exceed the retention limit
|
694 |
/*------------------------------------------------------*/
|
695 |
$jobs = self::get_jobs_by_status($job_type,array(WPBackItUp_Job::COMPLETE));
|
696 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Remaining Jobs After File Check:' .count($jobs));
|
697 |
|
698 |
if (is_array($jobs) && count($jobs)>0) {
|
699 |
|
706 |
}
|
707 |
|
708 |
$purge_count=count($purge_jobs);
|
709 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Jobs to be purged:' .$purge_count);
|
710 |
if ($purge_count>0){
|
711 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,var_export($jobs,true));
|
712 |
foreach ($purge_jobs as $key=>$job){
|
713 |
|
714 |
self::delete_job_records($job->getJobId());
|
715 |
$jobs_purged+=1;
|
716 |
|
717 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Deleted Job:');
|
718 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,var_export($job,true));
|
719 |
}
|
720 |
}
|
721 |
|
722 |
}
|
723 |
|
724 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'End - job purge complete. Jobs Purged:' .$jobs_purged);
|
725 |
|
726 |
return $jobs_purged;
|
727 |
}
|
735 |
* @return bool|WPBackItUp_Job
|
736 |
*/
|
737 |
public static function get_job_by_id($job_id) {
|
738 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin');
|
739 |
|
740 |
$db = new WPBackItUp_DataAccess();
|
741 |
$job = $db->get_job_by_id($job_id);
|
742 |
|
743 |
if (null!=$job) {
|
744 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Job found:' . var_export($job,true));
|
745 |
return new WPBackItUp_Job($job);
|
746 |
}
|
747 |
|
748 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'No job found with id.' . $job_id);
|
749 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'End');
|
750 |
return false;
|
751 |
}
|
752 |
|
761 |
* @return mixed Array of jobs or false when no jobs found
|
762 |
*/
|
763 |
public static function get_jobs_by_status($job_type,$job_status, $limit=100) {
|
764 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin');
|
765 |
|
766 |
$db = new WPBackItUp_DataAccess();
|
767 |
$job_rows = $db->get_jobs_by_status($job_type,$job_status,$limit);
|
768 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Jobs found:' . count($job_rows));
|
769 |
|
770 |
if (false===$job_rows) return false;
|
771 |
|
774 |
$jobs_list[] = new WPBackItUp_Job($row);
|
775 |
}
|
776 |
|
777 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'End');
|
778 |
return count( $jobs_list ) > 0 ? $jobs_list : false;
|
779 |
}
|
780 |
|
788 |
* @return array|bool Returns jobs or false when none found
|
789 |
*/
|
790 |
public static function get_jobs_by_job_name($job_type,$job_name, $job_status=null) {
|
791 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,sprintf('Begin:%s-%s',$job_type,$job_name));
|
792 |
|
793 |
$db = new WPBackItUp_DataAccess();
|
794 |
$db_jobs = $db->get_jobs_by_name($job_type,$job_name, $job_status);
|
795 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,sprintf('Job Ids:%s',var_export($db_jobs,true)));
|
796 |
|
797 |
$job_list = array();
|
798 |
foreach ($db_jobs as $key => $row) {
|
799 |
$job_list[] = new WPBackItUp_Job($row);
|
800 |
}
|
801 |
|
802 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'End');
|
803 |
return count( $job_list ) > 0 ? $job_list : false;
|
804 |
}
|
805 |
|
816 |
* @return bool|WPBackItUp_Job
|
817 |
*/
|
818 |
public static function queue_job($job_name, $job_id,$job_type,$job_run_type,$tasks){
|
819 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin - Job:'. $job_type);
|
820 |
|
821 |
$db = new WPBackItUp_DataAccess();
|
822 |
if (! $db->create_job($job_id,$job_type,$job_run_type,$job_name,self::QUEUED)){
|
823 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Job was not created:' . $job_id );
|
824 |
return false;
|
825 |
}
|
826 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Job Created:' .$job_id);
|
827 |
|
828 |
//add the tasks
|
829 |
if ( false === self::create_tasks( $job_id,$tasks ) ) {
|
830 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Job tasks not Created - deleting job:' . $job_id );
|
831 |
$db->update_job_status($job_id,WPBackItUp_Job::DELETED);
|
832 |
return false;
|
833 |
}
|
834 |
|
835 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'End');
|
836 |
return self::get_job_by_id($job_id);
|
837 |
}
|
838 |
|
846 |
* @return bool|WPBackItUp_Job false on failure/Job on success
|
847 |
*/
|
848 |
public static function import_completed_job($job_name, $job_id,$job_type){
|
849 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin - Job:'. $job_type);
|
850 |
|
851 |
$db= new WPBackItUp_DataAccess();
|
852 |
if (false=== $db->create_job($job_id,WPBackItUp_Job::BACKUP,WPBackItUp_Job::IMPORTED,$job_name,WPBackItUp_Job::COMPLETE)){
|
853 |
+
WPBackItUp_Logger::log_error(self::DEFAULT_LOG_NAME,__METHOD__,'Job NOT Created:' .$job_id);
|
854 |
return false;
|
855 |
}
|
856 |
|
857 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Job Created successfully:' .$job_id);
|
858 |
return self::get_job_by_id($job_id);
|
859 |
}
|
860 |
|
868 |
* @return bool
|
869 |
*/
|
870 |
private static function create_tasks($job_id, $tasks){
|
871 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'Begin');
|
872 |
|
873 |
$db = new WPBackItUp_DataAccess();
|
874 |
|
877 |
|
878 |
$task_created = $db->create_task($job_id,$task_name);
|
879 |
if (false===$task_created){
|
880 |
+
WPBackItUp_Logger::log_error(self::DEFAULT_LOG_NAME,__METHOD__,'Tasks NOT created');
|
881 |
return false;
|
882 |
}
|
883 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'task created:' . $task_created .':'. $task_name);
|
884 |
}
|
885 |
|
886 |
+
WPBackItUp_Logger::log_info(self::DEFAULT_LOG_NAME,__METHOD__,'End');
|
887 |
return true;
|
888 |
|
889 |
}
|
lib/includes/class-license.php
CHANGED
@@ -49,7 +49,7 @@ class WPBackItUp_License {
|
|
49 |
|
50 |
|
51 |
} catch ( Exception $e ) {
|
52 |
-
|
53 |
throw $e;
|
54 |
}
|
55 |
|
@@ -288,7 +288,7 @@ class WPBackItUp_License {
|
|
288 |
|
289 |
//if false try using site directly
|
290 |
if ( false === $license_data) {
|
291 |
-
|
292 |
$license_data= $this->edd_license_api_request(WPBACKITUP__SECURESITE_URL,'activate_license', $request_data);
|
293 |
}
|
294 |
|
@@ -317,7 +317,7 @@ class WPBackItUp_License {
|
|
317 |
|
318 |
//if false try using site directly
|
319 |
if ( false === $license_data) {
|
320 |
-
|
321 |
$license_data= $this->edd_license_api_request(WPBACKITUP__SECURESITE_URL,'activate_license', $request_data);
|
322 |
}
|
323 |
|
@@ -346,7 +346,7 @@ class WPBackItUp_License {
|
|
346 |
|
347 |
//if false try using site directly
|
348 |
if ( false === $license_data) {
|
349 |
-
|
350 |
$license_data= $this->edd_license_api_request(WPBACKITUP__SECURESITE_URL,'activate_license', $request_data);
|
351 |
}
|
352 |
|
@@ -399,7 +399,7 @@ class WPBackItUp_License {
|
|
399 |
delete_transient( 'wpbackitup_admin_notices' );
|
400 |
|
401 |
$activation_logname='debug_activation';
|
402 |
-
|
403 |
|
404 |
$license=trim($license);
|
405 |
|
@@ -533,7 +533,7 @@ class WPBackItUp_License {
|
|
533 |
)
|
534 |
);
|
535 |
|
536 |
-
|
537 |
}
|
538 |
|
539 |
if ( ( $license_data->error == 'no_activations_left' ) ) {
|
@@ -553,10 +553,10 @@ class WPBackItUp_License {
|
|
553 |
}
|
554 |
}
|
555 |
|
556 |
-
|
557 |
foreach($data as $key => $val ) {
|
558 |
WPBackItUp_Utility::set_option($key, $val);
|
559 |
-
|
560 |
}
|
561 |
return true;
|
562 |
}
|
@@ -570,9 +570,9 @@ class WPBackItUp_License {
|
|
570 |
} else {
|
571 |
$post_url = WPBACKITUP__SITE_URL . $post_url;
|
572 |
}
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
|
577 |
$response = wp_remote_post( $post_url, array(
|
578 |
'method' => 'POST',
|
@@ -586,13 +586,13 @@ class WPBackItUp_License {
|
|
586 |
|
587 |
if ( is_wp_error( $response ) ) {
|
588 |
$error_message = $response->get_error_message();
|
589 |
-
|
590 |
|
591 |
return false;
|
592 |
|
593 |
} else {
|
594 |
-
|
595 |
-
|
596 |
|
597 |
return true;
|
598 |
}
|
@@ -619,9 +619,9 @@ class WPBackItUp_License {
|
|
619 |
'url' => $request_data['url']
|
620 |
);
|
621 |
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
|
626 |
$response = wp_remote_get(
|
627 |
add_query_arg( $api_params, $activation_url ),
|
@@ -629,11 +629,11 @@ class WPBackItUp_License {
|
|
629 |
'sslverify' => false
|
630 |
)
|
631 |
);
|
632 |
-
|
633 |
|
634 |
|
635 |
$response_code = wp_remote_retrieve_response_code($response);
|
636 |
-
|
637 |
|
638 |
//IF no error
|
639 |
if ( !is_wp_error( $response ) && 200 == $response_code ) {
|
@@ -645,11 +645,11 @@ class WPBackItUp_License {
|
|
645 |
return $response;
|
646 |
|
647 |
} else { //Error
|
648 |
-
|
649 |
-
|
650 |
|
651 |
-
|
652 |
-
|
653 |
|
654 |
return false;
|
655 |
}
|
49 |
|
50 |
|
51 |
} catch ( Exception $e ) {
|
52 |
+
WPBackItUp_Logger::log_error( $this->log_name, __METHOD__, 'Constructor Exception: ' . $e );
|
53 |
throw $e;
|
54 |
}
|
55 |
|
288 |
|
289 |
//if false try using site directly
|
290 |
if ( false === $license_data) {
|
291 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__, 'Unable to activate using Gateway - attemtping direct');
|
292 |
$license_data= $this->edd_license_api_request(WPBACKITUP__SECURESITE_URL,'activate_license', $request_data);
|
293 |
}
|
294 |
|
317 |
|
318 |
//if false try using site directly
|
319 |
if ( false === $license_data) {
|
320 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__, 'Unable to activate using Gateway - attempting direct');
|
321 |
$license_data= $this->edd_license_api_request(WPBACKITUP__SECURESITE_URL,'activate_license', $request_data);
|
322 |
}
|
323 |
|
346 |
|
347 |
//if false try using site directly
|
348 |
if ( false === $license_data) {
|
349 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__, 'Unable to activate using Gateway - attempting direct');
|
350 |
$license_data= $this->edd_license_api_request(WPBACKITUP__SECURESITE_URL,'activate_license', $request_data);
|
351 |
}
|
352 |
|
399 |
delete_transient( 'wpbackitup_admin_notices' );
|
400 |
|
401 |
$activation_logname='debug_activation';
|
402 |
+
WPBackItUp_Logger::log_info($activation_logname,__METHOD__, 'Update License Options:' .$license);
|
403 |
|
404 |
$license=trim($license);
|
405 |
|
533 |
)
|
534 |
);
|
535 |
|
536 |
+
WPBackItUp_Logger::log_info($activation_logname,__METHOD__, 'Expire License.' );
|
537 |
}
|
538 |
|
539 |
if ( ( $license_data->error == 'no_activations_left' ) ) {
|
553 |
}
|
554 |
}
|
555 |
|
556 |
+
WPBackItUp_Logger::log_info($activation_logname,__METHOD__, 'Updating License Options');
|
557 |
foreach($data as $key => $val ) {
|
558 |
WPBackItUp_Utility::set_option($key, $val);
|
559 |
+
WPBackItUp_Logger::log_info($activation_logname,__METHOD__, 'Updated Option: ' .$key .':' .$val);
|
560 |
}
|
561 |
return true;
|
562 |
}
|
570 |
} else {
|
571 |
$post_url = WPBACKITUP__SITE_URL . $post_url;
|
572 |
}
|
573 |
+
WPBackItUp_Logger::log_info($registration_logname,__METHOD__, 'Lite User Registration Post URL: ' . $post_url );
|
574 |
+
WPBackItUp_Logger::log_info($registration_logname,__METHOD__, 'Lite User Registration Post Form Data: ' );
|
575 |
+
WPBackItUp_Logger::log($registration_logname,$form_data );
|
576 |
|
577 |
$response = wp_remote_post( $post_url, array(
|
578 |
'method' => 'POST',
|
586 |
|
587 |
if ( is_wp_error( $response ) ) {
|
588 |
$error_message = $response->get_error_message();
|
589 |
+
WPBackItUp_Logger::log_error($registration_logname,__METHOD__, 'Lite User Registration Error: ' . $error_message );
|
590 |
|
591 |
return false;
|
592 |
|
593 |
} else {
|
594 |
+
WPBackItUp_Logger::log_info($registration_logname,__METHOD__, 'Lite User Registered Successfully:' );
|
595 |
+
WPBackItUp_Logger::log($registration_logname,$response );
|
596 |
|
597 |
return true;
|
598 |
}
|
619 |
'url' => $request_data['url']
|
620 |
);
|
621 |
|
622 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__, 'Activate License Request Info:');
|
623 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'API URL:' .$activation_url);
|
624 |
+
WPBackItUp_Logger::log($this->log_name,$api_params);
|
625 |
|
626 |
$response = wp_remote_get(
|
627 |
add_query_arg( $api_params, $activation_url ),
|
629 |
'sslverify' => false
|
630 |
)
|
631 |
);
|
632 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__, 'API Response:'. var_export( $response,true ));
|
633 |
|
634 |
|
635 |
$response_code = wp_remote_retrieve_response_code($response);
|
636 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__, 'Response Code:'. $response_code);
|
637 |
|
638 |
//IF no error
|
639 |
if ( !is_wp_error( $response ) && 200 == $response_code ) {
|
645 |
return $response;
|
646 |
|
647 |
} else { //Error
|
648 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__, 'Requesting Server Name:'. $_SERVER['SERVER_NAME']);
|
649 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__, 'Requesting IP:'. $_SERVER['SERVER_ADDR']);
|
650 |
|
651 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__, 'Validation Response:');
|
652 |
+
WPBackItUp_Logger::log($this->log_name,var_export($response,true));
|
653 |
|
654 |
return false;
|
655 |
}
|
lib/includes/class-logger.php
CHANGED
@@ -1,5 +1,13 @@
|
|
1 |
<?php if (!defined ('ABSPATH')) die('No direct access allowed (logger)');
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
/**
|
4 |
* WP BackItUp - Logger System Class
|
5 |
*
|
@@ -11,253 +19,325 @@
|
|
11 |
|
12 |
class WPBackItUp_Logger {
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
$path = WPBACKITUP__PLUGIN_PATH .'/logs';
|
31 |
}
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
40 |
}
|
|
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
try {
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
unlink($this->logFilePath);
|
52 |
-
}
|
53 |
-
|
54 |
-
$this->dfh = fopen($this->logFilePath, 'a');
|
55 |
-
fwrite($this->dfh, "** Open LOG File ** ". PHP_EOL);
|
56 |
-
}
|
57 |
} catch(Exception $e) {
|
58 |
-
|
59 |
-
error_log($e);
|
60 |
}
|
61 |
-
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
} catch(Exception $e) {
|
74 |
-
|
75 |
-
print $e;
|
76 |
}
|
77 |
-
|
78 |
-
$this->dfh=null;
|
79 |
}
|
80 |
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
try{
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
$date='';
|
88 |
-
if ($datestamp) $date = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
|
89 |
-
|
90 |
-
if( is_array( $message ) || is_object( $message ) ){
|
91 |
-
fwrite($this->dfh, $date ." " .print_r( $message, true ) . PHP_EOL);
|
92 |
-
} else {
|
93 |
-
fwrite($this->dfh, $date ." " .$message . PHP_EOL);
|
94 |
-
}
|
95 |
-
}
|
96 |
}
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
100 |
}
|
101 |
}
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
}
|
112 |
}
|
113 |
|
114 |
-
//Log Errors
|
115 |
-
public function log_error($function,$message,$additional_message=null) {
|
116 |
-
$function='(' . $function . ') ERROR: ' . $additional_message;
|
117 |
-
if( is_array( $message ) || is_object( $message ) ){
|
118 |
-
$this->log($function);
|
119 |
-
$this->log($message);
|
120 |
-
} else {
|
121 |
-
$this->log($function .$message);
|
122 |
-
}
|
123 |
-
}
|
124 |
|
125 |
-
|
126 |
-
public function log_warning($function,$message,$additional_message=null) {
|
127 |
-
$function='(' . $function . ') WARNING: ' . $additional_message;
|
128 |
-
if( is_array( $message ) || is_object( $message ) ){
|
129 |
-
$this->log($function);
|
130 |
-
$this->log($message);
|
131 |
-
} else {
|
132 |
-
$this->log($function .$message);
|
133 |
-
}
|
134 |
-
}
|
135 |
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
try{
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
foreach (get_defined_constants() as $key=>$value)
|
149 |
-
{
|
150 |
-
if (substr($key,0,strlen($prefix))==$prefix) {
|
151 |
-
$this->log($key . ':' . $value);
|
152 |
-
}
|
153 |
-
}
|
154 |
-
|
155 |
-
$this->log("\n--Site Info--");
|
156 |
-
$this->log('Site URL:' . site_url());
|
157 |
-
$this->log('Home URL:' . home_url());
|
158 |
-
$this->log('Multisite:' . ( is_multisite() ? 'Yes' : 'No' )) ;
|
159 |
-
|
160 |
-
$this->log("\n--Wordpress Info--");
|
161 |
-
$this->log("Wordpress Version:" . get_bloginfo( 'version'));
|
162 |
-
$this->log('Language:' . ( defined( 'WPLANG' ) && WPLANG ? WPLANG : 'en_US' ));
|
163 |
-
$this->log('DB_HOST:' . DB_HOST);
|
164 |
-
$this->log('Table Prefix:' . 'Length: ' . strlen( $wpdb->prefix ) . ' Status: ' . ( strlen( $wpdb->prefix ) > 16 ? 'ERROR: Too long' : 'Acceptable' ));
|
165 |
-
$this->log('WP_DEBUG:' . ( defined( 'WP_DEBUG' ) ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set' ));
|
166 |
-
$this->log('Memory Limit:' . WP_MEMORY_LIMIT );
|
167 |
-
|
168 |
-
$this->log("\n--WordPress Active Plugins--");
|
169 |
-
// Check if get_plugins() function exists. This is required on the front end of the
|
170 |
-
// site, since it is in a file that is normally only loaded in the admin.
|
171 |
-
if ( ! function_exists( 'get_plugins' ) ) {
|
172 |
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
173 |
-
}
|
174 |
-
|
175 |
-
$plugins = get_plugins();
|
176 |
-
$active_plugins = get_option( 'active_plugins', array() );
|
177 |
-
foreach( $plugins as $plugin_path => $plugin ) {
|
178 |
-
if( !in_array( $plugin_path, $active_plugins ) ) continue;
|
179 |
-
|
180 |
-
$this->log( $plugin['Name'] . ': ' . $plugin['Version']);
|
181 |
-
}
|
182 |
-
|
183 |
-
// WordPress inactive plugins
|
184 |
-
$this->log("\n" . '--WordPress Inactive Plugins--');
|
185 |
-
|
186 |
-
foreach( $plugins as $plugin_path => $plugin ) {
|
187 |
-
if( in_array( $plugin_path, $active_plugins ) )
|
188 |
-
continue;
|
189 |
-
|
190 |
-
$this->log($plugin['Name'] . ': ' . $plugin['Version']);
|
191 |
-
}
|
192 |
-
|
193 |
-
$this->log("\n--Server Info--");
|
194 |
-
$this->log('PHP Version:' . PHP_VERSION);
|
195 |
-
$this->log('Webserver Info:' . $_SERVER['SERVER_SOFTWARE']);
|
196 |
-
$this->log('MySQL Version:' . $wpdb->db_version());
|
197 |
-
|
198 |
-
$this->log("\n--PHP Info--");
|
199 |
-
$this->log("PHP Info:" . phpversion());
|
200 |
-
$this->log("Operating System:" . php_uname());
|
201 |
-
|
202 |
-
if ( @ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'on' ){
|
203 |
-
$this->log("PHP Safe Mode: On");
|
204 |
-
} else{
|
205 |
-
$this->log("PHP Safe Mode: Off");
|
206 |
-
}
|
207 |
-
|
208 |
-
if ( @ini_get('sql.safe_mode') || strtolower(@ini_get('sql.safe_mode')) == 'on' ){
|
209 |
-
$this->log("SQL Safe Mode: On");
|
210 |
-
} else{
|
211 |
-
$this->log("SQL Safe Mode: Off");
|
212 |
-
}
|
213 |
-
$this->log("Script Max Execution Time:" . ini_get('max_execution_time'));
|
214 |
-
$this->log('Memory Limit:' . ini_get( 'memory_limit' ));
|
215 |
-
$this->log('Upload Max Size:' . ini_get( 'upload_max_filesize' ));
|
216 |
-
$this->log('Post Max Size:' . ini_get( 'post_max_size' ));
|
217 |
-
$this->log('Upload Max Filesize:' . ini_get( 'upload_max_filesize' ));
|
218 |
-
$this->log('Max Input Vars:' . ini_get( 'max_input_vars' ));
|
219 |
-
$this->log('Display Errors:' . ( ini_get( 'display_errors' ) ? 'On (' . ini_get( 'display_errors' ) . ')' : 'N/A' ));
|
220 |
-
$this->log('Curl Installed:' . (function_exists('curl_version') ?'True' : 'False'));
|
221 |
-
|
222 |
-
$this->log("\n**END SYSTEM INFO**");
|
223 |
-
}
|
224 |
-
} catch(Exception $e) {
|
225 |
-
//Dont do anything
|
226 |
-
print $e;
|
227 |
}
|
228 |
}
|
229 |
|
230 |
-
function log_memory_info(){
|
231 |
-
try{
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
-
|
238 |
-
|
239 |
-
$this->log('Peak usage: ' . $memory_peak_usage . ' ('. $memory_peak_usage/1024/1024 .' Mb)');
|
240 |
-
$this->log('Memory limit: ' . $memory_limit . ' ('. $memory_limit/1024/1024 .' Mb)');
|
241 |
-
$this->log("\n**END MEMORY USAGE INFO**");
|
242 |
-
} catch(Exception $e) {
|
243 |
-
//Dont do anything
|
244 |
-
//print $e;
|
245 |
}
|
246 |
}
|
247 |
|
248 |
/**
|
249 |
-
*
|
250 |
-
*
|
|
|
|
|
|
|
251 |
*/
|
252 |
-
public function
|
253 |
-
|
254 |
-
|
|
|
|
|
|
|
255 |
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
*/
|
260 |
-
public function getLogFilePath() {
|
261 |
-
return $this->logFilePath;
|
262 |
}
|
263 |
}
|
1 |
<?php if (!defined ('ABSPATH')) die('No direct access allowed (logger)');
|
2 |
|
3 |
+
if( !class_exists( 'Logger' ) ) {
|
4 |
+
require_once( WPBACKITUP__PLUGIN_PATH .'/vendor/KLogger/Logger.php' );
|
5 |
+
}
|
6 |
+
|
7 |
+
if( !class_exists( 'LogLevel' ) ) {
|
8 |
+
require_once( WPBACKITUP__PLUGIN_PATH .'/vendor/KLogger/LogLevel.php' );
|
9 |
+
}
|
10 |
+
|
11 |
/**
|
12 |
* WP BackItUp - Logger System Class
|
13 |
*
|
19 |
|
20 |
class WPBackItUp_Logger {
|
21 |
|
22 |
+
/**
|
23 |
+
* logger
|
24 |
+
* @var mixed
|
25 |
+
*/
|
26 |
+
private static $logger;
|
27 |
|
28 |
+
/**
|
29 |
+
* Write messages to the log
|
30 |
+
*
|
31 |
+
* @param $log_name Log Name
|
32 |
+
* @param $message Log Message (Array or object)
|
33 |
+
*/
|
34 |
+
public static function log($log_name,$message) {
|
35 |
+
try {
|
36 |
+
if(self::is_logging() === true) {
|
37 |
+
$logger = self::getLogger($log_name);
|
38 |
+
$logger->log(LogLevel::DEBUG, $message);
|
39 |
+
}
|
40 |
+
}catch(Exception $e) {
|
41 |
+
error_log( $e );
|
42 |
+
}
|
43 |
+
}
|
44 |
|
45 |
+
/**
|
46 |
+
* Write informational messages to the log
|
47 |
+
*
|
48 |
+
* @param $log_name Log Name
|
49 |
+
* @param $function Name of calling function(__METHOD__)
|
50 |
+
* @param $message Log Message (Array or object)
|
51 |
+
* @param null $additional_message (string)
|
52 |
+
*/
|
53 |
+
public static function log_info($log_name, $function, $message, $additional_message = null ) {
|
54 |
|
55 |
+
try {
|
56 |
+
if(self::is_logging() === true) {
|
57 |
+
$logger = self::getLogger($log_name);
|
58 |
+
$logger->log_info($function, $message, $additional_message);
|
59 |
+
}
|
60 |
|
61 |
+
}catch(Exception $e) {
|
62 |
+
error_log( $e );
|
|
|
63 |
}
|
64 |
+
}
|
65 |
|
66 |
+
/**
|
67 |
+
* Write error messages to the log
|
68 |
+
*
|
69 |
+
* @param $log_name Log Name
|
70 |
+
* @param $function Name of calling function(__METHOD__)
|
71 |
+
* @param $message Log Message (Array or object)
|
72 |
+
* @param null $additional_message (string)
|
73 |
+
*/
|
74 |
+
public static function log_error($log_name, $function,$message,$additional_message=null) {
|
75 |
|
76 |
+
try {
|
77 |
+
if(self::is_logging() === true) {
|
78 |
+
$logger = self::getLogger($log_name);
|
79 |
+
$logger->log_error($function, $message, $additional_message);
|
80 |
+
}
|
81 |
+
}catch(Exception $e) {
|
82 |
+
error_log( $e );
|
83 |
}
|
84 |
+
}
|
85 |
|
86 |
+
/**
|
87 |
+
* Write warning messages to the log
|
88 |
+
*
|
89 |
+
* @param $log_name Log Name
|
90 |
+
* @param $function Name of calling function(__METHOD__)
|
91 |
+
* @param $message Log Message (Array or object)
|
92 |
+
* @param null $additional_message (string)
|
93 |
+
*/
|
94 |
+
public static function log_warning($log_name, $function,$message,$additional_message=null) {
|
95 |
|
96 |
try {
|
97 |
+
if(self::is_logging() === true) {
|
98 |
+
$logger = self::getLogger($log_name);
|
99 |
+
$logger->log_warning($function, $message, $additional_message);
|
100 |
+
}
|
101 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
} catch(Exception $e) {
|
103 |
+
error_log( $e );
|
|
|
104 |
}
|
105 |
+
}
|
106 |
|
107 |
+
/**
|
108 |
+
* Write system information to the log
|
109 |
+
*
|
110 |
+
* @param $log_name
|
111 |
+
*
|
112 |
+
*/
|
113 |
+
public static function log_sysinfo($log_name) {
|
114 |
+
global $wpdb;
|
115 |
+
|
116 |
+
try{
|
117 |
+
if(self::is_logging() === true) {
|
118 |
+
$wpbackitup_license = new WPBackItUp_License();
|
119 |
+
|
120 |
+
// get the logger
|
121 |
+
$logger = self::getLogger($log_name);
|
122 |
+
|
123 |
+
$logger->log(LogLevel::DEBUG, "\n**SYSTEM INFO**");
|
124 |
+
|
125 |
+
$logger->log(LogLevel::DEBUG, "\n--WPBackItUp Info--");
|
126 |
+
|
127 |
+
$logger->log(LogLevel::DEBUG, "WPBACKITUP License Active: " . ($wpbackitup_license->is_license_active() ? 'true' : 'false'));
|
128 |
+
$prefix = 'WPBACKITUP';
|
129 |
+
foreach (get_defined_constants() as $key => $value) {
|
130 |
+
if (substr($key, 0, strlen($prefix)) == $prefix) {
|
131 |
+
$logger->log(LogLevel::DEBUG, $key . ':' . $value);
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
$logger->log(LogLevel::DEBUG, "\n--Site Info--");
|
136 |
+
$logger->log(LogLevel::DEBUG, 'Site URL:' . site_url());
|
137 |
+
$logger->log(LogLevel::DEBUG, 'Home URL:' . home_url());
|
138 |
+
$logger->log(LogLevel::DEBUG, 'Multisite:' . (is_multisite() ? 'Yes' : 'No'));
|
139 |
+
|
140 |
+
$logger->log(LogLevel::DEBUG, "\n--Wordpress Info--");
|
141 |
+
$logger->log(LogLevel::DEBUG, "Wordpress Version:" . get_bloginfo('version'));
|
142 |
+
$logger->log(LogLevel::DEBUG, 'Language:' . (defined('WPLANG') && WPLANG ? WPLANG : 'en_US'));
|
143 |
+
$logger->log(LogLevel::DEBUG, 'DB_HOST:' . DB_HOST);
|
144 |
+
$logger->log(LogLevel::DEBUG, 'Table Prefix:' . 'Length: ' . strlen($wpdb->prefix) . ' Status: ' . (strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable'));
|
145 |
+
$logger->log(LogLevel::DEBUG, 'WP_DEBUG:' . (defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set'));
|
146 |
+
$logger->log(LogLevel::DEBUG, 'Memory Limit:' . WP_MEMORY_LIMIT);
|
147 |
+
|
148 |
+
$logger->log(LogLevel::DEBUG, "\n--WordPress Active Plugins--");
|
149 |
+
// Check if get_plugins() function exists. This is required on the front end of the
|
150 |
+
// site, since it is in a file that is normally only loaded in the admin.
|
151 |
+
if (!function_exists('get_plugins')) {
|
152 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
153 |
+
}
|
154 |
+
|
155 |
+
$plugins = get_plugins();
|
156 |
+
$active_plugins = get_option('active_plugins', array());
|
157 |
+
foreach ($plugins as $plugin_path => $plugin) {
|
158 |
+
if (!in_array($plugin_path, $active_plugins)) continue;
|
159 |
+
|
160 |
+
$logger->log(LogLevel::DEBUG, $plugin['Name'] . ': ' . $plugin['Version']);
|
161 |
+
}
|
162 |
+
|
163 |
+
// WordPress inactive plugins
|
164 |
+
$logger->log(LogLevel::DEBUG, "\n" . '--WordPress Inactive Plugins--');
|
165 |
+
|
166 |
+
foreach ($plugins as $plugin_path => $plugin) {
|
167 |
+
if (in_array($plugin_path, $active_plugins))
|
168 |
+
continue;
|
169 |
+
|
170 |
+
$logger->log(LogLevel::DEBUG, $plugin['Name'] . ': ' . $plugin['Version']);
|
171 |
+
}
|
172 |
+
|
173 |
+
$logger->log(LogLevel::DEBUG, "\n--Server Info--");
|
174 |
+
$logger->log(LogLevel::DEBUG, 'PHP Version:' . PHP_VERSION);
|
175 |
+
$logger->log(LogLevel::DEBUG, 'Webserver Info:' . $_SERVER['SERVER_SOFTWARE']);
|
176 |
+
$logger->log(LogLevel::DEBUG, 'MySQL Version:' . $wpdb->db_version());
|
177 |
+
|
178 |
+
$logger->log(LogLevel::DEBUG, "\n--PHP Info--");
|
179 |
+
$logger->log(LogLevel::DEBUG, "PHP Info:" . phpversion());
|
180 |
+
$logger->log(LogLevel::DEBUG, "Operating System:" . php_uname());
|
181 |
+
|
182 |
+
if (@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'on') {
|
183 |
+
$logger->log(LogLevel::DEBUG, "PHP Safe Mode: On");
|
184 |
+
} else {
|
185 |
+
$logger->log(LogLevel::DEBUG, "PHP Safe Mode: Off");
|
186 |
+
}
|
187 |
+
|
188 |
+
if (@ini_get('sql.safe_mode') || strtolower(@ini_get('sql.safe_mode')) == 'on') {
|
189 |
+
$logger->log(LogLevel::DEBUG, "SQL Safe Mode: On");
|
190 |
+
} else {
|
191 |
+
$logger->log(LogLevel::DEBUG, "SQL Safe Mode: Off");
|
192 |
+
}
|
193 |
+
$logger->log(LogLevel::DEBUG, "Script Max Execution Time:" . ini_get('max_execution_time'));
|
194 |
+
$logger->log(LogLevel::DEBUG, 'Memory Limit:' . ini_get('memory_limit'));
|
195 |
+
$logger->log(LogLevel::DEBUG, 'Upload Max Size:' . ini_get('upload_max_filesize'));
|
196 |
+
$logger->log(LogLevel::DEBUG, 'Post Max Size:' . ini_get('post_max_size'));
|
197 |
+
$logger->log(LogLevel::DEBUG, 'Upload Max Filesize:' . ini_get('upload_max_filesize'));
|
198 |
+
$logger->log(LogLevel::DEBUG, 'Max Input Vars:' . ini_get('max_input_vars'));
|
199 |
+
$logger->log(LogLevel::DEBUG, 'Display Errors:' . (ini_get('display_errors') ? 'On (' . ini_get('display_errors') . ')' : 'N/A'));
|
200 |
+
$logger->log(LogLevel::DEBUG, 'Curl Installed:' . (function_exists('curl_version') ? 'True' : 'False'));
|
201 |
+
|
202 |
+
$logger->log(LogLevel::DEBUG, "\n**END SYSTEM INFO**");
|
203 |
+
}
|
204 |
+
} catch(Exception $e) {
|
205 |
+
error_log($e);
|
206 |
+
}
|
207 |
+
}
|
208 |
|
209 |
+
/**
|
210 |
+
* Write memory information to the log.
|
211 |
+
*
|
212 |
+
* @param $log_name
|
213 |
+
*
|
214 |
+
*/
|
215 |
+
private static function log_memory_info($log_name){
|
216 |
+
try{
|
217 |
+
if(self::is_logging() === true) {
|
218 |
+
$memory_usage = memory_get_usage();
|
219 |
+
$memory_peak_usage = memory_get_peak_usage();
|
220 |
+
$memory_limit = ini_get('memory_limit');
|
221 |
+
|
222 |
+
// get the logger
|
223 |
+
$logger = self::getLogger($log_name);
|
224 |
+
|
225 |
+
$logger->log(LogLevel::DEBUG, "\n**MEMORY USAGE INFO**");
|
226 |
+
$logger->log(LogLevel::DEBUG, 'Memory in use: ' . $memory_usage . ' (' . $memory_usage / 1024 / 1024 . ' Mb)');
|
227 |
+
$logger->log(LogLevel::DEBUG, 'Peak usage: ' . $memory_peak_usage . ' (' . $memory_peak_usage / 1024 / 1024 . ' Mb)');
|
228 |
+
$logger->log(LogLevel::DEBUG, 'Memory limit: ' . $memory_limit . ' (' . $memory_limit / 1024 / 1024 . ' Mb)');
|
229 |
+
$logger->log(LogLevel::DEBUG, "\n**END MEMORY USAGE INFO**");
|
230 |
}
|
231 |
} catch(Exception $e) {
|
232 |
+
error_log($e);
|
|
|
233 |
}
|
|
|
|
|
234 |
}
|
235 |
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Get Logger instance
|
239 |
+
*
|
240 |
+
* @param $log_name
|
241 |
+
* @param $log_level
|
242 |
+
*
|
243 |
+
* @return mixed
|
244 |
+
*/
|
245 |
+
private static function getLogger($log_name, $log_level = LogLevel::DEBUG) {
|
246 |
+
$path = WPBACKITUP__PLUGIN_PATH .'/logs';
|
247 |
+
|
248 |
+
$options = array (
|
249 |
+
'extension' => 'log',
|
250 |
+
'dateFormat' => 'Y-m-d G:i:s.u',
|
251 |
+
'filename' => $log_name,
|
252 |
+
'flushFrequency' => false,
|
253 |
+
'prefix' => 'log_',
|
254 |
+
'logFormat' => false,
|
255 |
+
'appendContext' => true,
|
256 |
+
);
|
257 |
+
|
258 |
try{
|
259 |
+
|
260 |
+
if (! isset( self::$logger[$log_name])) {
|
261 |
+
self::$logger[$log_name] = $logger = new Logger($path, $log_level, $options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
}
|
263 |
+
|
264 |
+
return self::$logger[$log_name];
|
265 |
+
|
266 |
+
}catch(Exception $e) {
|
267 |
+
error_log( $e );
|
268 |
}
|
269 |
}
|
270 |
|
271 |
+
/**
|
272 |
+
* Check if logging is enabled or not
|
273 |
+
*
|
274 |
+
* @return boolean
|
275 |
+
*/
|
276 |
+
private static function is_logging(){
|
277 |
+
global $WPBackitup;
|
278 |
+
return $WPBackitup->logging();
|
|
|
279 |
}
|
280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
|
282 |
+
/** PUBLIC METHODS **/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
|
284 |
+
/**
|
285 |
+
* close Log file name
|
286 |
+
*
|
287 |
+
* @param $log_name
|
288 |
+
*
|
289 |
+
* @return mixed
|
290 |
+
*/
|
291 |
+
public static function close($log_name) {
|
292 |
try{
|
293 |
+
if(self::is_logging() === true) {
|
294 |
+
$logger = self::getLogger($log_name);
|
295 |
+
$logger->close();
|
296 |
+
self::$logger[$log_name] = null;
|
297 |
+
unset(self::$logger[$log_name]);
|
298 |
+
}
|
299 |
+
|
300 |
+
}catch(Exception $e) {
|
301 |
+
error_log( $e );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
}
|
303 |
}
|
304 |
|
|
|
|
|
305 |
|
306 |
+
/**
|
307 |
+
* Get Log file name
|
308 |
+
*
|
309 |
+
* @param $log_name
|
310 |
+
*
|
311 |
+
* @return mixed
|
312 |
+
*/
|
313 |
+
public static function getLogFileName($log_name) {
|
314 |
+
try{
|
315 |
+
if(self::is_logging() === true) {
|
316 |
+
$logger = self::getLogger($log_name);
|
317 |
+
return $logger->getLogFileName();
|
318 |
+
}
|
319 |
|
320 |
+
}catch(Exception $e) {
|
321 |
+
error_log( $e );
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
}
|
323 |
}
|
324 |
|
325 |
/**
|
326 |
+
* Get Logger instance
|
327 |
+
*
|
328 |
+
* @param $log_name
|
329 |
+
*
|
330 |
+
* @return mixed
|
331 |
*/
|
332 |
+
public static function getLogFilePath($log_name) {
|
333 |
+
try{
|
334 |
+
if(self::is_logging() === true) {
|
335 |
+
$logger = self::getLogger($log_name);
|
336 |
+
return $logger->getLogFilePath();
|
337 |
+
}
|
338 |
|
339 |
+
}catch(Exception $e) {
|
340 |
+
error_log( $e );
|
341 |
+
}
|
|
|
|
|
|
|
342 |
}
|
343 |
}
|
lib/includes/class-loggerV2.php
CHANGED
@@ -1,5 +1,13 @@
|
|
1 |
<?php if (!defined ('ABSPATH')) die('No direct access allowed (logger)');
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
/**
|
4 |
* WP BackItUp - Logger System Class V2
|
5 |
*
|
@@ -11,6 +19,10 @@
|
|
11 |
|
12 |
class WPBackItUp_LoggerV2 {
|
13 |
|
|
|
|
|
|
|
|
|
14 |
private static $logger;
|
15 |
|
16 |
/**
|
@@ -18,14 +30,13 @@ class WPBackItUp_LoggerV2 {
|
|
18 |
*
|
19 |
* @param $log_name Log Name
|
20 |
* @param $message Log Message (Array or object)
|
21 |
-
* @param bool $datestamp add date stamp to every log item
|
22 |
*/
|
23 |
-
public static function log($log_name,$message
|
24 |
try {
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
}catch(Exception $e) {
|
30 |
error_log( $e );
|
31 |
}
|
@@ -42,9 +53,10 @@ class WPBackItUp_LoggerV2 {
|
|
42 |
public static function log_info($log_name, $function, $message, $additional_message = null ) {
|
43 |
|
44 |
try {
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
48 |
|
49 |
}catch(Exception $e) {
|
50 |
error_log( $e );
|
@@ -62,8 +74,10 @@ class WPBackItUp_LoggerV2 {
|
|
62 |
public static function log_error($log_name, $function,$message,$additional_message=null) {
|
63 |
|
64 |
try {
|
65 |
-
|
66 |
-
|
|
|
|
|
67 |
}catch(Exception $e) {
|
68 |
error_log( $e );
|
69 |
}
|
@@ -80,44 +94,171 @@ class WPBackItUp_LoggerV2 {
|
|
80 |
public static function log_warning($log_name, $function,$message,$additional_message=null) {
|
81 |
|
82 |
try {
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
86 |
|
87 |
} catch(Exception $e) {
|
88 |
error_log( $e );
|
89 |
}
|
90 |
}
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
|
109 |
/**
|
110 |
* Get Logger instance
|
111 |
*
|
112 |
* @param $log_name
|
|
|
113 |
*
|
114 |
* @return mixed
|
115 |
*/
|
116 |
-
private static function getLogger($log_name) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
try{
|
118 |
|
119 |
if (! isset( self::$logger[$log_name])) {
|
120 |
-
self::$logger[$log_name] = new
|
121 |
}
|
122 |
|
123 |
return self::$logger[$log_name];
|
@@ -127,6 +268,17 @@ class WPBackItUp_LoggerV2 {
|
|
127 |
}
|
128 |
}
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
/** PUBLIC METHODS **/
|
131 |
|
132 |
/**
|
@@ -138,11 +290,12 @@ class WPBackItUp_LoggerV2 {
|
|
138 |
*/
|
139 |
public static function close($log_name) {
|
140 |
try{
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
146 |
|
147 |
}catch(Exception $e) {
|
148 |
error_log( $e );
|
@@ -159,9 +312,10 @@ class WPBackItUp_LoggerV2 {
|
|
159 |
*/
|
160 |
public static function getLogFileName($log_name) {
|
161 |
try{
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
165 |
|
166 |
}catch(Exception $e) {
|
167 |
error_log( $e );
|
@@ -177,9 +331,10 @@ class WPBackItUp_LoggerV2 {
|
|
177 |
*/
|
178 |
public static function getLogFilePath($log_name) {
|
179 |
try{
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
183 |
|
184 |
}catch(Exception $e) {
|
185 |
error_log( $e );
|
1 |
<?php if (!defined ('ABSPATH')) die('No direct access allowed (logger)');
|
2 |
|
3 |
+
if( !class_exists( 'Logger' ) ) {
|
4 |
+
require_once( WPBACKITUP__PLUGIN_PATH .'/vendor/KLogger/Logger.php' );
|
5 |
+
}
|
6 |
+
|
7 |
+
if( !class_exists( 'LogLevel' ) ) {
|
8 |
+
require_once( WPBACKITUP__PLUGIN_PATH .'/vendor/KLogger/LogLevel.php' );
|
9 |
+
}
|
10 |
+
|
11 |
/**
|
12 |
* WP BackItUp - Logger System Class V2
|
13 |
*
|
19 |
|
20 |
class WPBackItUp_LoggerV2 {
|
21 |
|
22 |
+
/**
|
23 |
+
* logger
|
24 |
+
* @var mixed
|
25 |
+
*/
|
26 |
private static $logger;
|
27 |
|
28 |
/**
|
30 |
*
|
31 |
* @param $log_name Log Name
|
32 |
* @param $message Log Message (Array or object)
|
|
|
33 |
*/
|
34 |
+
public static function log($log_name,$message) {
|
35 |
try {
|
36 |
+
if(self::is_logging() === true) {
|
37 |
+
$logger = self::getLogger($log_name);
|
38 |
+
$logger->log(LogLevel::DEBUG, $message);
|
39 |
+
}
|
40 |
}catch(Exception $e) {
|
41 |
error_log( $e );
|
42 |
}
|
53 |
public static function log_info($log_name, $function, $message, $additional_message = null ) {
|
54 |
|
55 |
try {
|
56 |
+
if(self::is_logging() === true) {
|
57 |
+
$logger = self::getLogger($log_name);
|
58 |
+
$logger->log_info($function, $message, $additional_message);
|
59 |
+
}
|
60 |
|
61 |
}catch(Exception $e) {
|
62 |
error_log( $e );
|
74 |
public static function log_error($log_name, $function,$message,$additional_message=null) {
|
75 |
|
76 |
try {
|
77 |
+
if(self::is_logging() === true) {
|
78 |
+
$logger = self::getLogger($log_name);
|
79 |
+
$logger->log_error($function, $message, $additional_message);
|
80 |
+
}
|
81 |
}catch(Exception $e) {
|
82 |
error_log( $e );
|
83 |
}
|
94 |
public static function log_warning($log_name, $function,$message,$additional_message=null) {
|
95 |
|
96 |
try {
|
97 |
+
if(self::is_logging() === true) {
|
98 |
+
$logger = self::getLogger($log_name);
|
99 |
+
$logger->log_warning($function, $message, $additional_message);
|
100 |
+
}
|
101 |
|
102 |
} catch(Exception $e) {
|
103 |
error_log( $e );
|
104 |
}
|
105 |
}
|
106 |
|
107 |
+
/**
|
108 |
+
* Write system information to the log
|
109 |
+
*
|
110 |
+
* @param $log_name
|
111 |
+
*
|
112 |
+
*/
|
113 |
+
public static function log_sysinfo($log_name) {
|
114 |
+
global $wpdb;
|
115 |
+
|
116 |
+
try{
|
117 |
+
if(self::is_logging() === true) {
|
118 |
+
$wpbackitup_license = new WPBackItUp_License();
|
119 |
+
|
120 |
+
// get the logger
|
121 |
+
$logger = self::getLogger($log_name);
|
122 |
+
|
123 |
+
$logger->log(LogLevel::DEBUG, "\n**SYSTEM INFO**");
|
124 |
+
|
125 |
+
$logger->log(LogLevel::DEBUG, "\n--WPBackItUp Info--");
|
126 |
+
|
127 |
+
$logger->log(LogLevel::DEBUG, "WPBACKITUP License Active: " . ($wpbackitup_license->is_license_active() ? 'true' : 'false'));
|
128 |
+
$prefix = 'WPBACKITUP';
|
129 |
+
foreach (get_defined_constants() as $key => $value) {
|
130 |
+
if (substr($key, 0, strlen($prefix)) == $prefix) {
|
131 |
+
$logger->log(LogLevel::DEBUG, $key . ':' . $value);
|
132 |
+
}
|
133 |
+
}
|
134 |
+
|
135 |
+
$logger->log(LogLevel::DEBUG, "\n--Site Info--");
|
136 |
+
$logger->log(LogLevel::DEBUG, 'Site URL:' . site_url());
|
137 |
+
$logger->log(LogLevel::DEBUG, 'Home URL:' . home_url());
|
138 |
+
$logger->log(LogLevel::DEBUG, 'Multisite:' . (is_multisite() ? 'Yes' : 'No'));
|
139 |
+
|
140 |
+
$logger->log(LogLevel::DEBUG, "\n--Wordpress Info--");
|
141 |
+
$logger->log(LogLevel::DEBUG, "Wordpress Version:" . get_bloginfo('version'));
|
142 |
+
$logger->log(LogLevel::DEBUG, 'Language:' . (defined('WPLANG') && WPLANG ? WPLANG : 'en_US'));
|
143 |
+
$logger->log(LogLevel::DEBUG, 'DB_HOST:' . DB_HOST);
|
144 |
+
$logger->log(LogLevel::DEBUG, 'Table Prefix:' . 'Length: ' . strlen($wpdb->prefix) . ' Status: ' . (strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable'));
|
145 |
+
$logger->log(LogLevel::DEBUG, 'WP_DEBUG:' . (defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set'));
|
146 |
+
$logger->log(LogLevel::DEBUG, 'Memory Limit:' . WP_MEMORY_LIMIT);
|
147 |
+
|
148 |
+
$logger->log(LogLevel::DEBUG, "\n--WordPress Active Plugins--");
|
149 |
+
// Check if get_plugins() function exists. This is required on the front end of the
|
150 |
+
// site, since it is in a file that is normally only loaded in the admin.
|
151 |
+
if (!function_exists('get_plugins')) {
|
152 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
153 |
+
}
|
154 |
+
|
155 |
+
$plugins = get_plugins();
|
156 |
+
$active_plugins = get_option('active_plugins', array());
|
157 |
+
foreach ($plugins as $plugin_path => $plugin) {
|
158 |
+
if (!in_array($plugin_path, $active_plugins)) continue;
|
159 |
+
|
160 |
+
$logger->log(LogLevel::DEBUG, $plugin['Name'] . ': ' . $plugin['Version']);
|
161 |
+
}
|
162 |
+
|
163 |
+
// WordPress inactive plugins
|
164 |
+
$logger->log(LogLevel::DEBUG, "\n" . '--WordPress Inactive Plugins--');
|
165 |
+
|
166 |
+
foreach ($plugins as $plugin_path => $plugin) {
|
167 |
+
if (in_array($plugin_path, $active_plugins))
|
168 |
+
continue;
|
169 |
+
|
170 |
+
$logger->log(LogLevel::DEBUG, $plugin['Name'] . ': ' . $plugin['Version']);
|
171 |
+
}
|
172 |
+
|
173 |
+
$logger->log(LogLevel::DEBUG, "\n--Server Info--");
|
174 |
+
$logger->log(LogLevel::DEBUG, 'PHP Version:' . PHP_VERSION);
|
175 |
+
$logger->log(LogLevel::DEBUG, 'Webserver Info:' . $_SERVER['SERVER_SOFTWARE']);
|
176 |
+
$logger->log(LogLevel::DEBUG, 'MySQL Version:' . $wpdb->db_version());
|
177 |
+
|
178 |
+
$logger->log(LogLevel::DEBUG, "\n--PHP Info--");
|
179 |
+
$logger->log(LogLevel::DEBUG, "PHP Info:" . phpversion());
|
180 |
+
$logger->log(LogLevel::DEBUG, "Operating System:" . php_uname());
|
181 |
+
|
182 |
+
if (@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'on') {
|
183 |
+
$logger->log(LogLevel::DEBUG, "PHP Safe Mode: On");
|
184 |
+
} else {
|
185 |
+
$logger->log(LogLevel::DEBUG, "PHP Safe Mode: Off");
|
186 |
+
}
|
187 |
+
|
188 |
+
if (@ini_get('sql.safe_mode') || strtolower(@ini_get('sql.safe_mode')) == 'on') {
|
189 |
+
$logger->log(LogLevel::DEBUG, "SQL Safe Mode: On");
|
190 |
+
} else {
|
191 |
+
$logger->log(LogLevel::DEBUG, "SQL Safe Mode: Off");
|
192 |
+
}
|
193 |
+
$logger->log(LogLevel::DEBUG, "Script Max Execution Time:" . ini_get('max_execution_time'));
|
194 |
+
$logger->log(LogLevel::DEBUG, 'Memory Limit:' . ini_get('memory_limit'));
|
195 |
+
$logger->log(LogLevel::DEBUG, 'Upload Max Size:' . ini_get('upload_max_filesize'));
|
196 |
+
$logger->log(LogLevel::DEBUG, 'Post Max Size:' . ini_get('post_max_size'));
|
197 |
+
$logger->log(LogLevel::DEBUG, 'Upload Max Filesize:' . ini_get('upload_max_filesize'));
|
198 |
+
$logger->log(LogLevel::DEBUG, 'Max Input Vars:' . ini_get('max_input_vars'));
|
199 |
+
$logger->log(LogLevel::DEBUG, 'Display Errors:' . (ini_get('display_errors') ? 'On (' . ini_get('display_errors') . ')' : 'N/A'));
|
200 |
+
$logger->log(LogLevel::DEBUG, 'Curl Installed:' . (function_exists('curl_version') ? 'True' : 'False'));
|
201 |
+
|
202 |
+
$logger->log(LogLevel::DEBUG, "\n**END SYSTEM INFO**");
|
203 |
+
}
|
204 |
+
} catch(Exception $e) {
|
205 |
+
error_log($e);
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Write memory information to the log.
|
211 |
+
*
|
212 |
+
* @param $log_name
|
213 |
+
*
|
214 |
+
*/
|
215 |
+
private static function log_memory_info($log_name){
|
216 |
+
try{
|
217 |
+
if(self::is_logging() === true) {
|
218 |
+
$memory_usage = memory_get_usage();
|
219 |
+
$memory_peak_usage = memory_get_peak_usage();
|
220 |
+
$memory_limit = ini_get('memory_limit');
|
221 |
+
|
222 |
+
// get the logger
|
223 |
+
$logger = self::getLogger($log_name);
|
224 |
+
|
225 |
+
$logger->log(LogLevel::DEBUG, "\n**MEMORY USAGE INFO**");
|
226 |
+
$logger->log(LogLevel::DEBUG, 'Memory in use: ' . $memory_usage . ' (' . $memory_usage / 1024 / 1024 . ' Mb)');
|
227 |
+
$logger->log(LogLevel::DEBUG, 'Peak usage: ' . $memory_peak_usage . ' (' . $memory_peak_usage / 1024 / 1024 . ' Mb)');
|
228 |
+
$logger->log(LogLevel::DEBUG, 'Memory limit: ' . $memory_limit . ' (' . $memory_limit / 1024 / 1024 . ' Mb)');
|
229 |
+
$logger->log(LogLevel::DEBUG, "\n**END MEMORY USAGE INFO**");
|
230 |
+
}
|
231 |
+
} catch(Exception $e) {
|
232 |
+
error_log($e);
|
233 |
+
}
|
234 |
+
}
|
235 |
|
236 |
|
237 |
/**
|
238 |
* Get Logger instance
|
239 |
*
|
240 |
* @param $log_name
|
241 |
+
* @param $log_level
|
242 |
*
|
243 |
* @return mixed
|
244 |
*/
|
245 |
+
private static function getLogger($log_name, $log_level = LogLevel::DEBUG) {
|
246 |
+
$path = WPBACKITUP__PLUGIN_PATH .'/logs';
|
247 |
+
|
248 |
+
$options = array (
|
249 |
+
'extension' => 'log',
|
250 |
+
'dateFormat' => 'Y-m-d G:i:s.u',
|
251 |
+
'filename' => $log_name,
|
252 |
+
'flushFrequency' => false,
|
253 |
+
'prefix' => 'log_',
|
254 |
+
'logFormat' => false,
|
255 |
+
'appendContext' => true,
|
256 |
+
);
|
257 |
+
|
258 |
try{
|
259 |
|
260 |
if (! isset( self::$logger[$log_name])) {
|
261 |
+
self::$logger[$log_name] = $logger = new Logger($path, $log_level, $options);
|
262 |
}
|
263 |
|
264 |
return self::$logger[$log_name];
|
268 |
}
|
269 |
}
|
270 |
|
271 |
+
/**
|
272 |
+
* Check if logging is enabled or not
|
273 |
+
*
|
274 |
+
* @return boolean
|
275 |
+
*/
|
276 |
+
private static function is_logging(){
|
277 |
+
global $WPBackitup;
|
278 |
+
return $WPBackitup->logging();
|
279 |
+
}
|
280 |
+
|
281 |
+
|
282 |
/** PUBLIC METHODS **/
|
283 |
|
284 |
/**
|
290 |
*/
|
291 |
public static function close($log_name) {
|
292 |
try{
|
293 |
+
if(self::is_logging() === true) {
|
294 |
+
$logger = self::getLogger($log_name);
|
295 |
+
$logger->close();
|
296 |
+
self::$logger[$log_name] = null;
|
297 |
+
unset(self::$logger[$log_name]);
|
298 |
+
}
|
299 |
|
300 |
}catch(Exception $e) {
|
301 |
error_log( $e );
|
312 |
*/
|
313 |
public static function getLogFileName($log_name) {
|
314 |
try{
|
315 |
+
if(self::is_logging() === true) {
|
316 |
+
$logger = self::getLogger($log_name);
|
317 |
+
return $logger->getLogFileName();
|
318 |
+
}
|
319 |
|
320 |
}catch(Exception $e) {
|
321 |
error_log( $e );
|
331 |
*/
|
332 |
public static function getLogFilePath($log_name) {
|
333 |
try{
|
334 |
+
if(self::is_logging() === true) {
|
335 |
+
$logger = self::getLogger($log_name);
|
336 |
+
return $logger->getLogFilePath();
|
337 |
+
}
|
338 |
|
339 |
}catch(Exception $e) {
|
340 |
error_log( $e );
|
lib/includes/class-mutex.php
CHANGED
@@ -39,7 +39,7 @@ class WPBackItUp_Mutex {
|
|
39 |
|
40 |
private function attemptLock(){
|
41 |
$lockFilePath = $this->getLockFilePath();
|
42 |
-
|
43 |
if (PHP_OS == 'WINNT'){
|
44 |
if(file_exists($lockFilePath)){
|
45 |
$unlinked = @unlink($lockFilePath);
|
@@ -48,7 +48,7 @@ class WPBackItUp_Mutex {
|
|
48 |
}
|
49 |
|
50 |
$fileHandle = $this->getFileHandle();
|
51 |
-
|
52 |
|
53 |
if(!$fileHandle){
|
54 |
return false;
|
@@ -96,19 +96,19 @@ class WPBackItUp_Mutex {
|
|
96 |
* @return bool
|
97 |
*/
|
98 |
public function releaseLock(){
|
99 |
-
|
100 |
|
101 |
$close_rtn=true;
|
102 |
|
103 |
$fh = $this->fileHandle;
|
104 |
-
|
105 |
|
106 |
if (null!=$fh ) {
|
107 |
-
$flock_rtn = flock($fh, LOCK_UN);
|
108 |
-
|
109 |
|
110 |
-
$close_rtn = fclose($fh);
|
111 |
-
|
112 |
}
|
113 |
|
114 |
//delete file & release reference
|
39 |
|
40 |
private function attemptLock(){
|
41 |
$lockFilePath = $this->getLockFilePath();
|
42 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin:' .$lockFilePath);
|
43 |
if (PHP_OS == 'WINNT'){
|
44 |
if(file_exists($lockFilePath)){
|
45 |
$unlinked = @unlink($lockFilePath);
|
48 |
}
|
49 |
|
50 |
$fileHandle = $this->getFileHandle();
|
51 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Handle:' .var_export($fileHandle,true));
|
52 |
|
53 |
if(!$fileHandle){
|
54 |
return false;
|
96 |
* @return bool
|
97 |
*/
|
98 |
public function releaseLock(){
|
99 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin');
|
100 |
|
101 |
$close_rtn=true;
|
102 |
|
103 |
$fh = $this->fileHandle;
|
104 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'File Handle:' .var_export($fh,true));
|
105 |
|
106 |
if (null!=$fh ) {
|
107 |
+
$flock_rtn = @flock($fh, LOCK_UN);
|
108 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Flock Unlock:' .var_export($flock_rtn,true));
|
109 |
|
110 |
+
$close_rtn = @fclose($fh);
|
111 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Close File:' .var_export($close_rtn,true));
|
112 |
}
|
113 |
|
114 |
//delete file & release reference
|
lib/includes/class-scheduler.php
CHANGED
@@ -23,7 +23,7 @@ class WPBackItUp_Scheduler {
|
|
23 |
|
24 |
} catch(Exception $e) {
|
25 |
error_log($e);
|
26 |
-
|
27 |
}
|
28 |
}
|
29 |
|
@@ -42,7 +42,7 @@ class WPBackItUp_Scheduler {
|
|
42 |
* @return bool
|
43 |
*/
|
44 |
public function isJobScheduled($task){
|
45 |
-
|
46 |
|
47 |
//Check for tasks
|
48 |
$jobs = array();
|
@@ -57,7 +57,7 @@ class WPBackItUp_Scheduler {
|
|
57 |
break;
|
58 |
}
|
59 |
|
60 |
-
|
61 |
return false;
|
62 |
}
|
63 |
|
@@ -70,37 +70,37 @@ class WPBackItUp_Scheduler {
|
|
70 |
*/
|
71 |
private function check_cleanup_schedule(){
|
72 |
global $WPBackitup;
|
73 |
-
|
74 |
try {
|
75 |
|
76 |
//What is the current day of the week
|
77 |
$current_datetime = current_time( 'timestamp' );
|
78 |
$current_date = date("Ymd",$current_datetime);
|
79 |
|
80 |
-
|
81 |
|
82 |
//Get Last RUN date
|
83 |
$lastrun_datetime = $WPBackitup->cleanup_lastrun_date();
|
84 |
|
85 |
$lastrun_date = date("Ymd",$lastrun_datetime);
|
86 |
-
|
87 |
|
88 |
//Has it been at least an hour since the last cleanup?
|
89 |
|
90 |
$next_run_datetime=$lastrun_datetime+3600; //1 hour
|
91 |
-
|
92 |
|
93 |
-
|
94 |
if ($current_datetime>=$next_run_datetime){
|
95 |
-
|
96 |
return true;
|
97 |
}
|
98 |
|
99 |
-
|
100 |
return false;
|
101 |
|
102 |
}catch(Exception $e) {
|
103 |
-
|
104 |
return false;
|
105 |
}
|
106 |
|
23 |
|
24 |
} catch(Exception $e) {
|
25 |
error_log($e);
|
26 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .$e);
|
27 |
}
|
28 |
}
|
29 |
|
42 |
* @return bool
|
43 |
*/
|
44 |
public function isJobScheduled($task){
|
45 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Check schedule for task: ' . $task);
|
46 |
|
47 |
//Check for tasks
|
48 |
$jobs = array();
|
57 |
break;
|
58 |
}
|
59 |
|
60 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Task not found:' . $task);
|
61 |
return false;
|
62 |
}
|
63 |
|
70 |
*/
|
71 |
private function check_cleanup_schedule(){
|
72 |
global $WPBackitup;
|
73 |
+
WPBackItUp_Logger::log($this->log_name,'**Check Cleanup Schedule**');
|
74 |
try {
|
75 |
|
76 |
//What is the current day of the week
|
77 |
$current_datetime = current_time( 'timestamp' );
|
78 |
$current_date = date("Ymd",$current_datetime);
|
79 |
|
80 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Current Date time:' . date( 'Y-m-d H:i:s',$current_datetime));
|
81 |
|
82 |
//Get Last RUN date
|
83 |
$lastrun_datetime = $WPBackitup->cleanup_lastrun_date();
|
84 |
|
85 |
$lastrun_date = date("Ymd",$lastrun_datetime);
|
86 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Last Run Date Time:' . date( 'Y-m-d H:i:s',$lastrun_datetime));
|
87 |
|
88 |
//Has it been at least an hour since the last cleanup?
|
89 |
|
90 |
$next_run_datetime=$lastrun_datetime+3600; //1 hour
|
91 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Next Run Date Time:' . date( 'Y-m-d H:i:s',$next_run_datetime));
|
92 |
|
93 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'TimeToRun:' . $current_datetime . ':'.$next_run_datetime );
|
94 |
if ($current_datetime>=$next_run_datetime){
|
95 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Cleanup should be run now.');
|
96 |
return true;
|
97 |
}
|
98 |
|
99 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Not yet time to run Cleanup.');
|
100 |
return false;
|
101 |
|
102 |
}catch(Exception $e) {
|
103 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .$e);
|
104 |
return false;
|
105 |
}
|
106 |
|
lib/includes/class-sql.php
CHANGED
@@ -35,7 +35,7 @@ class WPBackItUp_SQL {
|
|
35 |
|
36 |
} catch(Exception $e) {
|
37 |
error_log($e);
|
38 |
-
|
39 |
}
|
40 |
}
|
41 |
|
@@ -60,7 +60,7 @@ class WPBackItUp_SQL {
|
|
60 |
* @return bool
|
61 |
*/
|
62 |
public function mysqldump_export_data($sql_data_file_name,$table,$offset,$limit,$create_table,$with_mysqlpath=false) {
|
63 |
-
|
64 |
|
65 |
$db_name = DB_NAME;
|
66 |
$db_user = DB_USER;
|
@@ -104,38 +104,38 @@ class WPBackItUp_SQL {
|
|
104 |
|
105 |
if (WPBACKITUP__DEBUG) {
|
106 |
$masked_command = str_replace(array($db_user,$db_pass),'XXXXXX',$command);
|
107 |
-
|
108 |
}
|
109 |
|
110 |
exec($command,$output,$rtn_var);
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
|
115 |
//0 is success
|
116 |
if ($rtn_var>0){
|
117 |
-
|
118 |
return false;
|
119 |
}
|
120 |
|
121 |
//Did the export work
|
122 |
clearstatcache();
|
123 |
if (!file_exists($sql_data_file_name) || filesize($sql_data_file_name)<=0) {
|
124 |
-
|
125 |
return false;
|
126 |
}
|
127 |
} catch(Exception $e) {
|
128 |
-
|
129 |
return false;
|
130 |
}
|
131 |
}
|
132 |
else
|
133 |
{
|
134 |
-
|
135 |
return false;
|
136 |
}
|
137 |
|
138 |
-
|
139 |
return true;
|
140 |
}
|
141 |
|
@@ -148,7 +148,7 @@ class WPBackItUp_SQL {
|
|
148 |
* @return bool
|
149 |
*/
|
150 |
public function generate_rename_sql($sql_file,$snapshot_prefix) {
|
151 |
-
|
152 |
|
153 |
global $wpdb;
|
154 |
try{
|
@@ -234,7 +234,7 @@ class WPBackItUp_SQL {
|
|
234 |
|
235 |
//if empty buffer then no tables were found with snapshot prefix
|
236 |
if (empty($output_buffer )){
|
237 |
-
|
238 |
return false;
|
239 |
}
|
240 |
|
@@ -243,7 +243,7 @@ class WPBackItUp_SQL {
|
|
243 |
|
244 |
//save sql to file to run at end of restore - replaces existing
|
245 |
if (false===file_put_contents($sql_file,$output_buffer)){
|
246 |
-
|
247 |
return false;
|
248 |
}
|
249 |
|
@@ -253,7 +253,7 @@ class WPBackItUp_SQL {
|
|
253 |
|
254 |
|
255 |
}catch(Exception $e) {
|
256 |
-
|
257 |
return false;
|
258 |
}
|
259 |
}
|
@@ -271,7 +271,7 @@ class WPBackItUp_SQL {
|
|
271 |
* @return bool True on success/ False on error
|
272 |
*/
|
273 |
public function wpbackitup_export_data($job_id,$sql_data_file_name,$table,$offset,$limit,$create_table) {
|
274 |
-
|
275 |
|
276 |
global $wpdb;
|
277 |
try{
|
@@ -280,7 +280,7 @@ class WPBackItUp_SQL {
|
|
280 |
//It is possible that the last export finished but the task was not updated to complete
|
281 |
//This is why we try export 3 times before error - log warning
|
282 |
if (file_exists($sql_data_file_name)){
|
283 |
-
|
284 |
}
|
285 |
|
286 |
$table_prefix= $wpdb->base_prefix;
|
@@ -298,7 +298,7 @@ class WPBackItUp_SQL {
|
|
298 |
$mysqli = $this->get_mysqli();
|
299 |
|
300 |
if (false===$mysqli) {
|
301 |
-
|
302 |
return false;
|
303 |
}
|
304 |
|
@@ -308,13 +308,13 @@ class WPBackItUp_SQL {
|
|
308 |
$sql = sprintf('SELECT * FROM %s LIMIT %s,%s',$table,$offset,$limit);
|
309 |
$sql_result = $mysqli->query($sql);
|
310 |
if (false===$sql_result) {
|
311 |
-
|
312 |
return false;
|
313 |
}
|
314 |
|
315 |
//export the database even when no data because want to drop and add the table during the restore
|
316 |
$num_rows = $sql_result->num_rows;
|
317 |
-
|
318 |
|
319 |
// Get number of fields (columns) of each table
|
320 |
$num_fields = $mysqli->field_count;
|
@@ -323,7 +323,7 @@ class WPBackItUp_SQL {
|
|
323 |
//open the SQL file - replace if aleaady exists
|
324 |
$handle = fopen($sql_data_file_name,'w');
|
325 |
if (false===$handle) {
|
326 |
-
|
327 |
return false;
|
328 |
}
|
329 |
|
@@ -382,7 +382,7 @@ class WPBackItUp_SQL {
|
|
382 |
mysqli_free_result( $schema );
|
383 |
|
384 |
if (!is_array($create_table_sql) || count($create_table_sql)<1 ){
|
385 |
-
|
386 |
return false;
|
387 |
}
|
388 |
|
@@ -495,31 +495,31 @@ class WPBackItUp_SQL {
|
|
495 |
|
496 |
//Did the export work
|
497 |
if (!file_exists($sql_data_file_name) || filesize($sql_data_file_name)<=0) {
|
498 |
-
|
499 |
return false;
|
500 |
}
|
501 |
|
502 |
-
|
503 |
return true;//Success
|
504 |
|
505 |
}catch(Exception $e) {
|
506 |
-
|
507 |
return false;
|
508 |
}
|
509 |
}
|
510 |
|
511 |
public function run_sql_exec($sql_file,$with_mysqlpath=false) {
|
512 |
-
|
513 |
|
514 |
//Is the backup sql file empty
|
515 |
if (!file_exists($sql_file) || filesize($sql_file)<=0) {
|
516 |
-
|
517 |
return false;
|
518 |
}
|
519 |
|
520 |
//This is to ensure that exec() is enabled on the server
|
521 |
if(exec('echo EXEC') != 'EXEC') {
|
522 |
-
|
523 |
return false;
|
524 |
}
|
525 |
|
@@ -555,34 +555,34 @@ class WPBackItUp_SQL {
|
|
555 |
|
556 |
if (WPBACKITUP__DEBUG) {
|
557 |
$masked_command = str_replace(array($db_user,$db_pass),'XXXXXX',$command);
|
558 |
-
|
559 |
}
|
560 |
|
561 |
//$output = shell_exec($command);
|
562 |
exec($command,$output,$rtn_var);
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
|
567 |
//0 is success
|
568 |
if ($rtn_var!=0){
|
569 |
-
|
570 |
return false;
|
571 |
}
|
572 |
|
573 |
}catch(Exception $e) {
|
574 |
-
|
575 |
return false;
|
576 |
}
|
577 |
|
578 |
//Success
|
579 |
-
|
580 |
return true;
|
581 |
}
|
582 |
|
583 |
function run_sql_manual($sql_file_path, $delimiter = ';')
|
584 |
{
|
585 |
-
|
586 |
|
587 |
// Assuming set time limit don't directly work for class file.
|
588 |
if(!ini_get('safe_mode')){
|
@@ -591,7 +591,7 @@ class WPBackItUp_SQL {
|
|
591 |
|
592 |
//Is the backup sql file empty
|
593 |
if (!file_exists($sql_file_path) || filesize($sql_file_path)<=0) {
|
594 |
-
|
595 |
return false;
|
596 |
}
|
597 |
|
@@ -606,7 +606,7 @@ class WPBackItUp_SQL {
|
|
606 |
|
607 |
$mysqli = $this->get_mysqli();
|
608 |
if (false === $mysqli) {
|
609 |
-
|
610 |
return false;
|
611 |
}
|
612 |
|
@@ -632,9 +632,9 @@ class WPBackItUp_SQL {
|
|
632 |
if ($mysqli->query($query) === false) {
|
633 |
$error_count++;
|
634 |
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
|
639 |
//$mysqli->rollback();
|
640 |
$mysqli->close();
|
@@ -643,7 +643,7 @@ class WPBackItUp_SQL {
|
|
643 |
return false;
|
644 |
}
|
645 |
// else {
|
646 |
-
//
|
647 |
// }
|
648 |
|
649 |
while (ob_get_level() > 0)
|
@@ -663,19 +663,19 @@ class WPBackItUp_SQL {
|
|
663 |
//$mysqli->commit();
|
664 |
$mysqli->close();
|
665 |
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
return fclose($sql_handle);
|
670 |
}
|
671 |
}
|
672 |
|
673 |
}catch(Exception $e) {
|
674 |
-
|
675 |
return false;
|
676 |
}
|
677 |
|
678 |
-
|
679 |
return false;
|
680 |
}
|
681 |
|
@@ -685,10 +685,10 @@ class WPBackItUp_SQL {
|
|
685 |
* @return bool|mysqli
|
686 |
*/
|
687 |
public function get_mysqli() {
|
688 |
-
|
689 |
|
690 |
if (! function_exists('mysqli_connect')) {
|
691 |
-
|
692 |
return false;
|
693 |
}
|
694 |
|
@@ -698,8 +698,8 @@ class WPBackItUp_SQL {
|
|
698 |
$db_host = $this->get_hostonly(DB_HOST);
|
699 |
$db_port = $this->get_portonly(DB_HOST);
|
700 |
|
701 |
-
|
702 |
-
|
703 |
|
704 |
//is the connection an object & responds to a ping
|
705 |
if (is_object($this->mysqli)){
|
@@ -717,7 +717,7 @@ class WPBackItUp_SQL {
|
|
717 |
}
|
718 |
|
719 |
if ($mysqli->connect_errno) {
|
720 |
-
|
721 |
return false;
|
722 |
}
|
723 |
|
@@ -752,7 +752,7 @@ class WPBackItUp_SQL {
|
|
752 |
|
753 |
$mysqli = $this->get_mysqli();
|
754 |
if (false === $mysqli) {
|
755 |
-
|
756 |
return false;
|
757 |
}
|
758 |
|
@@ -769,12 +769,12 @@ class WPBackItUp_SQL {
|
|
769 |
public function run_sql_command($sql){
|
770 |
$mysqli = $this->get_mysqli();
|
771 |
if (false === $mysqli) {
|
772 |
-
|
773 |
return false;
|
774 |
}
|
775 |
|
776 |
if(!mysqli_query($mysqli, $sql) ) {
|
777 |
-
|
778 |
return false;
|
779 |
}
|
780 |
|
35 |
|
36 |
} catch(Exception $e) {
|
37 |
error_log($e);
|
38 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .$e);
|
39 |
}
|
40 |
}
|
41 |
|
60 |
* @return bool
|
61 |
*/
|
62 |
public function mysqldump_export_data($sql_data_file_name,$table,$offset,$limit,$create_table,$with_mysqlpath=false) {
|
63 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Begin.');
|
64 |
|
65 |
$db_name = DB_NAME;
|
66 |
$db_user = DB_USER;
|
104 |
|
105 |
if (WPBACKITUP__DEBUG) {
|
106 |
$masked_command = str_replace(array($db_user,$db_pass),'XXXXXX',$command);
|
107 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Execute command:' . $masked_command);
|
108 |
}
|
109 |
|
110 |
exec($command,$output,$rtn_var);
|
111 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Execute output:');
|
112 |
+
WPBackItUp_Logger::log($this->log_name,$output);
|
113 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Return Value:' .$rtn_var);
|
114 |
|
115 |
//0 is success
|
116 |
if ($rtn_var>0){
|
117 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'EXPORT FAILED return Value:' .$rtn_var);
|
118 |
return false;
|
119 |
}
|
120 |
|
121 |
//Did the export work
|
122 |
clearstatcache();
|
123 |
if (!file_exists($sql_data_file_name) || filesize($sql_data_file_name)<=0) {
|
124 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'EXPORT FAILED: Dump was empty or missing.');
|
125 |
return false;
|
126 |
}
|
127 |
} catch(Exception $e) {
|
128 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'EXPORT FAILED Exception: ' .$e);
|
129 |
return false;
|
130 |
}
|
131 |
}
|
132 |
else
|
133 |
{
|
134 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'EXPORT FAILED Exec() disabled.');
|
135 |
return false;
|
136 |
}
|
137 |
|
138 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'SQL Dump SUCCESS.');
|
139 |
return true;
|
140 |
}
|
141 |
|
148 |
* @return bool
|
149 |
*/
|
150 |
public function generate_rename_sql($sql_file,$snapshot_prefix) {
|
151 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Generate Rename SQL:'.$sql_file);
|
152 |
|
153 |
global $wpdb;
|
154 |
try{
|
234 |
|
235 |
//if empty buffer then no tables were found with snapshot prefix
|
236 |
if (empty($output_buffer )){
|
237 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'No tables found for snapshot prefix: ' .$snapshot_prefix);
|
238 |
return false;
|
239 |
}
|
240 |
|
243 |
|
244 |
//save sql to file to run at end of restore - replaces existing
|
245 |
if (false===file_put_contents($sql_file,$output_buffer)){
|
246 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Snapshot Rename SQL file could not be created: ' .$sql_file);
|
247 |
return false;
|
248 |
}
|
249 |
|
253 |
|
254 |
|
255 |
}catch(Exception $e) {
|
256 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .$e);
|
257 |
return false;
|
258 |
}
|
259 |
}
|
271 |
* @return bool True on success/ False on error
|
272 |
*/
|
273 |
public function wpbackitup_export_data($job_id,$sql_data_file_name,$table,$offset,$limit,$create_table) {
|
274 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Export Database Table:'.$table);
|
275 |
|
276 |
global $wpdb;
|
277 |
try{
|
280 |
//It is possible that the last export finished but the task was not updated to complete
|
281 |
//This is why we try export 3 times before error - log warning
|
282 |
if (file_exists($sql_data_file_name)){
|
283 |
+
WPBackItUp_Logger::log_warning($this->log_name,__METHOD__,'SQL file already exists. This is not expected.');
|
284 |
}
|
285 |
|
286 |
$table_prefix= $wpdb->base_prefix;
|
298 |
$mysqli = $this->get_mysqli();
|
299 |
|
300 |
if (false===$mysqli) {
|
301 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'No SQL Connection');
|
302 |
return false;
|
303 |
}
|
304 |
|
308 |
$sql = sprintf('SELECT * FROM %s LIMIT %s,%s',$table,$offset,$limit);
|
309 |
$sql_result = $mysqli->query($sql);
|
310 |
if (false===$sql_result) {
|
311 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Query Error:' .var_export( $sql_result,true ));
|
312 |
return false;
|
313 |
}
|
314 |
|
315 |
//export the database even when no data because want to drop and add the table during the restore
|
316 |
$num_rows = $sql_result->num_rows;
|
317 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'ROWS to export:' .$num_rows);
|
318 |
|
319 |
// Get number of fields (columns) of each table
|
320 |
$num_fields = $mysqli->field_count;
|
323 |
//open the SQL file - replace if aleaady exists
|
324 |
$handle = fopen($sql_data_file_name,'w');
|
325 |
if (false===$handle) {
|
326 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'File could not be opened.');
|
327 |
return false;
|
328 |
}
|
329 |
|
382 |
mysqli_free_result( $schema );
|
383 |
|
384 |
if (!is_array($create_table_sql) || count($create_table_sql)<1 ){
|
385 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Could not generate create SQL:' .$table);
|
386 |
return false;
|
387 |
}
|
388 |
|
495 |
|
496 |
//Did the export work
|
497 |
if (!file_exists($sql_data_file_name) || filesize($sql_data_file_name)<=0) {
|
498 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Failure: SQL Export file was empty or didnt exist.');
|
499 |
return false;
|
500 |
}
|
501 |
|
502 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'SQL Backup File Created:'.$sql_data_file_name);
|
503 |
return true;//Success
|
504 |
|
505 |
}catch(Exception $e) {
|
506 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .$e);
|
507 |
return false;
|
508 |
}
|
509 |
}
|
510 |
|
511 |
public function run_sql_exec($sql_file,$with_mysqlpath=false) {
|
512 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'SQL Execute:' .$sql_file);
|
513 |
|
514 |
//Is the backup sql file empty
|
515 |
if (!file_exists($sql_file) || filesize($sql_file)<=0) {
|
516 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Failure: SQL File was empty:' .$sql_file);
|
517 |
return false;
|
518 |
}
|
519 |
|
520 |
//This is to ensure that exec() is enabled on the server
|
521 |
if(exec('echo EXEC') != 'EXEC') {
|
522 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Failure: Exec() disabled.');
|
523 |
return false;
|
524 |
}
|
525 |
|
555 |
|
556 |
if (WPBACKITUP__DEBUG) {
|
557 |
$masked_command = str_replace(array($db_user,$db_pass),'XXXXXX',$command);
|
558 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Execute command:' . $masked_command );
|
559 |
}
|
560 |
|
561 |
//$output = shell_exec($command);
|
562 |
exec($command,$output,$rtn_var);
|
563 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Execute output:');
|
564 |
+
WPBackItUp_Logger::log($this->log_name,$output);
|
565 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Return Value:' .$rtn_var);
|
566 |
|
567 |
//0 is success
|
568 |
if ($rtn_var!=0){
|
569 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'An Error has occurred RTNVAL: ' .$rtn_var);
|
570 |
return false;
|
571 |
}
|
572 |
|
573 |
}catch(Exception $e) {
|
574 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .$e);
|
575 |
return false;
|
576 |
}
|
577 |
|
578 |
//Success
|
579 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'SQL Executed successfully');
|
580 |
return true;
|
581 |
}
|
582 |
|
583 |
function run_sql_manual($sql_file_path, $delimiter = ';')
|
584 |
{
|
585 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'SQL Execute:' .$sql_file_path);
|
586 |
|
587 |
// Assuming set time limit don't directly work for class file.
|
588 |
if(!ini_get('safe_mode')){
|
591 |
|
592 |
//Is the backup sql file empty
|
593 |
if (!file_exists($sql_file_path) || filesize($sql_file_path)<=0) {
|
594 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Failure: SQL File was empty:' .$sql_file_path);
|
595 |
return false;
|
596 |
}
|
597 |
|
606 |
|
607 |
$mysqli = $this->get_mysqli();
|
608 |
if (false === $mysqli) {
|
609 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'No SQL Connection');
|
610 |
return false;
|
611 |
}
|
612 |
|
632 |
if ($mysqli->query($query) === false) {
|
633 |
$error_count++;
|
634 |
|
635 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Total Queries Executed:' .$total_query);
|
636 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Query Errors:' .$error_count);
|
637 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,' SQL ERROR: ' . $query);
|
638 |
|
639 |
//$mysqli->rollback();
|
640 |
$mysqli->close();
|
643 |
return false;
|
644 |
}
|
645 |
// else {
|
646 |
+
// WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'SUCCESS: ' . $query);
|
647 |
// }
|
648 |
|
649 |
while (ob_get_level() > 0)
|
663 |
//$mysqli->commit();
|
664 |
$mysqli->close();
|
665 |
|
666 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'SQL Executed successfully:' .$sql_file_path);
|
667 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Total Queries Executed:' .$total_query);
|
668 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Query Errors:' .$error_count);
|
669 |
return fclose($sql_handle);
|
670 |
}
|
671 |
}
|
672 |
|
673 |
}catch(Exception $e) {
|
674 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Exception: ' .$e);
|
675 |
return false;
|
676 |
}
|
677 |
|
678 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'SQL File could not be opened:' .$sql_file_path);
|
679 |
return false;
|
680 |
}
|
681 |
|
685 |
* @return bool|mysqli
|
686 |
*/
|
687 |
public function get_mysqli() {
|
688 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Get SQL connection to database.');
|
689 |
|
690 |
if (! function_exists('mysqli_connect')) {
|
691 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'mySQLi is not installed.');
|
692 |
return false;
|
693 |
}
|
694 |
|
698 |
$db_host = $this->get_hostonly(DB_HOST);
|
699 |
$db_port = $this->get_portonly(DB_HOST);
|
700 |
|
701 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Host:' . $db_host);
|
702 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Port:' . $db_port);
|
703 |
|
704 |
//is the connection an object & responds to a ping
|
705 |
if (is_object($this->mysqli)){
|
717 |
}
|
718 |
|
719 |
if ($mysqli->connect_errno) {
|
720 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Cannot connect to database.' . $mysqli->connect_error);
|
721 |
return false;
|
722 |
}
|
723 |
|
752 |
|
753 |
$mysqli = $this->get_mysqli();
|
754 |
if (false === $mysqli) {
|
755 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'No SQL Connection');
|
756 |
return false;
|
757 |
}
|
758 |
|
769 |
public function run_sql_command($sql){
|
770 |
$mysqli = $this->get_mysqli();
|
771 |
if (false === $mysqli) {
|
772 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'No SQL Connection');
|
773 |
return false;
|
774 |
}
|
775 |
|
776 |
if(!mysqli_query($mysqli, $sql) ) {
|
777 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Error:SQL Command Failed:' .$sql);
|
778 |
return false;
|
779 |
}
|
780 |
|
lib/includes/class-utility.php
CHANGED
@@ -26,7 +26,7 @@ class WPBackItUp_Utility {
|
|
26 |
|
27 |
} catch(Exception $e) {
|
28 |
error_log($e);
|
29 |
-
|
30 |
}
|
31 |
}
|
32 |
|
@@ -50,12 +50,12 @@ class WPBackItUp_Utility {
|
|
50 |
}
|
51 |
|
52 |
wp_mail($to, $subject, nl2br($message), $headers,$attachments);
|
53 |
-
|
54 |
-
|
55 |
}
|
56 |
|
57 |
} catch(Exception $e) {
|
58 |
-
|
59 |
}
|
60 |
|
61 |
}
|
@@ -84,17 +84,17 @@ class WPBackItUp_Utility {
|
|
84 |
//Send Mail
|
85 |
$rtn_val = wp_mail($to, $subject, nl2br($message), $headers,$attachments);
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
|
93 |
return $rtn_val;
|
94 |
}
|
95 |
|
96 |
} catch(Exception $e) {
|
97 |
-
|
98 |
return false;
|
99 |
}
|
100 |
|
26 |
|
27 |
} catch(Exception $e) {
|
28 |
error_log($e);
|
29 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Constructor Exception: ' .$e);
|
30 |
}
|
31 |
}
|
32 |
|
50 |
}
|
51 |
|
52 |
wp_mail($to, $subject, nl2br($message), $headers,$attachments);
|
53 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'EMail Sent from:' .$from_email);
|
54 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'EMail Sent to:' .$to);
|
55 |
}
|
56 |
|
57 |
} catch(Exception $e) {
|
58 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Send Email Exception:'.$e);
|
59 |
}
|
60 |
|
61 |
}
|
84 |
//Send Mail
|
85 |
$rtn_val = wp_mail($to, $subject, nl2br($message), $headers,$attachments);
|
86 |
|
87 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Headers:' .var_export($headers,true));
|
88 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'EMail Sent from:' .$from_email);
|
89 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'EMail Sent to:' .$to);
|
90 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'EMail Sent to:' .$to);
|
91 |
+
WPBackItUp_Logger::log_info($this->log_name,__METHOD__,'Return Code:' .var_export( $rtn_val,true ));
|
92 |
|
93 |
return $rtn_val;
|
94 |
}
|
95 |
|
96 |
} catch(Exception $e) {
|
97 |
+
WPBackItUp_Logger::log_error($this->log_name,__METHOD__,'Send Email Exception:'.$e);
|
98 |
return false;
|
99 |
}
|
100 |
|
lib/includes/class-wpbackitup-admin.php
CHANGED
@@ -39,6 +39,8 @@ class WPBackitup_Admin {
|
|
39 |
'delete_all' => 0,
|
40 |
'rversion_compare' => 0,
|
41 |
'backup_dbtables_batch_size'=> WPBACKITUP__DATABASE_BATCH_SIZE,
|
|
|
|
|
42 |
'backup_plugins_batch_size'=>WPBACKITUP__PLUGINS_BATCH_SIZE,
|
43 |
'backup_themes_batch_size'=>WPBACKITUP__THEMES_BATCH_SIZE,
|
44 |
'backup_uploads_batch_size'=>WPBACKITUP__UPLOADS_BATCH_SIZE,
|
@@ -352,23 +354,23 @@ class WPBackitup_Admin {
|
|
352 |
$nonce = $_REQUEST['_wpnonce'];
|
353 |
|
354 |
$wpbdebug_logname='wpb_debug';
|
355 |
-
//
|
356 |
|
357 |
// Handle POST requests
|
358 |
if( $is_post ) {
|
359 |
|
360 |
if( wp_verify_nonce( $nonce, "{$this->namespace}-update-options" ) ) {
|
361 |
-
|
362 |
$this->_admin_options_update();
|
363 |
}
|
364 |
|
365 |
if( wp_verify_nonce( $nonce, "{$this->namespace}-register" ) ) {
|
366 |
-
|
367 |
$this->_admin_register();
|
368 |
}
|
369 |
|
370 |
if( wp_verify_nonce( $nonce, "{$this->namespace}-update-schedule" ) ) {
|
371 |
-
|
372 |
|
373 |
$val = $_POST['days_selected'];
|
374 |
$days_selected = $this->_sanitize($val);
|
@@ -385,7 +387,7 @@ class WPBackitup_Admin {
|
|
385 |
}
|
386 |
|
387 |
if( wp_verify_nonce( $nonce, "{$this->namespace}-support-form" ) ) {
|
388 |
-
|
389 |
$this->_admin_send_support_request();
|
390 |
}
|
391 |
|
@@ -416,6 +418,11 @@ class WPBackitup_Admin {
|
|
416 |
|
417 |
require_once( WPBACKITUP__PLUGIN_PATH . '/lib/includes/class-license.php' );
|
418 |
|
|
|
|
|
|
|
|
|
|
|
419 |
$languages_path = dirname(dirname(dirname( plugin_basename( __FILE__ )))) . '/languages/';
|
420 |
|
421 |
load_plugin_textdomain(
|
@@ -438,7 +445,7 @@ class WPBackitup_Admin {
|
|
438 |
*/
|
439 |
public function wpbackitup_queue_scheduled_jobs(){
|
440 |
$scheduled_jobs_logname = 'debug_scheduled_jobs';
|
441 |
-
|
442 |
|
443 |
// Check permissions
|
444 |
if (! self::is_authorized()) exit('Access denied.');
|
@@ -463,7 +470,7 @@ class WPBackitup_Admin {
|
|
463 |
//RESTORE
|
464 |
$restore_job = WPBackItUp_Job::is_job_queued_active(WPBackItUp_Job::RESTORE);
|
465 |
if (false!==$restore_job){
|
466 |
-
|
467 |
exit;
|
468 |
}
|
469 |
|
@@ -484,14 +491,14 @@ class WPBackitup_Admin {
|
|
484 |
$backup_tasks= apply_filters( 'wp-backitup_post_backup_tasks', WPBackItUp_Job::$BACKUP_TASKS );
|
485 |
$backup_job = WPBackItUp_Job::queue_job($job_name,$job_id, WPBackItUp_Job::BACKUP,WPBackItUp_Job::SCHEDULED, $backup_tasks);
|
486 |
if (false===$backup_job){
|
487 |
-
|
488 |
}else {
|
489 |
//run background processor
|
490 |
$background_processor = new WPBackItUp_Task_Processor();
|
491 |
$background_processor->push_to_queue( $job_name);
|
492 |
$background_processor->save()->dispatch();
|
493 |
|
494 |
-
|
495 |
}
|
496 |
|
497 |
}
|
@@ -520,19 +527,19 @@ class WPBackitup_Admin {
|
|
520 |
//queue Job
|
521 |
$job = WPBackItUp_Job::queue_job($job_name,$job_id, $job_type, WPBackItUp_Job::SCHEDULED,$job_tasks);
|
522 |
if (false===$job){
|
523 |
-
|
524 |
} else {
|
525 |
//run background processor
|
526 |
$background_processor = new WPBackItUp_Task_Processor();
|
527 |
$background_processor->push_to_queue( $job_name);
|
528 |
$background_processor->save()->dispatch();
|
529 |
|
530 |
-
|
531 |
}
|
532 |
|
533 |
}
|
534 |
|
535 |
-
|
536 |
exit(0); //success nothing to schedule
|
537 |
}
|
538 |
|
@@ -545,7 +552,7 @@ class WPBackitup_Admin {
|
|
545 |
if (! self::is_authorized()) exit('Access denied.');
|
546 |
|
547 |
$events_logname='debug_events';
|
548 |
-
|
549 |
|
550 |
//Include Job class
|
551 |
if( !class_exists( 'WPBackItUp_Backup' ) ) {
|
@@ -592,8 +599,8 @@ class WPBackitup_Admin {
|
|
592 |
|
593 |
}
|
594 |
|
595 |
-
|
596 |
-
|
597 |
echo json_encode($rtnData);
|
598 |
exit;
|
599 |
}
|
@@ -609,7 +616,7 @@ class WPBackitup_Admin {
|
|
609 |
if (! self::is_authorized()) exit('Access denied.');
|
610 |
|
611 |
$events_logname='debug_events';
|
612 |
-
|
613 |
|
614 |
//Include Job class
|
615 |
//Include Job class
|
@@ -690,8 +697,8 @@ class WPBackitup_Admin {
|
|
690 |
}
|
691 |
}
|
692 |
|
693 |
-
|
694 |
-
|
695 |
echo json_encode($rtnData);
|
696 |
exit;
|
697 |
}
|
@@ -706,7 +713,7 @@ class WPBackitup_Admin {
|
|
706 |
$job_type=WPBackItUp_Job::BACKUP;
|
707 |
|
708 |
$events_logname=sprintf('debug_%s_tasks',$job_type); //Set Log name
|
709 |
-
|
710 |
|
711 |
$response = new stdClass();
|
712 |
$response->success=false; //default to error
|
@@ -717,14 +724,14 @@ class WPBackitup_Admin {
|
|
717 |
} else {
|
718 |
$job = WPBackItUp_Job::get_job_by_id($job_id);
|
719 |
if (false!==$job) {
|
720 |
-
|
721 |
$job->setStatus(WPBackItUp_Job::CANCELLED);
|
722 |
|
723 |
$response->success=true;
|
724 |
$response->message = __('Backup Cancelled', 'wp-backitup');
|
725 |
} else{
|
726 |
$response->message=__('Backup job not found', 'wp-backitup');
|
727 |
-
|
728 |
}
|
729 |
}
|
730 |
|
@@ -742,7 +749,7 @@ class WPBackitup_Admin {
|
|
742 |
@session_write_close();
|
743 |
|
744 |
$events_logname='debug_events';
|
745 |
-
|
746 |
|
747 |
|
748 |
$job_id = $_REQUEST['job_id'];
|
@@ -764,7 +771,7 @@ class WPBackitup_Admin {
|
|
764 |
if (! self::is_authorized()) exit('Access denied.');
|
765 |
|
766 |
$events_logname='debug_events';
|
767 |
-
|
768 |
|
769 |
//Check permissions
|
770 |
if ( current_user_can( 'manage_options' ) ) {
|
@@ -796,7 +803,7 @@ class WPBackitup_Admin {
|
|
796 |
if (! self::is_authorized()) exit('Access denied.');
|
797 |
|
798 |
$events_logname='debug_events';
|
799 |
-
|
800 |
|
801 |
//Check permissions
|
802 |
if ( current_user_can( 'manage_options' ) ) {
|
@@ -956,8 +963,8 @@ class WPBackitup_Admin {
|
|
956 |
$backup_folder_path = WPBACKITUP__BACKUP_PATH .'/' . $backup_folder_name;
|
957 |
$DLT_backup_folder_path = WPBACKITUP__BACKUP_PATH .'/DLT_' . $backup_folder_name .'_' . current_time( 'timestamp' );
|
958 |
|
959 |
-
|
960 |
-
|
961 |
|
962 |
//Mark the folder deleted so cleanup will handle
|
963 |
if (file_exists ($backup_folder_path)) {
|
@@ -968,14 +975,14 @@ class WPBackitup_Admin {
|
|
968 |
|
969 |
$file_system = new WPBackItUp_FileSystem($delete_logname);
|
970 |
if (! $file_system->rename_file($backup_folder_path,$DLT_backup_folder_path)){
|
971 |
-
|
972 |
exit('Backup NOT deleted');
|
973 |
}
|
974 |
}else{
|
975 |
-
|
976 |
}
|
977 |
} else{
|
978 |
-
|
979 |
}
|
980 |
|
981 |
exit('deleted successfully');
|
@@ -1008,15 +1015,15 @@ class WPBackitup_Admin {
|
|
1008 |
*/
|
1009 |
|
1010 |
$debug_logname='wpb_debug';
|
1011 |
-
|
1012 |
-
|
1013 |
|
1014 |
$wpbackitup_license = new WPBackItUp_License();
|
1015 |
foreach( $_POST['data'] as $key => $val ) {
|
1016 |
$posted_value = $this->_sanitize($val);
|
1017 |
//If license updated then validate
|
1018 |
if (!empty($key) && $key=='license_key') {
|
1019 |
-
|
1020 |
$wpbackitup_license->update_license_options($posted_value);
|
1021 |
}
|
1022 |
else {
|
@@ -1063,6 +1070,8 @@ class WPBackitup_Admin {
|
|
1063 |
}
|
1064 |
}
|
1065 |
|
|
|
|
|
1066 |
//** VALIDATE single file backupset **//
|
1067 |
if(empty($data['single_file_backupset']))
|
1068 |
{
|
@@ -1112,6 +1121,20 @@ class WPBackitup_Admin {
|
|
1112 |
set_transient('batch_size_settings-error-number', __('Please enter a number', $this->namespace), 60);
|
1113 |
}
|
1114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1115 |
//** VALIDATE backup_plugins_batch_size **//
|
1116 |
if(empty($data['backup_plugins_batch_size']) || !is_numeric($data['backup_plugins_batch_size']))
|
1117 |
{
|
@@ -1174,7 +1197,7 @@ class WPBackitup_Admin {
|
|
1174 |
// Update the options value with the data submitted
|
1175 |
foreach( $data as $key => $val ) {
|
1176 |
$this->set_option($key, $val);
|
1177 |
-
|
1178 |
}
|
1179 |
}
|
1180 |
|
@@ -1195,14 +1218,14 @@ class WPBackitup_Admin {
|
|
1195 |
|
1196 |
$url= str_replace('&s=1','',$_REQUEST['_wp_http_referer']);
|
1197 |
$support_logname='debug_support';
|
1198 |
-
|
1199 |
-
|
1200 |
|
1201 |
$error=false;
|
1202 |
if( wp_verify_nonce( $_REQUEST['_wpnonce'], "{$this->namespace}-support-form" ) ) {
|
1203 |
|
1204 |
-
|
1205 |
-
|
1206 |
|
1207 |
//save the email in place of transient
|
1208 |
$this->set_support_email($_POST['support_email']);
|
@@ -1268,7 +1291,7 @@ class WPBackitup_Admin {
|
|
1268 |
|
1269 |
//copy/replace WP debug file
|
1270 |
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
1271 |
-
|
1272 |
if (file_exists($wpdebug_file_path)) {
|
1273 |
copy( $wpdebug_file_path, $logs_path .'/wpdebug.log' );
|
1274 |
}
|
@@ -1337,8 +1360,8 @@ class WPBackitup_Admin {
|
|
1337 |
*/
|
1338 |
|
1339 |
$registration_logname='debug_registration';
|
1340 |
-
|
1341 |
-
|
1342 |
|
1343 |
//First lets check the license
|
1344 |
$val = $_POST['license_key'];
|
@@ -1347,13 +1370,13 @@ class WPBackitup_Admin {
|
|
1347 |
$wpbackitup_license = new WPBackItUp_License();
|
1348 |
|
1349 |
//activate the license if entered
|
1350 |
-
|
1351 |
$wpbackitup_license->update_license_options($license_key);
|
1352 |
|
1353 |
//LITE users only
|
1354 |
if ('0' == $wpbackitup_license->get_license_type()) {
|
1355 |
|
1356 |
-
|
1357 |
|
1358 |
$val = $_POST['license_email'];
|
1359 |
$license_email = $this->_sanitize( $val );
|
@@ -1379,10 +1402,10 @@ class WPBackitup_Admin {
|
|
1379 |
|
1380 |
$registration_response = $wpbackitup_license->register_lite($form_data);
|
1381 |
if ( false===$registration_response ) {
|
1382 |
-
|
1383 |
//try without SSL
|
1384 |
if ( false===$wpbackitup_license->register_lite($form_data,false) ) {
|
1385 |
-
|
1386 |
}
|
1387 |
}
|
1388 |
}
|
@@ -1440,6 +1463,15 @@ class WPBackitup_Admin {
|
|
1440 |
public function backup_dbtables_batch_size(){
|
1441 |
return $this->get('backup_dbtables_batch_size');
|
1442 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1443 |
public function backup_plugins_batch_size(){
|
1444 |
return $this->get('backup_plugins_batch_size');
|
1445 |
}
|
@@ -1936,30 +1968,30 @@ class WPBackitup_Admin {
|
|
1936 |
public static function is_authorized(){
|
1937 |
|
1938 |
$permission_logname='debug_permissions';
|
1939 |
-
|
1940 |
|
1941 |
-
|
1942 |
|
1943 |
if (defined('DOING_CRON')) {
|
1944 |
-
|
1945 |
} else {
|
1946 |
-
|
1947 |
}
|
1948 |
|
1949 |
if (defined('XMLRPC_REQUEST')) {
|
1950 |
-
|
1951 |
} else {
|
1952 |
-
|
1953 |
}
|
1954 |
|
1955 |
//Check User Permissions or CRON
|
1956 |
if (!current_user_can( 'manage_options' )
|
1957 |
&& (!defined('DOING_CRON') || !DOING_CRON)){
|
1958 |
-
|
1959 |
return false;
|
1960 |
}
|
1961 |
|
1962 |
-
|
1963 |
return true;
|
1964 |
}
|
1965 |
|
@@ -2096,7 +2128,7 @@ class WPBackitup_Admin {
|
|
2096 |
$process_id = uniqid();
|
2097 |
|
2098 |
$events_logname=sprintf('debug_run_tasks'); //Set Log name
|
2099 |
-
|
2100 |
|
2101 |
$response = new stdClass();
|
2102 |
$response->success=false; //default to error
|
@@ -2105,35 +2137,35 @@ class WPBackitup_Admin {
|
|
2105 |
$current_job = WPBackItUp_Job::get_job_by_id($job_id);
|
2106 |
$job_type= $current_job->getJobType();
|
2107 |
$job_run_type= $current_job->getJobRunType();
|
2108 |
-
|
2109 |
|
2110 |
if (false!==$current_job) {
|
2111 |
-
|
2112 |
|
2113 |
//IF job is active or queued then proceed
|
2114 |
if (WPBackItUp_Job::ACTIVE ==$current_job->getJobStatus() || WPBackItUp_Job::QUEUED==$current_job->getJobStatus() ){
|
2115 |
|
2116 |
//if job lock acquired run tasks
|
2117 |
if (true===$current_job->get_lock('job_lock')) {
|
2118 |
-
|
2119 |
|
2120 |
//Try Run Next Task in stack
|
2121 |
$current_task = $current_job->get_next_task();
|
2122 |
-
|
2123 |
-
|
2124 |
if ( null != $current_task && false !== $current_task ) {
|
2125 |
-
|
2126 |
|
2127 |
$current_task->increment_retry_count();
|
2128 |
|
2129 |
//Was there an error on the previous run
|
2130 |
if ( WPBackItUp_Job::ERROR == $current_task->getStatus() ) {
|
2131 |
//Log error but error handling should happen in include
|
2132 |
-
|
2133 |
}
|
2134 |
|
2135 |
//Run the task
|
2136 |
-
|
2137 |
|
2138 |
$this->backup_type = $job_run_type;
|
2139 |
$job_include_path = sprintf( WPBACKITUP__PLUGIN_PATH . '/lib/includes/job_%s.php', $job_type );
|
@@ -2141,30 +2173,30 @@ class WPBackitup_Admin {
|
|
2141 |
//error_log('run script');
|
2142 |
require_once( $job_include_path ); //Run tasks from job file
|
2143 |
|
2144 |
-
|
2145 |
} else {
|
2146 |
-
|
2147 |
return;
|
2148 |
}
|
2149 |
|
2150 |
$current_job->release_lock();
|
2151 |
-
|
2152 |
|
2153 |
} else {
|
2154 |
-
|
2155 |
}
|
2156 |
}else {
|
2157 |
-
|
2158 |
}
|
2159 |
|
2160 |
} else {
|
2161 |
-
|
2162 |
}
|
2163 |
|
2164 |
}
|
2165 |
|
2166 |
// $job type could cause error if there is no $job_id
|
2167 |
-
|
2168 |
}
|
2169 |
|
2170 |
|
39 |
'delete_all' => 0,
|
40 |
'rversion_compare' => 0,
|
41 |
'backup_dbtables_batch_size'=> WPBACKITUP__DATABASE_BATCH_SIZE,
|
42 |
+
'backup_sql_merge_batch_size' => WPBACKITUP__SQL_MERGE_BATCH_SIZE,
|
43 |
+
'backup_sql_batch_size' => WPBACKITUP__SQL_BATCH_SIZE,
|
44 |
'backup_plugins_batch_size'=>WPBACKITUP__PLUGINS_BATCH_SIZE,
|
45 |
'backup_themes_batch_size'=>WPBACKITUP__THEMES_BATCH_SIZE,
|
46 |
'backup_uploads_batch_size'=>WPBACKITUP__UPLOADS_BATCH_SIZE,
|
354 |
$nonce = $_REQUEST['_wpnonce'];
|
355 |
|
356 |
$wpbdebug_logname='wpb_debug';
|
357 |
+
//WPBackItUp_Logger::log_info($wpbdebug_logname,__METHOD__,'NONCE:' .$nonce);
|
358 |
|
359 |
// Handle POST requests
|
360 |
if( $is_post ) {
|
361 |
|
362 |
if( wp_verify_nonce( $nonce, "{$this->namespace}-update-options" ) ) {
|
363 |
+
WPBackItUp_Logger::log_info($wpbdebug_logname,__METHOD__,'Update Options Form Post');
|
364 |
$this->_admin_options_update();
|
365 |
}
|
366 |
|
367 |
if( wp_verify_nonce( $nonce, "{$this->namespace}-register" ) ) {
|
368 |
+
WPBackItUp_Logger::log_info($wpbdebug_logname,__METHOD__,'Register Lite Form Post');
|
369 |
$this->_admin_register();
|
370 |
}
|
371 |
|
372 |
if( wp_verify_nonce( $nonce, "{$this->namespace}-update-schedule" ) ) {
|
373 |
+
WPBackItUp_Logger::log_info($wpbdebug_logname,__METHOD__,'Update Schedule Form Post');
|
374 |
|
375 |
$val = $_POST['days_selected'];
|
376 |
$days_selected = $this->_sanitize($val);
|
387 |
}
|
388 |
|
389 |
if( wp_verify_nonce( $nonce, "{$this->namespace}-support-form" ) ) {
|
390 |
+
WPBackItUp_Logger::log_info($wpbdebug_logname,__METHOD__,'Support Form Post');
|
391 |
$this->_admin_send_support_request();
|
392 |
}
|
393 |
|
418 |
|
419 |
require_once( WPBACKITUP__PLUGIN_PATH . '/lib/includes/class-license.php' );
|
420 |
|
421 |
+
|
422 |
+
// This class is used for showing a review nag
|
423 |
+
require_once( WPBACKITUP__PLUGIN_PATH . '/lib/includes/class-admin-notice.php' );
|
424 |
+
//new WPBackitup_Admin_Notice( array('id' => 'wpbu-review-me','days_after' => 10,'type' => 'updated') );
|
425 |
+
|
426 |
$languages_path = dirname(dirname(dirname( plugin_basename( __FILE__ )))) . '/languages/';
|
427 |
|
428 |
load_plugin_textdomain(
|
445 |
*/
|
446 |
public function wpbackitup_queue_scheduled_jobs(){
|
447 |
$scheduled_jobs_logname = 'debug_scheduled_jobs';
|
448 |
+
WPBackItUp_Logger::log_info($scheduled_jobs_logname,__METHOD__,'Begin');
|
449 |
|
450 |
// Check permissions
|
451 |
if (! self::is_authorized()) exit('Access denied.');
|
470 |
//RESTORE
|
471 |
$restore_job = WPBackItUp_Job::is_job_queued_active(WPBackItUp_Job::RESTORE);
|
472 |
if (false!==$restore_job){
|
473 |
+
WPBackItUp_Logger::log_info($scheduled_jobs_logname,__METHOD__,'Restore Job Queued:'. $restore_job->getJobId());
|
474 |
exit;
|
475 |
}
|
476 |
|
491 |
$backup_tasks= apply_filters( 'wp-backitup_post_backup_tasks', WPBackItUp_Job::$BACKUP_TASKS );
|
492 |
$backup_job = WPBackItUp_Job::queue_job($job_name,$job_id, WPBackItUp_Job::BACKUP,WPBackItUp_Job::SCHEDULED, $backup_tasks);
|
493 |
if (false===$backup_job){
|
494 |
+
WPBackItUp_Logger::log_error($scheduled_jobs_logname,__METHOD__,'Scheduled backup could not be queued.');
|
495 |
}else {
|
496 |
//run background processor
|
497 |
$background_processor = new WPBackItUp_Task_Processor();
|
498 |
$background_processor->push_to_queue( $job_name);
|
499 |
$background_processor->save()->dispatch();
|
500 |
|
501 |
+
WPBackItUp_Logger::log_info($scheduled_jobs_logname,__METHOD__,'Backup scheduled to run.');
|
502 |
}
|
503 |
|
504 |
}
|
527 |
//queue Job
|
528 |
$job = WPBackItUp_Job::queue_job($job_name,$job_id, $job_type, WPBackItUp_Job::SCHEDULED,$job_tasks);
|
529 |
if (false===$job){
|
530 |
+
WPBackItUp_Logger::log_error($scheduled_jobs_logname,__METHOD__,'Scheduled job could not be queued:'.$job_type );
|
531 |
} else {
|
532 |
//run background processor
|
533 |
$background_processor = new WPBackItUp_Task_Processor();
|
534 |
$background_processor->push_to_queue( $job_name);
|
535 |
$background_processor->save()->dispatch();
|
536 |
|
537 |
+
WPBackItUp_Logger::log_info($scheduled_jobs_logname,__METHOD__,sprintf('Job queued to run:%s',$job->getJobName()));
|
538 |
}
|
539 |
|
540 |
}
|
541 |
|
542 |
+
WPBackItUp_Logger::log_info($scheduled_jobs_logname,__METHOD__,'End check scheduled jobs.');
|
543 |
exit(0); //success nothing to schedule
|
544 |
}
|
545 |
|
552 |
if (! self::is_authorized()) exit('Access denied.');
|
553 |
|
554 |
$events_logname='debug_events';
|
555 |
+
WPBackItUp_Logger::log_info($events_logname,__METHOD__,'Begin');
|
556 |
|
557 |
//Include Job class
|
558 |
if( !class_exists( 'WPBackItUp_Backup' ) ) {
|
599 |
|
600 |
}
|
601 |
|
602 |
+
WPBackItUp_Logger::log_info($events_logname,__METHOD__,'RtnData:' .$rtnData->message);
|
603 |
+
WPBackItUp_Logger::log_info($events_logname,__METHOD__,'End');
|
604 |
echo json_encode($rtnData);
|
605 |
exit;
|
606 |
}
|
616 |
if (! self::is_authorized()) exit('Access denied.');
|
617 |
|
618 |
$events_logname='debug_events';
|
619 |
+
WPBackItUp_Logger::log_info($events_logname,__METHOD__,'Begin');
|
620 |
|
621 |
//Include Job class
|
622 |
//Include Job class
|
697 |
}
|
698 |
}
|
699 |
|
700 |
+
WPBackItUp_Logger::log_info($events_logname,__METHOD__,'RtnData:' .$rtnData->message);
|
701 |
+
WPBackItUp_Logger::log_info($events_logname,__METHOD__,'End');
|
702 |
echo json_encode($rtnData);
|
703 |
exit;
|
704 |
}
|
713 |
$job_type=WPBackItUp_Job::BACKUP;
|
714 |
|
715 |
$events_logname=sprintf('debug_%s_tasks',$job_type); //Set Log name
|
716 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('(%s) Begin Cancel Backup',$job_type));
|
717 |
|
718 |
$response = new stdClass();
|
719 |
$response->success=false; //default to error
|
724 |
} else {
|
725 |
$job = WPBackItUp_Job::get_job_by_id($job_id);
|
726 |
if (false!==$job) {
|
727 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('(%s) Job found:',var_export($job,true)));
|
728 |
$job->setStatus(WPBackItUp_Job::CANCELLED);
|
729 |
|
730 |
$response->success=true;
|
731 |
$response->message = __('Backup Cancelled', 'wp-backitup');
|
732 |
} else{
|
733 |
$response->message=__('Backup job not found', 'wp-backitup');
|
734 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('(%s) No jobs found.',$job_type));
|
735 |
}
|
736 |
}
|
737 |
|
749 |
@session_write_close();
|
750 |
|
751 |
$events_logname='debug_events';
|
752 |
+
WPBackItUp_Logger::log_info($events_logname,__METHOD__, 'Ajax Run task Fired.');
|
753 |
|
754 |
|
755 |
$job_id = $_REQUEST['job_id'];
|
771 |
if (! self::is_authorized()) exit('Access denied.');
|
772 |
|
773 |
$events_logname='debug_events';
|
774 |
+
WPBackItUp_Logger::log_info($events_logname,__METHOD__, 'User Permissions: ' .current_user_can( 'manage_options' ));
|
775 |
|
776 |
//Check permissions
|
777 |
if ( current_user_can( 'manage_options' ) ) {
|
803 |
if (! self::is_authorized()) exit('Access denied.');
|
804 |
|
805 |
$events_logname='debug_events';
|
806 |
+
WPBackItUp_Logger::log_info($events_logname,__METHOD__, 'User Permissions: ' .current_user_can( 'manage_options' ));
|
807 |
|
808 |
//Check permissions
|
809 |
if ( current_user_can( 'manage_options' ) ) {
|
963 |
$backup_folder_path = WPBACKITUP__BACKUP_PATH .'/' . $backup_folder_name;
|
964 |
$DLT_backup_folder_path = WPBACKITUP__BACKUP_PATH .'/DLT_' . $backup_folder_name .'_' . current_time( 'timestamp' );
|
965 |
|
966 |
+
WPBackItUp_Logger::log_info($delete_logname,__METHOD__, 'From:'.$backup_folder_path );
|
967 |
+
WPBackItUp_Logger::log_info($delete_logname,__METHOD__, 'To:'.$DLT_backup_folder_path );
|
968 |
|
969 |
//Mark the folder deleted so cleanup will handle
|
970 |
if (file_exists ($backup_folder_path)) {
|
975 |
|
976 |
$file_system = new WPBackItUp_FileSystem($delete_logname);
|
977 |
if (! $file_system->rename_file($backup_folder_path,$DLT_backup_folder_path)){
|
978 |
+
WPBackItUp_Logger::log_error($delete_logname,__METHOD__, 'Folder was not renamed');
|
979 |
exit('Backup NOT deleted');
|
980 |
}
|
981 |
}else{
|
982 |
+
WPBackItUp_Logger::log_error($delete_logname,__METHOD__, 'Folder not found:'. $backup_folder_path);
|
983 |
}
|
984 |
} else{
|
985 |
+
WPBackItUp_Logger::log_error($delete_logname,__METHOD__, 'Job not found:'. $job_id);
|
986 |
}
|
987 |
|
988 |
exit('deleted successfully');
|
1015 |
*/
|
1016 |
|
1017 |
$debug_logname='wpb_debug';
|
1018 |
+
WPBackItUp_Logger::log_info($debug_logname,__METHOD__, 'Posted Fields');
|
1019 |
+
WPBackItUp_Logger::log($debug_logname, $_POST['data']); //License will not be in this array
|
1020 |
|
1021 |
$wpbackitup_license = new WPBackItUp_License();
|
1022 |
foreach( $_POST['data'] as $key => $val ) {
|
1023 |
$posted_value = $this->_sanitize($val);
|
1024 |
//If license updated then validate
|
1025 |
if (!empty($key) && $key=='license_key') {
|
1026 |
+
WPBackItUp_Logger::log_info($debug_logname,__METHOD__, 'License Posted:' .$posted_value);
|
1027 |
$wpbackitup_license->update_license_options($posted_value);
|
1028 |
}
|
1029 |
else {
|
1070 |
}
|
1071 |
}
|
1072 |
|
1073 |
+
// Todo: Refactor all common validation into a method. Make it more readable.
|
1074 |
+
|
1075 |
//** VALIDATE single file backupset **//
|
1076 |
if(empty($data['single_file_backupset']))
|
1077 |
{
|
1121 |
set_transient('batch_size_settings-error-number', __('Please enter a number', $this->namespace), 60);
|
1122 |
}
|
1123 |
|
1124 |
+
//** Validate backup_sql_merge_batch_size *//
|
1125 |
+
if(empty($data['backup_sql_merge_batch_size']) || !is_numeric($data['backup_sql_merge_batch_size']))
|
1126 |
+
{
|
1127 |
+
$data['backup_sql_merge_batch_size'] = $this->defaults['backup_sql_merge_batch_size'];
|
1128 |
+
set_transient('batch_size_settings-error-number', __('Please enter a number', $this->namespace), 60);
|
1129 |
+
}
|
1130 |
+
|
1131 |
+
//** Validate backup_sql_batch_size *//
|
1132 |
+
if(empty($data['backup_sql_batch_size']) || !is_numeric($data['backup_sql_batch_size']))
|
1133 |
+
{
|
1134 |
+
$data['backup_sql_batch_size'] = $this->defaults['backup_sql_batch_size'];
|
1135 |
+
set_transient('batch_size_settings-error-number', __('Please enter a number', $this->namespace), 60);
|
1136 |
+
}
|
1137 |
+
|
1138 |
//** VALIDATE backup_plugins_batch_size **//
|
1139 |
if(empty($data['backup_plugins_batch_size']) || !is_numeric($data['backup_plugins_batch_size']))
|
1140 |
{
|
1197 |
// Update the options value with the data submitted
|
1198 |
foreach( $data as $key => $val ) {
|
1199 |
$this->set_option($key, $val);
|
1200 |
+
WPBackItUp_Logger::log_info($debug_logname,__METHOD__, 'Updated Option: ' .$key .':' .$val);
|
1201 |
}
|
1202 |
}
|
1203 |
|
1218 |
|
1219 |
$url= str_replace('&s=1','',$_REQUEST['_wp_http_referer']);
|
1220 |
$support_logname='debug_support';
|
1221 |
+
WPBackItUp_Logger::log_sysinfo($support_logname);
|
1222 |
+
WPBackItUp_Logger::log_info($support_logname,__METHOD__, 'Send Support Request');
|
1223 |
|
1224 |
$error=false;
|
1225 |
if( wp_verify_nonce( $_REQUEST['_wpnonce'], "{$this->namespace}-support-form" ) ) {
|
1226 |
|
1227 |
+
WPBackItUp_Logger::log_info($support_logname,__METHOD__, 'Send support request');
|
1228 |
+
WPBackItUp_Logger::log($support_logname, $_POST);
|
1229 |
|
1230 |
//save the email in place of transient
|
1231 |
$this->set_support_email($_POST['support_email']);
|
1291 |
|
1292 |
//copy/replace WP debug file
|
1293 |
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
1294 |
+
WPBackItUp_Logger::log_info($support_logname,__METHOD__, 'Copy WP Debug: ' .$wpdebug_file_path);
|
1295 |
if (file_exists($wpdebug_file_path)) {
|
1296 |
copy( $wpdebug_file_path, $logs_path .'/wpdebug.log' );
|
1297 |
}
|
1360 |
*/
|
1361 |
|
1362 |
$registration_logname='debug_registration';
|
1363 |
+
WPBackItUp_Logger::log_info($registration_logname,__METHOD__, 'Register WPBackItUp');
|
1364 |
+
WPBackItUp_Logger::log($registration_logname,$_POST);
|
1365 |
|
1366 |
//First lets check the license
|
1367 |
$val = $_POST['license_key'];
|
1370 |
$wpbackitup_license = new WPBackItUp_License();
|
1371 |
|
1372 |
//activate the license if entered
|
1373 |
+
WPBackItUp_Logger::log_info($registration_logname,__METHOD__, 'Activate License');
|
1374 |
$wpbackitup_license->update_license_options($license_key);
|
1375 |
|
1376 |
//LITE users only
|
1377 |
if ('0' == $wpbackitup_license->get_license_type()) {
|
1378 |
|
1379 |
+
WPBackItUp_Logger::log_info($registration_logname,__METHOD__, 'Register WPBackItUp LITE');
|
1380 |
|
1381 |
$val = $_POST['license_email'];
|
1382 |
$license_email = $this->_sanitize( $val );
|
1402 |
|
1403 |
$registration_response = $wpbackitup_license->register_lite($form_data);
|
1404 |
if ( false===$registration_response ) {
|
1405 |
+
WPBackItUp_Logger::log_error($registration_logname,__METHOD__, 'Unable to register using SSL - attempting NONSSL' );
|
1406 |
//try without SSL
|
1407 |
if ( false===$wpbackitup_license->register_lite($form_data,false) ) {
|
1408 |
+
WPBackItUp_Logger::log_error($registration_logname,__METHOD__, 'Unable to register using SSL' );
|
1409 |
}
|
1410 |
}
|
1411 |
}
|
1463 |
public function backup_dbtables_batch_size(){
|
1464 |
return $this->get('backup_dbtables_batch_size');
|
1465 |
}
|
1466 |
+
|
1467 |
+
public function backup_sql_merge_batch_size(){
|
1468 |
+
return $this->get('backup_sql_merge_batch_size');
|
1469 |
+
}
|
1470 |
+
|
1471 |
+
public function backup_sql_batch_size(){
|
1472 |
+
return $this->get('backup_sql_batch_size');
|
1473 |
+
}
|
1474 |
+
|
1475 |
public function backup_plugins_batch_size(){
|
1476 |
return $this->get('backup_plugins_batch_size');
|
1477 |
}
|
1968 |
public static function is_authorized(){
|
1969 |
|
1970 |
$permission_logname='debug_permissions';
|
1971 |
+
WPBackItUp_Logger::log_info($permission_logname,__METHOD__, 'Begin');
|
1972 |
|
1973 |
+
WPBackItUp_Logger::log_info($permission_logname,__METHOD__, 'User Permissions: ' .current_user_can( 'manage_options' ));
|
1974 |
|
1975 |
if (defined('DOING_CRON')) {
|
1976 |
+
WPBackItUp_Logger::log_info($permission_logname,__METHOD__, 'Doing CRON Constant: ' . DOING_CRON );
|
1977 |
} else {
|
1978 |
+
WPBackItUp_Logger::log_info($permission_logname,__METHOD__, 'DOING_CRON - NOT defined');
|
1979 |
}
|
1980 |
|
1981 |
if (defined('XMLRPC_REQUEST')) {
|
1982 |
+
WPBackItUp_Logger::log_info($permission_logname,__METHOD__, 'XMLRPC_REQUEST Constant: ' .XMLRPC_REQUEST );
|
1983 |
} else {
|
1984 |
+
WPBackItUp_Logger::log_info($permission_logname,__METHOD__, 'XMLRPC_REQUEST - NOT defined ');
|
1985 |
}
|
1986 |
|
1987 |
//Check User Permissions or CRON
|
1988 |
if (!current_user_can( 'manage_options' )
|
1989 |
&& (!defined('DOING_CRON') || !DOING_CRON)){
|
1990 |
+
WPBackItUp_Logger::log_info($permission_logname,__METHOD__, 'End - NOT AUTHORIZED');
|
1991 |
return false;
|
1992 |
}
|
1993 |
|
1994 |
+
WPBackItUp_Logger::log_info($permission_logname,__METHOD__, 'End - SUCCESS');
|
1995 |
return true;
|
1996 |
}
|
1997 |
|
2128 |
$process_id = uniqid();
|
2129 |
|
2130 |
$events_logname=sprintf('debug_run_tasks'); //Set Log name
|
2131 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('(%s) Begin', 'DD'));
|
2132 |
|
2133 |
$response = new stdClass();
|
2134 |
$response->success=false; //default to error
|
2137 |
$current_job = WPBackItUp_Job::get_job_by_id($job_id);
|
2138 |
$job_type= $current_job->getJobType();
|
2139 |
$job_run_type= $current_job->getJobRunType();
|
2140 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('(%s) Begin:%s-%s',$job_id,$job_type,$job_run_type));
|
2141 |
|
2142 |
if (false!==$current_job) {
|
2143 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('Job found:(%s)',var_export($current_job,true)));
|
2144 |
|
2145 |
//IF job is active or queued then proceed
|
2146 |
if (WPBackItUp_Job::ACTIVE ==$current_job->getJobStatus() || WPBackItUp_Job::QUEUED==$current_job->getJobStatus() ){
|
2147 |
|
2148 |
//if job lock acquired run tasks
|
2149 |
if (true===$current_job->get_lock('job_lock')) {
|
2150 |
+
WPBackItUp_Logger::log_info( $events_logname, $process_id, sprintf('(%s) Job Lock Acquired.',$job_type));
|
2151 |
|
2152 |
//Try Run Next Task in stack
|
2153 |
$current_task = $current_job->get_next_task();
|
2154 |
+
WPBackItUp_Logger::log_info( $events_logname, $process_id, sprintf( '(%s) TASK INFO:', $job_type ) );
|
2155 |
+
WPBackItUp_Logger::log_info( $events_logname, $process_id, var_export( $current_task, true ) );
|
2156 |
if ( null != $current_task && false !== $current_task ) {
|
2157 |
+
WPBackItUp_Logger::log_info( $events_logname, $process_id, sprintf( '(%s) Available Task Found: %s', $job_type, $current_task->getTaskId() ) );
|
2158 |
|
2159 |
$current_task->increment_retry_count();
|
2160 |
|
2161 |
//Was there an error on the previous run
|
2162 |
if ( WPBackItUp_Job::ERROR == $current_task->getStatus() ) {
|
2163 |
//Log error but error handling should happen in include
|
2164 |
+
WPBackItUp_Logger::log_error( $events_logname, $process_id, sprintf( '(%s) Error Found Previous run: %s', $job_type, $current_task->getTaskId() ) );
|
2165 |
}
|
2166 |
|
2167 |
//Run the task
|
2168 |
+
WPBackItUp_Logger::log_info( $events_logname, $process_id, sprintf( '(%s) Try Run Task: %s', $job_type, $current_task->getTaskId() ));
|
2169 |
|
2170 |
$this->backup_type = $job_run_type;
|
2171 |
$job_include_path = sprintf( WPBACKITUP__PLUGIN_PATH . '/lib/includes/job_%s.php', $job_type );
|
2173 |
//error_log('run script');
|
2174 |
require_once( $job_include_path ); //Run tasks from job file
|
2175 |
|
2176 |
+
WPBackItUp_Logger::log_info( $events_logname, $process_id, sprintf( '(%s) End Try Run Task:%s', $job_type, $current_task->getTaskId() ) );
|
2177 |
} else {
|
2178 |
+
WPBackItUp_Logger::log_info( $events_logname, $process_id, sprintf( '(%s)No available tasks found.', $job_type ));
|
2179 |
return;
|
2180 |
}
|
2181 |
|
2182 |
$current_job->release_lock();
|
2183 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id ,sprintf('(%s)Lock Released.',$job_type));
|
2184 |
|
2185 |
} else {
|
2186 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('(%s) Job Lock NOT Acquired.',$job_type));
|
2187 |
}
|
2188 |
}else {
|
2189 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('(%s) Job not active or queued status:',$job_type));
|
2190 |
}
|
2191 |
|
2192 |
} else {
|
2193 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('(%s) No jobs found.',$job_type));
|
2194 |
}
|
2195 |
|
2196 |
}
|
2197 |
|
2198 |
// $job type could cause error if there is no $job_id
|
2199 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id, sprintf('(%s) End',$job_type));
|
2200 |
}
|
2201 |
|
2202 |
|
lib/includes/class-zip.php
CHANGED
@@ -1 +1 @@
|
|
1 |
-
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
2 |
* WP BackItUp - Zip Class
|
3 |
*
|
4 |
* @package WP BackItUp
|
5 |
* @author Chris Simmons <chris.simmons@wpbackitup.com>
|
6 |
* @link http://www.wpbackitup.com
|
7 |
*
|
8 |
*/
|
9 |
private $zip_file_count;
|
10 |
}
|
|
|
11 |
* WP BackItUp - Zip Class
|
12 |
*
|
13 |
* @package WP BackItUp
|
14 |
* @author Chris Simmons <chris.simmons@wpbackitup.com>
|
15 |
* @link http://www.wpbackitup.com
|
16 |
*
|
17 |
*/
|
18 |
private $zip_file_count;
|
19 |
}
|
|
|
1 |
* WP BackItUp - Zip Class
|
2 |
*
|
3 |
* @package WP BackItUp
|
4 |
* @author Chris Simmons <chris.simmons@wpbackitup.com>
|
5 |
* @link http://www.wpbackitup.com
|
6 |
*
|
7 |
*/
|
8 |
private $zip_file_count;
|
9 |
}
|
10 |
+
<?php if (!defined ('ABSPATH')) die('No direct access allowed');
|
11 |
* WP BackItUp - Zip Class
|
12 |
*
|
13 |
* @package WP BackItUp
|
14 |
* @author Chris Simmons <chris.simmons@wpbackitup.com>
|
15 |
* @link http://www.wpbackitup.com
|
16 |
*
|
17 |
*/
|
18 |
private $zip_file_count;
|
19 |
}
|
lib/includes/handler_download.php
CHANGED
@@ -24,13 +24,13 @@ while (@ob_end_clean());
|
|
24 |
@ini_set('zlib.output_compression', 'Off');
|
25 |
$download_logname='debug_download';
|
26 |
|
27 |
-
|
28 |
|
29 |
if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
30 |
&& isset($_REQUEST['backup_file']) && !empty($_REQUEST['backup_file']) ) {
|
31 |
|
32 |
if ( wp_verify_nonce( $_REQUEST['_wpnonce'], WPBACKITUP__NAMESPACE . '-download_backup' ) ) {
|
33 |
-
|
34 |
|
35 |
//strip off the suffix IF one exists
|
36 |
$folder_name = rtrim( $_REQUEST['backup_file'], '.zip' );
|
@@ -71,11 +71,11 @@ if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
|
71 |
if (isset($_REQUEST['download_logs']) && $_REQUEST['download_logs'] == '1') {
|
72 |
$log_filename = $_REQUEST['backup_file'];
|
73 |
$backup_path = WPBACKITUP__LOGS_PATH . '/'. $log_filename;
|
74 |
-
|
75 |
}else{
|
76 |
$backup_filename = $_REQUEST['backup_file'];
|
77 |
$backup_path = WPBACKITUP__BACKUP_PATH . '/' . $folder_name . '/' . $backup_filename;
|
78 |
-
|
79 |
}
|
80 |
|
81 |
if ( (!empty($backup_filename) || !empty($log_filename) ) && file_exists( $backup_path ) ) {
|
@@ -88,7 +88,7 @@ if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
|
88 |
if ($handle !== false) {
|
89 |
//Have the headers already been sent for some reason
|
90 |
if (headers_sent()) {
|
91 |
-
|
92 |
}
|
93 |
|
94 |
//Output Headers
|
@@ -111,20 +111,20 @@ if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
|
111 |
}
|
112 |
|
113 |
fclose($handle);
|
114 |
-
|
115 |
exit();
|
116 |
|
117 |
} else {
|
118 |
-
|
119 |
}
|
120 |
} else {
|
121 |
-
|
122 |
}
|
123 |
} else {
|
124 |
-
|
125 |
}
|
126 |
} else {
|
127 |
-
|
128 |
}
|
129 |
|
130 |
//Return empty file
|
24 |
@ini_set('zlib.output_compression', 'Off');
|
25 |
$download_logname='debug_download';
|
26 |
|
27 |
+
WPBackItUp_Logger::log($download_logname,$_REQUEST);
|
28 |
|
29 |
if ( isset($_REQUEST['_wpnonce']) && !empty($_REQUEST['_wpnonce'])
|
30 |
&& isset($_REQUEST['backup_file']) && !empty($_REQUEST['backup_file']) ) {
|
31 |
|
32 |
if ( wp_verify_nonce( $_REQUEST['_wpnonce'], WPBACKITUP__NAMESPACE . '-download_backup' ) ) {
|
33 |
+
WPBackItUp_Logger::log_info($download_logname,__METHOD__,'nonce verified' );
|
34 |
|
35 |
//strip off the suffix IF one exists
|
36 |
$folder_name = rtrim( $_REQUEST['backup_file'], '.zip' );
|
71 |
if (isset($_REQUEST['download_logs']) && $_REQUEST['download_logs'] == '1') {
|
72 |
$log_filename = $_REQUEST['backup_file'];
|
73 |
$backup_path = WPBACKITUP__LOGS_PATH . '/'. $log_filename;
|
74 |
+
WPBackItUp_Logger::log_info($download_logname,__METHOD__,'Backup file path:' . $backup_path );
|
75 |
}else{
|
76 |
$backup_filename = $_REQUEST['backup_file'];
|
77 |
$backup_path = WPBACKITUP__BACKUP_PATH . '/' . $folder_name . '/' . $backup_filename;
|
78 |
+
WPBackItUp_Logger::log_info($download_logname,__METHOD__,'Backup file path:' . $backup_path );
|
79 |
}
|
80 |
|
81 |
if ( (!empty($backup_filename) || !empty($log_filename) ) && file_exists( $backup_path ) ) {
|
88 |
if ($handle !== false) {
|
89 |
//Have the headers already been sent for some reason
|
90 |
if (headers_sent()) {
|
91 |
+
WPBackItUp_Logger::log_error($download_logname,__METHOD__,'Headers already sent.' );
|
92 |
}
|
93 |
|
94 |
//Output Headers
|
111 |
}
|
112 |
|
113 |
fclose($handle);
|
114 |
+
WPBackItUp_Logger::log_info($download_logname,__METHOD__,'Download complete' );
|
115 |
exit();
|
116 |
|
117 |
} else {
|
118 |
+
WPBackItUp_Logger::log_error($download_logname,__METHOD__,'File Not found' );
|
119 |
}
|
120 |
} else {
|
121 |
+
WPBackItUp_Logger::log_error($download_logname,__METHOD__,'Backup file doesnt exist:' . $backup_path );
|
122 |
}
|
123 |
} else {
|
124 |
+
WPBackItUp_Logger::log_error($download_logname,__METHOD__,'Bad Nonce');
|
125 |
}
|
126 |
} else {
|
127 |
+
WPBackItUp_Logger::log_error($download_logname,__METHOD__,'Form data missing');
|
128 |
}
|
129 |
|
130 |
//Return empty file
|
lib/includes/handler_upload.php
CHANGED
@@ -19,13 +19,13 @@
|
|
19 |
//*****************//
|
20 |
//*** MAIN CODE ***//
|
21 |
//*****************//
|
22 |
-
|
23 |
-
|
24 |
|
25 |
|
26 |
//verify nonce
|
27 |
if ( !wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-upload')) {
|
28 |
-
|
29 |
echo json_encode( array( 'error' => sprintf( __( 'Invalid Nonce','wp-backitup' ) ) ) );
|
30 |
exit;
|
31 |
|
@@ -35,7 +35,7 @@
|
|
35 |
$upload_path = WPBACKITUP__UPLOAD_PATH;
|
36 |
if ( !is_dir( $upload_path ) ){
|
37 |
if ( ! mkdir( $upload_path, 0755 )){
|
38 |
-
|
39 |
echo json_encode( array( 'error' => sprintf( __( "Upload directory is not writable, or does not exist.", 'wp-backitup' ) ) ) );
|
40 |
exit;
|
41 |
}
|
@@ -64,7 +64,7 @@
|
|
64 |
remove_filter( 'sanitize_file_name', array( $this, 'sanitize_file_name' ) );
|
65 |
|
66 |
if ( isset( $status['error'] ) ) {
|
67 |
-
|
68 |
echo json_encode( array( 'error' => $status['error'] ) );
|
69 |
exit;
|
70 |
}
|
@@ -76,7 +76,7 @@
|
|
76 |
$to_file_path = $upload_path . '/' . $zip_file_name . '_' . $chunk_id . '.zip.tmp';
|
77 |
if ( ! rename( $from_file_path, $to_file_path ) ) {
|
78 |
@unlink( $from_file_path );
|
79 |
-
|
80 |
echo json_encode( array( 'error' => sprintf( __( 'Error: %s', 'wp-backitup' ), __( 'File could not be uploaded', 'wp-backitup' ) ) ) );
|
81 |
exit;
|
82 |
}
|
@@ -142,7 +142,7 @@
|
|
142 |
|
143 |
//Is this a BackItUp archive
|
144 |
if ( empty( $folder_name ) || empty( $suffix )) {
|
145 |
-
|
146 |
echo json_encode( array( 'error' => sprintf( __( "Upload does not appear to be a WPBackItUp backup archive file.",'wp-backitup' ) ) ) );
|
147 |
unlink( $zip_file_path );//get rid of it
|
148 |
exit;
|
@@ -152,7 +152,7 @@
|
|
152 |
$backup_archive_folder = WPBACKITUP__BACKUP_PATH . '/' . $folder_name;
|
153 |
if ( ! is_dir( $backup_archive_folder ) ) {
|
154 |
if ( ! mkdir( $backup_archive_folder, 0755 ) ) {
|
155 |
-
|
156 |
echo json_encode( array( 'error' => sprintf( __( "Upload directory is not writable, or does not exist.", 'wp-backitup' ) ) ) );
|
157 |
exit;
|
158 |
}
|
@@ -162,12 +162,12 @@
|
|
162 |
//will overwrite if exists
|
163 |
$target_file = $backup_archive_folder . "/" . basename( $zip_file_path );
|
164 |
if ( ! rename( $zip_file_path, $target_file ) ) {
|
165 |
-
|
166 |
echo json_encode( array( 'error' => sprintf( __( "Could not import file into WPBackItUp backup set.",'wp-backitup' ) ) ) );
|
167 |
exit;
|
168 |
} else {
|
169 |
|
170 |
-
|
171 |
$folder_prefix = substr($folder_name,0,4);
|
172 |
$folder_name_parts = explode('_',$folder_name);
|
173 |
|
@@ -180,29 +180,29 @@
|
|
180 |
$jobs = WPBackItUp_Job::get_jobs_by_job_name(WPBackItUp_Job::BACKUP,$folder_name,WPBackItUp_Job::COMPLETE);
|
181 |
|
182 |
if ( false === $jobs ) {
|
183 |
-
|
184 |
$job_id=current_time('timestamp');//Create new job id just in case there are deleted job cnotrol records
|
185 |
$job = WPBackItUp_Job::import_completed_job( $folder_name, $job_id, WPBackItUp_Job::BACKUP, $job_id );
|
186 |
|
187 |
} else {
|
188 |
-
|
189 |
$job = is_array($jobs) ? current($jobs) : false;
|
190 |
}
|
191 |
|
192 |
-
|
193 |
|
194 |
|
195 |
if ( false !== $job ) {
|
196 |
-
|
197 |
|
198 |
$file_system = new WPBackItUp_FileSystem($upload_logname);
|
199 |
$zip_files = $file_system->get_fileonly_list_with_filesize($backup_archive_folder, 'zip');
|
200 |
|
201 |
-
|
202 |
|
203 |
$job->setJobMetaValue('backup_zip_files',$zip_files); //list of zip files
|
204 |
|
205 |
-
|
206 |
}
|
207 |
}
|
208 |
}
|
@@ -210,7 +210,7 @@
|
|
210 |
}
|
211 |
}
|
212 |
|
213 |
-
|
214 |
|
215 |
// send the uploaded file url in response
|
216 |
$response['success'] = $status['url'];
|
19 |
//*****************//
|
20 |
//*** MAIN CODE ***//
|
21 |
//*****************//
|
22 |
+
WPBackItUp_Logger::log($upload_logname,'***BEGIN UPLOAD***');
|
23 |
+
WPBackItUp_Logger::log($upload_logname,$_POST);
|
24 |
|
25 |
|
26 |
//verify nonce
|
27 |
if ( !wp_verify_nonce($_REQUEST['_wpnonce'],WPBACKITUP__NAMESPACE .'-upload')) {
|
28 |
+
WPBackItUp_Logger::log_error($upload_logname,__METHOD__,'Invalid Nonce');
|
29 |
echo json_encode( array( 'error' => sprintf( __( 'Invalid Nonce','wp-backitup' ) ) ) );
|
30 |
exit;
|
31 |
|
35 |
$upload_path = WPBACKITUP__UPLOAD_PATH;
|
36 |
if ( !is_dir( $upload_path ) ){
|
37 |
if ( ! mkdir( $upload_path, 0755 )){
|
38 |
+
WPBackItUp_Logger::log_error($upload_logname,__METHOD__,'Upload directory is not writable, or does not exist.');
|
39 |
echo json_encode( array( 'error' => sprintf( __( "Upload directory is not writable, or does not exist.", 'wp-backitup' ) ) ) );
|
40 |
exit;
|
41 |
}
|
64 |
remove_filter( 'sanitize_file_name', array( $this, 'sanitize_file_name' ) );
|
65 |
|
66 |
if ( isset( $status['error'] ) ) {
|
67 |
+
WPBackItUp_Logger::log($upload_logname,$status['error']);
|
68 |
echo json_encode( array( 'error' => $status['error'] ) );
|
69 |
exit;
|
70 |
}
|
76 |
$to_file_path = $upload_path . '/' . $zip_file_name . '_' . $chunk_id . '.zip.tmp';
|
77 |
if ( ! rename( $from_file_path, $to_file_path ) ) {
|
78 |
@unlink( $from_file_path );
|
79 |
+
WPBackItUp_Logger::log_error($upload_logname,__METHOD__,'Cant rename file.');
|
80 |
echo json_encode( array( 'error' => sprintf( __( 'Error: %s', 'wp-backitup' ), __( 'File could not be uploaded', 'wp-backitup' ) ) ) );
|
81 |
exit;
|
82 |
}
|
142 |
|
143 |
//Is this a BackItUp archive
|
144 |
if ( empty( $folder_name ) || empty( $suffix )) {
|
145 |
+
WPBackItUp_Logger::log_error($upload_logname,__METHOD__,'Upload does not appear to be a WPBackItUp backup archive');
|
146 |
echo json_encode( array( 'error' => sprintf( __( "Upload does not appear to be a WPBackItUp backup archive file.",'wp-backitup' ) ) ) );
|
147 |
unlink( $zip_file_path );//get rid of it
|
148 |
exit;
|
152 |
$backup_archive_folder = WPBACKITUP__BACKUP_PATH . '/' . $folder_name;
|
153 |
if ( ! is_dir( $backup_archive_folder ) ) {
|
154 |
if ( ! mkdir( $backup_archive_folder, 0755 ) ) {
|
155 |
+
WPBackItUp_Logger::log_error($upload_logname,__METHOD__,'Upload directory is not writable');
|
156 |
echo json_encode( array( 'error' => sprintf( __( "Upload directory is not writable, or does not exist.", 'wp-backitup' ) ) ) );
|
157 |
exit;
|
158 |
}
|
162 |
//will overwrite if exists
|
163 |
$target_file = $backup_archive_folder . "/" . basename( $zip_file_path );
|
164 |
if ( ! rename( $zip_file_path, $target_file ) ) {
|
165 |
+
WPBackItUp_Logger::log_error($upload_logname,__METHOD__,'Cant move zip file to backup folder');
|
166 |
echo json_encode( array( 'error' => sprintf( __( "Could not import file into WPBackItUp backup set.",'wp-backitup' ) ) ) );
|
167 |
exit;
|
168 |
} else {
|
169 |
|
170 |
+
WPBackItUp_Logger::log($upload_logname,'Import Backup To Post Table Started');
|
171 |
$folder_prefix = substr($folder_name,0,4);
|
172 |
$folder_name_parts = explode('_',$folder_name);
|
173 |
|
180 |
$jobs = WPBackItUp_Job::get_jobs_by_job_name(WPBackItUp_Job::BACKUP,$folder_name,WPBackItUp_Job::COMPLETE);
|
181 |
|
182 |
if ( false === $jobs ) {
|
183 |
+
WPBackItUp_Logger::log($upload_logname,'Import job');
|
184 |
$job_id=current_time('timestamp');//Create new job id just in case there are deleted job cnotrol records
|
185 |
$job = WPBackItUp_Job::import_completed_job( $folder_name, $job_id, WPBackItUp_Job::BACKUP, $job_id );
|
186 |
|
187 |
} else {
|
188 |
+
WPBackItUp_Logger::log($upload_logname,'Selecting Existing Post.');
|
189 |
$job = is_array($jobs) ? current($jobs) : false;
|
190 |
}
|
191 |
|
192 |
+
WPBackItUp_Logger::log($upload_logname,$job);
|
193 |
|
194 |
|
195 |
if ( false !== $job ) {
|
196 |
+
WPBackItUp_Logger::log($upload_logname,'### Update Zip Files ###');
|
197 |
|
198 |
$file_system = new WPBackItUp_FileSystem($upload_logname);
|
199 |
$zip_files = $file_system->get_fileonly_list_with_filesize($backup_archive_folder, 'zip');
|
200 |
|
201 |
+
WPBackItUp_Logger::log($upload_logname,$zip_files);
|
202 |
|
203 |
$job->setJobMetaValue('backup_zip_files',$zip_files); //list of zip files
|
204 |
|
205 |
+
WPBackItUp_Logger::log_info($upload_logname,__METHOD__,'Job Imported:' .$folder_name);
|
206 |
}
|
207 |
}
|
208 |
}
|
210 |
}
|
211 |
}
|
212 |
|
213 |
+
WPBackItUp_Logger::log_info($upload_logname,__METHOD__,'End');
|
214 |
|
215 |
// send the uploaded file url in response
|
216 |
$response['success'] = $status['url'];
|
lib/includes/job_backup.php
CHANGED
@@ -80,18 +80,18 @@ $status_array = array(
|
|
80 |
//*****************//
|
81 |
|
82 |
if (! is_object ($current_job)){
|
83 |
-
|
84 |
-
|
85 |
return false;
|
86 |
}
|
87 |
|
88 |
if (! is_object ($current_task)){
|
89 |
-
|
90 |
-
|
91 |
return false;
|
92 |
}
|
93 |
|
94 |
-
|
95 |
|
96 |
//*************************//
|
97 |
//*** MAIN BACKUP CODE ***//
|
@@ -111,15 +111,15 @@ $wp_backup = new WPBackItUp_Backup($backup_logname,$backup_name,$WPBackitup->bac
|
|
111 |
//*** BACKUP TASKS ***//
|
112 |
//*************************//
|
113 |
|
114 |
-
|
115 |
|
116 |
//An error has occurred on the previous tasks
|
117 |
if (WPBackItUp_Job::ERROR==$current_task->getStatus()){
|
118 |
-
|
119 |
|
120 |
//Fetch last wordpress error(might not be related to timeout)
|
121 |
//error type constants: http://php.net/manual/en/errorfunc.constants.php
|
122 |
-
|
123 |
|
124 |
//Check for error type
|
125 |
switch ($current_task->getTaskName()) {
|
@@ -210,15 +210,15 @@ if (WPBackItUp_Job::ERROR==$current_task->getStatus()){
|
|
210 |
if ('task_preparing'==$current_task->getTaskName()) {
|
211 |
|
212 |
//Init
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
|
218 |
$WPBackitup->increment_backup_count();
|
219 |
//End Init
|
220 |
|
221 |
-
|
222 |
|
223 |
//Cleanup & Validate the backup folded is ready
|
224 |
write_response_processing("preparing for backup");
|
@@ -228,7 +228,7 @@ if ('task_preparing'==$current_task->getTaskName()) {
|
|
228 |
|
229 |
//*** Check Dependencies ***
|
230 |
if ( ! WPBackItUp_Zip::zip_utility_exists()) {
|
231 |
-
|
232 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,125);
|
233 |
write_fatal_error_status( '125' );
|
234 |
end_backup( 125, false );
|
@@ -268,12 +268,12 @@ if ('task_preparing'==$current_task->getTaskName()) {
|
|
268 |
set_status('preparing',$complete,false);
|
269 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
270 |
|
271 |
-
|
272 |
return;
|
273 |
}
|
274 |
|
275 |
if ('task_inventory_database'==$current_task->getTaskName()) {
|
276 |
-
|
277 |
|
278 |
write_response_processing( "Create inventory" );
|
279 |
set_status( 'create_inventory', $active, true );
|
@@ -292,7 +292,7 @@ if ('task_inventory_database'==$current_task->getTaskName()) {
|
|
292 |
$batch_size = $WPBackitup->backup_dbtables_batch_size();
|
293 |
|
294 |
if ( ! $wp_backup->save_database_inventory($current_job->getJobId(), WPBackItUp_Job_Item::DATABASE, $batch_size, $tables_exclude ) ) {
|
295 |
-
|
296 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
297 |
|
298 |
write_fatal_error_status( '127' );
|
@@ -302,17 +302,17 @@ if ('task_inventory_database'==$current_task->getTaskName()) {
|
|
302 |
};
|
303 |
|
304 |
|
305 |
-
|
306 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
307 |
|
308 |
-
|
309 |
return;
|
310 |
|
311 |
}
|
312 |
|
313 |
|
314 |
if ('task_inventory_plugins'==$current_task->getTaskName()) {
|
315 |
-
|
316 |
|
317 |
write_response_processing( "Create inventory" );
|
318 |
set_status( 'create_inventory', $active, true );
|
@@ -330,11 +330,12 @@ if ('task_inventory_plugins'==$current_task->getTaskName()) {
|
|
330 |
$backup_plugins_filter,
|
331 |
array(
|
332 |
"wp-backitup",
|
|
|
333 |
)
|
334 |
);
|
335 |
|
336 |
if ( ! $wp_backup->save_folder_inventory( WPBACKITUP__SQL_BULK_INSERT_SIZE, $current_job->getJobId(), WPBackItUp_Job_Item::PLUGINS, WPBACKITUP__PLUGINS_ROOT_PATH, $plugin_exclude ) ) {
|
337 |
-
|
338 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
339 |
|
340 |
write_fatal_error_status( '127' );
|
@@ -344,12 +345,12 @@ if ('task_inventory_plugins'==$current_task->getTaskName()) {
|
|
344 |
};
|
345 |
|
346 |
|
347 |
-
|
348 |
|
349 |
//set_status('inventory',$complete,false);
|
350 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
351 |
|
352 |
-
|
353 |
return;
|
354 |
|
355 |
}
|
@@ -357,7 +358,7 @@ if ('task_inventory_plugins'==$current_task->getTaskName()) {
|
|
357 |
|
358 |
|
359 |
if ('task_inventory_themes'==$current_task->getTaskName()) {
|
360 |
-
|
361 |
|
362 |
$global_exclude = explode(',', WPBACKITUP__BACKUP_GLOBAL_IGNORE_LIST);
|
363 |
|
@@ -374,7 +375,7 @@ if ('task_inventory_themes'==$current_task->getTaskName()) {
|
|
374 |
);
|
375 |
|
376 |
if (! $wp_backup->save_folder_inventory(WPBACKITUP__SQL_BULK_INSERT_SIZE,$current_job->getJobId(),WPBackItUp_Job_Item::THEMES,WPBACKITUP__THEMES_ROOT_PATH,$theme_exclude)){
|
377 |
-
|
378 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
379 |
|
380 |
write_fatal_error_status('127');
|
@@ -382,17 +383,17 @@ if ('task_inventory_themes'==$current_task->getTaskName()) {
|
|
382 |
return false;
|
383 |
};
|
384 |
|
385 |
-
|
386 |
|
387 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
388 |
|
389 |
-
|
390 |
return;
|
391 |
|
392 |
}
|
393 |
|
394 |
if ('task_inventory_uploads'==$current_task->getTaskName()) {
|
395 |
-
|
396 |
|
397 |
$global_exclude = explode(',', WPBACKITUP__BACKUP_GLOBAL_IGNORE_LIST);
|
398 |
// Getting user filter
|
@@ -421,7 +422,7 @@ if ('task_inventory_uploads'==$current_task->getTaskName()) {
|
|
421 |
$upload_array = wp_upload_dir();
|
422 |
$uploads_root_path = $upload_array['basedir'];
|
423 |
if (! $wp_backup->save_folder_inventory(WPBACKITUP__SQL_BULK_INSERT_SIZE,$current_job->getJobId(),WPBackItUp_Job_Item::UPLOADS,$uploads_root_path,$upload_exclude)){
|
424 |
-
|
425 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
426 |
|
427 |
write_fatal_error_status('127');
|
@@ -429,16 +430,16 @@ if ('task_inventory_uploads'==$current_task->getTaskName()) {
|
|
429 |
return false;
|
430 |
};
|
431 |
|
432 |
-
|
433 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
434 |
|
435 |
-
|
436 |
return;
|
437 |
|
438 |
}
|
439 |
|
440 |
if ('task_inventory_others'==$current_task->getTaskName()) {
|
441 |
-
|
442 |
|
443 |
$global_exclude = explode(',', WPBACKITUP__BACKUP_GLOBAL_IGNORE_LIST);
|
444 |
// Getting user filter
|
@@ -475,7 +476,7 @@ if ('task_inventory_others'==$current_task->getTaskName()) {
|
|
475 |
));
|
476 |
|
477 |
if (! $wp_backup->save_folder_inventory(WPBACKITUP__SQL_BULK_INSERT_SIZE,$current_job->getJobId(),WPBackItUp_Job_Item::OTHERS,WPBACKITUP__CONTENT_PATH,$other_exclude)){
|
478 |
-
|
479 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
480 |
|
481 |
write_fatal_error_status('127');
|
@@ -483,20 +484,20 @@ if ('task_inventory_others'==$current_task->getTaskName()) {
|
|
483 |
return false;
|
484 |
};
|
485 |
|
486 |
-
|
487 |
|
488 |
//when others is done then update the task as completed
|
489 |
//set_status('create_inventory',$complete,false);
|
490 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
491 |
|
492 |
-
|
493 |
return;
|
494 |
|
495 |
}
|
496 |
|
497 |
//Create the site info file
|
498 |
if ('task_backup_siteinfo'==$current_task->getTaskName()) {
|
499 |
-
|
500 |
|
501 |
if ( $wp_backup->create_siteinfo_file($current_job->getJobId())) {
|
502 |
|
@@ -513,7 +514,7 @@ if ('task_backup_siteinfo'==$current_task->getTaskName()) {
|
|
513 |
set_status( 'create_inventory', $complete, false );
|
514 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
515 |
|
516 |
-
|
517 |
|
518 |
} else {
|
519 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,105);
|
@@ -528,7 +529,7 @@ if ('task_backup_siteinfo'==$current_task->getTaskName()) {
|
|
528 |
|
529 |
//Backup the database
|
530 |
if ('task_export_db'==$current_task->getTaskName()) {
|
531 |
-
|
532 |
write_response_processing( "Create database export" );
|
533 |
set_status( 'exportdb', $active, true );
|
534 |
|
@@ -542,7 +543,7 @@ if ('task_export_db'==$current_task->getTaskName()) {
|
|
542 |
|
543 |
$tables_remaining_count = $wp_backup->export_database_wpbackitup($current_job,WPBackItUp_Job_Item::DATABASE,$batch_size);
|
544 |
|
545 |
-
|
546 |
if (false===$tables_remaining_count) {
|
547 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,104);
|
548 |
write_fatal_error_status( '104' );
|
@@ -552,15 +553,15 @@ if ('task_export_db'==$current_task->getTaskName()) {
|
|
552 |
$current_task->setTaskMetaValue('db_mysqldump_path',$db_mysqldump_path);
|
553 |
if ($tables_remaining_count>0){
|
554 |
//CONTINUE
|
555 |
-
|
556 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
557 |
}else{
|
558 |
//COMPLETE
|
559 |
-
|
560 |
|
561 |
//set_status( 'exportdb', $complete, false );
|
562 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
563 |
-
|
564 |
}
|
565 |
}
|
566 |
|
@@ -572,86 +573,129 @@ if ('task_export_db'==$current_task->getTaskName()) {
|
|
572 |
//File for ref only so dont stop on error
|
573 |
if ('task_merge_sql'==$current_task->getTaskName()) {
|
574 |
|
575 |
-
|
576 |
-
write_response_processing( "Create single SQL File" );
|
577 |
-
//set_status( 'exportdb', $active, true );
|
578 |
|
579 |
if (true===$WPBackitup->single_file_db()){
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
}else{
|
597 |
-
|
598 |
-
}
|
599 |
|
600 |
-
|
601 |
-
|
602 |
-
|
|
|
|
|
603 |
|
604 |
return;
|
605 |
|
606 |
}
|
607 |
|
608 |
-
//TODO:
|
609 |
-
//Can store the file list in the task meta BUT need to handle the site info file condition at the top. Needs to be in the first pass only
|
610 |
-
//also change the db task names to export DB and zip or backup database
|
611 |
|
612 |
//Extract the site info
|
613 |
if ('task_backup_db'==$current_task->getTaskName()) {
|
614 |
-
|
615 |
write_response_processing( "Backup Database" );
|
616 |
set_status( 'backupdb', $active, true );
|
617 |
|
618 |
$file_system = new WPBackItUp_FileSystem($backup_logname);
|
619 |
-
$site_data_files = $file_system->get_fileonly_list($wp_backup->getBackupProjectPath(), 'txt|sql|db|config|crypt');
|
620 |
-
WPBackItUp_LoggerV2::log_info($backup_logname,__METHOD__, 'Main Files Found:' . var_export($site_data_files,true));
|
621 |
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
626 |
|
|
|
|
|
|
|
|
|
627 |
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
633 |
write_fatal_error_status( '135' );
|
634 |
end_backup( 135, false );
|
635 |
return false;
|
636 |
} else {
|
637 |
-
if ($
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
638 |
|
639 |
-
|
640 |
-
|
641 |
-
|
|
|
642 |
|
643 |
-
|
644 |
-
|
645 |
-
return false;
|
646 |
|
647 |
-
|
648 |
//get rid of the SQL and sitedata file - will check again at end in cleanup
|
649 |
$wp_backup->cleanup_current_backup_async('txt|sql|db|config|crypt');
|
650 |
|
651 |
set_status( 'backupdb', $complete, false );
|
652 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
653 |
|
654 |
-
|
655 |
}
|
656 |
}
|
657 |
|
@@ -661,15 +705,15 @@ if ('task_backup_db'==$current_task->getTaskName()) {
|
|
661 |
|
662 |
//Backup the themes
|
663 |
if ('task_backup_themes'==$current_task->getTaskName()) {
|
664 |
-
|
665 |
write_response_processing( "Backup themes " );
|
666 |
set_status( 'backup_themes', $active, true );
|
667 |
|
668 |
$themes_remaining_files_count = $wp_backup->backup_files($current_job->getJobId(),WPBACKITUP__THEMES_ROOT_PATH,WPBackItUp_Job_Item::THEMES);
|
669 |
-
|
670 |
if ($themes_remaining_files_count===false) {
|
671 |
//ERROR
|
672 |
-
|
673 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,120);
|
674 |
write_fatal_error_status( '120' );
|
675 |
end_backup( 120, false );
|
@@ -677,15 +721,15 @@ if ('task_backup_themes'==$current_task->getTaskName()) {
|
|
677 |
}else{
|
678 |
if ($themes_remaining_files_count>0){
|
679 |
//CONTINUE
|
680 |
-
|
681 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
682 |
}else{
|
683 |
//COMPLETE
|
684 |
-
|
685 |
|
686 |
set_status( 'backup_themes', $complete, false );
|
687 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
688 |
-
|
689 |
}
|
690 |
}
|
691 |
|
@@ -695,15 +739,15 @@ if ('task_backup_themes'==$current_task->getTaskName()) {
|
|
695 |
|
696 |
//Backup the plugins
|
697 |
if ('task_backup_plugins'==$current_task->getTaskName()) {
|
698 |
-
|
699 |
write_response_processing( "Backup plugins " );
|
700 |
set_status( 'backup_plugins', $active, true );
|
701 |
|
702 |
$plugins_remaining_files_count = $wp_backup->backup_files($current_job->getJobId(),WPBACKITUP__PLUGINS_ROOT_PATH,WPBackItUp_Job_Item::PLUGINS);
|
703 |
-
|
704 |
if ($plugins_remaining_files_count===false) {
|
705 |
//ERROR
|
706 |
-
|
707 |
|
708 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,121);
|
709 |
write_fatal_error_status( '121' );
|
@@ -712,14 +756,14 @@ if ('task_backup_plugins'==$current_task->getTaskName()) {
|
|
712 |
} else {
|
713 |
if ($plugins_remaining_files_count>0){
|
714 |
//CONTINUE
|
715 |
-
|
716 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
717 |
} else{
|
718 |
//COMPLETE
|
719 |
-
|
720 |
set_status( 'backup_plugins', $complete, false );
|
721 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
722 |
-
|
723 |
}
|
724 |
}
|
725 |
|
@@ -728,7 +772,7 @@ if ('task_backup_plugins'==$current_task->getTaskName()) {
|
|
728 |
|
729 |
//Backup the uploads
|
730 |
if ('task_backup_uploads'==$current_task->getTaskName()) {
|
731 |
-
|
732 |
write_response_processing( "Backup uploads " );
|
733 |
set_status( 'backup_uploads', $active, true );
|
734 |
|
@@ -737,10 +781,10 @@ if ('task_backup_uploads'==$current_task->getTaskName()) {
|
|
737 |
|
738 |
//exclude zip files from backup
|
739 |
$uploads_remaining_files_count = $wp_backup->backup_files($current_job->getJobId(),$source_uploads_root,WPBackItUp_Job_Item::UPLOADS);
|
740 |
-
|
741 |
if ( $uploads_remaining_files_count ===false) {
|
742 |
//ERROR
|
743 |
-
|
744 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,122);
|
745 |
|
746 |
write_fatal_error_status( '122' );
|
@@ -749,15 +793,15 @@ if ('task_backup_uploads'==$current_task->getTaskName()) {
|
|
749 |
} else {
|
750 |
if ( $uploads_remaining_files_count > 0 ) {
|
751 |
//CONTINUE
|
752 |
-
|
753 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
754 |
|
755 |
} else {
|
756 |
//COMPLETE
|
757 |
-
|
758 |
set_status( 'backup_uploads', $complete, false );
|
759 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
760 |
-
|
761 |
}
|
762 |
}
|
763 |
|
@@ -766,15 +810,15 @@ if ('task_backup_uploads'==$current_task->getTaskName()) {
|
|
766 |
|
767 |
//Backup all the other content in the wp-content root
|
768 |
if ('task_backup_other'==$current_task->getTaskName()) {
|
769 |
-
|
770 |
write_response_processing( "Backup other files " );
|
771 |
set_status( 'backup_other', $active, true );
|
772 |
|
773 |
$others_remaining_files_count = $wp_backup->backup_files($current_job->getJobId(),WPBACKITUP__CONTENT_PATH,WPBackItUp_Job_Item::OTHERS);
|
774 |
-
|
775 |
if ( $others_remaining_files_count ===false) {
|
776 |
//ERROR
|
777 |
-
|
778 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,123);
|
779 |
|
780 |
write_fatal_error_status( '123' );
|
@@ -783,15 +827,15 @@ if ('task_backup_other'==$current_task->getTaskName()) {
|
|
783 |
} else {
|
784 |
if ( $others_remaining_files_count > 0 ) {
|
785 |
//CONTINUE
|
786 |
-
|
787 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
788 |
} else {
|
789 |
//COMPLETE
|
790 |
-
|
791 |
|
792 |
set_status( 'backup_other', $complete, false );
|
793 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
794 |
-
|
795 |
}
|
796 |
|
797 |
}
|
@@ -803,7 +847,7 @@ if ('task_backup_other'==$current_task->getTaskName()) {
|
|
803 |
//Validate the backup IF logging is turned on - reporting only
|
804 |
if ('task_validate_backup'==$current_task->getTaskName()) {
|
805 |
//Validate the content if logging is on
|
806 |
-
|
807 |
|
808 |
write_response_processing( "Validating Backup " );
|
809 |
set_status( 'validate_backup', $active, true );
|
@@ -840,7 +884,7 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
840 |
$batch_ids = $db->get_item_batch_ids( $current_job->getJobId(), $validation_task );
|
841 |
|
842 |
if(!empty($batch_ids)){
|
843 |
-
|
844 |
//$plugin_validation_batch_ids will never be empty
|
845 |
|
846 |
$array_index = 0;
|
@@ -857,25 +901,25 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
857 |
$set_validate_backup_error = true;
|
858 |
} else {
|
859 |
$current_task->setTaskMetaValue( $meta_task, $array_index );
|
860 |
-
|
861 |
}
|
862 |
} else {
|
863 |
//task is done
|
864 |
$current_task->setTaskMetaValue( $meta_task, WPBackItUp_Job_Task::COMPLETE );
|
865 |
-
|
866 |
}
|
867 |
} else{
|
868 |
//task is done
|
869 |
-
|
870 |
$current_task->setTaskMetaValue( $meta_task, WPBackItUp_Job_Task::COMPLETE );
|
871 |
-
|
872 |
}
|
873 |
}
|
874 |
|
875 |
//if error set error message
|
876 |
if($set_validate_backup_error) {
|
877 |
//ERROR
|
878 |
-
|
879 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,126);
|
880 |
|
881 |
write_fatal_error_status( '126' );
|
@@ -887,8 +931,8 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
887 |
set_status( 'validate_backup', $complete, false );
|
888 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
889 |
|
890 |
-
|
891 |
-
|
892 |
|
893 |
} elseif ($set_validate_backup_job_queue === true) {
|
894 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
@@ -900,12 +944,12 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
900 |
|
901 |
//Create the manifest and add to main zip - part of validation step
|
902 |
if ('task_create_manifest'==$current_task->getTaskName()) {
|
903 |
-
|
904 |
|
905 |
write_response_processing( "Create Backup Manifest" );
|
906 |
set_status( 'validate_backup', $active, true );
|
907 |
|
908 |
-
|
909 |
|
910 |
//Generate manifest
|
911 |
if ( ! $wp_backup->create_backup_manifest() ) {
|
@@ -928,7 +972,7 @@ if ('task_create_manifest'==$current_task->getTaskName()) {
|
|
928 |
//ENCRYPT FILES HERE
|
929 |
if ('task_encrypt_files'==$current_task->getTaskName()) {
|
930 |
|
931 |
-
|
932 |
write_response_processing( "Encrypt Sensitive Files" );
|
933 |
set_status( 'encrypt', $active, true );
|
934 |
|
@@ -937,7 +981,7 @@ if ('task_encrypt_files'==$current_task->getTaskName()) {
|
|
937 |
$file_list= glob($wp_backup->getBackupProjectPath() .'*-main-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*.zip' );
|
938 |
|
939 |
if (count($file_list) != 1){
|
940 |
-
|
941 |
|
942 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,130);
|
943 |
|
@@ -955,12 +999,12 @@ if ('task_encrypt_files'==$current_task->getTaskName()) {
|
|
955 |
$encrypted= $encryption->encrypt_file($main_file);
|
956 |
|
957 |
} catch (Exception $e){
|
958 |
-
|
959 |
$encrypted=false;
|
960 |
}
|
961 |
|
962 |
if ( false === $encrypted){
|
963 |
-
|
964 |
|
965 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,130);
|
966 |
|
@@ -972,12 +1016,12 @@ if ('task_encrypt_files'==$current_task->getTaskName()) {
|
|
972 |
|
973 |
} else{
|
974 |
set_status( 'finalize_backup', $active, true ); //start the spinner
|
975 |
-
|
976 |
}
|
977 |
|
978 |
set_status( 'encrypt', $complete, false );
|
979 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
980 |
-
|
981 |
|
982 |
}
|
983 |
|
@@ -987,12 +1031,12 @@ if ('task_encrypt_files'==$current_task->getTaskName()) {
|
|
987 |
|
988 |
//Create the backup set
|
989 |
if ('task_create_backupset'==$current_task->getTaskName()) {
|
990 |
-
|
991 |
|
992 |
write_response_processing( "Create Backup Set" );
|
993 |
set_status( 'finalize_backup', $active, true );
|
994 |
|
995 |
-
|
996 |
if (false===$WPBackitup->single_file_backupset()){
|
997 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
998 |
return;
|
@@ -1020,27 +1064,27 @@ if ('task_create_backupset'==$current_task->getTaskName()) {
|
|
1020 |
}
|
1021 |
|
1022 |
//Log backup set info
|
1023 |
-
|
1024 |
-
|
1025 |
|
1026 |
//when is empty then all the files are in the backup set
|
1027 |
if (! empty($backup_zip_files) && is_array($backup_zip_files)) {
|
1028 |
|
1029 |
//Get zip from top of list
|
1030 |
$zip_file = key($backup_zip_files);
|
1031 |
-
|
1032 |
|
1033 |
//add file to backupset zip
|
1034 |
if (true===$wp_backup->backup_file_to_zip( $wp_backup->getBackupProjectPath(), 'backups', $zip_file,$backup_set_zip )){
|
1035 |
//remove file from list
|
1036 |
unset($backup_zip_files[$zip_file]);
|
1037 |
-
|
1038 |
|
1039 |
} else{
|
1040 |
|
1041 |
//error occurred so stop trying and move on to next step
|
1042 |
//This is not a fatal error BUT will result in no backup set
|
1043 |
-
|
1044 |
$backup_zip_files=null;
|
1045 |
|
1046 |
//remove the backup set if exists
|
@@ -1059,14 +1103,14 @@ if ('task_create_backupset'==$current_task->getTaskName()) {
|
|
1059 |
//are there any files left?
|
1060 |
if (is_array($backup_zip_files) && count($backup_zip_files)>0){
|
1061 |
//CONTINUE
|
1062 |
-
|
1063 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
1064 |
}else{
|
1065 |
//COMPLETE
|
1066 |
-
|
1067 |
|
1068 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
1069 |
-
|
1070 |
|
1071 |
}
|
1072 |
|
@@ -1077,7 +1121,7 @@ if ('task_create_backupset'==$current_task->getTaskName()) {
|
|
1077 |
|
1078 |
//Zip up the backup folder
|
1079 |
if ('task_finalize_backup'==$current_task->getTaskName()) {
|
1080 |
-
|
1081 |
|
1082 |
write_response_processing( "Compress Backup " );
|
1083 |
set_status( 'finalize_backup', $active, true );
|
@@ -1090,7 +1134,7 @@ if ('task_finalize_backup'==$current_task->getTaskName()) {
|
|
1090 |
if ( ! $wp_backup->cleanup_current_backup_async('txt|sql|db|config')) {
|
1091 |
//Warning - no need to error job
|
1092 |
write_warning_status( '106' );
|
1093 |
-
|
1094 |
}
|
1095 |
|
1096 |
write_fatal_error_status( '109' );
|
@@ -1110,7 +1154,7 @@ if ('task_finalize_backup'==$current_task->getTaskName()) {
|
|
1110 |
set_status( 'finalize_backup', $complete, false );
|
1111 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
1112 |
|
1113 |
-
|
1114 |
|
1115 |
//If we get this far we have a finalized backup so change the path
|
1116 |
|
@@ -1120,7 +1164,7 @@ if ('task_finalize_backup'==$current_task->getTaskName()) {
|
|
1120 |
if ( $wp_backup->cleanup_current_backup_async('txt|sql|db|config') ) {
|
1121 |
//Warning - no need to error job
|
1122 |
write_warning_status( '106' );
|
1123 |
-
|
1124 |
}
|
1125 |
|
1126 |
//If complete then no post backup tasks
|
@@ -1133,11 +1177,11 @@ if ('task_finalize_backup'==$current_task->getTaskName()) {
|
|
1133 |
|
1134 |
//Remove supporting zip files if backup set successful
|
1135 |
if (true===$WPBackitup->is_remove_supporting_zip_files()){
|
1136 |
-
|
1137 |
|
1138 |
//do not fail on error.
|
1139 |
if(false===$wp_backup->remove_supporting_zips($zip_files)){
|
1140 |
-
|
1141 |
}
|
1142 |
|
1143 |
}
|
@@ -1187,34 +1231,34 @@ exit();
|
|
1187 |
|
1188 |
function end_backup($err=null, $success=null){
|
1189 |
global $WPBackitup,$wp_backup,$backup_logname,$current_job;
|
1190 |
-
|
1191 |
|
1192 |
//Cleanup TMP folder on error - will dispatch before changing path below
|
1193 |
if (! $success) {
|
1194 |
-
|
1195 |
//cleanup the manifest and sql files from root
|
1196 |
if ( $wp_backup->cleanup_current_backup_async('txt|sql|db|config') ) {
|
1197 |
//Warning - no need to error job
|
1198 |
-
|
1199 |
}
|
1200 |
}
|
1201 |
|
1202 |
$wp_backup->set_final_backup_path();
|
1203 |
|
1204 |
-
|
1205 |
//Zip up all the logs in the log folder
|
1206 |
$logs_path = WPBACKITUP__PLUGIN_PATH .'logs';
|
1207 |
$zip_file_path = $wp_backup->getBackupProjectPath() .'logs_' .$current_job->getJobId() . '.zip';
|
1208 |
|
1209 |
//copy WP debug file
|
1210 |
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
1211 |
-
|
1212 |
if (file_exists($wpdebug_file_path)) {
|
1213 |
$debug_log = sprintf('%s/wpdebug_%s.log',$logs_path,$current_job->getJobId());
|
1214 |
copy( $wpdebug_file_path, $debug_log );
|
1215 |
-
|
1216 |
}else{
|
1217 |
-
|
1218 |
}
|
1219 |
|
1220 |
$zip = new WPBackItUp_Zip($backup_logname,$zip_file_path);
|
@@ -1226,7 +1270,7 @@ function end_backup($err=null, $success=null){
|
|
1226 |
// updating lastrun_date
|
1227 |
$updated = $WPBackitup->set_option('backup_lastrun_date', $current_datetime);
|
1228 |
$debug_set_options_logname='set_options_debug';
|
1229 |
-
|
1230 |
|
1231 |
|
1232 |
$util = new WPBackItUp_Utility($backup_logname);
|
@@ -1235,20 +1279,20 @@ function end_backup($err=null, $success=null){
|
|
1235 |
$processing_minutes = round($seconds / 60);
|
1236 |
$processing_seconds = $seconds % 60;
|
1237 |
|
1238 |
-
|
1239 |
|
1240 |
-
if (true===$success)
|
1241 |
-
if (false===$success)
|
1242 |
|
1243 |
-
|
1244 |
|
1245 |
//Send Notification email
|
1246 |
-
|
1247 |
$logs_attachment = array( $zip_file_path );
|
1248 |
send_backup_notification_email($err, $success,$logs_attachment);
|
1249 |
|
1250 |
-
$logFileName =
|
1251 |
-
$logFilePath =
|
1252 |
|
1253 |
//COPY the log if it exists
|
1254 |
$newlogFilePath = $wp_backup->getBackupProjectPath() .$logFileName;
|
@@ -1256,13 +1300,13 @@ function end_backup($err=null, $success=null){
|
|
1256 |
copy($logFilePath,$newlogFilePath);
|
1257 |
}
|
1258 |
|
1259 |
-
|
1260 |
echo('Backup has completed');
|
1261 |
}
|
1262 |
|
1263 |
function send_backup_notification_email($err, $success,$logs=array()) {
|
1264 |
global $WPBackitup, $wp_backup, $backup_logname,$status_array,$current_job;
|
1265 |
-
|
1266 |
|
1267 |
$start_timestamp = $current_job->getJobStartTimeTimeStamp();
|
1268 |
$end_timestamp = $current_job->getJobEndTimeTimeStamp();
|
@@ -1318,7 +1362,7 @@ function send_backup_notification_email($err, $success,$logs=array()) {
|
|
1318 |
if($notification_email)
|
1319 |
$utility->send_email($notification_email,$subject,$message,$logs);
|
1320 |
|
1321 |
-
|
1322 |
}
|
1323 |
|
1324 |
function write_fatal_error_status($status_code) {
|
@@ -1440,7 +1484,7 @@ function write_response_file_success() {
|
|
1440 |
$jsonResponse->backupDate = $current_job->getJobDate();
|
1441 |
$jsonResponse->backupDuration = $current_job->getJobDurationFormatted();
|
1442 |
|
1443 |
-
$jsonResponse->logFileExists = file_exists(
|
1444 |
|
1445 |
write_response_file($jsonResponse);
|
1446 |
}
|
@@ -1450,7 +1494,7 @@ function write_response_file($JSON_Response) {
|
|
1450 |
global $backup_logname;
|
1451 |
|
1452 |
$json_response = json_encode($JSON_Response);
|
1453 |
-
|
1454 |
|
1455 |
$fh=get_response_file();
|
1456 |
fwrite($fh, $json_response);
|
80 |
//*****************//
|
81 |
|
82 |
if (! is_object ($current_job)){
|
83 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,'Current job not object:');
|
84 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,var_export($current_job));
|
85 |
return false;
|
86 |
}
|
87 |
|
88 |
if (! is_object ($current_task)){
|
89 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,'Current task not object');
|
90 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,var_export($current_task));
|
91 |
return false;
|
92 |
}
|
93 |
|
94 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id ,'Run task:' .$current_task->getTaskName());
|
95 |
|
96 |
//*************************//
|
97 |
//*** MAIN BACKUP CODE ***//
|
111 |
//*** BACKUP TASKS ***//
|
112 |
//*************************//
|
113 |
|
114 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function ,'Run task:' .$current_task->getTaskName());
|
115 |
|
116 |
//An error has occurred on the previous tasks
|
117 |
if (WPBackItUp_Job::ERROR==$current_task->getStatus()){
|
118 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Fatal error on previous task:'. $current_task->getTaskName());
|
119 |
|
120 |
//Fetch last wordpress error(might not be related to timeout)
|
121 |
//error type constants: http://php.net/manual/en/errorfunc.constants.php
|
122 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Last Error: ' .var_export(error_get_last(),true));
|
123 |
|
124 |
//Check for error type
|
125 |
switch ($current_task->getTaskName()) {
|
210 |
if ('task_preparing'==$current_task->getTaskName()) {
|
211 |
|
212 |
//Init
|
213 |
+
WPBackItUp_Logger::log($backup_logname,'***BEGIN BACKUP***');
|
214 |
+
WPBackItUp_Logger::log_sysinfo($backup_logname);
|
215 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'BACKUP TYPE:' .$wp_backup->backup_type);
|
216 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'BACKUP ID:' .$current_job->getJobId());
|
217 |
|
218 |
$WPBackitup->increment_backup_count();
|
219 |
//End Init
|
220 |
|
221 |
+
WPBackItUp_Logger::log($backup_logname,'**BEGIN CLEANUP**');
|
222 |
|
223 |
//Cleanup & Validate the backup folded is ready
|
224 |
write_response_processing("preparing for backup");
|
228 |
|
229 |
//*** Check Dependencies ***
|
230 |
if ( ! WPBackItUp_Zip::zip_utility_exists()) {
|
231 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Zip Util does not exist.' );
|
232 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,125);
|
233 |
write_fatal_error_status( '125' );
|
234 |
end_backup( 125, false );
|
268 |
set_status('preparing',$complete,false);
|
269 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
270 |
|
271 |
+
WPBackItUp_Logger::log($backup_logname,'**END CLEANUP**');
|
272 |
return;
|
273 |
}
|
274 |
|
275 |
if ('task_inventory_database'==$current_task->getTaskName()) {
|
276 |
+
WPBackItUp_Logger::log( $backup_logname, '**INVENTORY DATABASE**' );
|
277 |
|
278 |
write_response_processing( "Create inventory" );
|
279 |
set_status( 'create_inventory', $active, true );
|
292 |
$batch_size = $WPBackitup->backup_dbtables_batch_size();
|
293 |
|
294 |
if ( ! $wp_backup->save_database_inventory($current_job->getJobId(), WPBackItUp_Job_Item::DATABASE, $batch_size, $tables_exclude ) ) {
|
295 |
+
WPBackItUp_Logger::log_error( $backup_logname, $log_function, 'Database Inventory Error.' );
|
296 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
297 |
|
298 |
write_fatal_error_status( '127' );
|
302 |
};
|
303 |
|
304 |
|
305 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Database Inventory complete.');
|
306 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
307 |
|
308 |
+
WPBackItUp_Logger::log($backup_logname,'**INVENTORY DATABASE**');
|
309 |
return;
|
310 |
|
311 |
}
|
312 |
|
313 |
|
314 |
if ('task_inventory_plugins'==$current_task->getTaskName()) {
|
315 |
+
WPBackItUp_Logger::log( $backup_logname, '**INVENTORY PLUGINS**' );
|
316 |
|
317 |
write_response_processing( "Create inventory" );
|
318 |
set_status( 'create_inventory', $active, true );
|
330 |
$backup_plugins_filter,
|
331 |
array(
|
332 |
"wp-backitup",
|
333 |
+
"wp-backitup-premium"
|
334 |
)
|
335 |
);
|
336 |
|
337 |
if ( ! $wp_backup->save_folder_inventory( WPBACKITUP__SQL_BULK_INSERT_SIZE, $current_job->getJobId(), WPBackItUp_Job_Item::PLUGINS, WPBACKITUP__PLUGINS_ROOT_PATH, $plugin_exclude ) ) {
|
338 |
+
WPBackItUp_Logger::log_error( $backup_logname, $log_function, 'Plugins Inventory Error.' );
|
339 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
340 |
|
341 |
write_fatal_error_status( '127' );
|
345 |
};
|
346 |
|
347 |
|
348 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Plugin Inventory complete.');
|
349 |
|
350 |
//set_status('inventory',$complete,false);
|
351 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
352 |
|
353 |
+
WPBackItUp_Logger::log($backup_logname,'**INVENTORY PLUGINS**');
|
354 |
return;
|
355 |
|
356 |
}
|
358 |
|
359 |
|
360 |
if ('task_inventory_themes'==$current_task->getTaskName()) {
|
361 |
+
WPBackItUp_Logger::log( $backup_logname, '**INVENTORY THEMES**' );
|
362 |
|
363 |
$global_exclude = explode(',', WPBACKITUP__BACKUP_GLOBAL_IGNORE_LIST);
|
364 |
|
375 |
);
|
376 |
|
377 |
if (! $wp_backup->save_folder_inventory(WPBACKITUP__SQL_BULK_INSERT_SIZE,$current_job->getJobId(),WPBackItUp_Job_Item::THEMES,WPBACKITUP__THEMES_ROOT_PATH,$theme_exclude)){
|
378 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Themes Inventory Error.');
|
379 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
380 |
|
381 |
write_fatal_error_status('127');
|
383 |
return false;
|
384 |
};
|
385 |
|
386 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Theme Inventory complete.');
|
387 |
|
388 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
389 |
|
390 |
+
WPBackItUp_Logger::log($backup_logname,'**INVENTORY THEMES**');
|
391 |
return;
|
392 |
|
393 |
}
|
394 |
|
395 |
if ('task_inventory_uploads'==$current_task->getTaskName()) {
|
396 |
+
WPBackItUp_Logger::log( $backup_logname, '**INVENTORY UPLOADS**' );
|
397 |
|
398 |
$global_exclude = explode(',', WPBACKITUP__BACKUP_GLOBAL_IGNORE_LIST);
|
399 |
// Getting user filter
|
422 |
$upload_array = wp_upload_dir();
|
423 |
$uploads_root_path = $upload_array['basedir'];
|
424 |
if (! $wp_backup->save_folder_inventory(WPBACKITUP__SQL_BULK_INSERT_SIZE,$current_job->getJobId(),WPBackItUp_Job_Item::UPLOADS,$uploads_root_path,$upload_exclude)){
|
425 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Uploads Inventory Error.');
|
426 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
427 |
|
428 |
write_fatal_error_status('127');
|
430 |
return false;
|
431 |
};
|
432 |
|
433 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Uploads Inventory complete.');
|
434 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
435 |
|
436 |
+
WPBackItUp_Logger::log($backup_logname,'**INVENTORY UPLOADS**');
|
437 |
return;
|
438 |
|
439 |
}
|
440 |
|
441 |
if ('task_inventory_others'==$current_task->getTaskName()) {
|
442 |
+
WPBackItUp_Logger::log( $backup_logname, '**INVENTORY OTHERS**' );
|
443 |
|
444 |
$global_exclude = explode(',', WPBACKITUP__BACKUP_GLOBAL_IGNORE_LIST);
|
445 |
// Getting user filter
|
476 |
));
|
477 |
|
478 |
if (! $wp_backup->save_folder_inventory(WPBACKITUP__SQL_BULK_INSERT_SIZE,$current_job->getJobId(),WPBackItUp_Job_Item::OTHERS,WPBACKITUP__CONTENT_PATH,$other_exclude)){
|
479 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Other Inventory Error.');
|
480 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,127);
|
481 |
|
482 |
write_fatal_error_status('127');
|
484 |
return false;
|
485 |
};
|
486 |
|
487 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Others Inventory complete.');
|
488 |
|
489 |
//when others is done then update the task as completed
|
490 |
//set_status('create_inventory',$complete,false);
|
491 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
492 |
|
493 |
+
WPBackItUp_Logger::log($backup_logname,'**INVENTORY OTHERS**');
|
494 |
return;
|
495 |
|
496 |
}
|
497 |
|
498 |
//Create the site info file
|
499 |
if ('task_backup_siteinfo'==$current_task->getTaskName()) {
|
500 |
+
WPBackItUp_Logger::log($backup_logname,'**SITE INFO**' );
|
501 |
|
502 |
if ( $wp_backup->create_siteinfo_file($current_job->getJobId())) {
|
503 |
|
514 |
set_status( 'create_inventory', $complete, false );
|
515 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
516 |
|
517 |
+
WPBackItUp_Logger::log($backup_logname,'**END SITE INFO**' );
|
518 |
|
519 |
} else {
|
520 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,105);
|
529 |
|
530 |
//Backup the database
|
531 |
if ('task_export_db'==$current_task->getTaskName()) {
|
532 |
+
WPBackItUp_Logger::log($backup_logname,'**BEGIN DATABASE EXPORT**');
|
533 |
write_response_processing( "Create database export" );
|
534 |
set_status( 'exportdb', $active, true );
|
535 |
|
543 |
|
544 |
$tables_remaining_count = $wp_backup->export_database_wpbackitup($current_job,WPBackItUp_Job_Item::DATABASE,$batch_size);
|
545 |
|
546 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Database Export Items remaining:' .var_export($tables_remaining_count,true));
|
547 |
if (false===$tables_remaining_count) {
|
548 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,104);
|
549 |
write_fatal_error_status( '104' );
|
553 |
$current_task->setTaskMetaValue('db_mysqldump_path',$db_mysqldump_path);
|
554 |
if ($tables_remaining_count>0){
|
555 |
//CONTINUE
|
556 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Continue backing up tables.');
|
557 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
558 |
}else{
|
559 |
//COMPLETE
|
560 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Complete - All tables backed up.');
|
561 |
|
562 |
//set_status( 'exportdb', $complete, false );
|
563 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
564 |
+
WPBackItUp_Logger::log($backup_logname,'**END DATABASE EXPORT**');
|
565 |
}
|
566 |
}
|
567 |
|
573 |
//File for ref only so dont stop on error
|
574 |
if ('task_merge_sql'==$current_task->getTaskName()) {
|
575 |
|
576 |
+
WPBackItUp_Logger::log($backup_logname,'**BEGIN SQL MERGE**');
|
|
|
|
|
577 |
|
578 |
if (true===$WPBackitup->single_file_db()){
|
579 |
+
write_response_processing( "Create single SQL File" );
|
580 |
+
|
581 |
+
// merged sql files to path.
|
582 |
+
$toFile_path = sprintf( '%s/%s.db',$wp_backup->getBackupProjectPath(),$backup_name);
|
583 |
+
$search_path = $wp_backup->getBackupProjectPath();
|
584 |
+
$task = $current_task;
|
585 |
+
// Getting SQL merge batch size and convert to integer
|
586 |
+
$batch_size = (int) $WPBackitup->backup_sql_merge_batch_size();
|
587 |
+
|
588 |
+
$sql_files_remaining_count = $wp_backup->merge_sql_files_to_path($task, $batch_size, $search_path, $toFile_path, 'sql');
|
589 |
+
|
590 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'SQL Merge Items remaining:' .var_export($sql_files_remaining_count,true));
|
591 |
+
if(false===$sql_files_remaining_count){
|
592 |
+
$WPBackitup->set_single_file_db(false);//turn off on failure
|
593 |
+
WPBackItUp_Logger::log_warning($backup_logname,$log_function, 'Could not merge SQL files');
|
594 |
+
}else{
|
595 |
+
if($sql_files_remaining_count>0){
|
596 |
+
// CONTINUE
|
597 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Continue merging SQL files');
|
598 |
+
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
599 |
+
}else{
|
600 |
+
//COMPLETE
|
601 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Complete - Merged all SQL files');
|
602 |
+
|
603 |
+
set_status( 'exportdb', $complete, false );
|
604 |
+
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
605 |
+
WPBackItUp_Logger::log($backup_logname,'**END SQL MERGE**');
|
606 |
+
}
|
607 |
+
}
|
608 |
}else{
|
609 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'SQL Merge option off.');
|
|
|
610 |
|
611 |
+
// Need set task as complete if merge option off.
|
612 |
+
set_status( 'exportdb', $complete, false );
|
613 |
+
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
614 |
+
WPBackItUp_Logger::log($backup_logname,'**END SQL MERGE**');
|
615 |
+
}
|
616 |
|
617 |
return;
|
618 |
|
619 |
}
|
620 |
|
621 |
+
//TODO: change the db task names to export DB and zip or backup database
|
|
|
|
|
622 |
|
623 |
//Extract the site info
|
624 |
if ('task_backup_db'==$current_task->getTaskName()) {
|
625 |
+
WPBackItUp_Logger::log($backup_logname,'**BACKUP DATABASE**' );
|
626 |
write_response_processing( "Backup Database" );
|
627 |
set_status( 'backupdb', $active, true );
|
628 |
|
629 |
$file_system = new WPBackItUp_FileSystem($backup_logname);
|
|
|
|
|
630 |
|
631 |
+
//Add site Info and SQL data to main zip
|
632 |
+
$suffix='main';
|
633 |
+
$source_site_data_root = $wp_backup->getBackupProjectPath();
|
634 |
+
$target_site_data_root = 'site-data';
|
635 |
+
$batch_size = $WPBackitup->backup_sql_batch_size();
|
636 |
+
|
637 |
+
// getting site data files from task meta
|
638 |
+
$site_data_files = $current_task->getTaskMetaValue('site_data_files', array());
|
639 |
+
|
640 |
+
// getting db file backup status from task meta.
|
641 |
+
$is_merged_db_file_backup_queued = $current_task->getTaskMetaValue('is_merged_db_file_backup_queued', false);
|
642 |
+
|
643 |
+
// getting batch ID from task meta.
|
644 |
+
// As we only need one zip file to created for main zip.
|
645 |
+
$batch_id = $current_task->getTaskMetaValue('task_backup_db_batch_id', null);
|
646 |
|
647 |
+
if(is_null($batch_id)){
|
648 |
+
$batch_id = current_time( 'timestamp' );
|
649 |
+
$current_task->setTaskMetaValue('task_backup_db_batch_id', $batch_id);
|
650 |
+
}
|
651 |
|
652 |
+
if(empty($site_data_files)){
|
653 |
+
$site_data_files = $file_system->get_fileonly_list($wp_backup->getBackupProjectPath(), 'txt|sql|config|crypt');
|
654 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__, 'Main Files Found:' . var_export($site_data_files,true));
|
655 |
+
}
|
656 |
|
657 |
+
// passing $site_data_files as a reference value
|
658 |
+
// counting site data remaining file to backup
|
659 |
+
$site_data_remaining_count = $wp_backup->backup_file_list( $source_site_data_root, $target_site_data_root, $suffix, $site_data_files, $batch_size, $batch_id);
|
660 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Site data Items remaining:' .var_export($site_data_remaining_count,true));
|
661 |
+
|
662 |
+
if ( $site_data_remaining_count === false ) {
|
663 |
+
$current_task->setStatus(WPBackItUp_Job_Task::ERROR, 135);
|
664 |
write_fatal_error_status( '135' );
|
665 |
end_backup( 135, false );
|
666 |
return false;
|
667 |
} else {
|
668 |
+
if ($site_data_remaining_count>0){
|
669 |
+
// CONTINUE
|
670 |
+
$current_task->setTaskMetaValue('site_data_files',$site_data_files);
|
671 |
+
|
672 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Continue backing up site data');
|
673 |
+
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
674 |
+
|
675 |
+
}elseif( false === $is_merged_db_file_backup_queued && true===$WPBackitup->single_file_db() ){
|
676 |
+
// set task meta so that db file backup queued.
|
677 |
+
$current_task->setTaskMetaValue('is_merged_db_file_backup_queued', true);
|
678 |
+
|
679 |
+
// Before complete Try to backup .db file or files
|
680 |
+
$db_file = $file_system->get_fileonly_list($wp_backup->getBackupProjectPath(), 'db');
|
681 |
+
WPBackItUp_Logger::log_info($backup_logname, $log_function, 'Found .db files: '. var_export($db_file, true));
|
682 |
|
683 |
+
// Run a pass to backup the .db file or files
|
684 |
+
WPBackItUp_Logger::log_info($backup_logname, $log_function, 'Trying to backup db files');
|
685 |
+
$current_task->setTaskMetaValue('site_data_files', $db_file);
|
686 |
+
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
687 |
|
688 |
+
}else{
|
689 |
+
// COMPLETE
|
|
|
690 |
|
691 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Complete - backup all site data files');
|
692 |
//get rid of the SQL and sitedata file - will check again at end in cleanup
|
693 |
$wp_backup->cleanup_current_backup_async('txt|sql|db|config|crypt');
|
694 |
|
695 |
set_status( 'backupdb', $complete, false );
|
696 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
697 |
|
698 |
+
WPBackItUp_Logger::log($backup_logname,'**END SITE INFO**' );
|
699 |
}
|
700 |
}
|
701 |
|
705 |
|
706 |
//Backup the themes
|
707 |
if ('task_backup_themes'==$current_task->getTaskName()) {
|
708 |
+
WPBackItUp_Logger::log($backup_logname,'**BACKUP THEMES TASK**' );
|
709 |
write_response_processing( "Backup themes " );
|
710 |
set_status( 'backup_themes', $active, true );
|
711 |
|
712 |
$themes_remaining_files_count = $wp_backup->backup_files($current_job->getJobId(),WPBACKITUP__THEMES_ROOT_PATH,WPBackItUp_Job_Item::THEMES);
|
713 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Themes remaining:' .$themes_remaining_files_count);
|
714 |
if ($themes_remaining_files_count===false) {
|
715 |
//ERROR
|
716 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Error backing up themes.');
|
717 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,120);
|
718 |
write_fatal_error_status( '120' );
|
719 |
end_backup( 120, false );
|
721 |
}else{
|
722 |
if ($themes_remaining_files_count>0){
|
723 |
//CONTINUE
|
724 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Continue backing up themes.');
|
725 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
726 |
}else{
|
727 |
//COMPLETE
|
728 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Complete - All themes backed up.');
|
729 |
|
730 |
set_status( 'backup_themes', $complete, false );
|
731 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
732 |
+
WPBackItUp_Logger::log($backup_logname,'**END BACKUP THEMES TASK**');
|
733 |
}
|
734 |
}
|
735 |
|
739 |
|
740 |
//Backup the plugins
|
741 |
if ('task_backup_plugins'==$current_task->getTaskName()) {
|
742 |
+
WPBackItUp_Logger::log($backup_logname,'**BACKUP PLUGINS TASK**' );
|
743 |
write_response_processing( "Backup plugins " );
|
744 |
set_status( 'backup_plugins', $active, true );
|
745 |
|
746 |
$plugins_remaining_files_count = $wp_backup->backup_files($current_job->getJobId(),WPBACKITUP__PLUGINS_ROOT_PATH,WPBackItUp_Job_Item::PLUGINS);
|
747 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Plugins remaining:' .$plugins_remaining_files_count);
|
748 |
if ($plugins_remaining_files_count===false) {
|
749 |
//ERROR
|
750 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Error backing up plugins.');
|
751 |
|
752 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,121);
|
753 |
write_fatal_error_status( '121' );
|
756 |
} else {
|
757 |
if ($plugins_remaining_files_count>0){
|
758 |
//CONTINUE
|
759 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Continue backing up plugins.');
|
760 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
761 |
} else{
|
762 |
//COMPLETE
|
763 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Complete - All plugins backed up.');
|
764 |
set_status( 'backup_plugins', $complete, false );
|
765 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
766 |
+
WPBackItUp_Logger::log($backup_logname,'**END BACKUP PLUGINS TASK**');
|
767 |
}
|
768 |
}
|
769 |
|
772 |
|
773 |
//Backup the uploads
|
774 |
if ('task_backup_uploads'==$current_task->getTaskName()) {
|
775 |
+
WPBackItUp_Logger::log($backup_logname,'**BACKUP UPLOADS TASK**' );
|
776 |
write_response_processing( "Backup uploads " );
|
777 |
set_status( 'backup_uploads', $active, true );
|
778 |
|
781 |
|
782 |
//exclude zip files from backup
|
783 |
$uploads_remaining_files_count = $wp_backup->backup_files($current_job->getJobId(),$source_uploads_root,WPBackItUp_Job_Item::UPLOADS);
|
784 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Uploads remaining:' .$uploads_remaining_files_count);
|
785 |
if ( $uploads_remaining_files_count ===false) {
|
786 |
//ERROR
|
787 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Error backing up uploads.' );
|
788 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,122);
|
789 |
|
790 |
write_fatal_error_status( '122' );
|
793 |
} else {
|
794 |
if ( $uploads_remaining_files_count > 0 ) {
|
795 |
//CONTINUE
|
796 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Continue backing up uploads.' );
|
797 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
798 |
|
799 |
} else {
|
800 |
//COMPLETE
|
801 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'All uploads backed up.' );
|
802 |
set_status( 'backup_uploads', $complete, false );
|
803 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
804 |
+
WPBackItUp_Logger::log($backup_logname,'**END BACKUP UPLOADS TASK**' );
|
805 |
}
|
806 |
}
|
807 |
|
810 |
|
811 |
//Backup all the other content in the wp-content root
|
812 |
if ('task_backup_other'==$current_task->getTaskName()) {
|
813 |
+
WPBackItUp_Logger::log($backup_logname,'**BACKUP OTHER TASK**' );
|
814 |
write_response_processing( "Backup other files " );
|
815 |
set_status( 'backup_other', $active, true );
|
816 |
|
817 |
$others_remaining_files_count = $wp_backup->backup_files($current_job->getJobId(),WPBACKITUP__CONTENT_PATH,WPBackItUp_Job_Item::OTHERS);
|
818 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Others remaining:' .$others_remaining_files_count);
|
819 |
if ( $others_remaining_files_count ===false) {
|
820 |
//ERROR
|
821 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Error backing up others.' );
|
822 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,123);
|
823 |
|
824 |
write_fatal_error_status( '123' );
|
827 |
} else {
|
828 |
if ( $others_remaining_files_count > 0 ) {
|
829 |
//CONTINUE
|
830 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Continue backing up others.' );
|
831 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
832 |
} else {
|
833 |
//COMPLETE
|
834 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'All others backed up.' );
|
835 |
|
836 |
set_status( 'backup_other', $complete, false );
|
837 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
838 |
+
WPBackItUp_Logger::log($backup_logname,'**END BACKUP OTHER TASK**' );
|
839 |
}
|
840 |
|
841 |
}
|
847 |
//Validate the backup IF logging is turned on - reporting only
|
848 |
if ('task_validate_backup'==$current_task->getTaskName()) {
|
849 |
//Validate the content if logging is on
|
850 |
+
WPBackItUp_Logger::log($backup_logname,'**VALIDATE CONTENT**');
|
851 |
|
852 |
write_response_processing( "Validating Backup " );
|
853 |
set_status( 'validate_backup', $active, true );
|
884 |
$batch_ids = $db->get_item_batch_ids( $current_job->getJobId(), $validation_task );
|
885 |
|
886 |
if(!empty($batch_ids)){
|
887 |
+
WPBackItUp_Logger::log_info( $backup_logname, $log_function, sprintf('%s Batch Ids: %s',$validation_task,var_export( $batch_ids, true )));
|
888 |
//$plugin_validation_batch_ids will never be empty
|
889 |
|
890 |
$array_index = 0;
|
901 |
$set_validate_backup_error = true;
|
902 |
} else {
|
903 |
$current_task->setTaskMetaValue( $meta_task, $array_index );
|
904 |
+
WPBackItUp_Logger::log_info( $backup_logname, $log_function, sprintf('%s Content, Batch ID: %s Validated Successfully!',$validation_task,$batch_id ));
|
905 |
}
|
906 |
} else {
|
907 |
//task is done
|
908 |
$current_task->setTaskMetaValue( $meta_task, WPBackItUp_Job_Task::COMPLETE );
|
909 |
+
WPBackItUp_Logger::log_info( $backup_logname, $log_function, sprintf('%s Content Validated Successfully!',$validation_task));
|
910 |
}
|
911 |
} else{
|
912 |
//task is done
|
913 |
+
WPBackItUp_Logger::log_info( $backup_logname, $log_function, sprintf('Task Done! Folder is empty'));
|
914 |
$current_task->setTaskMetaValue( $meta_task, WPBackItUp_Job_Task::COMPLETE );
|
915 |
+
WPBackItUp_Logger::log_info( $backup_logname, $log_function, sprintf('%s Content Validated Successfully!',$validation_task));
|
916 |
}
|
917 |
}
|
918 |
|
919 |
//if error set error message
|
920 |
if($set_validate_backup_error) {
|
921 |
//ERROR
|
922 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Content Validation ERROR.' );
|
923 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,126);
|
924 |
|
925 |
write_fatal_error_status( '126' );
|
931 |
set_status( 'validate_backup', $complete, false );
|
932 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
933 |
|
934 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'All Content Validated Successfully!' );
|
935 |
+
WPBackItUp_Logger::log($backup_logname,'**END VALIDATE CONTENT**' );
|
936 |
|
937 |
} elseif ($set_validate_backup_job_queue === true) {
|
938 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
944 |
|
945 |
//Create the manifest and add to main zip - part of validation step
|
946 |
if ('task_create_manifest'==$current_task->getTaskName()) {
|
947 |
+
WPBackItUp_Logger::log( $backup_logname, '**CREATE BACKUP MANIFEST**' );
|
948 |
|
949 |
write_response_processing( "Create Backup Manifest" );
|
950 |
set_status( 'validate_backup', $active, true );
|
951 |
|
952 |
+
WPBackItUp_Logger::log_info( $backup_logname, $log_function, 'Create Backup Set? ' . var_export( $WPBackitup->single_file_backupset(), true ) );
|
953 |
|
954 |
//Generate manifest
|
955 |
if ( ! $wp_backup->create_backup_manifest() ) {
|
972 |
//ENCRYPT FILES HERE
|
973 |
if ('task_encrypt_files'==$current_task->getTaskName()) {
|
974 |
|
975 |
+
WPBackItUp_Logger::log($backup_logname,'**ENCRYPT SENSITIVE FILES**');
|
976 |
write_response_processing( "Encrypt Sensitive Files" );
|
977 |
set_status( 'encrypt', $active, true );
|
978 |
|
981 |
$file_list= glob($wp_backup->getBackupProjectPath() .'*-main-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*.zip' );
|
982 |
|
983 |
if (count($file_list) != 1){
|
984 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function, 'More than 1 main File found:' . var_export( $file_list,true));
|
985 |
|
986 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,130);
|
987 |
|
999 |
$encrypted= $encryption->encrypt_file($main_file);
|
1000 |
|
1001 |
} catch (Exception $e){
|
1002 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function, 'Encryption Error:' . $e);
|
1003 |
$encrypted=false;
|
1004 |
}
|
1005 |
|
1006 |
if ( false === $encrypted){
|
1007 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function, 'Could not encrypt file:' . var_export( $main_file,true));
|
1008 |
|
1009 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,130);
|
1010 |
|
1016 |
|
1017 |
} else{
|
1018 |
set_status( 'finalize_backup', $active, true ); //start the spinner
|
1019 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Encryption option off.');
|
1020 |
}
|
1021 |
|
1022 |
set_status( 'encrypt', $complete, false );
|
1023 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
1024 |
+
WPBackItUp_Logger::log($backup_logname,'**END ENCRYPT SENSITIVE FILES**');
|
1025 |
|
1026 |
}
|
1027 |
|
1031 |
|
1032 |
//Create the backup set
|
1033 |
if ('task_create_backupset'==$current_task->getTaskName()) {
|
1034 |
+
WPBackItUp_Logger::log($backup_logname,'**CREATE BACKUP SET**' );
|
1035 |
|
1036 |
write_response_processing( "Create Backup Set" );
|
1037 |
set_status( 'finalize_backup', $active, true );
|
1038 |
|
1039 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Create Backup Set? '.var_export($WPBackitup->single_file_backupset(),true));
|
1040 |
if (false===$WPBackitup->single_file_backupset()){
|
1041 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
1042 |
return;
|
1064 |
}
|
1065 |
|
1066 |
//Log backup set info
|
1067 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Backup Set Name:'.$backup_set_zip );
|
1068 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Backup Files:'.var_export($backup_zip_files,true));
|
1069 |
|
1070 |
//when is empty then all the files are in the backup set
|
1071 |
if (! empty($backup_zip_files) && is_array($backup_zip_files)) {
|
1072 |
|
1073 |
//Get zip from top of list
|
1074 |
$zip_file = key($backup_zip_files);
|
1075 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Add File to backup set:'.$zip_file);
|
1076 |
|
1077 |
//add file to backupset zip
|
1078 |
if (true===$wp_backup->backup_file_to_zip( $wp_backup->getBackupProjectPath(), 'backups', $zip_file,$backup_set_zip )){
|
1079 |
//remove file from list
|
1080 |
unset($backup_zip_files[$zip_file]);
|
1081 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'File added to backup set successfully.' );
|
1082 |
|
1083 |
} else{
|
1084 |
|
1085 |
//error occurred so stop trying and move on to next step
|
1086 |
//This is not a fatal error BUT will result in no backup set
|
1087 |
+
WPBackItUp_Logger::log_error($backup_logname,$log_function,'Unable to create backup set.');
|
1088 |
$backup_zip_files=null;
|
1089 |
|
1090 |
//remove the backup set if exists
|
1103 |
//are there any files left?
|
1104 |
if (is_array($backup_zip_files) && count($backup_zip_files)>0){
|
1105 |
//CONTINUE
|
1106 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Continue adding backups to set' );
|
1107 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
1108 |
}else{
|
1109 |
//COMPLETE
|
1110 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'All others backed up.' );
|
1111 |
|
1112 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
1113 |
+
WPBackItUp_Logger::log($backup_logname,'**END CREATE BACKUP SET**' );
|
1114 |
|
1115 |
}
|
1116 |
|
1121 |
|
1122 |
//Zip up the backup folder
|
1123 |
if ('task_finalize_backup'==$current_task->getTaskName()) {
|
1124 |
+
WPBackItUp_Logger::log($backup_logname,'**FINALIZE BACKUP**' );
|
1125 |
|
1126 |
write_response_processing( "Compress Backup " );
|
1127 |
set_status( 'finalize_backup', $active, true );
|
1134 |
if ( ! $wp_backup->cleanup_current_backup_async('txt|sql|db|config')) {
|
1135 |
//Warning - no need to error job
|
1136 |
write_warning_status( '106' );
|
1137 |
+
WPBackItUp_Logger::log_warning($backup_logname,$log_function,'Cleanup could not be dispatched.');
|
1138 |
}
|
1139 |
|
1140 |
write_fatal_error_status( '109' );
|
1154 |
set_status( 'finalize_backup', $complete, false );
|
1155 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
1156 |
|
1157 |
+
WPBackItUp_Logger::log($backup_logname,'**END FINALIZE BACKUP**' );
|
1158 |
|
1159 |
//If we get this far we have a finalized backup so change the path
|
1160 |
|
1164 |
if ( $wp_backup->cleanup_current_backup_async('txt|sql|db|config') ) {
|
1165 |
//Warning - no need to error job
|
1166 |
write_warning_status( '106' );
|
1167 |
+
WPBackItUp_Logger::log_warning($backup_logname,$log_function,'Cleanup could not be dispatched.');
|
1168 |
}
|
1169 |
|
1170 |
//If complete then no post backup tasks
|
1177 |
|
1178 |
//Remove supporting zip files if backup set successful
|
1179 |
if (true===$WPBackitup->is_remove_supporting_zip_files()){
|
1180 |
+
WPBackItUp_Logger::log_info($backup_logname,$log_function,'Cleanup supporting zips.');
|
1181 |
|
1182 |
//do not fail on error.
|
1183 |
if(false===$wp_backup->remove_supporting_zips($zip_files)){
|
1184 |
+
WPBackItUp_Logger::log_warning($backup_logname,$log_function,'Supporting zip files NOT deleted.');
|
1185 |
}
|
1186 |
|
1187 |
}
|
1231 |
|
1232 |
function end_backup($err=null, $success=null){
|
1233 |
global $WPBackitup,$wp_backup,$backup_logname,$current_job;
|
1234 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'Begin');
|
1235 |
|
1236 |
//Cleanup TMP folder on error - will dispatch before changing path below
|
1237 |
if (! $success) {
|
1238 |
+
WPBackItUp_Logger::log_warning($backup_logname,__METHOD__,'Cleanup on backup error.');
|
1239 |
//cleanup the manifest and sql files from root
|
1240 |
if ( $wp_backup->cleanup_current_backup_async('txt|sql|db|config') ) {
|
1241 |
//Warning - no need to error job
|
1242 |
+
WPBackItUp_Logger::log_warning($backup_logname,__METHOD__,'Cleanup on backup error could not be dispatched.');
|
1243 |
}
|
1244 |
}
|
1245 |
|
1246 |
$wp_backup->set_final_backup_path();
|
1247 |
|
1248 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'Zip up all the logs.');
|
1249 |
//Zip up all the logs in the log folder
|
1250 |
$logs_path = WPBACKITUP__PLUGIN_PATH .'logs';
|
1251 |
$zip_file_path = $wp_backup->getBackupProjectPath() .'logs_' .$current_job->getJobId() . '.zip';
|
1252 |
|
1253 |
//copy WP debug file
|
1254 |
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
1255 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'Save WP Debug: ' .$wpdebug_file_path);
|
1256 |
if (file_exists($wpdebug_file_path)) {
|
1257 |
$debug_log = sprintf('%s/wpdebug_%s.log',$logs_path,$current_job->getJobId());
|
1258 |
copy( $wpdebug_file_path, $debug_log );
|
1259 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'WP Debug file saved: ' .$debug_log);
|
1260 |
}else{
|
1261 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'NO WP Debug file: ' .$wpdebug_file_path);
|
1262 |
}
|
1263 |
|
1264 |
$zip = new WPBackItUp_Zip($backup_logname,$zip_file_path);
|
1270 |
// updating lastrun_date
|
1271 |
$updated = $WPBackitup->set_option('backup_lastrun_date', $current_datetime);
|
1272 |
$debug_set_options_logname='set_options_debug';
|
1273 |
+
WPBackItUp_Logger::log_info($debug_set_options_logname,__METHOD__, 'Option backup_lastrun_date'. ' update status: ' . $updated );
|
1274 |
|
1275 |
|
1276 |
$util = new WPBackItUp_Utility($backup_logname);
|
1279 |
$processing_minutes = round($seconds / 60);
|
1280 |
$processing_seconds = $seconds % 60;
|
1281 |
|
1282 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'Script Processing Time:' .$processing_minutes .' Minutes ' .$processing_seconds .' Seconds');
|
1283 |
|
1284 |
+
if (true===$success) WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'Backup completed: SUCCESS');
|
1285 |
+
if (false===$success) WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'Backup completed: ERROR');
|
1286 |
|
1287 |
+
WPBackItUp_Logger::log($backup_logname,'*** END BACKUP ***');
|
1288 |
|
1289 |
//Send Notification email
|
1290 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'Send Email notification');
|
1291 |
$logs_attachment = array( $zip_file_path );
|
1292 |
send_backup_notification_email($err, $success,$logs_attachment);
|
1293 |
|
1294 |
+
$logFileName = WPBackItUp_Logger::getLogFileName($backup_logname);
|
1295 |
+
$logFilePath = WPBackItUp_Logger::getLogFilePath($backup_logname);
|
1296 |
|
1297 |
//COPY the log if it exists
|
1298 |
$newlogFilePath = $wp_backup->getBackupProjectPath() .$logFileName;
|
1300 |
copy($logFilePath,$newlogFilePath);
|
1301 |
}
|
1302 |
|
1303 |
+
WPBackItUp_Logger::close($backup_logname);
|
1304 |
echo('Backup has completed');
|
1305 |
}
|
1306 |
|
1307 |
function send_backup_notification_email($err, $success,$logs=array()) {
|
1308 |
global $WPBackitup, $wp_backup, $backup_logname,$status_array,$current_job;
|
1309 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'Begin');
|
1310 |
|
1311 |
$start_timestamp = $current_job->getJobStartTimeTimeStamp();
|
1312 |
$end_timestamp = $current_job->getJobEndTimeTimeStamp();
|
1362 |
if($notification_email)
|
1363 |
$utility->send_email($notification_email,$subject,$message,$logs);
|
1364 |
|
1365 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'End');
|
1366 |
}
|
1367 |
|
1368 |
function write_fatal_error_status($status_code) {
|
1484 |
$jsonResponse->backupDate = $current_job->getJobDate();
|
1485 |
$jsonResponse->backupDuration = $current_job->getJobDurationFormatted();
|
1486 |
|
1487 |
+
$jsonResponse->logFileExists = file_exists(WPBackItUp_Logger::getLogFilePath($backup_logname));
|
1488 |
|
1489 |
write_response_file($jsonResponse);
|
1490 |
}
|
1494 |
global $backup_logname;
|
1495 |
|
1496 |
$json_response = json_encode($JSON_Response);
|
1497 |
+
WPBackItUp_Logger::log_info($backup_logname,__METHOD__,'Write response file:' . $json_response);
|
1498 |
|
1499 |
$fh=get_response_file();
|
1500 |
fwrite($fh, $json_response);
|
lib/includes/job_cleanup.php
CHANGED
@@ -59,18 +59,18 @@ $success=99;
|
|
59 |
//*************************//
|
60 |
|
61 |
if (! is_object ($current_job)){
|
62 |
-
|
63 |
-
|
64 |
return false;
|
65 |
}
|
66 |
|
67 |
if (! is_object ($current_task)){
|
68 |
-
|
69 |
-
|
70 |
return false;
|
71 |
}
|
72 |
|
73 |
-
|
74 |
|
75 |
|
76 |
//*************************//
|
@@ -96,15 +96,15 @@ if ('task_scheduled_cleanup'==$current_task->getTaskName()) {
|
|
96 |
/* ** INIT **
|
97 |
/* -----------------------------------------------------------------------*/
|
98 |
|
99 |
-
|
100 |
-
|
101 |
|
102 |
-
|
103 |
|
104 |
//Check License
|
105 |
-
|
106 |
do_action( 'wpbackitup_check_license');
|
107 |
-
|
108 |
/* -----------------------------------------------------------------------*/
|
109 |
|
110 |
|
@@ -113,15 +113,15 @@ if ('task_scheduled_cleanup'==$current_task->getTaskName()) {
|
|
113 |
/* -----------------------------------------------------------------------*/
|
114 |
|
115 |
// Purge post and post meta
|
116 |
-
|
117 |
|
118 |
$backup_job_purge_count = WPBackItUp_Job::purge_jobs( WPBackItUp_Job::BACKUP,$backup_retention);
|
119 |
-
|
120 |
|
121 |
$cleanup_job_purge_count = WPBackItUp_Job::purge_jobs( WPBackItUp_Job::CLEANUP,2);
|
122 |
-
|
123 |
|
124 |
-
|
125 |
/* -----------------------------------------------------------------------*/
|
126 |
|
127 |
|
@@ -130,17 +130,17 @@ if ('task_scheduled_cleanup'==$current_task->getTaskName()) {
|
|
130 |
/* -----------------------------------------------------------------------*/
|
131 |
|
132 |
// Purge all folders if they have temp prefix
|
133 |
-
|
134 |
|
135 |
//cleanup any folders that have the TMP_ prefix
|
136 |
$wp_backup->cleanup_backups_by_prefix('TMP_');
|
137 |
-
|
138 |
|
139 |
-
|
140 |
//cleanup any folders that have the DLT_ prefix
|
141 |
$wp_backup->cleanup_backups_by_prefix('DLT_');
|
142 |
|
143 |
-
|
144 |
/* -----------------------------------------------------------------------*/
|
145 |
|
146 |
|
@@ -148,17 +148,17 @@ if ('task_scheduled_cleanup'==$current_task->getTaskName()) {
|
|
148 |
/* ** PURGE: BACKUP/RESTORE FOLDERS/FILES ** */
|
149 |
/* -----------------------------------------------------------------------*/
|
150 |
//Purge orphaned backup folders - folders with no job control record
|
151 |
-
|
152 |
$wp_backup->purge_orphaned_backups();
|
153 |
-
|
154 |
|
155 |
|
156 |
//remove all the old restore folders
|
157 |
if( class_exists( 'WPBackItUp_Premium_Restore' ) ) {
|
158 |
-
|
159 |
$wp_restore = new WPBackItUp_Premium_Restore($cleanup_logname,$job_name,null);
|
160 |
$wp_restore->delete_restore_folder();
|
161 |
-
|
162 |
}
|
163 |
/* -----------------------------------------------------------------------*/
|
164 |
|
@@ -166,12 +166,12 @@ if ('task_scheduled_cleanup'==$current_task->getTaskName()) {
|
|
166 |
/* -----------------------------------------------------------------------*/
|
167 |
/* ** PURGE OLD FILES ** */
|
168 |
/* -----------------------------------------------------------------------*/
|
169 |
-
|
170 |
|
171 |
// purge old files from the backup and logs folders - this is NOT for backups
|
172 |
$wp_backup->purge_old_files();
|
173 |
|
174 |
-
|
175 |
/* -----------------------------------------------------------------------*/
|
176 |
|
177 |
|
@@ -179,7 +179,7 @@ if ('task_scheduled_cleanup'==$current_task->getTaskName()) {
|
|
179 |
/* -----------------------------------------------------------------------*/
|
180 |
/* ** SECURE FOLDERS ** */
|
181 |
/* -----------------------------------------------------------------------*/
|
182 |
-
|
183 |
$file_system = new WPBackItUp_FileSystem($cleanup_logname);
|
184 |
|
185 |
//Make sure backup folder is secured
|
@@ -194,7 +194,7 @@ if ('task_scheduled_cleanup'==$current_task->getTaskName()) {
|
|
194 |
$logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs/';
|
195 |
$file_system->secure_folder( $logs_dir);
|
196 |
|
197 |
-
|
198 |
/* -----------------------------------------------------------------------*/
|
199 |
|
200 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
@@ -211,7 +211,7 @@ return true;
|
|
211 |
/******************/
|
212 |
function end_job($err=null, $success=null){
|
213 |
global $WPBackitup, $cleanup_logname, $current_job;
|
214 |
-
|
215 |
|
216 |
$current_datetime = current_time( 'timestamp' );
|
217 |
$WPBackitup->set_cleanup_lastrun_date($current_datetime);
|
@@ -222,11 +222,11 @@ function end_job($err=null, $success=null){
|
|
222 |
$processing_minutes = round($seconds / 60);
|
223 |
$processing_seconds = $seconds % 60;
|
224 |
|
225 |
-
|
226 |
|
227 |
-
if (true===$success)
|
228 |
-
if (false===$success)
|
229 |
-
|
230 |
|
231 |
echo('cleanup has completed');
|
232 |
}
|
59 |
//*************************//
|
60 |
|
61 |
if (! is_object ($current_job)){
|
62 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,'Current job not object:');
|
63 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,var_export($current_job));
|
64 |
return false;
|
65 |
}
|
66 |
|
67 |
if (! is_object ($current_task)){
|
68 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,'Current task not object');
|
69 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,var_export($current_task));
|
70 |
return false;
|
71 |
}
|
72 |
|
73 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id ,'Run task:' .$current_task->getTaskName());
|
74 |
|
75 |
|
76 |
//*************************//
|
96 |
/* ** INIT **
|
97 |
/* -----------------------------------------------------------------------*/
|
98 |
|
99 |
+
WPBackItUp_Logger::log($cleanup_logname,'***BEGIN JOB***');
|
100 |
+
WPBackItUp_Logger::log_sysinfo($cleanup_logname);
|
101 |
|
102 |
+
WPBackItUp_Logger::log($cleanup_logname,'Backup Retention:' .$backup_retention);
|
103 |
|
104 |
//Check License
|
105 |
+
WPBackItUp_Logger::log($cleanup_logname,'**CHECK LICENSE**');
|
106 |
do_action( 'wpbackitup_check_license');
|
107 |
+
WPBackItUp_Logger::log($cleanup_logname,'**END CHECK LICENSE**');
|
108 |
/* -----------------------------------------------------------------------*/
|
109 |
|
110 |
|
113 |
/* -----------------------------------------------------------------------*/
|
114 |
|
115 |
// Purge post and post meta
|
116 |
+
WPBackItUp_Logger::log($cleanup_logname,'**CLEANUP JOB CONTROL RECORDS**' );
|
117 |
|
118 |
$backup_job_purge_count = WPBackItUp_Job::purge_jobs( WPBackItUp_Job::BACKUP,$backup_retention);
|
119 |
+
WPBackItUp_Logger::log($cleanup_logname,'Backup job control records purged:' .$backup_job_purge_count );
|
120 |
|
121 |
$cleanup_job_purge_count = WPBackItUp_Job::purge_jobs( WPBackItUp_Job::CLEANUP,2);
|
122 |
+
WPBackItUp_Logger::log_info($cleanup_logname,__METHOD__,'Cleanup job control records purged:' .$cleanup_job_purge_count );
|
123 |
|
124 |
+
WPBackItUp_Logger::log($cleanup_logname,'**END CLEANUP JOB CONTROL RECORDS**' );
|
125 |
/* -----------------------------------------------------------------------*/
|
126 |
|
127 |
|
130 |
/* -----------------------------------------------------------------------*/
|
131 |
|
132 |
// Purge all folders if they have temp prefix
|
133 |
+
WPBackItUp_Logger::log($cleanup_logname,'**CLEAN UNFINISHED BACKUPS**' );
|
134 |
|
135 |
//cleanup any folders that have the TMP_ prefix
|
136 |
$wp_backup->cleanup_backups_by_prefix('TMP_');
|
137 |
+
WPBackItUp_Logger::log($cleanup_logname,'**END CLEAN UNFINISHED BACKUPS**' );
|
138 |
|
139 |
+
WPBackItUp_Logger::log($cleanup_logname,'**CLEAN DELETED BACKUPS**' );
|
140 |
//cleanup any folders that have the DLT_ prefix
|
141 |
$wp_backup->cleanup_backups_by_prefix('DLT_');
|
142 |
|
143 |
+
WPBackItUp_Logger::log($cleanup_logname,'**END CLEAN DELETED BACKUPS**' );
|
144 |
/* -----------------------------------------------------------------------*/
|
145 |
|
146 |
|
148 |
/* ** PURGE: BACKUP/RESTORE FOLDERS/FILES ** */
|
149 |
/* -----------------------------------------------------------------------*/
|
150 |
//Purge orphaned backup folders - folders with no job control record
|
151 |
+
WPBackItUp_Logger::log($cleanup_logname,'**CLEAN OLD BACKUPS**' );
|
152 |
$wp_backup->purge_orphaned_backups();
|
153 |
+
WPBackItUp_Logger::log($cleanup_logname,'**END CLEAN OLD BACKUPS**' );
|
154 |
|
155 |
|
156 |
//remove all the old restore folders
|
157 |
if( class_exists( 'WPBackItUp_Premium_Restore' ) ) {
|
158 |
+
WPBackItUp_Logger::log($cleanup_logname,'**CLEAN OLD RESTORES**' );
|
159 |
$wp_restore = new WPBackItUp_Premium_Restore($cleanup_logname,$job_name,null);
|
160 |
$wp_restore->delete_restore_folder();
|
161 |
+
WPBackItUp_Logger::log($cleanup_logname,'**END CLEAN OLD RESTORES**' );
|
162 |
}
|
163 |
/* -----------------------------------------------------------------------*/
|
164 |
|
166 |
/* -----------------------------------------------------------------------*/
|
167 |
/* ** PURGE OLD FILES ** */
|
168 |
/* -----------------------------------------------------------------------*/
|
169 |
+
WPBackItUp_Logger::log($cleanup_logname,'**PURGE OLD FILES**' );
|
170 |
|
171 |
// purge old files from the backup and logs folders - this is NOT for backups
|
172 |
$wp_backup->purge_old_files();
|
173 |
|
174 |
+
WPBackItUp_Logger::log($cleanup_logname,'**END PURGE OLD FILES**' );
|
175 |
/* -----------------------------------------------------------------------*/
|
176 |
|
177 |
|
179 |
/* -----------------------------------------------------------------------*/
|
180 |
/* ** SECURE FOLDERS ** */
|
181 |
/* -----------------------------------------------------------------------*/
|
182 |
+
WPBackItUp_Logger::log($cleanup_logname,'**SECURE FOLDERS**' );
|
183 |
$file_system = new WPBackItUp_FileSystem($cleanup_logname);
|
184 |
|
185 |
//Make sure backup folder is secured
|
194 |
$logs_dir = WPBACKITUP__PLUGIN_PATH .'/logs/';
|
195 |
$file_system->secure_folder( $logs_dir);
|
196 |
|
197 |
+
WPBackItUp_Logger::log($cleanup_logname,'**END SECURE FOLDERS**' );
|
198 |
/* -----------------------------------------------------------------------*/
|
199 |
|
200 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
211 |
/******************/
|
212 |
function end_job($err=null, $success=null){
|
213 |
global $WPBackitup, $cleanup_logname, $current_job;
|
214 |
+
WPBackItUp_Logger::log_info($cleanup_logname,__METHOD__,'Begin');
|
215 |
|
216 |
$current_datetime = current_time( 'timestamp' );
|
217 |
$WPBackitup->set_cleanup_lastrun_date($current_datetime);
|
222 |
$processing_minutes = round($seconds / 60);
|
223 |
$processing_seconds = $seconds % 60;
|
224 |
|
225 |
+
WPBackItUp_Logger::log_info($cleanup_logname,__METHOD__,'Script Processing Time:' .$processing_minutes .' Minutes ' .$processing_seconds .' Seconds');
|
226 |
|
227 |
+
if (true===$success) WPBackItUp_Logger::log($cleanup_logname,'Cleanup completed: SUCCESS');
|
228 |
+
if (false===$success) WPBackItUp_Logger::log($cleanup_logname,'Cleanup completed: ERROR');
|
229 |
+
WPBackItUp_Logger::log($cleanup_logname,'*** END JOB ***');
|
230 |
|
231 |
echo('cleanup has completed');
|
232 |
}
|
lib/includes/job_restore.php
CHANGED
@@ -82,18 +82,18 @@ $WPBackitup->set_logging(true);
|
|
82 |
|
83 |
|
84 |
if (! is_object ($current_job)){
|
85 |
-
|
86 |
-
|
87 |
return false;
|
88 |
}
|
89 |
|
90 |
if (! is_object ($current_task)){
|
91 |
-
|
92 |
-
|
93 |
return false;
|
94 |
}
|
95 |
|
96 |
-
|
97 |
|
98 |
|
99 |
//Get the job name
|
@@ -104,7 +104,7 @@ $log_function='job_restore::'.$current_task->getTaskName();
|
|
104 |
|
105 |
$backup_name = $current_job->getJobMetaValue('backup_name');
|
106 |
if( empty($backup_name)) {
|
107 |
-
|
108 |
write_fatal_error_status('error201');
|
109 |
end_restore();
|
110 |
return false;
|
@@ -113,7 +113,7 @@ if( empty($backup_name)) {
|
|
113 |
//Get user ID
|
114 |
$user_id = $current_job->getJobMetaValue('user_id');
|
115 |
if( empty($user_id)) {
|
116 |
-
|
117 |
write_fatal_error_status('error201');
|
118 |
end_restore();
|
119 |
return false;
|
@@ -121,8 +121,8 @@ if( empty($user_id)) {
|
|
121 |
|
122 |
//IF premium isnt installed then error
|
123 |
if( ! class_exists( 'WPBackItUp_Premium_Restore' )) {
|
124 |
-
|
125 |
-
|
126 |
|
127 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,9998);
|
128 |
fatal_error( 'WPBackItUp Premium is not installed', '9998', 'Task ended in error:'.$current_task->getTaskName() );
|
@@ -131,8 +131,8 @@ if( ! class_exists( 'WPBackItUp_Premium_Restore' )) {
|
|
131 |
|
132 |
$wpbackitup_license = new WPBackItUp_License();
|
133 |
if ( ! $wpbackitup_license->is_license_active()){
|
134 |
-
|
135 |
-
|
136 |
|
137 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,9999);
|
138 |
fatal_error( 'WPBackItUp Premium License is not active', '9999', 'Task ended in error:'.$current_task->getTaskName() );
|
@@ -149,11 +149,11 @@ $wp_restore = new WPBackItUp_Premium_Restore($restore_logname,$backup_name,$curr
|
|
149 |
//An error has occurred on the previous run
|
150 |
if (WPBackItUp_Job::ERROR==$current_task->getStatus()){
|
151 |
|
152 |
-
|
153 |
|
154 |
//Fetch last wordpress error(might not be related to timeout)
|
155 |
//error type constants: http://php.net/manual/en/errorfunc.constants.php
|
156 |
-
|
157 |
|
158 |
//Check for error type
|
159 |
switch ( $current_task->getTaskName() ) {
|
@@ -203,15 +203,15 @@ if (WPBackItUp_Job::ERROR==$current_task->getStatus()){
|
|
203 |
|
204 |
//Cleanup Task
|
205 |
if ('task_preparing'==$current_task->getTaskName()) {
|
206 |
-
|
207 |
-
|
208 |
|
209 |
$task = 'preparing';
|
210 |
start_status($task);
|
211 |
|
212 |
$WPBackitup->increment_restore_count();
|
213 |
|
214 |
-
|
215 |
|
216 |
//ONLY check license here and prevent restore from starting. If
|
217 |
//IF license check fails in later steps could be because DB was restored and no license on backup
|
@@ -230,31 +230,31 @@ if ('task_preparing'==$current_task->getTaskName()) {
|
|
230 |
return false;
|
231 |
}
|
232 |
|
233 |
-
|
234 |
if ( ! $wp_restore->delete_restore_folder()){
|
235 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,222);
|
236 |
fatal_error($task,'222','Restore folder could not be deleted.');
|
237 |
return false;
|
238 |
}
|
239 |
-
|
240 |
|
241 |
-
|
242 |
if ( ! $wp_restore->create_restore_root_folder()){
|
243 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,222);
|
244 |
fatal_error($task,'222','Root Restore folder could not be created.');
|
245 |
return false;
|
246 |
}
|
247 |
-
|
248 |
|
249 |
-
|
250 |
if ( ! $wp_restore->delete_staged_folders()){
|
251 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,222);
|
252 |
fatal_error($task, '222','Staged folders could not be deleted.');
|
253 |
return false;
|
254 |
}
|
255 |
-
|
256 |
|
257 |
-
|
258 |
$siteurl = $wp_restore->get_siteurl();
|
259 |
if (false===$siteurl){
|
260 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,207);
|
@@ -299,10 +299,10 @@ if ('task_preparing'==$current_task->getTaskName()) {
|
|
299 |
$current_job->setJobMetaValue('wpbackitup_options',$wpbackitup_options);
|
300 |
}
|
301 |
|
302 |
-
|
303 |
|
304 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
305 |
-
|
306 |
|
307 |
end_status($task);
|
308 |
return;
|
@@ -312,7 +312,7 @@ if ('task_preparing'==$current_task->getTaskName()) {
|
|
312 |
//Check for backup set in folder
|
313 |
if ('task_inventory_backupset'==$current_task->getTaskName()) {
|
314 |
|
315 |
-
|
316 |
|
317 |
$task = 'unpacking';
|
318 |
start_status($task);
|
@@ -329,7 +329,7 @@ if ('task_inventory_backupset'==$current_task->getTaskName()) {
|
|
329 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
330 |
|
331 |
|
332 |
-
|
333 |
|
334 |
return;
|
335 |
|
@@ -341,42 +341,42 @@ if ('task_inventory_backupset'==$current_task->getTaskName()) {
|
|
341 |
//do this even if no backupset
|
342 |
//Unpack backup set and update job meta
|
343 |
if ('task_unpack_backupset'==$current_task->getTaskName()) {
|
344 |
-
|
345 |
|
346 |
$task = 'unpacking';
|
347 |
start_status($task);
|
348 |
|
349 |
//Are there any backups to unpack from set file
|
350 |
$backupset_unpack_remaining = $current_job->getJobMetaValue('backupset_unpack_remaining');
|
351 |
-
|
352 |
|
353 |
if (is_array($backupset_unpack_remaining) && count($backupset_unpack_remaining)>0) {
|
354 |
|
355 |
//found one so unpack it
|
356 |
$backup_file = current($backupset_unpack_remaining);
|
357 |
$backup_file_key = key($backupset_unpack_remaining);
|
358 |
-
|
359 |
|
360 |
//Get backup set file
|
361 |
$backupset_file = $current_job->getJobMetaValue('backupset_file');
|
362 |
-
|
363 |
|
364 |
if ($wp_restore->unpack_backup_from_backupset( $current_job, $current_task,$backupset_file,$backup_file )){
|
365 |
|
366 |
//remove this element and save to job meta
|
367 |
unset($backupset_unpack_remaining[$backup_file_key]);
|
368 |
$current_job->setJobMetaValue('backupset_unpack_remaining',$backupset_unpack_remaining);//save to job meta for next task
|
369 |
-
|
370 |
|
371 |
//If there are more files to unpack then set task to queued and return
|
372 |
if (is_array($backupset_unpack_remaining) && count($backupset_unpack_remaining)>0) {
|
373 |
$current_task->setStatus( WPBackItUp_Job_Task::QUEUED );
|
374 |
-
|
375 |
return;
|
376 |
}
|
377 |
} else{
|
378 |
//Error occurred
|
379 |
-
|
380 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,260);
|
381 |
fatal_error($task,'260','Unable to unpack backup from backup set.');
|
382 |
return false;
|
@@ -389,39 +389,39 @@ if ('task_unpack_backupset'==$current_task->getTaskName()) {
|
|
389 |
//get the backup files contained in the backup folder
|
390 |
$backup_files = $wp_restore->get_backups_in_folder($current_job,$current_task,false);
|
391 |
if (is_array($backup_files)){
|
392 |
-
|
393 |
|
394 |
$current_job->setJobMetaValue('backup_set',$backup_files);
|
395 |
|
396 |
foreach ($backup_files as $key =>$backup_zip){
|
397 |
|
398 |
if (false===$current_job->getJobMetaValue( 'restore_plugins') && false !== strpos( $backup_zip, '-plugins-' )){
|
399 |
-
|
400 |
unset($backup_files[$key]);//remove from array
|
401 |
continue;
|
402 |
}
|
403 |
|
404 |
if (false===$current_job->getJobMetaValue( 'restore_themes') && false !== strpos( $backup_zip, '-themes-' )){
|
405 |
-
|
406 |
unset($backup_files[$key]);//remove from array
|
407 |
continue;
|
408 |
}
|
409 |
|
410 |
if (false===$current_job->getJobMetaValue( 'restore_uploads') && false !== strpos( $backup_zip, '-uploads-' )){
|
411 |
-
|
412 |
unset($backup_files[$key]);//remove from array
|
413 |
continue;
|
414 |
}
|
415 |
|
416 |
if (false===$current_job->getJobMetaValue( 'restore_others') && false !== strpos( $backup_zip, '-others-' )){
|
417 |
-
|
418 |
unset($backup_files[$key]);//remove from array
|
419 |
continue;
|
420 |
}
|
421 |
|
422 |
}
|
423 |
|
424 |
-
|
425 |
$current_job->setJobMetaValue('backup_set_remaining',$backup_files);
|
426 |
|
427 |
}else{
|
@@ -431,11 +431,11 @@ if ('task_unpack_backupset'==$current_task->getTaskName()) {
|
|
431 |
}
|
432 |
|
433 |
$current_task->setStatus( WPBackItUp_Job_Task::COMPLETE );
|
434 |
-
|
435 |
|
436 |
end_status($task);
|
437 |
|
438 |
-
|
439 |
return;
|
440 |
}
|
441 |
|
@@ -444,14 +444,14 @@ if ('task_unpack_backupset'==$current_task->getTaskName()) {
|
|
444 |
//- check for backupset archive FIRST
|
445 |
if ('task_unzip_backup_files'==$current_task->getTaskName()) {
|
446 |
|
447 |
-
|
448 |
$task = 'unzipping';
|
449 |
start_status($task);
|
450 |
|
451 |
//get the list of plugins zips in folder
|
452 |
$backup_set_list=$current_job->getJobMetaValue('backup_set_remaining');
|
453 |
-
|
454 |
-
|
455 |
|
456 |
if ( ! $wp_restore->unzip_archive_file( $backup_set_list) ) {
|
457 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,203);
|
@@ -464,14 +464,14 @@ if ('task_unzip_backup_files'==$current_task->getTaskName()) {
|
|
464 |
|
465 |
if (is_array($backup_set_list) && count($backup_set_list)>0){
|
466 |
//CONTINUE
|
467 |
-
|
468 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
469 |
} else{
|
470 |
//COMPLETE
|
471 |
-
|
472 |
end_status( $task);
|
473 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
474 |
-
|
475 |
}
|
476 |
|
477 |
}
|
@@ -483,7 +483,7 @@ if ('task_unzip_backup_files'==$current_task->getTaskName()) {
|
|
483 |
|
484 |
//Validate the backup folder against the manifest
|
485 |
if ('task_validate_backup'==$current_task->getTaskName()) {
|
486 |
-
|
487 |
|
488 |
$task = 'validation';
|
489 |
start_status($task);
|
@@ -495,11 +495,11 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
495 |
return false;
|
496 |
}
|
497 |
|
498 |
-
|
499 |
$backup_set_list=$current_job->getJobMetaValue('backup_set');
|
500 |
if ( $wp_restore->validate_manifest_file($backup_set_list,$error_code)===false){
|
501 |
|
502 |
-
|
503 |
|
504 |
switch ($error_code) {
|
505 |
case 1:
|
@@ -530,9 +530,9 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
530 |
return false;
|
531 |
|
532 |
}
|
533 |
-
|
534 |
|
535 |
-
|
536 |
//validate the site data file
|
537 |
$site_info = $wp_restore->validate_siteinfo_file();
|
538 |
|
@@ -554,7 +554,7 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
554 |
//need to do this for old backups
|
555 |
if ( is_null( $snapshot_prefix )) {
|
556 |
//Check table prefix values FATAL
|
557 |
-
|
558 |
if ( $table_prefix != $site_info['table_prefix'] ) {
|
559 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,221);
|
560 |
fatal_error($task,'221','Table prefix different from restore.');
|
@@ -566,10 +566,10 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
566 |
if($WPBackitup->rversion_compare() === 0){
|
567 |
$site_wordpress_version = get_bloginfo('version');
|
568 |
$backup_wordpress_version = $site_info['wp_version'];
|
569 |
-
|
570 |
-
|
571 |
if ( ! WPBackItUp_Utility::version_compare($site_wordpress_version, $backup_wordpress_version )) {
|
572 |
-
|
573 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,226);
|
574 |
fatal_error($task,'226','Backup was created using different version of wordpress');
|
575 |
return false;
|
@@ -578,36 +578,36 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
578 |
|
579 |
$restore_wpbackitup_version = $site_info['wpbackitup_version'];
|
580 |
$current_wpbackitup_version = WPBACKITUP__VERSION;
|
581 |
-
|
582 |
-
|
583 |
if (! WPBackItUp_Utility::version_compare($restore_wpbackitup_version, $current_wpbackitup_version )){
|
584 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,227);
|
585 |
fatal_error($task,'227','Backup was created using different version of WPBackItUp');
|
586 |
return false;
|
587 |
}
|
588 |
}
|
589 |
-
|
590 |
|
591 |
|
592 |
//all SQL files will be added to the jon_item table during validation
|
593 |
-
|
594 |
if ( ! $wp_restore->validate_SQL_add_items( )){
|
595 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,216);
|
596 |
fatal_error($task,'216','NO Database backups in backup.');
|
597 |
return false;
|
598 |
}
|
599 |
-
|
600 |
end_status($task);
|
601 |
|
602 |
-
|
603 |
$task='deactivate_plugins';
|
604 |
start_status($task);
|
605 |
$wp_restore->deactivate_plugins();
|
606 |
end_status($task);
|
607 |
-
|
608 |
|
609 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
610 |
-
|
611 |
|
612 |
return;
|
613 |
}
|
@@ -616,7 +616,7 @@ if ('task_validate_backup'==$current_task->getTaskName()) {
|
|
616 |
//import the snaphsot tables v1.13+
|
617 |
if ('task_import_database'==$current_task->getTaskName()) {
|
618 |
|
619 |
-
|
620 |
$task ='import_database';
|
621 |
start_status($task);
|
622 |
|
@@ -634,7 +634,7 @@ if ('task_import_database'==$current_task->getTaskName()) {
|
|
634 |
if ( ! is_null( $snapshot_prefix )) {
|
635 |
//V1.13+
|
636 |
$tables_remaining_count =$wp_restore->import_database($current_job,$snapshot_prefix);
|
637 |
-
|
638 |
if (false===$tables_remaining_count) {
|
639 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,212);
|
640 |
fatal_error($task,'212','Snapshot NOT imported.');
|
@@ -642,24 +642,24 @@ if ('task_import_database'==$current_task->getTaskName()) {
|
|
642 |
}else{
|
643 |
if ($tables_remaining_count>0){
|
644 |
//CONTINUE
|
645 |
-
|
646 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
647 |
return;
|
648 |
}
|
649 |
}
|
650 |
} else {
|
651 |
-
|
652 |
}
|
653 |
}else {
|
654 |
-
|
655 |
}
|
656 |
|
657 |
//DB Restore Complete
|
658 |
-
|
659 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
660 |
end_status($task);
|
661 |
|
662 |
-
|
663 |
return;
|
664 |
|
665 |
}
|
@@ -668,7 +668,7 @@ if ('task_import_database'==$current_task->getTaskName()) {
|
|
668 |
//Update the snapshot tables V1.13+
|
669 |
if ('task_update_snapshot'==$current_task->getTaskName()) {
|
670 |
|
671 |
-
|
672 |
$task ='update_database';
|
673 |
start_status($task);
|
674 |
|
@@ -690,15 +690,15 @@ if ('task_update_snapshot'==$current_task->getTaskName()) {
|
|
690 |
return false;
|
691 |
}
|
692 |
}else {
|
693 |
-
|
694 |
}
|
695 |
}else{
|
696 |
-
|
697 |
}
|
698 |
|
699 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
700 |
end_status($task);
|
701 |
-
|
702 |
return true;
|
703 |
|
704 |
}
|
@@ -706,7 +706,7 @@ if ('task_update_snapshot'==$current_task->getTaskName()) {
|
|
706 |
|
707 |
//Stage WP content folders
|
708 |
if ('task_stage_wpcontent'==$current_task->getTaskName()) {
|
709 |
-
|
710 |
$task = 'stage_wpcontent';
|
711 |
|
712 |
start_status($task);
|
@@ -714,7 +714,7 @@ if ('task_stage_wpcontent'==$current_task->getTaskName()) {
|
|
714 |
$folder_stage_suffix = $wp_restore->get_restore_staging_suffix();
|
715 |
|
716 |
//Stage all but plugins
|
717 |
-
|
718 |
if (true===$current_job->getJobMetaValue('restore_themes')) {
|
719 |
|
720 |
$from_folder_name = $wp_restore->get_restore_root_folder_path() . '/' . WPBackItUp_Premium_Restore::THEMESPATH;
|
@@ -728,12 +728,12 @@ if ('task_stage_wpcontent'==$current_task->getTaskName()) {
|
|
728 |
}
|
729 |
|
730 |
} else {
|
731 |
-
|
732 |
}
|
733 |
-
|
734 |
|
735 |
|
736 |
-
|
737 |
if (true===$current_job->getJobMetaValue('restore_uploads')) {
|
738 |
if ( ! $wp_restore->validate_no_uploads() ) {
|
739 |
$from_folder_name = $wp_restore->get_restore_root_folder_path() . '/' . WPBackItUp_Premium_Restore::UPLOADPATH;
|
@@ -751,12 +751,12 @@ if ('task_stage_wpcontent'==$current_task->getTaskName()) {
|
|
751 |
}
|
752 |
|
753 |
} else {
|
754 |
-
|
755 |
}
|
756 |
-
|
757 |
|
758 |
|
759 |
-
|
760 |
if (true===$current_job->getJobMetaValue('restore_others')) {
|
761 |
|
762 |
$other_list = glob( $wp_restore->get_restore_root_folder_path() . '/' . WPBackItUp_Premium_Restore::OTHERPATH . '/*', GLOB_ONLYDIR | GLOB_NOSORT );
|
@@ -773,15 +773,15 @@ if ('task_stage_wpcontent'==$current_task->getTaskName()) {
|
|
773 |
}
|
774 |
|
775 |
} else {
|
776 |
-
|
777 |
}
|
778 |
-
|
779 |
|
780 |
end_status( $task );
|
781 |
|
782 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);;
|
783 |
|
784 |
-
|
785 |
|
786 |
return;
|
787 |
}
|
@@ -790,22 +790,22 @@ if ('task_stage_wpcontent'==$current_task->getTaskName()) {
|
|
790 |
//Rename the staged folders to current
|
791 |
if ('task_restore_wpcontent'==$current_task->getTaskName()) {
|
792 |
|
793 |
-
|
794 |
$task ='restore_wpcontent';
|
795 |
start_status($task);
|
796 |
|
797 |
|
798 |
//This step will restore anything that was staged
|
799 |
-
|
800 |
$wpcontent_restore = $wp_restore->restore_wpcontent();
|
801 |
if ( ! $wpcontent_restore === true ) {
|
802 |
//array with failed list returned
|
803 |
//If any of them fail call it done.
|
804 |
warning( '300', 'Cant restore all WP content.' );
|
805 |
}
|
806 |
-
|
807 |
|
808 |
-
|
809 |
if (true===$current_job->getJobMetaValue('restore_plugins')) {
|
810 |
$plugin_restore = $wp_restore->restore_plugins();
|
811 |
if ( ! $plugin_restore === true ) {
|
@@ -813,13 +813,13 @@ if ('task_restore_wpcontent'==$current_task->getTaskName()) {
|
|
813 |
warning( '305', 'Couldnt restore all plugins.' );
|
814 |
}
|
815 |
} else{
|
816 |
-
|
817 |
}
|
818 |
-
|
819 |
|
820 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);;
|
821 |
end_status($task);
|
822 |
-
|
823 |
|
824 |
return;
|
825 |
}
|
@@ -827,7 +827,7 @@ if ('task_restore_wpcontent'==$current_task->getTaskName()) {
|
|
827 |
//restore the DB
|
828 |
if ('task_restore_database'==$current_task->getTaskName()) {
|
829 |
|
830 |
-
|
831 |
$task ='restore_database';
|
832 |
start_status($task);
|
833 |
|
@@ -844,7 +844,7 @@ if ('task_restore_database'==$current_task->getTaskName()) {
|
|
844 |
$rename_sql_file = $current_job->getJobMetaValue( 'rename_sql' );
|
845 |
if ( ! is_null( $rename_sql_file ) ) {
|
846 |
if ( false === $wp_restore->rename_snapshot_tables( $rename_sql_file ) ) {
|
847 |
-
|
848 |
|
849 |
$current_task->setStatus( WPBackItUp_Job_Task::ERROR, 212 );
|
850 |
fatal_error( $task, '240', 'Database NOT restored.' );
|
@@ -859,7 +859,7 @@ if ('task_restore_database'==$current_task->getTaskName()) {
|
|
859 |
|
860 |
//Not going to use the restore Point SQL because IF the import failed then DB may be intact
|
861 |
//$tables_remaining_count =$wp_restore->restore_database($current_job);
|
862 |
-
|
863 |
if ( false === $tables_remaining_count ) {
|
864 |
$current_task->setStatus( WPBackItUp_Job_Task::ERROR, 212 );
|
865 |
fatal_error( $task, '240', 'Database NOT restored.' );
|
@@ -868,7 +868,7 @@ if ('task_restore_database'==$current_task->getTaskName()) {
|
|
868 |
} else {
|
869 |
if ( $tables_remaining_count > 0 ) {
|
870 |
//CONTINUE
|
871 |
-
|
872 |
$current_task->setStatus( WPBackItUp_Job_Task::QUEUED );
|
873 |
|
874 |
return;
|
@@ -876,14 +876,14 @@ if ('task_restore_database'==$current_task->getTaskName()) {
|
|
876 |
}
|
877 |
}
|
878 |
} else {
|
879 |
-
|
880 |
}
|
881 |
|
882 |
//DB Restore Complete
|
883 |
-
//
|
884 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
885 |
end_status($task);
|
886 |
-
|
887 |
|
888 |
|
889 |
start_status('update_permalinks');
|
@@ -891,11 +891,11 @@ if ('task_restore_database'==$current_task->getTaskName()) {
|
|
891 |
//Check job flag
|
892 |
if (true===$current_job->getJobMetaValue('restore_update_permalinks')) {
|
893 |
if ( ! $wp_restore->update_permalinks() ) {
|
894 |
-
|
895 |
//dont do anything
|
896 |
}
|
897 |
} else {
|
898 |
-
|
899 |
}
|
900 |
|
901 |
end_status('update_permalinks');
|
@@ -910,20 +910,20 @@ if ('task_restore_database'==$current_task->getTaskName()) {
|
|
910 |
//if wp-backitup-premium is not included
|
911 |
if (false === array_search('wp-backitup-premium/wp-backitup-premium.php', $active_plugins_array)){
|
912 |
$active_plugins_array[]='wp-backitup-premium/wp-backitup-premium.php'; //add to array
|
913 |
-
|
914 |
}
|
915 |
|
916 |
//Update active plugin option
|
917 |
if ( false===$wp_restore->update_create_option( 'active_plugins', $active_plugins_array, 'yes' ) ) {
|
918 |
-
|
919 |
}
|
920 |
|
921 |
} else {
|
922 |
-
|
923 |
}
|
924 |
|
925 |
} else {
|
926 |
-
|
927 |
}
|
928 |
|
929 |
|
@@ -936,8 +936,8 @@ if ('task_restore_database'==$current_task->getTaskName()) {
|
|
936 |
$WPBackitup->increment_successful_restore_count();
|
937 |
$current_job->setStatus(WPBackItUp_Job::COMPLETE);
|
938 |
set_status_success();
|
939 |
-
|
940 |
-
|
941 |
|
942 |
end_restore(null,true);
|
943 |
return true;
|
@@ -953,7 +953,7 @@ return;
|
|
953 |
function fatal_error($process,$error_code,$error_message, $end=true){
|
954 |
global $current_job, $failure, $restore_logname;
|
955 |
|
956 |
-
|
957 |
$current_job->setStatus(WPBackItUp_Job::ERROR);
|
958 |
|
959 |
write_response_file_error($error_code,$error_message);
|
@@ -969,7 +969,7 @@ function fatal_error($process,$error_code,$error_message, $end=true){
|
|
969 |
function warning($error_code,$warning_message) {
|
970 |
global $restore_logname, $status_array,$warning;
|
971 |
|
972 |
-
|
973 |
|
974 |
//Add warning to array
|
975 |
$status_array['warning' .$error_code]=$warning;
|
@@ -1021,7 +1021,7 @@ function write_response_file($JSON_Response) {
|
|
1021 |
global $restore_logname;
|
1022 |
|
1023 |
$json_response = json_encode($JSON_Response);
|
1024 |
-
|
1025 |
|
1026 |
$fh=get_response_file();
|
1027 |
fwrite($fh, $json_response);
|
@@ -1113,23 +1113,23 @@ function set_status_success(){
|
|
1113 |
function end_restore($err=null, $success=null){
|
1114 |
global $current_job, $restore_logname;
|
1115 |
|
1116 |
-
if (true===$success)
|
1117 |
-
if (false===$success)
|
1118 |
|
1119 |
//copy/replace WP debug file
|
1120 |
$logs_path = WPBACKITUP__PLUGIN_PATH .'logs';
|
1121 |
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
1122 |
-
|
1123 |
if (file_exists($wpdebug_file_path)) {
|
1124 |
$debug_log = sprintf('%s/wpdebug_%s.log',$logs_path,$current_job->getJobId());
|
1125 |
copy( $wpdebug_file_path, $debug_log );
|
1126 |
}
|
1127 |
|
1128 |
-
|
1129 |
|
1130 |
|
1131 |
//Close the logger
|
1132 |
-
|
1133 |
$current_job->release_lock();
|
1134 |
|
1135 |
//response back the status file since this method will end processing
|
82 |
|
83 |
|
84 |
if (! is_object ($current_job)){
|
85 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,'Current job not object:');
|
86 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,var_export($current_job));
|
87 |
return false;
|
88 |
}
|
89 |
|
90 |
if (! is_object ($current_task)){
|
91 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,'Current task not object');
|
92 |
+
WPBackItUp_Logger::log_error($events_logname,$process_id,var_export($current_task));
|
93 |
return false;
|
94 |
}
|
95 |
|
96 |
+
WPBackItUp_Logger::log_info($events_logname,$process_id ,'Run task:' .$current_task->getTaskName());
|
97 |
|
98 |
|
99 |
//Get the job name
|
104 |
|
105 |
$backup_name = $current_job->getJobMetaValue('backup_name');
|
106 |
if( empty($backup_name)) {
|
107 |
+
WPBackItUp_Logger::log_error($restore_logname,$log_function,'Backup name not found in job meta.');
|
108 |
write_fatal_error_status('error201');
|
109 |
end_restore();
|
110 |
return false;
|
113 |
//Get user ID
|
114 |
$user_id = $current_job->getJobMetaValue('user_id');
|
115 |
if( empty($user_id)) {
|
116 |
+
WPBackItUp_Logger::log_error($restore_logname,$log_function,'User Id not found in job meta.');
|
117 |
write_fatal_error_status('error201');
|
118 |
end_restore();
|
119 |
return false;
|
121 |
|
122 |
//IF premium isnt installed then error
|
123 |
if( ! class_exists( 'WPBackItUp_Premium_Restore' )) {
|
124 |
+
WPBackItUp_Logger::log_sysinfo($restore_logname);
|
125 |
+
WPBackItUp_Logger::log_error($restore_logname,$log_function,'WPBackItUp Premium is not installed');
|
126 |
|
127 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,9998);
|
128 |
fatal_error( 'WPBackItUp Premium is not installed', '9998', 'Task ended in error:'.$current_task->getTaskName() );
|
131 |
|
132 |
$wpbackitup_license = new WPBackItUp_License();
|
133 |
if ( ! $wpbackitup_license->is_license_active()){
|
134 |
+
WPBackItUp_Logger::log_sysinfo($restore_logname);
|
135 |
+
WPBackItUp_Logger::log_error($restore_logname,$log_function,'WPBackItUp Premium License is not active');
|
136 |
|
137 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,9999);
|
138 |
fatal_error( 'WPBackItUp Premium License is not active', '9999', 'Task ended in error:'.$current_task->getTaskName() );
|
149 |
//An error has occurred on the previous run
|
150 |
if (WPBackItUp_Job::ERROR==$current_task->getStatus()){
|
151 |
|
152 |
+
WPBackItUp_Logger::log_error($restore_logname,$log_function,'Fatal error on previous task:'. $current_task->getTaskName());
|
153 |
|
154 |
//Fetch last wordpress error(might not be related to timeout)
|
155 |
//error type constants: http://php.net/manual/en/errorfunc.constants.php
|
156 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Last Error: ' .var_export(error_get_last(),true));
|
157 |
|
158 |
//Check for error type
|
159 |
switch ( $current_task->getTaskName() ) {
|
203 |
|
204 |
//Cleanup Task
|
205 |
if ('task_preparing'==$current_task->getTaskName()) {
|
206 |
+
WPBackItUp_Logger::log($restore_logname,'***BEGIN RESTORE***');
|
207 |
+
WPBackItUp_Logger::log_sysinfo($restore_logname);
|
208 |
|
209 |
$task = 'preparing';
|
210 |
start_status($task);
|
211 |
|
212 |
$WPBackitup->increment_restore_count();
|
213 |
|
214 |
+
WPBackItUp_Logger::log($restore_logname,'**PREPARING FOR RESTORE**');
|
215 |
|
216 |
//ONLY check license here and prevent restore from starting. If
|
217 |
//IF license check fails in later steps could be because DB was restored and no license on backup
|
230 |
return false;
|
231 |
}
|
232 |
|
233 |
+
WPBackItUp_Logger::log($restore_logname,'*DELETE RESTORE FOLDER*');
|
234 |
if ( ! $wp_restore->delete_restore_folder()){
|
235 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,222);
|
236 |
fatal_error($task,'222','Restore folder could not be deleted.');
|
237 |
return false;
|
238 |
}
|
239 |
+
WPBackItUp_Logger::log($restore_logname,'*END DELETE RESTORE FOLDER*');
|
240 |
|
241 |
+
WPBackItUp_Logger::log($restore_logname,'*CREATE ROOT RESTORE FOLDER*');
|
242 |
if ( ! $wp_restore->create_restore_root_folder()){
|
243 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,222);
|
244 |
fatal_error($task,'222','Root Restore folder could not be created.');
|
245 |
return false;
|
246 |
}
|
247 |
+
WPBackItUp_Logger::log($restore_logname,'*END CREATE RESTORE FOLDER*');
|
248 |
|
249 |
+
WPBackItUp_Logger::log($restore_logname,'*DELETE STAGED FOLDER*');
|
250 |
if ( ! $wp_restore->delete_staged_folders()){
|
251 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,222);
|
252 |
fatal_error($task, '222','Staged folders could not be deleted.');
|
253 |
return false;
|
254 |
}
|
255 |
+
WPBackItUp_Logger::log($restore_logname,'*END DELETE STAGED FOLDER*');
|
256 |
|
257 |
+
WPBackItUp_Logger::log($restore_logname,'*UPDATE SITE VALUES META*' );
|
258 |
$siteurl = $wp_restore->get_siteurl();
|
259 |
if (false===$siteurl){
|
260 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,207);
|
299 |
$current_job->setJobMetaValue('wpbackitup_options',$wpbackitup_options);
|
300 |
}
|
301 |
|
302 |
+
WPBackItUp_Logger::log($restore_logname,'*END UPDATE SITE VALUES META*' );
|
303 |
|
304 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
305 |
+
WPBackItUp_Logger::log($restore_logname,'**END PREPARING FOR RESTORE**');
|
306 |
|
307 |
end_status($task);
|
308 |
return;
|
312 |
//Check for backup set in folder
|
313 |
if ('task_inventory_backupset'==$current_task->getTaskName()) {
|
314 |
|
315 |
+
WPBackItUp_Logger::log( $restore_logname, '*INVENTORY BACKUPSET*' );
|
316 |
|
317 |
$task = 'unpacking';
|
318 |
start_status($task);
|
329 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
330 |
|
331 |
|
332 |
+
WPBackItUp_Logger::log( $restore_logname, '*END INVENTORY BACKUPSET*' );
|
333 |
|
334 |
return;
|
335 |
|
341 |
//do this even if no backupset
|
342 |
//Unpack backup set and update job meta
|
343 |
if ('task_unpack_backupset'==$current_task->getTaskName()) {
|
344 |
+
WPBackItUp_Logger::log( $restore_logname, '*UNPACK BACKUPSET*' );
|
345 |
|
346 |
$task = 'unpacking';
|
347 |
start_status($task);
|
348 |
|
349 |
//Are there any backups to unpack from set file
|
350 |
$backupset_unpack_remaining = $current_job->getJobMetaValue('backupset_unpack_remaining');
|
351 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'Backupset Remaining Files:' . var_export( $backupset_unpack_remaining, true ) );
|
352 |
|
353 |
if (is_array($backupset_unpack_remaining) && count($backupset_unpack_remaining)>0) {
|
354 |
|
355 |
//found one so unpack it
|
356 |
$backup_file = current($backupset_unpack_remaining);
|
357 |
$backup_file_key = key($backupset_unpack_remaining);
|
358 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'Unpack backup file:' . var_export( $backup_file, true ) );
|
359 |
|
360 |
//Get backup set file
|
361 |
$backupset_file = $current_job->getJobMetaValue('backupset_file');
|
362 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'Backup Set file:' . var_export( $backupset_file, true ) );
|
363 |
|
364 |
if ($wp_restore->unpack_backup_from_backupset( $current_job, $current_task,$backupset_file,$backup_file )){
|
365 |
|
366 |
//remove this element and save to job meta
|
367 |
unset($backupset_unpack_remaining[$backup_file_key]);
|
368 |
$current_job->setJobMetaValue('backupset_unpack_remaining',$backupset_unpack_remaining);//save to job meta for next task
|
369 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'Backupset Remaining Files:' . var_export( $backupset_unpack_remaining, true ) );
|
370 |
|
371 |
//If there are more files to unpack then set task to queued and return
|
372 |
if (is_array($backupset_unpack_remaining) && count($backupset_unpack_remaining)>0) {
|
373 |
$current_task->setStatus( WPBackItUp_Job_Task::QUEUED );
|
374 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'More backup files to extract - task queued.');
|
375 |
return;
|
376 |
}
|
377 |
} else{
|
378 |
//Error occurred
|
379 |
+
WPBackItUp_Logger::log_error( $restore_logname, __METHOD__, 'Failed to unpack backup file:' . $backup_file);
|
380 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,260);
|
381 |
fatal_error($task,'260','Unable to unpack backup from backup set.');
|
382 |
return false;
|
389 |
//get the backup files contained in the backup folder
|
390 |
$backup_files = $wp_restore->get_backups_in_folder($current_job,$current_task,false);
|
391 |
if (is_array($backup_files)){
|
392 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'Backup Files Found in Backup Folder:' . var_export( $backup_files, true ) );
|
393 |
|
394 |
$current_job->setJobMetaValue('backup_set',$backup_files);
|
395 |
|
396 |
foreach ($backup_files as $key =>$backup_zip){
|
397 |
|
398 |
if (false===$current_job->getJobMetaValue( 'restore_plugins') && false !== strpos( $backup_zip, '-plugins-' )){
|
399 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skip Zip File:' .$backup_zip);
|
400 |
unset($backup_files[$key]);//remove from array
|
401 |
continue;
|
402 |
}
|
403 |
|
404 |
if (false===$current_job->getJobMetaValue( 'restore_themes') && false !== strpos( $backup_zip, '-themes-' )){
|
405 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skip Zip File:' .$backup_zip);
|
406 |
unset($backup_files[$key]);//remove from array
|
407 |
continue;
|
408 |
}
|
409 |
|
410 |
if (false===$current_job->getJobMetaValue( 'restore_uploads') && false !== strpos( $backup_zip, '-uploads-' )){
|
411 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skip Zip File:' .$backup_zip);
|
412 |
unset($backup_files[$key]);//remove from array
|
413 |
continue;
|
414 |
}
|
415 |
|
416 |
if (false===$current_job->getJobMetaValue( 'restore_others') && false !== strpos( $backup_zip, '-others-' )){
|
417 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skip Zip File:' .$backup_zip);
|
418 |
unset($backup_files[$key]);//remove from array
|
419 |
continue;
|
420 |
}
|
421 |
|
422 |
}
|
423 |
|
424 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'Backup Files queued for unzip:' . var_export( $backup_files, true ) );
|
425 |
$current_job->setJobMetaValue('backup_set_remaining',$backup_files);
|
426 |
|
427 |
}else{
|
431 |
}
|
432 |
|
433 |
$current_task->setStatus( WPBackItUp_Job_Task::COMPLETE );
|
434 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'No More backup files to extract - task completed.');
|
435 |
|
436 |
end_status($task);
|
437 |
|
438 |
+
WPBackItUp_Logger::log( $restore_logname, '*END UNPACK BACKUPSET*' );
|
439 |
return;
|
440 |
}
|
441 |
|
444 |
//- check for backupset archive FIRST
|
445 |
if ('task_unzip_backup_files'==$current_task->getTaskName()) {
|
446 |
|
447 |
+
WPBackItUp_Logger::log($restore_logname,'**UNZIP BACKUP**' );
|
448 |
$task = 'unzipping';
|
449 |
start_status($task);
|
450 |
|
451 |
//get the list of plugins zips in folder
|
452 |
$backup_set_list=$current_job->getJobMetaValue('backup_set_remaining');
|
453 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Begin - Backup set list:');
|
454 |
+
WPBackItUp_Logger::log($restore_logname,$backup_set_list);
|
455 |
|
456 |
if ( ! $wp_restore->unzip_archive_file( $backup_set_list) ) {
|
457 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,203);
|
464 |
|
465 |
if (is_array($backup_set_list) && count($backup_set_list)>0){
|
466 |
//CONTINUE
|
467 |
+
WPBackItUp_Logger::log_info($restore_logname,__METHOD__,'Continue unzipping backup set.');
|
468 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
469 |
} else{
|
470 |
//COMPLETE
|
471 |
+
WPBackItUp_Logger::log_info($restore_logname,__METHOD__,'Complete - All archives restored.');
|
472 |
end_status( $task);
|
473 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
474 |
+
WPBackItUp_Logger::log($restore_logname,'**END UNZIP BACKUP**' );
|
475 |
}
|
476 |
|
477 |
}
|
483 |
|
484 |
//Validate the backup folder against the manifest
|
485 |
if ('task_validate_backup'==$current_task->getTaskName()) {
|
486 |
+
WPBackItUp_Logger::log($restore_logname,'**VALIDATE BACKUP**' );
|
487 |
|
488 |
$task = 'validation';
|
489 |
start_status($task);
|
495 |
return false;
|
496 |
}
|
497 |
|
498 |
+
WPBackItUp_Logger::log($restore_logname,'*VALIDATE MANIFEST*' );
|
499 |
$backup_set_list=$current_job->getJobMetaValue('backup_set');
|
500 |
if ( $wp_restore->validate_manifest_file($backup_set_list,$error_code)===false){
|
501 |
|
502 |
+
WPBackItUp_Logger::log_error($restore_logname,__METHOD__,'Error Code:' .$error_code );
|
503 |
|
504 |
switch ($error_code) {
|
505 |
case 1:
|
530 |
return false;
|
531 |
|
532 |
}
|
533 |
+
WPBackItUp_Logger::log($restore_logname,'*END VALIDATE MANIFEST*' );
|
534 |
|
535 |
+
WPBackItUp_Logger::log($restore_logname,'*VALIDATE SITEDATA FILE*' );
|
536 |
//validate the site data file
|
537 |
$site_info = $wp_restore->validate_siteinfo_file();
|
538 |
|
554 |
//need to do this for old backups
|
555 |
if ( is_null( $snapshot_prefix )) {
|
556 |
//Check table prefix values FATAL
|
557 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Site table Prefix:' . $table_prefix);
|
558 |
if ( $table_prefix != $site_info['table_prefix'] ) {
|
559 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,221);
|
560 |
fatal_error($task,'221','Table prefix different from restore.');
|
566 |
if($WPBackitup->rversion_compare() === 0){
|
567 |
$site_wordpress_version = get_bloginfo('version');
|
568 |
$backup_wordpress_version = $site_info['wp_version'];
|
569 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Site Wordpress Version:' . $site_wordpress_version);
|
570 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Backup Wordpress Version:' . $backup_wordpress_version);
|
571 |
if ( ! WPBackItUp_Utility::version_compare($site_wordpress_version, $backup_wordpress_version )) {
|
572 |
+
WPBackItUp_Logger::log($restore_logname,'*VALIDATE SITEDATA FILE*' );
|
573 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,226);
|
574 |
fatal_error($task,'226','Backup was created using different version of wordpress');
|
575 |
return false;
|
578 |
|
579 |
$restore_wpbackitup_version = $site_info['wpbackitup_version'];
|
580 |
$current_wpbackitup_version = WPBACKITUP__VERSION;
|
581 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'WPBackItUp current Version:' . $current_wpbackitup_version);
|
582 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'WPBackItUp backup Version:' . $restore_wpbackitup_version);
|
583 |
if (! WPBackItUp_Utility::version_compare($restore_wpbackitup_version, $current_wpbackitup_version )){
|
584 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,227);
|
585 |
fatal_error($task,'227','Backup was created using different version of WPBackItUp');
|
586 |
return false;
|
587 |
}
|
588 |
}
|
589 |
+
WPBackItUp_Logger::log($restore_logname,'*END VALIDATE SITEDATA FILE*' );
|
590 |
|
591 |
|
592 |
//all SQL files will be added to the jon_item table during validation
|
593 |
+
WPBackItUp_Logger::log($restore_logname,'*VALIDATE SQL FILE EXISTS*' );
|
594 |
if ( ! $wp_restore->validate_SQL_add_items( )){
|
595 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,216);
|
596 |
fatal_error($task,'216','NO Database backups in backup.');
|
597 |
return false;
|
598 |
}
|
599 |
+
WPBackItUp_Logger::log($restore_logname,'*END VALIDATE SQL FILE EXISTS*' );
|
600 |
end_status($task);
|
601 |
|
602 |
+
WPBackItUp_Logger::log($restore_logname,'*DEACTIVATE ACTIVE PLUGINS*');
|
603 |
$task='deactivate_plugins';
|
604 |
start_status($task);
|
605 |
$wp_restore->deactivate_plugins();
|
606 |
end_status($task);
|
607 |
+
WPBackItUp_Logger::log($restore_logname,'*END DEACTIVATE ACTIVE PLUGINS*');
|
608 |
|
609 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
610 |
+
WPBackItUp_Logger::log($restore_logname,'**END VALIDATE BACKUP**' );
|
611 |
|
612 |
return;
|
613 |
}
|
616 |
//import the snaphsot tables v1.13+
|
617 |
if ('task_import_database'==$current_task->getTaskName()) {
|
618 |
|
619 |
+
WPBackItUp_Logger::log($restore_logname,'**IMPORT DATABASE SNAPSHOT**');
|
620 |
$task ='import_database';
|
621 |
start_status($task);
|
622 |
|
634 |
if ( ! is_null( $snapshot_prefix )) {
|
635 |
//V1.13+
|
636 |
$tables_remaining_count =$wp_restore->import_database($current_job,$snapshot_prefix);
|
637 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Database Items remaining:' .var_export($tables_remaining_count,true));
|
638 |
if (false===$tables_remaining_count) {
|
639 |
$current_task->setStatus(WPBackItUp_Job_Task::ERROR,212);
|
640 |
fatal_error($task,'212','Snapshot NOT imported.');
|
642 |
}else{
|
643 |
if ($tables_remaining_count>0){
|
644 |
//CONTINUE
|
645 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Continue importing snapshot tables.');
|
646 |
$current_task->setStatus(WPBackItUp_Job_Task::QUEUED);
|
647 |
return;
|
648 |
}
|
649 |
}
|
650 |
} else {
|
651 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Older Backup - Skipping task.');
|
652 |
}
|
653 |
}else {
|
654 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skipping task.');
|
655 |
}
|
656 |
|
657 |
//DB Restore Complete
|
658 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Complete - All snaphsot tables imported successfully.');
|
659 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
660 |
end_status($task);
|
661 |
|
662 |
+
WPBackItUp_Logger::log($restore_logname,'**END IMPORT DATABASE SNAPSHOT**');
|
663 |
return;
|
664 |
|
665 |
}
|
668 |
//Update the snapshot tables V1.13+
|
669 |
if ('task_update_snapshot'==$current_task->getTaskName()) {
|
670 |
|
671 |
+
WPBackItUp_Logger::log($restore_logname,'**UPDATE SNAPSHOT TABLES**');
|
672 |
$task ='update_database';
|
673 |
start_status($task);
|
674 |
|
690 |
return false;
|
691 |
}
|
692 |
}else {
|
693 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Older backup - skipping task.');
|
694 |
}
|
695 |
}else{
|
696 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skipping task.');
|
697 |
}
|
698 |
|
699 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
700 |
end_status($task);
|
701 |
+
WPBackItUp_Logger::log($restore_logname,'**END UPDATE SNAPSHOT TABLES**');
|
702 |
return true;
|
703 |
|
704 |
}
|
706 |
|
707 |
//Stage WP content folders
|
708 |
if ('task_stage_wpcontent'==$current_task->getTaskName()) {
|
709 |
+
WPBackItUp_Logger::log($restore_logname,'**STAGE WP-CONTENT**');
|
710 |
$task = 'stage_wpcontent';
|
711 |
|
712 |
start_status($task);
|
714 |
$folder_stage_suffix = $wp_restore->get_restore_staging_suffix();
|
715 |
|
716 |
//Stage all but plugins
|
717 |
+
WPBackItUp_Logger::log( $restore_logname, '*STAGE THEMES*' );
|
718 |
if (true===$current_job->getJobMetaValue('restore_themes')) {
|
719 |
|
720 |
$from_folder_name = $wp_restore->get_restore_root_folder_path() . '/' . WPBackItUp_Premium_Restore::THEMESPATH;
|
728 |
}
|
729 |
|
730 |
} else {
|
731 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skipping task.');
|
732 |
}
|
733 |
+
WPBackItUp_Logger::log( $restore_logname, '*END STAGE THEMES*' );
|
734 |
|
735 |
|
736 |
+
WPBackItUp_Logger::log( $restore_logname, '*STAGE UPLOADS*' );
|
737 |
if (true===$current_job->getJobMetaValue('restore_uploads')) {
|
738 |
if ( ! $wp_restore->validate_no_uploads() ) {
|
739 |
$from_folder_name = $wp_restore->get_restore_root_folder_path() . '/' . WPBackItUp_Premium_Restore::UPLOADPATH;
|
751 |
}
|
752 |
|
753 |
} else {
|
754 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skipping task.');
|
755 |
}
|
756 |
+
WPBackItUp_Logger::log( $restore_logname, '*END STAGE UPLOADS*' );
|
757 |
|
758 |
|
759 |
+
WPBackItUp_Logger::log( $restore_logname, '*STAGE OTHER FOLDERS*' );
|
760 |
if (true===$current_job->getJobMetaValue('restore_others')) {
|
761 |
|
762 |
$other_list = glob( $wp_restore->get_restore_root_folder_path() . '/' . WPBackItUp_Premium_Restore::OTHERPATH . '/*', GLOB_ONLYDIR | GLOB_NOSORT );
|
773 |
}
|
774 |
|
775 |
} else {
|
776 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skipping task.');
|
777 |
}
|
778 |
+
WPBackItUp_Logger::log( $restore_logname, '*END STAGE OTHER FOLDERS*' );
|
779 |
|
780 |
end_status( $task );
|
781 |
|
782 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);;
|
783 |
|
784 |
+
WPBackItUp_Logger::log($restore_logname,'**END STAGE WP-CONTENT**');
|
785 |
|
786 |
return;
|
787 |
}
|
790 |
//Rename the staged folders to current
|
791 |
if ('task_restore_wpcontent'==$current_task->getTaskName()) {
|
792 |
|
793 |
+
WPBackItUp_Logger::log($restore_logname,'**RESTORE WPCONTENT**');
|
794 |
$task ='restore_wpcontent';
|
795 |
start_status($task);
|
796 |
|
797 |
|
798 |
//This step will restore anything that was staged
|
799 |
+
WPBackItUp_Logger::log( $restore_logname, '*RESTORE MAIN*' );
|
800 |
$wpcontent_restore = $wp_restore->restore_wpcontent();
|
801 |
if ( ! $wpcontent_restore === true ) {
|
802 |
//array with failed list returned
|
803 |
//If any of them fail call it done.
|
804 |
warning( '300', 'Cant restore all WP content.' );
|
805 |
}
|
806 |
+
WPBackItUp_Logger::log( $restore_logname, '*END RESTORE MAIN*' );
|
807 |
|
808 |
+
WPBackItUp_Logger::log( $restore_logname, '*RESTORE PLUGINS*' );
|
809 |
if (true===$current_job->getJobMetaValue('restore_plugins')) {
|
810 |
$plugin_restore = $wp_restore->restore_plugins();
|
811 |
if ( ! $plugin_restore === true ) {
|
813 |
warning( '305', 'Couldnt restore all plugins.' );
|
814 |
}
|
815 |
} else{
|
816 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skipping task.');
|
817 |
}
|
818 |
+
WPBackItUp_Logger::log($restore_logname,'*END RESTORE PLUGINS*');
|
819 |
|
820 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);;
|
821 |
end_status($task);
|
822 |
+
WPBackItUp_Logger::log($restore_logname,'**END RESTORE WPCONTENT**');
|
823 |
|
824 |
return;
|
825 |
}
|
827 |
//restore the DB
|
828 |
if ('task_restore_database'==$current_task->getTaskName()) {
|
829 |
|
830 |
+
WPBackItUp_Logger::log($restore_logname,'**RESTORE DATABASE**');
|
831 |
$task ='restore_database';
|
832 |
start_status($task);
|
833 |
|
844 |
$rename_sql_file = $current_job->getJobMetaValue( 'rename_sql' );
|
845 |
if ( ! is_null( $rename_sql_file ) ) {
|
846 |
if ( false === $wp_restore->rename_snapshot_tables( $rename_sql_file ) ) {
|
847 |
+
WPBackItUp_Logger::log_error( $restore_logname, __METHOD__, 'Rename snaphsot table error.' );
|
848 |
|
849 |
$current_task->setStatus( WPBackItUp_Job_Task::ERROR, 212 );
|
850 |
fatal_error( $task, '240', 'Database NOT restored.' );
|
859 |
|
860 |
//Not going to use the restore Point SQL because IF the import failed then DB may be intact
|
861 |
//$tables_remaining_count =$wp_restore->restore_database($current_job);
|
862 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'Database Items remaining:' . var_export( $tables_remaining_count, true ) );
|
863 |
if ( false === $tables_remaining_count ) {
|
864 |
$current_task->setStatus( WPBackItUp_Job_Task::ERROR, 212 );
|
865 |
fatal_error( $task, '240', 'Database NOT restored.' );
|
868 |
} else {
|
869 |
if ( $tables_remaining_count > 0 ) {
|
870 |
//CONTINUE
|
871 |
+
WPBackItUp_Logger::log_info( $restore_logname, $log_function, 'Continue restoring tables.' );
|
872 |
$current_task->setStatus( WPBackItUp_Job_Task::QUEUED );
|
873 |
|
874 |
return;
|
876 |
}
|
877 |
}
|
878 |
} else {
|
879 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skipping task.');
|
880 |
}
|
881 |
|
882 |
//DB Restore Complete
|
883 |
+
//WPBackItUp_Logger::log_info($restore_logname,$log_function,'Complete - All tables restored successfully.');
|
884 |
$current_task->setStatus(WPBackItUp_Job_Task::COMPLETE);
|
885 |
end_status($task);
|
886 |
+
WPBackItUp_Logger::log($restore_logname,'**END RESTORE DATABASE**');
|
887 |
|
888 |
|
889 |
start_status('update_permalinks');
|
891 |
//Check job flag
|
892 |
if (true===$current_job->getJobMetaValue('restore_update_permalinks')) {
|
893 |
if ( ! $wp_restore->update_permalinks() ) {
|
894 |
+
WPBackItUp_Logger::log_error( $restore_logname, $log_function, 'Permalinks were not updated' );
|
895 |
//dont do anything
|
896 |
}
|
897 |
} else {
|
898 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skipping update permalinks task.');
|
899 |
}
|
900 |
|
901 |
end_status('update_permalinks');
|
910 |
//if wp-backitup-premium is not included
|
911 |
if (false === array_search('wp-backitup-premium/wp-backitup-premium.php', $active_plugins_array)){
|
912 |
$active_plugins_array[]='wp-backitup-premium/wp-backitup-premium.php'; //add to array
|
913 |
+
WPBackItUp_Logger::log_info( $restore_logname, __METHOD__, 'WPBackItUp Premium Plugin added to active plugins.');
|
914 |
}
|
915 |
|
916 |
//Update active plugin option
|
917 |
if ( false===$wp_restore->update_create_option( 'active_plugins', $active_plugins_array, 'yes' ) ) {
|
918 |
+
WPBackItUp_Logger::log_error( $restore_logname, __METHOD__, 'Unable to activate plugins:' . var_export( $active_plugins_option, true ) );
|
919 |
}
|
920 |
|
921 |
} else {
|
922 |
+
WPBackItUp_Logger::log_error( $restore_logname, __METHOD__, 'Deserialization Error - Unable to activate plugins:' . var_export( $active_plugins_option, true ) );
|
923 |
}
|
924 |
|
925 |
} else {
|
926 |
+
WPBackItUp_Logger::log_info($restore_logname,$log_function,'Skipping activate plugins.');
|
927 |
}
|
928 |
|
929 |
|
936 |
$WPBackitup->increment_successful_restore_count();
|
937 |
$current_job->setStatus(WPBackItUp_Job::COMPLETE);
|
938 |
set_status_success();
|
939 |
+
WPBackItUp_Logger::log($restore_logname,'Restore completed successfully');
|
940 |
+
WPBackItUp_Logger::log($restore_logname,'***END RESTORE***');
|
941 |
|
942 |
end_restore(null,true);
|
943 |
return true;
|
953 |
function fatal_error($process,$error_code,$error_message, $end=true){
|
954 |
global $current_job, $failure, $restore_logname;
|
955 |
|
956 |
+
WPBackItUp_Logger::log_error($restore_logname,__METHOD__,$error_message);
|
957 |
$current_job->setStatus(WPBackItUp_Job::ERROR);
|
958 |
|
959 |
write_response_file_error($error_code,$error_message);
|
969 |
function warning($error_code,$warning_message) {
|
970 |
global $restore_logname, $status_array,$warning;
|
971 |
|
972 |
+
WPBackItUp_Logger::log_warning($restore_logname,__METHOD__, $warning_message);
|
973 |
|
974 |
//Add warning to array
|
975 |
$status_array['warning' .$error_code]=$warning;
|
1021 |
global $restore_logname;
|
1022 |
|
1023 |
$json_response = json_encode($JSON_Response);
|
1024 |
+
WPBackItUp_Logger::log($restore_logname,'Write response file:' . $json_response);
|
1025 |
|
1026 |
$fh=get_response_file();
|
1027 |
fwrite($fh, $json_response);
|
1113 |
function end_restore($err=null, $success=null){
|
1114 |
global $current_job, $restore_logname;
|
1115 |
|
1116 |
+
if (true===$success) WPBackItUp_Logger::log_info($restore_logname,__METHOD__,'Restore completed: SUCCESS');
|
1117 |
+
if (false===$success) WPBackItUp_Logger::log_error($restore_logname,__METHOD__,'Restore completed: ERROR');
|
1118 |
|
1119 |
//copy/replace WP debug file
|
1120 |
$logs_path = WPBACKITUP__PLUGIN_PATH .'logs';
|
1121 |
$wpdebug_file_path = WPBACKITUP__CONTENT_PATH . '/debug.log';
|
1122 |
+
WPBackItUp_Logger::log_info($restore_logname,__METHOD__,'Copy WP Debug: ' .$wpdebug_file_path);
|
1123 |
if (file_exists($wpdebug_file_path)) {
|
1124 |
$debug_log = sprintf('%s/wpdebug_%s.log',$logs_path,$current_job->getJobId());
|
1125 |
copy( $wpdebug_file_path, $debug_log );
|
1126 |
}
|
1127 |
|
1128 |
+
WPBackItUp_Logger::log($restore_logname,'*** END RESTORE ***');
|
1129 |
|
1130 |
|
1131 |
//Close the logger
|
1132 |
+
WPBackItUp_Logger::close($restore_logname);
|
1133 |
$current_job->release_lock();
|
1134 |
|
1135 |
//response back the status file since this method will end processing
|
lib/includes/update_database.php
CHANGED
@@ -34,20 +34,20 @@ function wpbackitup_update_database() {
|
|
34 |
// this is the target version that we need to reach
|
35 |
$target_db_ver = WPBackitup_Admin::DB_VERSION;
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
//If current version = 0 then this is an install so just create the custom tables
|
42 |
if ($current_db_ver==0){
|
43 |
-
|
44 |
|
45 |
wpbackitup_create_custom_tables($log_name);
|
46 |
|
47 |
wpbackitup_scan_import_backups($log_name);
|
48 |
|
49 |
update_option( 'wp-backitup_db_version', $target_db_ver );
|
50 |
-
|
51 |
|
52 |
return;
|
53 |
}
|
@@ -59,23 +59,23 @@ function wpbackitup_update_database() {
|
|
59 |
|
60 |
// increment the current db_ver by one
|
61 |
$current_db_ver ++;
|
62 |
-
|
63 |
|
64 |
// each db version will require a separate update function
|
65 |
// for example, for db_ver 3, the function name should be solis_update_routine_3
|
66 |
$func = "wpbackitup_update_database_routine_{$current_db_ver}";
|
67 |
if ( function_exists( $func ) ) {
|
68 |
-
|
69 |
call_user_func( $func ,$log_name);
|
70 |
-
|
71 |
} else{
|
72 |
-
|
73 |
}
|
74 |
|
75 |
// update the option in the database, so that this process can always
|
76 |
// pick up where it left off
|
77 |
update_option( 'wp-backitup_db_version', $current_db_ver );
|
78 |
-
|
79 |
}
|
80 |
|
81 |
}
|
@@ -88,7 +88,7 @@ function wpbackitup_update_database() {
|
|
88 |
*
|
89 |
*/
|
90 |
//function wpbackitup_update_database_routine_1($log_name){
|
91 |
-
//
|
92 |
// global $wpdb;
|
93 |
//
|
94 |
// $charset_collate = 'DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci'; //default value
|
@@ -115,7 +115,7 @@ function wpbackitup_update_database() {
|
|
115 |
//
|
116 |
// require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
117 |
// dbDelta( $sql );
|
118 |
-
//
|
119 |
//}
|
120 |
|
121 |
/**
|
@@ -178,7 +178,7 @@ function wpbackitup_update_database() {
|
|
178 |
*
|
179 |
*/
|
180 |
function wpbackitup_update_database_routine_3($log_name) {
|
181 |
-
|
182 |
|
183 |
|
184 |
//Drop & Create the custom job tables
|
@@ -187,7 +187,7 @@ function wpbackitup_update_database_routine_3($log_name) {
|
|
187 |
//scan the host for backups - import them into job tables
|
188 |
wpbackitup_scan_import_backups($log_name);
|
189 |
|
190 |
-
|
191 |
}
|
192 |
|
193 |
/**
|
@@ -196,7 +196,7 @@ function wpbackitup_update_database_routine_3($log_name) {
|
|
196 |
*
|
197 |
*/
|
198 |
function wpbackitup_update_database_routine_4($log_name) {
|
199 |
-
|
200 |
global $wpdb;
|
201 |
|
202 |
$job_control_table = $wpdb->prefix . "wpbackitup_job_control";
|
@@ -204,20 +204,20 @@ function wpbackitup_update_database_routine_4($log_name) {
|
|
204 |
$sql = "ALTER TABLE $job_control_table
|
205 |
CHANGE COLUMN job_name job_name VARCHAR(100)
|
206 |
";
|
207 |
-
|
208 |
|
209 |
$wpdb_result = $wpdb->query($sql);
|
210 |
$last_error = $wpdb->last_error;
|
211 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
212 |
-
|
213 |
}else{
|
214 |
-
|
215 |
}
|
216 |
|
217 |
//scan the host for backups - import them into job tables
|
218 |
wpbackitup_scan_import_backups($log_name); //needed because update 3 might have failed
|
219 |
|
220 |
-
|
221 |
}
|
222 |
|
223 |
|
@@ -241,56 +241,56 @@ function wpbackitup_create_custom_tables($log_name){
|
|
241 |
$job_tasks_table = $wpdb->prefix . "wpbackitup_job_tasks";
|
242 |
$job_items_table = $wpdb->prefix . "wpbackitup_job_items";
|
243 |
|
244 |
-
|
245 |
|
246 |
//drop the original job table
|
247 |
$sql = "DROP TABLE IF EXISTS $old_job_table;";
|
248 |
-
|
249 |
$wpdb_result = $wpdb->query($sql);
|
250 |
$last_error = $wpdb->last_error;
|
251 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
252 |
-
|
253 |
}else{
|
254 |
-
|
255 |
}
|
256 |
|
257 |
|
258 |
//drop the existing job table
|
259 |
$sql = "DROP TABLE IF EXISTS $job_control_table;";
|
260 |
-
|
261 |
$wpdb_result = $wpdb->query($sql);
|
262 |
$last_error = $wpdb->last_error;
|
263 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
264 |
-
|
265 |
}else{
|
266 |
-
|
267 |
}
|
268 |
|
269 |
//drop the existing Task table
|
270 |
$sql = "DROP TABLE IF EXISTS $job_tasks_table;";
|
271 |
-
|
272 |
$wpdb_result = $wpdb->query($sql);
|
273 |
$last_error = $wpdb->last_error;
|
274 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
275 |
-
|
276 |
}else{
|
277 |
-
|
278 |
}
|
279 |
|
280 |
//drop the existing item table
|
281 |
$sql = "DROP TABLE IF EXISTS $job_items_table;";
|
282 |
-
|
283 |
$wpdb_result = $wpdb->query($sql);
|
284 |
$last_error = $wpdb->last_error;
|
285 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
286 |
-
|
287 |
}else{
|
288 |
-
|
289 |
}
|
290 |
|
291 |
-
|
292 |
|
293 |
-
|
294 |
|
295 |
$sql = "CREATE TABLE $job_control_table (
|
296 |
job_id bigint(20) NOT NULL,
|
@@ -306,7 +306,7 @@ function wpbackitup_create_custom_tables($log_name){
|
|
306 |
PRIMARY KEY (job_id)
|
307 |
) $charset_collate;";
|
308 |
dbDelta( $sql );
|
309 |
-
|
310 |
|
311 |
$sql = "CREATE TABLE $job_tasks_table (
|
312 |
task_id bigint(20) NOT NULL AUTO_INCREMENT,
|
@@ -324,7 +324,7 @@ function wpbackitup_create_custom_tables($log_name){
|
|
324 |
PRIMARY KEY (task_id)
|
325 |
) $charset_collate;";
|
326 |
dbDelta( $sql );
|
327 |
-
|
328 |
|
329 |
$sql = "CREATE TABLE $job_items_table (
|
330 |
item_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
@@ -342,9 +342,9 @@ function wpbackitup_create_custom_tables($log_name){
|
|
342 |
PRIMARY KEY (item_id)
|
343 |
) $charset_collate;";
|
344 |
dbDelta( $sql );
|
345 |
-
|
346 |
|
347 |
-
|
348 |
}
|
349 |
|
350 |
/**
|
@@ -354,16 +354,16 @@ function wpbackitup_create_custom_tables($log_name){
|
|
354 |
*/
|
355 |
function wpbackitup_scan_import_backups($log_name){
|
356 |
//Import the backups into the custom tables
|
357 |
-
|
358 |
|
359 |
//get all the folders in the backup path
|
360 |
$backup_folder_root = WPBACKITUP__BACKUP_PATH;
|
361 |
$backup_folders = glob($backup_folder_root. '/*', GLOB_ONLYDIR);
|
362 |
-
|
363 |
|
364 |
//if not TMP and DLT add to job table
|
365 |
foreach($backup_folders as $folder) {
|
366 |
-
|
367 |
|
368 |
$folder_name= basename($folder);
|
369 |
$folder_prefix = substr($folder_name,0,4);
|
@@ -384,7 +384,7 @@ function wpbackitup_scan_import_backups($log_name){
|
|
384 |
|
385 |
//If no zip files found then skip this folder
|
386 |
if (! is_array($zip_files) || count($zip_files)<=0){
|
387 |
-
|
388 |
continue;
|
389 |
}
|
390 |
|
@@ -397,20 +397,20 @@ function wpbackitup_scan_import_backups($log_name){
|
|
397 |
if ($pos!==false) unset($zip_files[$key]);;
|
398 |
}
|
399 |
|
400 |
-
|
401 |
|
402 |
//update post meta
|
403 |
$job->setJobMetaValue('backup_zip_files' , $zip_files ); //list of zip files
|
404 |
-
|
405 |
}
|
406 |
}else {
|
407 |
-
|
408 |
}
|
409 |
} else{
|
410 |
-
|
411 |
}
|
412 |
}
|
413 |
|
414 |
-
|
415 |
|
416 |
}
|
34 |
// this is the target version that we need to reach
|
35 |
$target_db_ver = WPBackitup_Admin::DB_VERSION;
|
36 |
|
37 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Running database upgrade routines.');
|
38 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Current DB version:'.$current_db_ver );
|
39 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Target DB version:'.$target_db_ver );
|
40 |
|
41 |
//If current version = 0 then this is an install so just create the custom tables
|
42 |
if ($current_db_ver==0){
|
43 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'New Install.');
|
44 |
|
45 |
wpbackitup_create_custom_tables($log_name);
|
46 |
|
47 |
wpbackitup_scan_import_backups($log_name);
|
48 |
|
49 |
update_option( 'wp-backitup_db_version', $target_db_ver );
|
50 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Updated Db version in settings:'. $target_db_ver );
|
51 |
|
52 |
return;
|
53 |
}
|
59 |
|
60 |
// increment the current db_ver by one
|
61 |
$current_db_ver ++;
|
62 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, sprintf('Upgrading database to version %s',$current_db_ver) );
|
63 |
|
64 |
// each db version will require a separate update function
|
65 |
// for example, for db_ver 3, the function name should be solis_update_routine_3
|
66 |
$func = "wpbackitup_update_database_routine_{$current_db_ver}";
|
67 |
if ( function_exists( $func ) ) {
|
68 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Running update routine:' .$func);
|
69 |
call_user_func( $func ,$log_name);
|
70 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Update Routine complete:' .$func);
|
71 |
} else{
|
72 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'No updates for this version.');
|
73 |
}
|
74 |
|
75 |
// update the option in the database, so that this process can always
|
76 |
// pick up where it left off
|
77 |
update_option( 'wp-backitup_db_version', $current_db_ver );
|
78 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Updated Db version in settings:'. $current_db_ver );
|
79 |
}
|
80 |
|
81 |
}
|
88 |
*
|
89 |
*/
|
90 |
//function wpbackitup_update_database_routine_1($log_name){
|
91 |
+
// WPBackItUp_Logger::log_info($log_name,__METHOD__,'Begin upgrade database to V1');
|
92 |
// global $wpdb;
|
93 |
//
|
94 |
// $charset_collate = 'DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci'; //default value
|
115 |
//
|
116 |
// require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
117 |
// dbDelta( $sql );
|
118 |
+
// WPBackItUp_Logger::log_info($log_name,__METHOD__,'Begin upgrade database to V1');
|
119 |
//}
|
120 |
|
121 |
/**
|
178 |
*
|
179 |
*/
|
180 |
function wpbackitup_update_database_routine_3($log_name) {
|
181 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Begin upgrade database to V3');
|
182 |
|
183 |
|
184 |
//Drop & Create the custom job tables
|
187 |
//scan the host for backups - import them into job tables
|
188 |
wpbackitup_scan_import_backups($log_name);
|
189 |
|
190 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'End upgrade database to V3');
|
191 |
}
|
192 |
|
193 |
/**
|
196 |
*
|
197 |
*/
|
198 |
function wpbackitup_update_database_routine_4($log_name) {
|
199 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Begin upgrade database to V4' );
|
200 |
global $wpdb;
|
201 |
|
202 |
$job_control_table = $wpdb->prefix . "wpbackitup_job_control";
|
204 |
$sql = "ALTER TABLE $job_control_table
|
205 |
CHANGE COLUMN job_name job_name VARCHAR(100)
|
206 |
";
|
207 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'UPDATE SQL:'. $sql);
|
208 |
|
209 |
$wpdb_result = $wpdb->query($sql);
|
210 |
$last_error = $wpdb->last_error;
|
211 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
212 |
+
WPBackItUp_Logger::log_error($log_name,__METHOD__,'Last Error:' .var_export( $last_error,true ) );
|
213 |
}else{
|
214 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Job Name column updated successfully');
|
215 |
}
|
216 |
|
217 |
//scan the host for backups - import them into job tables
|
218 |
wpbackitup_scan_import_backups($log_name); //needed because update 3 might have failed
|
219 |
|
220 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'END upgrade database to V4');
|
221 |
}
|
222 |
|
223 |
|
241 |
$job_tasks_table = $wpdb->prefix . "wpbackitup_job_tasks";
|
242 |
$job_items_table = $wpdb->prefix . "wpbackitup_job_items";
|
243 |
|
244 |
+
WPBackItUp_Logger::log($log_name,'*** DROP JOB TABLES ***');
|
245 |
|
246 |
//drop the original job table
|
247 |
$sql = "DROP TABLE IF EXISTS $old_job_table;";
|
248 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Drop OLD Job Table:' .$sql);
|
249 |
$wpdb_result = $wpdb->query($sql);
|
250 |
$last_error = $wpdb->last_error;
|
251 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
252 |
+
WPBackItUp_Logger::log_error($log_name,__METHOD__,'Last Error:' .var_export( $last_error,true ) );
|
253 |
}else{
|
254 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'OLD Job Table Dropped successfully');
|
255 |
}
|
256 |
|
257 |
|
258 |
//drop the existing job table
|
259 |
$sql = "DROP TABLE IF EXISTS $job_control_table;";
|
260 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Drop Job Table:' .$sql);
|
261 |
$wpdb_result = $wpdb->query($sql);
|
262 |
$last_error = $wpdb->last_error;
|
263 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
264 |
+
WPBackItUp_Logger::log_error($log_name,__METHOD__,'Last Error:' .var_export( $last_error,true ) );
|
265 |
}else{
|
266 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Job Table Dropped successfully');
|
267 |
}
|
268 |
|
269 |
//drop the existing Task table
|
270 |
$sql = "DROP TABLE IF EXISTS $job_tasks_table;";
|
271 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Drop Task Table:' .$sql);
|
272 |
$wpdb_result = $wpdb->query($sql);
|
273 |
$last_error = $wpdb->last_error;
|
274 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
275 |
+
WPBackItUp_Logger::log_error($log_name,__METHOD__,'Last Error:' .var_export( $last_error,true ) );
|
276 |
}else{
|
277 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Task Table Dropped successfully');
|
278 |
}
|
279 |
|
280 |
//drop the existing item table
|
281 |
$sql = "DROP TABLE IF EXISTS $job_items_table;";
|
282 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Drop Job Table:' .$sql);
|
283 |
$wpdb_result = $wpdb->query($sql);
|
284 |
$last_error = $wpdb->last_error;
|
285 |
if ($wpdb_result === FALSE && !empty($last_error)) {
|
286 |
+
WPBackItUp_Logger::log_error($log_name,__METHOD__,'Last Error:' .var_export( $last_error,true ) );
|
287 |
}else{
|
288 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Item Table Dropped successfully');
|
289 |
}
|
290 |
|
291 |
+
WPBackItUp_Logger::log($log_name,'*** END DROP JOB TABLES ***');
|
292 |
|
293 |
+
WPBackItUp_Logger::log($log_name,'*** CREATE JOB TABLES ***');
|
294 |
|
295 |
$sql = "CREATE TABLE $job_control_table (
|
296 |
job_id bigint(20) NOT NULL,
|
306 |
PRIMARY KEY (job_id)
|
307 |
) $charset_collate;";
|
308 |
dbDelta( $sql );
|
309 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Table Created:'. $job_control_table);
|
310 |
|
311 |
$sql = "CREATE TABLE $job_tasks_table (
|
312 |
task_id bigint(20) NOT NULL AUTO_INCREMENT,
|
324 |
PRIMARY KEY (task_id)
|
325 |
) $charset_collate;";
|
326 |
dbDelta( $sql );
|
327 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Table Created:'. $job_tasks_table);
|
328 |
|
329 |
$sql = "CREATE TABLE $job_items_table (
|
330 |
item_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
342 |
PRIMARY KEY (item_id)
|
343 |
) $charset_collate;";
|
344 |
dbDelta( $sql );
|
345 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Table Created:'. $job_items_table);
|
346 |
|
347 |
+
WPBackItUp_Logger::log($log_name,'*** END CREATE JOB TABLES ***');
|
348 |
}
|
349 |
|
350 |
/**
|
354 |
*/
|
355 |
function wpbackitup_scan_import_backups($log_name){
|
356 |
//Import the backups into the custom tables
|
357 |
+
WPBackItUp_Logger::log($log_name,'***SCAN & IMPORT BACKUPS ***');
|
358 |
|
359 |
//get all the folders in the backup path
|
360 |
$backup_folder_root = WPBACKITUP__BACKUP_PATH;
|
361 |
$backup_folders = glob($backup_folder_root. '/*', GLOB_ONLYDIR);
|
362 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Backup Sets Found:' .var_export($backup_folders,true));
|
363 |
|
364 |
//if not TMP and DLT add to job table
|
365 |
foreach($backup_folders as $folder) {
|
366 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Importing:' .$folder);
|
367 |
|
368 |
$folder_name= basename($folder);
|
369 |
$folder_prefix = substr($folder_name,0,4);
|
384 |
|
385 |
//If no zip files found then skip this folder
|
386 |
if (! is_array($zip_files) || count($zip_files)<=0){
|
387 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'No backups found in folder:' .$folder);
|
388 |
continue;
|
389 |
}
|
390 |
|
397 |
if ($pos!==false) unset($zip_files[$key]);;
|
398 |
}
|
399 |
|
400 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Update Job Meta:' .var_export($zip_files,true));
|
401 |
|
402 |
//update post meta
|
403 |
$job->setJobMetaValue('backup_zip_files' , $zip_files ); //list of zip files
|
404 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Job Imported:' .$folder_name);
|
405 |
}
|
406 |
}else {
|
407 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Job already exists, not imported:' .$folder_name);
|
408 |
}
|
409 |
} else{
|
410 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__,'Backup was not imported:' .$folder);
|
411 |
}
|
412 |
}
|
413 |
|
414 |
+
WPBackItUp_Logger::log($log_name,'***END SCAN & IMPORT BACKUPS ***');
|
415 |
|
416 |
}
|
lib/includes/update_plugin.php
CHANGED
@@ -29,13 +29,13 @@ function wpbackitup_update_plugin() {
|
|
29 |
$target_plugin_major_ver = WPBACKITUP__MAJOR_VERSION;
|
30 |
$target_plugin_minor_ver = WPBACKITUP__MINOR_VERSION;
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
//If current version = 0 then this is an install
|
37 |
if ($current_plugin_major_ver==0){
|
38 |
-
|
39 |
|
40 |
update_option( 'wp-backitup_major_version', $target_plugin_major_ver );
|
41 |
update_option( 'wp-backitup_minor_version', $target_plugin_minor_ver );
|
@@ -49,19 +49,19 @@ function wpbackitup_update_plugin() {
|
|
49 |
while ( $current_plugin_minor_ver < $target_plugin_minor_ver ) {
|
50 |
|
51 |
$current_plugin_minor_ver ++;
|
52 |
-
|
53 |
|
54 |
$func = "wpbackitup_update_plugin_minor_routine_{$current_plugin_major_ver}_{$current_plugin_minor_ver}";
|
55 |
if ( function_exists( $func ) ) {
|
56 |
-
|
57 |
call_user_func( $func,$log_name );
|
58 |
-
|
59 |
} else{
|
60 |
-
|
61 |
}
|
62 |
|
63 |
update_option( 'wp-backitup_minor_version', $current_plugin_minor_ver );
|
64 |
-
|
65 |
}
|
66 |
return;
|
67 |
}
|
@@ -78,41 +78,41 @@ function wpbackitup_update_plugin() {
|
|
78 |
// increment the current db_ver by one
|
79 |
$current_plugin_major_ver ++;
|
80 |
|
81 |
-
|
82 |
|
83 |
// each version will require a separate update function
|
84 |
// for example, for ver 3, the function name should be solis_update_routine_3
|
85 |
$func = "wpbackitup_update_plugin_major_routine_{$current_plugin_major_ver}";
|
86 |
if ( function_exists( $func ) ) {
|
87 |
-
|
88 |
call_user_func( $func,$log_name );
|
89 |
-
|
90 |
} else{
|
91 |
-
|
92 |
}
|
93 |
|
94 |
// update the option in the database, so that this process can always
|
95 |
// pick up where it left off
|
96 |
update_option( 'wp-backitup_major_version', $current_plugin_major_ver );
|
97 |
-
|
98 |
|
99 |
-
|
100 |
|
101 |
//Check for up to 50 minor releases in this version
|
102 |
for ( $i = 1; $i <= 50; $i ++ ) {
|
103 |
$func = "wpbackitup_update_plugin_minor_routine_{$current_plugin_major_ver}_{$i}";
|
104 |
if ( function_exists( $func ) ) {
|
105 |
-
|
106 |
call_user_func( $func );
|
107 |
-
|
108 |
} else{
|
109 |
-
|
110 |
}
|
111 |
|
112 |
}
|
113 |
|
114 |
update_option( 'wp-backitup_minor_version', $target_plugin_minor_ver );
|
115 |
-
|
116 |
|
117 |
}
|
118 |
}
|
@@ -125,7 +125,7 @@ function wpbackitup_update_plugin() {
|
|
125 |
*/
|
126 |
function wpbackitup_update_plugin_major_routine_1($log_name){
|
127 |
// dont think this will ever run
|
128 |
-
|
129 |
|
130 |
//Need to reset the batch size for this release
|
131 |
$batch_size = get_option('wp-backitup_backup_batch_size');
|
@@ -146,7 +146,7 @@ function wpbackitup_update_plugin_major_routine_1($log_name){
|
|
146 |
delete_option('wp-backitup_lite_registration_email');
|
147 |
}
|
148 |
|
149 |
-
|
150 |
}
|
151 |
|
152 |
/*----------------------------------------------*/
|
@@ -158,16 +158,16 @@ function wpbackitup_update_plugin_major_routine_1($log_name){
|
|
158 |
* Minor Version update 1.12
|
159 |
*/
|
160 |
function wpbackitup_update_plugin_minor_routine_1_12($log_name){
|
161 |
-
|
162 |
|
163 |
//Update the db tables batch size - changes usage in this version
|
164 |
$settings_tables_batch_size = get_option('wp-backitup_backup_dbtables_batch_size');
|
165 |
if ($settings_tables_batch_size<10000){
|
166 |
delete_option('wp-backitup_backup_dbtables_batch_size');
|
167 |
-
|
168 |
}
|
169 |
|
170 |
-
|
171 |
}
|
172 |
|
173 |
|
29 |
$target_plugin_major_ver = WPBACKITUP__MAJOR_VERSION;
|
30 |
$target_plugin_minor_ver = WPBACKITUP__MINOR_VERSION;
|
31 |
|
32 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Current Plugin Major Version:' . $current_plugin_major_ver );
|
33 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Current Plugin Minor Version:' . $current_plugin_minor_ver );
|
34 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Target Plugin Minor Version:' . $target_plugin_minor_ver );
|
35 |
|
36 |
//If current version = 0 then this is an install
|
37 |
if ($current_plugin_major_ver==0){
|
38 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'New Install.');
|
39 |
|
40 |
update_option( 'wp-backitup_major_version', $target_plugin_major_ver );
|
41 |
update_option( 'wp-backitup_minor_version', $target_plugin_minor_ver );
|
49 |
while ( $current_plugin_minor_ver < $target_plugin_minor_ver ) {
|
50 |
|
51 |
$current_plugin_minor_ver ++;
|
52 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, sprintf('Upgrading plugin to MINOR version %s',$current_plugin_minor_ver) );
|
53 |
|
54 |
$func = "wpbackitup_update_plugin_minor_routine_{$current_plugin_major_ver}_{$current_plugin_minor_ver}";
|
55 |
if ( function_exists( $func ) ) {
|
56 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Running update routine:' . $func );
|
57 |
call_user_func( $func,$log_name );
|
58 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Update Routine complete:' . $func );
|
59 |
} else{
|
60 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'No updates for this version.');
|
61 |
}
|
62 |
|
63 |
update_option( 'wp-backitup_minor_version', $current_plugin_minor_ver );
|
64 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Updated plugin MINOR version in settings:'. $current_plugin_minor_ver );
|
65 |
}
|
66 |
return;
|
67 |
}
|
78 |
// increment the current db_ver by one
|
79 |
$current_plugin_major_ver ++;
|
80 |
|
81 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, sprintf('Upgrading plugin to MAJOR version %s',$current_plugin_major_ver) );
|
82 |
|
83 |
// each version will require a separate update function
|
84 |
// for example, for ver 3, the function name should be solis_update_routine_3
|
85 |
$func = "wpbackitup_update_plugin_major_routine_{$current_plugin_major_ver}";
|
86 |
if ( function_exists( $func ) ) {
|
87 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Running update routine:' . $func );
|
88 |
call_user_func( $func,$log_name );
|
89 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Update Routine complete:' . $func );
|
90 |
} else{
|
91 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'No updates for this version.');
|
92 |
}
|
93 |
|
94 |
// update the option in the database, so that this process can always
|
95 |
// pick up where it left off
|
96 |
update_option( 'wp-backitup_major_version', $current_plugin_major_ver );
|
97 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Updated plugin MAJOR version in settings:'. $current_plugin_major_ver );
|
98 |
|
99 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Check for MINOR version upgrades');
|
100 |
|
101 |
//Check for up to 50 minor releases in this version
|
102 |
for ( $i = 1; $i <= 50; $i ++ ) {
|
103 |
$func = "wpbackitup_update_plugin_minor_routine_{$current_plugin_major_ver}_{$i}";
|
104 |
if ( function_exists( $func ) ) {
|
105 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Running update routine:' . $func );
|
106 |
call_user_func( $func );
|
107 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Update Routine complete:' . $func );
|
108 |
} else{
|
109 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'No updates for this version:' .$i);
|
110 |
}
|
111 |
|
112 |
}
|
113 |
|
114 |
update_option( 'wp-backitup_minor_version', $target_plugin_minor_ver );
|
115 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Updated plugin MINOR version in settings:'. $target_plugin_minor_ver );
|
116 |
|
117 |
}
|
118 |
}
|
125 |
*/
|
126 |
function wpbackitup_update_plugin_major_routine_1($log_name){
|
127 |
// dont think this will ever run
|
128 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Begin upgrade plugin to V1' );
|
129 |
|
130 |
//Need to reset the batch size for this release
|
131 |
$batch_size = get_option('wp-backitup_backup_batch_size');
|
146 |
delete_option('wp-backitup_lite_registration_email');
|
147 |
}
|
148 |
|
149 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'End upgrade plugin to V1' );
|
150 |
}
|
151 |
|
152 |
/*----------------------------------------------*/
|
158 |
* Minor Version update 1.12
|
159 |
*/
|
160 |
function wpbackitup_update_plugin_minor_routine_1_12($log_name){
|
161 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'Begin upgrade plugin to V1.12' );
|
162 |
|
163 |
//Update the db tables batch size - changes usage in this version
|
164 |
$settings_tables_batch_size = get_option('wp-backitup_backup_dbtables_batch_size');
|
165 |
if ($settings_tables_batch_size<10000){
|
166 |
delete_option('wp-backitup_backup_dbtables_batch_size');
|
167 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'dbtables_batch_size removed');
|
168 |
}
|
169 |
|
170 |
+
WPBackItUp_Logger::log_info($log_name,__METHOD__, 'End upgrade plugin to V1.12' );
|
171 |
}
|
172 |
|
173 |
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.wpbackitup.com
|
|
4 |
Tags: backup, backups, restore, migrate, clone, duplicate, multisite, database, archive, malware, download, mysql
|
5 |
Requires at least: 3.8.0
|
6 |
Tested up to: 4.7.2
|
7 |
-
Stable tag: 1.14.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -195,10 +195,17 @@ Our online documentation and full list of FAQs can be found at [support.wpbackit
|
|
195 |
|
196 |
|
197 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
= 1.14.2 =
|
199 |
*Release Date - March 7, 2017
|
200 |
|
201 |
-
* FIX:
|
202 |
|
203 |
= 1.14.1 =
|
204 |
*Release Date - February 16, 2017
|
4 |
Tags: backup, backups, restore, migrate, clone, duplicate, multisite, database, archive, malware, download, mysql
|
5 |
Requires at least: 3.8.0
|
6 |
Tested up to: 4.7.2
|
7 |
+
Stable tag: 1.14.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
195 |
|
196 |
|
197 |
== Changelog ==
|
198 |
+
= 1.14.3 =
|
199 |
+
*Release Date - March 16,2017
|
200 |
+
|
201 |
+
* UPDATE: Added new admin notice class
|
202 |
+
* UPDATE: Added new logging class
|
203 |
+
* UPDATE: WPBDEV-134 Add support for extremely large databases(500+ SQL files)
|
204 |
+
|
205 |
= 1.14.2 =
|
206 |
*Release Date - March 7, 2017
|
207 |
|
208 |
+
* FIX: Correct issue with undefined index on admin notices
|
209 |
|
210 |
= 1.14.1 =
|
211 |
*Release Date - February 16, 2017
|
vendor/KLogger/LogLevel.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Describes log levels
|
5 |
+
*/
|
6 |
+
class LogLevel
|
7 |
+
{
|
8 |
+
const EMERGENCY = 'emergency';
|
9 |
+
const ALERT = 'alert';
|
10 |
+
const CRITICAL = 'critical';
|
11 |
+
const ERROR = 'error';
|
12 |
+
const WARNING = 'warning';
|
13 |
+
const NOTICE = 'notice';
|
14 |
+
const INFO = 'info';
|
15 |
+
const DEBUG = 'debug';
|
16 |
+
}
|
vendor/KLogger/Logger.php
ADDED
@@ -0,0 +1,463 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!class_exists('LogLevel')) {
|
4 |
+
require_once('LogLevel.php');
|
5 |
+
}
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Finally, a light, permissions-checking logging class.
|
9 |
+
*
|
10 |
+
* Originally written for use with wpSearch
|
11 |
+
*
|
12 |
+
* Usage:
|
13 |
+
* $log = new Katzgrau\KLogger\Logger('/var/log/', Psr\Log\LogLevel::INFO);
|
14 |
+
* $log->info('Returned a million search results'); //Prints to the log file
|
15 |
+
* $log->error('Oh dear.'); //Prints to the log file
|
16 |
+
* $log->debug('x = 5'); //Prints nothing due to current severity threshhold
|
17 |
+
*
|
18 |
+
* @author Kenny Katzgrau <katzgrau@gmail.com>
|
19 |
+
* @since July 26, 2008
|
20 |
+
* @link https://github.com/katzgrau/KLogger
|
21 |
+
* @version 1.0.0
|
22 |
+
*/
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Class documentation
|
26 |
+
*/
|
27 |
+
class Logger
|
28 |
+
{
|
29 |
+
/**
|
30 |
+
* KLogger options
|
31 |
+
* Anything options not considered 'core' to the logging library should be
|
32 |
+
* settable view the third parameter in the constructor
|
33 |
+
*
|
34 |
+
* Core options include the log file path and the log threshold
|
35 |
+
*
|
36 |
+
* @var array
|
37 |
+
*/
|
38 |
+
protected $options = array(
|
39 |
+
'extension' => 'txt',
|
40 |
+
'dateFormat' => 'Y-m-d G:i:s.u',
|
41 |
+
'filename' => false,
|
42 |
+
'flushFrequency' => false,
|
43 |
+
'prefix' => 'log_',
|
44 |
+
'logFormat' => false,
|
45 |
+
'appendContext' => true,
|
46 |
+
);
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Path to the log file
|
50 |
+
* @var string
|
51 |
+
*/
|
52 |
+
private $logFilePath;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Log file name
|
56 |
+
* @var string
|
57 |
+
*/
|
58 |
+
private $logFileName;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Current minimum logging threshold
|
62 |
+
* @var integer
|
63 |
+
*/
|
64 |
+
protected $logLevelThreshold = LogLevel::DEBUG;
|
65 |
+
|
66 |
+
/**
|
67 |
+
* The number of lines logged in this instance's lifetime
|
68 |
+
* @var int
|
69 |
+
*/
|
70 |
+
private $logLineCount = 0;
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Log Levels
|
74 |
+
* @var array
|
75 |
+
*/
|
76 |
+
protected $logLevels = array(
|
77 |
+
LogLevel::EMERGENCY => 0,
|
78 |
+
LogLevel::ALERT => 1,
|
79 |
+
LogLevel::CRITICAL => 2,
|
80 |
+
LogLevel::ERROR => 3,
|
81 |
+
LogLevel::WARNING => 4,
|
82 |
+
LogLevel::NOTICE => 5,
|
83 |
+
LogLevel::INFO => 6,
|
84 |
+
LogLevel::DEBUG => 7
|
85 |
+
);
|
86 |
+
|
87 |
+
/**
|
88 |
+
* This holds the file handle for this instance's log file
|
89 |
+
* @var resource
|
90 |
+
*/
|
91 |
+
private $fileHandle;
|
92 |
+
|
93 |
+
/**
|
94 |
+
* This holds the last line logged to the logger
|
95 |
+
* Used for unit tests
|
96 |
+
* @var string
|
97 |
+
*/
|
98 |
+
private $lastLine = '';
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Octal notation for default permissions of the log file
|
102 |
+
* @var integer
|
103 |
+
*/
|
104 |
+
private $defaultPermissions = 0777;
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Class constructor
|
108 |
+
*
|
109 |
+
* @param string $logDirectory File path to the logging directory
|
110 |
+
* @param string $logLevelThreshold The LogLevel Threshold
|
111 |
+
* @param array $options
|
112 |
+
*
|
113 |
+
* @internal param string $logFilePrefix The prefix for the log file name
|
114 |
+
* @internal param string $logFileExt The extension for the log file
|
115 |
+
*/
|
116 |
+
public function __construct($logDirectory, $logLevelThreshold = LogLevel::DEBUG, array $options = array())
|
117 |
+
{
|
118 |
+
$this->logLevelThreshold = $logLevelThreshold;
|
119 |
+
$this->options = array_merge($this->options, $options);
|
120 |
+
|
121 |
+
$logDirectory = rtrim($logDirectory, DIRECTORY_SEPARATOR);
|
122 |
+
if (!file_exists($logDirectory)) {
|
123 |
+
mkdir($logDirectory, $this->defaultPermissions, true);
|
124 |
+
}
|
125 |
+
|
126 |
+
if (strpos($logDirectory, 'php://') === 0) {
|
127 |
+
$this->setLogToStdOut($logDirectory);
|
128 |
+
$this->setFileHandle('w+');
|
129 |
+
} else {
|
130 |
+
$this->setLogFilePath($logDirectory);
|
131 |
+
if (file_exists($this->logFilePath) && !is_writable($this->logFilePath)) {
|
132 |
+
throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
|
133 |
+
}
|
134 |
+
$this->setFileHandle('a');
|
135 |
+
}
|
136 |
+
|
137 |
+
if (!$this->fileHandle) {
|
138 |
+
throw new RuntimeException('The file could not be opened. Check permissions.');
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* @param string $stdOutPath
|
144 |
+
*/
|
145 |
+
public function setLogToStdOut($stdOutPath)
|
146 |
+
{
|
147 |
+
$this->logFilePath = $stdOutPath;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* @param string $logDirectory
|
152 |
+
*/
|
153 |
+
public function setLogFilePath($logDirectory)
|
154 |
+
{
|
155 |
+
if ($this->options['filename']) {
|
156 |
+
if (strpos($this->options['filename'], '.log') !== false || strpos($this->options['filename'], '.txt') !== false) {
|
157 |
+
$this->logFileName = $this->options['filename'];
|
158 |
+
$this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options['filename'];
|
159 |
+
} else {
|
160 |
+
$this->logFileName = $this->options['filename'] . '.' . $this->options['extension'];
|
161 |
+
$this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options['filename'] . '.' . $this->options['extension'];
|
162 |
+
}
|
163 |
+
} else {
|
164 |
+
$this->logFileName = $this->options['prefix'] . date('Y-m-d') . '.' . $this->options['extension'];
|
165 |
+
$this->logFilePath = $logDirectory . DIRECTORY_SEPARATOR . $this->options['prefix'] . date('Y-m-d') . '.' . $this->options['extension'];
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* @param $writeMode
|
171 |
+
*
|
172 |
+
* @internal param resource $fileHandle
|
173 |
+
*/
|
174 |
+
public function setFileHandle($writeMode)
|
175 |
+
{
|
176 |
+
$this->fileHandle = fopen($this->logFilePath, $writeMode);
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Close file handle.
|
181 |
+
*/
|
182 |
+
public function close()
|
183 |
+
{
|
184 |
+
if ($this->fileHandle) {
|
185 |
+
@fclose($this->fileHandle);
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Class destructor
|
192 |
+
*/
|
193 |
+
public function __destruct()
|
194 |
+
{
|
195 |
+
if ($this->fileHandle) {
|
196 |
+
@fclose($this->fileHandle);
|
197 |
+
}
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Sets the date format used by all instances of KLogger
|
202 |
+
*
|
203 |
+
* @param string $dateFormat Valid format string for date()
|
204 |
+
*/
|
205 |
+
public function setDateFormat($dateFormat)
|
206 |
+
{
|
207 |
+
$this->options['dateFormat'] = $dateFormat;
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Sets the Log Level Threshold
|
212 |
+
*
|
213 |
+
* @param string $logLevelThreshold The log level threshold
|
214 |
+
*/
|
215 |
+
public function setLogLevelThreshold($logLevelThreshold)
|
216 |
+
{
|
217 |
+
$this->logLevelThreshold = $logLevelThreshold;
|
218 |
+
}
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Logs with an arbitrary level.
|
222 |
+
*
|
223 |
+
* @param mixed $level
|
224 |
+
* @param string $message
|
225 |
+
* @param array $context
|
226 |
+
* @return null
|
227 |
+
*/
|
228 |
+
public function log($level, $message, array $context = array())
|
229 |
+
{
|
230 |
+
if ($this->logLevels[$this->logLevelThreshold] < $this->logLevels[$level]) {
|
231 |
+
return;
|
232 |
+
}
|
233 |
+
$message = $this->formatMessage($level, $message, $context);
|
234 |
+
$this->write($message);
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Logs info.
|
239 |
+
*
|
240 |
+
* @param $function string
|
241 |
+
* @param string $message
|
242 |
+
* @param $additional_message string|null
|
243 |
+
* @return null
|
244 |
+
*/
|
245 |
+
public function log_info($function, $message, $additional_message = null)
|
246 |
+
{
|
247 |
+
|
248 |
+
$level = LogLevel::INFO;
|
249 |
+
$message = $this->formatMessageWithFunction($level, $function, $message, $additional_message);
|
250 |
+
$this->write($message);
|
251 |
+
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Logs error.
|
256 |
+
*
|
257 |
+
* @param $function string
|
258 |
+
* @param string $message
|
259 |
+
* @param $additional_message string|null
|
260 |
+
* @return null
|
261 |
+
*/
|
262 |
+
public function log_error($function, $message, $additional_message = null)
|
263 |
+
{
|
264 |
+
|
265 |
+
$level = LogLevel::ERROR;
|
266 |
+
$message = $this->formatMessageWithFunction($level, $function, $message, $additional_message);
|
267 |
+
$this->write($message);
|
268 |
+
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Logs error.
|
273 |
+
*
|
274 |
+
* @param $function string
|
275 |
+
* @param string $message
|
276 |
+
* @param $additional_message string|null
|
277 |
+
* @return null
|
278 |
+
*/
|
279 |
+
public function log_warning($function, $message, $additional_message = null)
|
280 |
+
{
|
281 |
+
$level = LogLevel::WARNING;
|
282 |
+
$message = $this->formatMessageWithFunction($level, $function, $message, $additional_message);
|
283 |
+
$this->write($message);
|
284 |
+
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Writes a line to the log without prepending a status or timestamp
|
289 |
+
*
|
290 |
+
* @param string $message Line to write to the log
|
291 |
+
* @return void
|
292 |
+
*/
|
293 |
+
public function write($message)
|
294 |
+
{
|
295 |
+
if (null !== $this->fileHandle) {
|
296 |
+
if (fwrite($this->fileHandle, $message) === false) {
|
297 |
+
throw new RuntimeException('The file could not be written to. Check that appropriate permissions have been set.');
|
298 |
+
} else {
|
299 |
+
$this->lastLine = trim($message);
|
300 |
+
$this->logLineCount++;
|
301 |
+
|
302 |
+
if ($this->options['flushFrequency'] && $this->logLineCount % $this->options['flushFrequency'] === 0) {
|
303 |
+
fflush($this->fileHandle);
|
304 |
+
}
|
305 |
+
}
|
306 |
+
}
|
307 |
+
}
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Get Log File Name
|
311 |
+
* @return string
|
312 |
+
*/
|
313 |
+
public function getLogFileName()
|
314 |
+
{
|
315 |
+
return $this->logFileName;
|
316 |
+
}
|
317 |
+
|
318 |
+
/**
|
319 |
+
* Get the file path that the log is currently writing to
|
320 |
+
*
|
321 |
+
* @return string
|
322 |
+
*/
|
323 |
+
public function getLogFilePath()
|
324 |
+
{
|
325 |
+
return $this->logFilePath;
|
326 |
+
}
|
327 |
+
|
328 |
+
/**
|
329 |
+
* Get the last line logged to the log file
|
330 |
+
*
|
331 |
+
* @return string
|
332 |
+
*/
|
333 |
+
public function getLastLogLine()
|
334 |
+
{
|
335 |
+
return $this->lastLine;
|
336 |
+
}
|
337 |
+
|
338 |
+
/**
|
339 |
+
* Formats the message for logging.
|
340 |
+
*
|
341 |
+
* @param string $level The Log Level of the message
|
342 |
+
* @param string $message The message to log
|
343 |
+
* @param array $context The context
|
344 |
+
* @return string
|
345 |
+
*/
|
346 |
+
protected function formatMessage($level, $message, $context)
|
347 |
+
{
|
348 |
+
if ($this->options['logFormat']) {
|
349 |
+
$parts = array(
|
350 |
+
'date' => $this->getTimestamp(),
|
351 |
+
'level' => strtoupper($level),
|
352 |
+
'level-padding' => str_repeat(' ', 9 - strlen($level)),
|
353 |
+
'priority' => $this->logLevels[$level],
|
354 |
+
'message' => $message,
|
355 |
+
'context' => json_encode($context),
|
356 |
+
);
|
357 |
+
$message = $this->options['logFormat'];
|
358 |
+
foreach ($parts as $part => $value) {
|
359 |
+
$message = str_replace('{' . $part . '}', $value, $message);
|
360 |
+
}
|
361 |
+
|
362 |
+
} else {
|
363 |
+
if(is_array($message)){
|
364 |
+
$message = "[{$this->getTimestamp()}] [{$level}] {$this->contextToString($message)}";
|
365 |
+
}else{
|
366 |
+
$message = "[{$this->getTimestamp()}] [{$level}] {$message}";
|
367 |
+
}
|
368 |
+
}
|
369 |
+
|
370 |
+
if ($this->options['appendContext'] && !empty($context)) {
|
371 |
+
$message .= PHP_EOL . $this->indent($this->contextToString($context));
|
372 |
+
}
|
373 |
+
|
374 |
+
return $message . PHP_EOL;
|
375 |
+
|
376 |
+
}
|
377 |
+
|
378 |
+
/**
|
379 |
+
* Formats the message for logging with function name and additional message
|
380 |
+
*
|
381 |
+
* @param string $level The Log Level of the message
|
382 |
+
* @param string $function The running function
|
383 |
+
* @param string $message The message to log
|
384 |
+
* @param string $additional_message Additional message
|
385 |
+
* @return string
|
386 |
+
*/
|
387 |
+
protected function formatMessageWithFunction($level, $function, $message, $additional_message)
|
388 |
+
{
|
389 |
+
$parts = array(
|
390 |
+
'date' => $this->getTimestamp(),
|
391 |
+
'function' => $function,
|
392 |
+
'level' => strtoupper($level),
|
393 |
+
'additional' => $additional_message,
|
394 |
+
'level-padding' => str_repeat(' ', 9 - strlen($level)),
|
395 |
+
'message' => $message,
|
396 |
+
);
|
397 |
+
$message = "[{date}] [{function}]::[{level}]: {message}";
|
398 |
+
if ($additional_message) {
|
399 |
+
$message = "[{date}] [{function}]::[{level}]: {additional} {message}";
|
400 |
+
}
|
401 |
+
|
402 |
+
foreach ($parts as $part => $value) {
|
403 |
+
$message = str_replace('{' . $part . '}', $value, $message);
|
404 |
+
}
|
405 |
+
|
406 |
+
return $message . PHP_EOL;
|
407 |
+
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Gets the correctly formatted Date/Time for the log entry.
|
412 |
+
*
|
413 |
+
* PHP DateTime is dump, and you have to resort to trickery to get microseconds
|
414 |
+
* to work correctly, so here it is.
|
415 |
+
*
|
416 |
+
* @return string
|
417 |
+
*/
|
418 |
+
private function getTimestamp()
|
419 |
+
{
|
420 |
+
$originalTime = microtime(true);
|
421 |
+
$micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000);
|
422 |
+
$date = new DateTime(date('Y-m-d H:i:s.' . $micro, $originalTime));
|
423 |
+
|
424 |
+
return $date->format($this->options['dateFormat']);
|
425 |
+
}
|
426 |
+
|
427 |
+
/**
|
428 |
+
* Takes the given context and coverts it to a string.
|
429 |
+
*
|
430 |
+
* @param array $context The Context
|
431 |
+
* @return string
|
432 |
+
*/
|
433 |
+
protected function contextToString($context)
|
434 |
+
{
|
435 |
+
$export = '';
|
436 |
+
foreach ($context as $key => $value) {
|
437 |
+
$export .= "{$key}: ";
|
438 |
+
$export .= preg_replace(array(
|
439 |
+
'/=>\s+([a-zA-Z])/im',
|
440 |
+
'/array\(\s+\)/im',
|
441 |
+
'/^ |\G /m'
|
442 |
+
), array(
|
443 |
+
'=> $1',
|
444 |
+
'array()',
|
445 |
+
' '
|
446 |
+
), str_replace('array (', 'array(', var_export($value, true)));
|
447 |
+
$export .= PHP_EOL;
|
448 |
+
}
|
449 |
+
return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Indents the given string with the given indent.
|
454 |
+
*
|
455 |
+
* @param string $string The string to indent
|
456 |
+
* @param string $indent What to use as the indent.
|
457 |
+
* @return string
|
458 |
+
*/
|
459 |
+
protected function indent($string, $indent = ' ')
|
460 |
+
{
|
461 |
+
return $indent . str_replace("\n", "\n" . $indent, $string);
|
462 |
+
}
|
463 |
+
}
|
views/backup.php
CHANGED
@@ -66,13 +66,13 @@ function scan_import_backups($backup_dir){
|
|
66 |
$file_list = $file_system->get_fileonly_list($backup_dir, 'zip|log');
|
67 |
|
68 |
//If there are zip files then move them into their own folders
|
69 |
-
|
70 |
|
71 |
//If files to import
|
72 |
$job_import_list = array();
|
73 |
if (null != $file_list && is_array($file_list)) {
|
74 |
foreach ( $file_list as $file ) {
|
75 |
-
//
|
76 |
|
77 |
$file_name = substr( basename( $file ), 0, - 4 );
|
78 |
|
@@ -108,7 +108,7 @@ function scan_import_backups($backup_dir){
|
|
108 |
|
109 |
//Is this a BackItUp archive
|
110 |
if ( empty( $folder_name ) || $extension!='.zip' ) {
|
111 |
-
|
112 |
unlink( $file );//get rid of it
|
113 |
continue;
|
114 |
}
|
@@ -117,13 +117,13 @@ function scan_import_backups($backup_dir){
|
|
117 |
$backup_archive_folder = WPBACKITUP__BACKUP_PATH . '/' . $folder_name;
|
118 |
if ( ! is_dir( $backup_archive_folder ) ) {
|
119 |
if ( ! mkdir( $backup_archive_folder, 0755 ) ) {
|
120 |
-
|
121 |
continue;
|
122 |
} else {
|
123 |
-
|
124 |
}
|
125 |
} else {
|
126 |
-
|
127 |
}
|
128 |
|
129 |
|
@@ -131,10 +131,10 @@ function scan_import_backups($backup_dir){
|
|
131 |
//will overwrite if exists
|
132 |
$target_file = $backup_archive_folder . "/" . basename( $file );
|
133 |
if ( ! rename( $file, $target_file ) ) {
|
134 |
-
|
135 |
continue;
|
136 |
} else{
|
137 |
-
|
138 |
}
|
139 |
|
140 |
//add folder to job array if doesnt already exist
|
@@ -144,7 +144,7 @@ function scan_import_backups($backup_dir){
|
|
144 |
|
145 |
}
|
146 |
|
147 |
-
|
148 |
//If any archives were imported then add the job meta
|
149 |
if (is_array($job_import_list) && count($job_import_list)>0) {
|
150 |
|
@@ -152,7 +152,7 @@ function scan_import_backups($backup_dir){
|
|
152 |
foreach ( $job_import_list as $job_name=>$job_path ) {
|
153 |
$ctr++;
|
154 |
//Import into job control table
|
155 |
-
|
156 |
$folder_prefix = substr( $job_name, 0, 4 );
|
157 |
$folder_name_parts = explode( '_', $job_name );
|
158 |
|
@@ -163,30 +163,30 @@ function scan_import_backups($backup_dir){
|
|
163 |
$jobs = WPBackItUp_Job::get_jobs_by_job_name( WPBackItUp_Job::BACKUP, $job_name, WPBackItUp_Job::COMPLETE );
|
164 |
|
165 |
if ( false === $jobs ) {
|
166 |
-
|
167 |
$job_id = current_time( 'timestamp' ) + $ctr; //Create new job id just in case there are deleted job cnotrol records
|
168 |
$job = WPBackItUp_Job::import_completed_job( $job_name, $job_id, WPBackItUp_Job::BACKUP, $job_id );
|
169 |
|
170 |
} else {
|
171 |
-
|
172 |
$job = is_array( $jobs ) ? current( $jobs ) : false;
|
173 |
}
|
174 |
|
175 |
-
|
176 |
|
177 |
//if job exists - update job meta
|
178 |
if ( false !== $job ) {
|
179 |
-
|
180 |
|
181 |
$file_system = new WPBackItUp_FileSystem();
|
182 |
$zip_files = $file_system->get_fileonly_list_with_filesize( $job_path, 'zip' );
|
183 |
|
184 |
-
|
185 |
|
186 |
$job->setJobMetaValue( 'backup_zip_files', $zip_files ); //list of zip files
|
187 |
|
188 |
//If we get this far job was imported successfully
|
189 |
-
|
190 |
}
|
191 |
}
|
192 |
}
|
66 |
$file_list = $file_system->get_fileonly_list($backup_dir, 'zip|log');
|
67 |
|
68 |
//If there are zip files then move them into their own folders
|
69 |
+
WPBackItUp_Logger::log_info($debug_backup_view_log,__METHOD__,'Files in backup folder: ' .var_export($file_list,true));
|
70 |
|
71 |
//If files to import
|
72 |
$job_import_list = array();
|
73 |
if (null != $file_list && is_array($file_list)) {
|
74 |
foreach ( $file_list as $file ) {
|
75 |
+
//WPBackItUp_Logger::log_info( $debug_backup_view_log, __METHOD__, 'File:' . $file );
|
76 |
|
77 |
$file_name = substr( basename( $file ), 0, - 4 );
|
78 |
|
108 |
|
109 |
//Is this a BackItUp archive
|
110 |
if ( empty( $folder_name ) || $extension!='.zip' ) {
|
111 |
+
WPBackItUp_Logger::log_error( $debug_backup_view_log, __METHOD__, 'File does not appear to be a WPBackItUp backup archive:'. $file );
|
112 |
unlink( $file );//get rid of it
|
113 |
continue;
|
114 |
}
|
117 |
$backup_archive_folder = WPBACKITUP__BACKUP_PATH . '/' . $folder_name;
|
118 |
if ( ! is_dir( $backup_archive_folder ) ) {
|
119 |
if ( ! mkdir( $backup_archive_folder, 0755 ) ) {
|
120 |
+
WPBackItUp_Logger::log_error( $debug_backup_view_log, __METHOD__, 'Folder is not writable:' . $backup_archive_folder );
|
121 |
continue;
|
122 |
} else {
|
123 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log, __METHOD__, 'Folder created:' . $backup_archive_folder );
|
124 |
}
|
125 |
} else {
|
126 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log, __METHOD__, 'Folder exists:' . $backup_archive_folder );
|
127 |
}
|
128 |
|
129 |
|
131 |
//will overwrite if exists
|
132 |
$target_file = $backup_archive_folder . "/" . basename( $file );
|
133 |
if ( ! rename( $file, $target_file ) ) {
|
134 |
+
WPBackItUp_Logger::log_error( $debug_backup_view_log, __METHOD__, 'Cant move zip file to backup folder' );
|
135 |
continue;
|
136 |
} else{
|
137 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log, __METHOD__, 'File Imported:' .$file);
|
138 |
}
|
139 |
|
140 |
//add folder to job array if doesnt already exist
|
144 |
|
145 |
}
|
146 |
|
147 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log,__METHOD__, 'Job Import List:' .var_export($job_import_list,true));
|
148 |
//If any archives were imported then add the job meta
|
149 |
if (is_array($job_import_list) && count($job_import_list)>0) {
|
150 |
|
152 |
foreach ( $job_import_list as $job_name=>$job_path ) {
|
153 |
$ctr++;
|
154 |
//Import into job control table
|
155 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log,__METHOD__, 'Import Backup To Post Table Started' );
|
156 |
$folder_prefix = substr( $job_name, 0, 4 );
|
157 |
$folder_name_parts = explode( '_', $job_name );
|
158 |
|
163 |
$jobs = WPBackItUp_Job::get_jobs_by_job_name( WPBackItUp_Job::BACKUP, $job_name, WPBackItUp_Job::COMPLETE );
|
164 |
|
165 |
if ( false === $jobs ) {
|
166 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log,__METHOD__, 'Import job' );
|
167 |
$job_id = current_time( 'timestamp' ) + $ctr; //Create new job id just in case there are deleted job cnotrol records
|
168 |
$job = WPBackItUp_Job::import_completed_job( $job_name, $job_id, WPBackItUp_Job::BACKUP, $job_id );
|
169 |
|
170 |
} else {
|
171 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log,__METHOD__,'Selecting Existing job.' );
|
172 |
$job = is_array( $jobs ) ? current( $jobs ) : false;
|
173 |
}
|
174 |
|
175 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log,__METHOD__, $job );
|
176 |
|
177 |
//if job exists - update job meta
|
178 |
if ( false !== $job ) {
|
179 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log,__METHOD__, 'Update Job Meta' );
|
180 |
|
181 |
$file_system = new WPBackItUp_FileSystem();
|
182 |
$zip_files = $file_system->get_fileonly_list_with_filesize( $job_path, 'zip' );
|
183 |
|
184 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log,__METHOD__, $zip_files );
|
185 |
|
186 |
$job->setJobMetaValue( 'backup_zip_files', $zip_files ); //list of zip files
|
187 |
|
188 |
//If we get this far job was imported successfully
|
189 |
+
WPBackItUp_Logger::log_info( $debug_backup_view_log, __METHOD__, 'Job Imported:' . $folder_name );
|
190 |
}
|
191 |
}
|
192 |
}
|
views/settings.php
CHANGED
@@ -20,6 +20,8 @@
|
|
20 |
|
21 |
|
22 |
$backup_dbtables_batch_size=$this->backup_dbtables_batch_size();
|
|
|
|
|
23 |
$backup_plugins_batch_size=$this->backup_plugins_batch_size();
|
24 |
$backup_themes_batch_size=$this->backup_themes_batch_size();
|
25 |
$backup_uploads_batch_size=$this->backup_uploads_batch_size();
|
@@ -149,10 +151,20 @@
|
|
149 |
<h3 class="promo"><i class="fa fa-wrench"></i> <?php _e('Batch Size', 'wp-backitup') ?></h3>
|
150 |
<p><b><?php _e('Enter the batch size for each of your content items.', 'wp-backitup') ?></b></p>
|
151 |
<p><?php _e('These settings tell WPBackItUp how many items that should be added to the backup at a time. If you experience timeouts while running a backup then these settings can be used to help reduce the amount of time it takes WPBackItUp to complete each backup task .', 'wp-backitup') ?></p>
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
<p>
|
158 |
<input name="data[backup_plugins_batch_size]" id="wpbackitup_plugins_batch_size" type="text" size="3" value="<?php echo $backup_plugins_batch_size; ?>"/>
|
20 |
|
21 |
|
22 |
$backup_dbtables_batch_size=$this->backup_dbtables_batch_size();
|
23 |
+
$backup_sql_merge_batch_size=$this->backup_sql_merge_batch_size();
|
24 |
+
$backup_sql_batch_size=$this->backup_sql_batch_size();
|
25 |
$backup_plugins_batch_size=$this->backup_plugins_batch_size();
|
26 |
$backup_themes_batch_size=$this->backup_themes_batch_size();
|
27 |
$backup_uploads_batch_size=$this->backup_uploads_batch_size();
|
151 |
<h3 class="promo"><i class="fa fa-wrench"></i> <?php _e('Batch Size', 'wp-backitup') ?></h3>
|
152 |
<p><b><?php _e('Enter the batch size for each of your content items.', 'wp-backitup') ?></b></p>
|
153 |
<p><?php _e('These settings tell WPBackItUp how many items that should be added to the backup at a time. If you experience timeouts while running a backup then these settings can be used to help reduce the amount of time it takes WPBackItUp to complete each backup task .', 'wp-backitup') ?></p>
|
154 |
+
<p>
|
155 |
+
<input name="data[backup_dbtables_batch_size]" id="wpbackitup_dbtables_batch_size" type="text" size="3" value="<?php echo $backup_dbtables_batch_size; ?>"/>
|
156 |
+
<label> <?php _e('DB Tables Batch Size', 'wp-backitup') ?></label>
|
157 |
+
</p>
|
158 |
+
|
159 |
+
<p>
|
160 |
+
<input name="data[backup_sql_merge_batch_size]" id="wpbackitup_sql_merge_batch_size" type="text" size="3" value="<?php echo $backup_sql_merge_batch_size; ?>"/>
|
161 |
+
<label> <?php _e('SQL Merge Batch Size', 'wp-backitup') ?></label>
|
162 |
+
</p>
|
163 |
+
|
164 |
+
<p>
|
165 |
+
<input name="data[backup_sql_batch_size]" id="wpbackitup_sql_batch_size" type="text" size="3" value="<?php echo $backup_sql_batch_size; ?>"/>
|
166 |
+
<label> <?php _e('SQL Batch Size', 'wp-backitup') ?></label>
|
167 |
+
</p>
|
168 |
|
169 |
<p>
|
170 |
<input name="data[backup_plugins_batch_size]" id="wpbackitup_plugins_batch_size" type="text" size="3" value="<?php echo $backup_plugins_batch_size; ?>"/>
|
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.
|
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',
|
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));
|
@@ -100,6 +100,8 @@ define( 'WPBACKITUP__PLUGINS_BATCH_SIZE', 5000); //~100kb each = 5000*100 = 5000
|
|
100 |
define( 'WPBACKITUP__OTHERS_BATCH_SIZE', 500); //~100kb each = 5000*100 = 500000 kb = 500 mb
|
101 |
define( 'WPBACKITUP__UPLOADS_BATCH_SIZE', 500); //anyones guess here
|
102 |
define( 'WPBACKITUP__DATABASE_BATCH_SIZE', 10000);
|
|
|
|
|
103 |
|
104 |
//activation hooks
|
105 |
register_activation_hook( __FILE__, array( 'WPBackitup_Admin', 'activate' ) );
|
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.3
|
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', 3); //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));
|
100 |
define( 'WPBACKITUP__OTHERS_BATCH_SIZE', 500); //~100kb each = 5000*100 = 500000 kb = 500 mb
|
101 |
define( 'WPBACKITUP__UPLOADS_BATCH_SIZE', 500); //anyones guess here
|
102 |
define( 'WPBACKITUP__DATABASE_BATCH_SIZE', 10000);
|
103 |
+
define( 'WPBACKITUP__SQL_MERGE_BATCH_SIZE', 10000);
|
104 |
+
define( 'WPBACKITUP__SQL_BATCH_SIZE', 10000);
|
105 |
|
106 |
//activation hooks
|
107 |
register_activation_hook( __FILE__, array( 'WPBackitup_Admin', 'activate' ) );
|