From 2ce7e3e50a70af6de65b69dac8ebca78a24dc7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Tue, 25 Apr 2023 10:50:17 +0300 Subject: [PATCH] Add new listener for 3.0.14 --- app/Listeners/Update/V30/Version3013.php | 41 +------------- app/Listeners/Update/V30/Version3014.php | 71 ++++++++++++++++++++++++ app/Providers/Event.php | 1 + 3 files changed, 74 insertions(+), 39 deletions(-) create mode 100644 app/Listeners/Update/V30/Version3014.php diff --git a/app/Listeners/Update/V30/Version3013.php b/app/Listeners/Update/V30/Version3013.php index 4bda06ab4..dc82ed46a 100644 --- a/app/Listeners/Update/V30/Version3013.php +++ b/app/Listeners/Update/V30/Version3013.php @@ -4,14 +4,11 @@ namespace App\Listeners\Update\V30; use App\Abstracts\Listeners\Update as Listener; use App\Events\Install\UpdateFinished as Event; -use App\Traits\Categories; -use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Log; class Version3013 extends Listener { - use Categories; - const ALIAS = 'core'; const VERSION = '3.0.13'; @@ -30,42 +27,8 @@ class Version3013 extends Listener Log::channel('stdout')->info('Updating to 3.0.13 version...'); - DB::transaction(function () { - $types = $this->getTypesByAllowedTranslations(); - - foreach ($types as $type => $translations) { - DB::table('categories')->whereIn('type', $translations)->update(['type' => $type]); - } - }); + Artisan::call('cache:clear'); Log::channel('stdout')->info('Done!'); } - - protected function getTypesByAllowedTranslations(): array - { - $types = $this->getCategoryTypes(false); - $lang_codes = array_keys(language()->allowed()); - - foreach ($types as $type => $trans_name) { - $translations_for_type = []; - - foreach ($lang_codes as $lang_code) { - $translation = trans_choice($trans_name, 1, locale: $lang_code); - - if ($translation === $trans_name) { - continue; - } - - $translations_for_type[] = $translation; - } - - $types[$type] = $translations_for_type; - } - - /** - * Example: en-GB es-ES - * 'income' => ['Income', 'Ingresos'] - */ - return $types; - } } diff --git a/app/Listeners/Update/V30/Version3014.php b/app/Listeners/Update/V30/Version3014.php new file mode 100644 index 000000000..f422a7b17 --- /dev/null +++ b/app/Listeners/Update/V30/Version3014.php @@ -0,0 +1,71 @@ +skipThisUpdate($event)) { + return; + } + + Log::channel('stdout')->info('Updating to 3.0.14 version...'); + + DB::transaction(function () { + $types = $this->getTypesByAllowedTranslations(); + + foreach ($types as $type => $translations) { + DB::table('categories')->whereIn('type', $translations)->update(['type' => $type]); + } + }); + + Log::channel('stdout')->info('Done!'); + } + + protected function getTypesByAllowedTranslations(): array + { + $types = $this->getCategoryTypes(false); + $lang_codes = array_keys(language()->allowed()); + + foreach ($types as $type => $trans_name) { + $translations_for_type = []; + + foreach ($lang_codes as $lang_code) { + $translation = trans_choice($trans_name, 1, locale: $lang_code); + + if ($translation === $trans_name) { + continue; + } + + $translations_for_type[] = $translation; + } + + $types[$type] = $translations_for_type; + } + + /** + * Example: en-GB es-ES + * 'income' => ['Income', 'Ingresos'] + */ + return $types; + } +} diff --git a/app/Providers/Event.php b/app/Providers/Event.php index 1049d0268..13c2b36ad 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -22,6 +22,7 @@ class Event extends Provider 'App\Listeners\Update\V30\Version307', 'App\Listeners\Update\V30\Version309', 'App\Listeners\Update\V30\Version3013', + 'App\Listeners\Update\V30\Version3014', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login',