summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-11-27 23:43:21 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2019-12-08 02:20:48 +0100
commit42721e95726559b4a601240bb5b0fe4e5d755b2a (patch)
tree6810e05f845ca787acc1d02fa82d3df15cd0ef9b /db
parent377b390c97afb9106fd9a139819d00306f996f24 (diff)
Added Schedule parsing and replaced old Fahrplan importer
Resolves #553 (Change Frab Import from xCal to XML) Resolves #538 (Feature Request: Multi Frab Import)
Diffstat (limited to 'db')
-rw-r--r--db/migrations/2019_09_07_000000_migrate_admin_schedule_permissions.php48
-rw-r--r--db/migrations/2019_09_07_000001_create_schedule_shift_table.php90
-rw-r--r--db/migrations/Reference.php22
3 files changed, 152 insertions, 8 deletions
diff --git a/db/migrations/2019_09_07_000000_migrate_admin_schedule_permissions.php b/db/migrations/2019_09_07_000000_migrate_admin_schedule_permissions.php
new file mode 100644
index 00000000..e39e22d8
--- /dev/null
+++ b/db/migrations/2019_09_07_000000_migrate_admin_schedule_permissions.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Engelsystem\Migrations;
+
+use Engelsystem\Database\Migration\Migration;
+
+class MigrateAdminSchedulePermissions extends Migration
+{
+ /**
+ * Run the migration
+ */
+ public function up()
+ {
+ if (!$this->schema->hasTable('Privileges')) {
+ return;
+ }
+
+ $this->schema->getConnection()
+ ->table('Privileges')
+ ->where('name', 'admin_import')
+ ->update(
+ [
+ 'name' => 'schedule.import',
+ 'desc' => 'Import rooms and shifts from schedule.xml',
+ ]
+ );
+ }
+
+ /**
+ * Reverse the migration
+ */
+ public function down()
+ {
+ if (!$this->schema->hasTable('Privileges')) {
+ return;
+ }
+
+ $this->schema->getConnection()
+ ->table('Privileges')
+ ->where('name', 'schedule.import')
+ ->update(
+ [
+ 'name' => 'admin_import',
+ 'desc' => 'Import rooms and shifts from schedule.xcs/schedule.xcal',
+ ]
+ );
+ }
+}
diff --git a/db/migrations/2019_09_07_000001_create_schedule_shift_table.php b/db/migrations/2019_09_07_000001_create_schedule_shift_table.php
new file mode 100644
index 00000000..c9cd7cfe
--- /dev/null
+++ b/db/migrations/2019_09_07_000001_create_schedule_shift_table.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace Engelsystem\Migrations;
+
+use Engelsystem\Database\Migration\Migration;
+use Illuminate\Database\Schema\Blueprint;
+
+class CreateScheduleShiftTable extends Migration
+{
+ use Reference;
+
+ /**
+ * Run the migration
+ */
+ public function up()
+ {
+ $this->schema->create(
+ 'schedules',
+ function (Blueprint $table) {
+ $table->increments('id');
+ $table->string('url');
+ }
+ );
+
+ $this->schema->create(
+ 'schedule_shift',
+ function (Blueprint $table) {
+ $table->integer('shift_id')->index()->unique();
+ if ($this->schema->hasTable('Shifts')) {
+ // Legacy table access
+ $table->foreign('shift_id')
+ ->references('SID')->on('Shifts')
+ ->onUpdate('cascade')
+ ->onDelete('cascade');
+ }
+
+ $this->references($table, 'schedules');
+ $table->uuid('guid');
+ }
+ );
+
+ if ($this->schema->hasTable('Shifts')) {
+ $this->schema->table(
+ 'Shifts',
+ function (Blueprint $table) {
+ $table->dropColumn('PSID');
+ }
+ );
+ }
+
+ if ($this->schema->hasTable('Room')) {
+ $this->schema->table(
+ 'Room',
+ function (Blueprint $table) {
+ $table->dropColumn('from_frab');
+ }
+ );
+ }
+ }
+
+ /**
+ * Reverse the migration
+ */
+ public function down()
+ {
+ if ($this->schema->hasTable('Room')) {
+ $this->schema->table(
+ 'Room',
+ function (Blueprint $table) {
+ $table->boolean('from_frab')
+ ->default(false);
+ }
+ );
+ }
+
+ if ($this->schema->hasTable('Shifts')) {
+ $this->schema->table(
+ 'Shifts',
+ function (Blueprint $table) {
+ $table->integer('PSID')
+ ->nullable()->default(null)
+ ->unique();
+ }
+ );
+ }
+
+ $this->schema->drop('schedule_shift');
+ $this->schema->drop('schedules');
+ }
+}
diff --git a/db/migrations/Reference.php b/db/migrations/Reference.php
index 49a1f9ea..d0550686 100644
--- a/db/migrations/Reference.php
+++ b/db/migrations/Reference.php
@@ -4,6 +4,7 @@ namespace Engelsystem\Migrations;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\ColumnDefinition;
+use Illuminate\Support\Str;
trait Reference
{
@@ -11,20 +12,25 @@ trait Reference
* @param Blueprint $table
* @param bool $setPrimary
*/
- protected function referencesUser(Blueprint $table, $setPrimary = false)
+ protected function referencesUser(Blueprint $table, bool $setPrimary = false)
{
- $this->references($table, 'users', 'user_id', $setPrimary);
+ $this->references($table, 'users', null, $setPrimary);
}
/**
- * @param Blueprint $table
- * @param string $targetTable
- * @param string $fromColumn
- * @param bool $setPrimary
+ * @param Blueprint $table
+ * @param string $targetTable
+ * @param string|null $fromColumn
+ * @param bool $setPrimary
* @return ColumnDefinition
*/
- protected function references(Blueprint $table, $targetTable, $fromColumn, $setPrimary = false): ColumnDefinition
- {
+ protected function references(
+ Blueprint $table,
+ string $targetTable,
+ ?string $fromColumn = null,
+ bool $setPrimary = false
+ ): ColumnDefinition {
+ $fromColumn = $fromColumn ?? Str::singular($targetTable) . '_id';
$col = $table->unsignedInteger($fromColumn);
if ($setPrimary) {