environment_6.inc

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

Specific functions for a drupal 6 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_system_modules_form_submit Submit the system modules form.
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 their dependencies.
_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_6.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Specific functions for a drupal 6 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. * We need to set the type for those modules that are not already in the system table.
  13. *
  14. * @param $include_hidden
  15. * Boolean to indicate whether hidden modules should be excluded or not.
  16. * @return
  17. * An array containing module info for all available modules.
  18. */
  19. function drush_get_modules($include_hidden = TRUE) {
  20. $modules = module_rebuild_cache();
  21. foreach ($modules as $key => $module) {
  22. if (!isset($module->type)) {
  23. $module->type = 'module';
  24. }
  25. if ((!$include_hidden) && isset($module->info['hidden']) && ($module->info['hidden'])) {
  26. unset($modules[$key]);
  27. }
  28. }
  29. return $modules;
  30. }
  31. /**
  32. * Returns drupal required modules, including their dependencies.
  33. *
  34. * A module may alter other module's .info to set a dependency on it.
  35. * See for example http://drupal.org/project/phpass
  36. */
  37. function _drush_drupal_required_modules($module_info) {
  38. $required = drupal_required_modules();
  39. foreach ($required as $module) {
  40. $required = array_merge($required, $module_info[$module]->info['dependencies']);
  41. }
  42. return $required;
  43. }
  44. /**
  45. * Return dependencies and its status for modules.
  46. *
  47. * @param $modules
  48. * Array of module names
  49. * @param $module_info
  50. * Drupal 'files' array for modules as returned by drush_get_modules().
  51. * @return
  52. * Array with dependencies and status for $modules
  53. */
  54. function drush_check_module_dependencies($modules, $module_info) {
  55. $status = array();
  56. foreach ($modules as $key => $module) {
  57. $dependencies = array_reverse($module_info[$module]->info['dependencies']);
  58. $unmet_dependencies = array_diff($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)))
  63. );
  64. }
  65. $status[$key]['unmet-dependencies'] = $unmet_dependencies;
  66. $status[$key]['dependencies'] = $dependencies;
  67. }
  68. return $status;
  69. }
  70. /**
  71. * Return dependents of modules.
  72. *
  73. * @param $modules
  74. * Array of module names
  75. * @param $module_info
  76. * Drupal 'files' array for modules as returned by drush_get_modules().
  77. * @return
  78. * Array with dependents for each one of $modules
  79. */
  80. function drush_module_dependents($modules, $module_info) {
  81. $dependents = array();
  82. foreach ($modules as $module) {
  83. $dependents = array_merge($dependents, $module_info[$module]->info['dependents']);
  84. }
  85. return array_unique($dependents);
  86. }
  87. /**
  88. * Returns a list of enabled modules.
  89. *
  90. * This is a simplified version of module_list().
  91. */
  92. function drush_module_list() {
  93. $enabled = array();
  94. $rsc = drush_db_select('system', 'name', 'type=:type AND status=:status', array(':type' => 'module', ':status' => 1));
  95. while ($row = drush_db_result($rsc)) {
  96. $enabled[$row] = $row;
  97. }
  98. return $enabled;
  99. }
  100. /**
  101. * Return a list of extensions from a list of named extensions.
  102. * Both enabled and disabled/uninstalled extensions are returned.
  103. */
  104. function drush_get_named_extensions_list($extensions) {
  105. $result = array();
  106. $rsc = drush_db_select('system', array('name', 'status'), 'name IN (:extensions)', array(':extensions' => $extensions));
  107. while ($row = drush_db_fetch_object($rsc)) {
  108. $result[$row->name] = $row;
  109. }
  110. return $result;
  111. }
  112. /**
  113. * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
  114. *
  115. * @param $modules
  116. * Array of module names
  117. */
  118. function drush_module_enable($modules) {
  119. // Try to install modules previous to enabling.
  120. foreach ($modules as $module) {
  121. _drupal_install_module($module);
  122. }
  123. module_enable($modules);
  124. drush_system_modules_form_submit();
  125. }
  126. /**
  127. * Disable a list of modules. It is assumed the list contains all dependents not already disabled.
  128. *
  129. * @param $modules
  130. * Array of module names
  131. */
  132. function drush_module_disable($modules) {
  133. module_disable($modules, FALSE);
  134. drush_system_modules_form_submit();
  135. }
  136. /**
  137. * Uninstall a list of modules.
  138. *
  139. * @param $modules
  140. * Array of module names
  141. */
  142. function drush_module_uninstall($modules) {
  143. require_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
  144. foreach ($modules as $module) {
  145. drupal_uninstall_module($module);
  146. }
  147. }
  148. /**
  149. * Checks that a given module exists and is enabled.
  150. *
  151. * @see module_exists().
  152. *
  153. */
  154. function drush_module_exists($module) {
  155. return module_exists($module);
  156. }
  157. /**
  158. * Determines which modules are implementing a hook.
  159. *
  160. */
  161. function drush_module_implements($hook, $sort = FALSE, $reset = FALSE) {
  162. return module_implements($hook, $sort, $reset);
  163. }
  164. /**
  165. * Invokes a hook in a particular module.
  166. *
  167. */
  168. function drush_module_invoke($module, $hook) {
  169. $args = func_get_args();
  170. return call_user_func_array('module_invoke', $args);
  171. }
  172. /**
  173. * Invokes a hook in all enabled modules that implement it.
  174. *
  175. */
  176. function drush_module_invoke_all($hook) {
  177. $args = func_get_args();
  178. return call_user_func_array('module_invoke_all', $args);
  179. }
  180. /**
  181. * Submit the system modules form.
  182. *
  183. * The modules should already be fully enabled/disabled before calling this
  184. * function. Calling this function just makes sure any activities triggered by
  185. * the form submit (such as admin_role) are completed.
  186. */
  187. function drush_system_modules_form_submit() {
  188. $active_modules = array();
  189. foreach (drush_get_modules(FALSE) as $key => $module) {
  190. if ($module->status == 1) {
  191. $active_modules[$key] = $key;
  192. }
  193. }
  194. module_load_include('inc', 'system', 'system.admin');
  195. $form_state = array('values' => array('status' => $active_modules));
  196. drupal_execute('system_modules', $form_state);
  197. }
  198. /**
  199. * Get complete information for all available themes.
  200. *
  201. * We need to set the type for those themes that are not already in the system table.
  202. *
  203. * @param $include_hidden
  204. * Boolean to indicate whether hidden themes should be excluded or not.
  205. * @return
  206. * An array containing theme info for all available themes.
  207. */
  208. function drush_get_themes($include_hidden = TRUE) {
  209. $themes = system_theme_data();
  210. foreach ($themes as $key => $theme) {
  211. if (!isset($theme->type)) {
  212. $theme->type = 'theme';
  213. }
  214. if ((!$include_hidden) && isset($theme->info['hidden']) && ($theme->info['hidden'])) {
  215. unset($themes[$key]);
  216. }
  217. }
  218. return $themes;
  219. }
  220. /**
  221. * Enable a list of themes.
  222. *
  223. * This function is based on system_themes_form_submit().
  224. *
  225. * @see system_themes_form_submit()
  226. * @param $themes
  227. * Array of theme names.
  228. */
  229. function drush_theme_enable($themes) {
  230. drupal_clear_css_cache();
  231. foreach ($themes as $theme) {
  232. system_initialize_theme_blocks($theme);
  233. }
  234. db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' AND name IN (".db_placeholders($themes, 'text').")", $themes);
  235. list_themes(TRUE);
  236. menu_rebuild();
  237. module_invoke('locale', 'system_update', $themes);
  238. }
  239. /**
  240. * Disable a list of themes.
  241. *
  242. * This function is based on system_themes_form_submit().
  243. *
  244. * @see system_themes_form_submit()
  245. * @param $themes
  246. * Array of theme names.
  247. */
  248. function drush_theme_disable($themes) {
  249. drupal_clear_css_cache();
  250. db_query("UPDATE {system} SET status = 0 WHERE type = 'theme' AND name IN (".db_placeholders($themes, 'text').")", $themes);
  251. list_themes(TRUE);
  252. menu_rebuild();
  253. drupal_rebuild_theme_registry();
  254. module_invoke('locale', 'system_update', $themes);
  255. }
  256. /**
  257. * Helper function to obtain the severity levels based on Drupal version.
  258. *
  259. * This is a copy of watchdog_severity_levels() without t().
  260. *
  261. * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  262. *
  263. * @return
  264. * Array of watchdog severity levels.
  265. */
  266. function drush_watchdog_severity_levels() {
  267. return array(
  268. WATCHDOG_EMERG => 'emergency',
  269. WATCHDOG_ALERT => 'alert',
  270. WATCHDOG_CRITICAL => 'critical',
  271. WATCHDOG_ERROR => 'error',
  272. WATCHDOG_WARNING => 'warning',
  273. WATCHDOG_NOTICE => 'notice',
  274. WATCHDOG_INFO => 'info',
  275. WATCHDOG_DEBUG => 'debug',
  276. );
  277. }
  278. /**
  279. * Helper function to obtain the message types based on drupal version.
  280. *
  281. * @return
  282. * Array of watchdog message types.
  283. */
  284. function drush_watchdog_message_types() {
  285. return drupal_map_assoc(_dblog_get_message_types());
  286. }
  287. function _drush_theme_default() {
  288. return variable_get('theme_default', 'garland');
  289. }
  290. function _drush_theme_admin() {
  291. return variable_get('admin_theme', drush_theme_get_default());
  292. }
  293. function _drush_file_public_path() {
  294. if (function_exists('file_directory_path')) {
  295. return file_directory_path();
  296. }
  297. }
  298. function _drush_file_private_path() {
  299. // @todo
  300. }
  301. /**
  302. * Gets the extension name.
  303. *
  304. * @param $info
  305. * The extension info.
  306. * @return string
  307. * The extension name.
  308. */
  309. function _drush_extension_get_name($info) {
  310. return $info->name;
  311. }
  312. /**
  313. * Gets the extension type.
  314. *
  315. * @param $info
  316. * The extension info.
  317. * @return string
  318. * The extension type.
  319. */
  320. function _drush_extension_get_type($info) {
  321. return $info->type;
  322. }
  323. /**
  324. * Gets the extension path.
  325. *
  326. * @param $info
  327. * The extension info.
  328. * @return string
  329. * The extension path.
  330. */
  331. function _drush_extension_get_path($info) {
  332. return dirname($info->filename);
  333. }
  334. /*
  335. * Wrapper for CSRF token generation.
  336. */
  337. function drush_get_token($value = NULL) {
  338. return drupal_get_token($value);
  339. }
  340. /*
  341. * Wrapper for _url().
  342. */
  343. function drush_url($path = NULL, $options = array()) {
  344. return url($path, $options);
  345. }