Esempio n. 1
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $mysqlUsername = $arguments['mysql-username'];
     $mysqlPassword = isset($arguments['mysql-password']) ? $arguments['mysql-password'] : '';
     $dbName = $arguments['db-name'];
     $this->logLine(sprintf('Dropping database %s', $dbName));
     $cmd = sprintf('mysqladmin -u%s %s drop  %s --force', $mysqlUsername, nbMysqlUtils::formatPasswordOption($mysqlPassword), $dbName);
     $this->executeShellCommand($cmd);
     $this->logLine(sprintf('Database %s dropped', $dbName));
     return true;
 }
Esempio n. 2
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $dbName = $arguments['db-name'];
     $path = $arguments['dump-path'];
     $username = $arguments['username'];
     $password = isset($arguments['password']) ? $arguments['password'] : null;
     $host = $arguments['host'];
     $timestamp = date('YmdHi', time());
     $dump = sprintf('%s/%s-%s.sql', $path, $timestamp, $dbName);
     $this->logLine(sprintf('Dumping database "%s" to "%s"', $dbName, $dump));
     $cmd = sprintf('mysqldump -u%s %s -h%s %s > %s', $username, nbMysqlUtils::formatPasswordOption($password), $host, $dbName, $dump);
     $this->executeShellCommand($cmd);
     $this->logLine('MySql database dumped!');
     return true;
 }
Esempio n. 3
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $dbName = $arguments['db-name'];
     $filename = $arguments['dump-filename'];
     $username = $arguments['username'];
     $password = isset($arguments['password']) ? $arguments['password'] : null;
     if (!file_exists($filename)) {
         throw new InvalidArgumentException('Database dump file: ' . $filename . ' does not exist');
     }
     $this->logLine('Restoring ' . $filename . ' to database ' . $dbName);
     $cmd = sprintf('mysql -u%s %s %s < %s', $username, nbMysqlUtils::formatPasswordOption($password), $dbName, $filename);
     $this->logLine($cmd);
     $this->executeShellCommand($cmd);
     $this->logLine('MySql database restored!');
     return true;
 }
Esempio n. 4
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $mysqlUsername = $arguments['mysql-username'];
     $mysqlPassword = isset($arguments['mysql-password']) ? $arguments['mysql-password'] : '';
     $dbName = $arguments['db-name'];
     $username = isset($options['username']) ? $options['username'] : null;
     $password = isset($options['password']) ? $options['password'] : null;
     $cmd = sprintf('mysqladmin -u%s %s create %s', $mysqlUsername, nbMysqlUtils::formatPasswordOption($mysqlPassword), $dbName);
     $this->executeShellCommand($cmd);
     $this->logLine(sprintf('Database %s created', $dbName));
     if ($username) {
         $cmd = sprintf('mysql -u%s %s mysql -e "grant all privileges on %s.* to \'%s\'@\'localhost\' %s"', $mysqlUsername, nbMysqlUtils::formatPasswordOption($mysqlPassword), $dbName, $username, $password ? sprintf(' identified by \'%s\'', $password) : '');
         $this->executeShellCommand($cmd);
         $this->logLine(sprintf('Database user %s successfully created', $username));
     }
     return true;
 }