/** * Create the specified file. * I dont understand why this exists with the provided $file. Surely if we want to * create a file we should be calling the file's constructor or one of its static * creation methods? * @param FileInterface $file - the file to be created? * @param FolderInterface $parent - the parent folder to stick the file within. * * @return FileInterface */ public function createFile(FileInterface $file, FolderInterface $parent) { $filepath = $file->getPath() . '/' . $file->getName(); $gridFs = ConnectionHandler::getInstance()->getConnection(); $timeNow = time(); $mongoFolder = MongoFolder::loadFromFolderInterface($parent); $metadata = array('creation_time' => $file->getCreatedTime(), 'modification_time' => $file->getModifiedTime(), 'parent' => $mongoFolder->getMongoId(), 'type' => 'file'); # This is another hack where the getPath() method here is returning the path to the # file as it is locally stored in the linux filesystem, rather than the path of where # it will be stored withing the mongo based filesystem. $mongoId = $gridFs->storeFile($file->getPath(), $metadata); $mongoFile = MongoFile::loadFromMongoId($mongoId); return $mongoFile; }
/** * @param FileInterface $file * @return FileInterface * @throws \Exception */ public function updateFileInDb(FileInterface $file) { /** * @var $file File */ $update = $this->pdo->prepare('UPDATE files SET name = :name, size = :size, modified_time = :modified_time, path = :path, folder_id = :folder_id WHERE id = :id'); $modified_time = $file->getModifiedTime() ? $file->getModifiedTime()->format('Y-m-d H:i:s') : null; try { $update->execute(array('name' => $file->getName(), 'size' => $file->getSize(), 'modified_time' => $modified_time, 'path' => $file->getPath(), 'folder_id' => $file->getParentFolder()->getId(), 'id' => $file->getId())); } catch (\Exception $ex) { throw new \Exception('Updating file failed'); } return $file; }