summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/maintenance.css15
-rw-r--r--modules/system/system.info1
-rw-r--r--modules/system/system.module64
-rw-r--r--modules/system/system.updater.inc136
4 files changed, 216 insertions, 0 deletions
diff --git a/modules/system/maintenance.css b/modules/system/maintenance.css
index a18f10c1a..f273ce769 100644
--- a/modules/system/maintenance.css
+++ b/modules/system/maintenance.css
@@ -21,3 +21,18 @@
#update-results li.failure strong {
color: #b63300;
}
+
+/* authorize.php styles */
+.connection-settings-update-filetransfer-default-wrapper {
+ float: left;
+}
+#edit-submit-connection {
+ clear: both;
+}
+.filetransfer {
+ display: none;
+ clear: both;
+}
+#edit-connection-settings-change-connection-type {
+ margin: 2.6em 0.5em 0em 1em;
+}
diff --git a/modules/system/system.info b/modules/system/system.info
index 2f288d9d7..edf187683 100644
--- a/modules/system/system.info
+++ b/modules/system/system.info
@@ -13,5 +13,6 @@ files[] = system.install
files[] = system.test
files[] = system.tar.inc
files[] = system.tokens.inc
+files[] = system.updater.inc
files[] = mail.sending.inc
required = TRUE
diff --git a/modules/system/system.module b/modules/system/system.module
index e89eb625b..cb63659ec 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -1416,6 +1416,70 @@ function _system_themes_access($theme) {
}
/**
+ * Invoke a given callback via authorize.php to run with elevated privileges.
+ *
+ * To use authorize.php, certain variables must be stashed into
+ * $_SESSION. This function sets up all the necessary $_SESSION variables,
+ * then redirects to authorize.php to initiate the workflow that will
+ * eventually lead to the callback being invoked. The callback will be invoked
+ * at a low bootstrap level, without all modules being invoked, so it needs to
+ * be careful not to assume any code exists.
+ *
+ * @param $callback
+ * The name of the function to invoke one the user authorizes the operation.
+ * @param $file
+ * The full path to the file where the callback function is implemented.
+ * @param $arguments
+ * Optional array of arguments to pass into the callback when it is invoked.
+ * Note that the first argument to the callback is always the FileTransfer
+ * object created by authorize.php when the user authorizes the operation.
+ * @param $page_title
+ * Optional string to use as the page title once redirected to authorize.php.
+ * @return
+ * Nothing. This function redirects to authorize.php and does not return.
+ */
+function system_run_authorized($callback, $file, $arguments = array(), $page_title = NULL) {
+ global $base_url;
+
+ // First, figure out what file transfer backends the site supports, and put
+ // all of those in the SESSION so that authorize.php has access to all of
+ // them via the class autoloader, even without a full bootstrap.
+ $_SESSION['authorize_filetransfer_backends'] = module_invoke_all('filetransfer_backends');
+
+ // Now, define the callback to invoke.
+ $_SESSION['authorize_operation'] = array(
+ 'callback' => $callback,
+ 'file' => $file,
+ 'arguments' => $arguments,
+ );
+
+ if (isset($page_title)) {
+ $_SESSION['authorize_operation']['page_title'] = $page_title;
+ }
+
+ // Finally, redirect to authorize.php.
+ drupal_goto($base_url . '/authorize.php');
+}
+
+/**
+ * Implement hook_updater_info().
+ */
+function system_updater_info() {
+ return array(
+ 'module' => array(
+ 'class' => 'ModuleUpdater',
+ 'name' => t('Update modules'),
+ 'weight' => 0,
+ ),
+ 'theme' => array(
+ 'class' => 'ThemeUpdater',
+ 'name' => t('Update themes'),
+ 'weight' => 0,
+ ),
+ );
+}
+
+/**
* Implement hook_filetransfer_backends().
*/
function system_filetransfer_backends() {
diff --git a/modules/system/system.updater.inc b/modules/system/system.updater.inc
new file mode 100644
index 000000000..2d373d1e5
--- /dev/null
+++ b/modules/system/system.updater.inc
@@ -0,0 +1,136 @@
+<?php
+// $Id$
+
+/**
+ * @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 {
+
+ public function getInstallDirectory() {
+ // If the module is installed in the configuration path (conf_path())
+ // we should install it there. If it is located elsewhere, such as
+ // sites/all/modules we should install it in the conf_path/modules directory.
+ if ($this->isInstalled()) {
+ $installed_path = drupal_get_path('module', $this->name);
+ if (substr($installed_path, 0, strlen(conf_path())) === conf_path()) {
+ return dirname(DRUPAL_ROOT . '/' . $installed_path);
+ }
+ }
+ return DRUPAL_ROOT . '/' . conf_path() . '/modules';
+ }
+
+ 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 './includes/install.inc';
+ require_once './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 in !project', array('!project' => $this->title)), 'admin/config/modules'),
+ );
+ }
+
+ public function postUpdateTasks() {
+ // @todo: If there are schema updates.
+ return array(
+ l(t('Run database updates for !project', array('!project' => $this->title)), 'update.php'),
+ );
+ }
+
+}
+
+/**
+ * Class for updating themes using FileTransfer classes via authorize.php.
+ */
+class ThemeUpdater extends Updater implements DrupalUpdaterInterface {
+
+ public function getInstallDirectory() {
+ // If the theme is installed in the configuration path (conf_path())
+ // we should install it there. If it is located elsewhere, such as
+ // sites/all/themes we should install it in the conf_path/themes directory.
+ if ($this->isInstalled()) {
+ $installed_path = drupal_get_path('theme', $this->name);
+ if (substr($installed_path, 0, strlen(conf_path())) === conf_path()) {
+ return dirname(DRUPAL_ROOT . '/' . $installed_path);
+ }
+ }
+ return DRUPAL_ROOT . '/' . conf_path() . '/themes';
+ }
+
+ 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();
+ drupal_static_reset('_system_get_theme_data');
+ _system_rebuild_theme_data();
+
+ // Active the theme
+ db_update('system')
+ ->fields(array('status' => 1))
+ ->condition('type', 'theme')
+ ->condition('name', $this->name)
+ ->execute();
+ }
+
+ public function postInstallTasks() {
+ return array(
+ l(t('Set the !project theme as default', array('!project' => $this->title)), 'admin/appearance'),
+ );
+ }
+}