<?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/>.
*
*/
namespace OCA\Social\Db;
use DateInterval;
use DateTime;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
use OCA\Social\AP;
use OCA\Social\Exceptions\DateTimeException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCA\Social\Model\ActivityPub\Object\Image;
use OCA\Social\Model\StreamAction;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/**
* Class CoreRequestBuilder
*
* @package OCA\Social\Db
*/
class CoreRequestBuilder {
// const TABLE_REQUEST_QUEUE = 'social_request_queue';
//
// const TABLE_SERVER_ACTORS = 'social_server_actors';
// const TABLE_SERVER_NOTES = 'social_server_notes';
// const TABLE_SERVER_HASHTAGS = 'social_server_hashtags';
// const TABLE_SERVER_FOLLOWS = 'social_server_follows';
//
// const TABLE_CACHE_ACTORS = 'social_cache_actors';
// const TABLE_CACHE_DOCUMENTS = 'social_cache_documents';
//
// const TABLE_QUEUE_STREAM = 'social_queue_stream';
// const TABLE_STREAM_ACTIONS = 'social_stream_actions';
const TABLE_REQUEST_QUEUE = 'social_a2_request_queue';
const TABLE_ACTORS = 'social_a2_actors';
const TABLE_STREAMS = 'social_a2_stream';
const TABLE_HASHTAGS = 'social_a2_hashtags';
const TABLE_FOLLOWS = 'social_a2_follows';
const TABLE_ACTIONS = 'social_a2_actions';
const TABLE_CACHE_ACTORS = 'social_a2_cache_actors';
const TABLE_CACHE_DOCUMENTS = 'social_a2_cache_documts';
const TABLE_STREAM_QUEUE = 'social_a2_stream_queue';
const TABLE_STREAM_ACTIONS = 'social_a2_stream_action';
/** @var IDBConnection */
protected $dbConnection;
/** @var ConfigService */
protected $configService;
/** @var MiscService */
protected $miscService;
/** @var string */
protected $defaultSelectAlias;
/** @var Person */
protected $viewer = null;
/**
* 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;
}
/**
* @param Person $viewer
*/
public function setViewer(Person $viewer) {
$this->viewer = $viewer;
}
/**
* @param IQueryBuilder $qb
* @param string $id
*/
public function generatePrimaryKey(IQueryBuilder $qb, string $id) {
$qb->setValue('id_prim', $qb->createNamedParameter(hash('sha512', $id)));
}
/**
* Limit the request to the Id
*
* @param IQueryBuilder $qb
* @param int $id
*/
protected function limitToId(IQueryBuilder &$qb, int $id) {
$this->limitToDBFieldInt($qb, 'id', $id);
}
/**
* Limit the request to the Id (string)
*
* @param IQueryBuilder $qb
* @param string $id
*/
protected function limitToIdString(IQueryBuilder &$qb, string $id) {
$this->limitToDBField($qb, 'id', $id, false);
}
/**
* Limit the request to the UserId
*
* @param IQueryBuilder $qb
* @param string $userId
*/
protected function limitToUserId(IQueryBuilder &$qb, string $userId) {
$this->limitToDBField($qb, 'user_id', $userId, false);
}
/**
* Limit the request to the ActivityId
*
* @param IQueryBuilder $qb
* @param string $activityId
*/
protected function limitToActivityId(IQueryBuilder &$qb, string $activityId) {
$this->limitToDBField($qb, 'activity_id', $activityId, false);
}
/**
* Limit the request to