2018-09-20 07:42:52 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Nextcloud - Social Support
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Maxence Lange <maxence@artificial-owl.com>
|
|
|
|
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-11-23 20:36:35 +00:00
|
|
|
|
2018-09-20 07:42:52 +00:00
|
|
|
namespace OCA\Social\Db;
|
|
|
|
|
|
|
|
|
2018-11-26 12:33:48 +00:00
|
|
|
use DateInterval;
|
|
|
|
use DateTime;
|
2018-09-20 07:42:52 +00:00
|
|
|
use Doctrine\DBAL\Query\QueryBuilder;
|
2018-11-26 12:33:48 +00:00
|
|
|
use Exception;
|
2018-11-14 12:04:33 +00:00
|
|
|
use OCA\Social\Exceptions\InvalidResourceException;
|
2018-11-23 20:36:35 +00:00
|
|
|
use OCA\Social\Model\ActivityPub\Document;
|
|
|
|
use OCA\Social\Model\ActivityPub\Image;
|
2018-11-14 12:04:33 +00:00
|
|
|
use OCA\Social\Model\ActivityPub\Person;
|
2018-09-20 07:42:52 +00:00
|
|
|
use OCA\Social\Service\ConfigService;
|
|
|
|
use OCA\Social\Service\MiscService;
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
2018-11-23 20:36:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CoreRequestBuilder
|
|
|
|
*
|
|
|
|
* @package OCA\Social\Db
|
|
|
|
*/
|
2018-09-20 07:42:52 +00:00
|
|
|
class CoreRequestBuilder {
|
|
|
|
|
2018-11-23 20:36:35 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
const TABLE_SERVER_ACTORS = 'social_server_actors';
|
|
|
|
const TABLE_SERVER_NOTES = 'social_server_notes';
|
2018-11-12 22:55:39 +00:00
|
|
|
const TABLE_SERVER_FOLLOWS = 'social_server_follows';
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
const TABLE_CACHE_ACTORS = 'social_cache_actors';
|
2018-11-23 20:36:35 +00:00
|
|
|
const TABLE_CACHE_DOCUMENTS = 'social_cache_documents';
|
2018-09-20 07:42:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** @var IDBConnection */
|
|
|
|
protected $dbConnection;
|
|
|
|
|
|
|
|
/** @var ConfigService */
|
|
|
|
protected $configService;
|
|
|
|
|
|
|
|
/** @var MiscService */
|
|
|
|
protected $miscService;
|
|
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
protected $defaultSelectAlias;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CoreRequestBuilder constructor.
|
|
|
|
*
|
|
|
|
* @param IDBConnection $connection
|
|
|
|
* @param ConfigService $configService
|
|
|
|
* @param MiscService $miscService
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
IDBConnection $connection, ConfigService $configService, MiscService $miscService
|
|
|
|
) {
|
|
|
|
$this->dbConnection = $connection;
|
|
|
|
$this->configService = $configService;
|
|
|
|
$this->miscService = $miscService;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Limit the request to the Id
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param int $id
|
|
|
|
*/
|
2018-11-12 22:55:39 +00:00
|
|
|
protected function limitToId(IQueryBuilder &$qb, int $id) {
|
2018-11-22 11:46:29 +00:00
|
|
|
$this->limitToDBFieldInt($qb, 'id', $id);
|
2018-11-12 22:55:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-11-22 11:46:29 +00:00
|
|
|
* Limit the request to the Id (string)
|
2018-11-12 22:55:39 +00:00
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $id
|
|
|
|
*/
|
|
|
|
protected function limitToIdString(IQueryBuilder &$qb, string $id) {
|
2018-09-20 07:42:52 +00:00
|
|
|
$this->limitToDBField($qb, 'id', $id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-11-22 11:46:29 +00:00
|
|
|
* Limit the request to the UserId
|
2018-09-20 07:42:52 +00:00
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $userId
|
|
|
|
*/
|
2018-11-22 11:46:29 +00:00
|
|
|
protected function limitToUserId(IQueryBuilder &$qb, string $userId) {
|
2018-09-20 07:42:52 +00:00
|
|
|
$this->limitToDBField($qb, 'user_id', $userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
/**
|
2018-11-22 11:46:29 +00:00
|
|
|
* Limit the request to the Preferred Username
|
2018-09-28 11:41:24 +00:00
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
2018-11-22 11:46:29 +00:00
|
|
|
* @param string $username
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
2018-11-22 11:46:29 +00:00
|
|
|
protected function limitToPreferredUsername(IQueryBuilder &$qb, string $username) {
|
|
|
|
$this->limitToDBField($qb, 'preferred_username', $username);
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 11:00:05 +00:00
|
|
|
/**
|
2018-11-22 11:46:29 +00:00
|
|
|
* search using username
|
2018-11-14 11:00:05 +00:00
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $username
|
|
|
|
*/
|
2018-11-22 11:46:29 +00:00
|
|
|
protected function searchInPreferredUsername(IQueryBuilder &$qb, string $username) {
|
2018-11-22 12:37:19 +00:00
|
|
|
$dbConn = $this->dbConnection;
|
|
|
|
$this->searchInDBField(
|
|
|
|
$qb, 'preferred_username', $dbConn->escapeLikeParameter($username) . '%'
|
|
|
|
);
|
2018-11-14 11:00:05 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
|
2018-11-24 14:15:26 +00:00
|
|
|
/**
|
|
|
|
* Limit the request to the ActorId
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
*/
|
|
|
|
protected function limitToPublic(IQueryBuilder &$qb) {
|
|
|
|
$this->limitToDBFieldInt($qb, 'public', 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-16 11:48:31 +00:00
|
|
|
/**
|
2018-11-21 19:22:09 +00:00
|
|
|
* Limit the request to the ActorId
|
2018-11-16 11:48:31 +00:00
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $actorId
|
2018-11-22 11:46:29 +00:00
|
|
|
* @param string $alias
|
2018-11-16 11:48:31 +00:00
|
|
|
*/
|
2018-11-22 11:46:29 +00:00
|
|
|
protected function limitToActorId(IQueryBuilder &$qb, string $actorId, string $alias = '') {
|
2018-11-22 12:21:47 +00:00
|
|
|
$this->limitToDBField($qb, 'actor_id', $actorId, true, $alias);
|
2018-11-16 11:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-21 19:22:09 +00:00
|
|
|
/**
|
|
|
|
* Limit the request to the FollowId
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $followId
|
|
|
|
*/
|
|
|
|
protected function limitToFollowId(IQueryBuilder &$qb, string $followId) {
|
|
|
|
$this->limitToDBField($qb, 'follow_id', $followId);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-16 11:48:31 +00:00
|
|
|
/**
|
|
|
|
* Limit the request to the ServiceId
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $objectId
|
|
|
|
*/
|
|
|
|
protected function limitToObjectId(IQueryBuilder &$qb, string $objectId) {
|
|
|
|
$this->limitToDBField($qb, 'object_id', $objectId);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-20 07:42:52 +00:00
|
|
|
/**
|
|
|
|
* Limit the request to the account
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $account
|
|
|
|
*/
|
|
|
|
protected function limitToAccount(IQueryBuilder &$qb, string $account) {
|
2018-11-22 04:38:29 +00:00
|
|
|
$this->limitToDBField($qb, 'account', $account, false);
|
2018-09-20 07:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-14 11:00:05 +00:00
|
|
|
/**
|
|
|
|
* Limit the request to the account
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $account
|
|
|
|
*/
|
|
|
|
protected function searchInAccount(IQueryBuilder &$qb, string $account) {
|
2018-11-22 12:37:19 +00:00
|
|
|
$dbConn = $this->dbConnection;
|
|
|
|
$this->searchInDBField($qb, 'account', $dbConn->escapeLikeParameter($account) . '%');
|
2018-11-14 11:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-26 12:33:48 +00:00
|
|
|
/**
|
|
|
|
* Limit the request to the creation
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param int $delay
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
protected function limitToCreation(IQueryBuilder &$qb, int $delay = 0) {
|
|
|
|
$date = new DateTime('now');
|
|
|
|
$date->sub(new DateInterval('PT' . $delay . 'M'));
|
|
|
|
|
|
|
|
$this->limitToDBFieldDateTime($qb, 'creation', $date);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Limit the request to the creation
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param int $delay
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
protected function limitToCaching(IQueryBuilder &$qb, int $delay = 0) {
|
|
|
|
$date = new DateTime('now');
|
|
|
|
$date->sub(new DateInterval('PT' . $delay . 'M'));
|
|
|
|
|
|
|
|
$this->limitToDBFieldDateTime($qb, 'caching', $date);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
/**
|
|
|
|
* Limit the request to the url
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $url
|
|
|
|
*/
|
|
|
|
protected function limitToUrl(IQueryBuilder &$qb, string $url) {
|
|
|
|
$this->limitToDBField($qb, 'url', $url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-20 07:42:52 +00:00
|
|
|
/**
|
|
|
|
* Limit the request to the status
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $status
|
|
|
|
*/
|
|
|
|
protected function limitToStatus(IQueryBuilder &$qb, $status) {
|
|
|
|
$this->limitToDBField($qb, 'status', $status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Limit the request to the instance
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $address
|
|
|
|
*/
|
2018-11-22 11:46:29 +00:00
|
|
|
protected function limitToAddress(IQueryBuilder &$qb, string $address) {
|
2018-09-20 07:42:52 +00:00
|
|
|
$this->limitToDBField($qb, 'address', $address);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-22 11:46:29 +00:00
|
|
|
/**
|
|
|
|
* Limit the request to the instance
|
|
|
|
*
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param bool $local
|
|
|
|
*/
|
|
|
|
protected function limitToLocal(IQueryBuilder &$qb, bool $local) {
|
|
|
|
$this->limitToDBField($qb, 'local', ($local) ? '1' : '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-12 22:55:39 +00:00
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $recipient
|
|
|
|
*/
|
|
|
|
protected function limitToRecipient(IQueryBuilder &$qb, string $recipient) {
|
|
|
|
$expr = $qb->expr();
|
|
|
|
$orX = $expr->orX();
|
2018-11-22 12:37:19 +00:00
|
|
|
$dbConn = $this->dbConnection;
|
2018-11-12 22:55:39 +00:00
|
|
|
|
|
|
|
$orX->add($expr->eq('to', $qb->createNamedParameter($recipient)));
|
2018-11-22 12:37:19 +00:00
|
|
|
$orX->add(
|
|
|
|
$expr->like(
|
|
|
|
'to_array',
|
|
|
|
$qb->createNamedParameter('%"' . $dbConn->escapeLikeParameter($recipient) . '"%')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$orX->add(
|
|
|
|
$expr->like(
|
|
|
|
'cc',
|
|
|
|
$qb->createNamedParameter('%"' . $dbConn->escapeLikeParameter($recipient) . '"%')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$orX->add(
|
|
|
|
$expr->like(
|
|
|
|
'bcc',
|
|
|
|
$qb->createNamedParameter('%"' . $dbConn->escapeLikeParameter($recipient) . '"%')
|
|
|
|
)
|
|
|
|
);
|
2018-11-12 22:55:39 +00:00
|
|
|
|
|
|
|
$qb->andWhere($orX);
|
|
|
|
}
|
|
|
|
|
2018-11-22 11:46:29 +00:00
|
|
|
|
2018-09-20 07:42:52 +00:00
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
2018-11-14 12:04:33 +00:00
|
|
|
* @param int $since
|
|
|
|
* @param int $limit
|
2018-11-13 14:20:43 +00:00
|
|
|
*/
|
|
|
|
protected function limitPaginate(IQueryBuilder &$qb, int $since = 0, int $limit = 5) {
|
|
|
|
if ($since > 0) {
|
|
|
|
$expr = $qb->expr();
|
|
|
|
$dt = new \DateTime();
|
|
|
|
$dt->setTimestamp($since);
|
2018-11-14 11:06:51 +00:00
|
|
|
// TODO: Pagination should use published date, once we can properly query the db for that
|
2018-11-14 12:04:33 +00:00
|
|
|
$qb->andWhere(
|
|
|
|
$expr->lt(
|
2018-11-15 16:26:18 +00:00
|
|
|
$this->defaultSelectAlias . '.creation',
|
|
|
|
$qb->createNamedParameter($dt, IQueryBuilder::PARAM_DATE),
|
2018-11-14 12:04:33 +00:00
|
|
|
IQueryBuilder::PARAM_DATE
|
|
|
|
)
|
|
|
|
);
|
2018-11-13 14:20:43 +00:00
|
|
|
}
|
|
|
|
$qb->setMaxResults($limit);
|
|
|
|
$qb->orderBy('creation', 'desc');
|
|
|
|
}
|
|
|
|
|
2018-11-22 11:46:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $field
|
|
|
|
* @param string $value
|
|
|
|
* @param bool $cs - case sensitive
|
2018-11-22 12:21:47 +00:00
|
|
|
* @param string $alias
|
2018-11-22 11:46:29 +00:00
|
|
|
*/
|
2018-11-26 12:33:48 +00:00
|
|
|
protected function limitToDBField(
|
2018-11-22 12:21:47 +00:00
|
|
|
IQueryBuilder &$qb, string $field, string $value, bool $cs = true, string $alias = ''
|
2018-11-22 11:46:29 +00:00
|
|
|
) {
|
|
|
|
$expr = $qb->expr();
|
2018-11-22 12:21:47 +00:00
|
|
|
|
|
|
|
$pf = '';
|
|
|
|
if ($qb->getType() === QueryBuilder::SELECT) {
|
|
|
|
$pf = (($alias === '') ? $this->defaultSelectAlias : $alias) . '.';
|
|
|
|
}
|
2018-11-22 11:46:29 +00:00
|
|
|
$field = $pf . $field;
|
|
|
|
|
|
|
|
if ($cs) {
|
|
|
|
$qb->andWhere($expr->eq($field, $qb->createNamedParameter($value)));
|
|
|
|
} else {
|
|
|
|
$func = $qb->func();
|
|
|
|
$qb->andWhere(
|
|
|
|
$expr->eq($func->lower($field), $func->lower($qb->createNamedParameter($value)))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $field
|
|
|
|
* @param int $value
|
|
|
|
*/
|
2018-11-26 12:33:48 +00:00
|
|
|
protected function limitToDBFieldInt(IQueryBuilder &$qb, string $field, int $value) {
|
2018-11-22 11:46:29 +00:00
|
|
|
$expr = $qb->expr();
|
|
|
|
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
|
|
|
$field = $pf . $field;
|
|
|
|
|
|
|
|
$qb->andWhere($expr->eq($field, $qb->createNamedParameter($value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-26 12:33:48 +00:00
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $field
|
|
|
|
*/
|
|
|
|
protected function limitToDBFieldEmpty(IQueryBuilder &$qb, string $field) {
|
|
|
|
$expr = $qb->expr();
|
|
|
|
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
|
|
|
$field = $pf . $field;
|
|
|
|
|
|
|
|
$qb->andWhere($expr->eq($field, $qb->createNamedParameter('')));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $field
|
|
|
|
* @param DateTime $date
|
|
|
|
*/
|
|
|
|
protected function limitToDBFieldDateTime(IQueryBuilder &$qb, string $field, DateTime $date) {
|
|
|
|
$expr = $qb->expr();
|
|
|
|
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
|
|
|
$field = $pf . $field;
|
|
|
|
|
|
|
|
$orX = $expr->orX();
|
|
|
|
$orX->add($expr->lte($field, $qb->createNamedParameter($date, IQueryBuilder::PARAM_DATE)));
|
|
|
|
$orX->add($expr->isNull($field));
|
|
|
|
$qb->andWhere($orX);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-13 14:20:43 +00:00
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
2018-11-15 16:26:18 +00:00
|
|
|
* @param string $field
|
2018-11-22 11:46:29 +00:00
|
|
|
* @param array $values
|
2018-09-20 07:42:52 +00:00
|
|
|
*/
|
2018-11-26 12:33:48 +00:00
|
|
|
protected function limitToDBFieldArray(IQueryBuilder &$qb, string $field, array $values) {
|
2018-09-20 07:42:52 +00:00
|
|
|
$expr = $qb->expr();
|
|
|
|
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
|
|
|
$field = $pf . $field;
|
|
|
|
|
|
|
|
if (!is_array($values)) {
|
|
|
|
$values = [$values];
|
|
|
|
}
|
|
|
|
|
|
|
|
$orX = $expr->orX();
|
|
|
|
foreach ($values as $value) {
|
2018-11-22 11:46:29 +00:00
|
|
|
$orX->add($expr->eq($field, $qb->createNamedParameter($value)));
|
2018-09-20 07:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$qb->andWhere($orX);
|
|
|
|
}
|
|
|
|
|
2018-11-22 11:46:29 +00:00
|
|
|
|
2018-11-14 11:00:05 +00:00
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $field
|
|
|
|
* @param string $value
|
|
|
|
*/
|
2018-11-26 12:33:48 +00:00
|
|
|
protected function searchInDBField(IQueryBuilder &$qb, string $field, string $value) {
|
2018-11-14 11:00:05 +00:00
|
|
|
$expr = $qb->expr();
|
2018-11-22 12:37:19 +00:00
|
|
|
|
2018-11-14 11:00:05 +00:00
|
|
|
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
|
|
|
$field = $pf . $field;
|
|
|
|
|
2018-11-22 04:38:29 +00:00
|
|
|
$qb->andWhere($expr->iLike($field, $qb->createNamedParameter($value)));
|
2018-11-14 11:00:05 +00:00
|
|
|
}
|
2018-09-20 07:42:52 +00:00
|
|
|
|
2018-11-14 12:04:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $fieldActorId
|
|
|
|
*/
|
|
|
|
protected function leftJoinCacheActors(IQueryBuilder &$qb, string $fieldActorId) {
|
|
|
|
|
|
|
|
if ($qb->getType() !== QueryBuilder::SELECT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$expr = $qb->expr();
|
|
|
|
$pf = $this->defaultSelectAlias;
|
|
|
|
|
2018-10-01 12:14:23 +00:00
|
|
|
// /** @noinspection PhpMethodParametersCountMismatchInspection */
|
2018-11-14 12:04:33 +00:00
|
|
|
$qb->selectAlias('ca.id', 'cacheactor_id')
|
|
|
|
->selectAlias('ca.account', 'cacheactor_account')
|
|
|
|
->selectAlias('ca.following', 'cacheactor_following')
|
|
|
|
->selectAlias('ca.followers', 'cacheactor_followers')
|
|
|
|
->selectAlias('ca.inbox', 'cacheactor_inbox')
|
|
|
|
->selectAlias('ca.shared_inbox', 'cacheactor_shared_inbox')
|
|
|
|
->selectAlias('ca.outbox', 'cacheactor_outbox')
|
|
|
|
->selectAlias('ca.featured', 'cacheactor_featured')
|
|
|
|
->selectAlias('ca.url', 'cacheactor_url')
|
|
|
|
->selectAlias('ca.preferred_username', 'cacheactor_preferred_username')
|
|
|
|
->selectAlias('ca.name', 'cacheactor_name')
|
|
|
|
->selectAlias('ca.summary', 'cacheactor_summary')
|
|
|
|
->selectAlias('ca.public_key', 'cacheactor_public_key')
|
2018-11-15 16:26:18 +00:00
|
|
|
->selectAlias('ca.source', 'cacheactor_source')
|
2018-11-14 12:04:33 +00:00
|
|
|
->selectAlias('ca.creation', 'cacheactor_creation')
|
|
|
|
->leftJoin(
|
|
|
|
$this->defaultSelectAlias, CoreRequestBuilder::TABLE_CACHE_ACTORS, 'ca',
|
|
|
|
$expr->eq($pf . '.' . $fieldActorId, 'ca.id')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return Person
|
|
|
|
* @throws InvalidResourceException
|
|
|
|
*/
|
|
|
|
protected function parseCacheActorsLeftJoin(array $data): Person {
|
|
|
|
$new = [];
|
|
|
|
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if (substr($k, 0, 11) === 'cacheactor_') {
|
|
|
|
$new[substr($k, 11)] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$actor = new Person();
|
2018-11-23 20:36:35 +00:00
|
|
|
$actor->importFromDatabase($new);
|
2018-11-14 12:04:33 +00:00
|
|
|
|
2018-11-19 10:34:54 +00:00
|
|
|
if ($actor->getType() !== Person::TYPE) {
|
2018-11-14 12:04:33 +00:00
|
|
|
throw new InvalidResourceException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $actor;
|
|
|
|
}
|
2018-09-20 07:42:52 +00:00
|
|
|
|
2018-11-23 20:41:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IQueryBuilder $qb
|
|
|
|
* @param string $fieldDocumentId
|
|
|
|
*/
|
|
|
|
protected function leftJoinCacheDocuments(IQueryBuilder &$qb, string $fieldDocumentId) {
|
|
|
|
if ($qb->getType() !== QueryBuilder::SELECT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$expr = $qb->expr();
|
|
|
|
$pf = $this->defaultSelectAlias;
|
|
|
|
|
|
|
|
// /** @noinspection PhpMethodParametersCountMismatchInspection */
|
|
|
|
$qb->selectAlias('cd.id', 'cachedocument_id')
|
|
|
|
->selectAlias('cd.type', 'cachedocument_type')
|
|
|
|
->selectAlias('cd.mime_type', 'cachedocument_mime_type')
|
|
|
|
->selectAlias('cd.media_type', 'cachedocument_media_type')
|
|
|
|
->selectAlias('cd.url', 'cachedocument_url')
|
|
|
|
->selectAlias('cd.local_copy', 'cachedocument_local_copy')
|
|
|
|
->selectAlias('cd.caching', 'cachedocument_caching')
|
2018-11-25 12:50:12 +00:00
|
|
|
->selectAlias('cd.public', 'cachedocument_public')
|
|
|
|
->selectAlias('cd.error', 'cachedocument_error')
|
2018-11-23 20:41:46 +00:00
|
|
|
->selectAlias('ca.creation', 'cachedocument_creation')
|
|
|
|
->leftJoin(
|
|
|
|
$this->defaultSelectAlias, CoreRequestBuilder::TABLE_CACHE_DOCUMENTS, 'cd',
|
|
|
|
$expr->eq($pf . '.' . $fieldDocumentId, 'cd.id')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return Document
|
|
|
|
* @throws InvalidResourceException
|
|
|
|
*/
|
|
|
|
protected function parseCacheDocumentsLeftJoin(array $data): Document {
|
|
|
|
$new = [];
|
|
|
|
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if (substr($k, 0, 14) === 'cachedocument_') {
|
|
|
|
$new[substr($k, 14)] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$document = new Document();
|
|
|
|
|
|
|
|
$document->importFromDatabase($new);
|
|
|
|
|
|
|
|
if ($document->getType() !== Image::TYPE) {
|
|
|
|
throw new InvalidResourceException();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $document;
|
|
|
|
}
|
|
|
|
|
2018-09-20 07:42:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|