diff --git a/community_server/db/skeema/gradido_community/migrations.sql b/community_server/db/skeema/gradido_community/migrations.sql new file mode 100644 index 000000000..7665bcf29 --- /dev/null +++ b/community_server/db/skeema/gradido_community/migrations.sql @@ -0,0 +1,5 @@ +CREATE TABLE `migrations` ( + `id` int UNSIGNED NOT NULL AUTO_INCREMENT, + `db_version` int DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/src/Controller/MigrationsController.php b/community_server/src/Controller/MigrationsController.php new file mode 100644 index 000000000..93a1b8044 --- /dev/null +++ b/community_server/src/Controller/MigrationsController.php @@ -0,0 +1,106 @@ +paginate($this->Migrations); + + $this->set(compact('migrations')); + } + + /** + * View method + * + * @param string|null $id Migration id. + * @return \Cake\Http\Response|null + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function view($id = null) + { + $migration = $this->Migrations->get($id, [ + 'contain' => [], + ]); + + $this->set('migration', $migration); + } + + /** + * Add method + * + * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise. + */ + public function add() + { + $migration = $this->Migrations->newEntity(); + if ($this->request->is('post')) { + $migration = $this->Migrations->patchEntity($migration, $this->request->getData()); + if ($this->Migrations->save($migration)) { + $this->Flash->success(__('The migration has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The migration could not be saved. Please, try again.')); + } + $this->set(compact('migration')); + } + + /** + * Edit method + * + * @param string|null $id Migration id. + * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function edit($id = null) + { + $migration = $this->Migrations->get($id, [ + 'contain' => [], + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $migration = $this->Migrations->patchEntity($migration, $this->request->getData()); + if ($this->Migrations->save($migration)) { + $this->Flash->success(__('The migration has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The migration could not be saved. Please, try again.')); + } + $this->set(compact('migration')); + } + + /** + * Delete method + * + * @param string|null $id Migration id. + * @return \Cake\Http\Response|null Redirects to index. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function delete($id = null) + { + $this->request->allowMethod(['post', 'delete']); + $migration = $this->Migrations->get($id); + if ($this->Migrations->delete($migration)) { + $this->Flash->success(__('The migration has been deleted.')); + } else { + $this->Flash->error(__('The migration could not be deleted. Please, try again.')); + } + + return $this->redirect(['action' => 'index']); + } +} diff --git a/community_server/src/Model/Entity/Migration.php b/community_server/src/Model/Entity/Migration.php new file mode 100644 index 000000000..700136cf8 --- /dev/null +++ b/community_server/src/Model/Entity/Migration.php @@ -0,0 +1,26 @@ + true, + ]; +} diff --git a/community_server/src/Model/Table/MigrationsTable.php b/community_server/src/Model/Table/MigrationsTable.php new file mode 100644 index 000000000..b5cb42154 --- /dev/null +++ b/community_server/src/Model/Table/MigrationsTable.php @@ -0,0 +1,56 @@ +setTable('migrations'); + $this->setDisplayField('id'); + $this->setPrimaryKey('id'); + } + + /** + * Default validation rules. + * + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator + */ + public function validationDefault(Validator $validator) + { + $validator + ->nonNegativeInteger('id') + ->allowEmptyString('id', null, 'create'); + + $validator + ->integer('db_version') + ->allowEmptyString('db_version'); + + return $validator; + } +} diff --git a/community_server/src/Template/Migrations/add.ctp b/community_server/src/Template/Migrations/add.ctp new file mode 100644 index 000000000..94a555733 --- /dev/null +++ b/community_server/src/Template/Migrations/add.ctp @@ -0,0 +1,23 @@ + + +
+ Form->create($migration) ?> +
+ + Form->control('db_version'); + ?> +
+ Form->button(__('Submit')) ?> + Form->end() ?> +
diff --git a/community_server/src/Template/Migrations/edit.ctp b/community_server/src/Template/Migrations/edit.ctp new file mode 100644 index 000000000..1e916afa1 --- /dev/null +++ b/community_server/src/Template/Migrations/edit.ctp @@ -0,0 +1,29 @@ + + +
+ Form->create($migration) ?> +
+ + Form->control('db_version'); + ?> +
+ Form->button(__('Submit')) ?> + Form->end() ?> +
diff --git a/community_server/src/Template/Migrations/index.ctp b/community_server/src/Template/Migrations/index.ctp new file mode 100644 index 000000000..9d755ecff --- /dev/null +++ b/community_server/src/Template/Migrations/index.ctp @@ -0,0 +1,47 @@ + + +
+

