1
0

Version1008Date20230921144701.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UserStatus\Migration;
  8. use Closure;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\DB\Types;
  11. use OCP\IDBConnection;
  12. use OCP\Migration\IOutput;
  13. use OCP\Migration\SimpleMigrationStep;
  14. class Version1008Date20230921144701 extends SimpleMigrationStep {
  15. public function __construct(
  16. private IDBConnection $connection,
  17. ) {
  18. }
  19. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  20. /** @var ISchemaWrapper $schema */
  21. $schema = $schemaClosure();
  22. $statusTable = $schema->getTable('user_status');
  23. if (!($statusTable->hasColumn('status_message_timestamp'))) {
  24. $statusTable->addColumn('status_message_timestamp', Types::INTEGER, [
  25. 'notnull' => true,
  26. 'length' => 11,
  27. 'unsigned' => true,
  28. 'default' => 0,
  29. ]);
  30. }
  31. if (!$statusTable->hasIndex('user_status_mtstmp_ix')) {
  32. $statusTable->addIndex(['status_message_timestamp'], 'user_status_mtstmp_ix');
  33. }
  34. return $schema;
  35. }
  36. public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
  37. $qb = $this->connection->getQueryBuilder();
  38. $update = $qb->update('user_status')
  39. ->set('status_message_timestamp', 'status_timestamp');
  40. $update->executeStatement();
  41. }
  42. }