Commit de2ef9de authored by Dries's avatar Dries

- Patch #1471376 by amateescu: convert updater.inc to PSR-0.

parent 6bab95b4
......@@ -7797,9 +7797,10 @@ function archiver_get_archiver($file) {
* file system, for example to update modules that have newer releases, or to
* install a new theme.
*
* @return
* @return array
* The Drupal Updater class registry.
*
* @see Drupal\Core\Updater\Updater
* @see hook_updater_info()
* @see hook_updater_info_alter()
*/
......
This diff is collapsed.
......@@ -4042,9 +4042,9 @@ function hook_batch_alter(&$batch) {
/**
* Provide information on Updaters (classes that can update Drupal).
*
* An Updater is a class that knows how to update various parts of the Drupal
* file system, for example to update modules that have newer releases, or to
* install a new theme.
* Drupal\Core\Updater\Updater is a class that knows how to update various parts
* of the Drupal file system, for example to update modules that have newer
* releases, or to install a new theme.
*
* @return
* An associative array of information about the updater(s) being provided.
......@@ -4066,12 +4066,12 @@ function hook_batch_alter(&$batch) {
function hook_updater_info() {
return array(
'module' => array(
'class' => 'ModuleUpdater',
'class' => 'Drupal\Core\Updater\Module',
'name' => t('Update modules'),
'weight' => 0,
),
'theme' => array(
'class' => 'ThemeUpdater',
'class' => 'Drupal\Core\Updater\Theme',
'name' => t('Update themes'),
'weight' => 0,
),
......
......@@ -7,7 +7,6 @@ files[] = system.archiver.inc
files[] = system.mail.inc
files[] = system.queue.inc
files[] = system.tar.inc
files[] = system.updater.inc
files[] = system.test
required = TRUE
configure = admin/config/system
......@@ -1862,12 +1862,12 @@ function system_authorized_batch_process() {
function system_updater_info() {
return array(
'module' => array(
'class' => 'ModuleUpdater',
'class' => 'Drupal\Core\Updater\Module',
'name' => t('Update modules'),
'weight' => 0,
),
'theme' => array(
'class' => 'ThemeUpdater',
'class' => 'Drupal\Core\Updater\Theme',
'name' => t('Update themes'),
'weight' => 0,
),
......
<?php
/**
* @file
* Subclasses of the Updater class to update Drupal core knows how to update.
* At this time, only modules and themes are supported.
*/
/**
* Class for updating modules using FileTransfer classes via authorize.php.
*/
class ModuleUpdater extends Updater implements DrupalUpdaterInterface {
/**
* Return the directory where a module should be installed.
*
* If the module is already installed, drupal_get_path() will return
* a valid path and we should install it there (although we need to use an
* absolute path, so we prepend DRUPAL_ROOT). If we're installing a new
* module, we always want it to go into sites/all/modules, since that's
* where all the documentation recommends users install their modules, and
* there's no way that can conflict on a multi-site installation, since
* the Update manager won't let you install a new module if it's already
* found on your system, and if there was a copy in sites/all, we'd see it.
*/
public function getInstallDirectory() {
if ($relative_path = drupal_get_path('module', $this->name)) {
$relative_path = dirname($relative_path);
}
else {
$relative_path = 'sites/all/modules';
}
return DRUPAL_ROOT . '/' . $relative_path;
}
public function isInstalled() {
return (bool) drupal_get_path('module', $this->name);
}
public static function canUpdateDirectory($directory) {
if (file_scan_directory($directory, '/.*\.module$/')) {
return TRUE;
}
return FALSE;
}
public static function canUpdate($project_name) {
return (bool) drupal_get_path('module', $project_name);
}
/**
* Return available database schema updates one a new version is installed.
*/
public function getSchemaUpdates() {
require_once DRUPAL_ROOT . '/core/includes/install.inc';
require_once DRUPAL_ROOT . '/core/includes/update.inc';
if (_update_get_project_type($project) != 'module') {
return array();
}
module_load_include('install', $project);
if (!$updates = drupal_get_schema_versions($project)) {
return array();
}
$updates_to_run = array();
$modules_with_updates = update_get_update_list();
if ($updates = $modules_with_updates[$project]) {
if ($updates['start']) {
return $updates['pending'];
}
}
return array();
}
public function postInstallTasks() {
return array(
l(t('Enable newly added modules'), 'admin/modules'),
l(t('Administration pages'), 'admin'),
);
}
public function postUpdateTasks() {
// We don't want to check for DB updates here, we do that once for all
// updated modules on the landing page.
}
}
/**
* Class for updating themes using FileTransfer classes via authorize.php.
*/
class ThemeUpdater extends Updater implements DrupalUpdaterInterface {
/**
* Return the directory where a theme should be installed.
*
* If the theme is already installed, drupal_get_path() will return
* a valid path and we should install it there (although we need to use an
* absolute path, so we prepend DRUPAL_ROOT). If we're installing a new
* theme, we always want it to go into sites/all/themes, since that's
* where all the documentation recommends users install their themes, and
* there's no way that can conflict on a multi-site installation, since
* the Update manager won't let you install a new theme if it's already
* found on your system, and if there was a copy in sites/all, we'd see it.
*/
public function getInstallDirectory() {
if ($relative_path = drupal_get_path('theme', $this->name)) {
$relative_path = dirname($relative_path);
}
else {
$relative_path = 'sites/all/themes';
}
return DRUPAL_ROOT . '/' . $relative_path;
}
public function isInstalled() {
return (bool) drupal_get_path('theme', $this->name);
}
static function canUpdateDirectory($directory) {
// This is a lousy test, but don't know how else to confirm it is a theme.
if (file_scan_directory($directory, '/.*\.module$/')) {
return FALSE;
}
return TRUE;
}
public static function canUpdate($project_name) {
return (bool) drupal_get_path('theme', $project_name);
}
public function postInstall() {
// Update the system table.
clearstatcache();
system_rebuild_theme_data();
}
public function postInstallTasks() {
return array(
l(t('Enable newly added themes'), 'admin/appearance'),
l(t('Administration pages'), 'admin'),
);
}
}
......@@ -9,6 +9,8 @@
* the rest of the update module code.
*/
use Drupal\Core\Updater\UpdaterException;
/**
* Callback invoked by authorize.php to update existing projects.
*
......@@ -19,7 +21,8 @@
* A nested array of projects to install into the live webroot, keyed by
* project name. Each subarray contains the following keys:
* - 'project': The canonical project short name.
* - 'updater_name': The name of the Updater class to use for this project.
* - 'updater_name': The name of the Drupal\Core\Updater\Updater class to use
* for this project.
* - 'local_url': The locally installed location of new code to update with.
*/
function update_authorize_run_update($filetransfer, $projects) {
......@@ -58,7 +61,8 @@ function update_authorize_run_update($filetransfer, $projects) {
* @param string $project
* The canonical project short name (e.g. {system}.name).
* @param string $updater_name
* The name of the Updater class to use for installing this project.
* The name of the Drupal\Core\Updater\Updater class to use for installing
* this project.
* @param string $local_url
* The URL to the locally installed temp directory where the project has
* already been downloaded and extracted into.
......@@ -95,7 +99,8 @@ function update_authorize_run_install($filetransfer, $project, $updater_name, $l
* @param string $project
* The canonical short name of the project being installed.
* @param string $updater_name
* The name of the Updater class to use for installing this project.
* The name of the Drupal\Core\Updater\Updater class to use for installing
* this project.
* @param string $local_url
* The URL to the locally installed temp directory where the project has
* already been downloaded and extracted into.
......
......@@ -35,6 +35,8 @@
* into the live web root.
*/
use Drupal\Core\Updater\Updater;
/**
* @defgroup update_manager_update Update manager: update
* @{
......@@ -393,9 +395,10 @@ function update_manager_update_ready_form($form, &$form_state) {
*
* If the site administrator requested that the site is put offline during the
* update, do so now. Otherwise, pull information about all the required
* updates out of the SESSION, figure out what Updater class is needed for
* each one, generate an array of update operations to perform, and hand it
* all off to system_authorized_init(), then redirect to authorize.php.
* updates out of the SESSION, figure out what Drupal\Core\Updater\Updater class
* is needed for each one, generate an array of update operations to perform,
* and hand it all off to system_authorized_init(), then redirect to
* authorize.php.
*
* @see update_authorize_run_update()
* @see system_authorized_init()
......@@ -600,10 +603,10 @@ function update_manager_install_form_validate($form, &$form_state) {
* Either downloads the file specified in the URL to a temporary cache, or
* uploads the file attached to the form, then attempts to extract the archive
* into a temporary location and verify it. Instantiate the appropriate
* Updater class for this project and make sure it is not already installed in
* the live webroot. If everything is successful, setup an operation to run
* via authorize.php which will copy the extracted files from the temporary
* location into the live site.
* Drupal\Core\Updater\Updater class for this project and make sure it is not
* already installed in the live webroot. If everything is successful, setup an
* operation to run via authorize.php which will copy the extracted files from
* the temporary location into the live site.
*
* @see update_authorize_run_install()
* @see system_authorized_init()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment