Beispiel #1
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);
 }
Beispiel #2
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>');
 }
Beispiel #3
0
 public function __construct()
 {
     parent::__construct(Berk::NAME, Berk::VERSION);
     $time = time();
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
         $output = $event->getOutput();
         $directory = Git::getWorkingDirectory();
         chdir($directory);
         $output->writeln('<info>Changed current directory to: ' . $directory . '</info>');
         $output->writeln('');
         $command = $event->getCommand();
         if ($command instanceof Command) {
             $command->setBerk(new Berk());
         }
     });
     $dispatcher->addListener(ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event) use($time) {
         $output = $event->getOutput();
         $time = time() - $time;
         $output->writeln('');
         $output->writeln('<info>Command completed in ' . $time . ' seconds. Bye.</info>');
     });
     $this->setDispatcher($dispatcher);
     $this->add(new ServerCommand());
     $this->add(new ExportCommand());
     $this->add(new DeployCommand());
 }
Beispiel #4
0
 protected function configure()
 {
     $this->setName('export');
     $this->addArgument('directory', InputArgument::OPTIONAL, 'Export root directory', Git::getWorkingPath(Berk::EXPORT_DIRECTORY));
     $this->addOption('from', 'f', InputOption::VALUE_REQUIRED, 'Export will start from this revision');
     $this->addOption('to', 't', InputOption::VALUE_REQUIRED, 'Export will end at this revision');
     $this->addOption('uncommited', 'u', InputOption::VALUE_NONE, 'Export will include uncommited files');
     $this->addOption('zip', 'z', InputOption::VALUE_NONE, 'Zip export');
 }