core.drush.inc

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

Core drush commands.

Functions

Namesort descending Description
core_core_config_complete Command argument complete callback.
core_core_rsync_complete Command argument complete callback.
core_drush_command Implementation of hook_drush_command().
core_drush_engine_drupal Implements hook_drush_engine_ENGINE_TYPE().
core_drush_engine_type_info Implementation of hook_drush_engine_type_info().
core_drush_help Implementation of hook_drush_help().
core_help_complete Command argument complete callback.
core_site_install_complete Command argument complete callback.
drush_core_batch_process Process sets from the specified batch.
drush_core_config Command callback. Edit drushrc and alias files.
drush_core_config_load
drush_core_cron Command callback. Runs all cron hooks.
drush_core_drupal_directory Command callback.
drush_core_execute Command callback. Execute specified shell code. Often used by shell aliases that start with !.
drush_core_global_options
drush_core_php_eval
drush_core_php_script Command callback. Runs "naked" php scripts and drush "shebang" scripts ("#!/usr/bin/env drush").
drush_core_quick_drupal Callback for core-quick-drupal command.
drush_core_quick_drupal_options Include options and engines for core-quick-drupal command, aggregated from other command options that are available. We prefix option descriptons, to make the long list more navigable.
drush_core_requirements Command callback. Provides information from the 'Status Reports' admin page.
drush_core_status Command callback. Provides a birds-eye view of the current Drupal installation.
drush_core_updatedb Command handler. Execute update.php code from drush.
drush_core_updatedb_batch_process Process outstanding updates during updatedb.
drush_core_updatedb_status Command handler. List pending DB updates.
drush_core_version Called for `drush version` or `drush --version`
_core_path_aliases
_core_site_credentials
_core_site_credential_table
_core_site_status_table
_drush_core_config_php_ini_files
_drush_core_directory Given a target (e.g. @site:%modules), return the evaluated directory path.
_drush_core_eval_shebang_script Evaluate a script that begins with #!drush php-script
_drush_core_execute_cmd Helper function for drush_core_execute: run one shell command
_drush_core_is_named_in_array
_drush_core_status_format_table_data

File

