diff --git a/app/Initialize/Actions/InitializeAction.php b/app/Initialize/Actions/InitializeAction.php index d2182ffa..5980e76e 100644 --- a/app/Initialize/Actions/InitializeAction.php +++ b/app/Initialize/Actions/InitializeAction.php @@ -60,6 +60,6 @@ class InitializeAction (int) $request->input('group_id', 0) ); - return redirect()->route('home'); + return redirect()->route('home')->success('Initialisierung beauftragt. Wir benachrichtigen dich per Mail wenn alles fertig ist.'); } } diff --git a/app/Initialize/InitializeActivities.php b/app/Initialize/InitializeActivities.php index fc7601aa..f1fe452c 100644 --- a/app/Initialize/InitializeActivities.php +++ b/app/Initialize/InitializeActivities.php @@ -2,6 +2,7 @@ namespace App\Initialize; +use DB; use Zoomyboy\LaravelNami\Api; class InitializeActivities @@ -18,4 +19,11 @@ class InitializeActivities $groupId = $this->api->groups()->first()->id; app(ActivityCreator::class)->createFor($this->api, $groupId); } + + public function restore(): void + { + DB::table('activity_subactivity')->delete(); + DB::table('activities')->delete(); + DB::table('subactivities')->delete(); + } } diff --git a/app/Initialize/InitializeConfessions.php b/app/Initialize/InitializeConfessions.php index fd32488d..1de9f592 100644 --- a/app/Initialize/InitializeConfessions.php +++ b/app/Initialize/InitializeConfessions.php @@ -3,6 +3,7 @@ namespace App\Initialize; use App\Confession; +use DB; use Zoomyboy\LaravelNami\Api; class InitializeConfessions @@ -21,4 +22,9 @@ class InitializeConfessions Confession::create(['nami_id' => $confession->id, 'name' => $confession->name, 'is_null' => $this->nullName === $confession->name]); }); } + + public function restore(): void + { + DB::table('confessions')->delete(); + } } diff --git a/app/Initialize/InitializeCountries.php b/app/Initialize/InitializeCountries.php index e7a5785a..7134d31f 100644 --- a/app/Initialize/InitializeCountries.php +++ b/app/Initialize/InitializeCountries.php @@ -2,6 +2,7 @@ namespace App\Initialize; +use DB; use Zoomyboy\LaravelNami\Api; class InitializeCountries @@ -19,4 +20,9 @@ class InitializeCountries \App\Country::create(['nami_id' => $country->id, 'name' => $country->name]); }); } + + public function restore(): void + { + DB::table('countries')->delete(); + } } diff --git a/app/Initialize/InitializeCourses.php b/app/Initialize/InitializeCourses.php index 137feb49..fe6f7d2b 100644 --- a/app/Initialize/InitializeCourses.php +++ b/app/Initialize/InitializeCourses.php @@ -3,6 +3,7 @@ namespace App\Initialize; use App\Course\Models\Course; +use DB; use Zoomyboy\LaravelNami\Api; class InitializeCourses @@ -20,4 +21,9 @@ class InitializeCourses Course::create(['nami_id' => $course->id, 'name' => $course->name]); }); } + + public function restore(): void + { + DB::table('courses')->delete(); + } } diff --git a/app/Initialize/InitializeFees.php b/app/Initialize/InitializeFees.php index d711d457..111912a6 100644 --- a/app/Initialize/InitializeFees.php +++ b/app/Initialize/InitializeFees.php @@ -3,6 +3,7 @@ namespace App\Initialize; use App\Fee; +use DB; use Zoomyboy\LaravelNami\Api; class InitializeFees @@ -25,4 +26,10 @@ class InitializeFees ]); }); } + + public function restore(): void + { + DB::table('subscriptions')->delete(); + DB::table('fees')->delete(); + } } diff --git a/app/Initialize/InitializeGenders.php b/app/Initialize/InitializeGenders.php index 607ad55c..992964f9 100644 --- a/app/Initialize/InitializeGenders.php +++ b/app/Initialize/InitializeGenders.php @@ -2,6 +2,7 @@ namespace App\Initialize; +use DB; use Zoomyboy\LaravelNami\Api; class InitializeGenders @@ -19,4 +20,9 @@ class InitializeGenders \App\Gender::create(['nami_id' => $gender->id, 'name' => $gender->name]); }); } + + public function restore(): void + { + DB::table('genders')->delete(); + } } diff --git a/app/Initialize/InitializeGroups.php b/app/Initialize/InitializeGroups.php index 23ef9113..d4023b11 100644 --- a/app/Initialize/InitializeGroups.php +++ b/app/Initialize/InitializeGroups.php @@ -3,6 +3,7 @@ namespace App\Initialize; use App\Group; +use DB; use Zoomyboy\LaravelNami\Api; class InitializeGroups @@ -30,4 +31,9 @@ class InitializeGroups $this->syncChildren($subgroup->id, $newParent); }); } + + public function restore(): void + { + DB::table('groups')->delete(); + } } diff --git a/app/Initialize/InitializeJob.php b/app/Initialize/InitializeJob.php index 3b06448f..8c749f82 100644 --- a/app/Initialize/InitializeJob.php +++ b/app/Initialize/InitializeJob.php @@ -2,6 +2,7 @@ namespace App\Initialize; +use Exception; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -24,4 +25,9 @@ class InitializeJob implements ShouldQueue { app(Initializer::class)->run(); } + + public function failed(Exception $e): void + { + app(Initializer::class)->restore(); + } } diff --git a/app/Initialize/InitializeMembers.php b/app/Initialize/InitializeMembers.php index 69093928..7b11ff52 100644 --- a/app/Initialize/InitializeMembers.php +++ b/app/Initialize/InitializeMembers.php @@ -3,6 +3,7 @@ namespace App\Initialize; use App\Actions\MemberPullAction; +use DB; use Zoomyboy\LaravelNami\Api; use Zoomyboy\LaravelNami\Member as NamiMember; @@ -23,4 +24,12 @@ class InitializeMembers fn (NamiMember $member) => app(MemberPullAction::class)->api($this->api)->member($member->group_id, $member->id)->execute() ); } + + public function restore(): void + { + DB::table('payments')->delete(); + DB::table('course_members')->delete(); + DB::table('memberships')->delete(); + DB::table('members')->delete(); + } } diff --git a/app/Initialize/InitializeNationalities.php b/app/Initialize/InitializeNationalities.php index e8321707..09fceb5e 100644 --- a/app/Initialize/InitializeNationalities.php +++ b/app/Initialize/InitializeNationalities.php @@ -3,6 +3,7 @@ namespace App\Initialize; use App\Nationality; +use DB; use Zoomyboy\LaravelNami\Api; class InitializeNationalities @@ -20,4 +21,9 @@ class InitializeNationalities Nationality::create(['nami_id' => $nationality->id, 'name' => $nationality->name]); }); } + + public function restore(): void + { + DB::table('nationalities')->delete(); + } } diff --git a/app/Initialize/InitializeRegions.php b/app/Initialize/InitializeRegions.php index c566be38..42114fee 100644 --- a/app/Initialize/InitializeRegions.php +++ b/app/Initialize/InitializeRegions.php @@ -2,6 +2,7 @@ namespace App\Initialize; +use DB; use Zoomyboy\LaravelNami\Api; class InitializeRegions @@ -20,4 +21,9 @@ class InitializeRegions \App\Region::create(['nami_id' => $region->id, 'name' => $region->name, 'is_null' => $region->name == $this->nullName]); }); } + + public function restore(): void + { + DB::table('regions')->delete(); + } } diff --git a/app/Initialize/Initializer.php b/app/Initialize/Initializer.php index 25220964..b7c7895f 100644 --- a/app/Initialize/Initializer.php +++ b/app/Initialize/Initializer.php @@ -8,6 +8,9 @@ class Initializer { public NamiSettings $settings; + /** + * @var array + */ public array $initializers = [ InitializeGroups::class, InitializeNationalities::class, @@ -32,4 +35,17 @@ class Initializer app($initializer)->handle($this->settings->login()); } } + + public function restore(): void + { + foreach (array_reverse($this->initializers) as $initializer) { + app($initializer)->restore(); + } + + $settings = app(NamiSettings::class); + $settings->mglnr = 0; + $settings->password = ''; + $settings->default_group_id = 0; + $settings->save(); + } }