Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Stark committed Feb 1, 2019
1 parent 143deb3 commit db61167
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 47 deletions.
29 changes: 15 additions & 14 deletions src/commands/SetupAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,34 +174,35 @@ protected function setupRemote(DeployConfig $config)
$app = $plugin->config->get()->app;

// Is copy deployed aready?
if ($plugin->ssh->exec("ls vendor/bin/craft-copy-installer.php | wc -l")) {
if ($plugin->ssh->exec("ls vendor/bin/craft-copy-import-db.php | wc -l")) {

// Yes. Existing setup? Try to pull DB.
// Yes. Existing setup?
if (trim($plugin->ssh->getOutput()) == "1") {

$this->head(
"Craft was detected on remote.",
"<comment>{$config}</comment> {$config->app}.frb.io"
);

$this->cmdBlock('php craft copy/db/down');
return (Craft::$app->runAction('copy/db/down') != 0) ? false : true;
$this->section('Do you need a copy of the remote?');
$this->line("craft copy/db/down" . PHP_EOL);
$this->line("craft copy/code/down" . PHP_EOL);

return true;
}

// Not installed
else {

// Try to deploy code
if ($this->confirm("The plugin is not installed with your App! Do you want to deploy now?", true)) {
$this->cmdBlock('copy/code/up');
if (Craft::$app->runAction('copy/code/up', ['interactive' => $this->interactive]) != 0) {
// failed
return false;
}
} else {

// Try to deploy code
if ($this->confirm("The plugin is not installed with your App! Do you want to deploy now?", true)) {
$this->cmdBlock('copy/code/up');
if (Craft::$app->runAction('copy/code/up', ['interactive' => $this->interactive]) != 0) {
// failed
return false;
}
} else {
// failed
return false;
}
}

Expand Down
33 changes: 0 additions & 33 deletions src/services/Ssh.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class Ssh extends Component

const DOWNLOAD_COMMAND = 'ssh {remote} "cat {src} | gzip" | zcat > {target}';

const IMPORT_DUMP_COMMAND = 'ssh {remote} \'mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -h "$MYSQL_HOST" "$APP_NAME" < {file} && echo 1\'';

const SSH_EXEC_TIMEOUT = 1200;

/**
Expand Down Expand Up @@ -118,27 +116,6 @@ public function download($src, $target)
}


/**
* Run 'mysql < file' on remote
*
* @param string $file
*
* @return bool
* @throws \fortrabbit\Copy\exceptions\RemoteException
*/
public function importMysql($file)
{
$process = new Process($this->getImportDumpCommand($file));
$process->setTimeout(self::SSH_EXEC_TIMEOUT);
$process->run();

if ($process->isSuccessful()) {
return true;
}

throw new RemoteException($process->getCommandLine() . PHP_EOL . $process->getErrorOutput());
}

/**
* Plugin check on remote
*
Expand Down Expand Up @@ -187,14 +164,4 @@ protected function getDownloadCommand(string $src, string $target)
return str_replace(array_keys($tokens), array_values($tokens), $cmd);
}

protected function getImportDumpCommand(string $file)
{
$cmd = self::IMPORT_DUMP_COMMAND;
$tokens = [
'{file}' => $file,
'{remote}' => $this->remote,
];

return str_replace(array_keys($tokens), array_values($tokens), $cmd);
}
}

0 comments on commit db61167

Please sign in to comment.