Example #1
0
 function upgrade($current)
 {
     global $wp_filesystem;
     $this->init();
     $this->upgrade_strings();
     if (!empty($feedback)) {
         add_filter('update_feedback', $feedback);
     }
     // Is an update available?
     if (!isset($current->response) || $current->response == 'latest') {
         return new WP_Error('up_to_date', $this->strings['up_to_date']);
     }
     $res = $this->fs_connect(array(ABSPATH, WP_CONTENT_DIR));
     if (is_wp_error($res)) {
         return $res;
     }
     $wp_dir = trailingslashit($wp_filesystem->abspath());
     $download = $this->download_package($current->package);
     if (is_wp_error($download)) {
         return $download;
     }
     $working_dir = $this->unpack_package($download);
     if (is_wp_error($working_dir)) {
         return $working_dir;
     }
     // Copy update-core.php from the new version into place.
     if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
         $wp_filesystem->delete($working_dir, true);
         return new WP_Error('copy_failed', $this->strings['copy_failed']);
     }
     $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
     require ABSPATH . 'wp-admin/includes/update-core.php';
     return update_core($working_dir, $wp_dir);
 }
    if ($arg == '--all') {
        $all = true;
    } elseif ($arg == "--core") {
        $core = true;
    } elseif ($arg == "--plugins") {
        $allplugins = true;
    } elseif (substr($arg, 0, 9) == "--plugin=") {
        $plugins[] = substr($arg, 9);
    } elseif ($arg == '--help') {
        echo "options: --all --core --plugins --plugin=Foo\n\n";
        exit(0);
    }
}
if ($all || $core) {
    echo "core...";
    update_core(INSTALLDIR, 'statusnet');
    echo " ok\n";
}
if ($all || $allplugins) {
    $plugins = get_plugins(INSTALLDIR);
}
if ($plugins) {
    foreach ($plugins as $plugin) {
        echo "{$plugin}...";
        if (update_plugin(INSTALLDIR, $plugin)) {
            echo " ok\n";
        } else {
            echo " not localized\n";
        }
    }
}
 /**
  * Upgrade WordPress core.
  *
  * @since 2.8.0
  *
  * @param object $current Response object for whether WordPress is current.
  * @param array  $args {
  *        Optional. Arguments for upgrading WordPress core. Default empty array.
  *
  *        @type bool $pre_check_md5    Whether to check the file checksums before
  *                                     attempting the upgrade. Default true.
  *        @type bool $attempt_rollback Whether to attempt to rollback the chances if
  *                                     there is a problem. Default false.
  *        @type bool $do_rollback      Whether to perform this "upgrade" as a rollback.
  *                                     Default false.
  * }
  * @return null|false|WP_Error False or WP_Error on failure, null on success.
  */
 public function upgrade($current, $args = array())
 {
     global $wp_filesystem;
     include ABSPATH . WPINC . '/version.php';
     // $wp_version;
     $start_time = time();
     $defaults = array('pre_check_md5' => true, 'attempt_rollback' => false, 'do_rollback' => false, 'allow_relaxed_file_ownership' => false);
     $parsed_args = wp_parse_args($args, $defaults);
     $this->init();
     $this->upgrade_strings();
     // Is an update available?
     if (!isset($current->response) || $current->response == 'latest') {
         return new WP_Error('up_to_date', $this->strings['up_to_date']);
     }
     $res = $this->fs_connect(array(ABSPATH, WP_CONTENT_DIR), $parsed_args['allow_relaxed_file_ownership']);
     if (!$res || is_wp_error($res)) {
         return $res;
     }
     $wp_dir = trailingslashit($wp_filesystem->abspath());
     $partial = true;
     if ($parsed_args['do_rollback']) {
         $partial = false;
     } elseif ($parsed_args['pre_check_md5'] && !$this->check_files()) {
         $partial = false;
     }
     /*
      * If partial update is returned from the API, use that, unless we're doing
      * a reinstall. If we cross the new_bundled version number, then use
      * the new_bundled zip. Don't though if the constant is set to skip bundled items.
      * If the API returns a no_content zip, go with it. Finally, default to the full zip.
      */
     if ($parsed_args['do_rollback'] && $current->packages->rollback) {
         $to_download = 'rollback';
     } elseif ($current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial) {
         $to_download = 'partial';
     } elseif ($current->packages->new_bundled && version_compare($wp_version, $current->new_bundled, '<') && (!defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || !CORE_UPGRADE_SKIP_NEW_BUNDLED)) {
         $to_download = 'new_bundled';
     } elseif ($current->packages->no_content) {
         $to_download = 'no_content';
     } else {
         $to_download = 'full';
     }
     $download = $this->download_package($current->packages->{$to_download});
     if (is_wp_error($download)) {
         return $download;
     }
     $working_dir = $this->unpack_package($download);
     if (is_wp_error($working_dir)) {
         return $working_dir;
     }
     // Copy update-core.php from the new version into place.
     if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
         $wp_filesystem->delete($working_dir, true);
         return new WP_Error('copy_failed_for_update_core_file', __('The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.'), 'wp-admin/includes/update-core.php');
     }
     $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
     require_once ABSPATH . 'wp-admin/includes/update-core.php';
     if (!function_exists('update_core')) {
         return new WP_Error('copy_failed_space', $this->strings['copy_failed_space']);
     }
     $result = update_core($working_dir, $wp_dir);
     // In the event of an issue, we may be able to roll back.
     if ($parsed_args['attempt_rollback'] && $current->packages->rollback && !$parsed_args['do_rollback']) {
         $try_rollback = false;
         if (is_wp_error($result)) {
             $error_code = $result->get_error_code();
             /*
              * Not all errors are equal. These codes are critical: copy_failed__copy_dir,
              * mkdir_failed__copy_dir, copy_failed__copy_dir_retry, and disk_full.
              * do_rollback allows for update_core() to trigger a rollback if needed.
              */
             if (false !== strpos($error_code, 'do_rollback')) {
                 $try_rollback = true;
             } elseif (false !== strpos($error_code, '__copy_dir')) {
                 $try_rollback = true;
             } elseif ('disk_full' === $error_code) {
                 $try_rollback = true;
             }
         }
         if ($try_rollback) {
             /** This filter is documented in wp-admin/includes/update-core.php */
             apply_filters('update_feedback', $result);
             /** This filter is documented in wp-admin/includes/update-core.php */
             apply_filters('update_feedback', $this->strings['start_rollback']);
             $rollback_result = $this->upgrade($current, array_merge($parsed_args, array('do_rollback' => true)));
             $original_result = $result;
             $result = new WP_Error('rollback_was_required', $this->strings['rollback_was_required'], (object) array('update' => $original_result, 'rollback' => $rollback_result));
         }
     }
     /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
     do_action('upgrader_process_complete', $this, array('action' => 'update', 'type' => 'core'));
     // Clear the current updates
     delete_site_transient('update_core');
     if (!$parsed_args['do_rollback']) {
         $stats = array('update_type' => $current->response, 'success' => true, 'fs_method' => $wp_filesystem->method, 'fs_method_forced' => defined('FS_METHOD') || has_filter('filesystem_method'), 'fs_method_direct' => !empty($GLOBALS['_wp_filesystem_direct_method']) ? $GLOBALS['_wp_filesystem_direct_method'] : '', 'time_taken' => time() - $start_time, 'reported' => $wp_version, 'attempted' => $current->version);
         if (is_wp_error($result)) {
             $stats['success'] = false;
             // Did a rollback occur?
             if (!empty($try_rollback)) {
                 $stats['error_code'] = $original_result->get_error_code();
                 $stats['error_data'] = $original_result->get_error_data();
                 // Was the rollback successful? If not, collect its error too.
                 $stats['rollback'] = !is_wp_error($rollback_result);
                 if (is_wp_error($rollback_result)) {
                     $stats['rollback_code'] = $rollback_result->get_error_code();
                     $stats['rollback_data'] = $rollback_result->get_error_data();
                 }
             } else {
                 $stats['error_code'] = $result->get_error_code();
                 $stats['error_data'] = $result->get_error_data();
             }
         }
         wp_version_check($stats);
     }
     return $result;
 }
