3 namespace Drupal\Core\Updater;
8 * Defines a class for updating modules using
9 * Drupal\Core\FileTransfer\FileTransfer classes via authorize.php.
11 class Module extends Updater implements UpdaterInterface {
14 * Returns the directory where a module should be installed.
16 * If the module is already installed, drupal_get_path() will return a valid
17 * path and we should install it there. If we're installing a new module, we
18 * always want it to go into /modules, since that's where all the
19 * documentation recommends users install their modules, and there's no way
20 * that can conflict on a multi-site installation, since the Update manager
21 * won't let you install a new module if it's already found on your system,
22 * and if there was a copy in the top-level we'd see it.
25 * The absolute path of the directory.
27 public function getInstallDirectory() {
28 if ($this->isInstalled() && ($relative_path = drupal_get_path('module', $this->name))) {
29 // The return value of drupal_get_path() is always relative to the site,
30 // so prepend DRUPAL_ROOT.
31 return DRUPAL_ROOT . '/' . dirname($relative_path);
34 // When installing a new module, prepend the requested root directory.
35 return $this->root . '/' . $this->getRootDirectoryRelativePath();
42 public static function getRootDirectoryRelativePath() {
49 public function isInstalled() {
50 // Check if the module exists in the file system, regardless of whether it
52 $modules = \Drupal::state()->get('system.module.files', []);
53 return isset($modules[$this->name]);
59 public static function canUpdateDirectory($directory) {
60 $info = static::getExtensionInfo($directory);
62 return (isset($info['type']) && $info['type'] == 'module');
66 * Determines whether this class can update the specified project.
68 * @param string $project_name
69 * The project to check.
73 public static function canUpdate($project_name) {
74 return (bool) drupal_get_path('module', $project_name);
78 * Returns available database schema updates once a new version is installed.
82 public function getSchemaUpdates() {
83 require_once DRUPAL_ROOT . '/core/includes/install.inc';
84 require_once DRUPAL_ROOT . '/core/includes/update.inc';
86 if (!self::canUpdate($this->name)) {
89 module_load_include('install', $this->name);
91 if (!$updates = drupal_get_schema_versions($this->name)) {
94 $modules_with_updates = update_get_update_list();
95 if ($updates = $modules_with_updates[$this->name]) {
96 if ($updates['start']) {
97 return $updates['pending'];
106 public function postInstallTasks() {
107 // Since this is being called outsite of the primary front controller,
108 // the base_url needs to be set explicitly to ensure that links are
109 // relative to the site root.
110 // @todo Simplify with https://www.drupal.org/node/2548095
115 'base_url' => $GLOBALS['base_url'],
120 '#url' => Url::fromRoute('update.module_install'),
121 '#title' => t('Install another module'),
124 '#url' => Url::fromRoute('system.modules_list'),
125 '#title' => t('Enable newly added modules'),
128 '#url' => Url::fromRoute('system.admin'),
129 '#title' => t('Administration pages'),
137 public function postUpdateTasks() {
138 // We don't want to check for DB updates here, we do that once for all
139 // updated modules on the landing page.