Exemplo n.º 1
0
 public function execute(InputInterface $i, OutputInterface $o)
 {
     $server = $i->getArgument('server');
     $set_revision = $i->getOption('set-revision');
     $show_log = (int) $i->getOption('log');
     if ($set_revision) {
         $revisions = Git::getRevisions();
         if (!in_array($set_revision, $revisions)) {
             $o->writeln('<error>Revision ' . $set_revision . ' is invalid</error>');
             return;
         }
     }
     $o->writeln('<info>Connecting to server: ' . $server . '</info>');
     $connection = $this->getBerk()->getFtpConnection($server);
     if ($set_revision) {
         $connection->setRevision($set_revision);
         $o->writeln('<info>Server revision updated: ' . $set_revision . '</info>');
         return;
     }
     if ($show_log) {
         $log = $connection->getLog();
         $log = array_slice($log, -$show_log);
         foreach ($log as $line) {
             $o->writeln($line);
         }
         return;
     }
     $revision_local = Git::getCurrentRevision();
     $revision_remote = $connection->getRevision();
     $o->writeln('<comment>Server revision: ' . $revision_remote . '</comment>');
     $o->writeln('<comment>Local revision: ' . $revision_local . '</comment>');
 }
Exemplo n.º 2
0
 public function execute(InputInterface $i, OutputInterface $o)
 {
     $server = $i->getArgument('server');
     $dry = $i->getOption('dry') === true;
     $all = $i->getOption('all') === true;
     $backup = $i->getOption('backup') === true;
     $uncommited = $all ? true : $i->getOption('uncommited') === true;
     $o->writeln('<info>Connecting to server: ' . $server . '</info>');
     $connection = $this->getBerk()->getFtpConnection($server);
     $revision_local = Git::getCurrentRevision();
     $revision_remote = $connection->getRevision();
     $revision_from = $all ? null : $revision_remote;
     $revision_to = $all ? null : $revision_local;
     $o->writeln('<comment>Server revision: ' . $revision_remote . '</comment>');
     $o->writeln('<comment>Local revision: ' . $revision_local . '</comment>');
     $files = $this->getFiles($revision_from, $revision_to, $uncommited);
     $modified = $removed = [];
     foreach ($files as $path) {
         if (is_file($path)) {
             $modified[] = $path;
         } else {
             $removed[] = $path;
         }
     }
     $count_modified = count($modified);
     $count_removed = count($removed);
     if ($dry) {
         $o->writeln('<info>Modified files: ' . $count_modified . '</info>');
         foreach ($modified as $path) {
             $o->writeln($path);
         }
         $o->writeln('<info>Removed files: ' . $count_removed . '</info>');
         foreach ($removed as $path) {
             $o->writeln($path);
         }
         return;
     }
     $working_dir = $this->getBerk()->getDirectory();
     if ($count_removed > 0) {
         $connection->log("[REV REMOVE][START] {$revision_remote} > {$revision_local} [{$count_removed}]");
         $this->processFiles('Removing obsolete files', $removed, function ($source) use($working_dir, $connection) {
             $target = str_replace($working_dir, '', $source);
             $target = ltrim($target, DIRECTORY_SEPARATOR);
             $connection->delete($target);
             return true;
         });
         $connection->log("[REV REMOVE][END] {$revision_remote} > {$revision_local}");
     }
     if ($count_modified > 0) {
         $connection->log("[REV UPLOAD][START] {$revision_remote} > {$revision_local} [{$count_modified}]");
         $result = $this->processFiles('Uploading modified files', $modified, function ($source) use($working_dir, $connection, $backup) {
             $target = str_replace($working_dir, '', $source);
             $target = ltrim($target, DIRECTORY_SEPARATOR);
             $connection->upload($source, $target, $backup);
             return true;
         });
         $connection->log("[REV UPLOAD][END] {$revision_remote} > {$revision_local}");
     }
     $connection->setRevision($revision_local);
 }