Skip to content

Commit

Permalink
#537280 by jasonn1234. D7 compatibility. This gets almost all command…
Browse files Browse the repository at this point in the history
…s except for the pm commands. help wanted.
  • Loading branch information
massgov-outsider committed Aug 19, 2009
1 parent 1cb52f2 commit 14c7daf
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 18 deletions.
7 changes: 4 additions & 3 deletions commands/core/core.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function core_drush_command() {
function core_drush_engine_drupal() {
$engines = array();
$engines['update'] = array();
$engines['environment'] = array();
return $engines;
}

Expand Down Expand Up @@ -424,12 +425,12 @@ function core_watchdog_format_message($watchdog) {
function drush_core_watchdog_delete($type = NULL) {
if ($type == "all") {
// D7: ought to be a dynamic query.
drush_op('db_query', 'DELETE FROM {watchdog}'); // indiscriminately delete all
drush_log(dt('Deleted !n rows.', array('!n' => db_affected_rows())), 'ok');
drush_op('db_query', 'DELETE FROM {watchdog}'); // Indiscriminately delete all
drush_log(dt('Deleted all rows.'), 'ok');
}
elseif (!empty($type)) {
drush_op('db_query', 'DELETE FROM {watchdog} WHERE type = \'%s\'', $type);
drush_log(dt('Deleted !n rows.', array('!n' => db_affected_rows())), 'ok');
drush_log(dt('Deleted all rows.'), 'ok');
}
else {
drush_set_error(dt('Please specify a message type, or "all" to delete all messages.'));
Expand Down
29 changes: 29 additions & 0 deletions commands/core/drupal/environment.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
// $Id:
/**
* @file
* Helper functions for /includes/environment.php.
* drush_include_engine() magically includes either this file
* or environment_7.php depending on which version of drupal drush
* is called from.
*/

/**
* Get module information for all installed modules.
*
* @return
* An array containing module info for all installed modules.
*/
function _drush_get_modules() {
return module_rebuild_cache();
}

/**
* Get theme information for all installed themes.
*
* @return
* An array containing theme info for all installed themes.
*/
function _drush_get_themes() {
return _system_theme_data();
}
34 changes: 34 additions & 0 deletions commands/core/drupal/environment_7.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
// $Id:
/**
* @file
* Helper functions for /includes/environment.php.
* drush_include_engine() magically includes either this file
* or environment.php depending on which version of drupal drush
* is called from.
*/

/**
* Get module information for all installed modules.
*
* @return
* An array containing module info for all installed modules.
*/
function _drush_get_modules() {
$module_info = drupal_system_listing('/\.module$/', 'modules', 'name', 0);
system_get_files_database($module_info, 'module');
foreach ($module_info as $module_name => $module){
$module_info[$module_name]->info = drupal_parse_info_file(dirname($module->filename) .'/'. $module->name .'.info');
}
return $module_info;
}

/**
* Get theme information for all installed themes.
*
* @return
* An array containing theme info for all installed themes.
*/
function _drush_get_themes() {
return _system_get_theme_data();
}
4 changes: 2 additions & 2 deletions commands/core/drupal/update_6.inc
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ function update_check_incompatibility($name, $type = 'module') {

// Store values of expensive functions for future use.
if (empty($themes) || empty($modules)) {
$themes = _system_theme_data();
$modules = module_rebuild_cache();
$themes = drush_get_themes();
$modules = drush_get_modules();
}

if ($type == 'module' && isset($modules[$name])) {
Expand Down
13 changes: 4 additions & 9 deletions commands/core/drupal/update_7.inc
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ function update_check_incompatibility($name, $type = 'module') {

// Store values of expensive functions for future use.
if (empty($themes) || empty($modules)) {
$themes = _system_theme_data();
$modules = module_rebuild_cache();
$themes = drush_get_themes();
$modules = drush_get_modules();
}

if ($type == 'module' && isset($modules[$name])) {
Expand Down Expand Up @@ -418,7 +418,7 @@ function update_main() {
drupal_load('module', 'filter');

// Set up $language, since the installer components require it.
drupal_init_language();
drupal_language_initialize();

// Set up theme system for the maintenance page.
drupal_maintenance_theme();
Expand All @@ -430,7 +430,7 @@ function update_main() {
// been created yet.
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_DATABASE);
include_once DRUPAL_ROOT . '/includes/install.inc';
drupal_install_init_database();
drupal_install_initialize_database();
spl_autoload_unregister('drupal_autoload_class');
spl_autoload_unregister('drupal_autoload_interface');
// The new {blocked_ips} table is used in Drupal 7 to store a list of
Expand All @@ -451,13 +451,8 @@ function update_main() {

// Updates only run reliably if user ID #1 is logged in. For example, node_delete() requires elevated perms in D5/6.
if (!drush_get_context('DRUSH_USER')) {
// Remove after http://drupal.org/node/439236 lands.
require(DRUPAL_ROOT . '/modules/field/field.crud.inc');
require(DRUPAL_ROOT . '/modules/field/field.autoload.inc');

drush_set_option('user', 1);
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_LOGIN);

}

drupal_maintenance_theme();
Expand Down
4 changes: 2 additions & 2 deletions commands/pm/pm.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function pm_module_manage($modules = array(), $enable = TRUE) {
require_once('./'. drupal_get_path('module', 'system') .'/system.module');
}

$module_info = module_rebuild_cache();
$module_info = drush_get_modules();
$enabled = array();
foreach ($module_info as $module_name => $module) {
// In Drupal 5, system_modules() returns NULL for the dependency list of the module if there are no dependencies.
Expand Down Expand Up @@ -274,7 +274,7 @@ function pm_module_manage($modules = array(), $enable = TRUE) {
drupal_form_submit('system_modules', $form_state);
}

$module_info = module_rebuild_cache();
$module_info = drush_get_modules();
foreach ($modules as $module_name) {
if ($enable) {
if ($module_info[$module_name]->status) {
Expand Down
2 changes: 1 addition & 1 deletion includes/command.inc
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ function _drush_find_commandfiles($phase) {
case DRUSH_BOOTSTRAP_DRUPAL_FULL:
// Add enabled module paths. Since we are bootstrapped,
// we can use the Drupal API.
$files = module_rebuild_cache();
$files = drush_get_modules();
foreach ($files as $file) {
if ($file->status) {
$searchpath[] = dirname($file->filename);
Expand Down
2 changes: 1 addition & 1 deletion includes/drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function drush_op($function) {
*
* @see t()
*/
function dt($string, $args = NULL) {
function dt($string, $args = array()) {
if (function_exists('t')) {
return t($string, $args);
}
Expand Down
30 changes: 30 additions & 0 deletions includes/environment.inc
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,33 @@ function drush_valid_db_credentials() {
return TRUE;
}
}

/**
* Get module information for all installed modules. Wrapper for _drush_get_modules().
*
* @return
* An array containing module info for all installed modules or FALSE on error.
*/
function drush_get_modules() {
if(drush_include_engine('drupal', 'environment')){
return _drush_get_modules();
}
else {
return drush_set_error('DRUSH_CORE', dt('Drush was unable to load module information.'));
}
}

/**
* Get theme information for all installed themes. Wrapper for _drush_get_themes().
*
* @return
* An array containing theme info for all installed themes or FALSE on error.
*/
function drush_get_themes() {
if(drush_include_engine('drupal', 'environment')){
return _drush_get_themes();
}
else {
return drush_set_error('DRUSH_CORE', dt('Drush was unable to load theme information.'));
}
}

0 comments on commit 14c7daf

Please sign in to comment.