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