/** * Copies a file. * * This method only copies the file if the origin file is newer than the target file. * * By default, if the target already exists, it is not overridden. * * @param string $originFile The original filename * @param string $targetFile The target filename * @param bool $override Whether to override an existing file or not * * @throws FileNotFoundException When originFile doesn't exist * * @return exit code */ public function copy($originFile, $targetFile, $override = false) { if (!$this->isFileExist($originFile)) { throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile); } $this->sshExec->run(strtr('mkdir -p %targetDir% && cp -R %override% %originFile% %targetFile%', ['%originFile%' => $originFile, '%targetDir%' => dirname($targetFile), '%targetFile%' => $targetFile, '%override%' => $override ? '' : '-n'])); if ($this->sshExec->getLastReturnStatus() !== 0) { !$this->logger ?: $this->logger->error(sprintf('Error copy %s to %s', $originFile, $targetFile)); } return $this->sshExec->getLastReturnStatus(); }
/** * Runs symfony console using ssh . * * @param string $symfonyConsolePath * @param string $commandAndOptions Command name and options * @param OutputInterface|null $output * * @return string */ public function run($symfonyConsolePath, $commandNameAndOptions, $env, OutputInterface $output = null, $verbosityMin = OutputInterface::VERBOSITY_VERY_VERBOSE) { $verbosityOption = $output ? $this->getVerbosityOption($output->getVerbosity()) : ''; $commandLine = strtr('php %symfony_console_path% %command_name_and_options% --env=%env% %verbosity_option%', ['%symfony_console_path%' => $symfonyConsolePath, '%command_name_and_options%' => $commandNameAndOptions, '%env%' => $env, '%verbosity_option%' => $verbosityOption]); return $this->sshExec->run($commandLine, $output, $verbosityMin); }