commands/core/core.drush.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Core drush commands.
  5. */
  6. /**
  7. * Implementation of hook_drush_command().
  8. *
  9. * In this hook, you specify which commands your
  10. * drush module makes available, what it does and
  11. * description.
  12. *
  13. * Notice how this structure closely resembles how
  14. * you define menu hooks.
  15. *
  16. * @return
  17. * An associative array describing your command(s).
  18. */
  19. function core_drush_command() {
  20. $items = array();
  21. $items['help'] = array(
  22. 'description' => 'Print this help message. See `drush help help` for more options.',
  23. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
  24. 'allow-additional-options' => TRUE,
  25. 'options' => array(
  26. 'sort' => 'Sort commands in alphabetical order. Drush waits for full bootstrap before printing any commands when this option is used.',
  27. 'filter' => array(
  28. 'description' => 'Restrict command list to those commands defined in the specified file. Omit value to choose from a list of names.',
  29. 'example-value' => 'category',
  30. 'value' => 'optional',
  31. ),
  32. 'format' => 'Format to output . Allowed values are: json, var_export, html.',
  33. 'html' => 'Print help for all commands in HTML format. Deprecated - see --format option.',
  34. 'pipe' => 'A list of available commands, one per line.',
  35. ),
  36. 'arguments' => array(
  37. 'command' => 'A command name, or command alias.',
  38. ),
  39. 'examples' => array(
  40. 'drush' => 'List all commands.',
  41. 'drush --filter=devel_generate' => 'Show only commands defined in devel_generate.drush.inc',
  42. 'drush help pm-download' => 'Show help for one command.',
  43. 'drush help dl' => 'Show help for one command using an alias.',
  44. ),
  45. 'topics' => array('docs-readme'),
  46. );
  47. $items['version'] = array(
  48. 'description' => 'Show drush version.',
  49. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
  50. 'options' => array(
  51. 'pipe' => 'Print just the version number, and nothing else.',
  52. ),
  53. 'outputformat' => array(
  54. 'default' => 'key-value',
  55. 'pipe-format' => 'string',
  56. 'label' => 'Drush Version',
  57. 'output-data-type' => 'format-single',
  58. ),
  59. );
  60. $items['core-cron'] = array(
  61. 'description' => 'Run all cron hooks in all active modules for specified site.',
  62. 'aliases' => array('cron'),
  63. 'topics' => array('docs-cron'),
  64. );
  65. $items['updatedb'] = array(
  66. 'description' => 'Apply any database updates required (as with running update.php).',
  67. 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_SITE,
  68. 'aliases' => array('updb'),
  69. );
  70. $items['updatedb-status'] = array(
  71. 'description' => 'List any pending database updates.',
  72. 'outputformat' => array(
  73. 'default' => 'table',
  74. 'pipe-format' => 'csv',
  75. 'field-labels' => array('module' => 'Module', 'update_id' => 'Update ID', 'description' => 'Description'),
  76. 'fields-default' => array('module', 'update_id', 'description'),
  77. 'output-data-type' => 'format-table',
  78. ),
  79. 'aliases' => array('updbst'),
  80. );
  81. $items['core-config'] = array(
  82. 'description' => 'Edit drushrc, site alias, and Drupal settings.php files.',
  83. 'bootstrap' => DRUSH_BOOTSTRAP_MAX,
  84. 'arguments' => array(
  85. 'filter' => 'A substring for filtering the list of files. Omit this argument to choose from loaded files.',
  86. ),
  87. 'options' => array(
  88. 'bg' => 'Run editor in the background. Does not work with editors such as `vi` that run in the terminal.',
  89. ),
  90. 'examples' => array(
  91. 'drush core-config' => 'Pick from a list of config/alias/settings files. Open selected in editor.',
  92. 'drush --bg core-config' => 'Return to shell prompt as soon as the editor window opens.',
  93. 'drush core-config etc' => 'Edit the global configuration file.',
  94. 'drush core-config demo.alia' => 'Edit a particular alias file.',
  95. 'drush core-config sett' => 'Edit settings.php for the current Drupal site.',
  96. 'drush core-config --choice=2' => 'Edit the second file in the choice list.',
  97. ),
  98. 'aliases' => array('conf', 'config'),
  99. );
  100. $items['core-status'] = array(
  101. 'description' => 'Provides a birds-eye view of the current Drupal installation, if any.',
  102. 'bootstrap' => DRUSH_BOOTSTRAP_MAX,
  103. 'aliases' => array('status', 'st'),
  104. 'examples' => array(
  105. 'drush core-status version' => 'Show all status lines that contain version information.',
  106. 'drush core-status --pipe' => 'A list key=value items separated by line breaks.',
  107. 'drush core-status drush-version --pipe' => 'Emit just the drush version with no label.',
  108. 'drush core-status config-active --pipe' => 'Emit just the active Config directory with no label.',
  109. ),
  110. 'arguments' => array(
  111. 'item' => 'Optional. The status item line(s) to display.',
  112. ),
  113. 'options' => array(
  114. 'show-passwords' => 'Show database password.',
  115. 'full' => 'Show all file paths and drush aliases in the report, even if there are a lot.',
  116. 'project' => array(
  117. 'description' => 'One or more projects that should be added to the path list',
  118. 'example-value' => 'foo,bar',
  119. ),
  120. ),
  121. 'outputformat' => array(
  122. 'default' => 'key-value',
  123. 'pipe-format' => 'json',
  124. 'field-labels' => array('drupal-version' => 'Drupal version', 'uri' => 'Site URI', 'db-driver' => 'Database driver', 'db-host' => 'Database hostname', 'db-username' => 'Database username', 'db-password' => 'Database password', 'db-name' => 'Database name', 'db-status' => 'Database', 'bootstrap' => 'Drupal bootstrap', 'user' => 'Drupal user', 'theme' => 'Default theme', 'admin-theme' => 'Administration theme', 'php-bin' => 'PHP executable', 'php-conf' => 'PHP configuration', 'php-os' => 'PHP OS', 'drush-version' => 'Drush version', 'drush-conf' => 'Drush configuration', 'drush-alias-files' => 'Drush alias files', 'root' => 'Drupal root', 'site-path' => 'Site path', 'root' => 'Drupal root', 'site' => 'Site path', 'themes' => 'Themes path', 'modules' => 'Modules path', 'files' => 'File directory path', 'private' => 'Private file directory path', 'temp' => 'Temporary file directory path', 'config-active' => 'Active config directory path', 'config-staging' => 'Staging config directory path', 'files-path' => 'File directory path', 'temp-path' => 'Temporary file directory path', '%paths' => 'Other paths'),
  125. 'formatted-filter' => '_drush_core_status_format_table_data',
  126. 'private-fields' => 'db-password',
  127. 'simplify-single' => TRUE,
  128. 'table-metadata' => array(
  129. 'list-separator' => ' ',
  130. ),
  131. 'output-data-type' => 'format-list',
  132. ),
  133. 'topics' => array('docs-readme'),
  134. );
  135. $items['core-requirements'] = array(
  136. 'description' => 'Provides information about things that may be wrong in your Drupal installation, if any.',
  137. 'aliases' => array('status-report','rq'),
  138. 'examples' => array(
  139. 'drush core-requirements' => 'Show all status lines from the Status Report admin page.',
  140. 'drush core-requirements --severity=2' => 'Show only the red lines from the Status Report admin page.',
  141. 'drush core-requirements --pipe' => 'Print out a short report in JSON format, where severity 2=error, 1=warning, and 0/-1=OK',
  142. ),
  143. 'options' => array(
  144. 'severity' => array(
  145. 'description' => 'Only show status report messages with a severity greater than or equal to the specified value.',
  146. 'value' => 'required',
  147. 'example-value' => '3',
  148. ),
  149. 'ignore' => 'Comma-separated list of requirements to remove from output. Run with --pipe to see key values to use.',
  150. ),
  151. 'outputformat' => array(
  152. 'default' => 'table',
  153. 'pipe-format' => 'json',
  154. 'field-labels' => array('title' => 'Title', 'severity' => 'Severity', 'sid' => 'SID', 'description' => 'Description', 'value' => 'Summary', 'reason' => 'Reason', 'weight' => 'Weight'),
  155. 'fields-default' => array('title', 'severity', 'description'),
  156. 'column-widths' => array('severity' => 8),
  157. 'concatenate-columns' => array('description' => array('value', 'description')),
  158. 'strip-tags' => TRUE,
  159. 'ini-item' => 'sid',
  160. 'key-value-item' => 'severity',
  161. 'list-metadata' => array(
  162. 'list-item' => 'severity',
  163. ),
  164. 'output-data-type' => 'format-table',
  165. ),
  166. );
  167. $items['php-eval'] = array(
  168. 'description' => 'Evaluate arbitrary php code after bootstrapping Drupal (if available).',
  169. 'examples' => array(
  170. 'drush php-eval "variable_set(\'hello\', \'world\');"' => 'Sets the hello variable using Drupal API.',
  171. ),
  172. 'arguments' => array(
  173. 'code' => 'PHP code',
  174. ),
  175. 'required-arguments' => TRUE,
  176. 'allow-additional-options' => TRUE,
  177. 'bootstrap' => DRUSH_BOOTSTRAP_MAX,
  178. 'aliases' => array('eval', 'ev'),
  179. 'outputformat' => array(
  180. 'default' => 'var_export',
  181. ),
  182. );
  183. $items['php-script'] = array(
  184. 'description' => "Run php script(s).",
  185. 'examples' => array(
  186. 'drush php-script scratch' => 'Run scratch.php script. See commands/core directory.',
  187. 'drush php-script example --script-path=/path/to/scripts:/another/path' => 'Run script from specified paths',
  188. 'drush php-script' => 'List all available scripts.',
  189. '' => '',
  190. "#!/usr/bin/env drush\n<?php\nvariable_set('key', drush_shift());" => "Execute php code with a full Drupal bootstrap directly from a shell script.",
  191. ),
  192. 'arguments' => array(
  193. 'filename' => 'Optional. The file you wish to execute (without extension). If omitted, list files ending in .php in the current working directory and specified script-path. Some might not be real drush scripts. Beware.',
  194. ),
  195. 'options' => array(
  196. 'script-path' => array(
  197. 'description' => "Additional paths to search for scripts, separated by : (Unix-based systems) or ; (Windows).",
  198. 'example-value' => '~/scripts',
  199. ),
  200. ),
  201. 'allow-additional-options' => TRUE,
  202. 'bootstrap' => DRUSH_BOOTSTRAP_MAX,
  203. 'aliases' => array('scr'),
  204. 'topics' => array('docs-examplescript', 'docs-scripts'),
  205. );
  206. $items['core-execute'] = array(
  207. 'description' => 'Execute a shell command. Usually used with a site alias.',
  208. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
  209. 'arguments' => array(
  210. 'command' => 'The shell command to be executed.',
  211. ),
  212. 'options' => drush_shell_exec_proc_build_options(),
  213. 'required-arguments' => TRUE,
  214. 'allow-additional-options' => TRUE,
  215. 'handle-remote-commands' => TRUE,
  216. 'strict-option-handling' => TRUE,
  217. 'examples' => array(
  218. 'drush core-execute git pull origin rebase' => 'Retrieve latest code from git',
  219. ),
  220. 'aliases' => array('exec', 'execute'),
  221. 'topics' => array('docs-aliases'),
  222. );
  223. $items['core-rsync'] = array(
  224. 'description' => 'Rsync the Drupal tree to/from another server using ssh.',
  225. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
  226. 'arguments' => array(
  227. 'source' => 'May be rsync path or site alias. See rsync documentation and example.aliases.drushrc.php.',
  228. 'destination' => 'May be rsync path or site alias. See rsync documentation and example.aliases.drushrc.php.',
  229. ),
  230. 'options' => array(
  231. 'mode' => 'The unary flags to pass to rsync; --mode=rultz implies rsync -rultz. Default is -akz.',
  232. 'exclude-conf' => 'Excludes settings.php from being rsynced. Default.',
  233. 'include-conf' => 'Allow settings.php to be rsynced. Default is to exclude settings.php.',
  234. 'include-vcs' => 'Include special version control directories (e.g. .svn). Default is to exclude vcs files.',
  235. 'exclude-files' => 'Exclude the files directory.',
  236. 'exclude-sites' => 'Exclude all directories in "sites/" except for "sites/all".',
  237. 'exclude-other-sites' => 'Exclude all directories in "sites/" except for "sites/all" and the site directory for the site being synced. Note: if the site directory is different between the source and destination, use --exclude-sites followed by "drush rsync @from:%site @to:%site"',
  238. 'exclude-paths' => 'List of paths to exclude, seperated by : (Unix-based systems) or ; (Windows).',
  239. 'include-paths' => 'List of paths to include, seperated by : (Unix-based systems) or ; (Windows).',
  240. '{rsync-option-name}' => "Replace {rsync-option-name} with the rsync option (or option='value') that you would like to pass through to rsync. Examples include --delete, --exclude=*.sql, --filter='merge /etc/rsync/default.rules', etc. See the rsync documentation for a complete explaination of all the rsync options and values.",
  241. ),
  242. 'strict-option-handling' => TRUE,
  243. 'examples' => array(
  244. 'drush rsync @dev @stage' => 'Rsync Drupal root from Drush alias dev to the alias stage (one of which must be local).',
  245. 'drush rsync ./ @stage:%files/img' => 'Rsync all files in the current directory to the \'img\' directory in the file storage folder on the Drush alias stage.',
  246. 'drush -s rsync @dev @stage --exclude=*.sql --delete' => "Simulate Rsync Drupal root from the Drush alias dev to the alias stage (one of which must be local), excluding all files that match the filter '*.sql' and delete all files on the destination that are no longer on the source.",
  247. ),
  248. 'aliases' => array('rsync'),
  249. 'topics' => array('docs-aliases'),
  250. );
  251. $items['site-install'] = array(
  252. 'description' => 'Install Drupal along with modules/themes/configuration using the specified install profile.',
  253. 'arguments' => array(
  254. 'profile' => 'the install profile you wish to run. defaults to \'default\' in D6, \'standard\' in D7+',
  255. 'key=value...' => 'any additional settings you wish to pass to the profile. Fully supported on D7+, partially supported on D6 (single step configure forms only). The key is in the form [form name].[parameter name] on D7 or just [parameter name] on D6.',
  256. ),
  257. 'options' => array(
  258. 'db-url' => array(
  259. 'description' => 'A Drupal 6 style database URL. Only required for initial install - not re-install.',
  260. 'example-value' => 'mysql://root:pass@host/db',
  261. ),
  262. 'db-prefix' => 'An optional table prefix to use for initial install. Can be a key-value array of tables/prefixes in a drushrc file (not the command line).',
  263. 'db-su' => array(
  264. 'description' => 'Account to use when creating a new database. Must have Grant permission (mysql only). Optional.',
  265. 'example-value' => 'root',
  266. ),
  267. 'db-su-pw' => array(
  268. 'description' => 'Password for the "db-su" account. Optional.',
  269. 'example-value' => 'pass',
  270. ),
  271. 'account-name' => 'uid1 name. Defaults to admin',
  272. 'account-pass' => 'uid1 pass. Defaults to a randomly generated password. If desired, set a fixed password in drushrc.php.',
  273. 'account-mail' => 'uid1 email. Defaults to admin@example.com',
  274. 'locale' => array(
  275. 'description' => 'A short language code. Sets the default site language. Language files must already be present. You may use download command to get them.',
  276. 'example-value' => 'en-GB',
  277. ),
  278. 'clean-url'=> 'Defaults to 1',
  279. 'site-name' => 'Defaults to Site-Install',
  280. 'site-mail' => 'From: for system mailings. Defaults to admin@example.com',
  281. 'sites-subdir' => array(
  282. 'description' => "Name of directory under 'sites' which should be created. Only needed when the subdirectory does not already exist. Defaults to 'default'",
  283. 'value' => 'required',
  284. 'example-value' => 'directory_name',
  285. ),
  286. ),
  287. 'examples' => array(
  288. 'drush site-install expert --locale=uk' => '(Re)install using the expert install profile. Set default language to Ukrainian.',
  289. 'drush site-install --db-url=mysql://root:pass@localhost:port/dbname' => 'Install using the specified DB params.',
  290. 'drush site-install --db-url=sqlite://sites/example.com/files/.ht.sqlite' => 'Install using SQLite (D7+ only).',
  291. 'drush site-install --account-name=joe --account-pass=mom' => 'Re-install with specified uid1 credentials.',
  292. 'drush site-install standard install_configure_form.site_default_country=FR my_profile_form.my_settings.key=value' => 'Pass additional arguments to the profile (D7 example shown here - for D6, omit the form id).',
  293. "drush site-install install_configure_form.update_status_module='array(FALSE,FALSE)'" => 'Disable email notification during install and later. If your server has no smtp, this gets rid of an error during install.',
  294. ),
  295. 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
  296. 'aliases' => array('si'),
  297. );
  298. $items['drupal-directory'] = array(
  299. 'description' => 'Return path to a given module/theme directory.',
  300. 'arguments' => array(
  301. 'target' => 'A module/theme name, or special names like root, files, private, or an alias : path alias string such as @alias:%files. Defaults to root.',
  302. ),
  303. 'options' => array(
  304. 'component' => "The portion of the evaluated path to return. Defaults to 'path'; 'name' returns the site alias of the target.",
  305. 'local' => "Reject any target that specifies a remote site.",
  306. ),
  307. 'examples' => array(
  308. 'cd `drush dd devel`' => 'Navigate into the devel module directory',
  309. 'cd `drush dd` ' => 'Navigate to the root of your Drupal site',
  310. 'cd `drush dd files`' => 'Navigate to the files directory.',
  311. 'drush dd @alias:%files' => 'Print the path to the files directory on the site @alias.',
  312. 'edit `drush dd devel`/devel.module' => "Open devel module in your editor (customize 'edit' for your editor)",
  313. ),
  314. 'aliases' => array('dd'),
  315. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
  316. );
  317. $items['batch-process'] = array(
  318. 'description' => 'Process operations in the specified batch set',
  319. 'hidden' => TRUE,
  320. 'arguments' => array(
  321. 'batch-id' => 'The batch id that will be processed.',
  322. ),
  323. 'required-arguments' => TRUE,
  324. 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN,
  325. );
  326. $items['updatedb-batch-process'] = array(
  327. 'description' => 'Perform update functions',
  328. 'hidden' => TRUE,
  329. 'arguments' => array(
  330. 'batch-id' => 'The batch id that will be processed',
  331. ),
  332. 'required-arguments' => TRUE,
  333. 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_SITE,
  334. );
  335. $items['core-global-options'] = array(
  336. 'description' => 'All global options',
  337. 'hidden' => TRUE,
  338. 'topic' => TRUE,
  339. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
  340. 'outputformat' => array(
  341. 'default' => 'table',
  342. 'pipe-format' => 'csv',
  343. 'field-labels' => array('label' => 'Label', 'description' => 'Description'),
  344. 'output-data-type' => 'format-table',
  345. ),
  346. );
  347. $items['core-quick-drupal'] = array(
  348. 'description' => 'Download, install, serve and login to Drupal with minimal configuration and dependencies.',
  349. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
  350. 'aliases' => array('qd'),
  351. 'arguments' => array(
  352. 'site' => 'Short name for the site to be created - used as a directory name and as sqlite file name. Optional - if omitted timestamped "quick-drupal" directory will be used instead.',
  353. 'projects' => 'A list of projects to download into the new site. If projects contain extensions (modules or themes) with the same name they will be enabled by default. See --enable option to control this behaviour further.',
  354. ),
  355. 'examples' => array(
  356. 'drush qd' => 'Download and install stable release of Drupal into a timestamped directory, start server, and open the site logged in as admin.',
  357. 'drush qd --profile=minimal --dev --cache --core=drupal-8.x --yes' => 'Fire up dev release of Drupal site with minimal install profile.',
  358. 'drush qd testsite devel --server=:8081/admin --browser=firefox --cache --yes' => 'Fire up stable release (using the cache) of Drupal site called "testsite", download and enable devel module, start a server on port 8081 and open /admin in firefox.',
  359. 'drush qd commercesite --core=commerce_kickstart --profile=commerce_kickstart --cache --yes --watchdog' => 'Download and install the "Commerce Kickstart" distribution/install profile, display watchdog messages on the server console.',
  360. 'drush qd --makefile=mysite.make' => 'Create and install a site from a makefile.',
  361. ),
  362. );
  363. // Add in options/engines.
  364. drush_core_quick_drupal_options($items);
  365. // Add in topics for engines
  366. $items += drush_get_engine_topics();
  367. return $items;
  368. }
  369. /**
  370. * Command argument complete callback.
  371. *
  372. * @return
  373. * Array of available command names.
  374. */
  375. function core_help_complete() {
  376. return array('values' => array_keys(drush_get_commands()));
  377. }
  378. /**
  379. * Command argument complete callback.
  380. *
  381. * @return
  382. * Array of available profile names.
  383. */
  384. function core_site_install_complete() {
  385. $max = drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_ROOT);
  386. if ($max >= DRUSH_BOOTSTRAP_DRUPAL_ROOT) {
  387. return array('values' => array_keys(drush_find_profiles(DRUPAL_ROOT)));
  388. }
  389. }
  390. /**
  391. * Command argument complete callback.
  392. *
  393. * @return
  394. * Array of available site aliases.
  395. */
  396. function core_core_rsync_complete() {
  397. return array('values' => array_keys(_drush_sitealias_all_list()));
  398. }
  399. /**
  400. * @defgroup engines Engine types
  401. * @{
  402. */
  403. /**
  404. * Implementation of hook_drush_engine_type_info().
  405. */
  406. function core_drush_engine_type_info() {
  407. $info = array();
  408. $info['drupal'] = array();
  409. return $info;
  410. }
  411. /**
  412. * Implements hook_drush_engine_ENGINE_TYPE().
  413. */
  414. function core_drush_engine_drupal() {
  415. $engines = array();
  416. $engines['batch'] = array();
  417. $engines['update'] = array();
  418. $engines['environment'] = array();
  419. $engines['site_install'] = array();
  420. return $engines;
  421. }
  422. /**
  423. * @} End of "Engine types".
  424. */
  425. /**
  426. * Command handler. Execute update.php code from drush.
  427. */
  428. function drush_core_updatedb() {
  429. if (drush_get_context('DRUSH_SIMULATE')) {
  430. drush_log(dt('updatedb command does not support --simulate option.'), 'ok');
  431. return TRUE;
  432. }
  433. drush_include_engine('drupal', 'update', drush_drupal_major_version());
  434. if (update_main() === FALSE) {
  435. return FALSE;
  436. }
  437. // Clear all caches in a new process. We just performed major surgery.
  438. drush_invoke_process('@self', 'cache-clear', array('all'));
  439. drush_log(dt('Finished performing updates.'), 'ok');
  440. }
  441. /**
  442. * Command handler. List pending DB updates.
  443. */
  444. function drush_core_updatedb_status() {
  445. require_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
  446. drupal_load_updates();
  447. drush_include_engine('drupal', 'update', drush_drupal_major_version());
  448. list($pending, $start) = updatedb_status();
  449. if (empty($pending)) {
  450. drush_log(dt("No database updates required"), 'ok');
  451. }
  452. return $pending;
  453. }
  454. /**
  455. * Implementation of hook_drush_help().
  456. *
  457. * This function is called whenever a drush user calls
  458. * 'drush help <name-of-your-command>'
  459. *
  460. * @param
  461. * A string with the help section (prepend with 'drush:')
  462. *
  463. * @return
  464. * A string with the help text for your command.
  465. */
  466. function core_drush_help($section) {
  467. switch ($section) {
  468. case 'meta:core:title':
  469. return dt("Core drush commands");
  470. case 'drush:help':
  471. return dt("Drush provides an extensive help system that describes both drush commands and topics of general interest. Use `drush help --filter` to present a list of command categories to view, and `drush topic` for a list of topics that go more in-depth on how to use and extend drush.");
  472. case 'drush:php-script':
  473. return dt("Runs the given php script(s) after a full Drupal bootstrap. A useful alternative to eval command when your php is lengthy or you can't be bothered to figure out bash quoting. If you plan to share a script with others, consider making a full drush command instead, since that's more self-documenting. Drush provides commandline options to the script via drush_get_option('option-name'), and commandline arguments can be accessed either via drush_get_arguments(), which returns all arguments in an array, or drush_shift(), which removes the next argument from the list and returns it.");
  474. case 'drush:rsync':
  475. return dt("Sync the entire drupal directory or a subdirectory to a <destination> using ssh. Excludes reserved files and directories for supported VCSs. Useful for pushing copies of your tree to a staging server, or retrieving a files directory from a remote site. Relative paths start from the Drupal root directory if a site alias is used; otherwise they start from the current working directory.");
  476. case 'drush:drupal-directory':
  477. return dt("Return the filesystem path for modules/themes and other key folders.");
  478. case 'error:DRUSH_DRUPAL_DB_ERROR':
  479. $message = dt("Drush was not able to start (bootstrap) the Drupal database.\n");
  480. $message .= dt("Hint: This may occur when Drush is trying to:\n");
  481. $message .= dt(" * bootstrap a site that has not been installed or does not have a configured database. In this case you can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command line. See `drush topic docs-aliases` for details.\n");
  482. $message .= dt(" * connect the database through a socket. The socket file may be wrong or the php-cli may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for details.\n");
  483. $message .= dt("\nDrush was attempting to connect to: \n!credentials\n", array('!credentials' => _core_site_credentials(12)));
  484. return $message;
  485. case 'error:DRUSH_DRUPAL_BOOTSTRAP_ERROR':
  486. $message = dt("Drush was not able to start (bootstrap) Drupal.\n");
  487. $message .= dt("Hint: This error can only occur once the database connection has already been successfully initiated, therefore this error generally points to a site configuration issue, and not a problem connecting to the database.\n");
  488. $message .= dt("\nDrush was attempting to connect to: \n!credentials\n", array('!credentials' => _core_site_credentials(12)));
  489. return $message;
  490. break;
  491. }
  492. }
  493. // TODO: consolidate with SQL commands?
  494. function _core_site_credentials($right_margin = 0) {
  495. // Leave some space on the right so that we can put the result into the
  496. // drush_log, which will again wordwrap the result.
  497. $original_columns = drush_get_context('DRUSH_COLUMNS', 80);
  498. drush_set_context('DRUSH_COLUMNS', $original_columns - $right_margin);
  499. $status_table = _core_site_status_table();
  500. $metadata = drush_get_command_format_metadata('core-status');
  501. $output = drush_format($status_table, $metadata, 'key-value');
  502. drush_set_context('DRUSH_COLUMNS', $original_columns);
  503. return $output;
  504. }
  505. function _core_site_credential_table($status_table) {
  506. $credentials = '';
  507. foreach ($status_table as $key => $value) {
  508. $credentials .= sprintf(" %-18s: %s\n", $key, $value);
  509. }
  510. return $credentials;
  511. }
  512. function _core_path_aliases($project = '') {
  513. $paths = array();
  514. if ($drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT')) {
  515. $paths['%root'] = $drupal_root;
  516. if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) {
  517. $paths['%site'] = $site_root;
  518. if (is_dir($modules_path = conf_path() . '/modules')) {
  519. $paths['%modules'] = $modules_path;
  520. }
  521. else {
  522. $paths['%modules'] = 'sites/all/modules';
  523. }
  524. if (is_dir($themes_path = conf_path() . '/themes')) {
  525. $paths['%themes'] = $themes_path;
  526. }
  527. else {
  528. $paths['%themes'] = 'sites/all/themes';
  529. }
  530. if (drush_drupal_major_version() >= 8 && drush_get_context('DRUSH_BOOTSTRAP_PHASE') >= DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION) {
  531. $paths['%config-active'] = config_get_config_directory(CONFIG_ACTIVE_DIRECTORY);
  532. $paths['%config-staging'] = config_get_config_directory(CONFIG_STAGING_DIRECTORY);
  533. }
  534. if (drush_drupal_major_version() >= 7) {
  535. if (drush_get_context('DRUSH_BOOTSTRAP_PHASE') >= DRUSH_BOOTSTRAP_DRUPAL_SITE) {
  536. $paths['%files'] = variable_get('file_public_path', conf_path() . '/files');
  537. $private_path = variable_get('file_private_path', FALSE);
  538. if (!empty($private_path)) {
  539. $paths['%private'] = $private_path;
  540. }
  541. }
  542. }
  543. elseif (function_exists('file_directory_path')) {
  544. $paths['%files'] = file_directory_path();
  545. }
  546. if (function_exists('file_directory_temp')) {
  547. $paths['%temp'] = file_directory_temp();
  548. }
  549. // If the 'project' parameter was specified, then search
  550. // for a project (or a few) and add its path to the path list
  551. if (!empty($project)) {
  552. drush_include_engine('drupal', 'environment');
  553. $projects = array_merge(drush_get_modules(), drush_get_themes());
  554. foreach(explode(',', $project) as $target) {
  555. if (array_key_exists($target, $projects)) {
  556. $paths['%' . $target] = $drupal_root . '/' . dirname($projects[$target]->filename);
  557. }
  558. }
  559. }
  560. }
  561. }
  562. // Add in all of the global paths from $options['path-aliases']
  563. $paths = array_merge($paths, drush_get_option('path-aliases', array()));
  564. return $paths;
  565. }
  566. function _core_site_status_table($project = '') {
  567. $phase = drush_get_context('DRUSH_BOOTSTRAP_PHASE');
  568. if ($drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT')) {
  569. $status_table['drupal-version'] = drush_drupal_version();
  570. if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) {
  571. $status_table['uri'] = drush_get_context('DRUSH_URI');
  572. if ($creds = drush_get_context('DRUSH_DB_CREDENTIALS')) {
  573. $status_table['db-driver'] = $creds['driver'];
  574. if (!empty($creds['unix_socket'])) {
  575. $status_table['db-socket'] = $creds['unix_socket'];
  576. }
  577. else {
  578. $status_table['db-hostname'] = $creds['host'];
  579. }
  580. $status_table['db-username'] = $creds['user'];
  581. $status_table['db-name'] = $creds['name'];
  582. $status_table['db-password'] = $creds['pass'];
  583. if ($phase > DRUSH_BOOTSTRAP_DRUPAL_DATABASE) {
  584. $status_table['db-status'] = dt('Connected');
  585. if ($phase > DRUSH_BOOTSTRAP_DRUPAL_FULL) {
  586. $status_table['bootstrap'] = dt('Successful');
  587. if ($phase == DRUSH_BOOTSTRAP_DRUPAL_LOGIN) {
  588. global $user;
  589. $username = ($user->uid) ? $user->name : dt('Anonymous');
  590. $status_table['user'] = $username;
  591. }
  592. }
  593. }
  594. }
  595. }
  596. $status_table['theme'] = drush_theme_get_default();
  597. $status_table['admin-theme'] = drush_theme_get_admin();
  598. }
  599. if ($php_bin = drush_get_option('php')) {
  600. $status_table['php-bin'] = $php_bin;
  601. }
  602. $status_table['php-os'] = PHP_OS;
  603. if ($php_ini_files = _drush_core_config_php_ini_files()) {
  604. $status_table['php-conf'] = $php_ini_files;
  605. }
  606. $status_table['drush-version'] = DRUSH_VERSION;
  607. $status_table['drush-conf'] = drush_flatten_array(drush_get_context_options('context-path', ''));
  608. $alias_files = _drush_sitealias_find_alias_files();
  609. $status_table['drush-alias-files'] = $alias_files;
  610. $paths = _core_path_aliases($project);
  611. if (!empty($paths)) {
  612. foreach ($paths as $target => $one_path) {
  613. $name = $target;
  614. if (substr($name,0,1) == '%') {
  615. $name = substr($name,1);
  616. }
  617. $status_table[$name] = $one_path;
  618. }
  619. }
  620. // Store the paths into the '%paths' index; this will be
  621. // used by other code, but will not be included in the output
  622. // of the drush status command.
  623. $status_table['%paths'] = $paths;
  624. return $status_table;
  625. }
  626. // Adjust the status output for any non-pipe output format
  627. function _drush_core_status_format_table_data($output, $metadata) {
  628. if (drush_get_option('full', FALSE) == FALSE) {
  629. // Hide any key that begins with a %
  630. foreach ($output as $key => $value) {
  631. if ($key[0] == '%') {
  632. unset($output[$key]);
  633. }
  634. }
  635. // Hide 'Modules path' and 'Themes path' as well
  636. unset($output['modules']);
  637. unset($output['themes']);
  638. // Shorten the list of alias files if there are too many
  639. if (isset($output['drush-alias-files']) && count($output['drush-alias-files']) > 24) {
  640. $msg = dt("\nThere are !count more alias files. Run with --full to see the full list.", array('!count' => count($output['drush-alias-files']) - 1));
  641. $output['drush-alias-files'] = array($output['drush-alias-files'][0] , $msg);
  642. }
  643. }
  644. return $output;
  645. }
  646. /**
  647. * Command callback. Runs all cron hooks.
  648. */
  649. function drush_core_cron() {
  650. if (drupal_cron_run()) {
  651. drush_log(dt('Cron run successful.'), 'success');
  652. }
  653. else {
  654. return drush_set_error('DRUSH_CRON_FAILED', dt('Cron run failed.'));
  655. }
  656. }
  657. /**
  658. * Command callback. Edit drushrc and alias files.
  659. */
  660. function drush_core_config($filter = NULL) {
  661. $all = drush_core_config_load();
  662. // Apply any filter that was supplied.
  663. if ($filter) {
  664. foreach ($all as $key => $file) {
  665. if (strpos($file, $filter) === FALSE) {
  666. unset($all[$key]);
  667. }
  668. }
  669. }
  670. $all = drush_map_assoc(array_values($all));
  671. $exec = drush_get_editor();
  672. if (count($all) == 1) {
  673. $filepath = current($all);
  674. return drush_shell_exec_interactive($exec, $filepath, $filepath);
  675. }
  676. else {
  677. $choice = drush_choice($all, 'Enter a number to choose which file to edit.', '!key');
  678. if ($choice !== FALSE) {
  679. $filepath = $all[$choice];
  680. drush_shell_exec_interactive($exec, $filepath, $filepath);
  681. }
  682. }
  683. }
  684. /**
  685. * Command argument complete callback.
  686. *
  687. * @return
  688. * Array of available configuration files for editing.
  689. */
  690. function core_core_config_complete() {
  691. return array('values' => drush_core_config_load(FALSE));
  692. }
  693. function drush_core_config_load($headers = TRUE) {
  694. $php_header = $php = $rcs_header = $rcs = $aliases_header = $aliases = $drupal_header = $drupal = array();
  695. $php = _drush_core_config_php_ini_files();
  696. if (!empty($php)) {
  697. if ($headers) {
  698. $php_header = array('phpini' => '-- PHP ini files --');
  699. }
  700. }
  701. drush_sitealias_load_all();
  702. if ($rcs = drush_get_context_options('context-path', TRUE)) {
  703. if ($headers) {
  704. $rcs_header = array('drushrc' => '-- Drushrc --');
  705. }
  706. }
  707. if ($aliases = drush_get_context('drush-alias-files')) {
  708. if ($headers) {
  709. $aliases_header = array('aliases' => '-- Aliases --');
  710. }
  711. }
  712. if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) {
  713. $drupal = array_merge(array(realpath($site_root . '/settings.php'), realpath(DRUPAL_ROOT . '/.htaccess')));
  714. if ($headers) {
  715. $drupal_header = array('drupal' => '-- Drupal --');
  716. }
  717. }
  718. return array_merge($php_header, $php, $rcs_header, $rcs, $aliases_header, $aliases, $drupal_header, $drupal);
  719. }
  720. function _drush_core_config_php_ini_files() {
  721. $ini_files = array();
  722. $ini_files[] = php_ini_loaded_file();
  723. if ($drush_ini = getenv('DRUSH_INI')) {
  724. if (file_exists($drush_ini)) {
  725. $ini_files[] = $drush_ini;
  726. }
  727. }
  728. foreach (array(DRUSH_BASE_PATH, '/etc/drush', drush_server_home() . '/.drush') as $ini_dir) {
  729. if (file_exists($ini_dir . "/php.ini")) {
  730. $ini_files[] = realpath($ini_dir . "/php.ini");
  731. }
  732. if (file_exists($ini_dir . "/drush.ini")) {
  733. $ini_files[] = realpath($ini_dir . "/drush.ini");
  734. }
  735. }
  736. return $ini_files;
  737. }
  738. /**
  739. * Command callback. Provides information from the 'Status Reports' admin page.
  740. */
  741. function drush_core_requirements() {
  742. include_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
  743. $severities = array(
  744. REQUIREMENT_INFO => t('Info'),
  745. REQUIREMENT_OK => t('OK'),
  746. REQUIREMENT_WARNING => t('Warning'),
  747. REQUIREMENT_ERROR => t('Error'),
  748. );
  749. drupal_load_updates();
  750. $requirements = module_invoke_all('requirements', 'runtime');
  751. // If a module uses "$requirements[] = " instead of
  752. // "$requirements['label'] = ", then build a label from
  753. // the title.
  754. foreach($requirements as $key => $info) {
  755. if (is_numeric($key)) {
  756. unset($requirements[$key]);
  757. $new_key = strtolower(str_replace(' ', '_', $info['title']));
  758. $requirements[$new_key] = $info;
  759. }
  760. }
  761. $ignore_requirements = drush_get_option_list('ignore');
  762. foreach ($ignore_requirements as $ignore) {
  763. unset($requirements[$ignore]);
  764. }
  765. ksort($requirements);
  766. $min_severity = drush_get_option('severity', -1);
  767. foreach($requirements as $key => $info) {
  768. $severity = array_key_exists('severity', $info) ? $info['severity'] : -1;
  769. $requirements[$key]['sid'] = $severity;
  770. $requirements[$key]['severity'] = $severities[$severity];
  771. if ($severity < $min_severity) {
  772. unset($requirements[$key]);
  773. }
  774. }
  775. return $requirements;
  776. }
  777. /**
  778. * Command callback. Provides a birds-eye view of the current Drupal
  779. * installation.
  780. */
  781. function drush_core_status() {
  782. $status_table = _core_site_status_table(drush_get_option('project',''));
  783. // If args are specified, filter out any entry that is not named
  784. // (in other words, only show lines named by one of the arg values)
  785. $args = func_get_args();
  786. if (!empty($args)) {
  787. $field_list = $args;
  788. $metadata = drush_get_command_format_metadata('core-status');
  789. foreach ($metadata['field-labels'] as $field_key => $field_label) {
  790. if (_drush_core_is_named_in_array($field_label, $args)) {
  791. $field_list[] = $field_key;
  792. }
  793. }
  794. foreach ($status_table as $key => $value) {
  795. if (!_drush_core_is_named_in_array($key, $field_list)) {
  796. unset($status_table[$key]);
  797. }
  798. }
  799. }
  800. return $status_table;
  801. }
  802. // Command callback. Show all global options. Exposed via topic command.
  803. function drush_core_global_options() {
  804. drush_print(dt('These options are applicable to most drush commands.'));
  805. drush_print();
  806. $fake = drush_global_options_command(FALSE);
  807. return drush_format_help_section($fake, 'options');
  808. }
  809. function _drush_core_is_named_in_array($key, $the_array) {
  810. $is_named = FALSE;
  811. $simplified_key = str_replace(array(' ', '_', '-'), array('', '', ''), $key);
  812. foreach ($the_array as $name) {
  813. if (stristr($simplified_key, str_replace(array(' ', '_', '-'), array('', '', ''), $name))) {
  814. $is_named = TRUE;
  815. }
  816. }
  817. return $is_named;
  818. }
  819. /**
  820. * Callback for core-quick-drupal command.
  821. */
  822. function drush_core_quick_drupal() {
  823. $requests = FALSE;
  824. $make_projects = array();
  825. $args = func_get_args();
  826. $name = drush_get_option('use-name');
  827. drush_set_option('backend', TRUE);
  828. drush_set_option('strict', FALSE); // We fail option validation because do so much internal drush_invoke().
  829. $makefile = drush_get_option('makefile');
  830. if (drush_get_option('use-existing', FALSE)) {
  831. $root = drush_get_option('root', FALSE);
  832. if (!$root) {
  833. return drush_set_error('QUICK_DRUPAL_NO_ROOT_SPECIFIED', 'Must specify site with --root when using --use-existing.');
  834. }
  835. if (empty($name)) {
  836. $name = basename($root);
  837. }
  838. $base = dirname($root);
  839. }
  840. else {
  841. if (!empty($args) && empty($name)) {
  842. $name = array_shift($args);
  843. }
  844. if (empty($name)) {
  845. $name = 'quick-drupal-' . gmdate('YmdHis', $_SERVER['REQUEST_TIME']);
  846. }
  847. $root = drush_get_option('root', FALSE);
  848. $core = drush_get_option('core', 'drupal');
  849. $project_rename = $core;
  850. if ($root) {
  851. $base = dirname($root);
  852. $project_rename = basename($root);
  853. }
  854. else {
  855. $base = getcwd() . '/' . $name;
  856. $root = $base . '/' . $core;
  857. }
  858. if (!empty($makefile)) {
  859. // Invoke 'drush make $makefile'.
  860. $result = drush_invoke_process('@none', 'make', array($makefile, $root));
  861. if ($result['error_status'] != 0) {
  862. return drush_set_error('DRUSH_QD_MAKE', 'Could not make; aborting.');
  863. }
  864. $make_projects = array_diff(array_keys($result['object']['projects']), array('drupal'));
  865. }
  866. else {
  867. drush_mkdir($base);
  868. drush_set_option('destination', $base);
  869. drush_set_option('drupal-project-rename', $project_rename);
  870. if (drush_invoke('pm-download', array($core)) === FALSE) {
  871. return drush_set_error('QUICK_DRUPAL_CORE_DOWNLOAD_FAIL', 'Drupal core download/extract failed.');
  872. }
  873. }
  874. }
  875. if (!drush_get_option('db-url', FALSE)) {
  876. drush_set_option('db-url', 'sqlite:' . $base . '/' . $name . '.sqlite');
  877. }
  878. drush_set_option('root', $root);
  879. if (!drush_bootstrap_to_phase(DRUSH_BOOTSTRAP_DRUPAL_ROOT)) {
  880. return drush_set_error('QUICK_DRUPAL_ROOT_LOCATE_FAIL', 'Unable to locate Drupal root directory.');
  881. }
  882. if (!empty($args)) {
  883. $requests = pm_parse_arguments($args, FALSE);
  884. }
  885. if ($requests) {
  886. // Unset --destination, so that downloads go to the site directories.
  887. drush_unset_option('destination');
  888. if (drush_invoke('pm-download', $requests) === FALSE) {
  889. return drush_set_error('QUICK_DRUPAL_PROJECT_DOWNLOAD_FAIL', 'Project download/extract failed.');
  890. }
  891. }
  892. drush_invoke('site-install', array(drush_get_option('profile')));
  893. // Log in with the admin user.
  894. // TODO: If site-install is given a sites-subdir other than 'default',
  895. // then it will bootstrap to DRUSH_BOOTSTRAP_DRUPAL_SITE get the installer
  896. // to recognize the desired site directory. This somehow interferes
  897. // with our desire to bootstrap to DRUSH_BOOTSTRAP_DRUPAL_LOGIN here.
  898. // We could do the last few steps in a new process if uri is not 'default'.
  899. drush_set_option('user', '1');
  900. if (!drush_bootstrap_to_phase(DRUSH_BOOTSTRAP_DRUPAL_LOGIN)) {
  901. return drush_set_error('QUICK_DRUPAL_INSTALL_FAIL', 'Drupal core install failed.');
  902. }
  903. $enable = array_merge(pm_parse_arguments(drush_get_option('enable', $requests)), $make_projects);
  904. if (!empty($enable)) {
  905. if (drush_invoke('pm-enable', $enable) === FALSE) {
  906. return drush_set_error('QUICK_DRUPAL_PROJECT_ENABLE_FAIL', 'Project enable failed.');
  907. }
  908. }
  909. if (!drush_get_option('no-server', FALSE)) {
  910. if ($server = drush_get_option('server', '/')) {
  911. // Current CLI user is also the web server user, which is for development
  912. // only. Hence we can safely make the site directory writable. This makes
  913. // it easier to delete and edit settings.php.
  914. @chmod(conf_path(), 0700);
  915. drush_invoke('runserver', array($server));
  916. }
  917. }
  918. else {
  919. drush_print(dt('Login URL: ') . drush_invoke('user-login'));
  920. }
  921. }
  922. /**
  923. * Include options and engines for core-quick-drupal command, aggregated from
  924. * other command options that are available. We prefix option descriptons,
  925. * to make the long list more navigable.
  926. *
  927. * @param $items
  928. * The core commandfile command array, by reference. Used to include
  929. * site-install options and add options and engines for core-quick-drupal.
  930. */
  931. function drush_core_quick_drupal_options(&$items) {
  932. $options = array(
  933. 'core' => 'Drupal core to download. Defaults to "drupal" (latest stable version).',
  934. 'use-existing' => 'Use an existing Drupal root, specified with --root. Overrides --core.',
  935. 'profile' => 'The install profile to use. Defaults to standard.',
  936. 'enable' => 'Specific extensions (modules or themes) to enable. By default, extensions with the same name as requested projects will be enabled automatically.',
  937. 'server' => 'Host IP address and port number to bind to and path to open in web browser (hyphen to clear a default path), all elements optional. See runserver examples for shorthand.',
  938. 'no-server' => 'Avoid starting runserver (and browser) for the created Drupal site.',
  939. 'browser' => 'Optional name of a browser to open site in. If omitted the OS default browser will be used. Set --no-browser to disable.',
  940. 'use-name' => array('hidden' => TRUE, 'description' => 'Overrides "name" argument.'),
  941. 'makefile' => array('description' => 'Makefile to use. Makefile must specify which version of Drupal core to build.', 'example-value' => 'mysite.make', 'value' => 'optional'),
  942. 'root' => array('description' => 'Path to Drupal root.', 'example-value' => '/path/to/root', 'value' => 'optional'),
  943. );
  944. $pm = pm_drush_command();
  945. foreach ($pm['pm-download']['options'] as $option => $description) {
  946. if (is_array($description)) {
  947. $description = $description['description'];
  948. }
  949. $options[$option] = 'Download option: ' . $description;
  950. }
  951. // Unset a few options that are not usable here, as we control them ourselves
  952. // or they are otherwise implied by the environment.
  953. unset($options['destination']);
  954. unset($options['drupal-project-rename']);
  955. unset($options['default-major']);
  956. unset($options['use-site-dir']);
  957. foreach ($items['site-install']['options'] as $option => $description) {
  958. if (is_array($description)) {
  959. $description = $description['description'];
  960. }
  961. $options[$option] = 'Site install option: ' . $description;
  962. }
  963. unset($options['sites-subdir']);
  964. $runserver = runserver_drush_command();
  965. foreach ($runserver['runserver']['options'] as $option => $description) {
  966. $options[$option] = 'Runserver option: ' . $description;
  967. }
  968. unset($options['user']);
  969. $items['core-quick-drupal']['options'] = $options;
  970. $items['core-quick-drupal']['engines'] = $pm['pm-download']['engines'];
  971. }
  972. /**
  973. * Command callback. Runs "naked" php scripts
  974. * and drush "shebang" scripts ("#!/usr/bin/env drush").
  975. *
  976. * @params
  977. * Command arguments, optional. First argument is site name, remaining
  978. * argument(s) are contrib modules to install.
  979. */
  980. function drush_core_php_script() {
  981. $found = FALSE;
  982. $script = NULL;
  983. if ($args = func_get_args()) {
  984. $script = $args[0];
  985. }
  986. if ($script == '-') {
  987. eval(stream_get_contents(STDIN));
  988. }
  989. elseif (file_exists($script)) {
  990. $found = $script;
  991. }
  992. else {
  993. // Array of paths to search for scripts
  994. $searchpath['DIR'] = dirname(__FILE__);
  995. $searchpath['cwd'] = drush_cwd();
  996. // Additional script paths, specified by 'script-path' option
  997. if ($script_path = drush_get_option('script-path', FALSE)) {
  998. foreach (explode(PATH_SEPARATOR, $script_path) as $path) {
  999. $searchpath[] = $path;
  1000. }
  1001. }
  1002. drush_log(dt('Searching for scripts in ') . implode(',', $searchpath), 'debug');
  1003. if (!isset($script)) {
  1004. // List all available scripts.
  1005. $all = array();
  1006. foreach($searchpath as $key => $path) {
  1007. $recurse = !(($key == 'cwd') || ($path == '/'));
  1008. $all = array_merge( $all , array_keys(drush_scan_directory($path, '/\.php$/', array('.', '..', 'CVS'), NULL, $recurse)) );
  1009. }
  1010. drush_print(implode("\n", $all));
  1011. }
  1012. else {
  1013. // Execute the specified script.
  1014. foreach($searchpath as $path) {
  1015. $script_filename = $path . '/' . $script;
  1016. if (file_exists($script_filename . '.php')) {
  1017. $script_filename .= '.php';
  1018. }
  1019. if (file_exists($script_filename)) {
  1020. $found = $script_filename;
  1021. break;
  1022. }
  1023. $all[] = $script_filename;
  1024. }
  1025. if (!$found) {
  1026. return drush_set_error('DRUSH_TARGET_NOT_FOUND', dt('Unable to find any of the following: @files', array('@files' => implode(', ', $all))));
  1027. }
  1028. }
  1029. }
  1030. if ($found) {
  1031. // Set the DRUSH_SHIFT_SKIP to two; this will cause
  1032. // drush_shift to skip the next two arguments the next
  1033. // time it is called. This allows scripts to get all
  1034. // arguments, including the 'php-script' and script
  1035. // pathname, via drush_get_arguments(), or it can process
  1036. // just the arguments that are relevant using drush_shift().
  1037. drush_set_context('DRUSH_SHIFT_SKIP', 2);
  1038. if (_drush_core_eval_shebang_script($found) === FALSE) {
  1039. include($found);
  1040. }
  1041. }
  1042. }
  1043. function drush_core_php_eval($command) {
  1044. return eval($command . ';');
  1045. }
  1046. /**
  1047. * Evaluate a script that begins with #!drush php-script
  1048. */
  1049. function _drush_core_eval_shebang_script($script_filename) {
  1050. $found = FALSE;
  1051. $fp = fopen($script_filename, "r");
  1052. if ($fp !== FALSE) {
  1053. $line = fgets($fp);
  1054. if (_drush_is_drush_shebang_line($line)) {
  1055. $first_script_line = '';
  1056. while ($line = fgets($fp)) {
  1057. $line = trim($line);
  1058. if ($line == '<?php') {
  1059. $found = TRUE;
  1060. break;
  1061. }
  1062. elseif (!empty($line)) {
  1063. $first_script_line = $line . "\n";
  1064. break;
  1065. }
  1066. }
  1067. $script = stream_get_contents($fp);
  1068. // Pop off the first two arguments, the
  1069. // command (php-script) and the path to
  1070. // the script to execute, as a service
  1071. // to the script.
  1072. eval($first_script_line . $script);
  1073. $found = TRUE;
  1074. }
  1075. fclose($fp);
  1076. }
  1077. return $found;
  1078. }
  1079. /**
  1080. * Process sets from the specified batch.
  1081. *
  1082. * This is the default batch processor that will be used if the $command parameter
  1083. * to drush_backend_batch_process() has not been specified.
  1084. */
  1085. function drush_core_batch_process($id) {
  1086. drush_batch_command($id);
  1087. }
  1088. /**
  1089. * Process outstanding updates during updatedb.
  1090. *
  1091. * This is a batch processing command that makes use of the drush_backend_invoke
  1092. * api.
  1093. *
  1094. * This command includes the version specific update engine, which correctly
  1095. * initialises the environment to be able to successfully handle minor and major
  1096. * upgrades.
  1097. */
  1098. function drush_core_updatedb_batch_process($id) {
  1099. drush_include_engine('drupal', 'update', drush_drupal_major_version());
  1100. _update_batch_command($id);
  1101. }
  1102. /**
  1103. * Given a target (e.g. @site:%modules), return the evaluated directory path.
  1104. *
  1105. * @param $target
  1106. * The target to evaluate. Can be @site or /path or @site:path
  1107. * or @site:%pathalias, etc. (just like rsync parameters)
  1108. * @param $component
  1109. * The portion of the evaluated path to return. Possible values:
  1110. * 'path' - the full path to the target (default)
  1111. * 'name' - the name of the site from the path (e.g. @site1)
  1112. * 'user-path' - the part after the ':' (e.g. %modules)
  1113. * 'root' & 'uri' - the Drupal root and URI of the site from the path
  1114. * 'path-component' - The ':' and the path
  1115. */
  1116. function _drush_core_directory($target = 'root', $component = 'path', $local_only = FALSE) {
  1117. // Normalize to a sitealias in the target.
  1118. $normalized_target = $target;
  1119. if (strpos($target, ':') === FALSE) {
  1120. if (substr($target, 0, 1) != '@') {
  1121. // drush_sitealias_evaluate_path() requires bootstrap to database.
  1122. if (!drush_bootstrap_to_phase(DRUSH_BOOTSTRAP_DRUPAL_DATABASE)) {
  1123. return drush_set_error('DRUPAL_SITE_NOT_FOUND', dt('You need to specify an alias or run this command within a drupal site.'));
  1124. }
  1125. $normalized_target = '@self:';
  1126. if (substr($target, 0, 1) != '%') {
  1127. $normalized_target .= '%';
  1128. }
  1129. $normalized_target .= $target;
  1130. }
  1131. }
  1132. $additional_options = array();
  1133. $values = drush_sitealias_evaluate_path($normalized_target, $additional_options, $local_only);
  1134. if (isset($values[$component])) {
  1135. // Hurray, we found the destination.
  1136. return $values[$component];
  1137. }
  1138. }
  1139. /**
  1140. * Command callback.
  1141. */
  1142. function drush_core_drupal_directory($target = 'root') {
  1143. $path = _drush_core_directory($target, drush_get_option('component', 'path'), drush_get_option('local', FALSE));
  1144. // If _drush_core_directory is working right, it will turn
  1145. // %blah into the path to the item referred to by the key 'blah'.
  1146. // If there is no such key, then no replacement is done. In the
  1147. // case of the dd command, we will consider it an error if
  1148. // any keys are -not- replaced in _drush_core_directory.
  1149. if ($path && (strpos($path, '%') === FALSE)) {
  1150. return $path;
  1151. }
  1152. else {
  1153. return drush_set_error('DRUSH_TARGET_NOT_FOUND', dt("Target '!target' not found.", array('!target' => $target)));
  1154. }
  1155. }
  1156. /**
  1157. * Called for `drush version` or `drush --version`
  1158. */
  1159. function drush_core_version() {
  1160. return DRUSH_VERSION;
  1161. }
  1162. /**
  1163. * Command callback. Execute specified shell code. Often used by shell aliases
  1164. * that start with !.
  1165. */
  1166. function drush_core_execute() {
  1167. $result = TRUE;
  1168. // Get all of the args and options that appear after the command name.
  1169. $args = drush_get_original_cli_args_and_options();
  1170. for ($x = 0; $x < count($args); $x++) {
  1171. // escape all args except for command separators.
  1172. if (!in_array($args[$x], array('&&', '||', ';'))) {
  1173. $args[$x] = drush_escapeshellarg($args[$x]);
  1174. }
  1175. }
  1176. $cmd = implode(' ', $args);
  1177. if ($alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS')) {
  1178. $site = drush_sitealias_get_record($alias);
  1179. if (!empty($site['site-list'])) {
  1180. $sites = drush_sitealias_resolve_sitelist($site);
  1181. foreach ($sites as $site_name => $site_spec) {
  1182. $result = _drush_core_execute_cmd($site_spec, $cmd);
  1183. if (!$result) {
  1184. break;
  1185. }
  1186. }
  1187. }
  1188. else {
  1189. $result = _drush_core_execute_cmd($site, $cmd);
  1190. }
  1191. }
  1192. else {
  1193. // Must be a local command.
  1194. $result = (drush_shell_proc_open($cmd) == 0);
  1195. }
  1196. if (!$result) {
  1197. return drush_set_error('CORE_EXECUTE_FAILED', dt("Command !command failed.", array('!command' => $cmd)));
  1198. }
  1199. return $result;
  1200. }
  1201. /**
  1202. * Helper function for drush_core_execute: run one shell command
  1203. */
  1204. function _drush_core_execute_cmd($site, $cmd) {
  1205. if (!empty($site['remote-host'])) {
  1206. // Remote, so execute an ssh command with a bash fragment at the end.
  1207. $exec = drush_shell_proc_build($site, $cmd, TRUE);
  1208. return (drush_shell_proc_open($exec) == 0);
  1209. }
  1210. elseif (!empty($site['root']) && is_dir($site['root'])) {
  1211. return (drush_shell_proc_open('cd ' . drush_escapeshellarg($site['root']) . ' && ' . $cmd) == 0);
  1212. }
  1213. return (drush_shell_proc_open($cmd) == 0);
  1214. }