Example #4
0
function wp_update_core($current, $feedback = '')
{
    if (!is_site_admin()) {
        return;
    }
    global $wp_filesystem;
    @set_time_limit(300);
    if (!empty($feedback)) {
        add_filter('update_feedback', $feedback);
    }
    // Is an update available?
    if (!isset($current->response) || $current->response == 'latest') {
        return new WP_Error('up_to_date', __('WordPress is at the latest version.'));
    }
    // Is a filesystem accessor setup?
    if (!$wp_filesystem || !is_object($wp_filesystem)) {
        WP_Filesystem();
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if ($wp_filesystem->errors->get_error_code()) {
        return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
    }
    // Get the base WP folder
    $wp_dir = $wp_filesystem->abspath();
    if (empty($wp_dir)) {
        return new WP_Error('fs_no_wp_dir', __('Unable to locate WordPress directory.'));
    }
    // And the same for the Content directory.
    $content_dir = $wp_filesystem->wp_content_dir();
    if (empty($content_dir)) {
        return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
    }
    $wp_dir = trailingslashit($wp_dir);
    $content_dir = trailingslashit($content_dir);
    // Get the URL to the zip file
    $package = $current->package;
    // Download the package
    apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));
    $download_file = download_url($package);
    if (is_wp_error($download_file)) {
        return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());
    }
    $working_dir = $content_dir . 'upgrade/core';
    // Clean up working directory
    if ($wp_filesystem->is_dir($working_dir)) {
        $wp_filesystem->delete($working_dir, true);
    }
    apply_filters('update_feedback', __('Unpacking the core update'));
    // Unzip package to working directory
    $result = unzip_file($download_file, $working_dir);
    // Once extracted, delete the package
    unlink($download_file);
    if (is_wp_error($result)) {
        $wp_filesystem->delete($working_dir, true);
        return $result;
    }
    // Copy update-core.php from the new version into place.
    if (!$wp_filesystem->copy($working_dir . '/wordpress-mu/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
        $wp_filesystem->delete($working_dir, true);
        return new WP_Error('copy_failed', __('Could not copy files'));
    }
    $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
    require ABSPATH . 'wp-admin/includes/update-core.php';
    return update_core($working_dir, $wp_dir);
}
 function upgrade($current)
 {
     global $wp_filesystem, $wp_version;
     $this->init();
     $this->upgrade_strings();
     if (!empty($feedback)) {
         add_filter('update_feedback', $feedback);
     }
     // Is an update available?
     if (!isset($current->response) || $current->response == 'latest') {
         return new WP_Error('up_to_date', $this->strings['up_to_date']);
     }
     $res = $this->fs_connect(array(ABSPATH, WP_CONTENT_DIR));
     if (is_wp_error($res)) {
         return $res;
     }
     $wp_dir = trailingslashit($wp_filesystem->abspath());
     // If partial update is returned from the API, use that, unless we're doing a reinstall.
     // If we cross the new_bundled version number, then use the new_bundled zip.
     // Don't though if the constant is set to skip bundled items.
     // If the API returns a no_content zip, go with it. Finally, default to the full zip.
     if ($current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version) {
         $to_download = 'partial';
     } elseif ($current->packages->new_bundled && version_compare($wp_version, $current->new_bundled, '<') && (!defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || !CORE_UPGRADE_SKIP_NEW_BUNDLED)) {
         $to_download = 'new_bundled';
     } elseif ($current->packages->no_content) {
         $to_download = 'no_content';
     } else {
         $to_download = 'full';
     }
     $download = $this->download_package($current->packages->{$to_download});
     if (is_wp_error($download)) {
         return $download;
     }
     $working_dir = $this->unpack_package($download);
     if (is_wp_error($working_dir)) {
         return $working_dir;
     }
     // Copy update-core.php from the new version into place.
     if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
         $wp_filesystem->delete($working_dir, true);
         return new WP_Error('copy_failed', $this->strings['copy_failed']);
     }
     $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
     require ABSPATH . 'wp-admin/includes/update-core.php';
     return update_core($working_dir, $wp_dir);
 }
 function upgrade($current, $args = array())
 {
     global $wp_filesystem, $wp_version;
     $defaults = array('pre_check_md5' => true, 'attempt_rollback' => false, 'do_rollback' => false);
     $parsed_args = wp_parse_args($args, $defaults);
     $this->init();
     $this->upgrade_strings();
     // Is an update available?
     if (!isset($current->response) || $current->response == 'latest') {
         return new WP_Error('up_to_date', $this->strings['up_to_date']);
     }
     $res = $this->fs_connect(array(ABSPATH, WP_CONTENT_DIR));
     if (is_wp_error($res)) {
         return $res;
     }
     $wp_dir = trailingslashit($wp_filesystem->abspath());
     // Pre-cache the checksums for the versions we care about
     get_core_checksums(array($wp_version, $current->version));
     $partial = true;
     if ($parsed_args['do_rollback']) {
         $partial = false;
     } elseif ($parsed_args['pre_check_md5'] && !$this->check_files()) {
         $partial = false;
     }
     // If partial update is returned from the API, use that, unless we're doing a reinstall.
     // If we cross the new_bundled version number, then use the new_bundled zip.
     // Don't though if the constant is set to skip bundled items.
     // If the API returns a no_content zip, go with it. Finally, default to the full zip.
     if ($parsed_args['do_rollback'] && $current->packages->rollback) {
         $to_download = 'rollback';
     } elseif ($current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial) {
         $to_download = 'partial';
     } elseif ($current->packages->new_bundled && version_compare($wp_version, $current->new_bundled, '<') && (!defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || !CORE_UPGRADE_SKIP_NEW_BUNDLED)) {
         $to_download = 'new_bundled';
     } elseif ($current->packages->no_content) {
         $to_download = 'no_content';
     } else {
         $to_download = 'full';
     }
     $download = $this->download_package($current->packages->{$to_download});
     if (is_wp_error($download)) {
         return $download;
     }
     $working_dir = $this->unpack_package($download);
     if (is_wp_error($working_dir)) {
         return $working_dir;
     }
     // Copy update-core.php from the new version into place.
     if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
         $wp_filesystem->delete($working_dir, true);
         return new WP_Error('copy_failed', $this->strings['copy_failed']);
     }
     $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
     require_once ABSPATH . 'wp-admin/includes/update-core.php';
     if (!function_exists('update_core')) {
         return new WP_Error('copy_failed_space', $this->strings['copy_failed_space']);
     }
     $result = update_core($working_dir, $wp_dir);
     // In the event of an error, rollback to the previous version
     if (is_wp_error($result) && $parsed_args['attempt_rollback'] && $current->packages->rollback) {
         apply_filters('update_feedback', $result);
         apply_filters('update_feedback', $this->strings['start_rollback']);
         $this->upgrade($current, array_merge($parsed_args, array('do_rollback' => true)));
         $result = new WP_Error('rollback_was_required', $this->strings['rollback_was_required']);
     }
     do_action('upgrader_process_complete', $this, array('action' => 'update', 'type' => 'core'), $result);
     return $result;
 }
