Reworked File->getUrl to throw exception
In case you require a local URL and one can't be generated, throw FileNotStoredLocallyException(File $file)
This commit is contained in:
parent
4a3ed7d0ae
commit
f02d32b718
@ -529,12 +529,22 @@ class File extends Managed_DataObject
|
|||||||
return common_local_url('attachment', array('attachment'=>$this->getID()));
|
return common_local_url('attachment', array('attachment'=>$this->getID()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrl($prefer_local=true)
|
/**
|
||||||
|
* @param mixed $use_local true means require local, null means prefer local, false means use whatever is stored
|
||||||
|
*/
|
||||||
|
public function getUrl($use_local=null)
|
||||||
{
|
{
|
||||||
if ($prefer_local && !empty($this->filename)) {
|
if ($use_local !== false) {
|
||||||
|
if (is_string($this->filename) || !empty($this->filename)) {
|
||||||
// A locally stored file, so let's generate a URL for our instance.
|
// A locally stored file, so let's generate a URL for our instance.
|
||||||
return self::url($this->getFilename());
|
return self::url($this->getFilename());
|
||||||
}
|
}
|
||||||
|
if ($use_local) {
|
||||||
|
// if the file wasn't stored locally (has filename) and we require a local URL
|
||||||
|
throw new FileNotStoredLocallyException($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// No local filename available, return the URL we have stored
|
// No local filename available, return the URL we have stored
|
||||||
return $this->url;
|
return $this->url;
|
||||||
|
15
lib/filenotstoredlocallyexception.php
Normal file
15
lib/filenotstoredlocallyexception.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
|
|
||||||
|
class FileNotStoredLocallyException extends ServerException
|
||||||
|
{
|
||||||
|
public $file = null;
|
||||||
|
|
||||||
|
public function __construct(File $file)
|
||||||
|
{
|
||||||
|
$this->file = $file;
|
||||||
|
common_debug('Requested local URL for a file that is not stored locally with id=='._ve($this->file->getID()));
|
||||||
|
parent::__construct(_('Requested local URL for a file that is not stored locally.'));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user