summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-07-28 15:33:01 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2019-07-29 00:58:02 +0200
commit62ed77ab25f8f2cf5103caf572079ebc2b50f6bc (patch)
tree8bd2e4b7b32a3389ca4e2e4ccbaee1168a2fed67 /db
parentbb45d460987032bedca6870df4386cfc4c01800f (diff)
Groups: Fix Naming and IDs
Diffstat (limited to 'db')
-rw-r--r--db/migrations/2019_07_21_000001_fix_old_groups_table_id_and_name.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/db/migrations/2019_07_21_000001_fix_old_groups_table_id_and_name.php b/db/migrations/2019_07_21_000001_fix_old_groups_table_id_and_name.php
new file mode 100644
index 00000000..044ba132
--- /dev/null
+++ b/db/migrations/2019_07_21_000001_fix_old_groups_table_id_and_name.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace Engelsystem\Migrations;
+
+use Engelsystem\Database\Migration\Migration;
+
+class FixOldGroupsTableIdAndName extends Migration
+{
+ /** @var array */
+ protected $naming = [
+ '1-Gast' => 'Guest',
+ '2-Engel' => 'Angel',
+ 'Shirt-Manager' => 'Shirt Manager',
+ '3-Shift Coordinator' => 'Shift Coordinator',
+ '4-Team Coordinator' => 'Team Coordinator',
+ '5-Bürokrat' => 'Bureaucrat',
+ '6-Developer' => 'Developer',
+ ];
+
+ /** @var array */
+ protected $ids = [
+ -65 => -80,
+ -70 => -90,
+ ];
+
+ /**
+ * Run the migration
+ */
+ public function up()
+ {
+ $this->migrate($this->naming, $this->ids);
+ }
+
+ /**
+ * Reverse the migration
+ */
+ public function down()
+ {
+ $this->migrate(array_flip($this->naming), array_flip($this->ids));
+ }
+
+ /**
+ * @param array $naming
+ * @param array $ids
+ */
+ protected function migrate($naming, $ids)
+ {
+ if (!$this->schema->hasTable('Groups')) {
+ return;
+ }
+
+ $connection = $this->schema->getConnection();
+ foreach ($connection->table('Groups')->get() as $data) {
+ if (isset($naming[$data->Name])) {
+ $data->Name = $naming[$data->Name];
+ }
+
+ $data->oldId = $data->UID;
+ if (isset($ids[$data->oldId])) {
+ $data->UID = $ids[$data->oldId];
+ } elseif (isset($ids[$data->oldId * -1])) {
+ $data->UID = $ids[$data->oldId * -1] * -1;
+ }
+
+ $connection
+ ->table('Groups')
+ ->where('UID', $data->oldId)
+ ->update([
+ 'UID' => $data->UID * -1,
+ 'Name' => $data->Name,
+ ]);
+ }
+ }
+}