From cb65aba6c985073065ab51ac5abbd9a59130a02e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 28 Jun 2023 15:58:50 +0200 Subject: [PATCH 1/3] Update artisan user:create command (cherry picked from commit e6cf237fa4ba116b1cb57a496a2fee00ecea6f97) --- app/Console/Commands/CreateAdmin.php | 102 +++++++++++++++++++++++++++ app/Console/Commands/UserCreate.php | 50 ------------- app/Models/User.php | 27 ++++++- 3 files changed, 128 insertions(+), 51 deletions(-) create mode 100644 app/Console/Commands/CreateAdmin.php delete mode 100644 app/Console/Commands/UserCreate.php diff --git a/app/Console/Commands/CreateAdmin.php b/app/Console/Commands/CreateAdmin.php new file mode 100644 index 0000000..5b6d448 --- /dev/null +++ b/app/Console/Commands/CreateAdmin.php @@ -0,0 +1,102 @@ +ask('Type the wanted user email', 'equipe.web@ldc.fr'); + $validator = Validator::make(['email' => $tmp], [ + 'email' => 'required|unique:users,email|email:rfc,dns' + ]); + $validator->validate(); + $email = $tmp; + } catch (ValidationException $e) { + $this->error(sprintf( + 'Please provide a valid email %s', + \implode(',', collect($e->errors())->flatten()->all()) + )); + continue; + } + } + $firstname = null; + while (is_null($firstname)) { + try { + $tmp = $this->ask('Type the wanted user firstname', 'Admin'); + $validator = Validator::make(['firstname' => $tmp], [ + 'firstname' => 'required|min:5,max:255' + ]); + $validator->validate(); + $firstname = $tmp; + } catch (ValidationException $e) { + $this->error(sprintf( + 'Please provide a valid firstname %s', + \implode(',', collect($e->errors())->flatten()->all()) + )); + continue; + } + } + + $lastname = null; + while (is_null($lastname)) { + try { + $tmp = $this->ask('Type the wanted user lastname', 'Saïtama'); + $validator = Validator::make(['lastname' => $tmp], [ + 'lastname' => 'required|min:5,max:255' + ]); + $validator->validate(); + $lastname = $tmp; + } catch (ValidationException $e) { + $this->error(sprintf( + 'Please provide a valid lastname %s', + \implode(',', collect($e->errors())->flatten()->all()) + )); + continue; + } + } + + $password = $this->secret('Type the wanted user password'); + + $admin = new User([ + 'lastname' => $lastname, + 'firstname' => $firstname, + 'email' => $email, + 'password' => $password + ]); + $admin->saveOrFail(); + + $this->info('User created.'); + return 0; + } +} diff --git a/app/Console/Commands/UserCreate.php b/app/Console/Commands/UserCreate.php deleted file mode 100644 index a198eda..0000000 --- a/app/Console/Commands/UserCreate.php +++ /dev/null @@ -1,50 +0,0 @@ -ask('What is the firstname?'); - $lastname = $this->ask('What is the lastname?'); - $email = $this->ask('What is the email?'); - $pwd = $this->secret('What is the password?'); - - $user = new User(); - $user->firstname = $firstname; - $user->lastname = $lastname; - $user->email = $email; - $user->password = Hash::make($pwd); - $user->save(); - - $this->info('User created.'); - return 0; - } -} diff --git a/app/Models/User.php b/app/Models/User.php index 6232f42..244c32e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -5,6 +5,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Str; class User extends Authenticatable { @@ -17,7 +19,8 @@ class User extends Authenticatable * @var array */ protected $fillable = [ - 'name', + 'lastname', + 'firstname', 'email', 'password', ]; @@ -40,4 +43,26 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted() + { + // * EVENT CLOSURES. + static::creating(function (self $model) { + if (Hash::needsRehash($model->password)) { + $model->password = Hash::make($model->password); + } + $model->remember_token = Str::random(10); + }); + static::updating(function (self $model) { + if (Hash::needsRehash($model->password)) { + $model->password = Hash::make($model->password); + } + $model->remember_token = Str::random(10); + }); + } } From ebe8d8daa31c145a7421c25b7ff6a3d1fe9512dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 28 Jun 2023 16:11:44 +0200 Subject: [PATCH 2/3] Fixes #3 Push empty line if no CSV question to export for a brand (cherry picked from commit bf5477d15c56e33fe980dc67cbc10a0b18f58169) --- app/Http/Controllers/QuestionController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Http/Controllers/QuestionController.php b/app/Http/Controllers/QuestionController.php index 516ac58..a55e268 100644 --- a/app/Http/Controllers/QuestionController.php +++ b/app/Http/Controllers/QuestionController.php @@ -248,6 +248,13 @@ class QuestionController extends Controller $w->insertOne([]); } + // * Push empty line if nothing to export + if (empty($results)) { + $w->insertOne([ + 'Aucune question pour cette marque' + ]); + } + /* We create a callable to output the CSV in chunk with Symfony StreamResponse you can flush the body content if necessary From ac060ba16769716fe73b9a309f137040cf45f328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 28 Jun 2023 15:47:23 +0200 Subject: [PATCH 3/3] Fixes #2 use isoFormat instead of format (cherry picked from commit ca5419a992d0e1838d1030db9469edbebc20d995) --- .../Controllers/Api/V2/StatsController.php | 4 +-- app/Http/Controllers/CustomerController.php | 2 +- app/Http/Controllers/QuestionController.php | 2 +- app/Http/Controllers/StatsController.php | 6 ++-- .../Resources/Api/V2/BrandStatsResource.php | 2 +- .../2021_10_29_160416_repair_stats_jobs.php | 2 +- resources/views/customers/show.blade.php | 10 +++--- .../mail/arcadiaOrders/default.blade.php | 2 +- .../views/mail/arcadiaOrders/game.blade.php | 2 +- .../mail/service-renewed-plain.blade.php | 2 +- .../views/mail/service-renewed.blade.php | 2 +- .../stats/view-stats-by-brands.blade.php | 16 +++++----- .../stats/view-stats-by-questions.blade.php | 4 +-- tests/CRM/ApiV2/StatsTest.php | 30 ++++++++--------- tests/Client/CrmClientV2StatsTest.php | 32 +++++++++---------- 15 files changed, 59 insertions(+), 59 deletions(-) diff --git a/app/Http/Controllers/Api/V2/StatsController.php b/app/Http/Controllers/Api/V2/StatsController.php index 174cbd8..e1fcc5f 100644 --- a/app/Http/Controllers/Api/V2/StatsController.php +++ b/app/Http/Controllers/Api/V2/StatsController.php @@ -71,7 +71,7 @@ class StatsController extends Controller ->get()->map(function ($custAnswer) { return [ 'answer_id' => $custAnswer->answer_id, - 'created_at' => $custAnswer->created_at->format('Y-m-d'), + 'created_at' => $custAnswer->created_at->isoFormat('YYYY-MM-DD'), ]; })->groupBy(['created_at', 'answer_id'])->map(function ($day) { return $day->map(function ($custAnswers) { @@ -80,7 +80,7 @@ class StatsController extends Controller }); do { - $currentDate = $start->format('Y-m-d'); + $currentDate = $start->isoFormat('YYYY-MM-DD'); /** @var \Illuminate\Support\Collection $answersByDays */ if (!$answersByDays->has($currentDate)) { $answersByDays->put( diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 05b4482..8300965 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -232,7 +232,7 @@ class CustomerController extends Controller 'Content-Disposition', sprintf( 'attachment; filename="Export pour newsletter %s %s.csv"', - Carbon::now()->format('d-m-Y_H-i'), + Carbon::now()->isoFormat('DD-MM-YYYY_HH-mm'), Str::slug($exportType) ) ); diff --git a/app/Http/Controllers/QuestionController.php b/app/Http/Controllers/QuestionController.php index a55e268..abbcfe5 100644 --- a/app/Http/Controllers/QuestionController.php +++ b/app/Http/Controllers/QuestionController.php @@ -233,7 +233,7 @@ class QuestionController extends Controller 'Content-Disposition', sprintf( 'attachment; filename="Export pour newsletter %s %s.csv"', - Carbon::now()->format('d-m-Y_H-i'), + Carbon::now()->isoFormat('DD-MM-YYYY_HH-mm'), Str::slug($brand->name) ) ); diff --git a/app/Http/Controllers/StatsController.php b/app/Http/Controllers/StatsController.php index aa19e6f..1b449b4 100644 --- a/app/Http/Controllers/StatsController.php +++ b/app/Http/Controllers/StatsController.php @@ -62,7 +62,7 @@ class StatsController extends Controller foreach ($stats as $stat) { $cols = [ - $stat->created_at->format('Y-m-d'), + $stat->created_at->isoFormat('YYYY-MM-DD'), $stat->brand->name ]; foreach ($columns as $colname) { @@ -161,7 +161,7 @@ class StatsController extends Controller ->get()->map(function ($custAnswer) { return [ 'answer_id' => $custAnswer->answer_id, - 'created_at' => $custAnswer->created_at->format('Y-m-d'), + 'created_at' => $custAnswer->created_at->isoFormat('YYYY-MM-DD'), ]; })->groupBy(['created_at', 'answer_id'])->map(function ($day) { return $day->map(function ($custAnswers) { @@ -170,7 +170,7 @@ class StatsController extends Controller }); do { - $currentDate = $start->format('Y-m-d'); + $currentDate = $start->isoFormat('YYYY-MM-DD'); /** @var \Illuminate\Support\Collection $answersByDays */ if (!$answersByDays->has($currentDate)) { $answersByDays->put( diff --git a/app/Http/Resources/Api/V2/BrandStatsResource.php b/app/Http/Resources/Api/V2/BrandStatsResource.php index 25fdf5a..582ff2e 100644 --- a/app/Http/Resources/Api/V2/BrandStatsResource.php +++ b/app/Http/Resources/Api/V2/BrandStatsResource.php @@ -19,7 +19,7 @@ class BrandStatsResource extends JsonResourceCollection return [ 'stats' => $this->collection->map(function (BrandStat $brandStat) { return [ - 'date' => $brandStat->created_at->format('Y-m-d'), + 'date' => $brandStat->created_at->isoFormat('YYYY-MM-DD'), 'active' => $brandStat->active, 'inactive' => $brandStat->inactive, 'old_accounts' => $brandStat->old_accounts, diff --git a/database/migrations/2021_10_29_160416_repair_stats_jobs.php b/database/migrations/2021_10_29_160416_repair_stats_jobs.php index 11d9b00..a1a900b 100644 --- a/database/migrations/2021_10_29_160416_repair_stats_jobs.php +++ b/database/migrations/2021_10_29_160416_repair_stats_jobs.php @@ -31,7 +31,7 @@ class RepairStatsJobs extends Migration $ref->setAccessible(true); $service = $ref->getValue(unserialize($payload->data->command)); - $date = Carbon::parse($job->created_at)->format('Y-m-d'); + $date = Carbon::parse($job->created_at)->isoFormat('YYYY-MM-DD'); $serviceStat = ServiceStat::whereDate('date', $date) ->where('service_id', $service->id)->where('brand_id', $service->brand->id) diff --git a/resources/views/customers/show.blade.php b/resources/views/customers/show.blade.php index ae54f49..47a8467 100644 --- a/resources/views/customers/show.blade.php +++ b/resources/views/customers/show.blade.php @@ -63,7 +63,7 @@ {{ __('Date de naissance') }} - {{ \Carbon\Carbon::parse($customerInfos->birth_date)->format('d/m/Y') }} + {{ \Carbon\Carbon::parse($customerInfos->birth_date)->isoFormat('DD\/MM\/YYYY') }} {{ __('Téléphone') }} @@ -96,14 +96,14 @@ {{ __('Date de la dernière modification de l\'abonnement') }} @if($customerInfos->customer->optInHistory()->orderBy('created_at', 'DESC')->exists()) - {{ \Carbon\Carbon::parse($customerInfos->customer->optInHistory()->orderBy('created_at', 'DESC')->first()->created_at)->format('d/m/Y à H:i') }} + {{ \Carbon\Carbon::parse($customerInfos->customer->optInHistory()->orderBy('created_at', 'DESC')->first()->created_at)->isoFormat('DD\/MM\/YYYY à HH:mm') }} @else @endif {{ __('Dernière connexion') }} - {{ \Carbon\Carbon::parse($customerLogin->last_connection)->format('d/m/Y à H:i') }} + {{ \Carbon\Carbon::parse($customerLogin->last_connection)->isoFormat('DD\/MM\/YYYY à HH:mm') }} {{ __('Status du compte') }} @@ -115,11 +115,11 @@ {{ __('Date de création') }} - {{ \Carbon\Carbon::parse($customerInfos->created_at)->format('d/m/Y à H:i') }} + {{ \Carbon\Carbon::parse($customerInfos->created_at)->isoFormat('DD\/MM\/YYYY à HH:mm') }} {{ __('Date de modification') }} - {{ \Carbon\Carbon::parse($customerInfos->updated_at)->format('d/m/Y à H:i') }} + {{ \Carbon\Carbon::parse($customerInfos->updated_at)->isoFormat('DD\/MM\/YYYY à HH:mm') }} diff --git a/resources/views/mail/arcadiaOrders/default.blade.php b/resources/views/mail/arcadiaOrders/default.blade.php index 892c8d4..c14a9e9 100644 --- a/resources/views/mail/arcadiaOrders/default.blade.php +++ b/resources/views/mail/arcadiaOrders/default.blade.php @@ -2,7 +2,7 @@ {{ $request->order_num }} - {{ \Carbon::parse($request->order_date)->format('d/m/Y') }} + {{ Carbon::parse($request->order_date)->isoFormat('DD\/MM\/YYYY') }} {{ $request->operation }} @if($type->equals(\App\Enums\ArcadiaMailType::default())) @if($orderType->equals(\App\Enums\ArcadiaOrderType::cb())) diff --git a/resources/views/mail/arcadiaOrders/game.blade.php b/resources/views/mail/arcadiaOrders/game.blade.php index 7fb0e96..4505039 100644 --- a/resources/views/mail/arcadiaOrders/game.blade.php +++ b/resources/views/mail/arcadiaOrders/game.blade.php @@ -2,7 +2,7 @@ - {{ \Carbon::parse($request->order_date)->format('d/m/Y') }} + {{ Carbon::parse($request->order_date)->isoFormat('DD\/MM\/YYYY') }} {{ $request->operation }} diff --git a/resources/views/mail/service-renewed-plain.blade.php b/resources/views/mail/service-renewed-plain.blade.php index b3b0c69..2616bf1 100644 --- a/resources/views/mail/service-renewed-plain.blade.php +++ b/resources/views/mail/service-renewed-plain.blade.php @@ -3,6 +3,6 @@ Un service vient d'être régénéré sur {{ $appName }} {{ $service->name }} (marque : {{ $service->brand->name }}) -Régénéré le {{ $service->updated_at->format('D/m/Y H:i') }} +Régénéré le {{ $service->updated_at->isoFormat('dddd DD\/MM\/YYYY HH:MM') }} par {{ $by }} Celà va empêcher le service de fonctionner tant que les crédentials d'api n'auront pas été mis à jour sur le service concerné, veuillez faire au plus vite ! diff --git a/resources/views/mail/service-renewed.blade.php b/resources/views/mail/service-renewed.blade.php index 31a1180..17275e6 100644 --- a/resources/views/mail/service-renewed.blade.php +++ b/resources/views/mail/service-renewed.blade.php @@ -7,7 +7,7 @@

Un service vient d'être régénéré sur {{ $appName }}

{{ $service->name }} (marque : {{ $service->brand->name }})

-

Régénéré le {{ $service->updated_at->format('D d/m/Y H:i') }}
par {{ $by }}

+

Régénéré le {{ $service->updated_at->isoFormat('dddd DD\/MM\/YYYY HH:MM') }}
par {{ $by }}

Celà va empêcher le service de fonctionner tant que les crédentials d'api n'auront pas été mis à jour sur le service concerné, veuillez faire au plus vite !

diff --git a/resources/views/stats/view-stats-by-brands.blade.php b/resources/views/stats/view-stats-by-brands.blade.php index 2cf837f..2e0aabf 100644 --- a/resources/views/stats/view-stats-by-brands.blade.php +++ b/resources/views/stats/view-stats-by-brands.blade.php @@ -25,9 +25,9 @@ {{ __('Début') }} - + {{ __('Fin') }} - + + {{ __('Fin') }} - +