From d1753e67e6af403138e0f03c1ba830b75e37e501 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 11 Mar 2008 16:37:44 +0000 Subject: [PATCH] Auto update fixes from DD32. see #5586 git-svn-id: http://svn.automattic.com/wordpress/trunk@7238 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-filesystem-direct.php | 4 +-- .../includes/class-wp-filesystem-ftpext.php | 4 +-- .../class-wp-filesystem-ftpsockets.php | 4 +-- wp-admin/includes/file.php | 7 ++--- wp-admin/includes/update.php | 23 ++++++++-------- wp-admin/update.php | 26 ++++++++++++------- 6 files changed, 36 insertions(+), 32 deletions(-) diff --git a/wp-admin/includes/class-wp-filesystem-direct.php b/wp-admin/includes/class-wp-filesystem-direct.php index f783bc574..d698b20d9 100644 --- a/wp-admin/includes/class-wp-filesystem-direct.php +++ b/wp-admin/includes/class-wp-filesystem-direct.php @@ -271,7 +271,7 @@ class WP_Filesystem_Direct{ foreach($filelist as $filename=>$det){ if ( '/' == substr($filename,-1,1) ) $this->rmdir($path.'/'.$filename,$recursive); - @rmdir($entry); + @rmdir($filename); } return @rmdir($path); } @@ -333,4 +333,4 @@ class WP_Filesystem_Direct{ return; } } -?> \ No newline at end of file +?> diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index 89860272c..a8a358505 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -132,7 +132,7 @@ class WP_Filesystem_FTPext{ } function get_contents($file,$type='',$resumepos=0){ if( empty($type) ){ - $extension = substr(strrchr($filename, "."), 1); + $extension = substr(strrchr($file, "."), 1); $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; } $temp = tmpfile(); @@ -348,7 +348,7 @@ class WP_Filesystem_FTPext{ } function rmdir($path,$recursive=false){ if( ! $recursive ) - return @ftp_rmdir($this->link, $file); + return @ftp_rmdir($this->link, $path); //TODO: Recursive Directory delete, Have to delete files from the folder first. //$dir = $this->dirlist($path); diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index 1b4c12104..15ab39076 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -139,7 +139,7 @@ class WP_Filesystem_ftpsockets{ return false; if( empty($type) ){ - $extension = substr(strrchr($filename, "."), 1); + $extension = substr(strrchr($file, "."), 1); $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_AUTOASCII; } $this->ftp->SetType($type); @@ -376,7 +376,7 @@ class WP_Filesystem_ftpsockets{ function rmdir($path,$recursive=false){ if( ! $recursive ) - return $this->ftp->rmdir($file); + return $this->ftp->rmdir($path); return $this->ftp->mdel($path); } diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 0ef2fb4ce..4f5d96b7c 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -231,7 +231,7 @@ function unzip_file($file, $to) { // Is the archive valid? if ( false == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING)) ) - return new WP_Error('incompatible_archive', __('Incompatible archive'), $archive->error_string); + return new WP_Error('incompatible_archive', __('Incompatible archive'), $archive->errorInfo(true)); if ( 0 == count($archive_files) ) return new WP_Error('empty_archive', __('Empty archive')); @@ -240,12 +240,9 @@ function unzip_file($file, $to) { $path = explode('/', $to); $tmppath = ''; for ( $j = 0; $j < count($path) - 1; $j++ ) { - $prevpath = $tmppath; $tmppath .= $path[$j] . '/'; - if ( ! $fs->is_dir($tmppath) ) { - //$fs->setDefaultPermissions( $fs->getchmod($tmppath) ); + if ( ! $fs->is_dir($tmppath) ) $fs->mkdir($tmppath, 0755); - } } foreach ($archive_files as $file) { diff --git a/wp-admin/includes/update.php b/wp-admin/includes/update.php index edfd0f7c5..461c93457 100644 --- a/wp-admin/includes/update.php +++ b/wp-admin/includes/update.php @@ -127,7 +127,7 @@ function wp_plugin_update_row( $file ) { $r = $current->response[ $file ]; echo ""; - printf( __('There is a new version of %1$s available. Download version %3$s here or upgrade automatically.'), $plugin_data['Name'], $r->url, $r->new_version, "update.php?action=upgrade-plugin&plugin=$file" ); + printf( __('There is a new version of %1$s available. Download version %3$s here or upgrade automatically.'), $plugin_data['Name'], $r->url, $r->new_version, wp_nonce_url("update.php?action=upgrade-plugin&plugin=$file", 'upgrade-plugin_' . $file) ); echo ""; } add_action( 'after_plugin_row', 'wp_plugin_update_row' ); @@ -167,20 +167,19 @@ function wp_update_plugin($plugin, $feedback = '') { // Download the package $package = $r->package; - apply_filters('update_feedback', sprintf(__("Downloading update from %s"), $package)); + apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); $file = download_url($package); if ( !$file ) return new WP_Error('download_failed', __('Download failed.')); - $name = basename($plugin, '.php'); - $working_dir = $base . 'wp-content/upgrade/' . $name; + $working_dir = $base . 'wp-content/upgrade/' . basename($plugin, '.php'); // Clean up working directory - if ( is_dir($working_dir) ) + if ( $wp_filesystem->is_dir($working_dir) ) $wp_filesystem->delete($working_dir, true); - apply_filters('update_feedback', __("Unpacking the update")); + apply_filters('update_feedback', __('Unpacking the update')); // Unzip package to working directory $result = unzip_file($file, $working_dir); if ( is_wp_error($result) ) { @@ -193,23 +192,25 @@ function wp_update_plugin($plugin, $feedback = '') { unlink($file); // Remove the existing plugin. - apply_filters('update_feedback', __("Removing the old version of the plugin")); + apply_filters('update_feedback', __('Removing the old version of the plugin')); $plugin_dir = dirname($base . PLUGINDIR . "/$plugin"); $plugin_dir = trailingslashit($plugin_dir); + // If plugin is in its own directory, recursively delete the directory. - if( ! in_array( $plugin_dir, array('.', trailingslashit($base . PLUGINDIR) ) ) ) + if( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' ) $deleted = $wp_filesystem->delete($plugin_dir, true); else $deleted = $wp_filesystem->delete($base . PLUGINDIR . "/$plugin"); + if ( !$deleted ) { $wp_filesystem->delete($working_dir, true); return new WP_Error('delete_failed', __('Could not remove the old plugin')); } - apply_filters('update_feedback', __("Installing the latest version")); + apply_filters('update_feedback', __('Installing the latest version')); // Copy new version of plugin into place. if ( !copy_dir($working_dir, $base . PLUGINDIR) ) { - //$wp_filesystem->delete($working_dir, true); + //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails. return new WP_Error('install_failed', __('Installation failed')); } @@ -220,4 +221,4 @@ function wp_update_plugin($plugin, $feedback = '') { delete_option('update_plugins'); } -?> +?> \ No newline at end of file diff --git a/wp-admin/update.php b/wp-admin/update.php index e0a599f85..b0473844b 100644 --- a/wp-admin/update.php +++ b/wp-admin/update.php @@ -5,14 +5,14 @@ require_once('admin.php'); if ( !current_user_can('edit_plugins') ) wp_die('

