Merge pull request #1536 from nextcloud/enh/noid/migration-db

migrate db
pull/1537/head
Maxence Lange 2022-11-23 10:04:18 -01:00 zatwierdzone przez GitHub
commit 69128016ab
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
19 zmienionych plików z 273 dodań i 580 usunięć

Wyświetl plik

@ -43,19 +43,12 @@
<job>OCA\Social\Cron\Queue</job>
</background-jobs>
<repair-steps>
<post-migration>
<step>OCA\Social\Migration\CheckInstallation</step>
</post-migration>
</repair-steps>
<commands>
<command>OCA\Social\Command\AccountCreate</command>
<command>OCA\Social\Command\AccountFollowing</command>
<command>OCA\Social\Command\CacheRefresh</command>
<command>OCA\Social\Command\CheckInstall</command>
<command>OCA\Social\Command\Fediverse</command>
<command>OCA\Social\Command\MigrateAlpha3</command>
<command>OCA\Social\Command\NoteLike</command>
<command>OCA\Social\Command\NoteCreate</command>
<command>OCA\Social\Command\NoteBoost</command>

Wyświetl plik

@ -1,397 +0,0 @@
<?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\Command;
use OCA\Social\Tools\Traits\TArrayTools;
use Exception;
use OC\Core\Command\Base;
use OCA\Social\Db\CoreRequestBuilder;
use OCA\Social\Service\CheckService;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IParameter;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class MigrateAlpha3 extends Base {
use TArrayTools;
private IDBConnection $dbConnection;
private CoreRequestBuilder $coreRequestBuilder;
private CheckService $checkService;
private ConfigService $configService;
private MiscService $miscService;
private array $done = [];
public array $tables = [
'social_a2_actions' => [
['id_prim'],
'social_3_action',
[
'actor_id_prim' => 'PRIM:actor_id',
'object_id_prim' => 'PRIM:object_id'
]
],
'social_a2_actors' => [['user_id'], 'social_3_actor', []],
'social_a2_cache_actors' => [['id_prim'], 'social_3_cache_actor', []],
'social_a2_cache_documts' => [['id_prim'], 'social_3_cache_doc', []],
'social_a2_follows' => [
['id_prim'],
'social_3_follow',
[
'actor_id_prim' => 'PRIM:actor_id',
'object_id_prim' => 'PRIM:object_id',
'follow_id_prim' => 'PRIM:follow_id'
]
],
'social_a2_hashtags' => [['hashtag'], 'social_3_hashtag', []],
'social_a2_request_queue' => [['id'], 'social_3_req_queue', []],
'social_a2_stream' => [
['id_prim'],
'social_3_stream',
[
'object_id_prim' => 'PRIM:object_id',
'in_reply_to_prim' => 'PRIM:in_reply_to',
'attributed_to_prim' => 'PRIM:attributed_to',
'filter_duplicate' => 'COPY:hidden_on_timeline',
'hidden_on_timeline' => 'REMOVED:'
]
],
'social_a2_stream_action' => [
['id'],
'social_3_stream_act',
[
'actor_id_prim' => 'PRIM:actor_id',
'stream_id_prim' => 'PRIM:stream_id',
'_function_' => 'migrateTableStreamAction'
]
],
'social_a2_stream_queue' => [['id'], 'social_3_stream_queue', []]
];
public function __construct(
IDBConnection $dbConnection, CoreRequestBuilder $coreRequestBuilder, CheckService $checkService,
ConfigService $configService, MiscService $miscService
) {
parent::__construct();
$this->dbConnection = $dbConnection;
$this->checkService = $checkService;
$this->coreRequestBuilder = $coreRequestBuilder;
$this->configService = $configService;
$this->miscService = $miscService;
}
protected function configure() {
parent::configure();
$this->setName('social:migrate:alpha3')
->setDescription('Trying to migrate old data to Alpha3')
->addOption(
'remove-migrated-tables', '', InputOption::VALUE_NONE, 'Remove old table once copy is done'
)
->addOption(
'force-remove-old-tables', '', InputOption::VALUE_NONE, 'Force remove old tables'
);
}
/**
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$tables = $this->checkTables();
if ($input->getOption('force-remove-old-tables')) {
foreach ($tables as $table) {
$this->dropTable($table);
}
return 0;
}
if (empty($tables)) {
$output->writeln('Nothing to migrate.');
return 0;
}
$defTables = '';
if (sizeof($tables) < sizeof($this->tables)) {
$defTables = ': \'' . implode("', '", $tables) . '\'';
}
$output->writeln(
'Found ' . sizeof($tables) . ' tables to migrate' . $defTables . '.'
);
if (!$this->confirmExecute($input, $output)) {
return 0;
}
$this->done = [];
$this->migrateTables($output, $tables);
if ($input->getOption('remove-migrated-tables')) {
$this->dropDeprecatedTables($input, $output);
}
return 0;
}
/**
* @return string[]
*/
private function checkTables(): array {
$ak = array_keys($this->tables);
$tables = [];
foreach ($ak as $k) {
if ($this->dbConnection->tableExists($k)) {
$tables[] = $k;
}
}
return $tables;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*/
private function confirmExecute(InputInterface $input, OutputInterface $output): bool {
$helper = $this->getHelper('question');
$output->writeln('');
$question = new ConfirmationQuestion(
'<info>Do you want to migrate data from the old database?</info> (y/N) ', false, '/^(y|Y)/i'
);
if (!$helper->ask($input, $output, $question)) {
return false;
}
return true;
}
private function migrateTables(OutputInterface $output, array $tables): void {
foreach ($tables as $table) {
try {
$this->migrateTable($output, $table);
$output->writeln('Migration of \'<comment>' . $table . '</comment>\': <info>ok</info>');
} catch (Exception $e) {
$output->writeln(
'Migration of \'<comment>' . $table . '</comment>\': <error>fail</error> - '
. $e->getMessage()
);
}
}
}
private function migrateTable(OutputInterface $output, string $table): void {
$output->writeln('');
$output->writeln('Retrieving data from \'' . $table . '\'.');
$fullContent = $this->getContentFromTable($table);
$output->write('Found ' . count($fullContent) . ' entries');
$m = $copied = 0;
foreach ($fullContent as $entry) {
if ($m % 50 === 0) {
$output->write('.');
}
if ($this->migrateEntry($table, $entry)) {
$copied++;
}
$m++;
}
$output->writeln(' <info>' . $copied . ' copied</info>');
$this->done[] = $table;
}
private function getContentFromTable(string $table): array {
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('*')
->from($table);
$entries = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
$entries[] = $data;
}
$cursor->closeCursor();
return $entries;
}
private function migrateEntry(string $table, $entry): bool {
if (!$this->checkUnique($table, $entry)) {
return false;
}
list(, $destTable, $destDefault) = $this->tables[$table];
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert($destTable);
$ak = array_merge(array_keys($entry), array_keys($destDefault));
foreach ($ak as $k) {
if ($k === '_function_') {
continue;
}
$value = '';
try {
if ($this->get($k, $entry, '') !== '') {
$this->manageDefault($qb, $this->get($k, $destDefault), $entry);
$value = $entry[$k];
} elseif (array_key_exists($k, $destDefault)) {
$value = $this->manageDefault($qb, $destDefault[$k], $entry);
}
} catch (Exception $e) {
continue;
}
if ($value !== '') {
$qb->setValue($k, $qb->createNamedParameter($value));
}
}
if (array_key_exists('_function_', $destDefault)) {
call_user_func_array([$this, $destDefault['_function_']], [$qb, $entry]);
}
$qb->execute();
return true;
}
private function checkUnique(string $table, $entry): bool {
list($unique, $destTable) = $this->tables[$table];
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('*')
->from($destTable);
$expr = $qb->expr();
$andX = $expr->andX();
foreach ($unique as $f) {
$andX->add($expr->eq($f, $qb->createNamedParameter($entry[$f])));
}
$qb->andWhere($andX);
$cursor = $qb->executeQuery();
$data = $cursor->fetch();
$cursor->closeCursor();
if ($data === false) {
return true;
}
return false;
}
/**
* @return IParameter|string
* @throws Exception
*/
private function manageDefault(IQueryBuilder $qb, string $default, array $entry) {
if ($default === '') {
return '';
}
if (!strpos($default, ':')) {
return $qb->createNamedParameter($default);
}
list($k, $v) = explode(':', $default, 2);
switch ($k) {
case 'COPY':
return $this->get($v, $entry, '');
case 'PRIM':
if ($this->get($v, $entry, '') === '') {
return '';
}
return hash('sha512', $entry[$v]);
case 'REMOVED':
throw new Exception();
}
return '';
}
private function dropDeprecatedTables(InputInterface $input, OutputInterface $output) {
$helper = $this->getHelper('question');
$output->writeln('');
$question = new ConfirmationQuestion(
'<info>You migrate ' . count($this->done) . ' table. Do you want to remove them ?</info> (y/N) ',
false, '/^(y|Y)/i'
);
if (!$helper->ask($input, $output, $question)) {
return;
}
foreach ($this->done as $table) {
$this->dropTable($table);
}
}
private function dropTable(string $table): void {
$this->dbConnection->dropTable($table);
}
public function migrateTableStreamAction(IQueryBuilder $qb, array $entry): void {
$values = json_decode($entry['values'], true);
if ($values === null) {
return;
}
$liked = ($this->getBool('liked', $values)) ? '1' : '0';
$boosted = ($this->getBool('boosted', $values)) ? '1' : '0';
$qb->setValue('liked', $qb->createNamedParameter($liked));
$qb->setValue('boosted', $qb->createNamedParameter($boosted));
}
}

