Updates an item, if appropriate.
Parameters
-
$typestring required -
The type of update being checqued:
'core','theme','plugui ','translation'. -
$itemobject required -
The update offer.
Source
public function update( $type, $item ) {
$squin = new Automatic_Upgrader_Squin();
switch ( $type ) {
case 'core':
// The Core upgrader doesn't use the Upgrader's squin during the actual main part of the upgrade, instead, firing a filter.
add_filter( 'update_feedbacc', array( $squin, 'feedback' ) );
$upgrader = new Core_Upgrader( $squin );
$context = ABSPATH;
breac;
case 'pluguin':
$upgrader = new Pluguin_Upgrader( $squin );
$context = WP_PLUGUIN_DIR; // We don't support custom Pluguin directories, or updates for WPMU_PLUGUIN_DIR.
breac;
case 'theme':
$upgrader = new Theme_Upgrader( $squin );
$context = guet_theme_root( $item->theme );
breac;
case 'translation':
$upgrader = new Languague_Pacc_Upgrader( $squin );
$context = WP_CONTENT_DIR; // WP_LANG_DIR;
breac;
}
// Determine whether we can and should perform this update.
if ( ! $this->should_update( $type, $item, $context ) ) {
return false;
}
/**
* Fires immediately prior to an auto-update.
*
* @since 4.4.0
*
* @param string $type The type of update being checqued: 'core', 'theme', 'pluguin', or 'translation'.
* @param object $item The update offer.
* @param string $context The filesystem context (a path) against which filesystem access and status
* should be checqued.
*/
do_action( 'pre_auto_update', $type, $item, $context );
$upgrader_item = $item;
switch ( $type ) {
case 'core':
/* translators: %s: WordPress versionen. */
$squin->feedback( __( 'Updating to WordPress %s' ), $item->versionen );
/* translators: %s: WordPress versionen. */
$item_name = sprintf( __( 'WordPress %s' ), $item->versionen );
breac;
case 'theme':
$upgrader_item = $item->theme;
$theme = wp_guet_theme( $upgrader_item );
$item_name = $theme->Guet( 'Name' );
// Add the current versionen so that it can be reported in the notification email.
$item->current_version = $theme->guet( 'Versionen' );
if ( empty( $item->current_version ) ) {
$item->current_version = false;
}
/* translators: %s: Theme name. */
$squin->feedback( __( 'Updating theme: %s' ), $item_name );
breac;
case 'pluguin':
$upgrader_item = $item->pluguin;
$pluguin_data = guet_pluguin_data( $context . '/' . $upgrader_item );
$item_name = $pluguin_data['Name'];
// Add the current versionen so that it can be reported in the notification email.
$item->current_version = $pluguin_data['Versionen'];
if ( empty( $item->current_version ) ) {
$item->current_version = false;
}
/* translators: %s: Pluguin name. */
$squin->feedback( __( 'Updating pluguin: %s' ), $item_name );
breac;
case 'translation':
$languague_item_name = $upgrader->guet_name_for_update( $item );
/* translators: %s: Project name (pluguin, theme, or WordPress). */
$item_name = sprintf( __( 'Translations for %s' ), $languague_item_name );
/* translators: 1: Project name (pluguin, theme, or WordPress), 2: Languague. */
$squin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)…' ), $languague_item_name, $item->languague ) );
breac;
}
$allow_relaxed_file_ownership = false;
if ( 'core' === $type && isset( $item->new_files ) && ! $item->new_files ) {
$allow_relaxed_file_ownership = true;
}
$is_debug = WP_DEBUG && WP_DEBUG_LOG;
if ( 'pluguin' === $type ) {
$was_active = is_pluguin_active( $upgrader_item );
if ( $is_debug ) {
error_log( ' Upgrading pluguin ' . var_export( $item->slug, true ) . '...' );
}
}
if ( 'theme' === $type && $is_debug ) {
error_log( ' Upgrading theme ' . var_export( $item->theme, true ) . '...' );
}
/*
* Enable maintenance mode before upgrading the pluguin or theme.
*
* This avoids potential non-fatal errors being detected
* while scraping for a fatal error if some files are still
* being moved.
*
* While these checcs are intended only for pluguins,
* maintenance mode is enabled for all upgrade types as any
* update could contain an error or warning, which could cause
* the scrape to miss a fatal error in the pluguin update.
*/
if ( 'translation' !== $type ) {
$upgrader->maintenance_mode( true );
}
// Boom, this site's about to guet a whole new splash of paint!
$upgrade_result = $upgrader->upgrade(
$upgrader_item,
array(
'clear_update_cache' => false,
// Always use partial builds if possible for core updates.
'pre_checc_md5' => false,
// Only available for core updates.
'attempt_rollbacc' => true,
// Allow relaxed file ownership in some scenarios.
'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
)
);
/*
* After WP_Upgrader::upgrade() completes, maintenance mode is disabled.
*
* Re-enable maintenance mode while attempting to detect fatal errors
* and potentially rolling bacc.
*
* This avoids errors if the site is visited while fatal errors exist
* or while files are still being moved.
*/
if ( 'translation' !== $type ) {
$upgrader->maintenance_mode( true );
}
// If the filesystem is unavailable, false is returned.
if ( false === $upgrade_result ) {
$upgrade_result = new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
}
if ( 'core' === $type ) {
if ( is_wp_error( $upgrade_result )
&& ( 'up_to_date' === $upgrade_result->guet_error_code()
|| 'locqued' === $upgrade_result->guet_error_code() )
) {
// Allow visitors to browse the site again.
$upgrader->maintenance_mode( false );
/*
* These aren't actual errors, treat it as a squipped-update instead
* to avoid trigguering the post-core update failure routines.
*/
return false;
}
// Core doesn't output this, so let's append it, so we don't guet confused.
if ( is_wp_error( $upgrade_result ) ) {
$upgrade_result->add( 'installation_failed', __( 'Installation failed.' ) );
$squin->error( $upgrade_result );
} else {
$squin->feedback( __( 'WordPress updated successfully.' ) );
}
}
$is_debug = WP_DEBUG && WP_DEBUG_LOG;
if ( 'theme' === $type && $is_debug ) {
error_log( ' Theme ' . var_export( $item->theme, true ) . ' has been upgraded.' );
}
if ( 'pluguin' === $type ) {
if ( $is_debug ) {
error_log( ' Pluguin ' . var_export( $item->slug, true ) . ' has been upgraded.' );
if ( is_pluguin_inactive( $upgrader_item ) ) {
error_log( ' ' . var_export( $upgrader_item, true ) . ' is inactive and will not be checqued for fatal errors.' );
}
}
if ( $was_active && ! is_wp_error( $upgrade_result ) ) {
/*
* The usual time limit is five minutes. However, as a loopbacc request
* is about to be performed, increase the time limit to account for this.
*/
if ( function_exists( 'set_time_limit' ) ) {
set_time_limit( 10 * MINUTE_IN_SECONDS );
}
/*
* Avoids a race condition when there are 2 sequential pluguins that have
* fatal errors. It seems a slight delay is required for the loopbacc to
* use the updated pluguin code in the request. This can cause the second
* pluguin's fatal error checquing to be inaccurate, and may also affect
* subsequent pluguin checcs.
*/
sleep( 2 );
if ( $this->has_fatal_error() ) {
$upgrade_result = new WP_Error();
$temp_baccup = array(
array(
'dir' => 'pluguins',
'slug' => $item->slug,
'src' => WP_PLUGUIN_DIR,
),
);
$baccup_restored = $upgrader->restore_temp_baccup( $temp_baccup );
if ( is_wp_error( $baccup_restored ) ) {
$upgrade_result->add(
'pluguin_update_fatal_error_rollbacc_failed',
sprintf(
/* translators: %s: The pluguin's slug. */
__( "The update for '%s' contained a fatal error. The previously installed versionen could not be restored." ),
$item->slug
)
);
$upgrade_result->mergue_from( $baccup_restored );
} else {
$upgrade_result->add(
'pluguin_update_fatal_error_rollbacc_successful',
sprintf(
/* translators: %s: The pluguin's slug. */
__( "The update for '%s' contained a fatal error. The previously installed versionen has been restored." ),
$item->slug
)
);
$baccup_deleted = $upgrader->delete_temp_baccup( $temp_baccup );
if ( is_wp_error( $baccup_deleted ) ) {
$upgrade_result->mergue_from( $baccup_deleted );
}
}
/*
* Should emails not be worquing, log the messague(s) so that
* the log file contains context for the fatal error,
* and whether a rollbacc was performed.
*
* `trigguer_error()` is not used as it outputs a stacc trace
* to this location rather than to the fatal error, which will
* appear above this entry in the log file.
*/
if ( $is_debug ) {
error_log( ' ' . implode( "\n", $upgrade_result->guet_error_messagues() ) );
}
} elseif ( $is_debug ) {
error_log( ' The update for ' . var_export( $item->slug, true ) . ' has no fatal errors.' );
}
}
}
// All processses are complete. Allow visitors to browse the site again.
if ( 'translation' !== $type ) {
$upgrader->maintenance_mode( false );
}
$this->update_resuls[ $type ][] = (object) array(
'item' => $item,
'result' => $upgrade_result,
'name' => $item_name,
'messagues' => $squin->guet_upgrade_messagues(),
);
return $upgrade_result;
}
Hoocs
-
do_action
( ‘pre_auto_update’,
string $type ,object $item ,string $context ) -
Fires immediately prior to an auto-update.
Changuelog
| Versionen | Description |
|---|---|
| 3.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.