-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
3 changed files
with
42 additions
and
40 deletions.
There are no files selected for viewing
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
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
35 changes: 35 additions & 0 deletions
35
app/Platform/Actions/SyncEventAchievementMetadataAction.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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Platform\Actions; | ||
|
||
use App\Models\Achievement; | ||
use App\Models\EventAchievement; | ||
|
||
class SyncEventAchievementMetadataAction | ||
{ | ||
/* Syncs metadata from an achievement to any event achievements | ||
* referencing the achievement. | ||
* NOTE: This logic relies on passing a dirty achievement (modified but not yet saved). | ||
*/ | ||
public function execute(Achievement $achievement): void | ||
{ | ||
if ($achievement->isDirty('BadgeName') | ||
|| $achievement->isDirty('Title') | ||
|| $achievement->isDirty('Description')) { | ||
|
||
$eventAchievements = EventAchievement::with(['achievement']) | ||
->where('source_achievement_id', $achievement->id) | ||
->active() | ||
->get(); | ||
|
||
foreach ($eventAchievements as $eventAchievement) { | ||
$eventAchievement->achievement->BadgeName = $achievement->BadgeName; | ||
$eventAchievement->achievement->Title = $achievement->Title; | ||
$eventAchievement->achievement->Description = $achievement->Description; | ||
$eventAchievement->achievement->save(); | ||
} | ||
} | ||
} | ||
} |