Wyświetl plik

@ -31,12 +31,12 @@ declare(strict_types=1);
namespace OCA\Social\Db;
use OCA\Social\Tools\Traits\TArrayTools;
use DateTime;
use Exception;
use OCA\Social\Exceptions\ActionDoesNotExistException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Object\Like;
use OCA\Social\Tools\Traits\TArrayTools;
use OCP\DB\QueryBuilder\IQueryBuilder;
/**
@ -53,6 +53,7 @@ class ActionsRequest extends ActionsRequestBuilder {
public function save(ACore $like): void {
$qb = $this->getActionsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($like->getId()))
->setValue('id_prim', $qb->createNamedParameter($qb->prim($like->getId())))
->setValue('actor_id', $qb->createNamedParameter($like->getActorId()))
->setValue('actor_id_prim', $qb->createNamedParameter($qb->prim($like->getActorId())))
->setValue('type', $qb->createNamedParameter($like->getType()))
@ -67,8 +68,6 @@ class ActionsRequest extends ActionsRequestBuilder {
} catch (Exception $e) {
}
$this->generatePrimaryKey($qb, $like->getId());
$qb->executeStatement();
}

Wyświetl plik

@ -47,7 +47,7 @@ class ActorsRequest extends ActorsRequestBuilder {
$qb = $this->getActorsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($actor->getId()))
->setValue('id_prim', $qb->createNamedParameter($this->prim($actor->getId())))
->setValue('id_prim', $qb->createNamedParameter($qb->prim($actor->getId())))
->setValue('user_id', $qb->createNamedParameter($actor->getUserId()))
->setValue('name', $qb->createNamedParameter($actor->getName()))
->setValue('summary', $qb->createNamedParameter($actor->getSummary()))

Wyświetl plik

@ -44,8 +44,8 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getActorsInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getActorsInsertSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->insert(self::TABLE_ACTORS);
return $qb;
@ -57,8 +57,8 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getActorsUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getActorsUpdateSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->update(self::TABLE_ACTORS);
return $qb;
@ -92,8 +92,8 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getActorsDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getActorsDeleteSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->delete(self::TABLE_ACTORS);
return $qb;

Wyświetl plik

@ -47,7 +47,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
public function save(Person $actor): void {
$qb = $this->getCacheActorsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($actor->getId()))
->setValue('id_prim', $qb->createNamedParameter($this->prim($actor->getId())))
->setValue('id_prim', $qb->createNamedParameter($qb->prim($actor->getId())))
->setValue('account', $qb->createNamedParameter($actor->getAccount()))
->setValue('type', $qb->createNamedParameter($actor->getType()))
->setValue('local', $qb->createNamedParameter(($actor->isLocal()) ? '1' : '0'))

Wyświetl plik

@ -47,6 +47,7 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder {
public function save(Document $document): void {
$qb = $this->getCacheDocumentsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($document->getId()))
->setValue('id_prim', $qb->createNamedParameter($qb->prim($document->getId())))
->setValue('type', $qb->createNamedParameter($document->getType()))
->setValue('url', $qb->createNamedParameter($document->getUrl()))
->setValue('media_type', $qb->createNamedParameter($document->getMediaType()))
@ -65,8 +66,6 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder {
} catch (Exception $e) {
}
$this->generatePrimaryKey($qb, $document->getId());
$qb->executeStatement();
}

Wyświetl plik

@ -32,13 +32,12 @@ namespace OCA\Social\Db;
use OCA\Social\Tools\Traits\TArrayTools;
use OCA\Social\Model\ActivityPub\Object\Document;
use OCP\DB\QueryBuilder\IQueryBuilder;
class CacheDocumentsRequestBuilder extends CoreRequestBuilder {
use TArrayTools;
protected function getCacheDocumentsInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getCacheDocumentsInsertSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->insert(self::TABLE_CACHE_DOCUMENTS);
return $qb;
@ -47,8 +46,8 @@ class CacheDocumentsRequestBuilder extends CoreRequestBuilder {
/**
* Base of the Sql Update request
*/
protected function getCacheDocumentsUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getCacheDocumentsUpdateSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->update(self::TABLE_CACHE_DOCUMENTS);
return $qb;
@ -76,8 +75,8 @@ class CacheDocumentsRequestBuilder extends CoreRequestBuilder {
/**
* Base of the Sql Delete request
*/
protected function getCacheDocumentsDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getCacheDocumentsDeleteSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->delete(self::TABLE_CACHE_DOCUMENTS);
return $qb;

Wyświetl plik

@ -31,20 +31,20 @@ declare(strict_types=1);
namespace OCA\Social\Db;
use OCA\Social\Tools\Exceptions\DateTimeException;
use DateInterval;
use DateTime;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
use OC;
use OC\DB\SchemaWrapper;
use OCP\DB\ISchemaWrapper;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCA\Social\Model\StreamAction;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCA\Social\Tools\Exceptions\DateTimeException;
use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IURLGenerator;
@ -57,44 +57,203 @@ use Psr\Log\LoggerInterface;
* @package OCA\Social\Db
*/
class CoreRequestBuilder {
public const TABLE_REQUEST_QUEUE = 'social_req_queue';
public const TABLE_INSTANCE = 'social_instance';
public const TABLE_ACTORS = 'social_actor';
public const TABLE_STREAM = 'social_stream';
public const TABLE_STREAM_DEST = 'social_stream_dest';
public const TABLE_STREAM_TAGS = 'social_stream_tag';
public const TABLE_STREAM_QUEUE = 'social_stream_queue';
public const TABLE_STREAM_ACTIONS = 'social_stream_act';
public const TABLE_HASHTAGS = 'social_hashtag';
public const TABLE_FOLLOWS = 'social_follow';
public const TABLE_ACTIONS = 'social_action';
public const TABLE_ACTORS = 'social_actor';
public const TABLE_CACHE_ACTORS = 'social_cache_actor';
public const TABLE_CACHE_DOCUMENTS = 'social_cache_doc';
public const TABLE_CLIENT = 'social_client';
public const TABLE_CLIENT_AUTH = 'social_client_auth';
public const TABLE_CLIENT_TOKEN = 'social_client_token';
public const TABLE_FOLLOWS = 'social_follow';
public const TABLE_HASHTAGS = 'social_hashtag';
public const TABLE_INSTANCE = 'social_instance';
public const TABLE_REQUEST_QUEUE = 'social_req_queue';
public const TABLE_STREAM = 'social_stream';
public const TABLE_STREAM_ACTIONS = 'social_stream_act';
public const TABLE_STREAM_DEST = 'social_stream_dest';
public const TABLE_STREAM_QUEUE = 'social_stream_queue';
public const TABLE_STREAM_TAGS = 'social_stream_tag';
private array $tables = [
self::TABLE_REQUEST_QUEUE,
self::TABLE_ACTORS,
self::TABLE_STREAM,
self::TABLE_HASHTAGS,
self::TABLE_FOLLOWS,
self::TABLE_ACTIONS,
self::TABLE_CACHE_ACTORS,
self::TABLE_CACHE_DOCUMENTS,
self::TABLE_STREAM_QUEUE,
self::TABLE_STREAM_DEST,
self::TABLE_STREAM_TAGS,
self::TABLE_STREAM_ACTIONS,
self::TABLE_CLIENT,
self::TABLE_CLIENT_AUTH,
self::TABLE_CLIENT_TOKEN
public static array $tables = [
self::TABLE_ACTIONS => [
'id_prim',
'id',
'type',
'actor_id',
'actor_id_prim',
'object_id',
'object_id_prim',
'creation'
],
self::TABLE_ACTORS => [
'id_prim',
'id',
'user_id',
'preferred_username',
'name',
'summary',
'public_key',
'private_key',
'avatar_version',
'creation'
],
self::TABLE_CACHE_ACTORS => [
'id_prim',
'id',
'type',
'account',
'local',
'following',
'followers',
'inbox',
'shared_index',
'outbox',
'featured',
'url',
'preferred_username',
'name',
'icon_id',
'summary',
'public_key',
'source',
'details',
'creation'
],
self::TABLE_CACHE_DOCUMENTS => [
'id_prim',
'id',
'type',
'parent_id',
'media_type',
'mime_type',
'url',
'local_copy',
'resized_copy',
'public',
'error',
'creation',
'caching'
],
self::TABLE_CLIENT => [
'id',
'app_name',
'app_website',
'app_redirect_uris',
'app_client_id',
'app_client_secret',
'app_scopes',
'auth_scopes',
'auth_account',
'auth_user_id',
'auth_code',
'token',
'last_update',
'creation'
],
self::TABLE_FOLLOWS => [
'id_prim',
'id',
'type',
'actor_id',
'actor_id_prim',
'object_id',
'object_id_prim',
'follow_id',
'follow_id_prim',
'accepted',
'creation'
],
self::TABLE_HASHTAGS => [
'hashtag',
'trend'
],
self::TABLE_INSTANCE => [
'uri',
'local',
'title',
'version',
'short_description',
'description',
'email',
'urls',
'stats',
'usage',
'image',
'languages',
'contact',
'account_prim',
'creation'
],
self::TABLE_REQUEST_QUEUE => [
'id',
'token',
'author',
'activity',
'instance',
'priority',
'status',
'tries',
'last'
],
self::TABLE_STREAM => [
'nid',
'id',
'id_prim',
'type',
'subtype',
'to',
'to_array',
'cc',
'bcc',
'content',
'summary',
'published',
'published_time',
'attributed_to',
'attributed_to_prim',
'in_reply_to',
'in_reply_to_prim',
'activity_id',
'object_id',
'object_id_prim',
'hashtags',
'details',
'source',
'instances',
'attachments',
'cache',
'creation',
'local',
'filter_duplicate'
],
self::TABLE_STREAM_ACTIONS => [
'id',
'actor_id',
'actor_id_prim',
'stream_id',
'stream_id_prim',
'liked',
'boosted',
'replied',
'values'
],
self::TABLE_STREAM_DEST => [
'stream_id',
'actor_id',
'type',
'subtype'
],
self::TABLE_STREAM_QUEUE => [
'id',
'token',
'stream_id',
'type',
'status',
'tries',
'last'
],
self::TABLE_STREAM_TAGS => [
'stream_id',
'hashtag'
],
];
protected LoggerInterface $logger;
@ -155,32 +314,6 @@ class CoreRequestBuilder {
}
/**
* @param string $id
*
* @return string
* @deprecated
*/
public function prim(string $id): string {
if ($id === '') {
return '';
}
return hash('sha512', $id);
}
/**
* @param IQueryBuilder $qb
* @param string $id
*
* @deprecated - not that useful, the raw line should be implemented instead of calling this method !
*/
public function generatePrimaryKey(IQueryBuilder $qb, string $id) {
$qb->setValue('id_prim', $qb->createNamedParameter($this->prim($id)));
}
/**
* Limit the request to the Id
*
@ -904,7 +1037,7 @@ class CoreRequestBuilder {
$on = $expr->andX();
$on->add(
$expr->eq(
'sa.actor_id_prim', $qb->createNamedParameter($this->prim($this->viewer->getId()))
'sa.actor_id_prim', $qb->createNamedParameter($qb->prim($this->viewer->getId()))
)
);
$on->add($orX);
@ -1131,8 +1264,8 @@ class CoreRequestBuilder {
*/
public function emptyAll() {
/** @var ISchemaWrapper|SchemaWrapper $schema */
$schema = new SchemaWrapper(Server::get(OC\DB\Connection::class));
foreach ($this->tables as $table) {
$schema = new SchemaWrapper(Server::get(IDBConnection::class));
foreach (array_keys(self::$tables) as $table) {
if ($schema->hasTable($table)) {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete($table);
@ -1147,8 +1280,8 @@ class CoreRequestBuilder {
*/
public function uninstallSocialTables() {
/** @var ISchemaWrapper|SchemaWrapper $schema */
$schema = new SchemaWrapper(Server::get(OC\DB\Connection::class));
foreach ($this->tables as $table) {
$schema = new SchemaWrapper(Server::get(IDBConnection::class));
foreach (array_keys(self::$tables) as $table) {
if ($schema->hasTable($table)) {
$schema->dropTable($table);
}

Wyświetl plik

@ -61,9 +61,9 @@ class FollowsRequest extends FollowsRequestBuilder {
->setValue('object_id', $qb->createNamedParameter($follow->getObjectId()))
->setValue('follow_id', $qb->createNamedParameter($follow->getFollowId()))
->setValue('accepted', $qb->createNamedParameter(($follow->isAccepted()) ? '1' : '0'))
->setValue('actor_id_prim', $qb->createNamedParameter($this->prim($follow->getActorId())))
->setValue('object_id_prim', $qb->createNamedParameter($this->prim($follow->getObjectId())))
->setValue('follow_id_prim', $qb->createNamedParameter($this->prim($follow->getFollowId())));
->setValue('actor_id_prim', $qb->createNamedParameter($qb->prim($follow->getActorId())))
->setValue('object_id_prim', $qb->createNamedParameter($qb->prim($follow->getObjectId())))
->setValue('follow_id_prim', $qb->createNamedParameter($qb->prim($follow->getFollowId())));
try {
$qb->setValue(
@ -86,9 +86,9 @@ class FollowsRequest extends FollowsRequestBuilder {
->setValue('object_id', $qb->createNamedParameter($actor->getId()))
->setValue('follow_id', $qb->createNamedParameter($actor->getId()))
->setValue('accepted', $qb->createNamedParameter('1'))
->setValue('actor_id_prim', $qb->createNamedParameter($this->prim($actor->getId())))
->setValue('object_id_prim', $qb->createNamedParameter($this->prim($actor->getId())))
->setValue('follow_id_prim', $qb->createNamedParameter($this->prim($actor->getId())));
->setValue('actor_id_prim', $qb->createNamedParameter($qb->prim($actor->getId())))
->setValue('object_id_prim', $qb->createNamedParameter($qb->prim($actor->getId())))
->setValue('follow_id_prim', $qb->createNamedParameter($qb->prim($actor->getId())));
try {
$qb->setValue(

Wyświetl plik

@ -48,8 +48,8 @@ class HashtagsRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getHashtagsInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getHashtagsInsertSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->insert(self::TABLE_HASHTAGS);
return $qb;
@ -61,8 +61,8 @@ class HashtagsRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getHashtagsUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getHashtagsUpdateSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->update(self::TABLE_HASHTAGS);
return $qb;
@ -93,8 +93,8 @@ class HashtagsRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getHashtagsDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getHashtagsDeleteSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->delete(self::TABLE_HASHTAGS);
return $qb;

Wyświetl plik

@ -67,7 +67,7 @@ class InstancesRequest extends InstancesRequestBuilder {
->setValue('usage', $qb->createNamedParameter(json_encode($instance->getUsage())))
->setValue('image', $qb->createNamedParameter($instance->getImage()))
->setValue('languages', $qb->createNamedParameter(json_encode($instance->getLanguages())))
->setValue('account_prim', $qb->createNamedParameter($instance->getAccountPrim() ? $this->prim($instance->getAccountPrim()) : null));
->setValue('account_prim', $qb->createNamedParameter($instance->getAccountPrim() ? $qb->prim($instance->getAccountPrim()) : null));
$qb->executeStatement();
}

Wyświetl plik

@ -43,8 +43,8 @@ class RequestQueueRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getRequestQueueInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getRequestQueueInsertSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->insert(self::TABLE_REQUEST_QUEUE);
return $qb;
@ -56,8 +56,8 @@ class RequestQueueRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getRequestQueueUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getRequestQueueUpdateSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->update(self::TABLE_REQUEST_QUEUE);
return $qb;
@ -91,8 +91,8 @@ class RequestQueueRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getRequestQueueDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getRequestQueueDeleteSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->delete(self::TABLE_REQUEST_QUEUE);
return $qb;

Wyświetl plik

@ -69,10 +69,10 @@ class SocialCoreQueryBuilder extends ExtendedQueryBuilder {
}
public function prim(string $id): string {
if ($id === '') {
if ($id === '' || substr($id, 0, 4) !== 'http') {
return '';
}
return hash('sha512', $id);
return md5($id);
}
}

Wyświetl plik

@ -52,9 +52,9 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
$replied = $this->getBool(StreamAction::REPLIED, $values, false);
$qb->setValue('actor_id', $qb->createNamedParameter($action->getActorId()))
->setValue('actor_id_prim', $qb->createNamedParameter($this->prim($action->getActorId())))
->setValue('actor_id_prim', $qb->createNamedParameter($qb->prim($action->getActorId())))
->setValue('stream_id', $qb->createNamedParameter($action->getStreamId()))
->setValue('stream_id_prim', $qb->createNamedParameter($this->prim($action->getStreamId())))
->setValue('stream_id_prim', $qb->createNamedParameter($qb->prim($action->getStreamId())))
->setValue(
'values', $qb->createNamedParameter(
json_encode($values, JSON_UNESCAPED_SLASHES)

Wyświetl plik

@ -48,8 +48,8 @@ class StreamActionsRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getStreamActionInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getStreamActionInsertSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->insert(self::TABLE_STREAM_ACTIONS);
return $qb;
@ -61,8 +61,8 @@ class StreamActionsRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getStreamActionUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getStreamActionUpdateSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->update(self::TABLE_STREAM_ACTIONS);
return $qb;
@ -93,8 +93,8 @@ class StreamActionsRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getStreamActionDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getStreamActionDeleteSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->delete(self::TABLE_STREAM_ACTIONS);
return $qb;

Wyświetl plik

@ -43,8 +43,8 @@ class StreamQueueRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getStreamQueueInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getStreamQueueInsertSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->insert(self::TABLE_STREAM_QUEUE);
return $qb;
@ -56,8 +56,8 @@ class StreamQueueRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getStreamQueueUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getStreamQueueUpdateSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->update(self::TABLE_STREAM_QUEUE);
return $qb;
@ -90,8 +90,8 @@ class StreamQueueRequestBuilder extends CoreRequestBuilder {
*
* @return IQueryBuilder
*/
protected function getStreamQueueDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getStreamQueueDeleteSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->delete(self::TABLE_STREAM_QUEUE);
return $qb;

Wyświetl plik

@ -2,7 +2,6 @@
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
@ -10,7 +9,7 @@ declare(strict_types=1);
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @copyright 2022, 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
@ -28,22 +27,15 @@ declare(strict_types=1);
*
*/
namespace OCA\Social\Migration;
use Closure;
use Doctrine\DBAL\Schema\SchemaException;
use Exception;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
* Class Version0003Date20200611000001
*
* @package OCA\Social\Migration
*/
class Version1000Date20221118000001 extends SimpleMigrationStep {
/**
* @param IOutput $output
@ -77,17 +69,6 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*
* @throws Exception
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}
/**
* @param ISchemaWrapper $schema
*
@ -109,7 +90,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128
'length' => 32
]
);
$table->addColumn(
@ -131,7 +112,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'actor_id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -146,7 +127,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'object_id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -184,7 +165,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128
'length' => 32
]
);
$table->addColumn(
@ -267,7 +248,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128
'length' => 32
]
);
$table->addColumn(
@ -289,7 +270,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'actor_id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -304,7 +285,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'object_id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -319,7 +300,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'follow_id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -486,7 +467,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'account_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -519,10 +500,6 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
[
'length' => 20,
'unsigned' => true
// 'autoincrement' => true,
// 'customSchemaOptions' => [
// 'unique' => true
// ]
]
);
$table->addColumn(
@ -535,7 +512,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128
'length' => 32
]
);
$table->addColumn(
@ -621,7 +598,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'attributed_to_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -636,7 +613,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'in_reply_to_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -658,7 +635,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'object_id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -755,14 +732,6 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
}
$table = $schema->createTable('social_cache_actor');
// $table->addColumn(
// 'nid', Types::BIGINT,
// [
// 'autoincrement' => true,
// 'length' => 11,
// 'unsigned' => true,
// ]
// );
$table->addColumn(
'id', Types::TEXT,
[
@ -773,7 +742,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128
'length' => 32
]
);
$table->addColumn(
@ -907,7 +876,6 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
$table->setPrimaryKey(['id_prim']);
$table->addUniqueIndex(['id_prim']);
// $table->addUniqueIndex(['nid']);
}
@ -932,7 +900,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128
'length' => 32
]
);
$table->addColumn(
@ -1015,7 +983,6 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
);
$table->setPrimaryKey(['id_prim']);
// $table->addUniqueIndex(['url'], 'unique_url');
}
/**
@ -1255,7 +1222,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'actor_id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -1270,7 +1237,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'stream_id_prim', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -1305,7 +1272,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'stream_id', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -1313,7 +1280,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'actor_id', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);
@ -1422,7 +1389,7 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
'stream_id', Types::STRING,
[
'notnull' => false,
'length' => 128,
'length' => 32,
'default' => ''
]
);

Wyświetl plik

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.26.0@6998fabb2bf528b65777bf9941920888d23c03ac">
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69">
<file src="lib/AP.php">
<InvalidScalarArgument occurrences="1">
<code>$level</code>