From 827214acb422982c4cf654fe1ccee25c494175e9 Mon Sep 17 00:00:00 2001 From: "Geoff St. Pierre" Date: Sun, 13 May 2018 12:12:49 -0400 Subject: [PATCH 1/2] Adding CoreUpdater class. Issue #3105: Add Backdrop core updates via /admin/modules/update UI. Issue #3105: Adding link to core UI update from /admin/reports/updates. --- core/includes/updater.inc | 34 +++++++++---- .../modules/installer/installer.authorize.inc | 9 +++- core/modules/installer/installer.manager.inc | 29 ++--------- core/modules/installer/installer.module | 13 ----- core/modules/system/system.module | 6 +++ core/modules/system/system.updater.inc | 51 ++++++++++++++++++- core/modules/update/update.theme.inc | 3 +- 7 files changed, 93 insertions(+), 52 deletions(-) diff --git a/core/includes/updater.inc b/core/includes/updater.inc index bd3a73de260..872d6f6ca47 100755 --- a/core/includes/updater.inc +++ b/core/includes/updater.inc @@ -181,16 +181,21 @@ abstract class Updater implements BackdropUpdaterInterface { * @throws UpdaterException */ public static function getProjectType($directory) { - $info_file = self::findInfoFile($directory); - $info = backdrop_parse_info_file($info_file); - if (empty($info)) { - throw new UpdaterException(t('Unable to parse info file: %info_file.', array('%info_file' => $info_file))); - } - if (empty($info['type'])) { - throw new UpdaterException(t("The info file (%info_file) does not define a 'type' attribute.", array('%info_file' => $info_file))); + if ($directory == BACKDROP_ROOT) { + return 'core'; } + else { + $info_file = self::findInfoFile($directory); + $info = backdrop_parse_info_file($info_file); + if (empty($info)) { + throw new UpdaterException(t('Unable to parse info file: %info_file.', array('%info_file' => $info_file))); + } + if (empty($info['type'])) { + throw new UpdaterException(t("The info file (%info_file) does not define a 'type' attribute.", array('%info_file' => $info_file))); + } - return $info['type']; + return $info['type']; + } } /** @@ -276,10 +281,19 @@ abstract class Updater implements BackdropUpdaterInterface { } // Copy the directory in place. - $filetransfer->copyDirectory($this->source, $args['install_dir']); + // Check for core udpate. + if ($this->name == 'backdrop') { + $source = $this->source . '/core'; + $name = 'core'; + } + else { + $source = $this->source; + $name = $this->name; + } + $filetransfer->copyDirectory($source, $args['install_dir']); // Make sure what we just installed is readable by the web server. - $this->makeWorldReadable($filetransfer, $args['install_dir'] . '/' . $this->name); + $this->makeWorldReadable($filetransfer, $args['install_dir'] . '/' . $name); // Run the updates. // @TODO: decide if we want to implement this. diff --git a/core/modules/installer/installer.authorize.inc b/core/modules/installer/installer.authorize.inc index d4fe578cfb7..16a91415d66 100644 --- a/core/modules/installer/installer.authorize.inc +++ b/core/modules/installer/installer.authorize.inc @@ -29,11 +29,18 @@ function installer_authorize_run_update($filetransfer, $projects) { $operations = array(); foreach ($projects as $project => $project_info) { + if ($project_info['project'] == 'backdrop') { + $updater_name = 'CoreUpdater'; + } + else { + $updater_name = $project_info['updater_name']; + } + $operations[] = array( 'installer_authorize_batch_copy_project', array( $project_info['project'], - $project_info['updater_name'], + $updater_name, $project_info['local_url'], $filetransfer, ), diff --git a/core/modules/installer/installer.manager.inc b/core/modules/installer/installer.manager.inc index 5393ee3c27c..eba93e2f00f 100644 --- a/core/modules/installer/installer.manager.inc +++ b/core/modules/installer/installer.manager.inc @@ -174,36 +174,15 @@ function installer_manager_update_form($form, $form_state, $context) { $entry['#attributes'] = array('class' => array('update-' . $type)); - // Backdrop CMS core needs to be upgraded manually. - $needs_manual = $project['project_type'] == 'core'; - - if ($needs_manual) { - // There are no checkboxes in the 'Manual updates' table so it will be - // rendered by theme('table'), not theme('tableselect'). Since the data - // formats are incompatible, we convert now to the format expected by - // theme('table'). - unset($entry['#weight']); - $attributes = $entry['#attributes']; - unset($entry['#attributes']); - $entry = array( - 'data' => $entry, - ) + $attributes; - } - else { - $form['project_downloads'][$name] = array( - '#type' => 'value', - '#value' => $recommended_release['download_link'], - ); - } + $form['project_downloads'][$name] = array( + '#type' => 'value', + '#value' => $recommended_release['download_link'], + ); // Based on what kind of project this is, save the entry into the // appropriate subarray. switch ($project['project_type']) { case 'core': - // Core needs manual updates at this time. - $projects['manual'][$name] = $entry; - break; - case 'module': case 'theme': case 'layout': diff --git a/core/modules/installer/installer.module b/core/modules/installer/installer.module index 83914030073..1a219ece3d2 100644 --- a/core/modules/installer/installer.module +++ b/core/modules/installer/installer.module @@ -220,19 +220,6 @@ function installer_theme($existing, $type, $theme, $path) { function installer_verify_update_archive($project, $archive_file, $directory) { $errors = array(); - // Make sure this isn't a tarball of Backdrop core. - if ( - file_exists("$directory/$project/index.php") - && file_exists("$directory/$project/core/update.php") - && file_exists("$directory/$project/core/includes/bootstrap.inc") - && file_exists("$directory/$project/core/modules/node/node.module") - && file_exists("$directory/$project/core/modules/system/system.module") - ) { - return array( - 'no-core' => t('Automatic updating of Backdrop CMS core is not supported. See the upgrade guide for information on how to update Backdrop CMS core manually.', array('@upgrade-guide' => 'https://backdropcms.org/guide/upgrade')), - ); - } - // Parse all the .info files and make sure at least one is compatible with // this version of Backdrop core. If one is compatible, then the project as a // whole is considered compatible (since, for example, the project may ship diff --git a/core/modules/system/system.module b/core/modules/system/system.module index be9f6013e5a..22e18437cdd 100755 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2161,6 +2161,11 @@ function system_authorized_batch_process($redirect_callback = 'backdrop_goto') { */ function system_updater_info() { return array( + 'core' => array( + 'class' => 'CoreUpdater', + 'name' => t('Update Backdrop core'), + 'weight' => 0, + ), 'module' => array( 'class' => 'ModuleUpdater', 'name' => t('Update modules'), @@ -3872,6 +3877,7 @@ function system_autoload_info() { 'SystemQueue' => 'system.queue.inc', 'MemoryQueue' => 'system.queue.inc', 'Archive_Tar' => 'system.tar.inc', + 'CoreUpdater' => 'system.updater.inc', 'ModuleUpdater' => 'system.updater.inc', 'ThemeUpdater' => 'system.updater.inc', 'LayoutUpdater' => 'system.updater.inc', diff --git a/core/modules/system/system.updater.inc b/core/modules/system/system.updater.inc index 875fb5fb711..498c248a7eb 100755 --- a/core/modules/system/system.updater.inc +++ b/core/modules/system/system.updater.inc @@ -2,10 +2,57 @@ /** * @file - * Subclasses of the Updater class to update Backdrop core knows how to update. - * At this time, only modules, themes and layouts are supported. + * Subclasses of the Updater class to update Backdrop core, modules, themes, and layouts. */ +/** + * Class for updating Backdrop core using FileTransfer classes via authorize.php. + */ +class CoreUpdater extends Updater { + + /** + * Return the Backdrop core directory. + */ + public function getInstallDirectory() { + return BACKDROP_ROOT; + } + + public function isInstalled() { + return (bool) file_exists($this->getInstallDirectory()); + } + + public static function canUpdateDirectory($directory) { + return (self::getProjectType($directory) == 'core'); + } + + static function canUpdate($project_name) { + return (bool) $this->isInstalled(); + } + + /** + * List of post install actions. + */ + public function postInstall() { + $project = array(); + $project['name'] = $this->name; + $project['type'] = 'core'; + $_SESSION['project_browser_installed_projects'][$this->name] = $project; + } + + /** + * List of post install actions. + */ + public function postInstallTasks() { + return array(); + } + + 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 modules using FileTransfer classes via authorize.php. */ diff --git a/core/modules/update/update.theme.inc b/core/modules/update/update.theme.inc index 2bd15a00332..e8547cc746a 100644 --- a/core/modules/update/update.theme.inc +++ b/core/modules/update/update.theme.inc @@ -79,7 +79,7 @@ function theme_update_report($variables) { foreach ($data as $project) { // Don't show a link to the "Update modules" page for core. - $update_link = ($project['name'] != 'backdrop'); + $update_link = ($project['name']); switch ($project['status']) { case UPDATE_NOT_SECURE: case UPDATE_REVOKED: @@ -121,6 +121,7 @@ function theme_update_report($variables) { $updatepath = 'admin/layouts/update'; break; + case 'core': case 'module': default: $updatepath = 'admin/modules/update'; From abd06011a048a44632939814cc6822b6a44c31e8 Mon Sep 17 00:00:00 2001 From: "Geoff St. Pierre" Date: Sat, 1 Sep 2018 11:11:48 -0400 Subject: [PATCH 2/2] Issue #3105: Clean up code style. --- core/modules/system/system.updater.inc | 2 +- core/modules/update/update.theme.inc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/modules/system/system.updater.inc b/core/modules/system/system.updater.inc index 498c248a7eb..76d1593cd0e 100755 --- a/core/modules/system/system.updater.inc +++ b/core/modules/system/system.updater.inc @@ -18,7 +18,7 @@ class CoreUpdater extends Updater { } public function isInstalled() { - return (bool) file_exists($this->getInstallDirectory()); + return (bool) file_exists($this->getInstallDirectory()); } public static function canUpdateDirectory($directory) { diff --git a/core/modules/update/update.theme.inc b/core/modules/update/update.theme.inc index e8547cc746a..f922b8d3d0f 100644 --- a/core/modules/update/update.theme.inc +++ b/core/modules/update/update.theme.inc @@ -121,7 +121,7 @@ function theme_update_report($variables) { $updatepath = 'admin/layouts/update'; break; - case 'core': + case 'core': case 'module': default: $updatepath = 'admin/modules/update';