Changeset 2639397
- Timestamp:
- 12/04/2021 07:53:46 AM (4 years ago)
- Location:
- b2-sync/trunk
- Files:
-
- 6 edited
-
src/B2Sync_plugin_helper.php (modified) (2 diffs)
-
src/Core/AdminLogPage.php (modified) (1 diff)
-
src/Core/PluginClass.php (modified) (1 diff)
-
src/Core/SyncClass.php (modified) (6 diffs)
-
src/Core/Utils.php (modified) (1 diff)
-
views/admin/page_log.twig (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
b2-sync/trunk/src/B2Sync_plugin_helper.php
r2636570 r2639397 18 18 * @throws \Exception 19 19 */ 20 function B2Sync_ infologthis($message)20 function B2Sync_logthis($message) 21 21 { 22 $log = new Logger('B2Sync_ plugin_infolog');23 $stream = new StreamHandler(WP_CONTENT_DIR . B2Sync_DS . Enum::LOG_FILE_ MESSAGE, Logger::INFO);22 $log = new Logger('B2Sync_LOG'); 23 $stream = new StreamHandler(WP_CONTENT_DIR . B2Sync_DS . Enum::LOG_FILE_ERROR, Logger::INFO); 24 24 $log->pushHandler($stream); 25 25 $log->info($message); … … 27 27 unset($stream); 28 28 } 29 function B2Sync_errorlogthis($message)30 {31 $log = new Logger('B2Sync_plugin_errorlog');32 $stream = new StreamHandler(WP_CONTENT_DIR . B2Sync_DS . Enum::LOG_FILE_ERROR, Logger::ERROR);33 $log->pushHandler($stream);34 $log->error($message);35 unset($log);36 unset($stream);37 } -
b2-sync/trunk/src/Core/AdminLogPage.php
r2636570 r2639397 89 89 { 90 90 $log_file = $log_file_path; 91 $max_lines = 10 ;91 $max_lines = 100; 92 92 $log_data = ''; 93 93 $log_data_array = []; -
b2-sync/trunk/src/Core/PluginClass.php
r2636570 r2639397 138 138 // Check for nonce security 139 139 if (!wp_verify_nonce($_POST['nonce'], 'ajax-nonce')) { 140 B2Sync_ errorlogthis('ajax nonce failed while sync button was clicked');140 B2Sync_logthis('[ERROR] ajax nonce failed while sync button was clicked'); 141 141 wp_send_json_error('An error occurred'); 142 142 } else { 143 B2Sync_errorlogthis('Sync process started via ajax action button'); 144 $error_msg = Utils::doSync(); 143 $error_msg = Utils::doSync('manual_ajax_action'); 145 144 wp_send_json_success('Sync process completed.'); 146 145 } -
b2-sync/trunk/src/Core/SyncClass.php
r2636570 r2639397 56 56 if (!Utils::notEmptyOrNull($this->key_id)) { 57 57 $error .= 'key_id empty ||'; 58 B2Sync_ errorlogthis('[fields] KeyID cannot be empty!');58 B2Sync_logthis('[fields] KeyID cannot be empty!'); 59 59 } 60 60 if (!Utils::notEmptyOrNull($this->application_key)) { 61 61 $error .= 'application_key empty ||'; 62 B2Sync_ errorlogthis('[fields] ApplicationKey cannot be empty!');62 B2Sync_logthis('[fields] ApplicationKey cannot be empty!'); 63 63 } 64 64 if (!Utils::notEmptyOrNull($this->bucket_name)) { 65 65 $error .= 'bucket_name empty ||'; 66 B2Sync_ errorlogthis('[fields] BucketName cannot be empty!');66 B2Sync_logthis('[fields] BucketName cannot be empty!'); 67 67 } 68 68 69 69 if (mb_strlen($error) > 0) { 70 70 $this->field_status = Enum::FIELD_STATUS_VALUE_OFF; 71 B2Sync_ errorlogthis('[WARNING] setting b2-sync to OFF - by rule, as some field(s) mentioned above is empty');71 B2Sync_logthis('[WARNING] setting b2-sync to OFF - by rule, as some field(s) mentioned above is empty'); 72 72 } 73 73 } … … 82 82 83 83 if ($rclonePath == Enum::NOT_FOUND) { 84 B2Sync_ errorlogthis('RCLONE was not found on this server');84 B2Sync_logthis('RCLONE was not found on this server'); 85 85 86 86 return false; … … 88 88 89 89 return true; 90 } 91 92 /** 93 * To check is there's any currently running rclone process 94 * 95 * @throws \Exception 96 * 97 * @return bool 98 */ 99 public static function checkAnyCurrentRunningProcess() 100 { 101 $process_pgrep = new Process([ 102 'pgrep', 103 '-f', 104 'rclone', 105 ]); 106 $process_pgrep->run(); 107 $is_running = $process_pgrep->getOutput(); 108 unset($process_pgrep); 109 110 if ($is_running > 0) { 111 return true; 112 } 113 114 return false; 90 115 } 91 116 … … 108 133 $remote_path = ':b2,account="' . $this->key_id . '",key="' . $this->application_key . '":' . $this->bucket_name . '/' . $this->uploads_folder_name; 109 134 110 B2Sync_ errorlogthis('Has started the syncing process..');135 B2Sync_logthis('[INFO] The syncing process has started..'); 111 136 /* 112 137 * Command we are trying to execute on Bash: … … 115 140 $process = new Process([ 116 141 'rclone', 117 '- q',142 '-v', 118 143 'sync', 119 144 $path_to_uploads, … … 122 147 $process->start(); 123 148 124 $item_count = 1;125 while ($process->isRunning()) {126 //waiting for process to finish127 B2Sync_errorlogthis('Still syncing.. Process check count->' . $item_count);128 $item_count++;129 }149 /** 150 * Getting real-time Process Output (from rclone) 151 * Waits until the given anonymous function returns true 152 */ 153 $process->waitUntil(function ($type, $output) { 154 B2Sync_logthis('[rclone]: ' . $output); 130 155 131 if ($process->isRunning() == false) { 132 B2Sync_errorlogthis('Syncing done!'); 133 } 156 return $output === 'Ready. Waiting for commands...'; 157 }); 134 158 135 159 if ($process->isSuccessful()) { 136 $output = $process->getOutput(); 137 B2Sync_errorlogthis('Syncing seems to be successful!'); 138 B2Sync_errorlogthis($output); 160 B2Sync_logthis('[DONE] Syncing has completed and seems to be successful!'); 139 161 } else { 140 B2Sync_ errorlogthis('There seems to be an issue, see output below');141 B2Sync_ errorlogthis($process->getErrorOutput());162 B2Sync_logthis('[ERROR] There seems to be an issue, see output below'); 163 B2Sync_logthis($process->getErrorOutput()); 142 164 } 143 165 } -
b2-sync/trunk/src/Core/Utils.php
r2636570 r2639397 97 97 public static function doSync($action = 'action_button') 98 98 { 99 //Clear log file before starting next sync 100 $error_log_file = WP_CONTENT_DIR . B2Sync_DS . Enum::LOG_FILE_ERROR; 101 AdminLogPage::clearErrorLog($error_log_file); 99 $error_msg = ''; 102 100 103 $error_msg = ''; 104 B2Sync_errorlogthis('A Sync was triggered by action: ' . $action); 105 if (SyncClass::checkRclone() === false) { 106 $error_msg = 'WARNING: the software "rclone" does not seem to be present on your server, please ask your server admin to install it before using this plugin'; 101 /** 102 * To check is there's any currently running rclone process 103 */ 104 $is_running = SyncClass::checkAnyCurrentRunningProcess(); 105 if ($is_running === true) { 106 B2Sync_logthis('[WARNING] You have invoked the sync more than once, Allow some time to let the current syncing complete!'); 107 108 return false; 107 109 } else { 108 $sync = new SyncClass(); 109 if ($sync->field_status == Enum::FIELD_STATUS_VALUE_OFF) { 110 $error_msg = 'Please enable the sync below in the dropdown or one of the field(s) is empty!'; 110 if (SyncClass::checkRclone() === false) { 111 $error_msg = '[ERROR] the software "rclone" does not seem to be present on your server, please ask your server admin to install it before using this plugin'; 111 112 } else { 112 $error_msg = 'Syncing has started, check the log on the sub-menu ' . Enum::ADMIN_LOG_MENU_TITLE . ' page'; 113 $sync->start(); 113 B2Sync_logthis('[INFO] A Sync was triggered by action: ' . $action); 114 115 //Clear log file before starting next sync 116 $error_log_file = WP_CONTENT_DIR . B2Sync_DS . Enum::LOG_FILE_ERROR; 117 AdminLogPage::clearErrorLog($error_log_file); 118 119 $sync = new SyncClass(); 120 if ($sync->field_status == Enum::FIELD_STATUS_VALUE_OFF) { 121 $error_msg = '[ERROR] Please enable the sync below in the dropdown or one of the field(s) is empty!'; 122 } else { 123 $error_msg = '[INFO] Syncing has started, check the log on the sub-menu ' . Enum::ADMIN_LOG_MENU_TITLE . ' page'; 124 $sync->start(); 125 } 114 126 } 127 128 return $error_msg; 115 129 } 116 117 return $error_msg;118 130 } 119 131 -
b2-sync/trunk/views/admin/page_log.twig
r2636570 r2639397 5 5 <table class="form-table"> 6 6 <tr> 7 <td>( Only the latest 10 entries will be displayed- pay attention to the DATE!)</td>7 <td>(<u>Only the latest 100 entries will be displayed</u> - pay attention to the DATE!)</td> 8 8 </tr> 9 9 <tr>
Note: See TracChangeset
for help on using the changeset viewer.