public function createSettingsFile($database, $db_user, $db_cred) { $web_dir = $this->getDocumentRoot(); $project_domain = $this->getProjectDomain(); if (empty($web_dir)) { $document_root = $this->getProjectDir(); } else { $document_root = $this->getProjectDir() . '/' . $web_dir; } $project_site_folder = $document_root . '/sites/' . $project_domain; // Create the settings.php file $this->settings_generator->generate_file($database, $db_user, $db_cred, $project_domain); drush_log(dt('Created the settings.php file.'), 'success'); // Do we want a multisite setup or not? $multi = drush_confirm(dt('Do you want to configure Drupal as a multi site setup (settings.php in a separate sites folder)?')); if ($multi) { // Create an empty project folder. conf_path(FALSE) will pick it up and take care of the rest if (!$this->file_system->checkDir($project_site_folder)) { $this->file_system->createDir($project_site_folder); $source = $this->getProjectDir() . '/' . $this->getDocumentRoot() . '/sites/default/settings.php'; $target = $this->getProjectDir() . '/' . $this->getDocumentRoot() . '/sites/' . $this->getProjectDomain() . '/settings.php'; $this->file_system->moveFile($source, $target); } } }
public function fetch($repository, $working_directory) { if (!drush_shell_exec("git clone {$repository} {$working_directory}")) { throw new RumRepositoryNotClonedException($repository, $working_directory); } $create_ignore = drush_confirm(dt('Do you want to create an ignore file?')); if ($create_ignore) { $this->createIgnoreFile($working_directory); } }
private function removeDirectory($directory) { $result = $this->file_system->checkDir($directory); if ($result) { $remove = drush_confirm(dt('Do you want to delete directory %directory?', array('%directory' => $directory))); if ($remove) { $result = $this->file_system->removeDir($directory); } else { $result = drush_user_abort('Aborting...'); } } return $result; }
/** * Load the desired environments. * * @param string $env * The environment argument. May be composite (env1+env2). * * @return bool * Whether the environments were loaded. */ public function setEnvironments($env) { $envs = explode('+', $env); while (!empty($envs)) { $_env = array_shift($envs); if (!$this->setEnvironment($_env)) { $msg = dt("Unable to locate an environment definition for '@env'.", ['@env' => $_env]); if (empty($envs)) { return drush_set_error('DRUSH_DRUPAL_ERROR_MESSAGE', $msg); } else { drush_log($msg, 'warning'); if (!drush_confirm(dt("Do you want to process the other environments?"))) { return drush_user_abort(dt("Aborting.")); } } } } return TRUE; }
/** * Class constructor. * * @param LWG $command * The current instance of the command. * @param array|object $input * The input parameter accepts an array. * @param int $flags * Flags to control the behaviour of the ArrayObject object. * @param string $iterator_class * Specify the class that will be used for iteration of the ArrayObject * object. ArrayIterator is the default class used. */ public function __construct(LWG $command, array $input = array(), $flags = 0, $iterator_class = "ArrayIterator") { $this->command = $command; $this->exchangeArray($input); $project = $command->getProject(); $filename = $this->getFilename(); $this->file = $project->getPath() . "/{$filename}"; $this->cache = new Cache($project->getName() . ':notice'); $cache = $this->cache->get(); if (!file_exists($this->file)) { $prompt = dt("An existing !filename file was not found in @project.\nWould you like to create one?", array('!filename' => $filename, '@project' => $project->getInfo('name') ?: 'this project')); if (drush_confirm($prompt)) { if (!$this->save()) { return drush_set_error('DRUSH_LWG_CREATE_FILE', dt("Unable to create the specified project file:\n!file", array('!file' => $this->file))); } } else { $this->file = FALSE; return $this; } } if (!is_writable($this->file)) { return drush_set_error('DRUSH_LWG_FILE_NOT_WRITABLE', dt("The specified project file is not writable:\n!file", array('!file' => $this->file))); } if (file_exists($this->file)) { $array = array(); // Convert each entry into an Asset object. foreach (Yaml::parse($this->file) ?: array() as $name => $data) { if (is_array($data)) { $array[$name] = new Asset($command, $name, $data); } } if (!$this->cache->exists()) { $this->cache->set($array); } $this->exchangeArray($array); $this->exists = TRUE; } }
/** * Initialize local Drush configuration * * Enrich the bash startup file with completion and aliases. * Copy .drushrc file to ~/.drush * * @todo: '@package core', @global-options, replacement mechanism for 'bootstrap' * * @option $edit Open the new config file in an editor. * @option $add-path Always add Drush to the \$PATH in the user's .bashrc * file, even if it is already in the \$PATH. Use --no-add-path to skip * updating .bashrc with the Drush \$PATH. Default is to update .bashrc * only if Drush is not already in the \$PATH. * @aliases core-init, init * @usage core-init --edit * Enrich Bash and open drush config file in editor. * @usage core-init --edit --bg * Return to shell prompt as soon as the editor window opens */ public function initializeDrush($options = ['edit' => '', 'add-path' => '']) { $home = drush_server_home(); $drush_config_dir = $home . "/.drush"; $drush_config_file = $drush_config_dir . "/drushrc.php"; $drush_bashrc = $drush_config_dir . "/drush.bashrc"; $drush_prompt = $drush_config_dir . "/drush.prompt.sh"; $drush_complete = $drush_config_dir . "/drush.complete.sh"; $examples_dir = DRUSH_BASE_PATH . "/examples"; $example_configuration = $examples_dir . "/example.drushrc.php"; $example_bashrc = $examples_dir . "/example.bashrc"; $example_prompt = $examples_dir . "/example.prompt.sh"; $example_complete = DRUSH_BASE_PATH . "/drush.complete.sh"; $collection = $this->collectionBuilder(); // Create a ~/.drush directory if it does not yet exist $collection->taskFilesystemStack()->mkdir($drush_config_dir); // If there is no ~/.drush/drushrc.php, then copy the // example Drush configuration file here if (!is_file($drush_config_file)) { $collection->taskWriteToFile($drush_config_file)->textFromFile($example_configuration); } // Decide whether we want to add our Bash commands to // ~/.bashrc or ~/.bash_profile, and create a task to // update it with includes of the various files we write, // as needed. If it is, then we will add it to the collection. $bashrc = $this->findBashrc($home); $taskUpdateBashrc = $this->taskWriteToFile($bashrc)->append(); // List of Drush bash configuration files, and // their source templates. $drushBashFiles = [$drush_bashrc => $example_bashrc, $drush_complete => $example_complete, $drush_prompt => $example_prompt]; // Mapping from Drush bash configuration files // to a description of what each one is. $drushBashFileDescriptions = [$drush_bashrc => 'Drush bash customizations', $drush_complete => 'Drush completion', $drush_prompt => 'Drush prompt customizations']; foreach ($drushBashFiles as $destFile => $sourceFile) { // If the destination file does not exist, then // copy the example file there. if (!is_file($destFile)) { $collection->taskWriteToFile($destFile)->textFromFile($sourceFile); $description = $drushBashFileDescriptions[$destFile]; $collection->progressMessage('Copied {description} to {path}', ['description' => $description, 'path' => $destFile], LogLevel::OK); $pattern = basename($destFile); $taskUpdateBashrc->appendUnlessMatches("#{$pattern}#", "# Include {$description}.\n" . $this->bashAddition($destFile)); } } // If Drush is not in the $PATH, then figure out which // path to add so that Drush can be found globally. $add_path = $options['add-path']; if ((!drush_which("drush") || $add_path) && $add_path !== FALSE) { $drush_path = $this->findPathToDrush(); $drush_path = preg_replace("%^" . preg_quote($home) . "/%", '$HOME/', $drush_path); $pattern = "{$drush_path}"; $taskUpdateBashrc->appendUnlessMatches("#{$pattern}#", "# Path to Drush, added by 'drush init'.\nexport PATH=\"\$PATH:{$drush_path}\"\n\n"); } $openEditor = FALSE; if ($taskUpdateBashrc->wouldChange()) { if (drush_confirm(dt("Modify !file to include Drush configuration files?", array('!file' => $bashrc)))) { $collection->addTask($taskUpdateBashrc); $collection->progressMessage('Updated bash configuration file {path}', ['path' => $bashrc], LogLevel::OK); $collection->progressMessage('Start a new shell in order to experience the improvements (e.g. `{shell}`).', ['shell' => 'bash'], LogLevel::OK); $openEditor = $options['edit']; } else { return drush_user_abort(); } } else { $collection->progressMessage('No code added to {path}', ['path' => $bashrc]); } $result = $collection->run(); if ($result->wasSuccessful() && $openEditor) { $exec = drush_get_editor(); drush_shell_exec_interactive($exec, $drush_config_file, $drush_config_file); } return $result; }