Projet

Général

Profil

Paste
Télécharger (4,56 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / system / system.updater.inc @ 76597ebf

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Subclasses of the Updater class to update Drupal core knows how to update.
6
 * At this time, only modules and themes are supported.
7
 */
8
9
/**
10
 * Class for updating modules using FileTransfer classes via authorize.php.
11
 */
12
class ModuleUpdater extends Updater implements DrupalUpdaterInterface {
13
14
  /**
15
   * Return the directory where a module should be installed.
16
   *
17
   * If the module is already installed, drupal_get_path() will return
18
   * a valid path and we should install it there (although we need to use an
19
   * absolute path, so we prepend DRUPAL_ROOT). If we're installing a new
20
   * module, we always want it to go into sites/all/modules, since that's
21
   * where all the documentation recommends users install their modules, and
22
   * there's no way that can conflict on a multi-site installation, since
23
   * the Update manager won't let you install a new module if it's already
24
   * found on your system, and if there was a copy in sites/all, we'd see it.
25
   */
26
  public function getInstallDirectory() {
27
    if ($relative_path = drupal_get_path('module', $this->name)) {
28
      $relative_path = dirname($relative_path);
29
    }
30
    else {
31
      $relative_path = 'sites/all/modules';
32
    }
33
    return DRUPAL_ROOT . '/' . $relative_path;
34
  }
35
36
  public function isInstalled() {
37
    return (bool) drupal_get_path('module', $this->name);
38
  }
39
40
  public static function canUpdateDirectory($directory) {
41
    if (file_scan_directory($directory, '/.*\.module$/')) {
42
      return TRUE;
43
    }
44
    return FALSE;
45
  }
46
47
  public static function canUpdate($project_name) {
48
    return (bool) drupal_get_path('module', $project_name);
49
  }
50
51
  /**
52
   * Return available database schema updates one a new version is installed.
53
   */
54
  public function getSchemaUpdates() {
55
    require_once DRUPAL_ROOT . '/includes/install.inc';
56
    require_once DRUPAL_ROOT . '/includes/update.inc';
57
58
    if (_update_get_project_type($project) != 'module') {
59
      return array();
60
    }
61
    module_load_include('install', $project);
62
63
    if (!$updates = drupal_get_schema_versions($project)) {
64
      return array();
65
    }
66
    $updates_to_run = array();
67
    $modules_with_updates = update_get_update_list();
68
    if ($updates = $modules_with_updates[$project]) {
69
      if ($updates['start']) {
70
        return $updates['pending'];
71
      }
72
    }
73
    return array();
74
  }
75
76
  /**
77
   * Returns a list of post install actions.
78
   */
79
  public function postInstallTasks() {
80
    return array(
81
      l(t('Install another module'), 'admin/modules/install'),
82
      l(t('Enable newly added modules'), 'admin/modules'),
83
      l(t('Administration pages'), 'admin'),
84
    );
85
  }
86
87
  public function postUpdateTasks() {
88
    // We don't want to check for DB updates here, we do that once for all
89
    // updated modules on the landing page.
90
  }
91
92
}
93
94
/**
95
 * Class for updating themes using FileTransfer classes via authorize.php.
96
 */
97
class ThemeUpdater extends Updater implements DrupalUpdaterInterface {
98
99
  /**
100
   * Return the directory where a theme should be installed.
101
   *
102
   * If the theme is already installed, drupal_get_path() will return
103
   * a valid path and we should install it there (although we need to use an
104
   * absolute path, so we prepend DRUPAL_ROOT). If we're installing a new
105
   * theme, we always want it to go into sites/all/themes, since that's
106
   * where all the documentation recommends users install their themes, and
107
   * there's no way that can conflict on a multi-site installation, since
108
   * the Update manager won't let you install a new theme if it's already
109
   * found on your system, and if there was a copy in sites/all, we'd see it.
110
   */
111
  public function getInstallDirectory() {
112
    if ($relative_path = drupal_get_path('theme', $this->name)) {
113
      $relative_path = dirname($relative_path);
114
    }
115
    else {
116
      $relative_path = 'sites/all/themes';
117
    }
118
    return DRUPAL_ROOT . '/' . $relative_path;
119
  }
120
121
  public function isInstalled() {
122
    return (bool) drupal_get_path('theme', $this->name);
123
  }
124
125
  static function canUpdateDirectory($directory) {
126
    // This is a lousy test, but don't know how else to confirm it is a theme.
127
    if (file_scan_directory($directory, '/.*\.module$/')) {
128
      return FALSE;
129
    }
130
    return TRUE;
131
  }
132
133
  public static function canUpdate($project_name) {
134
    return (bool) drupal_get_path('theme', $project_name);
135
  }
136
137
  public function postInstall() {
138
    // Update the system table.
139
    clearstatcache();
140
    system_rebuild_theme_data();
141
142
  }
143
144
  public function postInstallTasks() {
145
    return array(
146
      l(t('Enable newly added themes'), 'admin/appearance'),
147
      l(t('Administration pages'), 'admin'),
148
    );
149
  }
150
}