diff --git a/Mage/Task/BuiltIn/Filesystem/CopyTask.php b/Mage/Task/BuiltIn/Filesystem/CopyTask.php new file mode 100644 index 0000000..b69d967 --- /dev/null +++ b/Mage/Task/BuiltIn/Filesystem/CopyTask.php @@ -0,0 +1,130 @@ + + */ +class CopyTask extends AbstractTask +{ + /** + * The source of the file/folder including full path to it. + * + * If the stage is on local host you should give full paths. If on remote + * you may give full or relative to the current release directory paths. + * + * @var string + */ + private $source; + + /** + * The destination to which the file/folder should copied to including full path to it. + * + * If the stage is on local host you should give full paths. If on remote + * you may give full or relative to the current release directory paths. + * + * @var string + */ + private $destination; + + /** + * Initialize parameters. + * + * @throws RequiredConfigNotFoundException + */ + public function init() + { + parent::init(); + + if (!$this->getParameter('destination')) { + throw new RequiredConfigNotFoundException('Missing required source.'); + } + + $this->setDestination($this->getParameter('destination')); + + if (!$this->getParameter('source')) { + throw new RequiredConfigNotFoundException('Missing required destination.'); + } + + $this->setSource($this->getParameter('source')); + } + + /** + * @return string + */ + public function getName() + { + return "Copying files [built-in]"; + } + + /** + * @return boolean + */ + public function run() + { + $command = 'cp -r ' . $this->getAbsolutPath($this->getSource()) . + ' ' . $this->getAbsolutPath($this->getDestination()); + + $result = $this->runCommand($command); + + return $result; + } + + /** + * @param string $path + * @return string + */ + public function getAbsolutPath($path) + { + if ($this->getStage() != 'pre-deploy' && $path[0] != '/' && $this->getConfig()->deployment('to')) { + $releasesDirectory = trim($this->getConfig()->release('directory', 'releases'), '/') . '/' . $this->getConfig()->getReleaseId(); + return rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory . '/' . ltrim($path, '/'); + } + + return $path; + } + + /** + * @return string + */ + public function getSource() + { + return $this->source; + } + + /** + * @param string $source + */ + public function setSource($source) + { + $this->source = $source; + } + + /** + * @return string + */ + public function getDestination() + { + return $this->destination; + } + + /** + * @param string $destination + */ + public function setDestination($destination) + { + $this->destination = $destination; + } + +}