00001 <?php
00002
00003
00004 include_once 'includes/multi.inc';
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 function multi_drush_init() {
00017 $drush_version = array();
00018 $drush_version = explode('-', DRUSH_VERSION);
00019
00020 if ($drush_version[0] < 4.0) {
00021 $drush_info = drush_read_drush_info();
00022 if ($drush_version['datestamp'] < 1293480992) {
00023 drush_log('Some command won`t work properly. You need a drush v. >=4.0[-dev -rc*] with a builddate newer or equal 27. Dec 2010 20:16:32 (1293480992).', 'warning');
00024 }
00025 }
00026 }
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 function multi_drush_help($section) {
00042 switch ($section) {
00043 case 'drush:multi-status':
00044 return dt("Status of your multisite installation.");
00045 case 'drush:multi-exec':
00046 return dt('Execute a drush command for all sites in your multisite installation.');
00047 case 'drush:multi-drupalupdate':
00048 return dt('Run a drupal minor update on your multisite installation.');
00049 case 'drush:multi-site':
00050 return dt('Create a new site in your your multisite installation within a files, modules and themes directory.');
00051 case 'drush:multi-create':
00052 return dt('Create a multisite installation.');
00053 case 'drush:multi-sql-dump':
00054 return dt('Improved sql-dump.');
00055 case 'drush:multi-nagios':
00056 return 'For the use as nagios plugin. Print a message and returns with exit status.';
00057 }
00058 }
00059
00060
00061
00062
00063
00064
00065
00066 function multi_drush_command() {
00067 $items = array();
00068
00069 $items['multi-status'] = array(
00070 'callback' => 'multi_status',
00071 'aliases' => array('mst'),
00072 'description' => 'Status of your drupal multisite installation',
00073 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
00074 'examples' => array(
00075 'drush -r /path/to/drupal multi-status' => 'Displays the status.',
00076 ),
00077 );
00078 $items['multi-nagios'] = array(
00079 'callback' => 'multi_nagios',
00080 'aliases' => array('mna', 'nagios'),
00081 'description' => 'Message and exit code for nagios.',
00082 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
00083 'examples' => array(
00084 'drush -r /path/to/drupal multi-nagios' =>
00085 "We assume that drupal-6.14 is the recommended release.\n" .
00086 "With an older version, eg. drupal-6.13 we get:\n" .
00087 "DRUPAL ROOT CRITICAL: drupal-6.13 @ /var/www/drupal-6.13\n" .
00088 " - drupal-6.14 (2009-09-16 21:40) available, see http://drupal.org/node/579476 for details.\n" .
00089 "with exit status 2\n" .
00090 "Or if we are running the recommended version:\n" .
00091 "'DRUPAL ROOT OK: drupal-6.14 @ /path/to/drupal/6.x is uptodate.'\n" .
00092 "with exit status 0.",
00093 'drush -r /path/to/drupal multi-nagios --file=/path/to/file' => 'Same as above with a specified file.',
00094 'drush -r /path/to/drupal -l example.com multi-nagios' =>
00095 "If there are no updates available, this will produce to following output:\n" .
00096 "DRUPAL SITE OK - example.com @ /path/to/drupal/example.com: All modules are uptodate.\n" .
00097 "If there are available updates, it might produce the following output:\n" .
00098 "DRUPAL SITE CRITICAL - example.com @ /path/to/drupal/sites/example.com:\n" .
00099 "there are updates for admin_menu,drupal,image, see http://example.com/?q=admin/reports/updates for datails.\n" .
00100 "NOTE: If there is a site at sites/default, this command runs on site basis, although ou have only specified the Drupal installation."
00101 ),
00102 'options' => array(
00103 '--file' => "Path to release information file, this could be a (temp) file to avoid nrpe-socket timeouts.\n" .
00104 "It is also possible to supply path via URI, like http://updates.drupal.org/release-history/drupal/6.x.\n" .
00105 "NOTE: This option is only available for checking the Drupal installation."
00106 ),
00107 );
00108 $items['multi-moo'] = array(
00109 'aliases' => array('moo'),
00110 'callback' => 'multi_moo',
00111 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
00112 );
00113 $items['multi-exec'] = array(
00114 'aliases' => array('mex'),
00115 'description' => 'Run a drush command on all sites in your multisite installation. Implemented drush commands are: \'cache clear\', \'cron\', \'update\', \'updatecode\', \'updatedb\', \'watchdog delete\', \'watchdog show\' and \'refresh\'.',
00116 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
00117 'examples' => array(
00118 'drush -r /path/to/drupal multi-exec cron' => 'Run all cron hooks on all sites in your multisite installation.',
00119 'drush -r /path/to/drupal multi-exec variable-set --argument=\'site_offline 1\' --option=\'--nocolor\'' => 'Put all sites in maintenance mode without using color highlighting on log messages.',
00120 'drush -r /path/to/drupal multi-exec updatedb' => 'Execute the update.php process for all sites.',
00121 ),
00122 'options' => array(
00123 '--argument' => 'Argument to pass to drush command e.g. \'php\' as type for \'watchdog delete\' and \'watchdog show\'.',
00124 '--option' => 'Option to pass to drush command. or drush itself e.g. \--nocolor\' to suppress color highlighting on log messages.',
00125 ),
00126 'arguments' => array(
00127 'command' => 'The drush command to execute. For drush commands with blanks like \'watchdog show\' make sure to use single or double quotes. Mandatory.',
00128 ),
00129 );
00130 $items['multi-drupalupdate'] = array(
00131 'aliases' => array('mdr', 'drupalupdate'),
00132 'description' => 'Update your drupal installation to the current version minor release, if available.',
00133 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
00134 'options' => array(
00135 '--sql-dump' => 'Calls multi_sql_dump for all sites before starting the drupalupdate. See "drush help multi sql dump" for options and details.',
00136 '--updatedb' => 'Put sites in maintenance mode before drupalupdate, execute updatedb and put sites back from maintenance mode after drupalupdate.',
00137 ),
00138 'examples' => array(
00139 'drush -r /path/to/drupal multi-drupalupdate' => 'Update your drupal installation to the recommended release.',
00140 'drush -r /path/to/drupal multi-drupalupdate --sql-dump --comment="before drupaldate" --update' =>
00141 'Runs a "multi-drupalupdate" on /path/to/drupal with making sql dumps of all sites with optional comment "before drupalupdate" for sql dump filenames and execution of "updatedb" afterwards',
00142 ),
00143 );
00144 $items['multi-site'] = array(
00145 'aliases' => array('msi', 'site'),
00146 'description' => 'Create a site in your drupal installation',
00147 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
00148 'examples' => array(
00149 'drush -r /path/to/drupal multi-site example.com --create-directories=dir1,dir2,dir3' =>
00150 "Create the site 'example.com' within a settings.php,\n" .
00151 "a 'files', 'themes', 'modules' directory\n" .
00152 "and the additional directories 'dir1', 'dir2' and 'dir3' in /path/to/drupal/sites.",
00153 ),
00154 'options' => array(
00155 '--create-directories' => 'Comma seperated list of aditional directories.',
00156 ),
00157 'arguments' => array(
00158 'site-name' => 'Name of the site. Mandatory.',
00159 ),
00160 );
00161 $items['multi-create'] = array(
00162 'aliases' => array('mcr', 'create'),
00163 'description' => 'Create a multisite installation',
00164 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
00165 'examples' => array(
00166 'drush multi-create /var/www --core=6.x' =>
00167 'Creates a Drupal 6 multisite installation in /var/www with creating the directories '.
00168 '6.x_backup, 6.x_profiles and 6.x_sites, in /var/www ' .
00169 'linked as sites and backup withing the drupal installation folder.',
00170 'drush multi-create /var/www --makefile=/path/to/makefile.make' =>
00171 'Creates a Drupal multisite installation in /var/www by using the supplied makefile' .
00172 ' at /path/to/makefile.make.',
00173 ),
00174 'options' => array(
00175
00176 '--makefile' => "Path to drush_make makefile. \nThe makefile must contain the core specification (eg. \"core = 6.x\" for Drupal 6)\nand Drupal as project (projects[] = drupal).",
00177 '--core' => "Drupal core version (5.x, 6.x). \nTakes default from pm_parse_project_version(array('drupal') if not supplied.",
00178 ),
00179 'arguments' => array(
00180 '/path/to/installation' => 'Path to where drupal should be installed. Mandatory',
00181
00182 ),
00183 );
00184 $items['multi-sql-dump'] = array(
00185 'aliases' => array('msq'),
00186 'description' => 'Exports the Drupal DB as SQL. File pattern is ${uri} and a \'_date(\'Y-m-d\TH:i\').sql suffix.',
00187 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_DATABASE,
00188 'examples' => array(
00189 'drush -r /path/to/drupal -l example.com multi-sql-dump --bzip2 --comment=before-update-to-6.15 --target=$HOME/db_backups' =>
00190 'Run \'sql dump\' on example.com with \'before-update-to-6.15\' as comment. ' . "\n" .
00191 'The result file will be bzip compressed and stored in \'db_backups\' in your home directory.' .
00192 "\nDump name schema:\n\${uri} [ _ \${comment} _ \${date('Y-m-d\TH:i')] .sql [.bz2], \nwhere \${url} is example.com supplied by -l/--uri."
00193 ),
00194 'options' => array(
00195 '--target' => 'Absolute Path to the directory where to store the sql dumps. Default /tmp.',
00196 '--dump-type' => "Arguments:\n" .
00197 "\"full\" Creates one file for all tables, default.\n" .
00198 '"tables" Creates for each table within each database a seperate file.',
00199 '--comment' => 'Comment for filename. May contain alphanumics, \'-\' and \'_\'.',
00200 '--datetime' => 'Adds an optional datetime string to each result file. Format YYYY-MM-DDThh:mm',
00201 '--bzip2' => 'Use bzip2 for compression of each sql dump.',
00202 ),
00203 );
00204 return $items;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 function multi_status() {
00217
00218
00219
00220 drush_core_status();
00221
00222 $table = $sites = array();
00223
00224
00225 $sites = _multi_scan_sites();
00226
00227
00228 $table['Site Counter'] = count($sites);
00229
00230
00231 if(count($sites) != 0 ){
00232 $table['Sites'] = implode(' ', $sites);
00233 }
00234
00235
00236 if ($versions = _multi_previous_installations() != 0) {
00237 $table['Prev. Installations'] = implode(' ', $versions);
00238 }
00239
00240
00241 if ($recommended_version = _multi_recommended_version(
00242 drush_drupal_major_version().'.x', 'drupal', TRUE)
00243 ) {
00244 if (drush_drupal_version() < $recommended_version) {
00245 $table['Drupal core status'] = $recommended_version . " available";
00246 }
00247 else {
00248 $table['Drupal core status'] = 'Uptodate';
00249 }
00250 }
00251 else {
00252 $table['Drupal core status'] = 'Unknown';
00253 }
00254 drush_print_table(drush_key_value_to_array_table($table), TRUE);
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 function multi_nagios() {
00270
00271
00272 $uri = drush_get_option(array('uri','l'));
00273
00274 if (!empty($uri)) {
00275 return _multi_nagios_site();
00276 }
00277 else {
00278
00279 return _multi_nagios_root();
00280 }
00281 }
00282
00283
00284
00285
00286
00287
00288 function multi_moo() {
00289
00290 $cowsay = "\n ------------\n";
00291 $cowsay .= "< i <3 drush >\n";
00292 $cowsay .= " ------------\n";
00293 $cowsay .= " \ ^__^\n";
00294 $cowsay .= " \ (oo)\_______\n";
00295 $cowsay .= " (__)\ )\/\\\n";
00296 $cowsay .= " ||----w |\n";
00297 $cowsay .= " || ||\n";
00298 $cowsay .= "This drush has super cow powers!";
00299 drush_print($cowsay);
00300 }
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 function drush_multi_sql_dump_validate() {
00321
00322
00323 if (in_array('--bzip2', $GLOBALS['argv'])) {
00324 drush_set_option('bzip2', TRUE);
00325 }
00326
00327
00328 if (in_array('--datetime', $GLOBALS['argv'])) {
00329 drush_set_option('datetime', '_' . date('Y-m-d\TH:i')) ;
00330 }
00331
00332
00333 $target = drush_get_option('target');
00334 if (!empty($target)) {
00335 if (!is_dir($target)) {
00336 return drush_set_error('MULTI_TARGET_IS_NOT_A_DIRECTORY', 'Supplied argument for target is not a directory. Aborting.');
00337 }
00338
00339
00340 if (!is_writable($target)) {
00341 return drush_set_error('MULTI_TARGET_NOT_WRITABLE',
00342 dt('Directory !dir is not writable. Aborting.', array('!dir' => $target))
00343 );
00344 }
00345 }
00346 else {
00347
00348 drush_set_option('target', '/tmp');
00349 }
00350
00351
00352 $comment = drush_get_option('comment');
00353 if (isset($comment)) {
00354 if (!preg_match("/^[a-zA-Z0-9\-_]{1,}$/", $comment)) {
00355 return drush_set_error('MULTI_INVALID_COMMENT_ARGUMENT',
00356 dt('Invalid argument for comment, only alphanumerics, "-" and "_" allowed. Aborting.')
00357 );
00358 }
00359 else {
00360
00361 drush_set_option('comment', '_' . $comment);
00362 }
00363 }
00364
00365
00366 $dump_type = drush_get_option('dump-type','full');
00367
00368 $dump_types = array('full','tables');
00369 if (!in_array($dump_type, $dump_types )) {
00370 return drush_set_error('MULTI_INVALID_DUMP_TYPE_ARGUMENT',
00371 dt('Invalid argument for dump-type. Aborting.')
00372 );
00373 }
00374 }
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 function drush_multi_sql_dump() {
00387
00388 $dump_type = drush_get_option('dump-type', 'full');
00389 $db_spec = _drush_sql_get_db_spec();
00390
00391 $site = drush_get_option(array('uri','l'));
00392 $datetime = drush_get_option('datetime');
00393 $comment = drush_get_option('comment');
00394 $target = drush_get_option('target');
00395
00396
00397 if ($dump_type == 'full') {
00398 _multi_sql_dump_full($db_spec, $site, $datetime, $comment, $target);
00399 }
00400
00401 else {
00402 _multi_sql_dump_tables($db_spec, $site, $datetime, $comment, $target);
00403 }
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416 function drush_multi_create_validate($destination, $document_root = NULL) {
00417
00418
00419 if (!$destination) {
00420 return drush_set_error('MULTI_MISSING_DESTINATION',
00421 dt('Missing argument for destination. Aborting'));
00422 }
00423 else {
00424 if (!is_dir($destination)) {
00425 return drush_set_error('MULTI_INVALID_DESTINATION',
00426 dt('Invalid argument for destination, "!destination" is no directory. Aborting',
00427 array('!destination' => $destination)
00428 )
00429 );
00430 }
00431 if (!is_writable($destination)){
00432 return drush_set_error('MULTI_DESTINATION_NOT_WRITABLE',
00433 dt('Destinattion !destination is not writable. Aborting',
00434 array(
00435 '!destination' => $destination,
00436 )
00437 )
00438 );
00439 }
00440 }
00441
00442
00443 $makefile = drush_get_option('makefile');
00444
00445 if ($makefile) {
00446
00447 if (!drush_is_command('make')) {
00448 return drush_set_error('MULTI_MAKE_UNAVAILABLE', 'Could not find drush_make');
00449 }
00450 if (!is_file($makefile)) {
00451 return drush_set_error('MULTI_INVALID_MAKEFILE',
00452 dt('Invalid argument for makefile, file !makefile does not exist. Aborting',
00453 array('!makefile' => $makefile)
00454 )
00455 );
00456 }
00457
00458 $parsed_makefile = drush_make_parse_info_file($makefile);
00459
00460
00461 if (!in_array('drupal', $parsed_makefile['projects'])){
00462 $core_project = FALSE;
00463 foreach ($parsed_makefile['projects'] as $project) {
00464 if (is_array($project)) {
00465 if (array_search('core', $project)) {
00466 $core_project = TRUE;
00467 }
00468 }
00469 }
00470 }
00471 else {
00472 $core_project = TRUE;
00473 }
00474 if (!$core_project){
00475 return drush_set_error('MULTI_MAKE_NO_CORE_PROJECT','A core project must be supplied in the makefile. Aborting.');
00476 }
00477 $core = FALSE;
00478 $core = $parsed_makefile['core'];
00479
00480 if (!$core) {
00481 return drush_set_error('MULTI_MAKE_NO_CORE', 'Core must be supplied in the makefile. Aborting.');
00482 }
00483 else {
00484
00485 drush_set_option('core', $core);
00486 }
00487 }
00488 }
00489
00490
00491
00492
00493
00494 function drush_multi_create($destination, $document_root = NULL) {
00495
00496 $destination = realpath($destination);
00497 $core = drush_get_option('core');
00498
00499 if (!$recommended_version = _multi_recommended_version($core)) {
00500 return $recommended_version;
00501 }
00502 if ($document_root == NULL) {
00503 $document_root_destination = 'drupal-' . strtolower($recommended_version['version']);
00504 $document_root = $core;
00505 }
00506 else {
00507 $document_root_destination = $document_root . '-' . strtolower($recommended_version['version']);
00508 }
00509
00510 if ($makefile = rtrim(drush_get_option('makefile'), '/')) {
00511 drush_invoke('make', $makefile, $destination . '/' . $document_root_destination);
00512 }
00513
00514 else {
00515 $recommended_version = 'drupal-' . strtolower($recommended_version['version']);
00516 drush_set_option('package-handler', 'wget');
00517 drush_set_option('destination', $destination);
00518 drush_set_context('DRUSH_NOCOLOR', 1);
00519 drush_invoke('pm-download', $recommended_version);
00520 drush_set_context('DRUSH_NOCOLOR', 0);
00521 }
00522
00523
00524 if (!drush_op('chdir', $destination)) {
00525 return drush_set_error('MULTI_COULD_NOT_CHANGE_TO_DESTINATION',
00526 dt('Could not change to !destination. Aborting.',
00527 array('!destination' => $destination)
00528 )
00529 );
00530 }
00531
00532
00533 if (!drush_op('mkdir', $document_root . '_backup')) {
00534 return drush_set_error('MULTI_COULD_NOT_CREATE_BACKUP_DIR',
00535 dt('Could not create backup directory "!pwd/!document_root.x_backup". Aborting.',
00536 array('!pwd' => drush_cwd(), '!document_root' => $document_root)
00537 )
00538 );
00539 }
00540
00541
00542 if (!drush_op('mkdir', $document_root . '_sites')) {
00543 return drush_set_error('MULTI_COULD_NOT_CREATE_SITES_DIR',
00544 dt('Could not create sites directory "!pwd/!document_root_sites". Aborting.',
00545 array('!pwd' => drush_cwd(), '!document_root' => $document_root)
00546 )
00547 );
00548 }
00549
00550 $dir = realpath($destination . '/' . $document_root_destination . '/sites');
00551
00552
00553 $exec = 'cp -r ' . $dir . '/* ' . $document_root . '_sites';
00554 if (!drush_shell_exec($exec)) {
00555 return drush_set_error('MULTI_COULD_NOT_COPY_SITES_DEFAULT_DIR',
00556 dt('Could not copy !dir to !target',
00557 array('!dir' => $dir . '/default', '!target' => $document_root . '.x_sites')
00558 )
00559 );
00560 }
00561
00562
00563
00564 $exec = 'mv ' . $dir . ' ' . $dir . '.bak';
00565 if (!drush_shell_exec($exec)) {
00566 return drush_set_error('MULTI_COULD_NOT_RENAME_SITES_DIR',
00567 dt('Could not rename sites directory !dir to !target',
00568 array('!dir' => $dir, '!target' => $dir . '.bak')
00569 )
00570 );
00571 }
00572
00573
00574 if (!drush_op('mkdir', $document_root . '_profiles')) {
00575 return drush_set_error('MULTI_COULD_NOT_CREATE_PROFILES_DIR',
00576 dt('Could not create profiles directory "!pwd/!document_root_profiles". Aborting.',
00577 array('!pwd' => drush_cwd(),
00578 '!document_root' => $document_root)
00579 )
00580 );
00581 }
00582
00583 $dir = realpath($destination . '/' . $document_root_destination . '/profiles');
00584
00585
00586 $exec = 'cp -r ' . $dir . '/* ' . $document_root . '_profiles';
00587 if (!drush_shell_exec($exec)) {
00588 return drush_set_error('MULTI_COULD_NOT_COPY_PROFILES_DEFAULT_DIR',
00589 dt('Could not copy !dir to !target',
00590 array('!dir' => $dir . '/default', '!target' => $document_root . '_profiles')
00591 )
00592 );
00593 }
00594
00595
00596
00597 $exec = 'mv ' . $dir . ' ' . $dir . '.bak';
00598 if (!drush_shell_exec($exec)) {
00599 return drush_set_error('MULTI_COULD_NOT_RENAME_DEFAULT_DIR',
00600 dt('Could not rename profiles directory !dir to !target',
00601 array('!dir' => $dir, '!target' => $dir . '.bak')
00602 )
00603 );
00604 }
00605
00606
00607 if(drush_op('chdir', realpath($destination . '/' . $document_root_destination))) {
00608
00609 $sites_dir = _multi_relative_path($destination . '/' . $document_root .'_sites');
00610 if (!drush_op('symlink', $sites_dir, 'sites')) {
00611 return drush_set_error('MULTI_COULD_NOT_CREATE_SITES_SYMLINK',
00612 dt('symlink(): Unable to create symlink from !source into !target for sites-directory.',
00613 array('!source' => $sites_dir, '!target' => getcwd() .'/sites')
00614 )
00615 );
00616 }
00617
00618 $profiles_dir = _multi_relative_path($destination . '/' . $document_root .'_profiles');
00619 if (!drush_op('symlink', $profiles_dir, 'profiles')) {
00620 return drush_set_error('MULTI_COULD_NOT_CREATE_PROFILES_SYMLINK',
00621 dt('symlink(): Unable to create relative symlink from !target into !target for backup-directory.',
00622 array('!target' => $profiles_dir, '!target' => getcwd())
00623 )
00624 );
00625 }
00626 }
00627 else {
00628 return drush_set_error('MULTI_COULD_NOT_CREATE_SITES_SYMLINK',
00629 dt('symlink(): Unable to create relative symlink from !target into !target for backup-directory.',
00630 array('!source' => $sites_dir, '!target' => getcwd())
00631 )
00632 );
00633 }
00634
00635 drush_op('chdir', $destination);
00636
00637
00638 if (!drush_op('symlink', $document_root_destination, $document_root)) {
00639 return drush_set_error('MULTI_COULD_NOT_SYMLINK_DOKUMENT_ROOT',
00640 dt('symlink(): Could not create symlink from !drupal to !document_root for DOCUMENT_ROOT',
00641 array('!drupal' => $document_root_destination, '!document_root' => $document_root)
00642 )
00643 );
00644 }
00645 }
00646
00647
00648
00649
00650 function drush_multi_create_rollback($destination, $document_root = NULL) {
00651
00652 }
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667 function drush_multi_drupalupdate_validate () {
00668
00669
00670 if (!is_writable(realpath(rtrim(drush_get_context('DRUSH_DRUPAL_ROOT'),'/') . '/..'))) {
00671 drush_set_error('MULTI_DRUPALUPDATE_DESTINATION_NOT_WRITABLE',
00672 dt('\'!destination\' is not writable, check permission. Aborting.',
00673 array('!destination' => $dest)
00674 )
00675 );
00676 }
00677
00678 $drupal_root = rtrim(drush_get_context('DRUSH_DRUPAL_ROOT'),'/');
00679
00680
00681 if (is_link($drupal_root)) {
00682
00683 $path_pieces = explode('/', $drupal_root);
00684 $link_name = $path_pieces[count($path_pieces)-1];
00685
00686 drush_set_context('DRUPAL_ROOT_SYMLINK', $link_name);
00687
00688 drush_set_context('DRUSH_DRUPAL_ROOT', $drupal_root);
00689 }
00690 else {
00691 drush_set_error('MULTI_DRUPALUPDATE_DRUPAL_ROOT_IS_NO_SYMLINK',
00692 dt('Drupal root !drupal_root is not a symbolic link. Aborting.',
00693 array('!drupal_root' => $drupal_root)
00694 )
00695 );
00696 }
00697
00698
00699 if (!$recommended_version = _multi_recommended_version(drush_drupal_major_version() . '.x')) {
00700
00701 return $recommended_version;
00702 }
00703 $recommended_version = 'drupal-' . strtolower($recommended_version['version']);
00704
00705 drush_set_context('DRUPAL_RECOMMENDED_VERSION', $recommended_version);
00706
00707
00708 if (_multi_current_version() == $recommended_version) {
00709 drush_user_abort('Your drupal version is uptodate. Aborting');
00710 }
00711
00712
00713 if (in_array('--updatedb', $argv = $GLOBALS['argv'])) {
00714 drush_set_option('--updatedb', TRUE);
00715 }
00716
00717
00718 if (in_array('--sql-dump', $argv = $GLOBALS['argv'])) {
00719 drush_set_option('--sql-dump', TRUE);
00720 }
00721 }
00722
00723
00724
00725
00726
00727
00728
00729
00730 function drush_multi_pre_multi_drupalupdate() {
00731
00732 if (drush_get_option('--sql-dump')) {
00733 drush_shell_exec(DRUSH_COMMAND . ' -r ' . drush_get_context('DRUSH_DRUPAL_ROOT') . ' @sites' . ' multi-sql-dump -yd');
00734 }
00735 if (drush_get_option('--updatedb')) {
00736 drush_shell_exec(DRUSH_COMMAND . ' -r ' . drush_get_context('DRUSH_DRUPAL_ROOT') . ' @sites' . ' variable-set site_offline 1 -yd');
00737 }
00738 }
00739
00740
00741
00742
00743
00744
00745
00746
00747 function drush_multi_drupalupdate() {
00748
00749
00750 $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
00751 $link_name = drush_get_context('DRUPAL_ROOT_SYMLINK');
00752 $recommended_version = drush_get_context('DRUPAL_RECOMMENDED_VERSION');
00753 $version = drush_drupal_version();
00754 $dest = realpath($drupal_root . '/../');
00755
00756
00757 drush_set_option('destination', $dest);
00758 drush_set_option('package-handler', 'wget');
00759 drush_set_context('DRUSH_NOCOLOR', 1);
00760 drush_invoke('pm-download', $recommended_version);
00761 drush_set_context('DRUSH_NOCOLOR', 0);
00762
00763
00764
00765
00766 _multi_preserve_symlinks($drupal_root, $dest . '/' . $recommended_version);
00767
00768
00769 if (drush_op('chdir', '..')) {
00770
00771 if (!drush_op('unlink', $link_name)) {
00772 return drush_set_error('DRUSH_SM_COULD_NOT_UNLINK_DOKUMENT_ROOT',
00773 dt('unlink(): Could not unlink !doc_root.', array('!doc_root' => $link_name))
00774 );
00775 }
00776
00777 if (!drush_op('symlink', $recommended_version, $link_name)) {
00778 return drush_set_error('DRUSH_SM_COULD_NOT_SYMLINK_DOKUMENT_ROOT',
00779 dt('symlink(): Could not create symlink from !drupal to !link for DOCUMENT_ROOT.',
00780 array('!drupal' => $recommended_version, '!link' => $link_name)
00781 )
00782 );
00783 }
00784 }
00785
00786 else {
00787 return drush_set_error('DRUSH_SM_COULD_CHANGE_INTO_DRUPAL_PARENT',
00788 dt('chdir(): Could not change to parent of drupal directory.')
00789 );
00790 }
00791 }
00792
00793
00794
00795
00796 function drush_multi_drupalupdate_rollback() {
00797
00798 }
00799
00800
00801
00802
00803
00804
00805 function drush_multi_post_multi_drupalupdate() {
00806
00807 if (drush_get_option('--updatedb')) {
00808
00809 drush_shell_exec(DRUSH_COMMAND . ' -r ' . drush_get_context('DRUSH_DRUPAL_ROOT') . ' @sites' . ' updatedb -yd');
00810 drush_shell_exec(DRUSH_COMMAND . ' -r ' . drush_get_context('DRUSH_DRUPAL_ROOT') . ' @sites' . ' variable-set site_offline 0 -yd');
00811 drush_log(dt('Drupalupdate finished.'), 'completed');
00812 }
00813 else {
00814 drush_log(dt('Drupalupdate finished, now you should run update.php for each site'), 'completed');
00815 }
00816 }
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830 function drush_multi_site_validate($site_name) {
00831
00832 if (!$site_name) {
00833 return drush_set_error('MULTI_SITE_MISSING_SITE_ARGUMENT',
00834 dt('Missing site argument.')
00835 );
00836 }
00837 else {
00838
00839 }
00840
00841 if($directories_option = drush_get_option('create-directories')) {
00842 $directories = array();
00843 $directories = explode(',', $directories_option);
00844 foreach ($directories as $directory) {
00845
00846 ltrim($directory, '/');
00847 }
00848 }
00849 }
00850
00851
00852
00853
00854
00855 function drush_multi_pre_multi_site($site_name) {
00856
00857 $sites_dir = rtrim(drush_get_context('DRUSH_DRUPAL_ROOT'),'/') . '/sites/';
00858 if (!is_writable($sites_dir)) {
00859 return drush_set_error('MULTI_SITE_SITES_DIR_NOT_WRITABLE',
00860 dt('Site directory \'!sites_dir\' is not writable.', array('!sites_dir' => $sites_dir))
00861 );
00862 }
00863 if (is_dir($sites_dir .'/' . $site_name)) {
00864 return drush_set_error('MULTI_SITE_SITE_DIR_ALREADY_EXISTS',
00865 dt('The supplied sitename !site_name already exists within !sites_dir. Aborting.',
00866 array(
00867 '!site_name' => $site_name,
00868 '!sites_dir' => $sites_dir
00869 )
00870 )
00871 );
00872 }
00873 }
00874
00875
00876
00877
00878
00879 function drush_multi_site($site_name) {
00880
00881 $sites_dir = rtrim(drush_get_context('DRUSH_DRUPAL_ROOT'),'/') . '/sites/';
00882 $site = $sites_dir . $site_name;
00883
00884
00885 if (!drush_op('mkdir', $site)) {
00886 drush_set_error('MULTI_SITE_COULD_NOT_CREATE_SITE_DIR',
00887 dt('Could not create site directory !dir.', array('!dir' => $site))
00888 );
00889 }
00890
00891
00892 if (!drush_op('chdir', $site)) {
00893 drush_set_error('MULTI_SITE_COULD_NOT_CWD',
00894 dt('Could not change to !dir.', array('!dir' => $site))
00895 );
00896 }
00897
00898
00899 switch (drush_drupal_major_version()){
00900 case '5':
00901
00902 $settings_src = $sites_dir . 'default/settings.php';
00903 if (!drush_op('copy', $settings_src, 'settings.php')) {
00904 drush_set_error('MULTI_SITE_COULD_NOT_COPY_DEFAULT_SETTINGS',
00905 dt('Could not copy !src to settings.php.', array('!src' => $settings_src))
00906 );
00907 }
00908 break;
00909 case '6':
00910 case '7':
00911
00912 $settings_src = $sites_dir . 'default/default.settings.php';
00913 if (!drush_op('copy', $settings_src, 'settings.php')) {
00914 drush_set_error('MULTI_SITE_COULD_NOT_COPY_DEFAULT_SETTINGS',
00915 dt('Could not copy !src to settings.php.', array('!src' => $settings_src))
00916 );
00917 }
00918 break;
00919 }
00920
00921 $directories = array();
00922
00923
00924 $directories[] = 'files';
00925 $directories[] = 'modules';
00926 $directories[] = 'themes';
00927
00928
00929 if($directories_option = drush_get_option('create-directories')) {
00930 $tmp = array();
00931 $tmp = explode(',', $directories_option);
00932 $directories = array_merge($directories, $tmp);
00933 }
00934
00935
00936 foreach ($directories as $directory) {
00937 if (!drush_op('mkdir', $directory, 0755, TRUE)) {
00938 drush_set_error('MULTI_SITE_COULD_NOT_DIRECTORY',
00939 dt('Could not create directory \'!dir\'', array('!dir' => $directory))
00940 );
00941 }
00942 }
00943 }
00944
00945
00946
00947
00948
00949
00950 function drush_multi_post_multi_site($site_name){
00951
00952 $site_path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/' . $site_name;
00953
00954 $apache_user = drush_get_option('multi-apache-user');
00955 $apache_group = drush_get_option('multi-apache-group');
00956
00957 if ($apache_user){
00958 drush_op('chown', $site_path . '/settings.php', $apache_user);
00959 drush_op('chown', $site_path . '/files', $apache_user);
00960 }
00961 if ($apache_group){
00962 drush_op('chgrp', $site_path . '/settings.php', $apache_group);
00963 drush_op('chgrp', $site_path . '/files', $apache_group);
00964 }
00965 }
00966
00967
00968
00969
00970
00971 function drush_multi_site_rollback($site_name) {
00972 if (!drush_cmp_error('MULTI_SITE_COULD_NOT_CREATE_SITE_DIR')) {
00973 delete_dir(rtrim(drush_get_context('DRUSH_DRUPAL_ROOT'),'/') . '/sites/'. $site_name);
00974 }
00975 }
00976
00977
00978