diff --git a/.travis.yml b/.travis.yml index d96d4217a6..198b88399d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,11 +18,6 @@ sudo: false env: matrix: -#D6 - - UNISH_DRUPAL_MAJOR_VERSION=6 PHPUNIT_ARGS=--group=base - - UNISH_DRUPAL_MAJOR_VERSION=6 PHPUNIT_ARGS=--group=commands - - UNISH_DRUPAL_MAJOR_VERSION=6 PHPUNIT_ARGS=--group=pm - - UNISH_DRUPAL_MAJOR_VERSION=6 PHPUNIT_ARGS=--exclude-group=base,make,commands,pm,quick-drupal #D7 - UNISH_DRUPAL_MAJOR_VERSION=7 PHPUNIT_ARGS=--group=make - UNISH_DRUPAL_MAJOR_VERSION=7 PHPUNIT_ARGS=--group=base @@ -56,18 +51,6 @@ env: - UNISH_NO_TIMEOUTS=y - UNISH_DB_URL=mysql://root:@127.0.0.1 -matrix: - exclude: - - php: 7.0 - env: UNISH_DRUPAL_MAJOR_VERSION=6 PHPUNIT_ARGS=--group=base - - php: 7.0 - env: UNISH_DRUPAL_MAJOR_VERSION=6 PHPUNIT_ARGS=--group=commands - - php: 7.0 - env: UNISH_DRUPAL_MAJOR_VERSION=6 PHPUNIT_ARGS=--group=pm - - php: 7.0 - env: UNISH_DRUPAL_MAJOR_VERSION=6 PHPUNIT_ARGS=--exclude-group=base,make,commands,pm,quick-drupal - - before_install: - echo 'mbstring.http_input = pass' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - echo 'mbstring.http_output = pass' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini diff --git a/commands/core/archive.drush.inc b/commands/core/archive.drush.inc index 402ea43f13..acd7cb1976 100644 --- a/commands/core/archive.drush.inc +++ b/commands/core/archive.drush.inc @@ -14,7 +14,8 @@ function archive_drush_command() { 'arguments' => array( 'sites' => 'Optional. Site specifications, delimited by commas. Typically, list subdirectory name(s) under /sites.', ), - 'options' => array( + // Most options on sql-dump should not be shown, so just offer a subset. + 'options' => drush_sql_get_table_selection_options() + array( 'description' => 'Describe the archive contents.', 'tags' => 'Add tags to the archive manifest. Delimit multiple by commas.', 'destination' => 'The full path and filename in which the archive should be stored. If omitted, it will be saved to the drush-backups directory and a filename will be generated.', diff --git a/commands/core/config.drush.inc b/commands/core/config.drush.inc index 9d723de45a..99151a5770 100644 --- a/commands/core/config.drush.inc +++ b/commands/core/config.drush.inc @@ -32,6 +32,7 @@ function config_drush_help($section) { * Implementation of hook_drush_command(). */ function config_drush_command() { + $deps = array('drupal dependencies' => array('config')); $items['config-get'] = array( 'description' => 'Display a config value, or a whole configuration object.', 'arguments' => array( @@ -116,7 +117,7 @@ function config_drush_command() { ), ); - $items['config-import'] = array( + $items['config-import'] = $deps + array( 'description' => 'Import config from a config directory.', 'arguments' => array( 'label' => "A config directory label (i.e. a key in \$config_directories array in settings.php). Defaults to 'sync'", @@ -160,8 +161,8 @@ function config_drush_command() { ), ); - $items['config-edit'] = array( - 'description' => 'Open a config file in a text editor. Edits are imported into active configration after closing editor.', + $items['config-edit'] = $deps + array( + 'description' => 'Open a config file in a text editor. Edits are imported into active configuration after closing editor.', 'core' => array('8+'), 'aliases' => array('cedit'), 'arguments' => array( @@ -272,7 +273,7 @@ function drush_config_set($config_name, $key = NULL, $data = NULL) { return drush_set_error('DRUSH_CONFIG_ERROR', dt('No config value specified.')); } - $config = Drupal::configFactory()->getEditable($config_name); + $config = \Drupal::configFactory()->getEditable($config_name); // Check to see if config key already exists. if ($config->get($key) === NULL) { $new_key = TRUE; @@ -436,7 +437,7 @@ function _drush_config_export($destination, $destination_dir, $branch) { // Retrieve a list of differences between the active and target configuration (if any). $target_storage = new FileStorage($destination_dir); /** @var \Drupal\Core\Config\StorageInterface $active_storage */ - $active_storage = Drupal::service('config.storage'); + $active_storage = \Drupal::service('config.storage'); $comparison_source = $active_storage; // If the output is being filtered, then write a temporary copy before doing @@ -454,7 +455,7 @@ function _drush_config_export($destination, $destination_dir, $branch) { } } - $config_comparer = new StorageComparer($comparison_source, $target_storage, Drupal::service('config.manager')); + $config_comparer = new StorageComparer($comparison_source, $target_storage, \Drupal::service('config.manager')); if (!$config_comparer->createChangelist()->hasChanges()) { return drush_log(dt('The active configuration is identical to the configuration in the export directory (!target).', array('!target' => $destination_dir)), LogLevel::OK); } @@ -482,7 +483,7 @@ function _drush_config_export($destination, $destination_dir, $branch) { } // Write all .yml files. - $source_storage = Drupal::service('config.storage'); + $source_storage = \Drupal::service('config.storage'); $destination_storage = new FileStorage($destination_dir); // If there are any filters, then attach them to the destination storage if (!empty($storage_filters)) { @@ -605,7 +606,7 @@ function drush_config_import($source = NULL) { // Determine $source_storage in partial and non-partial cases. /** @var \Drupal\Core\Config\StorageInterface $active_storage */ - $active_storage = Drupal::service('config.storage'); + $active_storage = \Drupal::service('config.storage'); if (drush_get_option('partial')) { $source_storage = new StorageReplaceDataWrapper($active_storage); $file_storage = new FileStorage($source_dir); @@ -627,7 +628,7 @@ function drush_config_import($source = NULL) { } /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */ - $config_manager = Drupal::service('config.manager'); + $config_manager = \Drupal::service('config.manager'); $storage_comparer = new StorageComparer($source_storage, $active_storage, $config_manager); @@ -666,14 +667,14 @@ function drush_config_import($source = NULL) { function _drush_config_import(StorageComparer $storage_comparer) { $config_importer = new ConfigImporter( $storage_comparer, - Drupal::service('event_dispatcher'), - Drupal::service('config.manager'), - Drupal::lock(), - Drupal::service('config.typed'), - Drupal::moduleHandler(), - Drupal::service('module_installer'), - Drupal::service('theme_handler'), - Drupal::service('string_translation') + \Drupal::service('event_dispatcher'), + \Drupal::service('config.manager'), + \Drupal::lock(), + \Drupal::service('config.typed'), + \Drupal::moduleHandler(), + \Drupal::service('module_installer'), + \Drupal::service('theme_handler'), + \Drupal::service('string_translation') ); if ($config_importer->alreadyImporting()) { drush_log('Another request may be synchronizing configuration already.', LogLevel::WARNING); @@ -704,7 +705,7 @@ function _drush_config_import(StorageComparer $storage_comparer) { function drush_config_edit($config_name = '') { // Identify and validate input. if ($config_name) { - $config = Drupal::configFactory()->get($config_name); + $config = \Drupal::configFactory()->get($config_name); if ($config->isNew()) { return drush_set_error(dt('Config !name does not exist', array('!name' => $config_name))); } @@ -717,7 +718,7 @@ function drush_config_edit($config_name = '') { } else { $config_name = $config_names[$choice]; - $config = Drupal::configFactory()->get($config_name); + $config = \Drupal::configFactory()->get($config_name); } } diff --git a/commands/core/core.drush.inc b/commands/core/core.drush.inc index 189c911a25..d4f36b6245 100644 --- a/commands/core/core.drush.inc +++ b/commands/core/core.drush.inc @@ -1194,9 +1194,8 @@ function _drush_core_eval_shebang_script($script_filename) { return $found; } - /** - * Process sets from the specified batch. + * Command callback. Process sets from the specified batch. * * This is the default batch processor that will be used if the $command parameter * to drush_backend_batch_process() has not been specified. @@ -1206,7 +1205,7 @@ function drush_core_batch_process($id) { } /** - * Process outstanding updates during updatedb. + * Command callback. Process outstanding updates during updatedb. * * This is a batch processing command that makes use of the drush_backend_invoke * api. diff --git a/commands/core/drupal/batch.inc b/commands/core/drupal/batch.inc index 5c12b97978..f883781e69 100644 --- a/commands/core/drupal/batch.inc +++ b/commands/core/drupal/batch.inc @@ -50,14 +50,21 @@ function _drush_backend_batch_process($command = 'batch-process', $args, $option drush_include_engine('drupal', 'environment'); // Store the batch. - db_insert('batch') - ->fields(array( - 'bid' => $batch['id'], - 'timestamp' => REQUEST_TIME, - 'token' => drush_get_token($batch['id']), - 'batch' => serialize($batch), - )) - ->execute(); + if (drush_drupal_major_version() >= 8) { + /** @var \Drupal\Core\Batch\BatchStorage $batch_storage */ + $batch_storage = \Drupal::service('batch.storage'); + $batch_storage->create($batch); + } + else { + db_insert('batch') + ->fields(array( + 'bid' => $batch['id'], + 'timestamp' => REQUEST_TIME, + 'token' => drush_get_token($batch['id']), + 'batch' => serialize($batch), + )) + ->execute(); + } $finished = FALSE; // Not used in D8+ and possibly earlier. @@ -235,16 +242,24 @@ function _drush_batch_finished() { $queue = _batch_queue($batch_set); $operations = $queue->getAllItems(); $elapsed = $batch_set['elapsed'] / 1000; - $elapsed = drush_drupal_major_version() >=8 ? Drupal::service('date.formatter')->formatInterval($elapsed) : format_interval($elapsed); + $elapsed = drush_drupal_major_version() >=8 ? \Drupal::service('date.formatter')->formatInterval($elapsed) : format_interval($elapsed); $batch_set['finished']($batch_set['success'], $batch_set['results'], $operations, $elapsed); } } } // Clean up the batch table and unset the static $batch variable. - db_delete('batch') - ->condition('bid', $batch['id']) - ->execute(); + if (drush_drupal_major_version() >= 8) { + /** @var \Drupal\Core\Batch\BatchStorage $batch_storage */ + $batch_storage = \Drupal::service('batch.storage'); + $batch_storage->delete($batch['id']); + } + else { + db_delete('batch') + ->condition('bid', $batch['id']) + ->execute(); + } + foreach ($batch['sets'] as $batch_set) { if ($queue = _batch_queue($batch_set)) { $queue->deleteQueue(); @@ -261,9 +276,16 @@ function _drush_batch_finished() { */ function _drush_batch_shutdown() { if ($batch = batch_get()) { - db_update('batch') - ->fields(array('batch' => serialize($batch))) - ->condition('bid', $batch['id']) - ->execute(); + if (drush_drupal_major_version() >= 8) { + /** @var \Drupal\Core\Batch\BatchStorage $batch_storage */ + $batch_storage = \Drupal::service('batch.storage'); + $batch_storage->update($batch); + } + else { + db_update('batch') + ->fields(array('batch' => serialize($batch))) + ->condition('bid', $batch['id']) + ->execute(); + } } } diff --git a/commands/core/drupal/batch_6.inc b/commands/core/drupal/batch_6.inc deleted file mode 100644 index 11bbb5a8f2..0000000000 --- a/commands/core/drupal/batch_6.inc +++ /dev/null @@ -1,199 +0,0 @@ - 0, - ); - $batch += $process_info; - - // Initiate db storage in order to get a batch id. We have to provide - // at least an empty string for the (not null) 'token' column. - db_query("INSERT INTO {batch} (token, timestamp) VALUES ('', %d)", time()); - $batch['id'] = db_last_insert_id('batch', 'bid'); - $args[] = $batch['id']; - - // Actually store the batch data and the token generated form the batch id. - db_query("UPDATE {batch} SET token = '%s', batch = '%s' WHERE bid = %d", drupal_get_token($batch['id']), serialize($batch), $batch['id']); - - $finished = FALSE; - - while (!$finished) { - $data = drush_invoke_process('@self', $command, $args, $options); - $finished = drush_get_error() || !$data || (isset($data['context']['drush_batch_process_finished']) && $data['context']['drush_batch_process_finished'] == TRUE); - } - } -} - -/** - * Initialize the batch command and call the worker function. - * - * Loads the batch record from the database and sets up the requirements - * for the worker, such as registering the shutdown function. - * - * @param id - * The batch id of the batch being processed. - */ -function _drush_batch_command($id) { - $batch =& batch_get(); - // Retrieve the current state of batch from db. - if ($data = db_result(db_query("SELECT batch FROM {batch} WHERE bid = %d", $id))) { - $batch = unserialize($data); - } - else { - return FALSE; - } - if (!isset($batch['running'])) { - $batch['running'] = TRUE; - } - - // Register database update for end of processing. - register_shutdown_function('_drush_batch_shutdown'); - - if (_drush_batch_worker()) { - _drush_batch_finished(); - } -} - -/** - * Process batch operations - * - * Using the current $batch process each of the operations until the batch - * has been completed or half of the available memory for the process has been - * reached. - */ -function _drush_batch_worker() { - $batch =& batch_get(); - $current_set =& _batch_current_set(); - $set_changed = TRUE; - - timer_start('batch_processing'); - - while (!$current_set['success']) { - // If this is the first time we iterate this batch set in the current - // request, we check if it requires an additional file for functions - // definitions. - if ($set_changed && isset($current_set['file']) && is_file($current_set['file'])) { - include_once($current_set['file']); - } - - $finished = 1; - $task_message = ''; - if ((list($function, $args) = reset($current_set['operations'])) && function_exists($function)) { - // Build the 'context' array, execute the function call, - // and retrieve the user message. - $batch_context = array('sandbox' => &$current_set['sandbox'], 'results' => &$current_set['results'], 'finished' => &$finished, 'message' => &$task_message); - // Magic wrap to catch changes to 'message' key. - $batch_context = new DrushBatchContext($batch_context); - // Process the current operation. - call_user_func_array($function, array_merge($args, array(&$batch_context))); - $finished = $batch_context['finished']; - } - - if ($finished >= 1) { - // Make sure this step isn't counted double when computing $current. - $finished = 0; - // Remove the operation and clear the sandbox. - array_shift($current_set['operations']); - $current_set['sandbox'] = array(); - } - - // If the batch set is completed, browse through the remaining sets, - // executing 'control sets' (stored form submit handlers) along the way - - // this might in turn insert new batch sets. - // Stop when we find a set that actually has operations. - $set_changed = FALSE; - $old_set = $current_set; - while (empty($current_set['operations']) && ($current_set['success'] = TRUE) && _batch_next_set()) { - $current_set =& _batch_current_set(); - $set_changed = TRUE; - } - // At this point, either $current_set is a 'real' batch set (has operations), - // or all sets have been completed. - - - // TODO - replace with memory check! - // If we're in progressive mode, stop after 1 second. - if ((memory_get_usage() * 2) >= drush_memory_limit()) { - drush_log(dt("Batch process has consumed in excess of 50% of available memory. Starting new thread"), LogLevel::BATCH); - break; - } - } - - // Gather progress information. - - // Reporting 100% progress will cause the whole batch to be considered - // processed. If processing was paused right after moving to a new set, - // we have to use the info from the new (unprocessed) one. - if ($set_changed && isset($current_set['operations'])) { - // Processing will continue with a fresh batch set. - $remaining = count($current_set['operations']); - $total = $current_set['total']; - $task_message = ''; - } - else { - $remaining = count($old_set['operations']); - $total = $old_set['total']; - } - - $current = $total - $remaining + $finished; - $percentage = $total ? floor($current / $total * 100) : 100; - - return ($percentage == 100); -} - -/** - * End the batch processing: - * Call the 'finished' callbacks to allow custom handling of results, - * and resolve page redirection. - */ -function _drush_batch_finished() { - $batch =& batch_get(); - - // Execute the 'finished' callbacks for each batch set. - foreach ($batch['sets'] as $key => $batch_set) { - if (isset($batch_set['finished'])) { - // Check if the set requires an additional file for functions definitions. - if (isset($batch_set['file']) && is_file($batch_set['file'])) { - include_once($batch_set['file']); - } - if (function_exists($batch_set['finished'])) { - $batch_set['finished']($batch_set['success'], $batch_set['results'], $batch_set['operations']); - } - } - } - - // Cleanup the batch table and unset the global $batch variable. - db_query("DELETE FROM {batch} WHERE bid = %d", $batch['id']); - $_batch = $batch; - $batch = NULL; - drush_set_option('drush_batch_process_finished', TRUE); -} - -/** - * Shutdown function: store the batch data for next request, - * or clear the table if the batch is finished. - */ -function _drush_batch_shutdown() { - if ($batch = batch_get()) { - db_query("UPDATE {batch} SET batch = '%s' WHERE bid = %d", serialize($batch), $batch['id']); - } -} diff --git a/commands/core/drupal/cache.inc b/commands/core/drupal/cache.inc index a980d622fe..61b546ccf5 100644 --- a/commands/core/drupal/cache.inc +++ b/commands/core/drupal/cache.inc @@ -50,15 +50,9 @@ function _drush_cache_clear_types($include_bootstrapped_types) { 'module-list' => 'drush_get_modules', 'theme-list' => 'drush_get_themes', ); - } - $drupal_version = drush_drupal_major_version(); - - if ($drupal_version >= 7) { - $types['registry'] = 'registry_update'; - } - elseif ($drupal_version == 6 && function_exists('module_exists') && module_exists('autoload')) { - // TODO: move this to autoload module. - $types['registry'] = 'autoload_registry_update'; + if (drush_drupal_major_version() == 7) { + $types['registry'] = 'registry_update'; + } } return $types; diff --git a/commands/core/drupal/environment.inc b/commands/core/drupal/environment.inc index d588e230aa..1c122ae898 100644 --- a/commands/core/drupal/environment.inc +++ b/commands/core/drupal/environment.inc @@ -249,7 +249,7 @@ function drush_module_invoke_all($hook) { $args = func_get_args(); // Remove $hook from the arguments. array_shift($args); - return Drupal::moduleHandler()->invokeAll($hook, $args); + return \Drupal::moduleHandler()->invokeAll($hook, $args); } /** diff --git a/commands/core/drupal/environment_6.inc b/commands/core/drupal/environment_6.inc deleted file mode 100644 index 964704d38d..0000000000 --- a/commands/core/drupal/environment_6.inc +++ /dev/null @@ -1,398 +0,0 @@ - $module) { - if (!isset($module->type)) { - $module->type = 'module'; - } - if ((!$include_hidden) && isset($module->info['hidden']) && ($module->info['hidden'])) { - unset($modules[$key]); - } - } - - return $modules; -} - -/** - * Returns drupal required modules, including their dependencies. - * - * A module may alter other module's .info to set a dependency on it. - * See for example http://drupal.org/project/phpass - */ -function _drush_drupal_required_modules($module_info) { - $required = drupal_required_modules(); - foreach ($required as $module) { - $required = array_merge($required, $module_info[$module]->info['dependencies']); - } - return $required; -} - -/** - * Return dependencies and its status for modules. - * - * @param $modules - * Array of module names - * @param $module_info - * Drupal 'files' array for modules as returned by drush_get_modules(). - * @return - * Array with dependencies and status for $modules - */ -function drush_check_module_dependencies($modules, $module_info) { - $status = array(); - foreach ($modules as $key => $module) { - $dependencies = array_reverse($module_info[$module]->info['dependencies']); - $unmet_dependencies = array_diff($dependencies, array_keys($module_info)); - if (!empty($unmet_dependencies)) { - $status[$key]['error'] = array( - 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_NOT_FOUND', - '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))) - ); - } - $status[$key]['unmet-dependencies'] = $unmet_dependencies; - $status[$key]['dependencies'] = array(); - foreach ($dependencies as $dependency) { - $status[$key]['dependencies'][$dependency] = array('name' => $dependency); - } - } - - return $status; -} - -/** - * Return dependents of modules. - * - * @param $modules - * Array of module names - * @param $module_info - * Drupal 'files' array for modules as returned by drush_get_modules(). - * @return - * Array with dependents for each one of $modules - */ -function drush_module_dependents($modules, $module_info) { - $dependents = array(); - foreach ($modules as $module) { - $dependents = array_merge($dependents, $module_info[$module]->info['dependents']); - } - - return array_unique($dependents); -} - -/** - * Returns a list of enabled modules. - * - * This is a simplified version of module_list(). - */ -function drush_module_list() { - $enabled = array(); - $rsc = drush_db_select('system', 'name', 'type=:type AND status=:status', array(':type' => 'module', ':status' => 1)); - while ($row = drush_db_result($rsc)) { - $enabled[$row] = $row; - } - - return $enabled; -} - -/** - * Return a list of extensions from a list of named extensions. - * Both enabled and disabled/uninstalled extensions are returned. - */ -function drush_get_named_extensions_list($extensions) { - $result = array(); - $rsc = drush_db_select('system', array('name', 'status'), 'name IN (:extensions)', array(':extensions' => $extensions)); - while ($row = drush_db_fetch_object($rsc)) { - $result[$row->name] = $row; - } - return $result; -} - -/** - * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled. - * - * @param $modules - * Array of module names - */ -function drush_module_enable($modules) { - // Try to install modules previous to enabling. - foreach ($modules as $module) { - _drupal_install_module($module); - } - module_enable($modules); - drush_system_modules_form_submit(); -} - -/** - * Disable a list of modules. It is assumed the list contains all dependents not already disabled. - * - * @param $modules - * Array of module names - */ -function drush_module_disable($modules) { - module_disable($modules, FALSE); - drush_system_modules_form_submit(); -} - -/** - * Uninstall a list of modules. - * - * @param $modules - * Array of module names - */ -function drush_module_uninstall($modules) { - require_once DRUSH_DRUPAL_CORE . '/includes/install.inc'; - foreach ($modules as $module) { - drupal_uninstall_module($module); - } -} - -/** - * Checks that a given module exists and is enabled. - * - * @see module_exists(). - * - */ -function drush_module_exists($module) { - return module_exists($module); -} - -/** - * Determines which modules are implementing a hook. - * - */ -function drush_module_implements($hook, $sort = FALSE, $reset = FALSE) { - return module_implements($hook, $sort, $reset); -} - -/** - * Invokes a hook in a particular module. - * - */ -function drush_module_invoke($module, $hook) { - $args = func_get_args(); - return call_user_func_array('module_invoke', $args); -} - -/** - * Invokes a hook in all enabled modules that implement it. - * - */ -function drush_module_invoke_all($hook) { - $args = func_get_args(); - return call_user_func_array('module_invoke_all', $args); -} - -/** - * Submit the system modules form. - * - * The modules should already be fully enabled/disabled before calling this - * function. Calling this function just makes sure any activities triggered by - * the form submit (such as admin_role) are completed. - */ -function drush_system_modules_form_submit() { - $active_modules = array(); - foreach (drush_get_modules(FALSE) as $key => $module) { - if ($module->status == 1) { - $active_modules[$key] = $key; - } - } - module_load_include('inc', 'system', 'system.admin'); - $form_state = array('values' => array('status' => $active_modules)); - drupal_execute('system_modules', $form_state); -} - -/** - * Returns a list of enabled themes. Use drush_get_themes() if you need to rebuild - * and include hidden/disabled as well. - * - * @return array - * A list of themes keyed by name. - */ -function drush_theme_list() { - $enabled = array(); - foreach (list_themes() as $key => $info) { - if ($info->status) { - $enabled[$key] = $info; - } - } - return $enabled; -} - -/** - * Get complete information for all available themes. - * - * We need to set the type for those themes that are not already in the system table. - * - * @param $include_hidden - * Boolean to indicate whether hidden themes should be excluded or not. - * @return - * An array containing theme info for all available themes. - */ -function drush_get_themes($include_hidden = TRUE) { - $themes = system_theme_data(); - foreach ($themes as $key => $theme) { - if (!isset($theme->type)) { - $theme->type = 'theme'; - } - if ((!$include_hidden) && isset($theme->info['hidden']) && ($theme->info['hidden'])) { - unset($themes[$key]); - } - } - - return $themes; -} - -/** - * Enable a list of themes. - * - * This function is based on system_themes_form_submit(). - * - * @see system_themes_form_submit() - * @param $themes - * Array of theme names. - */ -function drush_theme_enable($themes) { - drupal_clear_css_cache(); - foreach ($themes as $theme) { - system_initialize_theme_blocks($theme); - } - db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' AND name IN (".db_placeholders($themes, 'text').")", $themes); - list_themes(TRUE); - menu_rebuild(); - module_invoke('locale', 'system_update', $themes); -} - -/** - * Disable a list of themes. - * - * This function is based on system_themes_form_submit(). - * - * @see system_themes_form_submit() - * @param $themes - * Array of theme names. - */ -function drush_theme_disable($themes) { - drupal_clear_css_cache(); - db_query("UPDATE {system} SET status = 0 WHERE type = 'theme' AND name IN (".db_placeholders($themes, 'text').")", $themes); - list_themes(TRUE); - menu_rebuild(); - drupal_rebuild_theme_registry(); - module_invoke('locale', 'system_update', $themes); -} - -/** - * Helper function to obtain the severity levels based on Drupal version. - * - * This is a copy of watchdog_severity_levels() without t(). - * - * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt. - * - * @return - * Array of watchdog severity levels. - */ -function drush_watchdog_severity_levels() { - return array( - WATCHDOG_EMERG => 'emergency', - WATCHDOG_ALERT => 'alert', - WATCHDOG_CRITICAL => 'critical', - WATCHDOG_ERROR => 'error', - WATCHDOG_WARNING => 'warning', - WATCHDOG_NOTICE => 'notice', - WATCHDOG_INFO => 'info', - WATCHDOG_DEBUG => 'debug', - ); -} - -/** - * Helper function to obtain the message types based on drupal version. - * - * @return - * Array of watchdog message types. - */ -function drush_watchdog_message_types() { - return drupal_map_assoc(_dblog_get_message_types()); -} - -function _drush_theme_default() { - return variable_get('theme_default', 'garland'); -} - -function _drush_theme_admin() { - return variable_get('admin_theme', drush_theme_get_default()); -} - -function _drush_file_public_path() { - if (function_exists('file_directory_path')) { - return file_directory_path(); - } -} - -function _drush_file_private_path() { - // @todo -} - -/** - * Gets the extension name. - * - * @param $info - * The extension info. - * @return string - * The extension name. - */ -function _drush_extension_get_name($info) { - return $info->name; -} - -/** - * Gets the extension type. - * - * @param $info - * The extension info. - * @return string - * The extension type. - */ -function _drush_extension_get_type($info) { - return $info->type; -} - -/** - * Gets the extension path. - * - * @param $info - * The extension info. - * @return string - * The extension path. - */ -function _drush_extension_get_path($info) { - return dirname($info->filename); -} - -/* - * Wrapper for CSRF token generation. - */ -function drush_get_token($value = NULL) { - return drupal_get_token($value); -} - -/* - * Wrapper for _url(). - */ -function drush_url($path = NULL, $options = array()) { - return url($path, $options); -} diff --git a/commands/core/drupal/site_install_6.inc b/commands/core/drupal/site_install_6.inc deleted file mode 100644 index 01958db6eb..0000000000 --- a/commands/core/drupal/site_install_6.inc +++ /dev/null @@ -1,140 +0,0 @@ -&1 - // redirect added to the command in drush_shell_exec(). We will actually take out - // all but fatal errors. See http://drupal.org/node/985716 for more information. - $phpcode = 'error_reporting(E_ERROR);' . _drush_site_install6_cookies($profile). ' include("'. $drupal_root .'/install.php");'; - drush_shell_exec('php -r %s', $phpcode); - $cli_output = drush_shell_exec_output(); - $cli_cookie = end($cli_output); - - // We need to bootstrap the database to be able to check the progress of the - // install batch process since we're not duplicating the install process using - // drush_batch functions, but calling the process directly. - drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_DATABASE); - - $status = _drush_site_install6_stage($profile, $cli_cookie, "start"); - if ($status === FALSE) { - return FALSE; - } - - $status = _drush_site_install6_stage($profile, $cli_cookie, "do_nojs"); - if ($status === FALSE) { - return FALSE; - } - - $status = _drush_site_install6_stage($profile, $cli_cookie, "finished"); - if ($status === FALSE) { - return FALSE; - } - - $account_pass = drush_get_option('account-pass', drush_generate_password()); - $account_name = drush_get_option('account-name', 'admin'); - $phpcode = _drush_site_install6_cookies($profile, $cli_cookie); - $post = array ( - "site_name" => drush_get_option('site-name', 'Site-Install'), - "site_mail" => drush_get_option('site-mail', 'admin@example.com'), - "account" => array ( - "name" => $account_name, - "mail" => drush_get_option('account-mail', 'admin@example.com'), - "pass" => array ( - "pass1" => $account_pass, - "pass2" => $account_pass, - ) - ), - "date_default_timezone" => "0", - "clean_url" => drush_get_option('clean-url', TRUE), - "form_id" => "install_configure_form", - "update_status_module" => array("1" => "1"), - ); - // Merge in the additional options. - foreach ($additional_form_options as $key => $value) { - $current = &$post; - foreach (explode('.', $key) as $param) { - $current = &$current[$param]; - } - $current = $value; - } - $phpcode .= ' - $_POST = ' . var_export($post, true) . '; - include("'. $drupal_root .'/install.php");'; - drush_shell_exec('php -r %s', $phpcode); - - drush_log(dt('Installation complete. User name: @name User password: @pass', array('@name' => $account_name, '@pass' => $account_pass)), LogLevel::OK); -} - -/** - * Submit a given op to install.php; if a meta "Refresh" tag - * is returned in the result, then submit that op as well. - */ -function _drush_site_install6_stage($profile, $cli_cookie, $initial_op) { - $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT'); - // Remember the install task at the start of the stage - $install_task = _drush_site_install6_install_task(); - $op = $initial_op; - while (!empty($op)) { - $phpcode = _drush_site_install6_cookies($profile, $cli_cookie). ' $_GET["op"]="' . $op . '"; include("'. $drupal_root .'/install.php");'; - drush_shell_exec('php -r %s', $phpcode); - $output = implode("\n", drush_shell_exec_output()); - // Check for a "Refresh" back to the do_nojs op; e.g.: - // - // If this pattern is NOT found, then go on to the "finished" step. - $matches = array(); - $match_result = preg_match('/http-equiv="Refresh".*op=([a-zA-Z0-9_]*)/', $output, $matches); - if ($match_result) { - $op = $matches[1]; - } - else { - $op = ''; - } - } - if (($install_task == _drush_site_install6_install_task()) && ($initial_op != "finished")) { - return drush_set_error('DRUSH_SITE_INSTALL_FAILED', dt("The site install task '!task' failed.", array('!task' => $install_task))); - } - return TRUE; -} - -/** - * Utility function to grab/set current "cli cookie". - */ -function _drush_site_install6_cookies($profile, $cookie = NULL) { - $drupal_base_url = parse_url(drush_get_context('DRUSH_SELECTED_URI')); - $output = '$_GET=array("profile"=>"' . $profile . '", "locale"=>"' . drush_get_option('locale', 'en') . '", "id"=>"1"); $_REQUEST=&$_GET;'; - $output .= 'define("DRUSH_SITE_INSTALL6", TRUE);$_SERVER["SERVER_SOFTWARE"] = NULL;'; - $output .= '$_SERVER["SCRIPT_NAME"] = "/install.php";'; - $output .= '$_SERVER["HTTP_HOST"] = "'.$drupal_base_url['host'].'";'; - $output .= '$_SERVER["REMOTE_ADDR"] = "127.0.0.1";'; - - if ($cookie) { - $output .= sprintf('$_COOKIE=unserialize("%s");', str_replace('"', '\"', $cookie)); - } - else { - $output .= 'function _cli_cookie_print(){print(serialize(array(session_name()=>session_id())));} register_shutdown_function("_cli_cookie_print");'; - } - - return $output; -} - -/** - * Utility function to check the install_task. We are - * not bootstrapped to a high enough level to use variable_get. - */ -function _drush_site_install6_install_task() { - if ($data = db_result(db_query("SELECT value FROM {variable} WHERE name = 'install_task'",1))) { - $result = unserialize($data); - } - return $result; -} diff --git a/commands/core/drupal/update_6.inc b/commands/core/drupal/update_6.inc deleted file mode 100644 index 2accffc9c8..0000000000 --- a/commands/core/drupal/update_6.inc +++ /dev/null @@ -1,522 +0,0 @@ - "''" - * in the $attributes array. If NOT NULL and DEFAULT are set the PostgreSQL - * version will set values of the added column in old rows to the - * DEFAULT value. - * - * @param $ret - * Array to which results will be added. - * @param $table - * Name of the table, without {} - * @param $column - * Name of the column - * @param $type - * Type of column - * @param $attributes - * Additional optional attributes. Recognized attributes: - * not null => TRUE|FALSE - * default => NULL|FALSE|value (the value must be enclosed in '' marks) - * @return - * nothing, but modifies $ret parameter. - */ -function db_add_column(&$ret, $table, $column, $type, $attributes = array()) { - if (array_key_exists('not null', $attributes) and $attributes['not null']) { - $not_null = 'NOT NULL'; - } - if (array_key_exists('default', $attributes)) { - if (!isset($attributes['default'])) { - $default_val = 'NULL'; - $default = 'default NULL'; - } - elseif ($attributes['default'] === FALSE) { - $default = ''; - } - else { - $default_val = "$attributes[default]"; - $default = "default $attributes[default]"; - } - } - - $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column $type"); - if (!empty($default)) { - $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET $default"); - } - if (!empty($not_null)) { - if (!empty($default)) { - $ret[] = update_sql("UPDATE {". $table ."} SET $column = $default_val"); - } - $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column SET NOT NULL"); - } -} - -/** - * Change a column definition using syntax appropriate for PostgreSQL. - * Save result of SQL commands in $ret array. - * - * Remember that changing a column definition involves adding a new column - * and dropping an old one. This means that any indices, primary keys and - * sequences from serial-type columns are dropped and might need to be - * recreated. - * - * @param $ret - * Array to which results will be added. - * @param $table - * Name of the table, without {} - * @param $column - * Name of the column to change - * @param $column_new - * New name for the column (set to the same as $column if you don't want to change the name) - * @param $type - * Type of column - * @param $attributes - * Additional optional attributes. Recognized attributes: - * not null => TRUE|FALSE - * default => NULL|FALSE|value (with or without '', it won't be added) - * @return - * nothing, but modifies $ret parameter. - */ -function db_change_column(&$ret, $table, $column, $column_new, $type, $attributes = array()) { - if (array_key_exists('not null', $attributes) and $attributes['not null']) { - $not_null = 'NOT NULL'; - } - if (array_key_exists('default', $attributes)) { - if (!isset($attributes['default'])) { - $default_val = 'NULL'; - $default = 'default NULL'; - } - elseif ($attributes['default'] === FALSE) { - $default = ''; - } - else { - $default_val = "$attributes[default]"; - $default = "default $attributes[default]"; - } - } - - $ret[] = update_sql("ALTER TABLE {". $table ."} RENAME $column TO ". $column ."_old"); - $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column_new $type"); - $ret[] = update_sql("UPDATE {". $table ."} SET $column_new = ". $column ."_old"); - if ($default) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET $default"); } - if ($not_null) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET NOT NULL"); } - $ret[] = update_sql("ALTER TABLE {". $table ."} DROP ". $column ."_old"); -} - - -/** - * Disable anything in the {system} table that is not compatible with the - * current version of Drupal core. - */ -function update_fix_compatibility() { - $ret = array(); - $incompatible = array(); - $query = db_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')"); - while ($result = db_fetch_object($query)) { - if (update_check_incompatibility($result->name, $result->type)) { - $incompatible[] = $result->name; - drush_log(dt("!type !name is incompatible with this release of Drupal, and will be disabled.", - array("!type" => $result->type, '!name' => $result->name)), LogLevel::WARNING); - } - } - if (!empty($incompatible)) { - - $ret[] = update_sql("UPDATE {system} SET status = 0 WHERE name IN ('". implode("','", $incompatible) ."')"); - } - return $ret; -} - -/** - * Helper function to test compatibility of a module or theme. - */ -function update_check_incompatibility($name, $type = 'module') { - static $themes, $modules; - - // Store values of expensive functions for future use. - if (empty($themes) || empty($modules)) { - drush_include_engine('drupal', 'environment'); - $themes = _system_theme_data(); - $modules = module_rebuild_cache(); - } - - if ($type == 'module' && isset($modules[$name])) { - $file = $modules[$name]; - } - else if ($type == 'theme' && isset($themes[$name])) { - $file = $themes[$name]; - } - if (!isset($file) - || !isset($file->info['core']) - || $file->info['core'] != drush_get_drupal_core_compatibility() - || version_compare(phpversion(), $file->info['php']) < 0) { - return TRUE; - } - return FALSE; -} - -/** - * Perform Drupal 5.x to 6.x updates that are required for update.php - * to function properly. - * - * This function runs when update.php is run the first time for 6.x, - * even before updates are selected or performed. It is important - * that if updates are not ultimately performed that no changes are - * made which make it impossible to continue using the prior version. - * Just adding columns is safe. However, renaming the - * system.description column to owner is not. Therefore, we add the - * system.owner column and leave it to system_update_6008() to copy - * the data from description and remove description. The same for - * renaming locales_target.locale to locales_target.language, which - * will be finished by locale_update_6002(). - */ -function update_fix_d6_requirements() { - $ret = array(); - - if (drupal_get_installed_schema_version('system') < 6000 && !variable_get('update_d6_requirements', FALSE)) { - $spec = array('type' => 'int', 'size' => 'small', 'default' => 0, 'not null' => TRUE); - db_add_field($ret, 'cache', 'serialized', $spec); - db_add_field($ret, 'cache_filter', 'serialized', $spec); - db_add_field($ret, 'cache_page', 'serialized', $spec); - db_add_field($ret, 'cache_menu', 'serialized', $spec); - - db_add_field($ret, 'system', 'info', array('type' => 'text')); - db_add_field($ret, 'system', 'owner', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); - if (db_table_exists('locales_target')) { - db_add_field($ret, 'locales_target', 'language', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '')); - } - if (db_table_exists('locales_source')) { - db_add_field($ret, 'locales_source', 'textgroup', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'default')); - db_add_field($ret, 'locales_source', 'version', array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'none')); - } - variable_set('update_d6_requirements', TRUE); - - // Create the cache_block table. See system_update_6027() for more details. - $schema['cache_block'] = array( - 'fields' => array( - 'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), - 'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'), - 'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - 'headers' => array('type' => 'text', 'not null' => FALSE), - 'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0) - ), - 'indexes' => array('expire' => array('expire')), - 'primary key' => array('cid'), - ); - db_create_table($ret, 'cache_block', $schema['cache_block']); - - // Create the semaphore table now -- the menu system after 6.15 depends on - // this table, and menu code runs in updates prior to the table being - // created in its original update function, system_update_6054(). - $schema['semaphore'] = array( - 'fields' => array( - 'name' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => ''), - 'value' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => ''), - 'expire' => array( - 'type' => 'float', - 'size' => 'big', - 'not null' => TRUE), - ), - 'indexes' => array('expire' => array('expire')), - 'primary key' => array('name'), - ); - db_create_table($ret, 'semaphore', $schema['semaphore']); - } - - return $ret; -} - -/** - * Check update requirements and report any errors. - */ -function update_check_requirements() { - // Check the system module requirements only. - $requirements = module_invoke('system', 'requirements', 'update'); - $severity = drupal_requirements_severity($requirements); - - // If there are issues, report them. - if ($severity != REQUIREMENT_OK) { - foreach ($requirements as $requirement) { - if (isset($requirement['severity']) && $requirement['severity'] != REQUIREMENT_OK) { - $message = isset($requirement['description']) ? $requirement['description'] : ''; - if (isset($requirement['value']) && $requirement['value']) { - $message .= ' (Currently using '. $requirement['title'] .' '. $requirement['value'] .')'; - } - drush_log($message, LogLevel::WARNING); - } - } - } -} - -/** - * Create the batch table. - * - * This is part of the Drupal 5.x to 6.x migration. - */ -function update_create_batch_table() { - - // If batch table exists, update is not necessary - if (db_table_exists('batch')) { - return; - } - - $schema['batch'] = array( - 'fields' => array( - 'bid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), - 'token' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE), - 'timestamp' => array('type' => 'int', 'not null' => TRUE), - 'batch' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big') - ), - 'primary key' => array('bid'), - 'indexes' => array('token' => array('token')), - ); - - $ret = array(); - db_create_table($ret, 'batch', $schema['batch']); - return $ret; -} - -function update_main_prepare() { - global $profile; - // Some unavoidable errors happen because the database is not yet up-to-date. - // Our custom error handler is not yet installed, so we just suppress them. - drush_errors_off(); - - require_once './includes/bootstrap.inc'; - // Minimum load of components. - // This differs from the Drupal 6 update.php workflow for compatbility with - // the Drupal 6 backport of module_implements() caching. - // @see http://drupal.org/node/557542 - drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_DATABASE); - require_once './includes/install.inc'; - require_once './includes/file.inc'; - require_once './modules/system/system.install'; - - // Load module basics. - include_once './includes/module.inc'; - $module_list['system']['filename'] = 'modules/system/system.module'; - $module_list['filter']['filename'] = 'modules/filter/filter.module'; - module_list(TRUE, FALSE, FALSE, $module_list); - module_implements('', FALSE, TRUE); - - drupal_load('module', 'system'); - drupal_load('module', 'filter'); - - // Set up $language, since the installer components require it. - drupal_init_language(); - - // Set up theme system for the maintenance page. - drupal_maintenance_theme(); - - // Check the update requirements for Drupal. - update_check_requirements(); - - drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL); - $profile = variable_get('install_profile', 'default'); - // Updates only run reliably if user ID #1 is logged in. For example, node_delete() requires elevated perms in D5/6. - if (!drush_get_context('DRUSH_USER')) { - drush_set_option('user', 1); - drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_LOGIN); - } - - // This must happen *after* drupal_bootstrap(), since it calls - // variable_(get|set), which only works after a full bootstrap. - _drush_log_update_sql(update_create_batch_table()); - - // Turn error reporting back on. From now on, only fatal errors (which are - // not passed through the error handler) will cause a message to be printed. - drush_errors_on(); - - // Perform Drupal 5.x to 6.x updates that are required for update.php to function properly. - _drush_log_update_sql(update_fix_d6_requirements()); - - // Must unset $theme->status in order to safely rescan and repopulate - // the system table to ensure we have a full picture of the platform. - // This is needed because $theme->status is set to 0 in a call to - // list_themes() done by drupal_maintenance_theme(). - // It is a issue with _system_theme_data() that returns its own cache - // variable and can be modififed by others. When this is fixed in - // drupal core we can remove this unset. - // For reference see: http://drupal.org/node/762754 - $themes = _system_theme_data(); - foreach ($themes as $theme) { - unset($theme->status); - } - drush_get_extensions(); - - include_once './includes/batch.inc'; - drupal_load_updates(); - - // Disable anything in the {system} table that is not compatible with the current version of Drupal core. - _drush_log_update_sql(update_fix_compatibility()); -} - -function update_main() { - update_main_prepare(); - - list($pending, $start) = updatedb_status(); - - // Print a list of pending updates for this module and get confirmation. - if ($pending) { - // @todo get table header working - // array_unshift($pending, array(dt('Module'), dt('ID'), dt('Description'))); - drush_print_table($pending, FALSE); - if (!drush_confirm(dt('Do you wish to run all pending updates?'))) { - return drush_user_abort(); - } - // Proceed with running all pending updates. - $operations = array(); - foreach ($start as $module => $version) { - drupal_set_installed_schema_version($module, $version - 1); - $updates = drupal_get_schema_versions($module); - $max_version = max($updates); - if ($version <= $max_version) { - drush_log(dt('Updating module @module from schema version @start to schema version @max', array('@module' => $module, '@start' => $version - 1, '@max' => $max_version))); - foreach ($updates as $update) { - if ($update >= $version) { - $operations[] = array('_update_do_one', array($module, $update)); - } - } - } - else { - drush_log(dt('No database updates for module @module', array('@module' => $module)), LogLevel::SUCCESS); - } - } - $batch = array( - 'operations' => $operations, - 'title' => 'Updating', - 'init_message' => 'Starting updates', - 'error_message' => 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.', - 'finished' => 'update_finished', - ); - batch_set($batch); - $batch =& batch_get(); - $batch['progressive'] = FALSE; - drush_backend_batch_process('updatedb-batch-process'); - } - else { - drush_log(dt("No database updates required"), LogLevel::SUCCESS); - } - - return count($pending); -} - -/** - * A simplified version of the batch_do_one function from update.php - * - * This does not mess with sessions and the like, as it will be used - * from the command line - */ -function _update_do_one($module, $number, &$context) { - // If updates for this module have been aborted - // in a previous step, go no further. - if (!empty($context['results'][$module]['#abort'])) { - return; - } - - $function = $module .'_update_'. $number; - drush_log("Executing $function", LogLevel::SUCCESS); - - if (function_exists($function)) { - $ret = $function($context['sandbox']); - $context['results'][$module] = $ret; - _drush_log_update_sql($ret); - } - - if (isset($ret['#finished'])) { - $context['finished'] = $ret['#finished']; - unset($ret['#finished']); - } - - if ($context['finished'] == 1 && empty($context['results'][$module]['#abort'])) { - drupal_set_installed_schema_version($module, $number); - } - -} - -function _update_batch_command($id) { - update_main_prepare(); - drush_batch_command($id); -} - -/** - * Return a 2 item array with - * - an array where each item is a 3 item associative array describing a pending update. - * - an array listing the first update to run, keyed by module. - */ -function updatedb_status() { - $return = array(); - - $modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE); - foreach ($modules as $module => $schema_version) { - $updates = drupal_get_schema_versions($module); - // Skip incompatible module updates completely, otherwise test schema versions. - if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) { - // module_invoke returns NULL for nonexisting hooks, so if no updates - // are removed, it will == 0. - $last_removed = module_invoke($module, 'update_last_removed'); - if ($schema_version < $last_removed) { - drush_set_error('PROVISION_DRUPAL_UPDATE_FAILED', dt( $module .' module can not be updated. Its schema version is '. $schema_version .'. Updates up to and including '. $last_removed .' have been removed in this release. In order to update '. $module .' module, you will first need to upgrade to the last version in which these updates were available.')); - continue; - } - - $updates = drupal_map_assoc($updates); - - // Record the starting update number for each module. - foreach (array_keys($updates) as $update) { - if ($update > $schema_version) { - $start[$module] = $update; - break; - } - } - if (isset($start['system'])) { - // Ensure system module's updates run first. - $start = array('system' => $start['system']) + $start; - } - - // Record any pending updates. Used for confirmation prompt. - foreach (array_keys($updates) as $update) { - if ($update > $schema_version) { - if (class_exists('ReflectionFunction')) { - // The description for an update comes from its Doxygen. - $func = new ReflectionFunction($module. '_update_'. $update); - $description = trim(str_replace(array("\n", '*', '/'), '', $func->getDocComment())); - } - if (empty($description)) { - $description = dt('description not available'); - } - - $return[] = array('module' => ucfirst($module), 'update_id' => $update, 'description' => $description); - } - } - } - } - - return array($return, $start); -} diff --git a/commands/core/locale.d8.drush.inc b/commands/core/locale.d8.drush.inc index ab639e264d..7f4b08959e 100644 --- a/commands/core/locale.d8.drush.inc +++ b/commands/core/locale.d8.drush.inc @@ -23,10 +23,12 @@ function locale_drush_help($section) { function locale_drush_command() { $items['locale-check'] = [ 'description' => 'Checks for available translation updates.', + 'drupal dependencies' => ['locale'], 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, ]; $items['locale-update'] = [ 'description' => 'Updates the available translations.', + 'drupal dependencies' => ['locale'], 'options' => [ 'langcodes' => 'A comma-separated list of language codes to update. If omitted, all translations will be updated.' ], @@ -78,7 +80,7 @@ function drush_locale_update() { $langcodes = []; foreach (locale_translation_get_status() as $project_id => $project) { foreach ($project as $langcode => $project_info) { - if (!empty($project_info->type)) { + if (!empty($project_info->type) && !in_array($langcode, $langcodes)) { $langcodes[] = $langcode; } } diff --git a/commands/core/role.drush.inc b/commands/core/role.drush.inc index fb4f9e9d16..a7436ae936 100644 --- a/commands/core/role.drush.inc +++ b/commands/core/role.drush.inc @@ -36,12 +36,12 @@ function role_drush_command() { $items['role-create'] = array( 'description' => 'Create a new role.', 'examples' => array( - "drush role-create 'test role'" => "Create a new role 'test role' on D6 or D7; auto-assign the rid. On D8, 'test role' is the rid, and the human-readable name is set to 'Test role'.", - "drush role-create 'test role' 'Test role'" => "Create a new role with a machine name of 'test role', and a human-readable name of 'Test role'. On D6 and D7, behaves as the previous example." + "drush role-create 'test role'" => "Create a new role 'test role' on D7; auto-assign the rid. On D8, 'test role' is the rid, and the human-readable name is set to 'Test role'.", + "drush role-create 'test role' 'Test role'" => "Create a new role with a machine name of 'test role', and a human-readable name of 'Test role'. On D7, behaves as the previous example." ), 'arguments' => array( 'machine name' => 'The symbolic machine name for the role. Required.', - 'human-readable name' => 'A descriptive name for the role. Optional; Drupal 8 only. Ignored in D6 and D7.', + 'human-readable name' => 'A descriptive name for the role. Optional; Drupal 8 only. Ignored in D7.', ), 'aliases' => array('rcrt'), ); @@ -51,7 +51,7 @@ function role_drush_command() { "drush role-delete 'test role'" => "Delete the role 'test role'.", ), 'arguments' => array( - 'machine name' => 'The symbolic machine name for the role. Required. In D6 and D7, this may also be a numeric role ID.', + 'machine name' => 'The symbolic machine name for the role. Required. In D7, this may also be a numeric role ID.', ), 'aliases' => array('rdel'), ); diff --git a/commands/core/rsync.core.inc b/commands/core/rsync.core.inc index b595820f75..6e6b00f6a8 100644 --- a/commands/core/rsync.core.inc +++ b/commands/core/rsync.core.inc @@ -267,12 +267,20 @@ function _drush_core_rsync_both_remote($source, $destination, $additional_option // in the destination (i.e. there is no 'tmpdir' in the destination). // // All three of these cases need to be handled correctly in order - // to ensure the correct results. In all cases, though, the first - // rsync always copies to $tmpDir, and the second rsync always - // copies from $tmpDir/basename($source_path). So, the actual logic - // comes out to be much simpler than the analysis. + // to ensure the correct results. In all cases the first + // rsync always copies to $tmpDir, however the second rsync has + // two cases that depend on the source path. If the source path ends + // in /, the contents of a directory have been copied to $tmpDir, and + // the contents of $tmpDir must be copied to the destination. Otherwise, + // a specific file or directory has been copied to $tmpDir and that + // specific item, identified by basename($source_path) must be copied to + // the destination. + $putInTmpPath = drush_tempdir(); - $getFromTmpPath = "$putInTmpPath/" . basename($source_path); + $getFromTmpPath = "$putInTmpPath/"; + if (substr($source_path, -1) !== '/') { + $getFromTmpPath .= basename($source_path); + } // Copy from the source to the temporary location. Exit on failure. $values = drush_invoke_process('@self', 'core-rsync', array($source, $putInTmpPath), $options); diff --git a/commands/core/site_install.drush.inc b/commands/core/site_install.drush.inc index a57213482c..24f39ca117 100644 --- a/commands/core/site_install.drush.inc +++ b/commands/core/site_install.drush.inc @@ -24,7 +24,7 @@ function site_install_drush_command() { // block in the profile's info YAML file. // See https://www.drupal.org/node/2210443 for more information. 'profile' => 'The install profile you wish to run. Defaults to \'default\' in D6, \'standard\' in D7+, unless an install profile is marked as exclusive (or as a distribution in D8+ terminology) in which case that is used.', - '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.', + 'key=value...' => 'Any additional settings you wish to pass to the profile. The key is in the form [form name].[parameter name].', ), 'options' => array( 'db-url' => array( @@ -199,15 +199,11 @@ function drush_core_pre_site_install($profile = NULL) { // We need to be at least at DRUSH_BOOTSTRAP_DRUPAL_SITE to select the site uri to install to define('MAINTENANCE_MODE', 'install'); - if (drush_drupal_major_version() == 6) { - // The Drupal 6 installer needs to bootstrap up to the specified site. - drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION); - } - else { - drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE); - } + drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_SITE); - $sql->drop_or_create($db_spec); + if (!$sql->drop_or_create($db_spec)) { + return drush_set_error(dt('Failed to create database: @error', array('@error' => implode(drush_shell_exec_output())))); + } return TRUE; } diff --git a/commands/core/views.d8.drush.inc b/commands/core/views.d8.drush.inc index 7641fadf58..d4f53dd022 100644 --- a/commands/core/views.d8.drush.inc +++ b/commands/core/views.d8.drush.inc @@ -194,7 +194,7 @@ function drush_views_list() { $format = drush_get_option('format', FALSE); - $views = Drupal::entityManager()->getStorage('view')->loadMultiple(); + $views = \Drupal::entityManager()->getStorage('view')->loadMultiple(); // Get the --name option. $name = array_filter(drush_get_option_list('name')); @@ -313,10 +313,10 @@ function drush_views_analyze() { $format = drush_get_option('format', FALSE); - $views = Drupal::entityManager()->getStorage('view')->loadMultiple(); + $views = \Drupal::entityManager()->getStorage('view')->loadMultiple(); if (!empty($views)) { - $analyzer = Drupal::service('views.analyzer'); + $analyzer = \Drupal::service('views.analyzer'); foreach ($views as $view_name => $view) { $view = $view->getExecutable(); @@ -374,9 +374,9 @@ function _views_drush_op($op = '', array $view_names = array()) { return drush_set_error(dt('Invalid op type')); } - $view_names = MapArray::copyValuesToKeys($view_names); + $view_names = array_combine($view_names, $view_names); - if ($views = Drupal::entityManager()->getStorageController('view')->loadMultiple($view_names)) { + if ($views = \Drupal::entityManager()->getStorage('view')->loadMultiple($view_names)) { foreach ($views as $view) { $tokens = array('@view' => $view->id(), '@action' => $op_types[$op]['action']); @@ -483,5 +483,5 @@ function views_views_disable_complete() { */ function _drush_views_complete() { drush_bootstrap_max(); - return array('values' => array_keys(Drupal::entityManager()->getStorageController('view')->loadMultiple())); + return array('values' => array_keys(\Drupal::entityManager()->getStorage('view')->loadMultiple())); } diff --git a/commands/make/generate.contents.make.inc b/commands/make/generate.contents.make.inc index 7785739879..a7a17e0541 100644 --- a/commands/make/generate.contents.make.inc +++ b/commands/make/generate.contents.make.inc @@ -135,10 +135,16 @@ function make_generate_from_makefile($file, $makefile) { if (!(isset($project['download']['type'])) || ($project['download']['type'] == 'pm')) { unset($projects[$name]['download']); // PM is the default } - $ignore = array('build_path', 'contrib_destination', 'core', 'location', 'make_directory', 'l10n_url', 'download_type'); + $ignore = array('build_path', 'contrib_destination', 'core', 'make_directory', 'l10n_url', 'download_type'); foreach ($ignore as $key) { unset($projects[$name][$key]); } + + // Remove the location if it's the default. + if ($projects[$name]['location'] == 'https://updates.drupal.org/release-history') { + unset($projects[$name]['location']); + } + // Remove empty entries (e.g. 'directory_name') $projects[$name] = _make_generate_array_filter($projects[$name]); } diff --git a/commands/runserver/runserver-prepend.php b/commands/runserver/runserver-prepend.php index 5bf753292d..48802ee232 100644 --- a/commands/runserver/runserver-prepend.php +++ b/commands/runserver/runserver-prepend.php @@ -35,7 +35,7 @@ function filter_init() { if (!function_exists('system_watchdog')) { // Check function_exists as a safety net in case it is added in future. function system_watchdog($log_entry = array()) { - // Drupal <= 7.x defines VERSION. Drupal 8 defines Drupal::VERSION instead. + // Drupal <= 7.x defines VERSION. Drupal 8 defines \Drupal::VERSION instead. if (defined('VERSION')) { $uid = $log_entry['user']->uid; } diff --git a/commands/sql/sql.drush.inc b/commands/sql/sql.drush.inc index 9ad109177c..0f6c386ddf 100644 --- a/commands/sql/sql.drush.inc +++ b/commands/sql/sql.drush.inc @@ -103,18 +103,12 @@ function sql_drush_command() { 'drush sql-dump --skip-tables-key=common' => 'Skip standard tables. @see example.drushrc.php', 'drush sql-dump --extra=--no-data' => 'Pass extra option to dump command.', ), - 'options' => array( + 'options' => drush_sql_get_table_selection_options() + array( 'result-file' => array( 'description' => 'Save to a file. The file should be relative to Drupal root. If --result-file is provided with no value, then date based filename will be created under ~/drush-backups directory.', 'example-value' => '/path/to/file', 'value' => 'optional', ), - 'skip-tables-key' => 'A key in the $skip_tables array. @see example.drushrc.php. Optional.', - 'structure-tables-key' => 'A key in the $structure_tables array. @see example.drushrc.php. Optional.', - 'tables-key' => 'A key in the $tables array. Optional.', - 'skip-tables-list' => 'A comma-separated list of tables to exclude completely. Optional.', - 'structure-tables-list' => 'A comma-separated list of tables to include for structure, but not data. Optional.', - 'tables-list' => 'A comma-separated list of tables to transfer. Optional.', 'create-db' => array('hidden' => TRUE, 'description' => 'Omit DROP TABLE statements. Postgres and Oracle only. Used by sql-sync, since including the DROP TABLE statements interfere with the import when the database is created.'), 'data-only' => 'Dump data without statements to create any of the schema.', 'ordered-dump' => 'Order by primary key and add line breaks for efficient diff in revision control. Slows down the dump. Mysql only.', @@ -255,7 +249,7 @@ function drush_sql_create() { } } - return $sql->createdb(); + return $sql->createdb(TRUE); } @@ -292,6 +286,17 @@ function drush_sql_get_table_selection() { return array('skip' => $skip_tables, 'structure' => $structure_tables, 'tables' => $tables); } +function drush_sql_get_table_selection_options() { + return array( + 'skip-tables-key' => 'A key in the $skip_tables array. @see example.drushrc.php. Optional.', + 'structure-tables-key' => 'A key in the $structure_tables array. @see example.drushrc.php. Optional.', + 'tables-key' => 'A key in the $tables array. Optional.', + 'skip-tables-list' => 'A comma-separated list of tables to exclude completely. Optional.', + 'structure-tables-list' => 'A comma-separated list of tables to include for structure, but not data. Optional.', + 'tables-list' => 'A comma-separated list of tables to transfer. Optional.', + ); +} + /** * Expand wildcard tables. * @@ -452,7 +457,7 @@ function drush_sql_cli() { } /** - * Command callback. Run's the sanitization operations on the current database. + * Command callback. Runs the sanitization operations on the current database. * * @see hook_drush_sql_sync_sanitize() for adding custom sanitize routines. */ @@ -463,8 +468,8 @@ function drush_sql_sanitize() { } drush_command_invoke_all('drush_sql_sync_sanitize', 'default'); - $options = drush_get_context('post-sync-ops'); - if (!empty($options)) { + $operations = drush_get_context('post-sync-ops'); + if (!empty($operations)) { if (!drush_get_context('DRUSH_SIMULATE')) { $messages = _drush_sql_get_post_sync_messages(); if ($messages) { @@ -472,27 +477,20 @@ function drush_sql_sanitize() { drush_print($messages); } } + $queries = array_column($operations, 'query'); + $sanitize_query = implode(" ", $queries); } if (!drush_confirm(dt('Do you really want to sanitize the current database?'))) { return drush_user_abort(); } - $sanitize_query = ''; - foreach($options as $id => $data) { - // Enable prefix processing when db-prefix option is used. - if (drush_get_option('db-prefix')) { - if (drush_drupal_major_version() >= 7) { - $data['query'] = Database::getConnection()->prefixTables($data['query']); - } - else { - $data['query'] = db_prefix_tables($data['query']); - } - } - $sanitize_query .= $data['query'] . " "; - } if ($sanitize_query) { $sql = drush_sql_get_class(); - return $sql->query($sanitize_query); + $sanitize_query = $sql->query_prefix($sanitize_query); + $result = $sql->query($sanitize_query); + if (!$result) { + return drush_set_error('DRUSH_SQL_NO_QUERY', dt('Sanitize query failed.')); + } } } @@ -536,17 +534,14 @@ function drush_sql_register_post_sync_op($id, $message, $query = NULL) { * All post-sync operation messages concatenated together. */ function _drush_sql_get_post_sync_messages() { - $messages = FALSE; - - $options = drush_get_context('post-sync-ops'); - if (!empty($options)) { + $messages = ''; + $operations = drush_get_context('post-sync-ops'); + if (!empty($operations)) { $messages = dt('The following operations will be done on the target database:') . "\n"; - foreach($options as $id => $data) { - $messages .= " * " . $data['message'] . "\n"; - } + $bullets = array_column($operations, 'message'); + $messages .= " * " . implode("\n * ", $bullets) . "\n"; } - return $messages; } @@ -604,14 +599,14 @@ function drush_sql_get_version() { } /** - * Implements hook_sql_drush_sql_sync_sanitize. + * Implements hook_drush_sql_sync_sanitize(). * * Sanitize usernames, passwords, and sessions when the --sanitize option is used. * It is also an example of how to write a database sanitizer for sql sync. * * To write your own sync hook function, define mymodule_drush_sql_sync_sanitize() - * and follow the form of this function to add your own database - * sanitization operations via the register post-sync op function; + * in mymodule.drush.inc and follow the form of this function to add your own + * database sanitization operations via the register post-sync op function; * @see drush_sql_register_post_sync_op(). This is the only thing that the * sync hook function needs to do; sql-sync takes care of the rest. * @@ -624,12 +619,7 @@ function drush_sql_get_version() { function sql_drush_sql_sync_sanitize($site) { $site_settings = drush_sitealias_get_record($site); $databases = sitealias_get_databases_from_record($site_settings); - if (drush_get_option('db-prefix') || !empty($databases['default']['default']['prefix'])) { - $wrap_table_name = TRUE; - } - else { - $wrap_table_name = FALSE; - } + $wrap_table_name = (bool) drush_get_option('db-prefix'); $user_table_updates = array(); $message_list = array(); diff --git a/commands/sql/sqlsync.drush.inc b/commands/sql/sqlsync.drush.inc index b1e52031b5..903fe3bb39 100644 --- a/commands/sql/sqlsync.drush.inc +++ b/commands/sql/sqlsync.drush.inc @@ -20,13 +20,7 @@ function sqlsync_drush_command() { 'target' => 'A site-alias or the name of a subdirectory within /sites whose database you want to replace.', ), 'required-arguments' => TRUE, - 'options' => array( - 'skip-tables-key' => 'A key in the $skip_tables array. See example.drushrc.php. Optional.', - 'skip-tables-list' => 'A comma-separated list of tables to exclude completely. Optional.', - 'structure-tables-key' => 'A key in the $structure_tables array. See example.drushrc.php. Optional.', - 'structure-tables-list' => 'A comma-separated list of tables to include for structure, but not data. Optional.', - 'tables-key' => 'A key in the $tables array. Optional.', - 'tables-list' => 'A comma-separated list of tables to transfer. Optional.', + 'options' => drush_sql_get_table_selection_options() + array( // 'cache' => 'Skip dump if result file exists and is less than "cache" hours old. Optional; default is 24 hours.', // 'no-cache' => 'Do not cache the sql-dump file.', 'no-dump' => 'Do not dump the sql database; always use an existing dump file.', diff --git a/composer.json b/composer.json index 7cb44ec540..c867bcf9e0 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ "psr-0": { "Drush": "lib/" }, - "files": [ + "classmap": [ "lib/Drush.php" ] }, diff --git a/docs/install-alternative.md b/docs/install-alternative.md index 0fb3d0b9be..2d4ef6b2dd 100644 --- a/docs/install-alternative.md +++ b/docs/install-alternative.md @@ -1,9 +1,9 @@ Install a global Drush via Composer ------------------ -Follow the instructions below, or [watch a video by Drupalize.me](https://youtu.be/eAtDaD8xz0Q). +To install Drush globally for a single user follow the instructions below, or [watch a video by Drupalize.me](https://youtu.be/eAtDaD8xz0Q). -1. [Install Composer globally](https://getcomposer.org/doc/00-intro.md#globally). -1. Add composer's `bin` directory to the system path by placing `export PATH="$HOME/.composer/vendor/bin:$PATH"` into your ~/.bash_profile (Mac OS users) or into your ~/.bashrc (Linux users). +1. [Install Composer globally][]. +1. Add composer's `bin` directory to the system path by placing `export PATH="$HOME/.composer/vendor/bin:$PATH"` into your ~/.bash_profile (Mac OS users) or into your ~/.bashrc (Linux users). 1. Install latest stable Drush: `composer global require drush/drush`. 1. Verify that Drush works: `drush status` @@ -17,19 +17,65 @@ Follow the instructions below, or [watch a video by Drupalize.me](https://youtu. # Install master branch as a git clone. Great for contributing back to Drush project. composer global require drush/drush:dev-master --prefer-source -* Alternate way to install for all users via Composer: +* [Documentation for composer's require command](http://getcomposer.org/doc/03-cli.md#require). +* Uninstall with : `composer global remove drush/drush` - COMPOSER_HOME=/opt/drush COMPOSER_BIN_DIR=/usr/local/bin COMPOSER_VENDOR_DIR=/opt/drush/7 composer require drush/drush:7 +Install Drush for all users via Composer +------------ +If you need Drush installed for all users on a system using Composer, [install Composer globally][] then follow the steps below. -* [Documentation for composer's require command.](http://getcomposer.org/doc/03-cli.md#require) -* Uninstall with : `composer global remove drush/drush` +**Important:** Run these shell commands as a privelged user with write access to `/opt` and `/usr/local/bin` or prefix with `sudo`. + +```sh +# Create and/or navigate to a path for the single Composer Drush install. +mkdir --parents /opt/drush-8.x +cd /opt/drush-8.x +# Initialise a new Composer project that requires Drush. +composer init --require=drush/drush:8.* -n +# Configure the path Composer should use for the Drush vendor binaries. +composer config bin-dir /usr/local/bin +# Install Drush. +composer install +``` + +### Getting Updates + +Use composer to update Drush just as you would with any other composer managed project. The [vendor binaries][] will be updated for all users. + +```sh +# Navigate to the Drush install path. +cd /opt/drush-8.x +# Run composer update +composer update +``` + +### Major Version Upgrade + +If upgrading to a new major version the steps are the same, with one addition: + +```sh +# Remove the existing symlinks to Drush vendor binaries. +find /usr/local/bin -lname '/opt/drush*' -exec unlink \{\} \; +# Follow the steps shown above, starting with creation of a new path. +mkdir --parents /opt/drush-9.x +cd /opt/drush-9.x +``` + +**Important:** At the time of writing composer will warn you if it cannot create [vendor binaries][] due to a name conflict with an existing file. + +[Install Composer globally]: https://getcomposer.org/doc/00-intro.md#globally +[vendor binaries]: https://getcomposer.org/doc/articles/vendor-binaries.md Windows ------------ Drush on Windows is not recommended, since Drush's test suite is not running there ([help wanted](https://github.com/drush-ops/drush/issues/1612)). -* [Acquia Dev Desktop](https://www.acquia.com/downloads) is excellent, and includes Drush. See the terminal icon after setting up a web site. -* Or consider running Linux/OSX via Virtualbox. [Drupal VM](http://www.drupalvm.com/) and [Vlad](https://github.com/hashbangcode/vlad) are popular.* These Windows packages include Drush and its dependencies (including MSys). * [7.0.0 (stable)](https://github.com/drush-ops/drush/releases/download/7.0.0/windows-7.0.0.zip). * [6.6.0](https://github.com/drush-ops/drush/releases/download/6.6.0/windows-6.6.0.zip). * [6.0](https://github.com/drush-ops/drush/releases/download/6.0.0/Drush-6.0-2013-08-28-Installer-v1.0.21.msi). -* Or install LAMP on your own, and run Drush via [Git's shell](https://git-for-windows.github.io/), in order to insure that [all depedencies](https://github.com/acquia/DevDesktopCommon/tree/master/bintools-win/msys/bin) are available. -* Whenever the documentation or the help text refers to `drush [option] ` or something similar, 'drush' may need to be replaced by 'drush.bat'. -* When creating site aliases for Windows remote machines, pay particular attention to information presented in the example.aliases.drushrc.php file, especially when setting values for 'remote-host' and 'os', as these are very important when running Drush rsync and Drush sql-sync commands. +- [Acquia Dev Desktop](https://www.acquia.com/downloads) is excellent, and includes Drush. See the terminal icon after setting up a web site. +- Or consider running Linux/OSX via Virtualbox. [Drupal VM](http://www.drupalvm.com/) and [Vlad](https://github.com/hashbangcode/vlad) are popular. +- These Windows packages include Drush and its dependencies (including MSys). + - [7.0.0 (stable)](https://github.com/drush-ops/drush/releases/download/7.0.0/windows-7.0.0.zip). + - [6.6.0](https://github.com/drush-ops/drush/releases/download/6.6.0/windows-6.6.0.zip). + - [6.0](https://github.com/drush-ops/drush/releases/download/6.0.0/Drush-6.0-2013-08-28-Installer-v1.0.21.msi). +- Or install LAMP on your own, and run Drush via [Git's shell](https://git-for-windows.github.io/), in order to insure that [all depedencies](https://github.com/acquia/DevDesktopCommon/tree/master/bintools-win/msys/bin) are available. +- Whenever the documentation or the help text refers to `drush [option] ` or something similar, `drush` may need to be replaced by `drush.bat`. +- When creating site aliases for Windows remote machines, pay particular attention to information presented in the `example.aliases.drushrc.php` file, especially when setting values for `'remote-host'` and `'os'`, as these are very important when running `drush rsync` and `drush sql-sync` commands. diff --git a/docs/install.md b/docs/install.md index 072e3f2916..493bf5064d 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,21 +1,21 @@ Install/Upgrade a global Drush --------------- -```bash +```sh # Download latest stable release using the code below or browse to github.com/drush-ops/drush/releases. -wget http://files.drush.org/drush.phar -# Or use our upcoming release: wget http://files.drush.org/drush-unstable.phar +php -r "readfile('http://files.drush.org/drush.phar');" > drush +# Or use our upcoming release: php -r "readfile('http://files.drush.org/drush-unstable.phar');" > drush # Test your install. -php drush.phar core-status +php drush core-status -# Rename to `drush` instead of `php drush.phar`. Destination can be anywhere on $PATH. -chmod +x drush.phar -sudo mv drush.phar /usr/local/bin/drush +# Make `drush` executable as a command from anywhere. Destination can be anywhere on $PATH. +chmod +x drush +sudo mv drush /usr/local/bin # Optional. Enrich the bash startup file with completion and aliases. drush init ``` - + * MAMP users, and anyone wishing to launch a non-default PHP, needs to [edit ~/.bashrc so that the right PHP is in your $PATH](http://stackoverflow.com/questions/4145667/how-to-override-the-path-of-php-to-use-the-mamp-path/10653443#10653443). * We have documented [alternative ways to install](http://docs.drush.org/en/master/install-alternative/), including [Windows](http://docs.drush.org/en/master/install-alternative/#windows). * If you need to pass custom php.ini values, run `php -d foo=bar drush.phar --php-options=foo=bar` diff --git a/drush-services.yml b/drush-services.yml index f253be472c..b687466270 100644 --- a/drush-services.yml +++ b/drush-services.yml @@ -35,6 +35,9 @@ services: arguments: ['@logger'] tags: - { name: bootstrap.boot } + # + # This service is needed in order to show the D6 deprecation message. + # bootstrap.drupal6: class: Drush\Boot\DrupalBoot6 arguments: ['@logger'] diff --git a/drush.api.php b/drush.api.php index 876d8cacc3..95764fac7a 100644 --- a/drush.api.php +++ b/drush.api.php @@ -280,9 +280,10 @@ function drush_hook_pre_pm_enable() { * @see sql_drush_sql_sync_sanitize() */ function hook_drush_sql_sync_sanitize($source) { + $table = drush_get_option('db-prefix') ? '{users}' : 'users'; drush_sql_register_post_sync_op('my-sanitize-id', dt('Reset passwords and email addresses in user table.'), - "UPDATE users SET pass = MD5('password'), mail = concat('user+', uid, '@localhost') WHERE uid > 0;"); + "UPDATE $table SET pass = MD5('password'), mail = concat('user+', uid, '@localhost') WHERE uid > 0;"); } /** diff --git a/drush.complete.sh b/drush.complete.sh index 38b882ec35..62ad507433 100755 --- a/drush.complete.sh +++ b/drush.complete.sh @@ -13,7 +13,7 @@ # source /path/to/your/drush.complete.sh # Ensure drush is available. -which drush > /dev/null || alias drush &> /dev/null || return +command -v drush >/dev/null || alias drush &> /dev/null || return __drush_ps1() { f="${TMPDIR:-/tmp/}/drush-env-${USER}/drush-drupal-site-$$" diff --git a/examples/example.drushrc.php b/examples/example.drushrc.php index 229aa0bc0c..d4068452b5 100644 --- a/examples/example.drushrc.php +++ b/examples/example.drushrc.php @@ -243,7 +243,7 @@ # $options['skip-tables']['common'] = array('migration_*'); /** - * Override specific entries in Drupal's variable system or settings.php (D6/D7 only). + * Override specific entries in Drupal's variable system or settings.php (D7 only). */ # $options['variables']['site_name'] = 'My Drupal site'; # $options['variables']['theme_default'] = 'minnelli'; diff --git a/examples/policy.drush.inc b/examples/policy.drush.inc index 17ae611fd3..ed6857fa9d 100644 --- a/examples/policy.drush.inc +++ b/examples/policy.drush.inc @@ -68,6 +68,33 @@ function policy_drush_sitealias_alter(&$alias_record) { } } += 6 && $log_entry['severity'] <= 2) { + if ($log_entry['severity'] <= 2) { $severity = 'error'; } else { diff --git a/includes/drush.inc b/includes/drush.inc index e0850cb408..c3609fa3c4 100644 --- a/includes/drush.inc +++ b/includes/drush.inc @@ -49,8 +49,8 @@ define('DRUSH_CACHE_LIFETIME_DEFAULT', 86400); * Include a file, selecting a version specific file if available. * * For example, if you pass the path "/var/drush" and the name - * "update" when bootstrapped on a Drupal 6 site it will first check for - * the presence of "/var/drush/update_6.inc" in include it if exists. If this + * "update" when bootstrapped on a Drupal 8 site it will first check for + * the presence of "/var/drush/update_8.inc" in include it if exists. If this * file does NOT exist it will proceed and check for "/var/drush/update.inc". * If neither file exists, it will return FALSE. * diff --git a/includes/environment.inc b/includes/environment.inc index 0f6daeaf81..bc5e65e6fc 100644 --- a/includes/environment.inc +++ b/includes/environment.inc @@ -359,9 +359,8 @@ function drush_locate_root($start_path = NULL) { * @param string * Path to check. * - * @return string - * The relative path to common.inc (varies by Drupal version), or FALSE if not - * a Drupal root. + * @return bool + * True if the provided path is a valid Drupal root. */ function drush_valid_root($root) { $bootstrap_class = \Drush::bootstrapManager()->bootstrapObjectForRoot($root); @@ -858,8 +857,8 @@ function drush_get_drupal_core_compatibility() { if (defined('DRUPAL_CORE_COMPATIBILITY')) { return DRUPAL_CORE_COMPATIBILITY; } - elseif (defined('Drupal::CORE_COMPATIBILITY')) { - return Drupal::CORE_COMPATIBILITY; + elseif (defined('\Drupal::CORE_COMPATIBILITY')) { + return \Drupal::CORE_COMPATIBILITY; } } diff --git a/includes/preflight.inc b/includes/preflight.inc index 369347054b..7a3d75ac1f 100644 --- a/includes/preflight.inc +++ b/includes/preflight.inc @@ -228,6 +228,8 @@ function drush_preflight_prepare() { /** * Set up our dependency injection container, and load drush-services.yml. + * + * The Drupal6 boot service is needed in order to show the D6 deprecation message. */ function drush_init_dependency_injection_container($input = null, $output = null) { // Set up our dependency injection container. @@ -531,7 +533,6 @@ function drush_preflight_root() { if ($root) { $root = realpath($root); } - // @todo Drupal code should use DRUSH_DRUPAL_ROOT instead of this constant. \Drush::bootstrapManager()->setRoot($root); // Load the config options from Drupal's /drush, ../drush, and sites/all/drush directories, diff --git a/lib/Drush/Boot/DrupalBoot.php b/lib/Drush/Boot/DrupalBoot.php index e36209daa4..682ada05b4 100644 --- a/lib/Drush/Boot/DrupalBoot.php +++ b/lib/Drush/Boot/DrupalBoot.php @@ -281,7 +281,7 @@ function bootstrap_drupal_root_validate() { $version = drush_drupal_version($drupal_root); $major_version = drush_drupal_major_version($drupal_root); - if ($major_version <= 5) { + if ($major_version <= 6) { return drush_set_error('DRUSH_DRUPAL_VERSION_UNSUPPORTED', dt('Drush !drush_version does not support Drupal !major_version.', array('!drush_version' => DRUSH_VERSION, '!major_version' => $major_version))); } @@ -451,8 +451,7 @@ function bootstrap_drupal_configuration() { global $conf; $override = array( - 'dev_query' => FALSE, // Force Drupal6 not to store queries since we are not outputting them. - 'cron_safe_threshold' => 0, // Don't run poormanscron during Drush request (D7+). + 'cron_safe_threshold' => 0, // Don't run poormanscron during Drush request (D7). ); $current_override = drush_get_option_list('variables'); diff --git a/lib/Drush/Boot/DrupalBoot6.php b/lib/Drush/Boot/DrupalBoot6.php index a7eb4ee455..282fefc788 100644 --- a/lib/Drush/Boot/DrupalBoot6.php +++ b/lib/Drush/Boot/DrupalBoot6.php @@ -1,5 +1,10 @@ perms)) { - $perms = db_result(db_query("SELECT perm FROM {permission} pm LEFT JOIN {role} r ON r.rid = pm.rid WHERE r.rid = '%d'", $this->rid)); - $role_perms = explode(", ", $perms); - $this->perms = array_filter($role_perms); - } - return $this->perms; - } - - public function getModulePerms($module) { - return module_invoke($module, 'perm'); - } - - public function role_create($role_machine_name, $role_human_readable_name = '') { - $this->_admin_user_role_op($role_machine_name, t('Add role')); - return TRUE; - } - - public function delete() { - $this->_admin_user_role_op($this->rid, t('Delete role')); - } - - function _admin_user_role_op($role_machine_name, $op) { - // c.f. http://drupal.org/node/283261 - require_once(drupal_get_path('module', 'user') . "/user.admin.inc"); - - $form_id = "user_admin_new_role"; - $form_values = array(); - $form_values["name"] = $role_machine_name; - $form_values["op"] = $op; - $form_state = array(); - $form_state["values"] = $form_values; - - drupal_execute($form_id, $form_state); - } - - public function grant_permissions($perms_to_add) { - $perms = $this->getPerms(); - $this->perms = array_unique(array_merge($this->perms, $perms_to_add)); - $this->updatePerms(); - } - - public function revoke_permissions($perms_to_remove) { - $perms = $this->getPerms(); - $this->perms = array_diff($this->perms, $perms_to_remove); - $this->updatePerms(); - } - - function updatePerms() { - $new_perms = implode(", ", $this->perms); - drush_op('db_query', "UPDATE {permission} SET perm = '%s' WHERE rid= %d", $new_perms, $this->rid); - } -} diff --git a/lib/Drush/Role/Role8.php b/lib/Drush/Role/Role8.php index ce0b28eaec..08d51519f0 100644 --- a/lib/Drush/Role/Role8.php +++ b/lib/Drush/Role/Role8.php @@ -6,7 +6,7 @@ class Role8 extends Role7 { public function role_create($role_machine_name, $role_human_readable_name = '') { - // In D6 and D7, when we create a new role, the role + // In D7, when we create a new role, the role // machine name is specified, and the numeric rid is // auto-assigned (next available id); in D8, when we // create a new role, we need to specify both the rid, diff --git a/lib/Drush/Role/RoleBase.php b/lib/Drush/Role/RoleBase.php index 5e19d4282f..65c7efafb7 100644 --- a/lib/Drush/Role/RoleBase.php +++ b/lib/Drush/Role/RoleBase.php @@ -4,7 +4,7 @@ abstract class RoleBase { /** - * Drupal 6 and Drupal 7: + * Drupal 7: * 'rid' is numeric * 'name' is machine name (e.g. 'anonymous user') * diff --git a/lib/Drush/Sql/Sql6.php b/lib/Drush/Sql/Sql6.php deleted file mode 100644 index 1091f1340b..0000000000 --- a/lib/Drush/Sql/Sql6.php +++ /dev/null @@ -1,45 +0,0 @@ - $type)), LogLevel::BOOTSTRAP); - return FALSE; - } - } - else { - drush_log(dt('!type database type is unsupported.', array('!type' => $type)), LogLevel::BOOTSTRAP); - return FALSE; - } - return TRUE; - } - -} diff --git a/lib/Drush/Sql/SqlBase.php b/lib/Drush/Sql/SqlBase.php index e2379d9a10..7b42074c4b 100644 --- a/lib/Drush/Sql/SqlBase.php +++ b/lib/Drush/Sql/SqlBase.php @@ -215,11 +215,21 @@ public function query_format($query) { return $query; } + /** + * Drop specified database. + * + * @param array $tables + * An array of table names + * @return boolean + * True if successful, FALSE if failed. + */ public function drop($tables) { + $return = TRUE; if ($tables) { $sql = 'DROP TABLE '. implode(', ', $tables); - return $this->query($sql); + $return = $this->query($sql); } + return $return; } /** @@ -237,12 +247,13 @@ public function createdb_sql($dbname, $quoted = FALSE) {} * Create a new database. * * @param boolean $quoted - * Quote the database name. Mysql uses backticks to quote which can cause problems - * in a Windows shell. Set TRUE if the CREATE is not running on the bash command line. + * Quote the database name. + * @return boolean + * True if successful, FALSE otherwise. */ public function createdb($quoted = FALSE) { $dbname = $this->db_spec['database']; - $sql = $this->createdb_sql($dbname); + $sql = $this->createdb_sql($dbname, $quoted); // Adjust connection to allow for superuser creds if provided. $this->su(); return $this->query($sql); @@ -256,10 +267,10 @@ public function createdb($quoted = FALSE) { */ public function drop_or_create() { if ($this->db_exists()) { - $this->drop($this->listTables()); + return $this->drop($this->listTables()); } else { - $this->createdb(); + return $this->createdb(); } } @@ -318,7 +329,7 @@ public function get_expanded_table_selection() { /** * Extract the name of all existing tables in the given database. * - * @return array + * @return array|null * An array of table names which exist in the current database. */ public function listTables() {} diff --git a/lib/Drush/Sql/Sqlmysql.php b/lib/Drush/Sql/Sqlmysql.php index de55db4d03..1fdbaf7d5b 100644 --- a/lib/Drush/Sql/Sqlmysql.php +++ b/lib/Drush/Sql/Sqlmysql.php @@ -2,6 +2,8 @@ namespace Drush\Sql; +use PDO; + class Sqlmysql extends SqlBase { public function command() { @@ -51,6 +53,26 @@ public function creds($hide_password = TRUE) { $parameters['socket'] = $this->db_spec['pdo']['unix_socket']; } + if (!empty($this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_CA])) { + $parameters['ssl-ca'] = $this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_CA]; + } + + if (!empty($this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_CAPATH])) { + $parameters['ssl-capath'] = $this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_CAPATH]; + } + + if (!empty($this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_CERT])) { + $parameters['ssl-cert'] = $this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_CERT]; + } + + if (!empty($this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_CIPHER])) { + $parameters['ssl-cipher'] = $this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_CIPHER]; + } + + if (!empty($this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_KEY])) { + $parameters['ssl-key'] = $this->db_spec['pdo'][PDO::MYSQL_ATTR_SSL_KEY]; + } + return $this->params_to_options($parameters); } @@ -66,7 +88,12 @@ public function createdb_sql($dbname, $quoted = FALSE) { $sql[] = sprintf('CREATE DATABASE %s /*!40100 DEFAULT CHARACTER SET utf8 */;', $dbname); $db_superuser = drush_get_option('db-su'); if (isset($db_superuser)) { - $sql[] = sprintf('GRANT ALL PRIVILEGES ON %s.* TO \'%s\'@\'%%\'', $dbname, $this->db_spec['username']); + // - For a localhost database, create a localhost user. This is important for security. + // localhost is special and only allows local Unix socket file connections. + // - If the database is on a remote server, create a wilcard user with %. + // We can't easily know what IP adderss or hostname would represent our server. + $domain = ($this->db_spec['host'] == 'localhost') ? 'localhost' : '%'; + $sql[] = sprintf('GRANT ALL PRIVILEGES ON %s.* TO \'%s\'@\'%s\'', $dbname, $this->db_spec['username'], $domain); $sql[] = sprintf("IDENTIFIED BY '%s';", $this->db_spec['password']); $sql[] = 'FLUSH PRIVILEGES;'; } diff --git a/lib/Drush/Sql/Sqlsqlite.php b/lib/Drush/Sql/Sqlsqlite.php index 94e044002b..2182afb38b 100644 --- a/lib/Drush/Sql/Sqlsqlite.php +++ b/lib/Drush/Sql/Sqlsqlite.php @@ -40,6 +40,10 @@ public function createdb($quoted = FALSE) { drush_mkdir($path); if (!file_exists($path)) { drush_log("SQLITE: Cannot create $path", LogLevel::ERROR); + return FALSE; + } + else { + return TRUE; } } diff --git a/lib/Drush/UpdateService/StatusInfoDrupal6.php b/lib/Drush/UpdateService/StatusInfoDrupal6.php deleted file mode 100644 index b0cc4d6428..0000000000 --- a/lib/Drush/UpdateService/StatusInfoDrupal6.php +++ /dev/null @@ -1,71 +0,0 @@ -update_check_disabled = $conf['update_advanced_check_disabled']; - $conf['update_advanced_check_disabled'] = $check_disabled; - } - } - - /** - * {@inheritdoc} - */ - function afterGetStatus(&$update_info, $projects, $check_disabled) { - // Restore Drupal settings. - if (!is_null($check_disabled)) { - global $conf; - $conf['update_advanced_check_disabled'] = $this->update_check_disabled; - unset($this->update_check_disabled); - } - - // update_advanced.module sets a different project type - // for disabled projects. Here we normalize it. - if ($check_disabled) { - foreach ($update_info as $key => $project) { - if (in_array($project['project_type'], array('disabled-module', 'disabled-theme'))) { - $update_info[$key]['project_type'] = substr($project['project_type'], strpos($project['project_type'], '-') + 1); - } - } - } - } - - /** - * Obtains release info for all installed projects via update.module. - * - * @see update_get_available(). - * @see update_manual_status(). - */ - protected function getAvailableReleases() { - // We force a refresh if the cache is not available. - if (!cache_get('update_available_releases', 'cache_update')) { - $this->refresh(); - } - - $available = update_get_available(TRUE); - - // Force to invalidate some update_status caches that are only cleared - // when visiting update status report page. - if (function_exists('_update_cache_clear')) { - _update_cache_clear('update_project_data'); - _update_cache_clear('update_project_projects'); - } - - return $available; - } -} - diff --git a/lib/Drush/UpdateService/StatusInfoDrush.php b/lib/Drush/UpdateService/StatusInfoDrush.php index 0fe6b96c22..1574206d61 100644 --- a/lib/Drush/UpdateService/StatusInfoDrush.php +++ b/lib/Drush/UpdateService/StatusInfoDrush.php @@ -192,7 +192,6 @@ private function calculateProjectStatus($project_release_info) { * * This is a stripped down version of update_calculate_project_status(). * That function has the same logic in Drupal 6,7,8. - * Note: in Drupal 6 this is part of update_calculate_project_data(). * * @see update_calculate_project_status(). */ diff --git a/lib/Drush/User/User6.php b/lib/Drush/User/User6.php deleted file mode 100644 index 1ecb6681a5..0000000000 --- a/lib/Drush/User/User6.php +++ /dev/null @@ -1,29 +0,0 @@ - $name)); - } - - /** - * {@inheritdoc} - */ - public function load_by_mail($mail) { - return user_load(array('mail' => $mail)); - } - -} diff --git a/lib/Drush/User/UserSingle6.php b/lib/Drush/User/UserSingle6.php deleted file mode 100644 index 1411682643..0000000000 --- a/lib/Drush/User/UserSingle6.php +++ /dev/null @@ -1,10 +0,0 @@ -account->uid); - } -} diff --git a/tests/Unish/UnishTestCase.php b/tests/Unish/UnishTestCase.php index 1f5ade8976..581d7f6937 100644 --- a/tests/Unish/UnishTestCase.php +++ b/tests/Unish/UnishTestCase.php @@ -318,13 +318,9 @@ function fetchInstallDrupal($env = 'dev', $install = FALSE, $version_string = UN $options = array(); $site = "$root/sites/$uri"; - if (substr($version_string, 0, 1) == 6 && $this->db_driver(UNISH_DB_URL) == 'sqlite') { - // Validate - $this->markTestSkipped("Drupal 6 does not support SQLite."); - } if ($version_string == 8) { // We want to track Drupal 8 very closely. - $version_string = '8.0.x'; + $version_string = '8.1.x'; $options['no-md5'] = NULL; } diff --git a/tests/cacheCommandTest.php b/tests/cacheCommandTest.php index 6d9781adff..ce00966237 100644 --- a/tests/cacheCommandTest.php +++ b/tests/cacheCommandTest.php @@ -19,7 +19,6 @@ function testCacheGet() { $options = $this->getOptions(); // Test the cache get command. $inputs = array( - 6 => array('variables', NULL), 7 => array('schema', NULL), 8 => array('system.date', 'config'), ); diff --git a/tests/configTest.php b/tests/configTest.php index 6a3450791d..3189802365 100644 --- a/tests/configTest.php +++ b/tests/configTest.php @@ -16,6 +16,7 @@ function setUp() { if (!$this->getSites()) { $this->setUpDrupal(1, TRUE); + $this->drush('pm-enable', array('config'), $this->options()); } } @@ -66,9 +67,10 @@ function testConfigExportImport() { // Similar, but this time via --partial option. $contents = file_get_contents($system_site_yml); $contents = preg_replace('/front: .*/', 'front: unish partial', $contents); - $partial_path = UNISH_SANDBOX . '/system.site.yml'; - $contents = file_put_contents($partial_path, $contents); - $this->drush('config-import', array(), $options + array('partial' => $partial_path)); + $partial_path = UNISH_SANDBOX . '/partial'; + mkdir($partial_path); + $contents = file_put_contents($partial_path. '/system.site.yml', $contents); + $this->drush('config-import', array(), $options + array('partial' => NULL, 'source' => $partial_path)); $this->drush('config-get', array('system.site', 'page'), $options + array('format' => 'json')); $page = $this->getOutputFromJSON('system.site:page'); $this->assertContains('unish partial', $page->front, '--partial was successfully imported.'); diff --git a/tests/imageTest.php b/tests/imageTest.php index 3f54acec6e..e38fa9cd20 100644 --- a/tests/imageTest.php +++ b/tests/imageTest.php @@ -10,10 +10,6 @@ class ImageCase extends CommandUnishTestCase { function testImage() { - if (UNISH_DRUPAL_MAJOR_VERSION == 6) { - $this->markTestSkipped("Image styles not available in Drupal 6 core."); - } - $sites = $this->setUpDrupal(1, TRUE, UNISH_DRUPAL_MAJOR_VERSION, 'standard'); $options = array( 'yes' => NULL, diff --git a/tests/makefiles/qd-devel.make b/tests/makefiles/qd-devel.make index c08f72fcba..8f193fb8d8 100644 --- a/tests/makefiles/qd-devel.make +++ b/tests/makefiles/qd-devel.make @@ -1,6 +1,6 @@ core = "7.x" api = 2 -projects[drupal][version] = "7.22" +projects[drupal][version] = "7.42" defaults[projects][subdir] = "contrib" projects[devel] = "1.3" diff --git a/tests/pmEnDisUnListInfoTest.php b/tests/pmEnDisUnListInfoTest.php index 6cf81b42f5..e4c0508ca6 100644 --- a/tests/pmEnDisUnListInfoTest.php +++ b/tests/pmEnDisUnListInfoTest.php @@ -103,7 +103,7 @@ public function testEnDisUnList() { // Test pm-enable is able to download dependencies. // @todo pathauto has no usable D8 release yet. // Also, Drupal 6 has no stable releases any longer, so resolve-dependencies are inconvenient to test. - if (UNISH_DRUPAL_MAJOR_VERSION ==7) { + if (UNISH_DRUPAL_MAJOR_VERSION == 7) { $this->drush('pm-download', array('pathauto'), $options); $this->drush('pm-enable', array('pathauto'), $options + array('resolve-dependencies' => TRUE)); $this->drush('pm-list', array(), $options + array('status' => 'enabled')); diff --git a/tests/pmUpdateStatusTest.php b/tests/pmUpdateStatusTest.php index ae55e77cc5..8e4ec3c1a7 100644 --- a/tests/pmUpdateStatusTest.php +++ b/tests/pmUpdateStatusTest.php @@ -24,7 +24,6 @@ class pmUpdateStatus extends CommandUnishTestCase { * We choose to setup a Drupal 7 environment for convenience: * - It has modules in each maintenance status * and they're not willing to change in short - * - Drupal 6 will start to be unsupported at some point * - Drupal 8 still has not enough variety to cover the tests */ function setUp() { diff --git a/tests/quickDrupalTest.php b/tests/quickDrupalTest.php index d44982e8bc..0f23892f88 100644 --- a/tests/quickDrupalTest.php +++ b/tests/quickDrupalTest.php @@ -65,7 +65,7 @@ function getQuickDrupalTestParameters($key) { 'options' => array( 'skip' => NULL, // for speed up enable of devel module. 'browser' => 0, - 'profile' => UNISH_DRUPAL_MAJOR_VERSION == 6 ? 'standard' : 'testing', + 'profile' => 'testing', ), ), ); diff --git a/tests/roleTest.php b/tests/roleTest.php index 9f74e77be4..bc58581388 100644 --- a/tests/roleTest.php +++ b/tests/roleTest.php @@ -18,7 +18,7 @@ class roleCase extends CommandUnishTestCase { */ public function testRole() { // In D8+, the testing profile has no perms. - $sites = $this->setUpDrupal(1, TRUE, UNISH_DRUPAL_MAJOR_VERSION, UNISH_DRUPAL_MAJOR_VERSION == 6 ? 'default' : 'standard'); + $sites = $this->setUpDrupal(1, TRUE, UNISH_DRUPAL_MAJOR_VERSION, 'standard'); $root = $this->webroot(); $name = "example"; $options = array( diff --git a/tests/siteAliasTest.php b/tests/siteAliasTest.php index 0cc6f911f9..2e6cffdc00 100644 --- a/tests/siteAliasTest.php +++ b/tests/siteAliasTest.php @@ -168,10 +168,6 @@ public function testBadAlias() { * Ensure that a --uri on CLI overrides on provided by site alias during a backend invoke. */ public function testBackendHonorsAliasOverride() { - if (UNISH_DRUPAL_MAJOR_VERSION == 6) { - $this->markTestSkipped("Sites.php not available in Drupal 6 core."); - } - // Test a standard remote dispatch. $this->drush('core-status', array(), array('uri' => 'http://example.com', 'simulate' => NULL), 'user@server/path/to/drupal#sitename'); $this->assertContains('--uri=http://example.com', $this->getOutput()); diff --git a/tests/siteIntallD6Test.php b/tests/siteIntallD6Test.php deleted file mode 100644 index 91db1e4aba..0000000000 --- a/tests/siteIntallD6Test.php +++ /dev/null @@ -1,78 +0,0 @@ -markTestSkipped('This test class is designed for Drupal 6.'); - return; - } - } - - /** - * Test a D6 install with extra options. - */ - public function testExtraConfigurationOptions() { - // Set up codebase without installing Drupal. - $sites = $this->setUpDrupal(1, FALSE, '6'); - $root = $this->webroot(); - $site = key($sites); - - // Copy the "example" test profile into the newly created site's profiles directory - $profile_dir = "$root/profiles/example"; - mkdir($profile_dir); - copy(dirname(__FILE__) . '/resources/example.profile', $profile_dir . '/example.profile'); - - $test_string = $this->randomString(); - // example.profile Has values 0-2 defined as allowed. - $test_int = rand(0, 2); - $site_name = $this->randomString(); - - $this->drush('site-install', array( - // First argument is the profile name - 'example', - // Then the extra profile options - "myopt1=$test_string", - "myopt2=$test_int", - ), - array( - 'db-url' => $this->db_url($site), - 'yes' => NULL, - 'sites-subdir' => $site, - 'root' => $root, - 'site-name' => $site_name, - 'uri' => $site, - )); - - $this->checkVariable('site_name', $site_name, $site); - $this->checkVariable('myopt1', $test_string, $site); - $this->checkVariable('myopt2', $test_int, $site); - } - - /** - * Check the value of a Drupal variable against an expectation using drush. - * - * @param $name - * The variable name. - * @param $value - * The expected value of this variable. - * @param $site - * The name of an individual multisite installation site. - */ - private function checkVariable($name, $value, $site) { - $options = array( - 'root' => $this->webroot(), - 'uri' => $site, - ); - - $this->drush('variable-get', array($name), $options); - $this->assertEquals("$name: $value", $this->getOutput()); - } -} diff --git a/tests/sqlDumpTest.php b/tests/sqlDumpTest.php index 24ddd00539..709ff6d497 100644 --- a/tests/sqlDumpTest.php +++ b/tests/sqlDumpTest.php @@ -50,7 +50,7 @@ function testSqlDump() { $this->assertFileExists($full_dump_file_path); $full_dump_file = file_get_contents($full_dump_file_path); // Test that we have sane contents. - $this->assertContains('batch', $full_dump_file); + $this->assertContains('queue', $full_dump_file); // Test skip-files-list and wildcard expansion. $this->assertNotContains('history', $full_dump_file); // Next, set up an alias file and run a couple of simulated @@ -62,7 +62,7 @@ function testSqlDump() { $this->assertFileExists($full_dump_file_path); $full_dump_file = file_get_contents($full_dump_file_path); // Test that we have sane contents. - $this->assertContains('batch', $full_dump_file); + $this->assertContains('queue', $full_dump_file); // Test skip-files-list and wildcard expansion. $this->assertContains('history', $full_dump_file); @@ -91,7 +91,7 @@ function testSqlDump() { $this->assertFileExists($full_dump_file_path); $full_dump_file = file_get_contents($full_dump_file_path); // Test that we have sane contents. - $this->assertContains('batch', $full_dump_file); + $this->assertContains('queue', $full_dump_file); // Test skip-files-list and wildcard expansion. $this->assertNotContains('history', $full_dump_file); // Repeat control test: options not recovered in absence of an alias. @@ -100,7 +100,7 @@ function testSqlDump() { $this->assertFileExists($full_dump_file_path); $full_dump_file = file_get_contents($full_dump_file_path); // Test that we have sane contents. - $this->assertContains('batch', $full_dump_file); + $this->assertContains('queue', $full_dump_file); // Test skip-files-list and wildcard expansion. $this->assertContains('history', $full_dump_file); // Now run yet with @self, and test to see that Drush can recover the option @@ -110,7 +110,7 @@ function testSqlDump() { $this->assertFileExists($full_dump_file_path); $full_dump_file = file_get_contents($full_dump_file_path); // Test that we have sane contents. - $this->assertContains('batch', $full_dump_file); + $this->assertContains('queue', $full_dump_file); // Test skip-files-list and wildcard expansion. $this->assertNotContains('history', $full_dump_file); } diff --git a/tests/sqlSyncTest.php b/tests/sqlSyncTest.php index f3e84d6d5c..6562d86778 100644 --- a/tests/sqlSyncTest.php +++ b/tests/sqlSyncTest.php @@ -33,20 +33,6 @@ public function testLocalSqlSync() { $sites = $this->setUpDrupal(2, TRUE); return $this->localSqlSync(); } - /** - * Do the same test as above, but use Drupal 6 sites instead of Drupal 7. - */ - public function testLocalSqlSyncD6() { - if (UNISH_DRUPAL_MAJOR_VERSION != 6) { - $this->markTestSkipped('This test class is designed for Drupal 6.'); - return; - } - - chdir(UNISH_TMP); // Avoids perm denied Windows error. - $this->setUpBeforeClass(); - $sites = $this->setUpDrupal(2, TRUE, '6'); - return $this->localSqlSync(); - } public function localSqlSync() { // Create a user in the staging site diff --git a/tests/userTest.php b/tests/userTest.php index bdd6e75478..1cdd30614a 100644 --- a/tests/userTest.php +++ b/tests/userTest.php @@ -31,7 +31,7 @@ function setUp() { function testBlockUnblock() { $this->drush('user-block', array(self::NAME), $this->options()); $this->drush('user-information', array(self::NAME), $this->options() + array('format' => 'json')); - $uid = UNISH_DRUPAL_MAJOR_VERSION == 6 ? 3 : 2; + $uid = 2; $output = $this->getOutputFromJSON($uid); $this->assertEquals(0, $output->{self::$status_prop}, 'User is blocked.'); @@ -47,8 +47,8 @@ function testUserRole() { $this->drush('role-create', array('test role'), $this->options()); $this->drush('user-add-role', array('test role', self::NAME), $this->options()); $this->drush('user-information', array(self::NAME), $this->options() + array('format' => 'json')); - $uid = UNISH_DRUPAL_MAJOR_VERSION == 6 ? 3 : 2; - $output = $this->getOutputFromJSON($uid); + $uid = 2; + $output = $this->getOutputFromJSON($uid); $expected = array(self::$authenticated, 'test role'); $this->assertEquals($expected, array_values((array)$output->roles), 'User has test role.'); @@ -64,11 +64,7 @@ function testUserPassword() { $newpass = 'newpass'; $name = self::NAME; $this->drush('user-password', array(self::NAME), $this->options() + array('password' => $newpass)); - // user_authenticate() is more complex in D6 so skip it. switch (UNISH_DRUPAL_MAJOR_VERSION) { - case 6: - $this->markTestSkipped('Drupal 6 authentication too complex for testing.'); - break; case 7: $eval = "return user_authenticate('$name', '$newpass')"; break; @@ -101,15 +97,12 @@ function testUserLogin() { } $this->assertEquals($browser, TRUE, 'Correct browser opened at correct URL'); // Check specific user and path argument. - $uid = UNISH_DRUPAL_MAJOR_VERSION == 6 ? 3 : 2; + $uid = 2; $this->drush('user-login', array(self::NAME, 'node/add'), $user_login_options); $output = $this->getOutput(); $url = parse_url($output); // user_pass_reset_url encodes the URL in D6, but not in D7 or D8 $query = $url['query']; - if (UNISH_DRUPAL_MAJOR_VERSION < 7) { - $query = urldecode($query); - } $this->assertContains('/user/reset/' . $uid, $url['path'], 'Login with user argument returned a valid reset URL'); $this->assertEquals('destination=node/add', $query, 'Login included destination path in URL'); // Check path used as only argument when using uid option. @@ -118,9 +111,6 @@ function testUserLogin() { $url = parse_url($output); $this->assertContains('/user/reset/' . $uid, $url['path'], 'Login with uid option returned a valid reset URL'); $query = $url['query']; - if (UNISH_DRUPAL_MAJOR_VERSION < 7) { - $query = urldecode($query); - } $this->assertEquals('destination=node/add', $query, 'Login included destination path in URL'); } @@ -158,7 +148,7 @@ function testUserCancel() { function UserCreate() { $this->drush('user-create', array(self::NAME), $this->options() + array('password' => 'password', 'mail' => "example@example.com")); $this->drush('user-information', array(self::NAME), $this->options() + array('format' => 'json')); - $uid = UNISH_DRUPAL_MAJOR_VERSION == 6 ? 3 : 2; + $uid = 2; $output = $this->getOutputFromJSON($uid); $this->assertEquals('example@example.com', $output->mail); $this->assertEquals(self::NAME, $output->name);