mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-07 15:54:26 +02:00
Fix 10 PHPStan errors
This commit is contained in:
parent
9ea4f591c7
commit
7ce6afd151
9 changed files with 122 additions and 167 deletions
|
@ -24,7 +24,7 @@ class BaseCollection extends \ArrayIterator
|
|||
* @param BaseEntity[] $entities
|
||||
* @param int|null $totalCount
|
||||
*/
|
||||
public function __construct(array $entities = [], int $totalCount = null)
|
||||
public function __construct(array $entities = [], ?int $totalCount = null)
|
||||
{
|
||||
parent::__construct($entities);
|
||||
|
||||
|
@ -102,7 +102,7 @@ class BaseCollection extends \ArrayIterator
|
|||
* @return BaseCollection
|
||||
* @see array_filter()
|
||||
*/
|
||||
public function filter(callable $callback = null, int $flag = 0): BaseCollection
|
||||
public function filter(?callable $callback = null, int $flag = 0): BaseCollection
|
||||
{
|
||||
$class = get_class($this);
|
||||
|
||||
|
@ -111,8 +111,6 @@ class BaseCollection extends \ArrayIterator
|
|||
|
||||
/**
|
||||
* Reverse the orders of the elements in the collection
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function reverse(): BaseCollection
|
||||
{
|
||||
|
@ -125,7 +123,6 @@ class BaseCollection extends \ArrayIterator
|
|||
* Split the collection in smaller collections no bigger than the provided length
|
||||
*
|
||||
* @param int $length
|
||||
* @return static[]
|
||||
*/
|
||||
public function chunk(int $length): array
|
||||
{
|
||||
|
@ -133,11 +130,14 @@ class BaseCollection extends \ArrayIterator
|
|||
throw new \RangeException('BaseCollection->chunk(): Size parameter expected to be greater than 0');
|
||||
}
|
||||
|
||||
return array_map(function ($array) {
|
||||
$class = get_class($this);
|
||||
return array_map(
|
||||
function ($array) {
|
||||
$class = get_class($this);
|
||||
|
||||
return new $class($array);
|
||||
}, array_chunk($this->getArrayCopy(), $length));
|
||||
return new $class($array);
|
||||
},
|
||||
array_chunk($this->getArrayCopy(), $length)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
namespace Friendica\Contact\FriendSuggest\Repository;
|
||||
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Contact\FriendSuggest\Collection;
|
||||
use Friendica\Contact\FriendSuggest\Collection\FriendSuggests as FriendSuggestsCollection;
|
||||
use Friendica\Contact\FriendSuggest\Entity\FriendSuggest as FriendSuggestEntity;
|
||||
use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException;
|
||||
use Friendica\Contact\FriendSuggest\Exception\FriendSuggestPersistenceException;
|
||||
use Friendica\Contact\FriendSuggest\Factory;
|
||||
use Friendica\Contact\FriendSuggest\Factory\FriendSuggest as FriendSuggestFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -20,12 +20,12 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
class FriendSuggest extends BaseRepository
|
||||
{
|
||||
/** @var Factory\FriendSuggest */
|
||||
/** @var FriendSuggestFactory */
|
||||
protected $factory;
|
||||
|
||||
protected static $table_name = 'fsuggest';
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\FriendSuggest $factory)
|
||||
public function __construct(Database $database, LoggerInterface $logger, FriendSuggestFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
}
|
||||
|
@ -49,20 +49,17 @@ class FriendSuggest extends BaseRepository
|
|||
*/
|
||||
private function selectOne(array $condition, array $params = []): FriendSuggestEntity
|
||||
{
|
||||
return parent::_selectOne($condition, $params);
|
||||
$fields = $this->_selectFirstRowAsArray( $condition, $params);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
*
|
||||
* @return Collection\FriendSuggests
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function select(array $condition, array $params = []): Collection\FriendSuggests
|
||||
private function select(array $condition, array $params = []): FriendSuggestsCollection
|
||||
{
|
||||
return new Collection\FriendSuggests(parent::_select($condition, $params)->getArrayCopy());
|
||||
return new FriendSuggestsCollection(parent::_select($condition, $params)->getArrayCopy());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,13 +75,9 @@ class FriendSuggest extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $cid
|
||||
*
|
||||
* @return Collection\FriendSuggests
|
||||
*
|
||||
* @throws FriendSuggestPersistenceException In case the underlying storage cannot select the suggestion
|
||||
*/
|
||||
public function selectForContact(int $cid): Collection\FriendSuggests
|
||||
public function selectForContact(int $cid): FriendSuggestsCollection
|
||||
{
|
||||
try {
|
||||
return $this->select(['cid' => $cid]);
|
||||
|
@ -114,13 +107,9 @@ class FriendSuggest extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Collection\FriendSuggests $fsuggests
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws FriendSuggestNotFoundException in case the underlying storage cannot delete the suggestion
|
||||
*/
|
||||
public function delete(Collection\FriendSuggests $fsuggests): bool
|
||||
public function delete(FriendSuggestsCollection $fsuggests): bool
|
||||
{
|
||||
try {
|
||||
$ids = $fsuggests->column('id');
|
||||
|
|
|
@ -10,9 +10,9 @@ namespace Friendica\Contact\Introduction\Repository;
|
|||
use Friendica\BaseRepository;
|
||||
use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
|
||||
use Friendica\Contact\Introduction\Exception\IntroductionPersistenceException;
|
||||
use Friendica\Contact\Introduction\Collection;
|
||||
use Friendica\Contact\Introduction\Entity;
|
||||
use Friendica\Contact\Introduction\Factory;
|
||||
use Friendica\Contact\Introduction\Collection\Introductions as IntroductionsCollection;
|
||||
use Friendica\Contact\Introduction\Entity\Introduction as IntroductionEntity;
|
||||
use Friendica\Contact\Introduction\Factory\Introduction as IntroductionFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -20,37 +20,30 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
class Introduction extends BaseRepository
|
||||
{
|
||||
/** @var Factory\Introduction */
|
||||
/** @var IntroductionFactory */
|
||||
protected $factory;
|
||||
|
||||
protected static $table_name = 'intro';
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\Introduction $factory)
|
||||
public function __construct(Database $database, LoggerInterface $logger, IntroductionFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
*
|
||||
* @return Entity\Introduction
|
||||
*
|
||||
* @throws NotFoundException the underlying exception if there's no Introduction with the given conditions
|
||||
*/
|
||||
private function selectOne(array $condition, array $params = []): Entity\Introduction
|
||||
private function selectOne(array $condition, array $params = []): IntroductionEntity
|
||||
{
|
||||
return parent::_selectOne($condition, $params);
|
||||
$fields = $this->_selectFirstRowAsArray( $condition, $params);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given Introduction into a DB compatible row array
|
||||
*
|
||||
* @param Entity\Introduction $introduction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function convertToTableRow(Entity\Introduction $introduction): array
|
||||
protected function convertToTableRow(IntroductionEntity $introduction): array
|
||||
{
|
||||
return [
|
||||
'uid' => $introduction->uid,
|
||||
|
@ -65,14 +58,9 @@ class Introduction extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $uid
|
||||
*
|
||||
* @return Entity\Introduction
|
||||
*
|
||||
* @throws IntroductionNotFoundException in case there is no Introduction with this id
|
||||
*/
|
||||
public function selectOneById(int $id, int $uid): Entity\Introduction
|
||||
public function selectOneById(int $id, int $uid): IntroductionEntity
|
||||
{
|
||||
try {
|
||||
return $this->selectOne(['id' => $id, 'uid' => $uid]);
|
||||
|
@ -88,10 +76,8 @@ class Introduction extends BaseRepository
|
|||
* @param int|null $min_id
|
||||
* @param int|null $max_id
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection\Introductions
|
||||
*/
|
||||
public function selectForUser(int $uid, int $min_id = null, int $max_id = null, int $limit = self::LIMIT): Collection\Introductions
|
||||
public function selectForUser(int $uid, ?int $min_id = null, ?int $max_id = null, int $limit = self::LIMIT): IntroductionsCollection
|
||||
{
|
||||
try {
|
||||
$BaseCollection = parent::_selectByBoundaries(
|
||||
|
@ -102,19 +88,15 @@ class Introduction extends BaseRepository
|
|||
throw new IntroductionPersistenceException(sprintf('Cannot select Introductions for used %d', $uid), $e);
|
||||
}
|
||||
|
||||
return new Collection\Introductions($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
|
||||
return new IntroductionsCollection($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the introduction for a given contact
|
||||
*
|
||||
* @param int $cid
|
||||
*
|
||||
* @return Entity\Introduction
|
||||
*
|
||||
* @throws IntroductionNotFoundException in case there is not Introduction for this contact
|
||||
*/
|
||||
public function selectForContact(int $cid): Entity\Introduction
|
||||
public function selectForContact(int $cid): IntroductionEntity
|
||||
{
|
||||
try {
|
||||
return $this->selectOne(['contact-id' => $cid]);
|
||||
|
@ -150,13 +132,9 @@ class Introduction extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\Introduction $introduction
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws IntroductionPersistenceException in case the underlying storage cannot delete the Introduction
|
||||
*/
|
||||
public function delete(Entity\Introduction $introduction): bool
|
||||
public function delete(IntroductionEntity $introduction): bool
|
||||
{
|
||||
if (!$introduction->id) {
|
||||
return false;
|
||||
|
@ -170,13 +148,9 @@ class Introduction extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\Introduction $introduction
|
||||
*
|
||||
* @return Entity\Introduction
|
||||
*
|
||||
* @throws IntroductionPersistenceException In case the underlying storage cannot save the Introduction
|
||||
*/
|
||||
public function save(Entity\Introduction $introduction): Entity\Introduction
|
||||
public function save(IntroductionEntity $introduction): IntroductionEntity
|
||||
{
|
||||
try {
|
||||
$fields = $this->convertToTableRow($introduction);
|
||||
|
|
|
@ -7,59 +7,54 @@
|
|||
|
||||
namespace Friendica\Contact\LocalRelationship\Repository;
|
||||
|
||||
use Friendica\Contact\LocalRelationship\Entity;
|
||||
use Friendica\Contact\LocalRelationship\Exception;
|
||||
use Friendica\Contact\LocalRelationship\Factory;
|
||||
use Exception;
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Contact\LocalRelationship\Entity\LocalRelationship as LocalRelationshipEntity;
|
||||
use Friendica\Contact\LocalRelationship\Exception\LocalRelationshipPersistenceException;
|
||||
use Friendica\Contact\LocalRelationship\Factory\LocalRelationship as LocalRelationshipFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class LocalRelationship extends \Friendica\BaseRepository
|
||||
class LocalRelationship extends BaseRepository
|
||||
{
|
||||
protected static $table_name = 'user-contact';
|
||||
|
||||
/** @var Factory\LocalRelationship */
|
||||
/** @var LocalRelationshipFactory */
|
||||
protected $factory;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\LocalRelationship $factory)
|
||||
public function __construct(Database $database, LoggerInterface $logger, LocalRelationshipFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @param int $cid
|
||||
* @return Entity\LocalRelationship
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function selectForUserContact(int $uid, int $cid): Entity\LocalRelationship
|
||||
public function selectForUserContact(int $uid, int $cid): LocalRelationshipEntity
|
||||
{
|
||||
return $this->_selectOne(['uid' => $uid, 'cid' => $cid]);
|
||||
$fields = $this->_selectFirstRowAsArray( ['uid' => $uid, 'cid' => $cid]);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the existing local relationship between a user and a public contact or a default
|
||||
* relationship if it doesn't.
|
||||
*
|
||||
* @param int $uid
|
||||
* @param int $cid
|
||||
* @return Entity\LocalRelationship
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function getForUserContact(int $uid, int $cid): Entity\LocalRelationship
|
||||
public function getForUserContact(int $uid, int $cid): LocalRelationshipEntity
|
||||
{
|
||||
try {
|
||||
return $this->selectForUserContact($uid, $cid);
|
||||
} catch (HTTPException\NotFoundException $e) {
|
||||
} catch (NotFoundException $e) {
|
||||
return $this->factory->createFromTableRow(['uid' => $uid, 'cid' => $cid]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @param int $cid
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function existsForUserContact(int $uid, int $cid): bool
|
||||
{
|
||||
|
@ -68,12 +63,8 @@ class LocalRelationship extends \Friendica\BaseRepository
|
|||
|
||||
/**
|
||||
* Converts a given local relationship into a DB compatible row array
|
||||
*
|
||||
* @param Entity\LocalRelationship $localRelationship
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function convertToTableRow(Entity\LocalRelationship $localRelationship): array
|
||||
protected function convertToTableRow(LocalRelationshipEntity $localRelationship): array
|
||||
{
|
||||
return [
|
||||
'uid' => $localRelationship->userId,
|
||||
|
@ -97,13 +88,9 @@ class LocalRelationship extends \Friendica\BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\LocalRelationship $localRelationship
|
||||
*
|
||||
* @return Entity\LocalRelationship
|
||||
*
|
||||
* @throws Exception\LocalRelationshipPersistenceException In case the underlying storage cannot save the LocalRelationship
|
||||
* @throws LocalRelationshipPersistenceException In case the underlying storage cannot save the LocalRelationship
|
||||
*/
|
||||
public function save(Entity\LocalRelationship $localRelationship): Entity\LocalRelationship
|
||||
public function save(LocalRelationshipEntity $localRelationship): LocalRelationshipEntity
|
||||
{
|
||||
try {
|
||||
$fields = $this->convertToTableRow($localRelationship);
|
||||
|
@ -111,8 +98,8 @@ class LocalRelationship extends \Friendica\BaseRepository
|
|||
$this->db->insert(self::$table_name, $fields, Database::INSERT_UPDATE);
|
||||
|
||||
return $localRelationship;
|
||||
} catch (\Exception $exception) {
|
||||
throw new Exception\LocalRelationshipPersistenceException(sprintf('Cannot insert/update the local relationship %d for user %d', $localRelationship->contactId, $localRelationship->userId), $exception);
|
||||
} catch (Exception $exception) {
|
||||
throw new LocalRelationshipPersistenceException(sprintf('Cannot insert/update the local relationship %d for user %d', $localRelationship->contactId, $localRelationship->userId), $exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
namespace Friendica\Content\Conversation\Repository;
|
||||
|
||||
use Friendica\BaseCollection;
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Content\Conversation\Collection\UserDefinedChannels;
|
||||
use Friendica\Content\Conversation\Entity;
|
||||
use Friendica\Content\Conversation\Factory;
|
||||
use Friendica\Content\Conversation\Entity\UserDefinedChannel as UserDefinedChannelEntity;
|
||||
use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
|
@ -21,13 +21,16 @@ use Friendica\Model\User;
|
|||
use Friendica\Util\DateTimeFormat;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class UserDefinedChannel extends \Friendica\BaseRepository
|
||||
class UserDefinedChannel extends BaseRepository
|
||||
{
|
||||
protected static $table_name = 'channel';
|
||||
|
||||
/** @var UserDefinedChannelFactory */
|
||||
protected $factory;
|
||||
|
||||
private IManageConfigValues $config;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\UserDefinedChannel $factory, IManageConfigValues $config)
|
||||
public function __construct(Database $database, LoggerInterface $logger, UserDefinedChannelFactory $factory, IManageConfigValues $config)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
|
||||
|
@ -40,7 +43,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
* @return UserDefinedChannels
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function _select(array $condition, array $params = []): BaseCollection
|
||||
protected function _select(array $condition, array $params = []): UserDefinedChannels
|
||||
{
|
||||
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
|
||||
|
||||
|
@ -62,12 +65,13 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
*
|
||||
* @param int $id The id of the user defined channel
|
||||
* @param int $uid The user that this channel belongs to. (Not part of the primary key)
|
||||
* @return Entity\UserDefinedChannel
|
||||
* @throws \Friendica\Network\HTTPException\NotFoundException
|
||||
*/
|
||||
public function selectById(int $id, int $uid): Entity\UserDefinedChannel
|
||||
public function selectById(int $id, int $uid): UserDefinedChannelEntity
|
||||
{
|
||||
return $this->_selectOne(['id' => $id, 'uid' => $uid]);
|
||||
$fields = $this->_selectFirstRowAsArray( ['id' => $id, 'uid' => $uid]);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,7 +110,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
return $this->_select(['uid' => $uid]);
|
||||
}
|
||||
|
||||
public function save(Entity\UserDefinedChannel $Channel): Entity\UserDefinedChannel
|
||||
public function save(UserDefinedChannelEntity $Channel): UserDefinedChannelEntity
|
||||
{
|
||||
$fields = [
|
||||
'label' => $Channel->label,
|
||||
|
@ -210,7 +214,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
$disposableFullTextSearch = new DisposableFullTextSearch($this->db, $searchtext);
|
||||
|
||||
$filteredChannels = $this->select(['uid' => array_column($users, 'uid'), 'publish' => true, 'valid' => true])->filter(
|
||||
function (Entity\UserDefinedChannel $channel) use ($owner_id, $reshare_id, $language, $tags, $media_type, $disposableFullTextSearch, $searchtext) {
|
||||
function (UserDefinedChannelEntity $channel) use ($owner_id, $reshare_id, $language, $tags, $media_type, $disposableFullTextSearch, $searchtext) {
|
||||
static $uids = [];
|
||||
|
||||
// Filter out channels from already picked users
|
||||
|
|
|
@ -13,7 +13,6 @@ use Friendica\Util\Images;
|
|||
use Friendica\Util\Proxy;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
|
||||
/**
|
||||
* @property-read int $id
|
||||
* @property-read int $uriId
|
||||
|
@ -210,7 +209,7 @@ class PostMedia extends BaseEntity
|
|||
*
|
||||
* @param \GuzzleHttp\Psr7\Uri $preview
|
||||
* @param string $size
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function withPreview(\GuzzleHttp\Psr7\Uri $preview, string $size = ''): self
|
||||
{
|
||||
|
|
|
@ -9,8 +9,9 @@ namespace Friendica\Content\Post\Factory;
|
|||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Capabilities\ICanCreateFromTableRow;
|
||||
use Friendica\Content\Post\Entity;
|
||||
use Friendica\Network;
|
||||
use Friendica\Content\Post\Entity\PostMedia as PostMediaEntity;
|
||||
use Friendica\Network\Entity\MimeType as MimeTypeEntity;
|
||||
use Friendica\Network\Factory\MimeType as MimeTypeFactory;
|
||||
use Friendica\Util\Network as UtilNetwork;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -18,10 +19,10 @@ use stdClass;
|
|||
|
||||
class PostMedia extends BaseFactory implements ICanCreateFromTableRow
|
||||
{
|
||||
/** @var Network\Factory\MimeType */
|
||||
/** @var MimeTypeFactory */
|
||||
private $mimeTypeFactory;
|
||||
|
||||
public function __construct(Network\Factory\MimeType $mimeTypeFactory, LoggerInterface $logger)
|
||||
public function __construct(MimeTypeFactory $mimeTypeFactory, LoggerInterface $logger)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
|
@ -31,9 +32,9 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createFromTableRow(array $row)
|
||||
public function createFromTableRow(array $row): PostMediaEntity
|
||||
{
|
||||
return new Entity\PostMedia(
|
||||
return new PostMediaEntity(
|
||||
$row['uri-id'],
|
||||
UtilNetwork::createUriFromString($row['url']),
|
||||
$row['type'],
|
||||
|
@ -58,13 +59,13 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
|
|||
);
|
||||
}
|
||||
|
||||
public function createFromBlueskyImageEmbed(int $uriId, stdClass $image): Entity\PostMedia
|
||||
public function createFromBlueskyImageEmbed(int $uriId, stdClass $image): PostMediaEntity
|
||||
{
|
||||
return new Entity\PostMedia(
|
||||
return new PostMediaEntity(
|
||||
$uriId,
|
||||
new Uri($image->fullsize),
|
||||
Entity\PostMedia::TYPE_IMAGE,
|
||||
new Network\Entity\MimeType('unkn', 'unkn'),
|
||||
PostMediaEntity::TYPE_IMAGE,
|
||||
new MimeTypeEntity('unkn', 'unkn'),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
@ -77,13 +78,13 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
|
|||
}
|
||||
|
||||
|
||||
public function createFromBlueskyExternalEmbed(int $uriId, stdClass $external): Entity\PostMedia
|
||||
public function createFromBlueskyExternalEmbed(int $uriId, stdClass $external): PostMediaEntity
|
||||
{
|
||||
return new Entity\PostMedia(
|
||||
return new PostMediaEntity(
|
||||
$uriId,
|
||||
new Uri($external->uri),
|
||||
Entity\PostMedia::TYPE_HTML,
|
||||
new Network\Entity\MimeType('text', 'html'),
|
||||
PostMediaEntity::TYPE_HTML,
|
||||
new MimeTypeEntity('text', 'html'),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
|
|
@ -7,11 +7,10 @@
|
|||
|
||||
namespace Friendica\Content\Post\Repository;
|
||||
|
||||
use Friendica\BaseCollection;
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Content\Post\Collection;
|
||||
use Friendica\Content\Post\Entity;
|
||||
use Friendica\Content\Post\Factory;
|
||||
use Friendica\Content\Post\Collection\PostMedias as PostMediasCollection;
|
||||
use Friendica\Content\Post\Entity\PostMedia as PostMediaEntity;
|
||||
use Friendica\Content\Post\Factory\PostMedia as PostMediaFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -21,16 +20,19 @@ class PostMedia extends BaseRepository
|
|||
{
|
||||
protected static $table_name = 'post-media';
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\PostMedia $factory)
|
||||
/** @var PostMediaFactory */
|
||||
protected $factory;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, PostMediaFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
}
|
||||
|
||||
protected function _select(array $condition, array $params = []): BaseCollection
|
||||
protected function _select(array $condition, array $params = []): PostMediasCollection
|
||||
{
|
||||
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
|
||||
|
||||
$Entities = new Collection\PostMedias();
|
||||
$Entities = new PostMediasCollection();
|
||||
foreach ($rows as $fields) {
|
||||
try {
|
||||
$Entities[] = $this->factory->createFromTableRow($fields);
|
||||
|
@ -42,17 +44,19 @@ class PostMedia extends BaseRepository
|
|||
return $Entities;
|
||||
}
|
||||
|
||||
public function selectOneById(int $postMediaId): Entity\PostMedia
|
||||
public function selectOneById(int $postMediaId): PostMediaEntity
|
||||
{
|
||||
return $this->_selectOne(['id' => $postMediaId]);
|
||||
$fields = $this->_selectFirstRowAsArray( ['id' => $postMediaId]);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
public function selectByUriId(int $uriId): Collection\PostMedias
|
||||
public function selectByUriId(int $uriId): PostMediasCollection
|
||||
{
|
||||
return $this->_select(["`uri-id` = ? AND `type` != ?", $uriId, Post\Media::UNKNOWN]);
|
||||
}
|
||||
|
||||
public function save(Entity\PostMedia $PostMedia): Entity\PostMedia
|
||||
public function save(PostMediaEntity $PostMedia): PostMediaEntity
|
||||
{
|
||||
$fields = [
|
||||
'uri-id' => $PostMedia->uriId,
|
||||
|
@ -97,14 +101,14 @@ class PostMedia extends BaseRepository
|
|||
* @param int $uri_id URI id
|
||||
* @param array $links list of links that shouldn't be added
|
||||
* @param bool $has_media
|
||||
* @return Collection\PostMedias[] Three collections in "visual", "link" and "additional" keys
|
||||
* @return PostMediasCollection[] Three collections in "visual", "link" and "additional" keys
|
||||
*/
|
||||
public function splitAttachments(int $uri_id, array $links = [], bool $has_media = true): array
|
||||
{
|
||||
$attachments = [
|
||||
'visual' => new Collection\PostMedias(),
|
||||
'link' => new Collection\PostMedias(),
|
||||
'additional' => new Collection\PostMedias(),
|
||||
'visual' => new PostMediasCollection(),
|
||||
'link' => new PostMediasCollection(),
|
||||
'additional' => new PostMediasCollection(),
|
||||
];
|
||||
|
||||
if (!$has_media) {
|
||||
|
@ -137,7 +141,7 @@ class PostMedia extends BaseRepository
|
|||
|
||||
// Currently these two types are ignored here.
|
||||
// Posts are added differently and contacts are not displayed as attachments.
|
||||
if (in_array($PostMedia->type, [Entity\PostMedia::TYPE_ACCOUNT, Entity\PostMedia::TYPE_ACTIVITY])) {
|
||||
if (in_array($PostMedia->type, [PostMediaEntity::TYPE_ACCOUNT, PostMediaEntity::TYPE_ACTIVITY])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -148,17 +152,17 @@ class PostMedia extends BaseRepository
|
|||
//$PostMedia->filetype = $filetype;
|
||||
//$PostMedia->subtype = $subtype;
|
||||
|
||||
if ($PostMedia->type == Entity\PostMedia::TYPE_HTML || ($PostMedia->mimetype->type == 'text' && $PostMedia->mimetype->subtype == 'html')) {
|
||||
if ($PostMedia->type == PostMediaEntity::TYPE_HTML || ($PostMedia->mimetype->type == 'text' && $PostMedia->mimetype->subtype == 'html')) {
|
||||
$attachments['link'][] = $PostMedia;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
in_array($PostMedia->type, [Entity\PostMedia::TYPE_AUDIO, Entity\PostMedia::TYPE_IMAGE, Entity\PostMedia::TYPE_HLS]) ||
|
||||
in_array($PostMedia->type, [PostMediaEntity::TYPE_AUDIO, PostMediaEntity::TYPE_IMAGE, PostMediaEntity::TYPE_HLS]) ||
|
||||
in_array($PostMedia->mimetype->type, ['audio', 'image'])
|
||||
) {
|
||||
$attachments['visual'][] = $PostMedia;
|
||||
} elseif (($PostMedia->type == Entity\PostMedia::TYPE_VIDEO) || ($PostMedia->mimetype->type == 'video')) {
|
||||
} elseif (($PostMedia->type == PostMediaEntity::TYPE_VIDEO) || ($PostMedia->mimetype->type == 'video')) {
|
||||
if (!empty($PostMedia->height)) {
|
||||
// Peertube videos are delivered in many different resolutions. We pick a moderate one.
|
||||
// Since only Peertube provides a "height" parameter, this wouldn't be executed
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
namespace Friendica\Core\Worker\Repository;
|
||||
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Core\Worker\Entity\Process as ProcessEntity;
|
||||
use Friendica\Core\Worker\Exception\ProcessPersistenceException;
|
||||
use Friendica\Core\Worker\Factory\Process as ProcessFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Core\Worker\Factory;
|
||||
use Friendica\Core\Worker\Entity;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
@ -24,13 +24,13 @@ class Process extends BaseRepository
|
|||
|
||||
protected static $table_name = 'process';
|
||||
|
||||
/** @var Factory\Process */
|
||||
/** @var ProcessFactory */
|
||||
protected $factory;
|
||||
|
||||
/** @var string */
|
||||
private $currentHost;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\Process $factory, array $server)
|
||||
public function __construct(Database $database, LoggerInterface $logger, ProcessFactory $factory, array $server)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
|
||||
|
@ -39,13 +39,8 @@ class Process extends BaseRepository
|
|||
|
||||
/**
|
||||
* Starts and Returns the process for a given PID at the current host
|
||||
*
|
||||
* @param int $pid
|
||||
* @param string $command
|
||||
*
|
||||
* @return Entity\Process
|
||||
*/
|
||||
public function create(int $pid, string $command): Entity\Process
|
||||
public function create(int $pid, string $command): ProcessEntity
|
||||
{
|
||||
// Cleanup inactive process
|
||||
$this->deleteInactive();
|
||||
|
@ -64,7 +59,9 @@ class Process extends BaseRepository
|
|||
}
|
||||
}
|
||||
|
||||
$result = $this->_selectOne(['pid' => $pid, 'hostname' => $this->currentHost]);
|
||||
$fields = $this->_selectFirstRowAsArray( ['pid' => $pid, 'hostname' => $this->currentHost]);
|
||||
|
||||
$result = $this->factory->createFromTableRow($fields);
|
||||
|
||||
$this->db->commit();
|
||||
|
||||
|
@ -74,7 +71,7 @@ class Process extends BaseRepository
|
|||
}
|
||||
}
|
||||
|
||||
public function delete(Entity\Process $process)
|
||||
public function delete(ProcessEntity $process)
|
||||
{
|
||||
try {
|
||||
if (!$this->db->delete(static::$table_name, [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue