Пример #1
0
 /**
  * Convert a FolderInterface object into a MongoFolder object.
  * @param FolderInterface $folder
  * @return \MongoFolder
  */
 public static function loadFromFolderInterface(FolderInterface $folder)
 {
     $conditions = array();
     $conditions[] = array("path" => $folder->getPath());
     $conditions[] = array("name" => $folder->getName());
     $query = array('$and' => $conditions);
     /* @var $gridFsDoc MongoGridFsFile */
     $gridFs = ConnectionHandler::getInstance()->getConnection();
     $gridFsDoc = $gridFs->findOne($query);
     if ($gridFsDoc === null) {
         print "Failed to find mongo folder for provided folder interface." . PHP_EOL;
         print "path: " . $folder->getPath() . PHP_EOL;
         print "name: " . $folder->getName() . PHP_EOL;
         die;
     }
     /* @var $mongoId MongoId */
     $folderMongoId = $gridFsDoc->file["_id"];
     $name = $gridFsDoc->file['name'];
     $creationTime = $gridFsDoc->path['creation_time'];
     $mongoFolder = new MongoFolder($name, $creationTime);
     if (isset($gridFsDoc->file["parent"])) {
         $parent = MongoFolder::loadFromMongoId($gridFsDoc->file["parent"]);
         $mongoFolder->setParentFolder($parent);
     }
     $mongoFolder->mMongoId = $folderMongoId;
     $mongoFolder->mGridFsFile = $gridFsDoc;
     return $mongoFolder;
 }
Пример #2
0
 /**
  * Load this object from the provided document within the gridfs system.
  * @param MongoGridFSFile $doc - the doc that represents a file.
  * @return \MongoFile
  */
 public static function loadFromMongoDoc(MongoGridFSFile $doc)
 {
     $name = $doc->file['name'];
     $modificationTime = $doc->file['modification_time'];
     $creationTime = $doc->file['creation_time'];
     $parentFolder = MongoFolder::loadFromMongoId($doc->file['parent']);
     $mongoFile = new MongoFile($name, $parentFolder, $creationTime, $modificationTime, $doc);
     $mongoFile->mMongoId = $id;
     return $mongoFile;
 }
Пример #3
0
 /**
  * Create the root folder that has no parent or name, and its path is just /
  * I do not understand why this takes a FolderInterface as a parameter.
  * @param FolderInterface $folder - the folder we wish to have as the root.
  *
  * @return FolderInterface - the created folder.
  */
 public function createRootFolder(FolderInterface $folder)
 {
     $folder->setName("");
     $folder->setPath("/");
     $gridFs = ConnectionHandler::getInstance()->getConnection();
     $metadata = array('name' => $folder->getName(), 'path' => $folder->getPath(), 'creation_time' => $folder->getCreatedTime(), 'type' => 'folder');
     $mongoId = $gridFs->storeBytes("", $metadata);
     # folder is an empty file with metadata
     $mongoFolder = MongoFolder::loadFromMongoId($mongoId);
     return $mongoFolder;
 }
Пример #4
0
 /**
  * Fetch the parent folder that contains this object.
  * @return FolderInterface
  * @throws Exception - if there is no parent
  */
 public function getParentFolder()
 {
     $parentMongoId = $this->getMetadataField("parent");
     if ($parentMongoId !== null) {
         $mongoFolder = MongoFolder::loadFromMongoId($parentMongoId);
     } else {
         throw new Exception("Folder has no parent");
     }
     return $mongoFolder;
 }