Skip to content

Commit

Permalink
Merge pull request #25 from 42coders/delete_triggers_and_tasks_with_w…
Browse files Browse the repository at this point in the history
…orkflows

adding cascading delete to workflows.
  • Loading branch information
Max-Hutschenreiter committed Feb 21, 2022
2 parents 5a51f71 + d160390 commit f41b4b1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"php": "^7.2|^8.0",
"illuminate/support": "*",
"barryvdh/laravel-dompdf": "^0.9.0",
"guzzlehttp/guzzle": "^7"
"guzzlehttp/guzzle": "^7",
"doctrine/dbal": "^3"
},
"require-dev": {
"orchestra/testbench": "^5.2",
Expand Down
61 changes: 61 additions & 0 deletions database/migrations/2022_02_21_173228_update_cascade_delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class UpdateCascadeDelete extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table(config('workflows.db_prefix').'task_logs', function (Blueprint $table) {
$table->bigInteger('task_id')->unsigned()->change();
$table->foreign('task_id')->references('id')->on('tasks')->onDelete('cascade');
});

Schema::table(config('workflows.db_prefix').'tasks', function (Blueprint $table) {
$table->dropIndex(['workflow_id']);
$table->bigInteger('workflow_id')->unsigned()->change();
$table->foreign('workflow_id')->references('id')->on('workflows')->onDelete('cascade');
});

Schema::table(config('workflows.db_prefix').'triggers', function (Blueprint $table) {
$table->bigInteger('workflow_id')->unsigned()->change();
$table->foreign('workflow_id')->references('id')->on('workflows')->onDelete('cascade');
});

Schema::table(config('workflows.db_prefix').'workflow_logs', function (Blueprint $table) {
$table->bigInteger('workflow_id')->unsigned()->change();
$table->foreign('workflow_id')->references('id')->on('workflows')->onDelete('cascade');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table(config('workflows.db_prefix').'tasks', function (Blueprint $table) {
$table->dropForeign(['workflow_id']);
});

Schema::table(config('workflows.db_prefix').'triggers', function (Blueprint $table) {
$table->dropForeign(['workflow_id']);
});

Schema::table(config('workflows.db_prefix').'workflow_logs', function (Blueprint $table) {
$table->dropForeign(['workflow_id']);
});

Schema::table(config('workflows.db_prefix').'task_logs', function (Blueprint $table) {
$table->dropForeign(['task_id']);
});
}
}
7 changes: 6 additions & 1 deletion src/Http/Controllers/WorkflowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ public function update(Request $request, $id)
return redirect(route('workflow.index'));
}

/**
* Deletes the Workflow and over cascading also the Tasks, TaskLogs, WorkflowLogs and Triggers.
*
* @param $id
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function delete($id)
{
$workflow = Workflow::find($id);

//TODO: delete all depending tasks?
$workflow->delete();

return redirect(route('workflow.index'));
Expand Down

0 comments on commit f41b4b1

Please sign in to comment.