Skip to content

Instantly share code, notes, and snippets.

@marc-hanheide
Created November 16, 2018 14:24
Show Gist options
  • Select an option

  • Save marc-hanheide/12e6331620e289a8ca8b739afa497e8a to your computer and use it in GitHub Desktop.

Select an option

Save marc-hanheide/12e6331620e289a8ca8b739afa497e8a to your computer and use it in GitHub Desktop.
milestone merge in PGR system
<?php
$mt_name_old = "TDNAI (With Confirmation of Studies)"
$mt_name_new = "RDNAI (With Confirmation of Studies)"
// Get Old and New MilstoneType IDs
$mt_old = App\Models\MilestoneType::where('name', $mt_name_old )->withTrashed()->first();
$mt_new = App\Models\MilestoneType::where('name', $mt_name_new )->first();
// Get all Milestonesand Templates with the new ID
$ms = App\Models\Milestone::where('milestone_type_id', $mt_new->id)->withTrashed()->get();
$mst = App\Models\MilestoneTemplate::where('milestone_type_id', $mt_new->id)->withTrashed()->get();
// Go through and correct the milestones by changing all milestone_type_id with the new MilestoneType to the old one
$ms->each->update(['milestone_type_id' => $mt_old_id]);
$mst->each->update(['milestone_type_id' => $mt_old_id]);
// Then delete the new MilestoneType
$mt_new->forceDelete();
// Restore the old MilestoneType
$mt_old->restore();
// Finally renaming the old milestone to the new name (as it should have been in the first place)
$mt_old->update('name', $mt_name_new);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment