|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\ContextChat\Migration; |
| 11 | + |
| 12 | +use Closure; |
| 13 | +use OCA\ContextChat\AppInfo\Application; |
| 14 | +use OCP\DB\ISchemaWrapper; |
| 15 | +use OCP\DB\QueryBuilder\IQueryBuilder; |
| 16 | +use OCP\IDBConnection; |
| 17 | +use OCP\Migration\IOutput; |
| 18 | +use OCP\Migration\SimpleMigrationStep; |
| 19 | +use Override; |
| 20 | + |
| 21 | +class Version005000001Date20251124093628 extends SimpleMigrationStep { |
| 22 | + private static array $configKeys = [ |
| 23 | + 'action_job_interval', |
| 24 | + 'auto_indexing', |
| 25 | + 'backend_init', |
| 26 | + 'crawl_job_interval', |
| 27 | + 'fs_listener_job_interval', |
| 28 | + 'indexed_files_count', |
| 29 | + 'indexing_batch_size', |
| 30 | + 'indexing_job_interval', |
| 31 | + 'indexing_max_size', |
| 32 | + 'indexing_max_time', |
| 33 | + 'installed_time', |
| 34 | + 'last_indexed_file_id', |
| 35 | + 'last_indexed_time', |
| 36 | + 'logfile', |
| 37 | + 'providers', |
| 38 | + ]; |
| 39 | + |
| 40 | + public function __construct( |
| 41 | + private IDBConnection $connection, |
| 42 | + ) { |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @param IOutput $output |
| 47 | + * @param Closure(): ISchemaWrapper $schemaClosure |
| 48 | + * @param array $options |
| 49 | + * @return null|ISchemaWrapper |
| 50 | + */ |
| 51 | + #[Override] |
| 52 | + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
| 53 | + $schema = $schemaClosure(); |
| 54 | + |
| 55 | + if (!$schema->hasTable('appconfig')) { |
| 56 | + return null; |
| 57 | + } |
| 58 | + |
| 59 | + $qb = $this->connection->getQueryBuilder(); |
| 60 | + $qb->update('appconfig') |
| 61 | + ->set('lazy', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) |
| 62 | + ->where( |
| 63 | + $qb->expr()->eq('appid', $qb->createNamedParameter(Application::APP_ID, IQueryBuilder::PARAM_STR)) |
| 64 | + ) |
| 65 | + ->andWhere( |
| 66 | + $qb->expr()->in('configkey', $qb->createNamedParameter(self::$configKeys, IQueryBuilder::PARAM_STR_ARRAY)) |
| 67 | + ); |
| 68 | + $qb->executeStatement(); |
| 69 | + |
| 70 | + return $schema; |
| 71 | + } |
| 72 | +} |
0 commit comments