X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FAttach.php;h=d65e67fe3e6a8c34adec09eb7ffca2091f8e7f2c;hb=6071fe81b410ec6a971d0e45379a51809cbeec71;hp=c74209d6a176bb7cb0c0e5e950bf0671654b27ca;hpb=3282ce53894b624893ee2989747a59866ab4b137;p=friendica.git diff --git a/src/Model/Attach.php b/src/Model/Attach.php index c74209d6a1..d65e67fe3e 100644 --- a/src/Model/Attach.php +++ b/src/Model/Attach.php @@ -7,13 +7,15 @@ namespace Friendica\Model; use Friendica\BaseObject; -use Friendica\Core\System; use Friendica\Core\StorageManager; +use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Database\DBStructure; -use Friendica\Util\Security; +use Friendica\Model\Storage\IStorage; +use Friendica\Object\Image; use Friendica\Util\DateTimeFormat; use Friendica\Util\Mimetype; +use Friendica\Util\Security; /** * Class to handle attach dabatase table @@ -29,7 +31,7 @@ class Attach extends BaseObject */ private static function getFields() { - $allfields = DBStructure::definition(false); + $allfields = DBStructure::definition(self::getApp()->getBasePath(), false); $fields = array_keys($allfields['attach']['fields']); array_splice($fields, array_search('data', $fields), 1); return $fields; @@ -50,7 +52,7 @@ class Attach extends BaseObject public static function select(array $fields = [], array $conditions = [], array $params = []) { if (empty($fields)) { - $selected = self::getFields(); + $fields = self::getFields(); } $r = DBA::select('attach', $fields, $conditions, $params); @@ -175,7 +177,7 @@ class Attach extends BaseObject * @return boolean/integer Row id on success, False on errors * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function store($data, $uid, $filename, $filetype = '' , $filesize = null, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') + public static function store($data, $uid, $filename, $filetype = '' , $filesize = null, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { if ($filetype === '') { $filetype = Mimetype::getContentType($filename); @@ -185,6 +187,7 @@ class Attach extends BaseObject $filesize = strlen($data); } + /** @var IStorage $backend_class */ $backend_class = StorageManager::getBackend(); $backend_ref = ''; if ($backend_class !== '') { @@ -232,7 +235,7 @@ class Attach extends BaseObject * @return boolean True on success * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function storeFile($src, $uid, $filename = '', $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') + public static function storeFile($src, $uid, $filename = '', $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { if ($filename === '') { $filename = basename($src); @@ -257,18 +260,19 @@ class Attach extends BaseObject * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @see \Friendica\Database\DBA::update */ - public static function update($fields, $conditions, $img = null, array $old_fields = []) + public static function update($fields, $conditions, Image $img = null, array $old_fields = []) { - if (!is_null($data)) { + if (!is_null($img)) { // get items to update $items = self::select(['backend-class','backend-ref'], $conditions); foreach($items as $item) { + /** @var IStorage $backend_class */ $backend_class = (string)$item['backend-class']; if ($backend_class !== '') { $fields['backend-ref'] = $backend_class::put($img->asString(), $item['backend-ref']); } else { - $fields['data'] = $data; + $fields['data'] = $img->asString(); } } } @@ -296,6 +300,7 @@ class Attach extends BaseObject $items = self::select(['backend-class','backend-ref'], $conditions); foreach($items as $item) { + /** @var IStorage $backend_class */ $backend_class = (string)$item['backend-class']; if ($backend_class !== '') { $backend_class::delete($item['backend-ref']);