Files
integration_gotosocial/lib/Migration/Version030001Date20241018141359.php
Neon Overlord d2c70bc226 fork: rebrand as integration_gotosocial
Fork of nextcloud/integration_mastodon v5.2.0 (6a56211), AGPL-3.0, with
upstream copyright notices and CHANGELOG preserved unchanged.

Rebranded: app ID, namespace, dashboard widgets, reference provider, icon
component, search provider IDs and every user-facing string. GoToSocial
calls them posts, not toots, and its mascot is a sloth.

Deliberately NOT rebranded: MastodonAPIService, MastodonAPIController,
route names and config keys. They speak the Mastodon client API, which is
what GoToSocial implements -- renaming them would make the code claim a
protocol that does not exist, and would make this fork expensive to rebase
on future upstream releases.

Translations are inherited. Strings reworded by the rebrand fall back to
English; the rest still work in all 124 locales.

Assisted-by: Claude Code:claude-opus-5
2026-08-03 14:51:51 -07:00

81 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\GoToSocial\Migration;
use Closure;
use OCA\GoToSocial\AppInfo\Application;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use OCP\Security\ICrypto;
class Version030001Date20241018141359 extends SimpleMigrationStep {
public function __construct(
private IDBConnection $connection,
private ICrypto $crypto,
) {
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
// user tokens, client_id and client_secret
$qbUpdate = $this->connection->getQueryBuilder();
$qbUpdate->update('preferences')
->set('configvalue', $qbUpdate->createParameter('updateValue'))
->where(
$qbUpdate->expr()->eq('appid', $qbUpdate->createNamedParameter(Application::APP_ID, IQueryBuilder::PARAM_STR))
)
->andWhere(
$qbUpdate->expr()->eq('userid', $qbUpdate->createParameter('updateUserId'))
)
->andWhere(
$qbUpdate->expr()->eq('configkey', $qbUpdate->createParameter('updateConfigKey'))
);
$qbSelect = $this->connection->getQueryBuilder();
$qbSelect->select('userid', 'configvalue', 'configkey')
->from('preferences')
->where(
$qbSelect->expr()->eq('appid', $qbSelect->createNamedParameter(Application::APP_ID, IQueryBuilder::PARAM_STR))
);
$or = $qbSelect->expr()->orx();
$or->add($qbSelect->expr()->eq('configkey', $qbSelect->createNamedParameter('token', IQueryBuilder::PARAM_STR)));
$or->add($qbSelect->expr()->eq('configkey', $qbSelect->createNamedParameter('client_id', IQueryBuilder::PARAM_STR)));
$or->add($qbSelect->expr()->eq('configkey', $qbSelect->createNamedParameter('client_secret', IQueryBuilder::PARAM_STR)));
$qbSelect->andWhere($or);
$qbSelect->andWhere(
$qbSelect->expr()->nonEmptyString('configvalue')
)
->andWhere(
$qbSelect->expr()->isNotNull('configvalue')
);
$req = $qbSelect->executeQuery();
while ($row = $req->fetch()) {
$userId = $row['userid'];
$configKey = $row['configkey'];
$storedClearValue = $row['configvalue'];
$encryptedValue = $this->crypto->encrypt($storedClearValue);
$qbUpdate->setParameter('updateConfigKey', $configKey, IQueryBuilder::PARAM_STR);
$qbUpdate->setParameter('updateValue', $encryptedValue, IQueryBuilder::PARAM_STR);
$qbUpdate->setParameter('updateUserId', $userId, IQueryBuilder::PARAM_STR);
$qbUpdate->executeStatement();
}
$req->closeCursor();
}
}