Version1008Date20230921144701.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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(private IDBConnection $connection) {
  16. }
  17. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  18. /** @var ISchemaWrapper $schema */
  19. $schema = $schemaClosure();
  20. $statusTable = $schema->getTable('user_status');
  21. if (!($statusTable->hasColumn('status_message_timestamp'))) {
  22. $statusTable->addColumn('status_message_timestamp', Types::INTEGER, [
  23. 'notnull' => true,
  24. 'length' => 11,
  25. 'unsigned' => true,
  26. 'default' => 0,
  27. ]);
  28. }
  29. if (!$statusTable->hasIndex('user_status_mtstmp_ix')) {
  30. $statusTable->addIndex(['status_message_timestamp'], 'user_status_mtstmp_ix');
  31. }
  32. return $schema;
  33. }
  34. public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
  35. $qb = $this->connection->getQueryBuilder();
  36. $update = $qb->update('user_status')
  37. ->set('status_message_timestamp', 'status_timestamp');
  38. $update->executeStatement();
  39. }
  40. }