+ + + + + + + + + + + + + + + + + +
Paginator->sort('id') ?>Paginator->sort('db_version') ?>
Number->format($migration->id) ?>Number->format($migration->db_version) ?> + Html->link(__('View'), ['action' => 'view', $migration->id]) ?> + Html->link(__('Edit'), ['action' => 'edit', $migration->id]) ?> + Form->postLink(__('Delete'), ['action' => 'delete', $migration->id], ['confirm' => __('Are you sure you want to delete # {0}?', $migration->id)]) ?> +
+
+ +

Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')]) ?>

+
+
diff --git a/community_server/src/Template/Migrations/view.ctp b/community_server/src/Template/Migrations/view.ctp new file mode 100644 index 000000000..dc4c5ded3 --- /dev/null +++ b/community_server/src/Template/Migrations/view.ctp @@ -0,0 +1,28 @@ + + +
+

id) ?>

+ + + + + + + + + +
Number->format($migration->id) ?>
Number->format($migration->db_version) ?>
+
diff --git a/community_server/tests/Fixture/MigrationsFixture.php b/community_server/tests/Fixture/MigrationsFixture.php new file mode 100644 index 000000000..1fab6a133 --- /dev/null +++ b/community_server/tests/Fixture/MigrationsFixture.php @@ -0,0 +1,44 @@ + ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], + 'db_version' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => true, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null], + '_constraints' => [ + 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], + ], + '_options' => [ + 'engine' => 'InnoDB', + 'collation' => 'utf8mb4_unicode_ci' + ], + ]; + // @codingStandardsIgnoreEnd + /** + * Init method + * + * @return void + */ + public function init() + { + $this->records = [ + [ + 'id' => 1, + 'db_version' => 1, + ], + ]; + parent::init(); + } +} diff --git a/community_server/tests/TestCase/Controller/MigrationsControllerTest.php b/community_server/tests/TestCase/Controller/MigrationsControllerTest.php new file mode 100644 index 000000000..4bb794d4d --- /dev/null +++ b/community_server/tests/TestCase/Controller/MigrationsControllerTest.php @@ -0,0 +1,75 @@ +markTestIncomplete('Not implemented yet.'); + } + + /** + * Test view method + * + * @return void + */ + public function testView() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test add method + * + * @return void + */ + public function testAdd() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test edit method + * + * @return void + */ + public function testEdit() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test delete method + * + * @return void + */ + public function testDelete() + { + $this->markTestIncomplete('Not implemented yet.'); + } +} diff --git a/community_server/tests/TestCase/Model/Table/MigrationsTableTest.php b/community_server/tests/TestCase/Model/Table/MigrationsTableTest.php new file mode 100644 index 000000000..f88893585 --- /dev/null +++ b/community_server/tests/TestCase/Model/Table/MigrationsTableTest.php @@ -0,0 +1,72 @@ +exists('Migrations') ? [] : ['className' => MigrationsTable::class]; + $this->Migrations = TableRegistry::getTableLocator()->get('Migrations', $config); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() + { + unset($this->Migrations); + + parent::tearDown(); + } + + /** + * Test initialize method + * + * @return void + */ + public function testInitialize() + { + $this->markTestIncomplete('Not implemented yet.'); + } + + /** + * Test validationDefault method + * + * @return void + */ + public function testValidationDefault() + { + $this->markTestIncomplete('Not implemented yet.'); + } +}