Skip to content

Commit

Permalink
fix: 主任务被删除或归档时子任务应该也同步
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Jan 6, 2022
1 parent c930e4d commit 24287c0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
12 changes: 8 additions & 4 deletions app/Models/ProjectTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,11 @@ public function archivedTask($archived_at, $isAuto = false)
$this->addLog($logText, $userid);
$this->pushMsg('archived');
}
self::whereParentId($this->id)->update([
'archived_at' => $this->archived_at,
'archived_userid' => $this->archived_userid,
'archived_follow' => $this->archived_follow,
]);
$this->save();
});
return true;
Expand All @@ -814,12 +819,11 @@ public function deleteTask($pushMsg = true)
AbstractModel::transaction(function () {
if ($this->dialog_id) {
$dialog = WebSocketDialog::find($this->dialog_id);
if ($dialog) {
$dialog->deleteDialog();
}
$dialog?->deleteDialog();
}
$this->delete();
self::whereParentId($this->id)->delete();
$this->addLog("删除{任务}:" . $this->name);
$this->delete();
});
if ($pushMsg) {
$this->pushMsg('delete');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class ProjectTasksUpdateSubtaskTime extends Migration
{
/**
* Run the migrations.
* 子任务同步主任务(任务时间)
*
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use App\Models\ProjectTask;
use Illuminate\Database\Migrations\Migration;

class ProjectTasksUpdateSubtaskArchivedDelete extends Migration
{
/**
* 子任务同步主任务(归档、删除)
*
* @return void
*/
public function up()
{
// 归档
ProjectTask::whereParentId(0)
->whereNotNull('archived_at')
->chunkById(100, function ($lists) {
/** @var ProjectTask $task */
foreach ($lists as $task) {
ProjectTask::whereParentId($task->id)->update([
'archived_at' => $task->archived_at,
'archived_userid' => $task->archived_userid,
'archived_follow' => $task->archived_follow,
]);
}
});

// 删除
ProjectTask::onlyTrashed()
->whereParentId(0)
->chunkById(100, function ($lists) {
/** @var ProjectTask $task */
foreach ($lists as $task) {
ProjectTask::whereParentId($task->id)->update([
'deleted_at' => $task->deleted_at,
]);
}
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

0 comments on commit 24287c0

Please sign in to comment.