Ejemplo n.º 1
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $zipDir = \Deployer::applyGlobalParams($this->param('dir'));
     $zipFile = \Deployer::applyGlobalParams($this->param('file'));
     if (is_file($zipFile)) {
         unlink($zipFile);
     }
     if (!is_dir($zipDir)) {
         throw new \Deployer\TaskException('"dir" must be a valid directory');
     }
     $zip = new \ZipArchive();
     if (!$zip->open($zipFile, \ZIPARCHIVE::CREATE)) {
         throw new \Deployer\TaskException('can\'t create zip file');
     }
     $dirs = \Deployer::sortByDepth(\Deployer::dirs($zipDir, SORT_ASC));
     foreach ($dirs as $dir) {
         $newDir = $this->_localPath($zipDir, $dir);
         $zip->addEmptyDir($newDir);
     }
     $files = \Deployer::files($zipDir);
     foreach ($files as $file) {
         $newFile = $this->_localPath($zipDir, $file);
         $zip->addFile($file, $newFile);
     }
     $zip->close();
     if (is_file($zipFile)) {
         return $this->info(sprintf('file created; size: %s', \Deployer::size(filezize($zipFile))));
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $info = '';
     $dirsCopied = $filesCopied = 0;
     $realFrom = realpath($this->_processPathParam($this->param('from'))) . DIRECTORY_SEPARATOR;
     $realTo = $this->_processPathParam($this->param('to'));
     if (!file_exists($realFrom)) {
         \Deployer::criticalError(sprintf('"%s" not found.', $this->_processPathParam($this->param('from'))));
     }
     if (!file_exists($realTo) && $this->param('create')) {
         @mkdir($realTo);
         if (!is_dir($realTo)) {
             \Deployer::criticalError(sprintf('Something went wrong. Can not create directory "%s".', $this->_processPathParam($this->param('from'))));
         }
         $info .= sprintf('Directory "%s" created.', $realTo) . PHP_EOL;
     }
     if (is_file($realFrom)) {
         @copy($realFrom, $realTo);
         if (!is_file($realTo) || filesize($realFrom) != filesize($realTo)) {
             \Deployer::criticalError(sprintf('Can not copy "%s" => "%s".', $realFrom, $realTo));
         }
         $info .= sprintf('Copied "%s" => "$s".', $realFrom, $realTo) . PHP_EOL;
         $filesCopied = 1;
     } else {
         $files = \Deployer::files($realFrom, $this->param('names'), $this->param('notnames'), SORT_ASC);
         $dirs = \Deployer::dirs($realFrom, $this->param('names'), $this->param('notnames'), SORT_ASC);
         foreach ($dirs as $dir) {
             $destDir = str_replace($realFrom, $realTo, $dir);
             if (file_exists($destDir)) {
                 \Deployer::criticalError(sprintf('Can not copy dir "%s" => "%s". Destination directory exists.', $dir, $destDir));
             }
             @mkdir($destDir);
             if (!is_dir($destDir)) {
                 \Deployer::criticalError(sprintf('Something went wrong. Can not copy dir "%s" => "%s".', $dir, $destDir));
             }
             $info .= sprintf('Directory copied "%s" => "%s".', $dir, $destDir) . PHP_EOL;
         }
         foreach ($files as $file) {
             $destFile = str_replace($realFrom, $realTo, $file);
             if (file_exists($destFile)) {
                 \Deployer::criticalError(sprintf('Can not copy file "%s" => "%s". Destination file exists.', $file, $destFile));
             }
             @copy($file, $destFile);
             if (!is_file($destFile) || filesize($file) != filesize($destFile)) {
                 \Deployer::criticalError(sprintf('Something went wrong. Can not copy file "%s" => "%s".', $file, $destFile));
             }
             $info .= sprintf('File copied "%s" => "%s".', $file, $destFile) . PHP_EOL;
             $dirsCopied = sizeof($dirs);
             $filesCopied = sizeof($files);
         }
     }
     $message = sprintf('Copied %d dirs and %d files.', $dirsCopied, $filesCopied);
     \Deployer::messageInfo($message);
     $info .= $message . PHP_EOL;
     if (!empty($info)) {
         return $this->info($info);
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $info = '';
     $realDir = $this->_processPathParam($this->param('dir'));
     if (!is_dir($realDir)) {
         if ($this->param('create')) {
             @mkdir($realDir);
             if (!is_dir($realDir)) {
                 \Deployer::criticalError(sprintf('Something went wrong. Can not create directory "%s".', $realDir));
             }
             $info = sprintf('Created directory %s.', $realDir);
             \Deployer::messageInfo($info);
             return $this->info($info . PHP_EOL);
         }
         \Deployer::criticalError(sprintf('"%s" is not a directory.', $realDir));
     }
     if (!is_writable($realDir)) {
         \Deployer::criticalError(sprintf('Directory "%s" must be writable.', $realDir));
     }
     $files = \Deployer::files($realDir, $this->param('names'), $this->param('notnames'), SORT_DESC);
     $dirs = \Deployer::dirs($realDir, $this->param('names'), $this->param('notnames'), SORT_DESC);
     foreach ($files as $file) {
         @unlink($file);
         if (is_file($file)) {
             \Deployer::criticalError(sprintf('Something went wrong. Can not delete file "%s".', $file));
         }
         $info .= sprintf('File "%s" deleted.', $file) . PHP_EOL;
     }
     foreach ($dirs as $dir) {
         @rmdir($dir);
         if (is_dir($dir)) {
             \Deployer::criticalError(sprintf('Something went wrong. Can not remove directory "%s".', $dir));
         }
         $info .= sprintf('Directory "%s" removed.', $dir) . PHP_EOL;
     }
     $dirsRemoved = sizeof($dirs);
     $filesRemoved = sizeof($files);
     if ($this->param('remove') && !$this->param('create')) {
         @rmdir($realDir);
         if (is_dir($realDir)) {
             \Deployer::criticalError(sprintf('Something went wrong. Can not remove directory "%s".', $file));
         }
         $info .= sprintf('Directory "%s" removed.', $realDir) . PHP_EOL;
         $dirsRemoved++;
     }
     $message = sprintf('Removed %d dirs and %d files.', $dirsRemoved, sizeof($files));
     \Deployer::messageInfo($message);
     $info .= $message . PHP_EOL;
     if (!empty($info)) {
         return $this->info($info);
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $dir = \Deployer::applyGlobalParams($this->param('dir'));
     $allFiles = 0;
     foreach ($this->param('names') as $name) {
         $files = \Deployer::files($dir, \Deployer::applyGlobalParams($name));
         foreach ($files as $file) {
             if (is_file($file)) {
                 $mask = str_replace('*', null, $name);
                 rename($file, str_replace($mask, null, $file));
                 $allFiles++;
             }
         }
     }
     $info = sprintf('%d files renamed', $allFiles);
     \Deployer::messageInfo($info);
     return $this->info($info);
 }