/** main entry point for update wizard (called from /program/main_admin.php)
 *
 * This routine takes care of executing update routines for both the core
 * program and modules, themes, etc. It is called automagically whenever
 * the core program version in the database is different from the version
 * in the file {@lnk version.php} (see also {@link main_admin()}).
 *
 * It can also be called manually via 'job=update'. When no specific
 * task is specified, this routine shows the overview of versions for
 * core, modules, themes, etc. Whenever a component is NOT up to date,
 * an [Update] button is displayed. If a component IS up to date, we
 * simply display the word 'OK'. This implies that when everything is up
 * to date, the overview simply displays a list of OK's and the user
 * is 'free to go'.
 *
 * The actual updates for modules, themes, etc. is done via the various
 * subsystems themselves, e.g. by calling htmlpage_upgrade() in the file
 * /program/modules/htmlpage/htmlpage_install.php. The updates for the
 * core program are actually performed from this file right here, see
 * {@link update_core_2010120800()} below for an example.
 *
 * Note that we give a core update high priority: if the core
 * is not up to date, nothing will work, except updating the core.
 *
 * @param object &$output collects the html output
 * @return void results are returned as output in $output
 */
function job_update(&$output)
{
    global $CFG, $WAS_SCRIPT_NAME, $USER;
    $output->set_helptopic('update');
    $task = get_parameter_string('task', TASK_UPDATE_OVERVIEW);
    if ($task == TASK_UPDATE_OVERVIEW) {
        update_show_overview($output);
    } elseif ($task == TASK_UPDATE_CORE) {
        update_core($output);
        update_show_overview($output);
    } elseif (intval($CFG->version) != intval(WAS_VERSION)) {
        $output->add_message(t('update_core_warnning_core_goes_first', 'admin'));
        update_show_overview($output);
    } else {
        $key = get_parameter_string('key', '');
        switch ($task) {
            case TASK_INSTALL_LANGUAGE:
                install_language($output, $key);
                update_show_overview($output);
                break;
            case TASK_UPDATE_LANGUAGE:
                update_language($output, $key);
                update_show_overview($output);
                break;
            case TASK_INSTALL_MODULE:
                install_module($output, $key);
                update_show_overview($output);
                break;
            case TASK_UPDATE_MODULE:
                update_module($output, $key);
                update_show_overview($output);
                break;
            case TASK_INSTALL_THEME:
                install_theme($output, $key);
                update_show_overview($output);
                break;
            case TASK_UPDATE_THEME:
                update_theme($output, $key);
                update_show_overview($output);
                break;
            default:
                $s = utf8_strlen($task) <= 50 ? $task : utf8_substr($task, 0, 44) . ' (...)';
                $message = t('task_unknown', 'admin', array('{TASK}' => htmlspecialchars($s)));
                $output->add_message($message);
                logger('tools: unknown task: ' . htmlspecialchars($s));
                update_show_overview($output);
                break;
        }
    }
}
Example #8
0
 /**
  * Upgrades WordPress locally
  */
 public function upgrade_core($current)
 {
     ob_start();
     if (file_exists(ABSPATH . '/wp-admin/includes/update.php')) {
         include_once ABSPATH . '/wp-admin/includes/update.php';
     }
     @wp_version_check();
     $current_update = false;
     ob_end_flush();
     ob_end_clean();
     $core = $this->mmb_get_transient('update_core');
     if (isset($core->updates) && !empty($core->updates)) {
         $updates = $core->updates[0];
         $updated = $core->updates[0];
         if (!isset($updated->response) || $updated->response == 'latest') {
             return array('upgraded' => ' updated');
         }
         if ($updated->response == "development" && $current['response'] == "upgrade") {
             return array('error' => '<font color="#900">Unexpected error. Please upgrade manually.</font>');
         } else {
             if ($updated->response == $current['response'] || $updated->response == "upgrade" && $current['response'] == "development") {
                 if ($updated->locale != $current['locale']) {
                     foreach ($updates as $update) {
                         if ($update->locale == $current['locale']) {
                             $current_update = $update;
                             break;
                         }
                     }
                     if ($current_update == false) {
                         return array('error' => ' Localization mismatch. Try again.');
                     }
                 } else {
                     $current_update = $updated;
                 }
             } else {
                 return array('error' => ' Transient mismatch. Try again.');
             }
         }
     } else {
         return array('error' => ' Refresh transient failed. Try again.');
     }
     if ($current_update != false) {
         global $wp_filesystem, $wp_version;
         if (version_compare($wp_version, '3.1.9', '>')) {
             if (!class_exists('Core_Upgrader')) {
                 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
             }
             /** @handled class */
             $core = new Core_Upgrader(mwp_container()->getUpdaterSkin());
             $result = $core->upgrade($current_update);
             $this->mmb_maintenance_mode(false);
             if (is_wp_error($result)) {
                 return array('error' => $this->mmb_get_error($result));
             } else {
                 return array('upgraded' => ' updated');
             }
         } else {
             if (!class_exists('WP_Upgrader')) {
                 include_once ABSPATH . 'wp-admin/includes/update.php';
                 if (function_exists('wp_update_core')) {
                     $result = wp_update_core($current_update);
                     if (is_wp_error($result)) {
                         return array('error' => $this->mmb_get_error($result));
                     } else {
                         return array('upgraded' => ' updated');
                     }
                 }
             }
             if (class_exists('WP_Upgrader')) {
                 /** @handled class */
                 $upgrader_skin = new WP_Upgrader_Skin();
                 $upgrader_skin->done_header = true;
                 /** @handled class */
                 $upgrader = new WP_Upgrader($upgrader_skin);
                 // Is an update available?
                 if (!isset($current_update->response) || $current_update->response == 'latest') {
                     return array('upgraded' => ' updated');
                 }
                 $res = $upgrader->fs_connect(array(ABSPATH, WP_CONTENT_DIR));
                 if (is_wp_error($res)) {
                     return array('error' => $this->mmb_get_error($res));
                 }
                 $wp_dir = trailingslashit($wp_filesystem->abspath());
                 $core_package = false;
                 if (isset($current_update->package) && !empty($current_update->package)) {
                     $core_package = $current_update->package;
                 } elseif (isset($current_update->packages->full) && !empty($current_update->packages->full)) {
                     $core_package = $current_update->packages->full;
                 }
                 $download = $upgrader->download_package($core_package);
                 if (is_wp_error($download)) {
                     return array('error' => $this->mmb_get_error($download));
                 }
                 $working_dir = $upgrader->unpack_package($download);
                 if (is_wp_error($working_dir)) {
                     return array('error' => $this->mmb_get_error($working_dir));
                 }
                 if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
                     $wp_filesystem->delete($working_dir, true);
                     return array('error' => 'Unable to move update files.');
                 }
                 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
                 require ABSPATH . 'wp-admin/includes/update-core.php';
                 $update_core = update_core($working_dir, $wp_dir);
                 ob_end_clean();
                 $this->mmb_maintenance_mode(false);
                 if (is_wp_error($update_core)) {
                     return array('error' => $this->mmb_get_error($update_core));
                 }
                 ob_end_flush();
                 return array('upgraded' => 'updated');
             } else {
                 return array('error' => 'failed');
             }
         }
     } else {
         return array('error' => 'failed');
     }
 }
