system.updater.inc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. public function postInstallTasks() {
  67. return array(
  68. l(t('Enable newly added modules'), 'admin/modules'),
  69. l(t('Administration pages'), 'admin'),
  70. );
  71. }
  72. public function postUpdateTasks() {
  73. // We don't want to check for DB updates here, we do that once for all
  74. // updated modules on the landing page.
  75. }
  76. }
  77. /**
  78. * Class for updating themes using FileTransfer classes via authorize.php.
  79. */
  80. class ThemeUpdater extends Updater implements DrupalUpdaterInterface {
  81. /**
  82. * Return the directory where a theme should be installed.
  83. *
  84. * If the theme is already installed, drupal_get_path() will return
  85. * a valid path and we should install it there (although we need to use an
  86. * absolute path, so we prepend DRUPAL_ROOT). If we're installing a new
  87. * theme, we always want it to go into sites/all/themes, since that's
  88. * where all the documentation recommends users install their themes, and
  89. * there's no way that can conflict on a multi-site installation, since
  90. * the Update manager won't let you install a new theme if it's already
  91. * found on your system, and if there was a copy in sites/all, we'd see it.
  92. */
  93. public function getInstallDirectory() {
  94. if ($relative_path = drupal_get_path('theme', $this->name)) {
  95. $relative_path = dirname($relative_path);
  96. }
  97. else {
  98. $relative_path = 'sites/all/themes';
  99. }
  100. return DRUPAL_ROOT . '/' . $relative_path;
  101. }
  102. public function isInstalled() {
  103. return (bool) drupal_get_path('theme', $this->name);
  104. }
  105. static function canUpdateDirectory($directory) {
  106. // This is a lousy test, but don't know how else to confirm it is a theme.
  107. if (file_scan_directory($directory, '/.*\.module$/')) {
  108. return FALSE;
  109. }
  110. return TRUE;
  111. }
  112. public static function canUpdate($project_name) {
  113. return (bool) drupal_get_path('theme', $project_name);
  114. }
  115. public function postInstall() {
  116. // Update the system table.
  117. clearstatcache();
  118. system_rebuild_theme_data();
  119. }
  120. public function postInstallTasks() {
  121. return array(
  122. l(t('Enable newly added themes'), 'admin/appearance'),
  123. l(t('Administration pages'), 'admin'),
  124. );
  125. }
  126. }