Make WordPress Core

Ticket #31138: backup_package_class-wp-upgrader.patch

File backup_package_class-wp-upgrader.patch, 4.2 KB (added by aercolino, 10 years ago)
  • ../../../wp-admin/includes/class-wp-upgrader.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    410410                }
    411411
    412412                if ( $clear_destination ) {
    413                         //We're going to clear the destination if there's something there
    414                         $this->skin->feedback('remove_old');
    415413                        $removed = true;
    416414                        if ( $wp_filesystem->exists( $remote_destination ) ) {
     415                                // Backup everything.
     416                                $this->skin->feedback('backup_old');
     417                                $type = $args['hook_extra']['type'];
     418                                if ($this->backup_package( $remote_destination, $type, $backup_name, $backup_dir )) {
     419                                        $this->backup_set_transient( $remote_destination, $type, $backup_name, $backup_dir );
     420                                }
     421                                // Remove everything.
     422                                $this->skin->feedback('remove_old');
    417423                                $removed = $wp_filesystem->delete( $remote_destination, true );
    418424                        }
    419425
     
    643649                }
    644650        }
    645651
    646 }
     652        /**
     653         * Backup all files and directories (recursively) in the package_dir.
     654         *
     655         * @see backup_prefix
     656         *
     657         * @param string $package_dir The plugin/theme directory.
     658         * @param string $type        'plugin' or 'theme'.
     659         * @param string $backup_name The unique name of this backup. Used or defaulted.
     660         * @param string $backup_dir  The unique directory of this backup. Used or defaulted.
     661         *
     662         * @return true|WP_Error
     663         */
     664        protected function backup_package( $package_dir, $type, &$backup_name, &$backup_dir ) {
     665                if (is_null($backup_name)) {
     666                        $backup_prefix = backup_prefix( $package_dir, $type );
     667                        $backup_name = uniqid($backup_prefix);  // eg: 'backup_p_akismet_54c3c6107485f'
     668                }
     669                if (is_null($backup_dir)) {
     670//                      $backup_dir = get_temp_dir() . $backup_name;
     671                        $backup_dir = WP_CONTENT_DIR . '/tmp/' . $backup_name;
     672                }
     673                wp_mkdir_p($backup_dir);
     674                $result = copy_dir($package_dir, $backup_dir);
     675                return $result;
     676        }
    647677
    648 /**
     678        /**
     679         * Set backup data in a transient.
     680         *
     681         * @see backup_prefix
     682         *
     683         * @param string $package_dir The plugin/theme directory.
     684         * @param string $type        'plugin' or 'theme'.
     685         * @param string $backup_name The unique name of this backup.
     686         * @param string $backup_dir  The unique directory of this backup.
     687         */
     688        protected function backup_set_transient( $package_dir, $type, $backup_name, $backup_dir ) {
     689                $package_file = $type == 'plugin'
     690                                ? $package_dir . basename($package_dir) . '.php'
     691                                : $package_dir . 'style.css';
     692                $headers = get_file_data( $package_file, array('Version' => 'Version'), $type );
     693                $backup_data = array(
     694                        'package_dir' => $package_dir,
     695                        'package_ver' => $headers['Version'],
     696                        'backup_dir'  => $backup_dir,
     697                        'backup_date' => date('Y-m-d H:i:s'),
     698                );
     699                set_transient($backup_name, $backup_data, 1 * WEEK_IN_SECONDS);
     700        }
     701}
     702
     703/**
    649704 * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file.
    650705 *
    651706 * @package WordPress
     
    681736                $this->strings['no_package'] = __('Update package not available.');
    682737                $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;');
    683738                $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
     739                $this->strings['backup_old'] = __('Backing up the old version of the plugin&#8230;');
    684740                $this->strings['remove_old'] = __('Removing the old version of the plugin&#8230;');
    685741                $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
    686742                $this->strings['process_failed'] = __('Plugin update failed.');
     
    11151171                $this->strings['no_package'] = __('Update package not available.');
    11161172                $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>&#8230;');
    11171173                $this->strings['unpack_package'] = __('Unpacking the update&#8230;');
     1174                $this->strings['backup_old'] = __('Backing up the old version of the theme&#8230;');
    11181175                $this->strings['remove_old'] = __('Removing the old version of the theme&#8230;');
    11191176                $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
    11201177                $this->strings['process_failed'] = __('Theme update failed.');