/** * Prompt the user to enter the database name, login and password to use on the remote server for executing the database patches. * The credentials are checked by creating and dropping a table. * * @param bool $pre_check If this is just a check to access te database (to check the db_patches table) or asking for confirmation to send the changes */ protected function getDatabaseLogin($pre_check = false) { if ($this->database_checked) { return; } $database_name = $this->database_name; // if the database credentials are known, no need to ask for them again if ($database_name === null) { if ($this->local_shell->inputPrompt('Check if database needs updates? (y/N): ', 'n', false, array('y', 'n')) != 'y') { $database_name = 'skip'; } } if ('skip' != $database_name) { if ($this->database_name !== null) { // we're not updating anything yet, so no need to ask questions if (!$pre_check) { if ($this->local_shell->inputPrompt('Update database ' . $this->database_name . '? (y/N): ', 'n', false, array('y', 'n')) != 'y') { $database_name = 'skip'; } } } else { $database_name = $this->local_shell->inputPrompt('Database name [skip]: ', 'skip'); } } if ('' == $database_name || 'n' == $database_name) { $database_name = 'skip'; } if ('skip' == $database_name) { $username = ''; $password = ''; $this->logger->log('Skip database patches'); } else { $username = $this->database_user !== null ? $this->database_user : $this->local_shell->inputPrompt('Database username [root]: ', 'root'); $password = $this->database_pass !== null ? $this->database_pass : $this->local_shell->inputPrompt('Database password: '******'', true); $return = 0; $output = array(); // Simple access test (check if this user can create and drop a table) $this->query("\n CREATE TABLE `temp_" . $this->current_timestamp . "` (`field1` INT NULL);\n DROP TABLE `temp_" . $this->current_timestamp . "`;\n ", $output, $return, $database_name, $username, $password); if ($return != 0) { $this->getDatabaseLogin(); } $this->logger->log('Database account check passed', LOG_INFO, true); } $this->database_checked = true; $this->database_name = $database_name; $this->database_user = $username; $this->database_pass = $password; }
/** * Deletes old, obsolete deployments */ public function cleanup() { $this->logger->log('cleanup', LOG_DEBUG); $past_deployments = array(); if (is_array($this->remote_host)) { foreach ($this->remote_host as $remote_host) { if ($past_dirs = $this->collectPastDeployments($remote_host, $this->remote_dir)) { $past_deployments[] = array('remote_host' => $remote_host, 'remote_dir' => $this->remote_dir, 'dirs' => $past_dirs); } } } else { if ($past_dirs = $this->collectPastDeployments($this->remote_host, $this->remote_dir)) { $past_deployments[] = array('remote_host' => $this->remote_host, 'remote_dir' => $this->remote_dir, 'dirs' => $past_dirs); } } if (!empty($past_deployments)) { if ($this->local_shell->inputPrompt('Delete old directories? (y/N): ', 'n', false, array('y', 'n')) == 'y') { $this->deletePastDeployments($past_deployments); } } else { $this->logger->log('No cleanup needed'); } }