connection = $connection; } /** * @param IOutput $output * @param Closure $schemaClosure * @param array $options * @return null|ISchemaWrapper */ #[\Override] public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); $accountsTable = $schema->getTable('mail_accounts'); // Widen refresh token $refreshTokenColumn = $accountsTable->getColumn('oauth_refresh_token'); $refreshTokenColumn->setLength(3000); // Fits Microsoft and Google tokens even after encryption // Add dedicated access token column if (!$accountsTable->hasColumn('oauth_access_token')) { $accountsTable->addColumn('oauth_access_token', Types::TEXT, [ 'notnull' => false, ]); } return $schema; } /** * @return void */ #[\Override] public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { $this->atomic(function () { // Migrate old data to the new column $qb1 = $this->connection->getQueryBuilder(); $qb1->update('mail_accounts') ->set('oauth_access_token', 'inbound_password') ->where( $qb1->expr()->eq('auth_method', $qb1->createNamedParameter('xoauth2')), $qb1->expr()->isNotNull('inbound_password') ); $qb1->executeStatement(); // Delete previous data $qb2 = $this->connection->getQueryBuilder(); $qb2->update('mail_accounts') ->set('inbound_password', $qb2->createNamedParameter(null, IQueryBuilder::PARAM_NULL)) ->set('outbound_password', $qb2->createNamedParameter(null, IQueryBuilder::PARAM_NULL)) ->where( $qb2->expr()->eq('auth_method', $qb2->createNamedParameter('xoauth2')), $qb2->expr()->isNotNull('oauth_access_token') ); $qb2->executeStatement(); }, $this->connection); } }