/** * @see BackendAdapter::createFile */ public function createFile(File $file, Folder $folder) { $document = array('folder_id' => $folder->getId(), 'name' => $file->getName(), 'profile' => $file->getProfile(), 'status' => $file->getStatus(), 'date_created' => new MongoDate($file->getDateCreated()->getTimestamp()), 'uuid' => $file->getUuid(), 'resource_id' => $file->getResource()->getId(), 'data' => $file->getData()->toArray()); $this->getMongo()->files->ensureIndex(array('folder_id' => 1, 'name' => 1), array('unique' => true)); $this->getMongo()->files->insert($document, array('w' => true)); $file->setId((string) $document['_id']); $file->setFolderId($folder->getId()); return $file; }
/** * @see BackendAdapter::createFile */ public function createFile(File $file, Folder $folder) { $document = array('folder_id' => $folder->getId(), 'name' => $file->getName(), 'profile' => $file->getProfile(), 'status' => $file->getStatus(), 'date_created' => $file->getDateCreated()->format('Y-m-d H:i:s'), 'uuid' => $file->getUuid(), 'resource_id' => $file->getResource()->getId(), 'data' => $file->getData()->toArray()); $document['id'] = $this->createId(); $this->create('files', $document['id'], $document); $file->setId($document['id']); $file->setFolderId($folder->getId()); return $file; }
/** * Returns a link for a file * * @param File $file * @return string Link */ protected function getBaseLink(File $file) { $folder = $this->folderRepository->find($file->getFolderId()); $beautifurl = explode('/', $folder->getUrl()); $beautifurl = array_filter($beautifurl, function ($beautifurl) { return (bool) $beautifurl; }); $beautifurl = array_map(function ($fragment) { return $this->slugifier->slugify($fragment); }, $beautifurl); $beautifurl[] = $file->getName(); $beautifurl = implode(DIRECTORY_SEPARATOR, $beautifurl); return $beautifurl; }
/** * @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; }
/** * @param File $file * @return string */ public function getFileName(File $file) { return $file->getName(); }
/** * @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; }); }
/** * @param File $file * @return string */ protected function getFileName(File $file) { return $file->getName(); }
/** * Creates a file * * @param File $file * @param Folder $folder * @throws FilelibException If file could not be uploaded. */ public function createFile(File $file, Folder $folder) { $finder = new FileFinder(array('folder_id' => $folder->getId(), 'name' => $file->getName())); if ($this->findByFinder($finder)->count()) { throw new NonUniqueFileException(sprintf('A file with the name "%s" already exists in folder "%s"', $file->getName(), $folder->getName())); } return $this->resolveAdapter()->createFile($file, $folder); }