Example #1
0
 /**
  * 
  * Uploads file to MogileFS, and populate model with
  * returned values (such as fid)
  * @param MogileFS_File $file
  * @throws Exception
  * @return MogileFS_File stored in MogileFS
  */
 public function save(File $file)
 {
     if (!$file->isValid()) {
         throw new Exception(__METHOD__ . ' Cannot save invalid file model', Exception::INVALID_ARGUMENT);
     }
     $file->setMapper($this);
     $this->getAdapter()->saveFile($file->getKey(), $file->getFile(false), $file->getClass(false));
     $storedFile = $this->find($file->getKey(), false);
     $storedFileArray = $storedFile->toArray();
     unset($storedFileArray['file']);
     // MogileFS has no information about local file
     $file->fromArray($storedFileArray);
     return $file;
 }