environment_7.inc

  1. 8.0.x commands/core/drupal/environment_7.inc
  2. 6.x commands/core/drupal/environment_7.inc
  3. 7.x commands/core/drupal/environment_7.inc
  4. 3.x commands/core/drupal/environment_7.inc
  5. master commands/core/drupal/environment_7.inc

Specific functions for a drupal 7 environment. drush_include_engine() magically includes either this file or environment_X.inc depending on which version of drupal drush is called from.

Functions

Namesort descending Description
drush_check_module_dependencies Return dependencies and its status for modules.
drush_get_modules Get complete information for all available modules.
drush_get_named_extensions_list Return a list of extensions from a list of named extensions. Both enabled and disabled/uninstalled extensions are returned.
drush_get_themes Get complete information for all available themes.
drush_get_token
drush_module_dependents Return dependents of modules.
drush_module_disable Disable a list of modules. It is assumed the list contains all dependents not already disabled.
drush_module_enable Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
drush_module_exists Checks that a given module exists and is enabled.
drush_module_implements Determines which modules are implementing a hook.
drush_module_invoke Invokes a hook in a particular module.
drush_module_invoke_all Invokes a hook in all enabled modules that implement it.
drush_module_list Returns a list of enabled modules.
drush_module_uninstall Uninstall a list of modules.
drush_theme_disable Disable a list of themes.
drush_theme_enable Enable a list of themes.
drush_theme_list Returns a list of enabled themes. Use drush_get_themes() if you need to rebuild and include hidden/disabled as well.
drush_url
drush_watchdog_message_types Helper function to obtain the message types based on drupal version.
drush_watchdog_severity_levels Helper function to obtain the severity levels based on Drupal version.
_drush_drupal_required_modules Returns drupal required modules, including modules declared as required dynamically.
_drush_extension_get_name Gets the extension name.
_drush_extension_get_path Gets the extension path.
_drush_extension_get_type Gets the extension type.
_drush_file_private_path
_drush_file_public_path
_drush_theme_admin
_drush_theme_default

File

