Plugin Directory

Changeset 3292404


Ignore:
Timestamp:
05/13/2025 09:03:33 AM (11 months ago)
Author:
watchful
Message:

v2.0.5

Location:
watchful
Files:
10 added
16 edited
1 copied

Legend:

Unmodified
Added
Removed
  • watchful/tags/v2.0.5/lib/Backup/Processor.php

    r3257611 r3292404  
    1414final class Processor
    1515{
     16    public const DB_PREFIX_PLACEHOLDER = 'DB_PREFIX_';
    1617    private const BACKUP_PATHS_TO_IGNORE = ['wp-content/ai1wm-backups', 'wp-content/backups'];
    1718
     
    263264        if ($current_offset === 0) {
    264265            $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";
    265280            $write_result = file_put_contents(
    266281                $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",
    269285                $file_mode
    270286            );
     
    301317        }
    302318
    303         $sql_content = '';
     319        $sql_content = "START TRANSACTION;\n";
    304320        foreach ($rows as $row) {
    305321            $insert_values = array_map(function ($value) use ($wpdb) {
     
    307323            }, $row);
    308324
    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 ('".
    310327                implode("', '", $insert_values)."');\n";
    311328        }
     329        $sql_content .= "COMMIT;\n\n";
    312330
    313331        $write_result = file_put_contents($backup_file, $sql_content, FILE_APPEND);
  • watchful/tags/v2.0.5/lib/Backup/Utils.php

    r3257611 r3292404  
    44
    55use RuntimeException;
     6use Watchful\Helpers\Files;
    67use WP_Filesystem_Direct;
    78use ZipArchive;
     
    1112    public const BACKUP_DATABASE_FILE_NAME = 'database.sql';
    1213    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
    1323
    1424    public function get_zip_archive(string $backup_id): ZipArchive
     
    7181        }
    7282
    73         $this->add_security_files($backup_dir);
     83        $this->file_helper->add_security_files($backup_dir);
    7484
    7585        return $backup_dir;
     
    102112        }
    103113
    104         $this->add_security_files($backup_dir);
     114        $this->file_helper->add_security_files($backup_dir);
    105115
    106116        return $backup_dir;
    107     }
    108 
    109     private function add_security_files(string $path): void
    110     {
    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         }
    132117    }
    133118
  • watchful/tags/v2.0.5/lib/Helpers/Connection.php

    r3123686 r3292404  
    5757     *                      pass as post data.
    5858     *
    59      * @return false on error | a response object with the following properties
     59     * @return StdClass|false  false on error | a response object with the following properties
    6060     *      - data : raw response
    6161     *      - info : curl info
    6262     *      - error : curl error
    6363     */
    64     public function get_curl($config)
     64    public function get_curl(array $config)
    6565    {
    6666        if (!isset($config['url'])) {
  • watchful/tags/v2.0.5/lib/Helpers/Files.php

    r3123686 r3292404  
    1313namespace Watchful\Helpers;
    1414
     15use RuntimeException;
    1516use Watchful\Audit\Files\Tools;
    1617use Watchful\Exception;
     18use WP_Filesystem_Direct;
    1719
    1820/**
     
    112114        return 200 === $code;
    113115    }
     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    }
    114141}
  • watchful/tags/v2.0.5/lib/Helpers/PluginManager.php

    r3266148 r3292404  
    385385        }
    386386
    387         if (version_compare(phpversion(), $min_php_version) < 0) {
     387        if ($min_php_version && version_compare(phpversion(), $min_php_version) < 0) {
    388388            $this->logger->log('PHP version is too low for this update', [
    389389                'required_version' => $min_php_version,
  • watchful/tags/v2.0.5/lib/Routes.php

    r3243697 r3292404  
    1919use Watchful\Controller\Logs;
    2020use Watchful\Controller\Plugins;
     21use Watchful\Controller\Restore;
    2122use Watchful\Controller\Tests;
    2223use Watchful\Controller\Themes;
     
    9495        $logs = new Logs();
    9596        $logs->register_routes();
     97
     98        $restore = new Restore();
     99        $restore->register_routes();
    96100    }
    97101}
  • watchful/tags/v2.0.5/readme.txt

    r3280129 r3292404  
    8383
    8484== Changelog ==
     85= 2.0.5 =
     86* Implement backup restoration
     87
    8588= v2.0.4 =
    8689* Use the same lock when updating plugins and themes
  • watchful/tags/v2.0.5/watchful.php

    r3266148 r3292404  
    44 * Plugin URI: https://app.watchful.net
    55 * Description: Remote Website Management Plugin by Watchful
    6  * Version: 2.0.4
     6 * Version: 2.0.5
    77 * Author: watchful
    88 * Author URI: https://watchful.net
  • watchful/trunk/lib/Backup/Processor.php

    r3257611 r3292404  
    1414final class Processor
    1515{
     16    public const DB_PREFIX_PLACEHOLDER = 'DB_PREFIX_';
    1617    private const BACKUP_PATHS_TO_IGNORE = ['wp-content/ai1wm-backups', 'wp-content/backups'];
    1718
     
    263264        if ($current_offset === 0) {
    264265            $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";
    265280            $write_result = file_put_contents(
    266281                $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",
    269285                $file_mode
    270286            );
     
    301317        }
    302318
    303         $sql_content = '';
     319        $sql_content = "START TRANSACTION;\n";
    304320        foreach ($rows as $row) {
    305321            $insert_values = array_map(function ($value) use ($wpdb) {
     
    307323            }, $row);
    308324
    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 ('".
    310327                implode("', '", $insert_values)."');\n";
    311328        }
     329        $sql_content .= "COMMIT;\n\n";
    312330
    313331        $write_result = file_put_contents($backup_file, $sql_content, FILE_APPEND);
  • watchful/trunk/lib/Backup/Utils.php

    r3257611 r3292404  
    44
    55use RuntimeException;
     6use Watchful\Helpers\Files;
    67use WP_Filesystem_Direct;
    78use ZipArchive;
     
    1112    public const BACKUP_DATABASE_FILE_NAME = 'database.sql';
    1213    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
    1323
    1424    public function get_zip_archive(string $backup_id): ZipArchive
     
    7181        }
    7282
    73         $this->add_security_files($backup_dir);
     83        $this->file_helper->add_security_files($backup_dir);
    7484
    7585        return $backup_dir;
     
    102112        }
    103113
    104         $this->add_security_files($backup_dir);
     114        $this->file_helper->add_security_files($backup_dir);
    105115
    106116        return $backup_dir;
    107     }
    108 
    109     private function add_security_files(string $path): void
    110     {
    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         }
    132117    }
    133118
  • watchful/trunk/lib/Helpers/Connection.php

    r3123686 r3292404  
    5757     *                      pass as post data.
    5858     *
    59      * @return false on error | a response object with the following properties
     59     * @return StdClass|false  false on error | a response object with the following properties
    6060     *      - data : raw response
    6161     *      - info : curl info
    6262     *      - error : curl error
    6363     */
    64     public function get_curl($config)
     64    public function get_curl(array $config)
    6565    {
    6666        if (!isset($config['url'])) {
  • watchful/trunk/lib/Helpers/Files.php

    r3123686 r3292404  
    1313namespace Watchful\Helpers;
    1414
     15use RuntimeException;
    1516use Watchful\Audit\Files\Tools;
    1617use Watchful\Exception;
     18use WP_Filesystem_Direct;
    1719
    1820/**
     
    112114        return 200 === $code;
    113115    }
     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    }
    114141}
  • watchful/trunk/lib/Helpers/PluginManager.php

    r3266148 r3292404  
    385385        }
    386386
    387         if (version_compare(phpversion(), $min_php_version) < 0) {
     387        if ($min_php_version && version_compare(phpversion(), $min_php_version) < 0) {
    388388            $this->logger->log('PHP version is too low for this update', [
    389389                'required_version' => $min_php_version,
  • watchful/trunk/lib/Routes.php

    r3243697 r3292404  
    1919use Watchful\Controller\Logs;
    2020use Watchful\Controller\Plugins;
     21use Watchful\Controller\Restore;
    2122use Watchful\Controller\Tests;
    2223use Watchful\Controller\Themes;
     
    9495        $logs = new Logs();
    9596        $logs->register_routes();
     97
     98        $restore = new Restore();
     99        $restore->register_routes();
    96100    }
    97101}
  • watchful/trunk/readme.txt

    r3280129 r3292404  
    8383
    8484== Changelog ==
     85= 2.0.5 =
     86* Implement backup restoration
     87
    8588= v2.0.4 =
    8689* Use the same lock when updating plugins and themes
  • watchful/trunk/watchful.php

    r3266148 r3292404  
    44 * Plugin URI: https://app.watchful.net
    55 * Description: Remote Website Management Plugin by Watchful
    6  * Version: 2.0.4
     6 * Version: 2.0.5
    77 * Author: watchful
    88 * Author URI: https://watchful.net
Note: See TracChangeset for help on using the changeset viewer.