system.updater.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 ($this->isInstalled() && ($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_filename('module', $this->name, NULL, FALSE);
  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. * Returns a list of post install actions.
  46. */
  47. public function postInstallTasks() {
  48. return array(
  49. l(t('Install another module'), 'admin/modules/install'),
  50. l(t('Enable newly added modules'), 'admin/modules'),
  51. l(t('Administration pages'), 'admin'),
  52. );
  53. }
  54. public function postUpdateTasks() {
  55. // We don't want to check for DB updates here, we do that once for all
  56. // updated modules on the landing page.
  57. }
  58. }
  59. /**
  60. * Class for updating themes using FileTransfer classes via authorize.php.
  61. */
  62. class ThemeUpdater extends Updater implements DrupalUpdaterInterface {
  63. /**
  64. * Return the directory where a theme should be installed.
  65. *
  66. * If the theme is already installed, drupal_get_path() will return
  67. * a valid path and we should install it there (although we need to use an
  68. * absolute path, so we prepend DRUPAL_ROOT). If we're installing a new
  69. * theme, we always want it to go into sites/all/themes, since that's
  70. * where all the documentation recommends users install their themes, and
  71. * there's no way that can conflict on a multi-site installation, since
  72. * the Update manager won't let you install a new theme if it's already
  73. * found on your system, and if there was a copy in sites/all, we'd see it.
  74. */
  75. public function getInstallDirectory() {
  76. if ($this->isInstalled() && ($relative_path = drupal_get_path('theme', $this->name))) {
  77. $relative_path = dirname($relative_path);
  78. }
  79. else {
  80. $relative_path = 'sites/all/themes';
  81. }
  82. return DRUPAL_ROOT . '/' . $relative_path;
  83. }
  84. public function isInstalled() {
  85. return (bool) drupal_get_filename('theme', $this->name, NULL, FALSE);
  86. }
  87. static function canUpdateDirectory($directory) {
  88. // This is a lousy test, but don't know how else to confirm it is a theme.
  89. if (file_scan_directory($directory, '/.*\.module$/')) {
  90. return FALSE;
  91. }
  92. return TRUE;
  93. }
  94. public static function canUpdate($project_name) {
  95. return (bool) drupal_get_path('theme', $project_name);
  96. }
  97. public function postInstall() {
  98. // Update the system table.
  99. clearstatcache();
  100. system_rebuild_theme_data();
  101. }
  102. public function postInstallTasks() {
  103. return array(
  104. l(t('Enable newly added themes'), 'admin/appearance'),
  105. l(t('Administration pages'), 'admin'),
  106. );
  107. }
  108. }