Changeset 3292404
- Timestamp:
- 05/13/2025 09:03:33 AM (11 months ago)
- Location:
- watchful
- Files:
-
- 10 added
- 16 edited
- 1 copied
-
tags/v2.0.5 (copied) (copied from watchful/trunk)
-
tags/v2.0.5/lib/Backup/Processor.php (modified) (4 diffs)
-
tags/v2.0.5/lib/Backup/Utils.php (modified) (4 diffs)
-
tags/v2.0.5/lib/Controller/Restore.php (added)
-
tags/v2.0.5/lib/Helpers/Connection.php (modified) (1 diff)
-
tags/v2.0.5/lib/Helpers/Files.php (modified) (2 diffs)
-
tags/v2.0.5/lib/Helpers/PluginManager.php (modified) (1 diff)
-
tags/v2.0.5/lib/Restore (added)
-
tags/v2.0.5/lib/Restore/Manager.php (added)
-
tags/v2.0.5/lib/Restore/RestoreDownloader.php (added)
-
tags/v2.0.5/lib/Restore/StepResponse.php (added)
-
tags/v2.0.5/lib/Routes.php (modified) (2 diffs)
-
tags/v2.0.5/readme.txt (modified) (1 diff)
-
tags/v2.0.5/watchful.php (modified) (1 diff)
-
trunk/lib/Backup/Processor.php (modified) (4 diffs)
-
trunk/lib/Backup/Utils.php (modified) (4 diffs)
-
trunk/lib/Controller/Restore.php (added)
-
trunk/lib/Helpers/Connection.php (modified) (1 diff)
-
trunk/lib/Helpers/Files.php (modified) (2 diffs)
-
trunk/lib/Helpers/PluginManager.php (modified) (1 diff)
-
trunk/lib/Restore (added)
-
trunk/lib/Restore/Manager.php (added)
-
trunk/lib/Restore/RestoreDownloader.php (added)
-
trunk/lib/Restore/StepResponse.php (added)
-
trunk/lib/Routes.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/watchful.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
watchful/tags/v2.0.5/lib/Backup/Processor.php
r3257611 r3292404 14 14 final class Processor 15 15 { 16 public const DB_PREFIX_PLACEHOLDER = 'DB_PREFIX_'; 16 17 private const BACKUP_PATHS_TO_IGNORE = ['wp-content/ai1wm-backups', 'wp-content/backups']; 17 18 … … 263 264 if ($current_offset === 0) { 264 265 $create_table = $wpdb->get_row("SHOW CREATE TABLE $table_name", ARRAY_N); 266 267 $create_sql = $create_table[1]; 268 $table_name_without_prefix = str_replace($wpdb->prefix, self::DB_PREFIX_PLACEHOLDER, $table_name); 269 $create_sql = str_replace($table_name, $table_name_without_prefix, $create_sql); 270 271 if (strpos($create_sql, 'REFERENCES `'.$wpdb->prefix) !== false) { 272 $create_sql = str_replace( 273 'REFERENCES `'.$wpdb->prefix, 274 'REFERENCES `'.self::DB_PREFIX_PLACEHOLDER, 275 $create_sql 276 ); 277 } 278 279 $drop_table = "DROP TABLE IF EXISTS `$table_name_without_prefix`;\n"; 265 280 $write_result = file_put_contents( 266 281 $backup_file, 267 "-- Table: $table_name\n". 268 $create_table[1].";\n\n", 282 "-- Table: $table_name_without_prefix\n". 283 $drop_table. 284 $create_sql.";\n\n", 269 285 $file_mode 270 286 ); … … 301 317 } 302 318 303 $sql_content = '';319 $sql_content = "START TRANSACTION;\n"; 304 320 foreach ($rows as $row) { 305 321 $insert_values = array_map(function ($value) use ($wpdb) { … … 307 323 }, $row); 308 324 309 $sql_content .= "INSERT INTO $table_name VALUES ('". 325 $table_name_without_prefix = str_replace($wpdb->prefix, self::DB_PREFIX_PLACEHOLDER, $table_name); 326 $sql_content .= "INSERT INTO $table_name_without_prefix VALUES ('". 310 327 implode("', '", $insert_values)."');\n"; 311 328 } 329 $sql_content .= "COMMIT;\n\n"; 312 330 313 331 $write_result = file_put_contents($backup_file, $sql_content, FILE_APPEND); -
watchful/tags/v2.0.5/lib/Backup/Utils.php
r3257611 r3292404 4 4 5 5 use RuntimeException; 6 use Watchful\Helpers\Files; 6 7 use WP_Filesystem_Direct; 7 8 use ZipArchive; … … 11 12 public const BACKUP_DATABASE_FILE_NAME = 'database.sql'; 12 13 public const BACKUP_FILES_LIST_FILE_NAME = 'files_list.txt'; 14 15 /** @var Files $file_helper */ 16 private $file_helper; 17 18 public function __construct() 19 { 20 $this->file_helper = new Files(); 21 } 22 13 23 14 24 public function get_zip_archive(string $backup_id): ZipArchive … … 71 81 } 72 82 73 $this-> add_security_files($backup_dir);83 $this->file_helper->add_security_files($backup_dir); 74 84 75 85 return $backup_dir; … … 102 112 } 103 113 104 $this-> add_security_files($backup_dir);114 $this->file_helper->add_security_files($backup_dir); 105 115 106 116 return $backup_dir; 107 }108 109 private function add_security_files(string $path): void110 {111 /** @var $wp_filesystem WP_Filesystem_Direct */112 global $wp_filesystem;113 if (empty($wp_filesystem)) {114 require_once(ABSPATH.'wp-admin/includes/file.php');115 WP_Filesystem();116 }117 118 $result = true;119 $htaccess_path = $path.'/.htaccess';120 if (!file_exists($htaccess_path)) {121 $result = $wp_filesystem->put_contents($htaccess_path, "Deny from all\n");122 }123 124 $index_path = $path.'/index.php';125 if (!file_exists($index_path)) {126 $result = $wp_filesystem->put_contents($index_path, "<?php // Silence is golden. ?>\n");127 }128 129 if ($result === false) {130 throw new RuntimeException('Failed to create security files');131 }132 117 } 133 118 -
watchful/tags/v2.0.5/lib/Helpers/Connection.php
r3123686 r3292404 57 57 * pass as post data. 58 58 * 59 * @return false on error | a response object with the following properties59 * @return StdClass|false false on error | a response object with the following properties 60 60 * - data : raw response 61 61 * - info : curl info 62 62 * - error : curl error 63 63 */ 64 public function get_curl( $config)64 public function get_curl(array $config) 65 65 { 66 66 if (!isset($config['url'])) { -
watchful/tags/v2.0.5/lib/Helpers/Files.php
r3123686 r3292404 13 13 namespace Watchful\Helpers; 14 14 15 use RuntimeException; 15 16 use Watchful\Audit\Files\Tools; 16 17 use Watchful\Exception; 18 use WP_Filesystem_Direct; 17 19 18 20 /** … … 112 114 return 200 === $code; 113 115 } 116 117 public function add_security_files(string $path): void 118 { 119 /** @var $wp_filesystem WP_Filesystem_Direct */ 120 global $wp_filesystem; 121 if (empty($wp_filesystem)) { 122 require_once(ABSPATH.'wp-admin/includes/file.php'); 123 WP_Filesystem(); 124 } 125 126 $result = true; 127 $htaccess_path = $path.'/.htaccess'; 128 if (!file_exists($htaccess_path)) { 129 $result = $wp_filesystem->put_contents($htaccess_path, "Deny from all\n"); 130 } 131 132 $index_path = $path.'/index.php'; 133 if (!file_exists($index_path)) { 134 $result = $wp_filesystem->put_contents($index_path, "<?php // Silence is golden. ?>\n"); 135 } 136 137 if ($result === false) { 138 throw new RuntimeException('Failed to create security files'); 139 } 140 } 114 141 } -
watchful/tags/v2.0.5/lib/Helpers/PluginManager.php
r3266148 r3292404 385 385 } 386 386 387 if ( version_compare(phpversion(), $min_php_version) < 0) {387 if ($min_php_version && version_compare(phpversion(), $min_php_version) < 0) { 388 388 $this->logger->log('PHP version is too low for this update', [ 389 389 'required_version' => $min_php_version, -
watchful/tags/v2.0.5/lib/Routes.php
r3243697 r3292404 19 19 use Watchful\Controller\Logs; 20 20 use Watchful\Controller\Plugins; 21 use Watchful\Controller\Restore; 21 22 use Watchful\Controller\Tests; 22 23 use Watchful\Controller\Themes; … … 94 95 $logs = new Logs(); 95 96 $logs->register_routes(); 97 98 $restore = new Restore(); 99 $restore->register_routes(); 96 100 } 97 101 } -
watchful/tags/v2.0.5/readme.txt
r3280129 r3292404 83 83 84 84 == Changelog == 85 = 2.0.5 = 86 * Implement backup restoration 87 85 88 = v2.0.4 = 86 89 * Use the same lock when updating plugins and themes -
watchful/tags/v2.0.5/watchful.php
r3266148 r3292404 4 4 * Plugin URI: https://app.watchful.net 5 5 * Description: Remote Website Management Plugin by Watchful 6 * Version: 2.0. 46 * Version: 2.0.5 7 7 * Author: watchful 8 8 * Author URI: https://watchful.net -
watchful/trunk/lib/Backup/Processor.php
r3257611 r3292404 14 14 final class Processor 15 15 { 16 public const DB_PREFIX_PLACEHOLDER = 'DB_PREFIX_'; 16 17 private const BACKUP_PATHS_TO_IGNORE = ['wp-content/ai1wm-backups', 'wp-content/backups']; 17 18 … … 263 264 if ($current_offset === 0) { 264 265 $create_table = $wpdb->get_row("SHOW CREATE TABLE $table_name", ARRAY_N); 266 267 $create_sql = $create_table[1]; 268 $table_name_without_prefix = str_replace($wpdb->prefix, self::DB_PREFIX_PLACEHOLDER, $table_name); 269 $create_sql = str_replace($table_name, $table_name_without_prefix, $create_sql); 270 271 if (strpos($create_sql, 'REFERENCES `'.$wpdb->prefix) !== false) { 272 $create_sql = str_replace( 273 'REFERENCES `'.$wpdb->prefix, 274 'REFERENCES `'.self::DB_PREFIX_PLACEHOLDER, 275 $create_sql 276 ); 277 } 278 279 $drop_table = "DROP TABLE IF EXISTS `$table_name_without_prefix`;\n"; 265 280 $write_result = file_put_contents( 266 281 $backup_file, 267 "-- Table: $table_name\n". 268 $create_table[1].";\n\n", 282 "-- Table: $table_name_without_prefix\n". 283 $drop_table. 284 $create_sql.";\n\n", 269 285 $file_mode 270 286 ); … … 301 317 } 302 318 303 $sql_content = '';319 $sql_content = "START TRANSACTION;\n"; 304 320 foreach ($rows as $row) { 305 321 $insert_values = array_map(function ($value) use ($wpdb) { … … 307 323 }, $row); 308 324 309 $sql_content .= "INSERT INTO $table_name VALUES ('". 325 $table_name_without_prefix = str_replace($wpdb->prefix, self::DB_PREFIX_PLACEHOLDER, $table_name); 326 $sql_content .= "INSERT INTO $table_name_without_prefix VALUES ('". 310 327 implode("', '", $insert_values)."');\n"; 311 328 } 329 $sql_content .= "COMMIT;\n\n"; 312 330 313 331 $write_result = file_put_contents($backup_file, $sql_content, FILE_APPEND); -
watchful/trunk/lib/Backup/Utils.php
r3257611 r3292404 4 4 5 5 use RuntimeException; 6 use Watchful\Helpers\Files; 6 7 use WP_Filesystem_Direct; 7 8 use ZipArchive; … … 11 12 public const BACKUP_DATABASE_FILE_NAME = 'database.sql'; 12 13 public const BACKUP_FILES_LIST_FILE_NAME = 'files_list.txt'; 14 15 /** @var Files $file_helper */ 16 private $file_helper; 17 18 public function __construct() 19 { 20 $this->file_helper = new Files(); 21 } 22 13 23 14 24 public function get_zip_archive(string $backup_id): ZipArchive … … 71 81 } 72 82 73 $this-> add_security_files($backup_dir);83 $this->file_helper->add_security_files($backup_dir); 74 84 75 85 return $backup_dir; … … 102 112 } 103 113 104 $this-> add_security_files($backup_dir);114 $this->file_helper->add_security_files($backup_dir); 105 115 106 116 return $backup_dir; 107 }108 109 private function add_security_files(string $path): void110 {111 /** @var $wp_filesystem WP_Filesystem_Direct */112 global $wp_filesystem;113 if (empty($wp_filesystem)) {114 require_once(ABSPATH.'wp-admin/includes/file.php');115 WP_Filesystem();116 }117 118 $result = true;119 $htaccess_path = $path.'/.htaccess';120 if (!file_exists($htaccess_path)) {121 $result = $wp_filesystem->put_contents($htaccess_path, "Deny from all\n");122 }123 124 $index_path = $path.'/index.php';125 if (!file_exists($index_path)) {126 $result = $wp_filesystem->put_contents($index_path, "<?php // Silence is golden. ?>\n");127 }128 129 if ($result === false) {130 throw new RuntimeException('Failed to create security files');131 }132 117 } 133 118 -
watchful/trunk/lib/Helpers/Connection.php
r3123686 r3292404 57 57 * pass as post data. 58 58 * 59 * @return false on error | a response object with the following properties59 * @return StdClass|false false on error | a response object with the following properties 60 60 * - data : raw response 61 61 * - info : curl info 62 62 * - error : curl error 63 63 */ 64 public function get_curl( $config)64 public function get_curl(array $config) 65 65 { 66 66 if (!isset($config['url'])) { -
watchful/trunk/lib/Helpers/Files.php
r3123686 r3292404 13 13 namespace Watchful\Helpers; 14 14 15 use RuntimeException; 15 16 use Watchful\Audit\Files\Tools; 16 17 use Watchful\Exception; 18 use WP_Filesystem_Direct; 17 19 18 20 /** … … 112 114 return 200 === $code; 113 115 } 116 117 public function add_security_files(string $path): void 118 { 119 /** @var $wp_filesystem WP_Filesystem_Direct */ 120 global $wp_filesystem; 121 if (empty($wp_filesystem)) { 122 require_once(ABSPATH.'wp-admin/includes/file.php'); 123 WP_Filesystem(); 124 } 125 126 $result = true; 127 $htaccess_path = $path.'/.htaccess'; 128 if (!file_exists($htaccess_path)) { 129 $result = $wp_filesystem->put_contents($htaccess_path, "Deny from all\n"); 130 } 131 132 $index_path = $path.'/index.php'; 133 if (!file_exists($index_path)) { 134 $result = $wp_filesystem->put_contents($index_path, "<?php // Silence is golden. ?>\n"); 135 } 136 137 if ($result === false) { 138 throw new RuntimeException('Failed to create security files'); 139 } 140 } 114 141 } -
watchful/trunk/lib/Helpers/PluginManager.php
r3266148 r3292404 385 385 } 386 386 387 if ( version_compare(phpversion(), $min_php_version) < 0) {387 if ($min_php_version && version_compare(phpversion(), $min_php_version) < 0) { 388 388 $this->logger->log('PHP version is too low for this update', [ 389 389 'required_version' => $min_php_version, -
watchful/trunk/lib/Routes.php
r3243697 r3292404 19 19 use Watchful\Controller\Logs; 20 20 use Watchful\Controller\Plugins; 21 use Watchful\Controller\Restore; 21 22 use Watchful\Controller\Tests; 22 23 use Watchful\Controller\Themes; … … 94 95 $logs = new Logs(); 95 96 $logs->register_routes(); 97 98 $restore = new Restore(); 99 $restore->register_routes(); 96 100 } 97 101 } -
watchful/trunk/readme.txt
r3280129 r3292404 83 83 84 84 == Changelog == 85 = 2.0.5 = 86 * Implement backup restoration 87 85 88 = v2.0.4 = 86 89 * Use the same lock when updating plugins and themes -
watchful/trunk/watchful.php
r3266148 r3292404 4 4 * Plugin URI: https://app.watchful.net 5 5 * Description: Remote Website Management Plugin by Watchful 6 * Version: 2.0. 46 * Version: 2.0.5 7 7 * Author: watchful 8 8 * Author URI: https://watchful.net
Note: See TracChangeset
for help on using the changeset viewer.