function dropDatabaseUser($mysqlAdminUsername, $mysqlAdminPassword, $username) { try { $cmd = sprintf('mysql -u%s %s -e "drop user \'%s\'@\'localhost\'"', $mysqlAdminUsername, $mysqlAdminPassword != '' ? '-p' . $mysqlAdminPassword : '', $username); $shell = new nbShell(); $shell->execute($cmd, true); } catch (Exception $e) { // Ignore errors } }
protected function execute(array $arguments = array(), array $options = array()) { if (!($arg = $this->getAlias($arguments['command_name']))) { $arg = $arguments['command_name']; } if (isset($options['args'])) { $arg .= ' ' . $options['args']; } $this->log('Executing: ' . $arg, nbLogger::COMMENT); $this->log("\n\n"); $shell = new nbShell(isset($options['redirect'])); return $shell->execute($arg); }
protected function execute(array $arguments = array(), array $options = array()) { $this->checkBeeProject(); if (!nbConfig::has('project_repository_root-directory')) { throw new Exception('You must configure your project directory (absolute path!)'); } $shell = new nbShell(); if (!isset($options['force'])) { // git status $this->logLine("git status:", nbLogger::INFO); $command = 'git status'; $shell->execute($command); // git tag $this->logLine("git tag", nbLogger::INFO); $command = 'git tag'; $shell->execute($command); return 0; } if (!isset($arguments['message'])) { throw new Exception('You must write a commit message!'); } $message = $arguments['message']; $repoDir = nbConfig::get('project_repository_root-directory'); // git add <project repository directory> $command = sprintf('git add %s', $repoDir); $shell->execute($command); // git commit -m "<message>" $command = sprintf('git commit -m "%s"', $message); $shell->execute($command); // git pull $command = 'git pull'; if (!$shell->execute($command)) { throw new Exception('There are conflicts. Resolve them and re-run this command.'); } // test command if (!nbConfig::has('project_test-command')) { throw new Exception('You must configure your test command'); } $command = nbConfig::get('project_test-command'); if (!$shell->execute($command)) { throw new Exception('There are test failures. Fix them and re-run this command.'); } if (isset($options['tag'])) { $tag = $options['tag']; $command = sprintf('git tag %s', $tag); $shell->execute($command); // git push with tags $command = 'git push origin master --tags'; } else { // git push $command = 'git push'; } $shell->execute($command); }
protected function execute(array $arguments = array(), array $options = array()) { $interactiveMode = isset($options['interactive']) ? true : false; $forceMode = isset($options['force']) ? true : false; $message = $arguments["message"]; $buildMessage = "Update build version"; $repositoryType = nbConfig::get('project_repository_type', 'git'); if (nbConfig::has('project_repository_root-directory')) { $projectRootDir = nbConfig::get('project_repository_root-directory'); } else { throw new Exception('You must configure your project root directory'); } $buildVersionFile = $projectRootDir . "/version.yml"; if (nbConfig::has('project_repository') and $repositoryType == 'git') { $shell = new nbShell(); $this->logLine(sprintf('Starting repository commit for project %', nbConfig::get('project_name'))); // git add <project root dir> $this->logLine(sprintf('adding working dir %s to stage', $projectRootDir)); $cmd = sprintf('git add %s', $projectRootDir); $code = $shell->execute($cmd); if ($code == 0 and !$this->askConfirmation(sprintf('Error in "%s", do you want to continue anyway?', $cmd))) { $this->logLine('Bye'); die; } // git status $this->logLine('git status'); $cmd = sprintf('git status', $projectRootDir); $code = $shell->execute($cmd); // git commit -m "<commit message>" if ($interactiveMode and !$this->askConfirmation("Do you want to commit your changes to your local repository?")) { $this->logLine('Bye'); die; } $this->logLine(sprintf('commiting working dir %s to local repository', $projectRootDir)); $cmd = sprintf('git commit -m "%s"', $message); $code = $shell->execute($cmd); // git pull if ($interactiveMode and !$this->askConfirmation("Do you want to update from your remote repository?")) { $this->logLine('Bye'); die; } $this->logLine('updating local repository with remote changes'); $cmd = 'git pull'; $code = $shell->execute($cmd); if ($code == 0) { $this->logLine('git pull failed'); die; } // bee test:all if (!$interactiveMode or $interactiveMode and $this->askConfirmation("Do you want to test your project?")) { $this->logLine('executing nbTestAllCommand'); $cmd = new nbTestAllCommand(); $cmd->setApplication($this->getApplication()); $code = $cmd->run(new nbCommandLineParser(), ''); if ($code == 0 and !$interactiveMode and !$forceMode or $code == 0 and $interactiveMode and !$this->askConfirmation('There are some errors in your tests, do you want to continue anyway?')) { $this->logLine('Bye'); die; } } // commit repository updating build file if ($interactiveMode and !$this->askConfirmation("Do you want to commit your changes in the remote repository?")) { $this->logLine('Bye'); die; } // bee version:update-build <build version file> $cmd = new nbUpdateBuildVersionCommand(); $cmdLine = sprintf('%s', $buildVersionFile); $parser = new nbCommandLineParser(); $cmd->run($parser, $cmdLine); // git add <build version file> $this->logLine('adding build version file'); $cmd = sprintf('git add %s', $buildVersionFile); $code = $shell->execute($cmd); if ($code == 0 and !$this->askConfirmation(sprintf('Error in "%s", do you want to continue anyway?', $cmd))) { $this->logLine('Bye'); die; } // git commit -m "<commit build message>" $this->logLine('updating local repository with remote changes'); $cmd = sprintf('git commit -m "%s"', $buildMessage); $code = $shell->execute($cmd); if ($code == 0 and !$this->askConfirmation(sprintf('Error in "%s", do you want to continue anyway?', $cmd))) { $this->logLine('Bye'); die; } // git push $this->logLine('merging remote repository with local repository'); $cmd = 'git push'; $code = $shell->execute($cmd); if ($code == 0) { $this->logLine('Push error'); die; } $this->logLine('Repository commit executed succesfully'); } }
public function executeShellCommand($command, $doit = true) { $shell = new nbShell(); if (!$shell->execute($command, $doit)) { throw new Exception(sprintf('Command "%s" exited with error: %s', $command, $shell->getReturnCode())); } return $shell->getOutput(); }