summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-12-30 15:12:00 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2018-12-30 15:12:00 +0100
commit5a912a0f7e9673c958745e2c670d9636002f758a (patch)
treed8d64e4c1d5f31cad8cdf086cf23a7c192510895
parent99126cab0c1d272d86be175923583105eee549d3 (diff)
migration: Add shiftentry_edit_angeltype_supporter permission to angels
-rw-r--r--db/migrations/2018_01_01_000005_add_angel_supporter_permissions.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/db/migrations/2018_01_01_000005_add_angel_supporter_permissions.php b/db/migrations/2018_01_01_000005_add_angel_supporter_permissions.php
new file mode 100644
index 00000000..b9d4cdc2
--- /dev/null
+++ b/db/migrations/2018_01_01_000005_add_angel_supporter_permissions.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Engelsystem\Migrations;
+
+use Engelsystem\Database\Migration\Migration;
+
+class AddAngelSupporterPermissions extends Migration
+{
+ /** @var string[] */
+ protected $data = [
+ '2-Engel',
+ 'shiftentry_edit_angeltype_supporter',
+ ];
+
+ /**
+ * Run the migration
+ */
+ public function up()
+ {
+ if (!$this->schema->hasTable('GroupPrivileges')) {
+ return;
+ }
+
+ $db = $this->schema->getConnection();
+ if (!empty($db->select($this->getQuery('SELECT *'), $this->data))) {
+ return;
+ }
+
+ // Add permissions to angels to edit angels if they are angeltype supporters
+ $db->insert(
+ '
+ INSERT IGNORE INTO GroupPrivileges (group_id, privilege_id)
+ VALUES ((SELECT UID FROM `Groups` WHERE `name` = ?), (SELECT id FROM `Privileges` WHERE `name` = ?))
+ ',
+ $this->data
+ );
+ }
+
+ /**
+ * Reverse the migration
+ */
+ public function down()
+ {
+ if (!$this->schema->hasTable('GroupPrivileges')) {
+ return;
+ }
+
+ // Remove permission from angels
+ $this->schema->getConnection()->delete(
+ $this->getQuery('DELETE'),
+ $this->data
+ );
+ }
+
+ /**
+ * @param string $type
+ * @return string
+ */
+ protected function getQuery($type)
+ {
+ return sprintf('
+ %s FROM GroupPrivileges
+ WHERE group_id = (SELECT UID FROM `Groups` WHERE `name` = ?)
+ AND privilege_id = (SELECT id FROM `Privileges` WHERE `name` = ?)
+ ', $type);
+ }
+}