function Updater::update

Same name in other branches
  1. 7.x includes/updater.inc \Updater::update()
  2. 8.9.x core/lib/Drupal/Core/Updater/Updater.php \Drupal\Core\Updater\Updater::update()
  3. 10 core/lib/Drupal/Core/Updater/Updater.php \Drupal\Core\Updater\Updater::update()
  4. 11.x core/lib/Drupal/Core/Updater/Updater.php \Drupal\Core\Updater\Updater::update()

Updates a Drupal project and returns a list of next actions.

Parameters

\Drupal\Core\FileTransfer\FileTransfer $filetransfer: Object that is a child of FileTransfer. Used for moving files to the server.

array $overrides: An array of settings to override defaults; see self::getInstallArgs().

Return value

array An array of links which the user may need to complete the update

Throws

\Drupal\Core\Updater\UpdaterException

\Drupal\Core\Updater\UpdaterFileTransferException

File

core/lib/Drupal/Core/Updater/Updater.php, line 230

Class

Updater
Defines the base class for Updaters used in Drupal.

Namespace

Drupal\Core\Updater

Code

public function update(&$filetransfer, $overrides = []) {
    try {
        // Establish arguments with possible overrides.
        $args = $this->getInstallArgs($overrides);
        // Take a Backup.
        if ($args['make_backup']) {
            $this->makeBackup($filetransfer, $args['install_dir'], $args['backup_dir']);
        }
        if (!$this->name) {
            // This is bad, don't want to delete the install directory.
            throw new UpdaterException('Fatal error in update, cowardly refusing to wipe out the install directory.');
        }
        // Make sure the installation parent directory exists and is writable.
        $this->prepareInstallDirectory($filetransfer, $args['install_dir']);
        if (is_dir($args['install_dir'] . '/' . $this->name)) {
            // Remove the existing installed file.
            $filetransfer->removeDirectory($args['install_dir'] . '/' . $this->name);
        }
        // Copy the directory in place.
        $filetransfer->copyDirectory($this->source, $args['install_dir']);
        // Make sure what we just installed is readable by the web server.
        $this->makeWorldReadable($filetransfer, $args['install_dir'] . '/' . $this->name);
        // Run the updates.
        // @todo Decide if we want to implement this.
        $this->postUpdate();
        // For now, just return a list of links of things to do.
        return $this->postUpdateTasks();
    } catch (FileTransferException $e) {
        throw new UpdaterFileTransferException("File Transfer failed, reason: '" . strtr($e->getMessage(), $e->arguments) . "'");
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.