forked from kuaifan/dootask
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
database/migrations/2022_01_06_132023_project_tasks_update_subtask_time.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
use App\Models\ProjectTask; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class ProjectTasksUpdateSubtaskTime extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
ProjectTask::where('parent_id', '>', 0) | ||
->whereNull('end_at') | ||
->chunkById(100, function ($lists) { | ||
/** @var ProjectTask $task */ | ||
foreach ($lists as $task) { | ||
$parent = ProjectTask::whereNotNull('end_at')->find($task->parent_id); | ||
if ($parent) { | ||
$task->start_at = $parent->start_at; | ||
$task->end_at = $parent->end_at; | ||
$task->save(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
// | ||
} | ||
} |