Version2000Date20190808074233.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OCA\WorkflowEngine\Migration;
  29. use Closure;
  30. use Doctrine\DBAL\Schema\Table;
  31. use OCP\DB\Types;
  32. use OCA\WorkflowEngine\Entity\File;
  33. use OCP\DB\ISchemaWrapper;
  34. use OCP\Migration\IOutput;
  35. use OCP\Migration\SimpleMigrationStep;
  36. class Version2000Date20190808074233 extends SimpleMigrationStep {
  37. /**
  38. * @param IOutput $output
  39. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  40. * @param array $options
  41. * @return null|ISchemaWrapper
  42. */
  43. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
  44. /** @var ISchemaWrapper $schema */
  45. $schema = $schemaClosure();
  46. if (!$schema->hasTable('flow_checks')) {
  47. $table = $schema->createTable('flow_checks');
  48. $table->addColumn('id', Types::INTEGER, [
  49. 'autoincrement' => true,
  50. 'notnull' => true,
  51. 'length' => 4,
  52. ]);
  53. $table->addColumn('class', Types::STRING, [
  54. 'notnull' => true,
  55. 'length' => 256,
  56. 'default' => '',
  57. ]);
  58. $table->addColumn('operator', Types::STRING, [
  59. 'notnull' => true,
  60. 'length' => 16,
  61. 'default' => '',
  62. ]);
  63. $table->addColumn('value', Types::TEXT, [
  64. 'notnull' => false,
  65. ]);
  66. $table->addColumn('hash', Types::STRING, [
  67. 'notnull' => true,
  68. 'length' => 32,
  69. 'default' => '',
  70. ]);
  71. $table->setPrimaryKey(['id']);
  72. $table->addUniqueIndex(['hash'], 'flow_unique_hash');
  73. }
  74. if (!$schema->hasTable('flow_operations')) {
  75. $table = $schema->createTable('flow_operations');
  76. $table->addColumn('id', Types::INTEGER, [
  77. 'autoincrement' => true,
  78. 'notnull' => true,
  79. 'length' => 4,
  80. ]);
  81. $table->addColumn('class', Types::STRING, [
  82. 'notnull' => true,
  83. 'length' => 256,
  84. 'default' => '',
  85. ]);
  86. $table->addColumn('name', Types::STRING, [
  87. 'notnull' => false,
  88. 'length' => 256,
  89. 'default' => '',
  90. ]);
  91. $table->addColumn('checks', Types::TEXT, [
  92. 'notnull' => false,
  93. ]);
  94. $table->addColumn('operation', Types::TEXT, [
  95. 'notnull' => false,
  96. ]);
  97. $this->ensureEntityColumns($table);
  98. $table->setPrimaryKey(['id']);
  99. } else {
  100. $table = $schema->getTable('flow_operations');
  101. $this->ensureEntityColumns($table);
  102. }
  103. if (!$schema->hasTable('flow_operations_scope')) {
  104. $table = $schema->createTable('flow_operations_scope');
  105. $table->addColumn('id', Types::BIGINT, [
  106. 'autoincrement' => true,
  107. 'notnull' => true,
  108. 'length' => 4,
  109. ]);
  110. $table->addColumn('operation_id', Types::INTEGER, [
  111. 'notnull' => true,
  112. 'length' => 4,
  113. 'default' => 0,
  114. ]);
  115. $table->addColumn('type', Types::INTEGER, [
  116. 'notnull' => true,
  117. 'length' => 4,
  118. 'default' => 0,
  119. ]);
  120. $table->addColumn('value', Types::STRING, [
  121. 'notnull' => false,
  122. 'length' => 64,
  123. 'default' => '',
  124. ]);
  125. $table->setPrimaryKey(['id']);
  126. $table->addUniqueIndex(['operation_id', 'type', 'value'], 'flow_unique_scope');
  127. }
  128. return $schema;
  129. }
  130. protected function ensureEntityColumns(Table $table) {
  131. if (!$table->hasColumn('entity')) {
  132. $table->addColumn('entity', Types::STRING, [
  133. 'notnull' => true,
  134. 'length' => 256,
  135. 'default' => File::class,
  136. ]);
  137. }
  138. if (!$table->hasColumn('events')) {
  139. $table->addColumn('events', Types::TEXT, [
  140. 'notnull' => true,
  141. 'default' => '[]',
  142. ]);
  143. }
  144. }
  145. }