2018-09-28 11:41:24 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-09-08 13:46:22 +00:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Db;
|
|
|
|
|
2018-11-15 11:26:25 +00:00
|
|
|
use OCA\Social\Exceptions\SocialAppConfigException;
|
2018-12-13 09:40:27 +00:00
|
|
|
use OCA\Social\Model\ActivityPub\Actor\Person;
|
2023-05-25 20:45:28 +00:00
|
|
|
use OCA\Social\Tools\Traits\TArrayTools;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
class ActorsRequestBuilder extends CoreRequestBuilder {
|
|
|
|
use TArrayTools;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base of the Sql Insert request
|
|
|
|
*
|
2022-12-03 16:55:34 +00:00
|
|
|
* @return SocialQueryBuilder
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
2022-11-22 23:16:36 +00:00
|
|
|
protected function getActorsInsertSql(): SocialQueryBuilder {
|
|
|
|
$qb = $this->getQueryBuilder();
|
2019-05-07 15:11:04 +00:00
|
|
|
$qb->insert(self::TABLE_ACTORS);
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
return $qb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base of the Sql Update request
|
|
|
|
*
|
2022-12-03 16:55:34 +00:00
|
|
|
* @return SocialQueryBuilder
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
2022-11-22 23:16:36 +00:00
|
|
|
protected function getActorsUpdateSql(): SocialQueryBuilder {
|
|
|
|
$qb = $this->getQueryBuilder();
|
2019-05-07 15:11:04 +00:00
|
|
|
$qb->update(self::TABLE_ACTORS);
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
return $qb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base of the Sql Select request for Shares
|
|
|
|
*
|
2020-06-25 02:48:36 +00:00
|
|
|
* @return SocialQueryBuilder
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
2020-06-25 02:48:36 +00:00
|
|
|
protected function getActorsSelectSql(): SocialQueryBuilder {
|
|
|
|
$qb = $this->getQueryBuilder();
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
|
|
|
$qb->select(
|
2019-09-23 10:34:21 +00:00
|
|
|
'a.id', 'a.id_prim', 'a.user_id', 'a.preferred_username', 'a.name', 'a.summary',
|
2023-01-05 09:58:13 +00:00
|
|
|
'a.public_key', 'a.avatar_version', 'a.private_key', 'a.creation', 'a.deleted'
|
2018-09-28 11:41:24 +00:00
|
|
|
)
|
2024-10-28 12:53:06 +00:00
|
|
|
->from(self::TABLE_ACTORS, 'a');
|
2018-09-28 11:41:24 +00:00
|
|
|
|
2019-09-23 10:34:21 +00:00
|
|
|
$this->defaultSelectAlias = 'a';
|
2020-06-25 02:48:36 +00:00
|
|
|
$qb->setDefaultSelectAlias('a');
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
return $qb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base of the Sql Delete request
|
|
|
|
*
|
2022-12-03 16:55:34 +00:00
|
|
|
* @return SocialQueryBuilder
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
2022-11-22 23:16:36 +00:00
|
|
|
protected function getActorsDeleteSql(): SocialQueryBuilder {
|
|
|
|
$qb = $this->getQueryBuilder();
|
2019-05-07 15:11:04 +00:00
|
|
|
$qb->delete(self::TABLE_ACTORS);
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
return $qb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*
|
2018-11-12 22:55:39 +00:00
|
|
|
* @return Person
|
2018-11-15 11:26:25 +00:00
|
|
|
* @throws SocialAppConfigException
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
2020-06-18 19:40:57 +00:00
|
|
|
public function parseActorsSelectSql($data): Person {
|
2019-07-11 13:58:58 +00:00
|
|
|
$root = $this->configService->getSocialUrl();
|
2018-11-12 22:55:39 +00:00
|
|
|
|
|
|
|
$actor = new Person();
|
2018-11-23 20:36:35 +00:00
|
|
|
$actor->importFromDatabase($data);
|
2018-11-27 16:55:24 +00:00
|
|
|
$actor->setType('Person');
|
2018-11-12 22:55:39 +00:00
|
|
|
$actor->setInbox($actor->getId() . '/inbox')
|
2024-10-28 12:53:06 +00:00
|
|
|
->setOutbox($actor->getId() . '/outbox')
|
|
|
|
->setUserId($this->get('user_id', $data, ''))
|
|
|
|
->setFollowers($actor->getId() . '/followers')
|
|
|
|
->setFollowing($actor->getId() . '/following')
|
|
|
|
->setSharedInbox($root . 'inbox')
|
|
|
|
->setLocal(true)
|
|
|
|
->setAvatarVersion($this->getInt('avatar_version', $data, -1))
|
|
|
|
->setAccount(
|
|
|
|
$actor->getPreferredUsername() . '@' . $this->configService->getSocialAddress()
|
|
|
|
);
|
2018-11-23 20:36:35 +00:00
|
|
|
$actor->setUrlSocial($root)
|
2024-10-28 12:53:06 +00:00
|
|
|
->setUrl($actor->getId());
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
return $actor;
|
|
|
|
}
|
|
|
|
}
|