/**
  * Return a filestore suitable for saving this file.
  * This filestore is either a pre-registered filestore,
  * a filestore as recorded in metadata or the system default.
  *
  * @return ElggFilestore
  */
 protected function getFilestore()
 {
     // Short circuit if already set.
     if ($this->filestore) {
         return $this->filestore;
     }
     // ask for entity specific filestore
     // saved as filestore::className in metadata.
     // need to get all filestore::* metadata because the rest are "parameters" that
     // get passed to filestore::setParameters()
     if ($this->guid) {
         $db_prefix = elgg_get_config('dbprefix');
         $options = array('guid' => $this->guid, 'where' => array("n.string LIKE 'filestore::%'"));
         $mds = elgg_get_metadata($options);
         $parameters = array();
         foreach ($mds as $md) {
             list($foo, $name) = explode("::", $md->name);
             if ($name == 'filestore') {
                 $filestore = $md->value;
             }
             $parameters[$name] = $md->value;
         }
     }
     // need to check if filestore is set because this entity is loaded in save()
     // before the filestore metadata is saved.
     if (isset($filestore)) {
         if (!class_exists($filestore)) {
             $msg = elgg_echo('ClassNotFoundException:NotFoundNotSavedWithFile', array($filestore, $this->guid));
             throw new ClassNotFoundException($msg);
         }
         $this->filestore = new $filestore();
         $this->filestore->setParameters($parameters);
     }
     // this means the entity hasn't been saved so fallback to default
     if (!$this->filestore) {
         $this->filestore = get_default_filestore();
     }
     return $this->filestore;
 }
Пример #2
0
 /**
  * Return a filestore suitable for saving this file.
  * This filestore is either a pre-registered filestore,
  * a filestore as recorded in metadata or the system default.
  *
  * @return \ElggFilestore
  *
  * @throws ClassNotFoundException
  */
 protected function getFilestore()
 {
     // Short circuit if already set.
     if ($this->filestore) {
         return $this->filestore;
     }
     // ask for entity specific filestore
     // saved as filestore::className in metadata.
     // need to get all filestore::* metadata because the rest are "parameters" that
     // get passed to filestore::setParameters()
     if ($this->guid) {
         $options = array('guid' => $this->guid, 'where' => array("n.string LIKE 'filestore::%'"));
         $mds = elgg_get_metadata($options);
         $parameters = array();
         foreach ($mds as $md) {
             list(, $name) = explode("::", $md->name);
             if ($name == 'filestore') {
                 $filestore = $md->value;
             }
             $parameters[$name] = $md->value;
         }
     }
     // need to check if filestore is set because this entity is loaded in save()
     // before the filestore metadata is saved.
     if (isset($filestore)) {
         if (!class_exists($filestore)) {
             $msg = "Unable to load filestore class " . $filestore . " for file " . $this->guid;
             throw new \ClassNotFoundException($msg);
         }
         $this->filestore = new $filestore();
         $this->filestore->setParameters($parameters);
         // @todo explain why $parameters will always be set here (PhpStorm complains)
     }
     // this means the entity hasn't been saved so fallback to default
     if (!$this->filestore) {
         $this->filestore = get_default_filestore();
     }
     return $this->filestore;
 }
Пример #3
0
 /**
  * Return a filestore suitable for saving this file.
  * This filestore is either a pre-registered filestore, a filestore loaded from metatags saved
  * along side this file, or the system default.
  */
 protected function getFilestore()
 {
     // Short circuit if already set.
     if ($this->filestore) {
         return $this->filestore;
     }
     // If filestore meta set then retrieve filestore TODO: Better way of doing this?
     $metas = get_metadata_for_entity($this->guid);
     $parameters = array();
     if (is_array($metas)) {
         foreach ($metas as $meta) {
             if (strpos($meta->name, "filestore::") !== false) {
                 // Filestore parameter tag
                 $comp = explode("::", $meta->name);
                 $name = $comp[1];
                 $parameters[$name] = $meta->value;
             }
         }
     }
     // If parameters loaded then create new filestore
     if (count($parameters) != 0) {
         // Create new filestore object
         if (!isset($parameters['filestore']) || !class_exists($parameters['filestore'])) {
             throw new ClassNotFoundException(elgg_echo('ClassNotFoundException:NotFoundNotSavedWithFile'));
         }
         // if dir_root is not set, we use default filestore
         if (isset($parameters['dir_root'])) {
             $this->filestore = new $parameters['filestore']($parameters['dir_root']);
         }
     }
     // if still nothing then set filestore to default
     if (!$this->filestore) {
         $this->filestore = get_default_filestore();
     }
     return $this->filestore;
 }