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_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. * Get complete information for all available themes.
  200. *
  201. * @param $include_hidden
  202. * Boolean to indicate whether hidden themes should be excluded or not.
  203. * @return
  204. * An array containing theme info for all available themes.
  205. */
  206. function drush_get_themes($include_hidden = TRUE) {
  207. $themes = system_rebuild_theme_data();
  208. if (!$include_hidden) {
  209. foreach ($themes as $key => $theme) {
  210. if (isset($theme->info['hidden'])) {
  211. unset($themes[$key]);
  212. }
  213. }
  214. }
  215. return $themes;
  216. }
  217. /**
  218. * Enable a list of themes.
  219. *
  220. * @param $themes
  221. * Array of theme names.
  222. */
  223. function drush_theme_enable($themes) {
  224. theme_enable($themes);
  225. }
  226. /**
  227. * Disable a list of themes.
  228. *
  229. * @param $themes
  230. * Array of theme names.
  231. */
  232. function drush_theme_disable($themes) {
  233. theme_disable($themes);
  234. }
  235. /**
  236. * Helper function to obtain the severity levels based on Drupal version.
  237. *
  238. * This is a copy of watchdog_severity_levels() without t().
  239. *
  240. * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  241. *
  242. * @return
  243. * Array of watchdog severity levels.
  244. */
  245. function drush_watchdog_severity_levels() {
  246. return array(
  247. WATCHDOG_EMERGENCY=> 'emergency',
  248. WATCHDOG_ALERT => 'alert',
  249. WATCHDOG_CRITICAL => 'critical',
  250. WATCHDOG_ERROR => 'error',
  251. WATCHDOG_WARNING => 'warning',
  252. WATCHDOG_NOTICE => 'notice',
  253. WATCHDOG_INFO => 'info',
  254. WATCHDOG_DEBUG => 'debug',
  255. );
  256. }
  257. /**
  258. * Helper function to obtain the message types based on drupal version.
  259. *
  260. * @return
  261. * Array of watchdog message types.
  262. */
  263. function drush_watchdog_message_types() {
  264. return drupal_map_assoc(_dblog_get_message_types());
  265. }
  266. function _drush_theme_default() {
  267. return variable_get('theme_default', 'garland');
  268. }
  269. function _drush_theme_admin() {
  270. return variable_get('admin_theme', drush_theme_get_default());
  271. }
  272. function _drush_file_public_path() {
  273. return variable_get('file_public_path', conf_path() . '/files');
  274. }
  275. function _drush_file_private_path() {
  276. return variable_get('file_private_path', FALSE);
  277. }
  278. /**
  279. * Gets the extension name.
  280. *
  281. * @param $info
  282. * The extension info.
  283. * @return string
  284. * The extension name.
  285. */
  286. function _drush_extension_get_name($info) {
  287. return $info->name;
  288. }
  289. /**
  290. * Gets the extension type.
  291. *
  292. * @param $info
  293. * The extension info.
  294. * @return string
  295. * The extension type.
  296. */
  297. function _drush_extension_get_type($info) {
  298. return $info->type;
  299. }
  300. /**
  301. * Gets the extension path.
  302. *
  303. * @param $info
  304. * The extension info.
  305. * @return string
  306. * The extension path.
  307. */
  308. function _drush_extension_get_path($info) {
  309. return dirname($info->filename);
  310. }
  311. /*
  312. * Wrapper for CSRF token generation.
  313. */
  314. function drush_get_token($value = NULL) {
  315. return drupal_get_token($value);
  316. }
  317. /*
  318. * Wrapper for _url().
  319. */
  320. function drush_url($path = NULL, array $options = array()) {
  321. return url($path, $options);
  322. }