| 1 |
<?php
|
| 2 |
// $Id: system.updater.inc,v 1.1 2009/10/15 21:19:31 webchick Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Subclasses of the Updater class to update Drupal core knows how to update.
|
| 7 |
* At this time, only modules and themes are supported.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Class for updating modules using FileTransfer classes via authorize.php.
|
| 12 |
*/
|
| 13 |
class ModuleUpdater extends Updater implements DrupalUpdaterInterface {
|
| 14 |
|
| 15 |
public function getInstallDirectory() {
|
| 16 |
// If the module is installed in the configuration path (conf_path())
|
| 17 |
// we should install it there. If it is located elsewhere, such as
|
| 18 |
// sites/all/modules we should install it in the conf_path/modules directory.
|
| 19 |
if ($this->isInstalled()) {
|
| 20 |
$installed_path = drupal_get_path('module', $this->name);
|
| 21 |
if (substr($installed_path, 0, strlen(conf_path())) === conf_path()) {
|
| 22 |
return dirname(DRUPAL_ROOT . '/' . $installed_path);
|
| 23 |
}
|
| 24 |
}
|
| 25 |
return DRUPAL_ROOT . '/' . conf_path() . '/modules';
|
| 26 |
}
|
| 27 |
|
| 28 |
public function isInstalled() {
|
| 29 |
return (bool) drupal_get_path('module', $this->name);
|
| 30 |
}
|
| 31 |
|
| 32 |
public static function canUpdateDirectory($directory) {
|
| 33 |
if (file_scan_directory($directory, '/.*\.module/')) {
|
| 34 |
return TRUE;
|
| 35 |
}
|
| 36 |
return FALSE;
|
| 37 |
}
|
| 38 |
|
| 39 |
public static function canUpdate($project_name) {
|
| 40 |
return (bool) drupal_get_path('module', $project_name);
|
| 41 |
}
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Return available database schema updates one a new version is installed.
|
| 45 |
*/
|
| 46 |
public function getSchemaUpdates() {
|
| 47 |
require_once './includes/install.inc';
|
| 48 |
require_once './includes/update.inc';
|
| 49 |
|
| 50 |
if (_update_get_project_type($project) != 'module') {
|
| 51 |
return array();
|
| 52 |
}
|
| 53 |
module_load_include('install', $project);
|
| 54 |
|
| 55 |
if (!$updates = drupal_get_schema_versions($project)) {
|
| 56 |
return array();
|
| 57 |
}
|
| 58 |
$updates_to_run = array();
|
| 59 |
$modules_with_updates = update_get_update_list();
|
| 60 |
if ($updates = $modules_with_updates[$project]) {
|
| 61 |
if ($updates['start']) {
|
| 62 |
return $updates['pending'];
|
| 63 |
}
|
| 64 |
}
|
| 65 |
return array();
|
| 66 |
}
|
| 67 |
|
| 68 |
public function postInstallTasks() {
|
| 69 |
return array(
|
| 70 |
l(t('Enable newly added modules in !project', array('!project' => $this->title)), 'admin/config/modules'),
|
| 71 |
);
|
| 72 |
}
|
| 73 |
|
| 74 |
public function postUpdateTasks() {
|
| 75 |
// @todo: If there are schema updates.
|
| 76 |
return array(
|
| 77 |
l(t('Run database updates for !project', array('!project' => $this->title)), 'update.php'),
|
| 78 |
);
|
| 79 |
}
|
| 80 |
|
| 81 |
}
|
| 82 |
|
| 83 |
/**
|
| 84 |
* Class for updating themes using FileTransfer classes via authorize.php.
|
| 85 |
*/
|
| 86 |
class ThemeUpdater extends Updater implements DrupalUpdaterInterface {
|
| 87 |
|
| 88 |
public function getInstallDirectory() {
|
| 89 |
// If the theme is installed in the configuration path (conf_path())
|
| 90 |
// we should install it there. If it is located elsewhere, such as
|
| 91 |
// sites/all/themes we should install it in the conf_path/themes directory.
|
| 92 |
if ($this->isInstalled()) {
|
| 93 |
$installed_path = drupal_get_path('theme', $this->name);
|
| 94 |
if (substr($installed_path, 0, strlen(conf_path())) === conf_path()) {
|
| 95 |
return dirname(DRUPAL_ROOT . '/' . $installed_path);
|
| 96 |
}
|
| 97 |
}
|
| 98 |
return DRUPAL_ROOT . '/' . conf_path() . '/themes';
|
| 99 |
}
|
| 100 |
|
| 101 |
public function isInstalled() {
|
| 102 |
return (bool) drupal_get_path('theme', $this->name);
|
| 103 |
}
|
| 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 |
|
| 113 |
public static function canUpdate($project_name) {
|
| 114 |
return (bool) drupal_get_path('theme', $project_name);
|
| 115 |
}
|
| 116 |
|
| 117 |
public function postInstall() {
|
| 118 |
// Update the system table.
|
| 119 |
clearstatcache();
|
| 120 |
drupal_static_reset('_system_rebuild_theme_data');
|
| 121 |
_system_rebuild_theme_data();
|
| 122 |
|
| 123 |
// Active the theme
|
| 124 |
db_update('system')
|
| 125 |
->fields(array('status' => 1))
|
| 126 |
->condition('type', 'theme')
|
| 127 |
->condition('name', $this->name)
|
| 128 |
->execute();
|
| 129 |
}
|
| 130 |
|
| 131 |
public function postInstallTasks() {
|
| 132 |
return array(
|
| 133 |
l(t('Set the !project theme as default', array('!project' => $this->title)), 'admin/appearance'),
|
| 134 |
);
|
| 135 |
}
|
| 136 |
}
|