'.__('You do not have sufficient permissions to update plugins for this blog.').'

'); -function request_filesystem_credentials($form_post, $type = '') { +function request_filesystem_credentials($form_post, $type = '', $error = false) { if ( empty($type) ) $type = get_filesystem_method(); if ( 'direct' == $type ) return array(); - if ( !empty($_POST['password']) && !empty($_POST['username']) && !empty($_POST['hostname']) ) { + if ( ! $error && !empty($_POST['password']) && !empty($_POST['username']) && !empty($_POST['hostname']) ) { $credentials = array('hostname' => $_POST['hostname'], 'username' => $_POST['username'], 'password' => $_POST['password'], 'ssl' => $_POST['ssl']); $stored_credentials = $credentials; @@ -26,6 +26,9 @@ function request_filesystem_credentials($form_post, $type = '') { $ssl = ''; if ( $credentials = get_option('ftp_credentials') ) extract($credentials, EXTR_OVERWRITE); + if( $error ){ + echo '

' . __('Error: There was an error connecting to the server, Please verify the settings are correct.') . '

'; + } ?>
@@ -42,7 +45,7 @@ function request_filesystem_credentials($form_post, $type = '') { - + @@ -80,13 +83,17 @@ function show_message($message) { function do_plugin_upgrade($plugin) { global $wp_filesystem; - $credentials = request_filesystem_credentials("update.php?action=upgrade-plugin&plugin=$plugin"); - if ( false === $credentials ) + $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin"); + if ( false === ($credentials = request_filesystem_credentials($url)) ) return; + + if( ! WP_Filesystem($credentials) ){ + request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again + return; + } + echo '
'; echo '

' . __('Upgrade Plugin') . '

'; - WP_Filesystem($credentials); - // TODO: look for auth and connect error codes and direct back to credentials form. if ( $wp_filesystem->errors->get_error_code() ) { foreach ( $wp_filesystem->errors->get_error_messages() as $message ) show_message($message); @@ -108,14 +115,13 @@ if ( isset($_GET['action']) ) { $plugin = trim($_GET['plugin']); if ( 'upgrade-plugin' == $_GET['action'] ) { - //check-admin_referer('upgrade-plugin_' . $plugin); + check_admin_referer('upgrade-plugin_' . $plugin); $title = __('Upgrade Plugin'); $parent_file = 'plugins.php'; require_once('admin-header.php'); do_plugin_upgrade($plugin); include('admin-footer.php'); } - } -?> \ No newline at end of file +?>