/**
  * @param $options
  */
 public function run($options)
 {
     $defaults = array('package' => '', 'destination' => '', 'clear_destination' => false, 'abort_if_destination_exists' => true, 'clear_working' => true, 'is_multi' => false, 'hook_extra' => array());
     $options = wp_parse_args($options, $defaults);
     // Connect to the Filesystem first.
     $res = $this->fs_connect(array(WP_CONTENT_DIR, $options['destination']));
     // Mainly for non-connected filesystem.
     if (!$res) {
         /*if ( ! $options['is_multi'] ) {
               $this->skin->footer();
           }*/
         return false;
     }
     //Download the package (Note, This just returns the filename of the file if the package is a local file)
     if (file_exists($options['package'])) {
         $download = $options['package'];
     } else {
         $download = $this->download_package($options['package']);
     }
     if (is_wp_error($download)) {
         $this->skin->error($download);
         //$this->skin->after();
         return $download;
     }
     $delete_package = $download != $options['package'];
     // Do not delete a "local" file
     //Unzips the file into a temporary directory
     $working_dir = $this->unpack_package($download, $delete_package);
     if (is_wp_error($working_dir)) {
         $this->skin->error($working_dir);
         $this->skin->after();
         return $working_dir;
     }
     $options['source'] = $working_dir;
     $options['package_folder'] = basename($working_dir);
     //With the given options, this installs it to the destination directory.
     $result = $this->install_package(array('source' => $working_dir, 'destination' => $options['destination'], 'clear_destination' => $options['clear_destination'], 'abort_if_destination_exists' => $options['abort_if_destination_exists'], 'clear_working' => $options['clear_working'], 'hook_extra' => $options['hook_extra']));
     $this->skin->set_result($result);
     if (is_wp_error($result)) {
         $this->skin->error($result);
         $this->skin->feedback('process_failed');
     } else {
         //Install Succeeded
         $this->skin->feedback('process_success');
         //update packages xml file
         $result = $this->update_packages_wxr($options);
         if (is_wp_error($result)) {
             $this->skin->error($result);
             $this->skin->feedback('process_failed');
         } else {
             $this->skin->feedback('process_success');
         }
     }
     $this->update_packages_wxr($options);
     $this->skin->feedback('go_manage_page');
     $this->skin->after();
     return $result;
 }
Пример #2
0
	/**
	 * Toggle maintenance mode for the site.
	 *
	 * Creates/deletes the maintenance file to enable/disable maintenance mode.
	 *
	 * @since 2.8.0
	 *
	 * @global WP_Filesystem_Base $wp_filesystem Subclass
	 *
	 * @param bool $enable True to enable maintenance mode, false to disable.
	 */
	public function maintenance_mode( $enable = false ) {
		global $wp_filesystem;
		$file = $wp_filesystem->abspath() . '.maintenance';
		if ( $enable ) {
			$this->skin->feedback('maintenance_start');
			// Create maintenance file to signal that we are upgrading
			$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
			$wp_filesystem->delete($file);
			$wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
		} elseif ( ! $enable && $wp_filesystem->exists( $file ) ) {
			$this->skin->feedback('maintenance_end');
			$wp_filesystem->delete($file);
		}
	}