1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- declare(strict_types=1);
- namespace OCA\Theming\Migration;
- use Closure;
- use OCA\Theming\AppInfo\Application;
- use OCA\Theming\Jobs\RestoreBackgroundImageColor;
- use OCP\BackgroundJob\IJobList;
- use OCP\IAppConfig;
- use OCP\IDBConnection;
- use OCP\Migration\IMigrationStep;
- use OCP\Migration\IOutput;
- class Version2006Date20240905111627 implements IMigrationStep {
- public function __construct(
- private IJobList $jobList,
- private IAppConfig $appConfig,
- private IDBConnection $connection,
- ) {
- }
- public function name(): string {
- return 'Restore custom primary color';
- }
- public function description(): string {
- return 'Restore custom primary color after separating primary color from background color';
- }
- public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
-
- }
- public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
- $this->restoreSystemColors($output);
- $userThemingEnabled = $this->appConfig->getValueBool('theming', 'disable-user-theming') === false;
- if ($userThemingEnabled) {
- $this->restoreUserColors($output);
- }
- return null;
- }
- public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
- $output->info('Initialize restoring of background colors for custom background images');
-
- $this->jobList->add(RestoreBackgroundImageColor::class, ['stage' => RestoreBackgroundImageColor::STAGE_PREPARE]);
- }
- private function restoreSystemColors(IOutput $output): void {
- $defaultColor = $this->appConfig->getValueString(Application::APP_ID, 'color', '');
- if ($defaultColor === '') {
- $output->info('No custom system color configured - skipping');
- } else {
-
- $this->appConfig->setValueString(Application::APP_ID, 'background_color', $defaultColor);
- $this->appConfig->setValueString(Application::APP_ID, 'primary_color', $defaultColor);
-
- $this->appConfig->deleteKey(Application::APP_ID, 'color');
-
- $output->info('Global primary color restored');
- }
- }
- private function restoreUserColors(IOutput $output): void {
- $output->info('Restoring user primary color');
-
- $qb = $this->connection->getQueryBuilder();
-
-
- $qb->update('preferences')
- ->set('configkey', $qb->createNamedParameter('primary_color'))
- ->where($qb->expr()->eq('appid', $qb->createNamedParameter(Application::APP_ID)))
- ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter('background_color')));
- $qb->executeStatement();
- $output->info('Primary color of users restored');
- }
- }
|