commands/core/drupal/environment_7.inc
View source
  1. <?php
  2. /**
  3. * @file
  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
  7. * is called from.
  8. */
  9. /**
  10. * Get complete information for all available modules.
  11. *
  12. * @param $include_hidden
  13. * Boolean to indicate whether hidden modules should be excluded or not.
  14. * @return
  15. * An array containing module info for all available modules.
  16. */
  17. function drush_get_modules($include_hidden = TRUE) {
  18. $modules = system_rebuild_module_data();
  19. if (!$include_hidden) {
  20. foreach ($modules as $key => $module) {
  21. if (isset($module->info['hidden'])) {
  22. unset($modules[$key]);
  23. }
  24. }
  25. }
  26. return $modules;
  27. }
  28. /**
  29. * Returns drupal required modules, including modules declared as required dynamically.
  30. */
  31. function _drush_drupal_required_modules($module_info) {
  32. $required = drupal_required_modules();
  33. foreach ($module_info as $name => $module) {
  34. if (isset($module->info['required']) && $module->info['required']) {
  35. $required[] = $name;
  36. }
  37. }
  38. return array_unique($required);
  39. }
  40. /**
  41. * Return dependencies and its status for modules.
  42. *
  43. * @param $modules
  44. * Array of module names
  45. * @param $module_info
  46. * Drupal 'files' array for modules as returned by drush_get_modules().
  47. * @return
  48. * Array with dependencies and status for $modules
  49. */
  50. function drush_check_module_dependencies($modules, $module_info) {
  51. $status = array();
  52. foreach ($modules as $key => $module) {
  53. $dependencies = array_reverse($module_info[$module]->requires);
  54. $unmet_dependencies = array_diff(array_keys($dependencies), array_keys($module_info));
  55. if (!empty($unmet_dependencies)) {
  56. $status[$key]['error'] = array(
  57. 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_NOT_FOUND',
  58. '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)))
  59. );
  60. }
  61. else {
  62. // check for version incompatibility
  63. foreach ($dependencies as $dependency_name => $v) {
  64. $current_version = $module_info[$dependency_name]->info['version'];
  65. $current_version = str_replace(drush_get_drupal_core_compatibility() . '-', '', $current_version);
  66. $incompatibility = drupal_check_incompatibility($v, $current_version);
  67. if (isset($incompatibility)) {
  68. $status[$key]['error'] = array(
  69. 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_VERSION_MISMATCH',
  70. '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))
  71. );
  72. }
  73. }
  74. }
  75. $status[$key]['unmet-dependencies'] = $unmet_dependencies;
  76. $status[$key]['dependencies'] = $dependencies;
  77. }
  78. return $status;
  79. }
  80. /**
  81. * Return dependents of modules.
  82. *
  83. * @param $modules
  84. * Array of module names
  85. * @param $module_info
  86. * Drupal 'files' array for modules as returned by drush_get_modules().
  87. * @return
  88. * Array with dependents for each one of $modules
  89. */
  90. function drush_module_dependents($modules, $module_info) {
  91. $dependents = array();
  92. foreach ($modules as $module) {
  93. $dependents = array_merge($dependents, drupal_map_assoc(array_keys($module_info[$module]->required_by)));
  94. }
  95. return array_unique($dependents);
  96. }
  97. /**
  98. * Returns a list of enabled modules.
  99. *
  100. * This is a simplified version of module_list().
  101. */
  102. function drush_module_list() {
  103. $enabled = array();
  104. $rsc = drush_db_select('system', 'name', 'type=:type AND status=:status', array(':type' => 'module', ':status' => 1));
  105. while ($row = drush_db_result($rsc)) {
  106. $enabled[$row] = $row;
  107. }
  108. return $enabled;
  109. }
  110. /**
  111. * Return a list of extensions from a list of named extensions.
  112. * Both enabled and disabled/uninstalled extensions are returned.
  113. */
  114. function drush_get_named_extensions_list($extensions) {
  115. $result = array();
  116. $rsc = drush_db_select('system', array('name', 'status'), 'name IN (:extensions)', array(':extensions' => $extensions));
  117. while ($row = drush_db_fetch_object($rsc)) {
  118. $result[$row->name] = $row;
  119. }
  120. return $result;
  121. }
  122. /**
  123. * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
  124. *
  125. * @param $modules
  126. * Array of module names
  127. */
  128. function drush_module_enable($modules) {
  129. // The list of modules already have all the dependencies, but they might not
  130. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  131. // Drupal will enable the modules in the correct order.
  132. module_enable($modules);
  133. // Flush all caches.
  134. drupal_flush_all_caches();
  135. }
  136. /**
  137. * Disable a list of modules. It is assumed the list contains all dependents not already disabled.
  138. *
  139. * @param $modules
  140. * Array of module names
  141. */
  142. function drush_module_disable($modules) {
  143. // The list of modules already have all the dependencies, but they might not
  144. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  145. // Drupal will enable the modules in the correct order.
  146. module_disable($modules);
  147. // Flush all caches.
  148. drupal_flush_all_caches();
  149. }
  150. /**
  151. * Uninstall a list of modules.
  152. *
  153. * @param $modules
  154. * Array of module names
  155. */
  156. function drush_module_uninstall($modules) {
  157. require_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
  158. // Break off 8.x functionality when we get another change.
  159. if (drush_drupal_major_version() >= 8) {
  160. module_uninstall($modules);
  161. }
  162. else {
  163. drupal_uninstall_modules($modules);
  164. }
  165. }
  166. /**
  167. * Checks that a given module exists and is enabled.
  168. *
  169. * @see module_exists().
  170. *
  171. */
  172. function drush_module_exists($module) {
  173. return module_exists($module);
  174. }
  175. /**
  176. * Determines which modules are implementing a hook.
  177. *
  178. */
  179. function drush_module_implements($hook, $sort = FALSE, $reset = FALSE) {
  180. return module_implements($hook, $sort, $reset);
  181. }
  182. /**
  183. * Invokes a hook in a particular module.
  184. *
  185. */
  186. function drush_module_invoke($module, $hook) {
  187. $args = func_get_args();
  188. return call_user_func_array('module_invoke', $args);
  189. }
  190. /**
  191. * Invokes a hook in all enabled modules that implement it.
  192. *
  193. */
  194. function drush_module_invoke_all($hook) {
  195. $args = func_get_args();
  196. return call_user_func_array('module_invoke_all', $args);
  197. }
  198. /**
  199. * Returns a list of enabled themes. Use drush_get_themes() if you need to rebuild
  200. * and include hidden/disabled as well.
  201. *
  202. * @return array
  203. * A list of themes keyed by name.
  204. */
  205. function drush_theme_list() {
  206. $enabled = array();
  207. foreach (list_themes() as $key => $info) {
  208. if ($info->status) {
  209. $enabled[$key] = $info;
  210. }
  211. }
  212. return $enabled;
  213. }
  214. /**
  215. * Get complete information for all available themes.
  216. *
  217. * @param $include_hidden
  218. * Boolean to indicate whether hidden themes should be excluded or not.
  219. * @return
  220. * An array containing theme info for all available themes.
  221. */
  222. function drush_get_themes($include_hidden = TRUE) {
  223. $themes = system_rebuild_theme_data();
  224. if (!$include_hidden) {
  225. foreach ($themes as $key => $theme) {
  226. if (isset($theme->info['hidden'])) {
  227. unset($themes[$key]);
  228. }
  229. }
  230. }
  231. return $themes;
  232. }
  233. /**
  234. * Enable a list of themes.
  235. *
  236. * @param $themes
  237. * Array of theme names.
  238. */
  239. function drush_theme_enable($themes) {
  240. theme_enable($themes);
  241. }
  242. /**
  243. * Disable a list of themes.
  244. *
  245. * @param $themes
  246. * Array of theme names.
  247. */
  248. function drush_theme_disable($themes) {
  249. theme_disable($themes);
  250. }
  251. /**
  252. * Helper function to obtain the severity levels based on Drupal version.
  253. *
  254. * This is a copy of watchdog_severity_levels() without t().
  255. *
  256. * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  257. *
  258. * @return
  259. * Array of watchdog severity levels.
  260. */
  261. function drush_watchdog_severity_levels() {
  262. return array(
  263. WATCHDOG_EMERGENCY=> 'emergency',
  264. WATCHDOG_ALERT => 'alert',
  265. WATCHDOG_CRITICAL => 'critical',
  266. WATCHDOG_ERROR => 'error',
  267. WATCHDOG_WARNING => 'warning',
  268. WATCHDOG_NOTICE => 'notice',
  269. WATCHDOG_INFO => 'info',
  270. WATCHDOG_DEBUG => 'debug',
  271. );
  272. }
  273. /**
  274. * Helper function to obtain the message types based on drupal version.
  275. *
  276. * @return
  277. * Array of watchdog message types.
  278. */
  279. function drush_watchdog_message_types() {
  280. return drupal_map_assoc(_dblog_get_message_types());
  281. }
  282. function _drush_theme_default() {
  283. return variable_get('theme_default', 'garland');
  284. }
  285. function _drush_theme_admin() {
  286. return variable_get('admin_theme', drush_theme_get_default());
  287. }
  288. function _drush_file_public_path() {
  289. return variable_get('file_public_path', conf_path() . '/files');
  290. }
  291. function _drush_file_private_path() {
  292. return variable_get('file_private_path', FALSE);
  293. }
  294. /**
  295. * Gets the extension name.
  296. *
  297. * @param $info
  298. * The extension info.
  299. * @return string
  300. * The extension name.
  301. */
  302. function _drush_extension_get_name($info) {
  303. return $info->name;
  304. }
  305. /**
  306. * Gets the extension type.
  307. *
  308. * @param $info
  309. * The extension info.
  310. * @return string
  311. * The extension type.
  312. */
  313. function _drush_extension_get_type($info) {
  314. return $info->type;
  315. }
  316. /**
  317. * Gets the extension path.
  318. *
  319. * @param $info
  320. * The extension info.
  321. * @return string
  322. * The extension path.
  323. */
  324. function _drush_extension_get_path($info) {
  325. return dirname($info->filename);
  326. }
  327. /*
  328. * Wrapper for CSRF token generation.
  329. */
  330. function drush_get_token($value = NULL) {
  331. return drupal_get_token($value);
  332. }
  333. /*
  334. * Wrapper for _url().
  335. */
  336. function drush_url($path = NULL, array $options = array()) {
  337. return url($path, $options);
  338. }