system.updater.inc

Subclasses of the Updater class to update Drupal core knows how to update. At this time, only modules and themes are supported.

File

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