4 * Specific functions for a drupal 7 environment.
5 * drush_include_engine() magically includes either this file
6 * or environment_X.inc depending on which version of drupal drush
11 * Get complete information for all available modules.
13 * @param $include_hidden
14 * Boolean to indicate whether hidden modules should be excluded or not.
16 * An array containing module info for all available modules.
18 function drush_get_modules($include_hidden = TRUE) {
19 $modules = system_rebuild_module_data();
20 if (!$include_hidden) {
21 foreach ($modules as $key => $module) {
22 if (isset($module->info['hidden'])) {
23 unset($modules[$key]);
32 * Returns drupal required modules, including modules declared as required dynamically.
34 function _drush_drupal_required_modules($module_info) {
35 $required = drupal_required_modules();
36 foreach ($module_info as $name => $module) {
37 if (isset($module->info['required']) && $module->info['required']) {
41 return array_unique($required);
45 * Return dependencies and its status for modules.
48 * Array of module names
50 * Drupal 'files' array for modules as returned by drush_get_modules().
52 * Array with dependencies and status for $modules
54 function drush_check_module_dependencies($modules, $module_info) {
56 foreach ($modules as $key => $module) {
57 $dependencies = array_reverse($module_info[$module]->requires);
58 $unmet_dependencies = array_diff(array_keys($dependencies), array_keys($module_info));
59 if (!empty($unmet_dependencies)) {
60 $status[$key]['error'] = array(
61 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_NOT_FOUND',
62 'message' => dt('Module !module cannot be enabled because it depends on the following modules which could not be found: !unmet_dependencies', array('!module' => $module, '!unmet_dependencies' => implode(',', $unmet_dependencies)))
66 // check for version incompatibility
67 foreach ($dependencies as $dependency_name => $v) {
68 $current_version = $module_info[$dependency_name]->info['version'];
69 $current_version = str_replace(drush_get_drupal_core_compatibility() . '-', '', $current_version);
70 $incompatibility = drupal_check_incompatibility($v, $current_version);
71 if (isset($incompatibility)) {
72 $status[$key]['error'] = array(
73 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_VERSION_MISMATCH',
74 'message' => dt('Module !module cannot be enabled because it depends on !dependency !required_version but !current_version is available', array('!module' => $module, '!dependency' => $dependency_name, '!required_version' => $incompatibility, '!current_version' => $current_version))
79 $status[$key]['unmet-dependencies'] = $unmet_dependencies;
80 $status[$key]['dependencies'] = $dependencies;
87 * Return dependents of modules.
90 * Array of module names
92 * Drupal 'files' array for modules as returned by drush_get_modules().
94 * Array with dependents for each one of $modules
96 function drush_module_dependents($modules, $module_info) {
97 $dependents = array();
98 foreach ($modules as $module) {
99 $dependents = array_merge($dependents, drupal_map_assoc(array_keys($module_info[$module]->required_by)));
102 return array_unique($dependents);
106 * Returns a list of enabled modules.
108 * This is a simplified version of module_list().
110 function drush_module_list() {
112 $rsc = drush_db_select('system', 'name', 'type=:type AND status=:status', array(':type' => 'module', ':status' => 1));
113 while ($row = drush_db_result($rsc)) {
114 $enabled[$row] = $row;
121 * Return a list of extensions from a list of named extensions.
122 * Both enabled and disabled/uninstalled extensions are returned.
124 function drush_get_named_extensions_list($extensions) {
126 $rsc = drush_db_select('system', array('name', 'status'), 'name IN (:extensions)', array(':extensions' => $extensions));
127 while ($row = drush_db_fetch_object($rsc)) {
128 $result[$row->name] = $row;
134 * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
137 * Array of module names
139 function drush_module_enable($modules) {
140 // The list of modules already have all the dependencies, but they might not
141 // be in the correct order. Still pass $enable_dependencies = TRUE so that
142 // Drupal will enable the modules in the correct order.
143 module_enable($modules);
145 drupal_flush_all_caches();
149 * Disable a list of modules. It is assumed the list contains all dependents not already disabled.
152 * Array of module names
154 function drush_module_disable($modules) {
155 // The list of modules already have all the dependencies, but they might not
156 // be in the correct order. Still pass $enable_dependencies = TRUE so that
157 // Drupal will enable the modules in the correct order.
158 module_disable($modules);
160 drupal_flush_all_caches();
164 * Uninstall a list of modules.
167 * Array of module names
169 function drush_module_uninstall($modules) {
170 require_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
171 // Break off 8.x functionality when we get another change.
172 if (drush_drupal_major_version() >= 8) {
173 module_uninstall($modules);
176 drupal_uninstall_modules($modules);
181 * Checks that a given module exists and is enabled.
183 * @see module_exists().
186 function drush_module_exists($module) {
187 return module_exists($module);
191 * Determines which modules are implementing a hook.
194 function drush_module_implements($hook, $sort = FALSE, $reset = FALSE) {
195 return module_implements($hook, $sort, $reset);
199 * Invokes a hook in a particular module.
202 function drush_module_invoke($module, $hook) {
203 $args = func_get_args();
204 return call_user_func_array('module_invoke', $args);
208 * Invokes a hook in all enabled modules that implement it.
211 function drush_module_invoke_all($hook) {
212 $args = func_get_args();
213 return call_user_func_array('module_invoke_all', $args);
217 * Returns a list of enabled themes. Use drush_get_themes() if you need to rebuild
218 * and include hidden/disabled as well.
221 * A list of themes keyed by name.
223 function drush_theme_list() {
225 foreach (list_themes() as $key => $info) {
227 $enabled[$key] = $info;
234 * Get complete information for all available themes.
236 * @param $include_hidden
237 * Boolean to indicate whether hidden themes should be excluded or not.
239 * An array containing theme info for all available themes.
241 function drush_get_themes($include_hidden = TRUE) {
242 $themes = system_rebuild_theme_data();
243 if (!$include_hidden) {
244 foreach ($themes as $key => $theme) {
245 if (isset($theme->info['hidden'])) {
246 unset($themes[$key]);
255 * Enable a list of themes.
258 * Array of theme names.
260 function drush_theme_enable($themes) {
261 theme_enable($themes);
265 * Disable a list of themes.
268 * Array of theme names.
270 function drush_theme_disable($themes) {
271 theme_disable($themes);
275 * Helper function to obtain the severity levels based on Drupal version.
277 * This is a copy of watchdog_severity_levels() without t().
279 * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
282 * Array of watchdog severity levels.
284 function drush_watchdog_severity_levels() {
286 WATCHDOG_EMERGENCY=> 'emergency',
287 WATCHDOG_ALERT => 'alert',
288 WATCHDOG_CRITICAL => 'critical',
289 WATCHDOG_ERROR => 'error',
290 WATCHDOG_WARNING => 'warning',
291 WATCHDOG_NOTICE => 'notice',
292 WATCHDOG_INFO => 'info',
293 WATCHDOG_DEBUG => 'debug',
298 * Helper function to obtain the message types based on drupal version.
301 * Array of watchdog message types.
303 function drush_watchdog_message_types() {
304 return drupal_map_assoc(_dblog_get_message_types());
307 function _drush_theme_default() {
308 return variable_get('theme_default', 'garland');
311 function _drush_theme_admin() {
312 return variable_get('admin_theme', drush_theme_get_default());
315 function _drush_file_public_path() {
316 return variable_get('file_public_path', conf_path() . '/files');
319 function _drush_file_private_path() {
320 return variable_get('file_private_path', FALSE);
324 * Gets the extension name.
327 * The extension info.
329 * The extension name.
331 function _drush_extension_get_name($info) {
336 * Gets the extension type.
339 * The extension info.
341 * The extension type.
343 function _drush_extension_get_type($info) {
348 * Gets the extension path.
351 * The extension info.
353 * The extension path.
355 function _drush_extension_get_path($info) {
356 return dirname($info->filename);
360 * Wrapper for CSRF token generation.
362 function drush_get_token($value = NULL) {
363 return drupal_get_token($value);
367 * Wrapper for _url().
369 function drush_url($path = NULL, array $options = array()) {
370 return url($path, $options);
374 * Output a Drupal render array, object or plain string as plain text.
376 * @param string $data
380 * The plain-text representation of the input.
382 function drush_render($data) {
383 if (is_array($data)) {
384 $data = drupal_render($data);
387 $data = drupal_html_to_text($data);