Version1008Date20230921144701.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OCA\UserStatus\Migration;
  23. use Closure;
  24. use OCP\DB\ISchemaWrapper;
  25. use OCP\DB\Types;
  26. use OCP\IDBConnection;
  27. use OCP\Migration\IOutput;
  28. use OCP\Migration\SimpleMigrationStep;
  29. class Version1008Date20230921144701 extends SimpleMigrationStep {
  30. public function __construct(private IDBConnection $connection) {
  31. }
  32. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  33. /** @var ISchemaWrapper $schema */
  34. $schema = $schemaClosure();
  35. $statusTable = $schema->getTable('user_status');
  36. if (!($statusTable->hasColumn('status_message_timestamp'))) {
  37. $statusTable->addColumn('status_message_timestamp', Types::INTEGER, [
  38. 'notnull' => true,
  39. 'length' => 11,
  40. 'unsigned' => true,
  41. 'default' => 0,
  42. ]);
  43. }
  44. if (!$statusTable->hasIndex('user_status_mtstmp_ix')) {
  45. $statusTable->addIndex(['status_message_timestamp'], 'user_status_mtstmp_ix');
  46. }
  47. return $schema;
  48. }
  49. public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
  50. $qb = $this->connection->getQueryBuilder();
  51. $update = $qb->update('user_status')
  52. ->set('status_message_timestamp', 'status_timestamp');
  53. $update->executeStatement();
  54. }
  55. }