示例#1
0
 /**
  * @param string $target
  * @param Version $version
  *
  * @return ExecuteResult
  */
 public function execute($target, Version $version)
 {
     $filesystem = new Filesystem();
     if ($this->io && !$this->io->isVerbose()) {
         $this->output(sprintf('Removing: <comment>0%%</comment>'));
     }
     $collection = new FileCollection($this->cwd);
     if (!$this->options['files'] && $this->options['exclude']) {
         $collection->add('*');
     }
     foreach ($this->options['files'] as $file) {
         $collection->add($file);
     }
     foreach ($this->options['exclude'] as $file) {
         $collection->remove($file);
     }
     $files = $collection->toArray();
     $total = count($files);
     $i = 0;
     foreach ($files as $file) {
         $filename = sprintf('%s/%s', rtrim($this->cwd, DIRECTORY_SEPARATOR), $file);
         $filesystem->remove($filename);
         if ($this->io && !$this->io->isVerbose()) {
             $this->output(sprintf('Removing: <comment>%d%%</comment>', round(++$i * 100 / $total)));
         } else {
             $this->output(sprintf("Removed %s", $file));
         }
         // remove empty directories
         $this->removeEmptyDirectories($this->cwd, $file);
     }
     if ($this->io && !$this->io->isVerbose()) {
         $this->output(sprintf('Removing: <comment>%d%%</comment>', 100));
     }
     return new ExecuteResult(array(), $files);
 }
示例#2
0
 public function execute(Context $context)
 {
     // this was filled by the builder
     $filesModified = $context->getFilesModified();
     $filesDeleted = $context->getFilesDeleted();
     if (false === $context->isFullDeploy()) {
         $diff = $this->repository->diff($context->getRemoteVersion(), $context->getVersion());
         $subselectionModified = new FileCollection($context->getBuilddir());
         foreach ($diff as $fileinfo) {
             if (Status::ADDED === $fileinfo->getStatus()) {
                 $subselectionModified[] = $fileinfo->getPathname();
             } elseif (Status::MODIFIED === $fileinfo->getStatus()) {
                 $subselectionModified[] = $fileinfo->getPathname();
             } elseif (Status::DELETED === $fileinfo->getStatus()) {
                 $filesDeleted->add($fileinfo->getPathname(), true);
             } else {
                 // @todo handle other cases if they actually exist
             }
         }
         foreach ($this->derivedFiles as $derivable) {
             $source = $derivable['source'];
             $derived = $derivable['derived'];
             if ($subselectionModified->has($source)) {
                 $subselectionModified->add($derived);
             }
         }
         // only keep files that are changed
         $filesModified->intersect($subselectionModified);
         //            if (0 === count($filesAdded) && count($subselectionAdded) > 0) {
         //                // hmm.. so files have changed but nothing to deploy
         //                // it looks like we forgot to specify some derived files
         //                // @todo inform the user about this?
         //            }
         // @todo we could also check here if all files are accounted for (maybe
         //       some files were deleted and not told to us by setting it in
         //       the `removes` config?) in other words: file_exists on all files?
     } else {
         foreach ($this->derivedFiles as $derivable) {
             $source = $derivable['source'];
             $derived = $derivable['derived'];
             if ($filesModified->has($source)) {
                 $filesModified->add($derived);
             }
         }
     }
     // never upload the conveyor configuration!
     $filesModified->remove('conveyor.yml');
     // validate result, throw exception when we have nothing to deploy
     if (0 === count($filesModified) && 0 === count($filesDeleted)) {
         throw new EmptyChangesetException();
     }
     $context->setFilesModified($filesModified);
     $context->setFilesDeleted($filesDeleted);
 }