Beispiel #1
0
 /**
  * Updates a file
  *
  * @param  File         $file
  * @return FileRepository
  */
 public function update(File $file)
 {
     $event = new FileEvent($file);
     $this->eventDispatcher->dispatch(Events::FILE_BEFORE_UPDATE, $event);
     $this->resourceRepository->update($file->getResource());
     $this->backend->updateFile($file);
     $event = new FileEvent($file);
     $this->eventDispatcher->dispatch(Events::FILE_AFTER_UPDATE, $event);
     return $file;
 }
Beispiel #2
0
 /**
  * Handles impostor's resource
  *
  * @param File $file
  */
 private function handleImpostorResource(File $file)
 {
     $oldResource = $file->getResource();
     if ($oldResource->isExclusive()) {
         $retrieved = $this->storage->retrieve($oldResource);
         $resource = Resource::create();
         $resource->setDateCreated(new DateTime());
         $resource->setHash($oldResource->getHash());
         $resource->setSize($oldResource->getSize());
         $resource->setMimetype($oldResource->getMimetype());
         $this->resourceRepository->create($resource, $retrieved);
         $file->setResource($resource);
     }
 }
 /**
  * @param File $file
  * @param Version $version
  * @return array
  */
 protected function doCreateTemporaryVersion(File $file, Version $version)
 {
     $version = $this->ensureValidVersion($version);
     $retrieved = $this->storage->retrieve($file->getResource());
     $commandDefinitions = call_user_func_array($this->commandDefinitionsGetter, array($file, $version, $this));
     $helper = new ImageMagickHelper($retrieved, $this->tempFiles, $commandDefinitions);
     return array($version->toString(), $helper->execute());
 }
 /**
  * @see BackendAdapter::createFile
  */
 public function createFile(File $file, Folder $folder)
 {
     $id = $this->conn->getDatabasePlatform()->getName() == 'mysql' ? null : $this->conn->fetchColumn($this->conn->getDatabasePlatform()->getSequenceNextValSQL('xi_filelib_file_id_seq'));
     $this->conn->insert('xi_filelib_file', array('id' => $id, 'folder_id' => $folder->getId(), 'fileprofile' => $file->getProfile(), 'filename' => $file->getName(), 'date_created' => $file->getDateCreated()->format('Y-m-d H:i:s'), 'status' => $file->getStatus(), 'uuid' => $file->getUuid(), 'resource_id' => $file->getResource()->getId(), 'data' => json_encode($file->getdata()->toArray())));
     $id = $this->conn->getDatabasePlatform()->getName() == 'mysql' ? $this->conn->lastInsertId() : $id;
     $file->setId($id);
     $file->setFolderId($folder->getId());
     return $file;
 }
 /**
  * @see BackendAdapter::createFile
  */
 public function createFile(File $file, Folder $folder)
 {
     $self = $this;
     return $this->em->transactional(function (EntityManager $em) use($self, $file, $folder) {
         $fileEntityName = $self->getFileEntityName();
         $entity = new $fileEntityName();
         $entity->setFolder($self->getFolderReference($folder->getId()));
         $entity->setName($file->getName());
         $entity->setProfile($file->getProfile());
         $entity->setDateCreated($file->getDateCreated());
         $entity->setStatus($file->getStatus());
         $entity->setUuid($file->getUuid());
         $entity->setData($file->getData()->toArray());
         $resource = $file->getResource();
         if ($resource) {
             $entity->setResource($em->getReference($self->getResourceEntityName(), $resource->getId()));
         }
         $em->persist($entity);
         $em->flush($entity);
         $file->setId($entity->getId());
         $file->setFolderId($entity->getFolder()->getId());
         return $file;
     });
 }
Beispiel #6
0
 /**
  * Returns the applicable storable for this plugin
  *
  * @param File $file
  * @return Versionable
  */
 public function getApplicableVersionable(File $file)
 {
     return $this->areSharedVersionsAllowed() ? $file->getResource() : $file;
 }
 /**
  * @see BackendAdapter::updateFile
  */
 public function updateFile(File $file)
 {
     $document = $file->toArray();
     $document['resource_id'] = $file->getResource()->getId();
     $document['date_created'] = $document['date_created']->format('Y-m-d H:i:s');
     unset($document['resource']);
     $this->update('files', $file->getId(), $document);
     return true;
 }
 /**
  * @see BackendAdapter::updateFile
  */
 public function updateFile(File $file)
 {
     $document = $file->toArray();
     $document['resource_id'] = $file->getResource()->getId();
     unset($document['id']);
     unset($document['resource']);
     $document['date_created'] = new MongoDate($document['date_created']->getTimestamp());
     $ret = $this->getMongo()->files->update(array('_id' => new MongoId($file->getId())), $document, array('w' => true));
     return (bool) $ret['n'];
 }
Beispiel #9
0
 /**
  * @param File $file
  * @param Version $version
  * @return array
  */
 protected function doCreateTemporaryVersion(File $file, Version $version)
 {
     $retrieved = $this->storage->retrieve($file->getResource());
     $versionVersion = $this->versions[$version->getVersion()];
     return array($version->toString(), $versionVersion->getHelper($retrieved, $this->tempFiles)->execute());
 }
Beispiel #10
0
 /**
  * @param  File             $file
  * @return array
  * @throws RuntimeException
  */
 protected function doCreateAllTemporaryVersions(File $file)
 {
     $retrieved = $this->storage->retrieve($file->getResource());
     $result = $this->getClient()->putObject(['Bucket' => $this->awsBucket, 'Key' => $file->getUuid(), 'SourceFile' => $retrieved]);
     $options = array("test" => false, "mock" => false, "input" => $result['ObjectURL'], "outputs" => $this->getOutputsToZencoder());
     try {
         $job = $this->getService()->jobs->create($options);
         $this->waitUntilJobFinished($job);
         $outputs = $this->fetchOutputs($job);
         $this->getClient()->deleteObject(array('Bucket' => $this->awsBucket, 'Key' => $file->getUuid()));
         return $outputs;
     } catch (Services_Zencoder_Exception $e) {
         throw new RuntimeException("Zencoder service responded with errors: " . $this->getZencoderErrors($e), 500, $e);
     }
 }
 protected function doCreateAllTemporaryVersions(File $file)
 {
     return array($this->identifier => $this->tempFiles->addFile($this->storage->retrieve($file->getResource())));
 }