Example #9
0
 function upgrade_core($current, $userid)
 {
     global $iwp_activities_log_post_type, $iwp_mmb_activities_log;
     ob_start();
     if (!function_exists('wp_version_check') || !function_exists('get_core_checksums')) {
         include_once ABSPATH . '/wp-admin/includes/update.php';
     }
     @wp_version_check();
     $current_update = false;
     ob_end_flush();
     ob_end_clean();
     $core = $this->iwp_mmb_get_transient('update_core');
     if (isset($core->updates) && !empty($core->updates)) {
         $updates = $core->updates[0];
         $updated = $core->updates[0];
         if (!isset($updated->response) || $updated->response == 'latest') {
             return array('upgraded' => 'updated');
         }
         if ($updated->response == "development" && $current->response == "upgrade") {
             return array('error' => '<font color="#900">Unexpected error. Please upgrade manually.</font>', 'error_code' => 'unexpected_error_please_upgrade_manually');
         } else {
             if ($updated->response == $current->response || $updated->response == "upgrade" && $current->response == "development") {
                 if ($updated->locale != $current->locale) {
                     foreach ($updates as $update) {
                         if ($update->locale == $current->locale) {
                             $current_update = $update;
                             break;
                         }
                     }
                     if ($current_update == false) {
                         return array('error' => ' Localization mismatch. Try again.', 'error_code' => 'localization_mismatch');
                     }
                 } else {
                     $current_update = $updated;
                 }
             } else {
                 return array('error' => ' Transient mismatch. Try again.', 'error_code' => 'transient_mismatch');
             }
         }
     } else {
         return array('error' => ' Refresh transient failed. Try again.', 'error_code' => 'refresh_transient_failed');
     }
     if ($current_update != false) {
         global $iwp_mmb_wp_version, $wp_filesystem, $wp_version;
         if (version_compare($wp_version, '3.1.9', '>')) {
             if (!class_exists('Core_Upgrader')) {
                 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
             }
             $core = new Core_Upgrader();
             $result = $core->upgrade($current_update);
             $this->iwp_mmb_maintenance_mode(false);
             if (is_wp_error($result)) {
                 return array('error' => $this->iwp_mmb_get_error($result), 'error_code' => 'maintenance_mode_upgrade_core');
             } else {
                 $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('core', 'update', $iwp_activities_log_post_type, $current, $userid);
                 return array('upgraded' => 'updated');
             }
         } else {
             if (!class_exists('WP_Upgrader')) {
                 include_once ABSPATH . 'wp-admin/includes/update.php';
                 if (function_exists('wp_update_core')) {
                     $result = wp_update_core($current_update);
                     if (is_wp_error($result)) {
                         return array('error' => $this->iwp_mmb_get_error($result), 'error_code' => 'wp_update_core_upgrade_core');
                     } else {
                         $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('core', 'update', $iwp_activities_log_post_type, $current, $userid);
                         return array('upgraded' => 'updated');
                     }
                 }
             }
             if (class_exists('WP_Upgrader')) {
                 $upgrader_skin = new WP_Upgrader_Skin();
                 $upgrader_skin->done_header = true;
                 $upgrader = new WP_Upgrader($upgrader_skin);
                 // Is an update available?
                 if (!isset($current_update->response) || $current_update->response == 'latest') {
                     return array('upgraded' => 'updated');
                 }
                 $res = $upgrader->fs_connect(array(ABSPATH, WP_CONTENT_DIR));
                 if (is_wp_error($res)) {
                     return array('error' => $this->iwp_mmb_get_error($res), 'error_code' => 'upgrade_core_wp_error_res');
                 }
                 $wp_dir = trailingslashit($wp_filesystem->abspath());
                 $core_package = false;
                 if (isset($current_update->package) && !empty($current_update->package)) {
                     $core_package = $current_update->package;
                 } elseif (isset($current_update->packages->full) && !empty($current_update->packages->full)) {
                     $core_package = $current_update->packages->full;
                 }
                 $download = $upgrader->download_package($core_package);
                 if (is_wp_error($download)) {
                     return array('error' => $this->iwp_mmb_get_error($download), 'error_code' => 'download_upgrade_core');
                 }
                 $working_dir = $upgrader->unpack_package($download);
                 if (is_wp_error($working_dir)) {
                     return array('error' => $this->iwp_mmb_get_error($working_dir), 'error_code' => 'working_dir_upgrade_core');
                 }
                 if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
                     $wp_filesystem->delete($working_dir, true);
                     return array('error' => 'Unable to move update files.', 'error_code' => 'unable_to_move_update_files');
                 }
                 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
                 require ABSPATH . 'wp-admin/includes/update-core.php';
                 $update_core = update_core($working_dir, $wp_dir);
                 ob_end_clean();
                 $this->iwp_mmb_maintenance_mode(false);
                 if (is_wp_error($update_core)) {
                     return array('error' => $this->iwp_mmb_get_error($update_core), 'error_code' => 'upgrade_core_wp_error');
                 }
                 ob_end_flush();
                 $iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('core', 'update', $iwp_activities_log_post_type, $current, $userid);
                 return array('upgraded' => 'updated');
             } else {
                 return array('error' => 'failed', 'error_code' => 'failed_WP_Upgrader_class_not_exists');
             }
         }
     } else {
         return array('error' => 'failed', 'error_code' => 'failed_current_update_false');
     }
 }
Example #10
0
<?php

if (strcmp(PHP_SAPI, 'cli') !== 0) {
    exit("This script must be run from the command line\n");
}
define('BASEDIR', __DIR__);
define('VERSION', '3.0.0 RC4');
define('MAILADDR', 'translator at xtrafile.com');
update_core(BASEDIR, 'xtraupload');
merge_translations(BASEDIR);
function update_core($dir, $domain)
{
    $potfile = BASEDIR . "/xtraupload.pot";
    $version = VERSION;
    $mailaddr = MAILADDR;
    $old = getcwd();
    chdir($dir);
    $application = realpath(BASEDIR . "/../../../application");
    unlink($potfile);
    passthru(<<<END
xgettext \\
\t--from-code=UTF-8 \\
\t--default-domain={$domain} \\
\t--output={$potfile} \\
\t--language=PHP \\
\t--copyright-holder="XtraUpload" \\
\t--package-name="XtraUpload" \\
\t--package-version="{$version}" \\
\t--msgid-bugs-address="{$mailaddr}" \\
\t--add-comments=HINT: \\
\t--keyword="nlang:1,1t" \\