1
0

Version24000Date20211230140012.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Migrations;
  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 Version24000Date20211230140012 extends SimpleMigrationStep {
  15. public function __construct(
  16. protected IDBConnection $connection,
  17. ) {
  18. }
  19. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  20. /** @var ISchemaWrapper $schema */
  21. $schema = $schemaClosure();
  22. $table = $schema->getTable('jobs');
  23. if (!$table->hasColumn('argument_hash')) {
  24. $table->addColumn('argument_hash', Types::STRING, [
  25. 'notnull' => false,
  26. 'length' => 32,
  27. ]);
  28. $table->addIndex(['class', 'argument_hash'], 'job_argument_hash');
  29. return $schema;
  30. }
  31. return null;
  32. }
  33. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  34. $update = $this->connection->getQueryBuilder();
  35. $update->update('jobs')
  36. ->set('argument_hash', $update->func()->md5('argument'));
  37. $update->executeStatement();
  38. }
  39. }