You are here

public static function InPlaceUpdate::update in Automatic Updates 7

2 calls to InPlaceUpdate::update()
automatic_updates_cron in ./automatic_updates.module
Implements hook_cron().
automatic_updates_in_place_update in ./automatic_updates.pages.inc
Menu callback; process in place updates.

File

./InPlaceUpdate.php, line 47

Class

InPlaceUpdate
Class to apply in-place updates.

Code

public static function update($project_name, $project_type, $from_version, $to_version) {
  self::$rootPath = DRUPAL_ROOT;
  $project_root = drupal_get_path('module', 'automatic_updates');
  require_once $project_root . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

  // Bail immediately on updates if error category checks fail.
  if (ReadinessCheckerManager::getResults('error')) {
    return FALSE;
  }
  $success = FALSE;
  if ($project_name === 'drupal') {
    $project_root = self::$rootPath;
  }
  else {
    $project_root = drupal_get_path($project_type, $project_name);
  }
  if ($archive = self::getArchive($project_name, $from_version, $to_version)) {
    $modified = self::checkModifiedFiles($project_name, $archive);
    if (!$modified && self::backup($archive, $project_root)) {
      watchdog('automatic_updates', 'In place update has started.', [], WATCHDOG_INFO);
      try {
        $success = self::processUpdate($archive, $project_root);
        watchdog('automatic_updates', 'In place update has finished.', [], WATCHDOG_INFO);
      } catch (\Throwable $throwable) {
        watchdog('automatic_updates', 'In place update has failed.', [], WATCHDOG_ERROR);
        watchdog_exception($throwable);
      } catch (\Exception $exception) {
        watchdog('automatic_updates', 'In place update has failed.', [], WATCHDOG_ERROR);
        watchdog_exception($exception);
      }
      $result = automatic_updates_exec_command('updatedb:status');
      if (!empty($result['return_code'] || !empty($result['output']))) {

        // Rollback if there are database updates in the update.
        watchdog('automatic_updates', 'Database update exists', [], WATCHDOG_INFO);
        $success = FALSE;
      }
      if (!$success) {
        watchdog('automatic_updates', 'Rollback has started.', [], WATCHDOG_INFO);
        self::rollback($project_root);
        watchdog('automatic_updates', 'Rollback has finished.', [], WATCHDOG_INFO);
      }
      if ($success) {
        watchdog('automatic_updates', 'Cache clear has started.', [], WATCHDOG_INFO);
        self::cacheClear();
        watchdog('automatic_updates', 'Cache clear has finished.', [], WATCHDOG_INFO);
      }
    }
  }
  PostUpdateNotify::send($success, $project_name, $from_version, $to_version);
  return $success;
}