Esempio 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;
 }
Esempio n. 2
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task\Min
  */
 public function execute()
 {
     $info = '';
     $dir = \Deployer::applyGlobalParams($this->param('dir'));
     $finder = new Finder();
     $iterator = $finder->files();
     $overallDecrease = 0;
     foreach ($this->param('name') as $name) {
         $iterator->name(\Deployer::applyGlobalParams($name));
     }
     $files = $iterator->in($dir);
     foreach ($files as $file) {
         $fileName = str_replace('/', DIRECTORY_SEPARATOR, $file);
         list($decreasePrecent, $decreaseBytes) = $this->_min($fileName);
         $overallDecrease += $decreaseBytes;
         $info .= sprintf('%s file decreased at %01.2f%% (%s)', \Deployer::censor($fileName), $decreasePrecent, \Deployer::size($decreaseBytes)) . PHP_EOL;
     }
     $message = sprintf('%d files minifyed at %s', sizeof($files), \Deployer::size($overallDecrease));
     \Deployer::messageInfo($message);
     $info .= $message . PHP_EOL;
     if (!empty($info)) {
         return $this->info($info);
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     foreach (array('dir', 'result') as $param) {
         ${$param} = \Deployer::applyGlobalParams($this->param($param));
     }
     $content = '';
     $finder = new Finder();
     $iterator = $finder->files();
     $allFiles = 0;
     foreach ($this->param('names') as $name) {
         $files = $iterator->name(\Deployer::applyGlobalParams($name))->in($dir);
         foreach ($files as $file) {
             if ($this->param('debug')) {
                 $content .= PHP_EOL . sprintf('/* %s */', $file) . PHP_EOL;
             }
             $content .= file_get_contents($file) . PHP_EOL;
             if ($this->param('delete')) {
                 unlink($file);
             }
             $allFiles++;
         }
     }
     if (is_file($result)) {
         unlink($result);
     }
     file_put_contents($result, $content);
     $info = sprintf('%d files merged; result file size: %s', $allFiles, \Deployer::size(filesize($result)));
     \Deployer::messageInfo($info);
     return $this->info($info);
 }
Esempio n. 4
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $info = '';
     foreach ((array) $this->param('cmd') as $cmd) {
         $command = \Deployer::applyGlobalParams($cmd);
         $result = $result = shell_exec($command);
         $info .= '$ ' . $command . PHP_EOL . $result . PHP_EOL . PHP_EOL;
     }
     return $this->info($info);
 }
Esempio n. 5
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     foreach ($this->params() as $param => $value) {
         $this->_params[$param] = \Deployer::applyGlobalParams($value);
     }
     $ssh = new \Net_SSH2($this->param('host'), $this->param('port'));
     if (!$ssh->login($this->param('username'), $this->param('password'))) {
         throw new \Deployer\TaskException('Can\'t connect to remote host');
     }
     $scp = new \Net_SCP($ssh);
     $scp->put($this->param('dest'), file_get_contents($this->param('file')));
     $info = sprintf('Filesize: %d bytes', filesize($this->param('file')));
     return $this->info($info);
 }
Esempio n. 6
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $file = \Deployer::applyGlobalParams($this->param('file'));
     if (!is_file($file)) {
         throw new \Deployer\TaskException(sprintf('file "%s" not found', $file));
     }
     if (!is_readable($file)) {
         throw new \Deployer\TaskException(sprintf('file "%s" must be readable', $file));
     }
     if (!is_writable($file)) {
         throw new \Deployer\TaskException(sprintf('file "%s" must be writable', $file));
     }
     $contents = file_get_contents($file);
     file_put_contents($file, str_replace(':version', $this->_version(), $contents));
     return $this;
 }
Esempio n. 7
0
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $info = '';
     foreach ($this->params() as $param => $value) {
         $this->_params[$param] = \Deployer::applyGlobalParams($value);
     }
     $ssh = new \Net_SSH2($this->param('host'), $this->param('port'));
     if (!$ssh->login($this->param('username'), $this->param('password'))) {
         throw new \Deployer\TaskException('Can\'t connect to remote host');
     }
     foreach ((array) $this->param('cmd') as $cmd) {
         $command = 'cd ' . $this->param('directory') . ' && ' . $cmd;
         $command = \Deployer::applyGlobalParams($command);
         $result = $ssh->exec($command);
         $info .= '$ ' . $command . PHP_EOL . $result . PHP_EOL;
     }
     return $this->info($info);
 }
Esempio n. 8
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);
 }
Esempio n. 9
0
 /**
  * Sends report
  *
  * @return \Deployer'\Logger\Provider\Smtp
  */
 public function send()
 {
     $path = \Deployer::applyGlobalParams($this->param('path'));
     $path = str_replace('/', DIRECTORY_SEPARATOR, $path);
     try {
         if (is_file($path)) {
             unlink($path);
         }
         file_put_contents($path, $this->data());
         $report = sprintf('report file saved: %s', $path);
     } catch (\Exception $e) {
         throw new \Deployer\ReportProviderException($e->getMessage());
     }
     if (!empty($report)) {
         return $this->report($report);
     }
     return $this;
 }
Esempio n. 10
0
 /**
  * Sends report
  *
  * @return \Deployer'\Logger\Provider\Smtp
  */
 public function send()
 {
     foreach (array('host', 'port', 'encryption', 'username', 'password', 'subject', 'from') as $param) {
         $this->_params[$param] = \Deployer::applyGlobalParams($this->_params[$param]);
     }
     try {
         $transport = \Swift_SmtpTransport::newInstance($this->param('host'), $this->param('port'), $this->param('encryption'))->setUsername($this->param('username'))->setPassword($this->param('password'));
         $mailer = \Swift_Mailer::newInstance($transport);
         $message = \Swift_Message::newInstance()->setSubject($this->param('subject'))->setFrom($this->param('from'))->addPart($this->data(), $this->mime());
         foreach ($this->param('to') as $to) {
             $message->setTo(\Deployer::applyGlobalParams($to));
         }
         $report = sptintf('email sent to %d recipients: %s', sizeof($this->param('to')), implode(', ', $this->param('to')));
     } catch (\Exception $e) {
         throw new \Deployer\ReportProviderException($e->getMessage());
     }
     if (!$mailer->send($message)) {
         throw new \Deployer\ReportProviderException('mail not sent');
     }
     if (!empty($report)) {
         return $this->report($report);
     }
     return $this;
 }
Esempio n. 11
0
 /**
  * Processes path param value
  *
  * @param string $paramValue
  * @return string
  */
 protected function _processPathParam($paramValue)
 {
     return str_replace('/', DIRECTORY_SEPARATOR, \Deployer::applyGlobalParams($paramValue));
 }