1
0

Version2000Date20190808074233.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\WorkflowEngine\Migration;
  8. use Closure;
  9. use Doctrine\DBAL\Schema\Table;
  10. use OCA\WorkflowEngine\Entity\File;
  11. use OCP\DB\ISchemaWrapper;
  12. use OCP\DB\Types;
  13. use OCP\Migration\IOutput;
  14. use OCP\Migration\SimpleMigrationStep;
  15. class Version2000Date20190808074233 extends SimpleMigrationStep {
  16. /**
  17. * @param IOutput $output
  18. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  19. * @param array $options
  20. * @return null|ISchemaWrapper
  21. */
  22. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
  23. /** @var ISchemaWrapper $schema */
  24. $schema = $schemaClosure();
  25. if (!$schema->hasTable('flow_checks')) {
  26. $table = $schema->createTable('flow_checks');
  27. $table->addColumn('id', Types::INTEGER, [
  28. 'autoincrement' => true,
  29. 'notnull' => true,
  30. 'length' => 4,
  31. ]);
  32. $table->addColumn('class', Types::STRING, [
  33. 'notnull' => true,
  34. 'length' => 256,
  35. 'default' => '',
  36. ]);
  37. $table->addColumn('operator', Types::STRING, [
  38. 'notnull' => true,
  39. 'length' => 16,
  40. 'default' => '',
  41. ]);
  42. $table->addColumn('value', Types::TEXT, [
  43. 'notnull' => false,
  44. ]);
  45. $table->addColumn('hash', Types::STRING, [
  46. 'notnull' => true,
  47. 'length' => 32,
  48. 'default' => '',
  49. ]);
  50. $table->setPrimaryKey(['id']);
  51. $table->addUniqueIndex(['hash'], 'flow_unique_hash');
  52. }
  53. if (!$schema->hasTable('flow_operations')) {
  54. $table = $schema->createTable('flow_operations');
  55. $table->addColumn('id', Types::INTEGER, [
  56. 'autoincrement' => true,
  57. 'notnull' => true,
  58. 'length' => 4,
  59. ]);
  60. $table->addColumn('class', Types::STRING, [
  61. 'notnull' => true,
  62. 'length' => 256,
  63. 'default' => '',
  64. ]);
  65. $table->addColumn('name', Types::STRING, [
  66. 'notnull' => false,
  67. 'length' => 256,
  68. 'default' => '',
  69. ]);
  70. $table->addColumn('checks', Types::TEXT, [
  71. 'notnull' => false,
  72. ]);
  73. $table->addColumn('operation', Types::TEXT, [
  74. 'notnull' => false,
  75. ]);
  76. $this->ensureEntityColumns($table);
  77. $table->setPrimaryKey(['id']);
  78. } else {
  79. $table = $schema->getTable('flow_operations');
  80. $this->ensureEntityColumns($table);
  81. }
  82. if (!$schema->hasTable('flow_operations_scope')) {
  83. $table = $schema->createTable('flow_operations_scope');
  84. $table->addColumn('id', Types::BIGINT, [
  85. 'autoincrement' => true,
  86. 'notnull' => true,
  87. 'length' => 4,
  88. ]);
  89. $table->addColumn('operation_id', Types::INTEGER, [
  90. 'notnull' => true,
  91. 'length' => 4,
  92. 'default' => 0,
  93. ]);
  94. $table->addColumn('type', Types::INTEGER, [
  95. 'notnull' => true,
  96. 'length' => 4,
  97. 'default' => 0,
  98. ]);
  99. $table->addColumn('value', Types::STRING, [
  100. 'notnull' => false,
  101. 'length' => 64,
  102. 'default' => '',
  103. ]);
  104. $table->setPrimaryKey(['id']);
  105. $table->addUniqueIndex(['operation_id', 'type', 'value'], 'flow_unique_scope');
  106. }
  107. return $schema;
  108. }
  109. protected function ensureEntityColumns(Table $table) {
  110. if (!$table->hasColumn('entity')) {
  111. $table->addColumn('entity', Types::STRING, [
  112. 'notnull' => true,
  113. 'length' => 256,
  114. 'default' => File::class,
  115. ]);
  116. }
  117. if (!$table->hasColumn('events')) {
  118. $table->addColumn('events', Types::TEXT, [
  119. 'notnull' => true,
  120. 'default' => '[]',
  121. ]);
  122. }
  123. }
  124. }