From 90df79c6276e6dfa1c67a7f4f01428892c23a21a Mon Sep 17 00:00:00 2001 From: Roxel Lay Date: Sat, 13 Jan 2024 22:11:51 +0100 Subject: [PATCH 1/8] Fix impossible de modifier page pays --- legacy/back/page_pays_back.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legacy/back/page_pays_back.php b/legacy/back/page_pays_back.php index f30078db..4d587b4f 100644 --- a/legacy/back/page_pays_back.php +++ b/legacy/back/page_pays_back.php @@ -18,7 +18,7 @@ appendQueryString($editFormAction); //Récupération variables -$colname_paysID = $_REQUEST['paysID']; +$colname_paysID = $_REQUEST['paysID'] ?? $_REQUEST['ch_pay_id']; unset($_REQUEST['paysID']); //Requete Pays From 32849a3e557f28308dddd05892f5099f2cec3ed4 Mon Sep 17 00:00:00 2001 From: Roxayl Date: Sat, 13 Jan 2024 22:30:13 +0100 Subject: [PATCH 2/8] Versioning des pages pays (#39) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * WIP versioning contenu pays * Fix impossible de modifier page pays * Historique des modifs page pays * Créé version initiale pr chaque pays --- app/Http/Controllers/ChapterController.php | 28 +++++----- app/Http/Controllers/PaysController.php | 56 +++++++++++++++++++ app/Http/Controllers/VersionController.php | 37 +----------- app/Models/Pays.php | 20 +++++++ app/Models/Traits/Versionable.php | 11 +++- app/Policies/PaysPolicy.php | 13 +++++ app/Services/VersionDiffService.php | 35 ++++++++++++ app/View/Components/Blocks/TextDiff.php | 7 ++- ...2024_01_13_211736_create_pays_versions.php | 27 +++++++++ legacy/back/page_pays_back.php | 28 +++++----- legacy/page-pays.php | 5 +- .../components/history-breadcrumb.blade.php | 13 +++++ resources/views/chapter/diff.blade.php | 14 ----- .../components/history-breadcrumb.blade.php | 6 ++ resources/views/version/diff.blade.php | 10 ++++ .../{chapter => version}/history.blade.php | 25 ++------- routes/web.php | 11 +++- 17 files changed, 246 insertions(+), 100 deletions(-) create mode 100644 app/Http/Controllers/PaysController.php create mode 100644 app/Services/VersionDiffService.php create mode 100644 database/migrations/2024_01_13_211736_create_pays_versions.php create mode 100644 resources/views/chapter/components/history-breadcrumb.blade.php delete mode 100644 resources/views/chapter/diff.blade.php create mode 100644 resources/views/pays/components/history-breadcrumb.blade.php create mode 100644 resources/views/version/diff.blade.php rename resources/views/{chapter => version}/history.blade.php (77%) diff --git a/app/Http/Controllers/ChapterController.php b/app/Http/Controllers/ChapterController.php index c0e38346..ae7935c1 100644 --- a/app/Http/Controllers/ChapterController.php +++ b/app/Http/Controllers/ChapterController.php @@ -11,7 +11,7 @@ use Roxayl\MondeGC\Models\Chapter; use Roxayl\MondeGC\Models\Roleplay; use Roxayl\MondeGC\Services\StringBladeService; -use Roxayl\MondeGC\View\Components\Blocks\TextDiff; +use Roxayl\MondeGC\Services\VersionDiffService; class ChapterController extends Controller { @@ -196,24 +196,32 @@ public function history(Chapter $chapter): View $this->authorize('display', Chapter::class); $firstChapter = $chapter->roleplay->chapters->first(); - $versions = $chapter->versions()->latest('version_id')->paginate(15); + $versions = $chapter->versions()->latest('version_id')->paginate(); $canRevert = Gate::allows('revert', $chapter); + $title = 'Historique du chapitre ' . $chapter->order . ' : ' . $chapter->name; + $diffRoute = 'chapter.diff'; + $breadcrumb = view('chapter.components.history-breadcrumb', compact('firstChapter', 'chapter')); - return view('chapter.history', - compact('chapter', 'firstChapter', 'versions', 'canRevert')); + return view( + 'version.history', + compact('title', 'breadcrumb', 'chapter', 'firstChapter', 'versions', 'canRevert', 'diffRoute') + ); } /** * Compare deux versions d'un chapitre. * + * @param VersionDiffService $diffService * @param Version $version1 * @param Version|null $version2 * @return View */ - public function diff(Version $version1, ?Version $version2 = null): View + public function diff(VersionDiffService $diffService, Version $version1, ?Version $version2 = null): View { $this->authorize('display', Chapter::class); + /** @var Chapter $model1 */ + /** @var Chapter $model2 */ $model1 = $version1->getModel(); if($version2 === null) { $model2 = new ($model1::class); @@ -221,14 +229,8 @@ public function diff(Version $version1, ?Version $version2 = null): View $model2 = $version2->getModel(); } - $nameDiffComponent = new TextDiff((string)$model2->name, $model1->name); - $summaryDiffComponent = new TextDiff((string)$model2->summary, $model1->summary); - $contentDiffComponent = new TextDiff((string)$model2->content, $model1->content); - - $nameDiff = $nameDiffComponent->render(); - $summaryDiff = $summaryDiffComponent->render(); - $contentDiff = $contentDiffComponent->render(); + $diffs = $diffService->generate($model1, $model2); - return view('chapter.diff', compact('nameDiff', 'summaryDiff', 'contentDiff')); + return view('version.diff', compact('diffs')); } } diff --git a/app/Http/Controllers/PaysController.php b/app/Http/Controllers/PaysController.php new file mode 100644 index 00000000..b5c01620 --- /dev/null +++ b/app/Http/Controllers/PaysController.php @@ -0,0 +1,56 @@ +versions()->latest('version_id')->paginate(); + $canRevert = Gate::allows('revert', $pays); + $title = 'Historique du pays ' . $pays->ch_pay_nom; + $diffRoute = 'pays.diff'; + $breadcrumb = view('pays.components.history-breadcrumb', compact('pays')); + + return view( + 'version.history', + compact('title', 'breadcrumb', 'pays', 'versions', 'canRevert', 'diffRoute') + ); + } + + /** + * Compare deux versions d'un pays. + * + * @param VersionDiffService $diffService + * @param Version $version1 + * @param Version|null $version2 + * @return View + */ + public function diff(VersionDiffService $diffService, Version $version1, ?Version $version2 = null): View + { + $this->authorize('viewAny', Pays::class); + + /** @var Pays $model1 */ + /** @var Pays $model2 */ + $model1 = $version1->getModel(); + if($version2 === null) { + $model2 = new ($model1::class); + } else { + $model2 = $version2->getModel(); + } + + $diffs = $diffService->generate($model1, $model2); + + return view('version.diff', compact('diffs')); + } +} diff --git a/app/Http/Controllers/VersionController.php b/app/Http/Controllers/VersionController.php index d0bae557..253241b7 100644 --- a/app/Http/Controllers/VersionController.php +++ b/app/Http/Controllers/VersionController.php @@ -3,11 +3,11 @@ namespace Roxayl\MondeGC\Http\Controllers; use Illuminate\Http\RedirectResponse; -use Illuminate\Http\Response; use Illuminate\Support\Facades\DB; use Illuminate\Validation\ValidationException; +use Reliese\Database\Eloquent\Model; +use Roxayl\MondeGC\Models\Traits\Versionable; use Roxayl\MondeGC\Models\Version; -use Roxayl\MondeGC\View\Components\Blocks\TextDiff; class VersionController extends Controller { @@ -19,8 +19,8 @@ class VersionController extends Controller public function revert(Version $version): RedirectResponse { DB::transaction(function() use ($version) { - // Modèle versionné. + /** @var Model|Versionable $model */ $model = $version->getModel(); $this->authorize('revert', $model); @@ -37,39 +37,8 @@ public function revert(Version $version): RedirectResponse $latestVersion = Version::query()->latest()->first(); $latestVersion->reason = "Retour à la version : " . $oldReason; $latestVersion->save(); - }); return redirect()->back()->with('message', 'success|Modèle restauré avec succès.'); } - - /** - * Affiche la diff entre deux versions. - * - * @param Version $version1 - * @param Version|null $version2 - * @param string $key - * @return Response - */ - public function diff(Version $version1, ?Version $version2, string $key): Response - { - $model1 = $version1->getModel(); - if($version2 === null) { - $model2 = new ($model1::class); - } else { - $model2 = $version2->getModel(); - } - - if($model1::class !== $model2::class) { - throw new \LogicException("Modèles des versions non identiques."); - } - - if(! in_array($key, $model1->getFillable())) { - throw new \InvalidArgumentException("Mauvais type de clé."); - } - - $diffComponent = new TextDiff((string)$model2->$key, $model1->$key); - - return response($diffComponent->render()); - } } diff --git a/app/Models/Pays.php b/app/Models/Pays.php index edb5d470..f38f2657 100644 --- a/app/Models/Pays.php +++ b/app/Models/Pays.php @@ -24,6 +24,7 @@ use Roxayl\MondeGC\Models\Traits\Infrastructurable as HasInfrastructures; use Roxayl\MondeGC\Models\Traits\Resourceable as HasResources; use Roxayl\MondeGC\Models\Traits\Roleplayable as ParticipatesInRoleplay; +use Roxayl\MondeGC\Models\Traits\Versionable; use Roxayl\MondeGC\Services\EconomyService; use Spatie\Searchable\Searchable; use Spatie\Searchable\SearchResult; @@ -153,6 +154,7 @@ class Pays extends Model implements Searchable, Infrastructurable, Resourceable, { use HasFactory, HasInfrastructures, HasResources, ParticipatesInRoleplay; use InfrastructurablePresenter, PaysPresenter; + use Versionable; protected $table = 'pays'; protected $primaryKey = 'ch_pay_id'; @@ -213,6 +215,24 @@ class Pays extends Model implements Searchable, Infrastructurable, Resourceable, 'ch_pay_text_patrimoine', ]; + protected $dontVersionFields = [ + 'ch_pay_label', + 'ch_pay_publication', + 'ch_pay_date', + 'ch_pay_nb_update', + 'ch_pay_mis_jour', + 'ch_pay_budget_carte', + 'ch_pay_industrie_carte', + 'ch_pay_commerce_carte', + 'ch_pay_agriculture_carte', + 'ch_pay_tourisme_carte', + 'ch_pay_recherche_carte', + 'ch_pay_environnement_carte', + 'ch_pay_education_carte', + 'ch_pay_population_carte', + 'ch_pay_emploi_carte', + ]; + public const STATUS_ACTIVE = 1; public const STATUS_ARCHIVED = 2; diff --git a/app/Models/Traits/Versionable.php b/app/Models/Traits/Versionable.php index b67ae0fd..1466da3b 100644 --- a/app/Models/Traits/Versionable.php +++ b/app/Models/Traits/Versionable.php @@ -2,6 +2,7 @@ namespace Roxayl\MondeGC\Models\Traits; +use Illuminate\Database\Eloquent\Model; use Mpociot\Versionable\VersionableTrait; use Roxayl\MondeGC\Models\Version; @@ -10,7 +11,15 @@ trait Versionable use VersionableTrait; /** - * @var string + * @var class-string */ public string $versionClass = Version::class; + + /** + * @return array + */ + public function getDontVersionFields(): array + { + return $this->dontVersionFields ?: []; + } } diff --git a/app/Policies/PaysPolicy.php b/app/Policies/PaysPolicy.php index 125a4d47..c78369e4 100644 --- a/app/Policies/PaysPolicy.php +++ b/app/Policies/PaysPolicy.php @@ -4,6 +4,7 @@ use Illuminate\Auth\Access\HandlesAuthorization; use Roxayl\MondeGC\Models\CustomUser; +use Roxayl\MondeGC\Models\Pays; use Roxayl\MondeGC\Policies\Traits\ManagesInfrastructures; class PaysPolicy @@ -14,4 +15,16 @@ public function viewAny(CustomUser $user): bool { return true; } + + public function update(CustomUser $user, Pays $pays): bool + { + if($user->hasMinPermission('ocgc')) return true; + + return $pays->users->contains($user); + } + + public function revert(CustomUser $user, Pays $pays): bool + { + return $this->update($user, $pays); + } } diff --git a/app/Services/VersionDiffService.php b/app/Services/VersionDiffService.php new file mode 100644 index 00000000..291a47cd --- /dev/null +++ b/app/Services/VersionDiffService.php @@ -0,0 +1,35 @@ + $fields + * @return Collection + */ + public function generate(Model $model1, Model $model2, array $fields = null): Collection + { + $diffs = collect(); + + if($fields === null) { + $fields = array_diff($model1->getFillable(), $model1->getDontVersionFields()); + } + + foreach($fields as $field) { + if($model1->$field === $model2->$field) { + continue; + } + $diffs->put($field, (new TextDiff((string) $model2->$field, (string) $model1->$field))->render()); + } + + return $diffs; + } +} diff --git a/app/View/Components/Blocks/TextDiff.php b/app/View/Components/Blocks/TextDiff.php index e122c337..1a1efb32 100644 --- a/app/View/Components/Blocks/TextDiff.php +++ b/app/View/Components/Blocks/TextDiff.php @@ -3,6 +3,7 @@ namespace Roxayl\MondeGC\View\Components\Blocks; use Caxy\HtmlDiff\HtmlDiff; +use Caxy\HtmlDiff\HtmlDiffConfig; use Roxayl\MondeGC\View\Components\BaseComponent; class TextDiff extends BaseComponent @@ -21,6 +22,10 @@ public function __construct(string $text1, string $text2) */ public function render(): string { - return (new HtmlDiff($this->text1, $this->text2))->build(); + $config = new HtmlDiffConfig(); + + return (new HtmlDiff($this->text1, $this->text2)) + ->setConfig($config) + ->build(); } } diff --git a/database/migrations/2024_01_13_211736_create_pays_versions.php b/database/migrations/2024_01_13_211736_create_pays_versions.php new file mode 100644 index 00000000..14f26dbb --- /dev/null +++ b/database/migrations/2024_01_13_211736_create_pays_versions.php @@ -0,0 +1,27 @@ += 10", escape_sql($colname_paysID, "int")); $User = mysql_query($query_User, $maconnexion); $row_User = mysql_fetch_assoc($User); +$eloquentPays = EloquentPays::query()->findOrFail($row_InfoGenerale['ch_pay_id']); + //Mise à jour formulaire pays if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "InfoHeader")) { @@ -41,7 +41,6 @@ $thisPays = new Pays($_POST['ch_pay_id']); if($thisUser->minStatus('OCGC') || $thisPays->getUserPermission($thisUser) >= Pays::$permissions['codirigeant']) { - if ($_POST['ch_pay_emplacement'] >= 3 and $_POST['ch_pay_emplacement'] <= 4 ){ $ch_pay_continent = "RFGC";} if ($_POST['ch_pay_emplacement'] >= 5 and $_POST['ch_pay_emplacement'] < 14 ){ $ch_pay_continent = "Aurinea";} if ($_POST['ch_pay_emplacement'] < 3 ){ $ch_pay_continent = "Aurinea";} @@ -49,12 +48,12 @@ if ($_POST['ch_pay_emplacement'] >= 18 and $_POST['ch_pay_emplacement'] < 24 ){ $ch_pay_continent = "Volcania";} if ($_POST['ch_pay_emplacement'] >= 24 and $_POST['ch_pay_emplacement'] <= 27 ){ $ch_pay_continent = "Aldesyl";} if ($_POST['ch_pay_emplacement'] >= 27 and $_POST['ch_pay_emplacement'] <= 42 ){ $ch_pay_continent = "Philicie";} - if( $_POST['ch_pay_emplacement'] > 42 and $_POST['ch_pay_emplacement'] <= 56 ){ $ch_pay_continent = "Aldesyl";} - if( $_POST['ch_pay_emplacement'] >= 56 and $_POST['ch_pay_emplacement'] <= 57 ){ $ch_pay_continent = "Volcania";} + if ($_POST['ch_pay_emplacement'] > 42 and $_POST['ch_pay_emplacement'] <= 56 ){ $ch_pay_continent = "Aldesyl";} + if ($_POST['ch_pay_emplacement'] >= 56 and $_POST['ch_pay_emplacement'] <= 57 ){ $ch_pay_continent = "Volcania";} if ($_POST['ch_pay_emplacement'] >= 57 and $_POST['ch_pay_emplacement'] <= 58 ){ $ch_pay_continent = "Aldesyl";} if ($_POST['ch_pay_emplacement'] >= 59){ $ch_pay_continent = "Volcania";} - $updateSQL = sprintf("UPDATE pays SET ch_pay_label=%s, ch_pay_publication=%s, ch_pay_continent=%s, ch_pay_emplacement=%s, ch_pay_lien_forum=%s, lien_wiki = %s, ch_pay_nom=%s, ch_pay_devise=%s, ch_pay_lien_imgheader=%s, ch_pay_lien_imgdrapeau=%s, ch_pay_date=%s, ch_pay_mis_jour=%s, ch_pay_nb_update=%s, ch_pay_forme_etat=%s, ch_pay_capitale=%s, ch_pay_langue_officielle=%s, ch_pay_monnaie=%s, ch_pay_header_presentation=%s, ch_pay_text_presentation=%s, ch_pay_header_geographie=%s, ch_pay_text_geographie=%s, ch_pay_header_politique=%s, ch_pay_text_politique=%s, ch_pay_header_histoire=%s, ch_pay_text_histoire=%s, ch_pay_header_economie=%s, ch_pay_text_economie=%s, ch_pay_header_transport=%s, ch_pay_text_transport=%s, ch_pay_header_sport=%s, ch_pay_text_sport=%s, ch_pay_header_culture=%s, ch_pay_text_culture=%s, ch_pay_header_patrimoine=%s, ch_pay_text_patrimoine=%s WHERE ch_pay_id=%s", + $updateSQL = sprintf("UPDATE pays SET ch_pay_label=%s, ch_pay_publication=%s, ch_pay_continent=%s, ch_pay_emplacement=%s, ch_pay_lien_forum=%s, lien_wiki = %s, ch_pay_nom=%s, ch_pay_devise=%s, ch_pay_lien_imgheader=%s, ch_pay_lien_imgdrapeau=%s, ch_pay_date=%s, ch_pay_mis_jour=%s, ch_pay_nb_update=%s, ch_pay_forme_etat=%s, ch_pay_capitale=%s, ch_pay_langue_officielle=%s, ch_pay_monnaie=%s, ch_pay_header_presentation=%s, ch_pay_text_presentation=%s, ch_pay_header_geographie=%s, ch_pay_text_geographie=%s, ch_pay_header_politique=%s, ch_pay_text_politique=%s, ch_pay_header_histoire=%s, ch_pay_text_histoire=%s, ch_pay_header_economie=%s, ch_pay_text_economie=%s, ch_pay_header_transport=%s, ch_pay_text_transport=%s, ch_pay_header_sport=%s, ch_pay_text_sport=%s, ch_pay_header_culture=%s, ch_pay_text_culture=%s, ch_pay_header_patrimoine=%s, ch_pay_text_patrimoine=%s WHERE ch_pay_id=%s", escape_sql($_POST['ch_pay_label'], "text"), escape_sql($_POST['ch_pay_publication'], "int"), escape_sql($ch_pay_continent, "text"), @@ -92,17 +91,19 @@ escape_sql($_POST['ch_pay_text_patrimoine'], "text"), escape_sql($_POST['ch_pay_id'], "int")); + $eloquentPays->fill(request()->all($eloquentPays->getFillable())); + $eloquentPays->save(); - $Result1 = mysql_query($updateSQL, $maconnexion); - getErrorMessage('success', "Le pays a été modifié avec succès !"); + $Result1 = mysql_query($updateSQL, $maconnexion); + getErrorMessage('success', "Le pays a été modifié avec succès !"); } else { getErrorMessage('error', "Vous n'avez pas accès à cette partie."); } - $updateGoTo = DEF_URI_PATH . "back/page_pays_back.php?paysID=" . (int)$_POST['ch_pay_id']; - appendQueryString($updateGoTo); - header(sprintf("Location: %s", $updateGoTo)); - exit; + $updateGoTo = DEF_URI_PATH . "back/page_pays_back.php?paysID=" . (int)$_POST['ch_pay_id']; + appendQueryString($updateGoTo); + header(sprintf("Location: %s", $updateGoTo)); + exit; } //requete liste des villes du joueur @@ -274,9 +275,6 @@ $paysPersonnages = $paysPersonnages[0]; } -// Pays -$eloquentPays = EloquentPays::query()->findOrFail($row_InfoGenerale['ch_pay_id']); - ?> diff --git a/legacy/page-pays.php b/legacy/page-pays.php index 577b18e2..30d597f7 100644 --- a/legacy/page-pays.php +++ b/legacy/page-pays.php @@ -255,9 +255,12 @@
- +
+ + Historique + Partager sur le forum diff --git a/resources/views/chapter/components/history-breadcrumb.blade.php b/resources/views/chapter/components/history-breadcrumb.blade.php new file mode 100644 index 00000000..80150ee1 --- /dev/null +++ b/resources/views/chapter/components/history-breadcrumb.blade.php @@ -0,0 +1,13 @@ + diff --git a/resources/views/chapter/diff.blade.php b/resources/views/chapter/diff.blade.php deleted file mode 100644 index 8834a3bc..00000000 --- a/resources/views/chapter/diff.blade.php +++ /dev/null @@ -1,14 +0,0 @@ - -
- Titre -
- {!! $nameDiff !!} -
- Résumé -
- {!! $summaryDiff !!} -
- Contenu -
- {!! $contentDiff !!} -
diff --git a/resources/views/pays/components/history-breadcrumb.blade.php b/resources/views/pays/components/history-breadcrumb.blade.php new file mode 100644 index 00000000..d114b8a3 --- /dev/null +++ b/resources/views/pays/components/history-breadcrumb.blade.php @@ -0,0 +1,6 @@ + diff --git a/resources/views/version/diff.blade.php b/resources/views/version/diff.blade.php new file mode 100644 index 00000000..4e27e305 --- /dev/null +++ b/resources/views/version/diff.blade.php @@ -0,0 +1,10 @@ +
+ @empty($diffs) +

Aucun diff disponible.

+ @endempty + @foreach($diffs as $field => $diff) + {{ $field }} + {!! $diff !!} +
+ @endforeach +
diff --git a/resources/views/chapter/history.blade.php b/resources/views/version/history.blade.php similarity index 77% rename from resources/views/chapter/history.blade.php rename to resources/views/version/history.blade.php index 38e12f44..26c02ac2 100644 --- a/resources/views/chapter/history.blade.php +++ b/resources/views/version/history.blade.php @@ -4,7 +4,7 @@ @extends('layouts.legacy') @section('title') - Historique du chapitre {{ $chapter->order }} : {{ $chapter->name }} + {{ $title }} @endsection @section('content') @@ -17,24 +17,11 @@

- Historique du chapitre {{ $chapter->order }} : {{ $chapter->name }} - Bêta + {{ $title }}

- + {!! $breadcrumb !!}
@@ -63,7 +50,7 @@ {{ $version->created_at->format('Y/m/d à H:i:s') }} {{ $version->reason }} - $version, 'version2' => $version->previous(), ]) }}" @@ -105,7 +92,7 @@ class="form-inline" style="display: inline;"> @parent -@endsection \ No newline at end of file +@endsection diff --git a/routes/web.php b/routes/web.php index 262149f2..8a7aa35a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -48,6 +48,15 @@ */ Route::get('page/{page}-{url}', [Controllers\PageController::class, 'index'])->name('page.show'); +/* +|-------------------------------------------------------------------------- +| Pays +|-------------------------------------------------------------------------- +*/ +Route::get('pays/history/{pays}', [Controllers\PaysController::class, 'history'])->name('pays.history'); +Route::get('pays/diff/{version1}/{version2?}', [Controllers\PaysController::class, 'diff']) + ->name('pays.diff'); + /* |-------------------------------------------------------------------------- | Organisation @@ -213,8 +222,6 @@ */ Route::post('version/revert/{version}', [Controllers\VersionController::class, 'revert']) ->name('version.revert'); -Route::get('version/diff/{version1}/{version2?}/{key}', [Controllers\VersionController::class, 'diff']) - ->name('version.diff'); /* |-------------------------------------------------------------------------- From de1175b9d2012708806e5e8ba47a34ac9df78663 Mon Sep 17 00:00:00 2001 From: Roxel Lay Date: Sun, 14 Jan 2024 12:00:30 +0100 Subject: [PATCH 3/8] =?UTF-8?q?Fix=20permissions=20pr=20utilisateurs=20non?= =?UTF-8?q?=20connect=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Policies/OrganisationPolicy.php | 10 +++++----- app/Policies/PatrimoinePolicy.php | 2 +- app/Policies/PaysPolicy.php | 23 +++++++++++++++++++---- app/Policies/VillePolicy.php | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/Policies/OrganisationPolicy.php b/app/Policies/OrganisationPolicy.php index a5545a12..0569cb0e 100644 --- a/app/Policies/OrganisationPolicy.php +++ b/app/Policies/OrganisationPolicy.php @@ -10,14 +10,14 @@ class OrganisationPolicy { use HandlesAuthorization, ManagesInfrastructures; - + /** * Determine whether the user can view any organisations. * - * @param CustomUser $user + * @param CustomUser|null $user * @return bool */ - public function viewAny(CustomUser $user): bool + public function viewAny(?CustomUser $user): bool { return true; } @@ -25,11 +25,11 @@ public function viewAny(CustomUser $user): bool /** * Determine whether the user can view the organisation. * - * @param CustomUser $user + * @param CustomUser|null $user * @param Organisation $organisation * @return bool */ - public function view(CustomUser $user, Organisation $organisation): bool + public function view(?CustomUser $user, Organisation $organisation): bool { return true; } diff --git a/app/Policies/PatrimoinePolicy.php b/app/Policies/PatrimoinePolicy.php index 4067bc7e..5ecd0da8 100644 --- a/app/Policies/PatrimoinePolicy.php +++ b/app/Policies/PatrimoinePolicy.php @@ -9,7 +9,7 @@ class PatrimoinePolicy { use HandlesAuthorization; - public function viewAny(CustomUser $user): bool + public function viewAny(?CustomUser $user): bool { return true; } diff --git a/app/Policies/PaysPolicy.php b/app/Policies/PaysPolicy.php index c78369e4..a0d7f88b 100644 --- a/app/Policies/PaysPolicy.php +++ b/app/Policies/PaysPolicy.php @@ -3,19 +3,31 @@ namespace Roxayl\MondeGC\Policies; use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Database\Eloquent\Model; use Roxayl\MondeGC\Models\CustomUser; use Roxayl\MondeGC\Models\Pays; +use Roxayl\MondeGC\Policies\Contracts\VersionablePolicy; use Roxayl\MondeGC\Policies\Traits\ManagesInfrastructures; -class PaysPolicy +class PaysPolicy implements VersionablePolicy { use HandlesAuthorization, ManagesInfrastructures; - public function viewAny(CustomUser $user): bool + /** + * @param CustomUser|null $user + * @return bool + */ + public function viewAny(?CustomUser $user): bool { return true; } + /** + * @param CustomUser $user + * @param Pays $pays + * @return bool + */ public function update(CustomUser $user, Pays $pays): bool { if($user->hasMinPermission('ocgc')) return true; @@ -23,8 +35,11 @@ public function update(CustomUser $user, Pays $pays): bool return $pays->users->contains($user); } - public function revert(CustomUser $user, Pays $pays): bool + /** + * @inheritDoc + */ + public function revert(CustomUser|Authenticatable $user, Pays|Model $model): bool { - return $this->update($user, $pays); + return $this->update($user, $model); } } diff --git a/app/Policies/VillePolicy.php b/app/Policies/VillePolicy.php index b4a9dda8..431ea4ec 100644 --- a/app/Policies/VillePolicy.php +++ b/app/Policies/VillePolicy.php @@ -11,7 +11,7 @@ class VillePolicy { use HandlesAuthorization, ManagesInfrastructures; - public function viewAny(CustomUser $user): bool + public function viewAny(?CustomUser $user): bool { return true; } From 7596405c4a4fc63f89189a78d5749f600a75781c Mon Sep 17 00:00:00 2001 From: Roxayl Date: Sun, 14 Jan 2024 15:34:02 +0100 Subject: [PATCH 4/8] Historique modifs pr villes et orgas (#40) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + cleanup mineurs pr la fonctionnalité d'historique des pays --- .../Controllers/OrganisationController.php | 46 +++++++++++++++ app/Http/Controllers/PaysController.php | 2 +- app/Http/Controllers/VilleController.php | 56 +++++++++++++++++++ app/Models/Organisation.php | 10 ++++ app/Models/Pays.php | 2 +- app/Models/Ville.php | 12 ++++ app/Policies/OrganisationPolicy.php | 15 ++++- app/Policies/VillePolicy.php | 24 +++++++- ...create_ville_and_organisation_versions.php | 29 ++++++++++ legacy/page-pays.php | 2 +- legacy/page-ville.php | 5 ++ .../components/history-breadcrumb.blade.php | 6 ++ resources/views/organisation/show.blade.php | 4 ++ resources/views/version/history.blade.php | 2 +- .../components/history-breadcrumb.blade.php | 22 ++++++++ routes/web.php | 13 +++++ 16 files changed, 244 insertions(+), 6 deletions(-) create mode 100644 app/Http/Controllers/VilleController.php create mode 100644 database/migrations/2024_01_14_140145_create_ville_and_organisation_versions.php create mode 100644 resources/views/organisation/components/history-breadcrumb.blade.php create mode 100644 resources/views/ville/components/history-breadcrumb.blade.php diff --git a/app/Http/Controllers/OrganisationController.php b/app/Http/Controllers/OrganisationController.php index 52c5bb0c..03af0a36 100644 --- a/app/Http/Controllers/OrganisationController.php +++ b/app/Http/Controllers/OrganisationController.php @@ -8,11 +8,13 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Str; +use Mpociot\Versionable\Version; use Roxayl\MondeGC\Events\Organisation\TypeMigrated; use Roxayl\MondeGC\Http\Requests\Organisation\MigrateType; use Roxayl\MondeGC\Models\Communique; use Roxayl\MondeGC\Models\Organisation; use Roxayl\MondeGC\Models\OrganisationMember; +use Roxayl\MondeGC\Services\VersionDiffService; class OrganisationController extends Controller { @@ -215,4 +217,48 @@ public function runMigration(MigrateType $request, int $id): RedirectResponse ->with('message', 'success|Votre organisation est devenue une ' . __("organisation.types.$organisation->type")); } + + /** + * @param Organisation $organisation + * @return \Illuminate\View\View + */ + public function history(Organisation $organisation): View + { + $versions = $organisation->versions()->latest('version_id')->paginate(); + $canRevert = Gate::allows('revert', $organisation); + $title = 'Historique de l\'organisation ' . $organisation->name; + $diffRoute = 'organisation.diff'; + $breadcrumb = view('organisation.components.history-breadcrumb', compact('organisation')); + + return view( + 'version.history', + compact('title', 'breadcrumb', 'versions', 'canRevert', 'diffRoute') + ); + } + + /** + * Compare deux versions d'une organisation. + * + * @param VersionDiffService $diffService + * @param Version $version1 + * @param Version|null $version2 + * @return View + */ + public function diff(VersionDiffService $diffService, Version $version1, ?Version $version2 = null): View + { + $this->authorize('viewAny', Organisation::class); + + /** @var Organisation $model1 */ + /** @var Organisation $model2 */ + $model1 = $version1->getModel(); + if($version2 === null) { + $model2 = new ($model1::class); + } else { + $model2 = $version2->getModel(); + } + + $diffs = $diffService->generate($model1, $model2); + + return view('version.diff', compact('diffs')); + } } diff --git a/app/Http/Controllers/PaysController.php b/app/Http/Controllers/PaysController.php index b5c01620..541bee36 100644 --- a/app/Http/Controllers/PaysController.php +++ b/app/Http/Controllers/PaysController.php @@ -24,7 +24,7 @@ public function history(Pays $pays): View return view( 'version.history', - compact('title', 'breadcrumb', 'pays', 'versions', 'canRevert', 'diffRoute') + compact('title', 'breadcrumb', 'versions', 'canRevert', 'diffRoute') ); } diff --git a/app/Http/Controllers/VilleController.php b/app/Http/Controllers/VilleController.php new file mode 100644 index 00000000..8d17ede3 --- /dev/null +++ b/app/Http/Controllers/VilleController.php @@ -0,0 +1,56 @@ +versions()->latest('version_id')->paginate(); + $canRevert = Gate::allows('revert', $ville); + $title = 'Historique de la ville ' . $ville->ch_vil_nom; + $diffRoute = 'ville.diff'; + $breadcrumb = view('ville.components.history-breadcrumb', compact('ville')); + + return view( + 'version.history', + compact('title', 'breadcrumb', 'versions', 'canRevert', 'diffRoute') + ); + } + + /** + * Compare deux versions d'une ville. + * + * @param VersionDiffService $diffService + * @param Version $version1 + * @param Version|null $version2 + * @return View + */ + public function diff(VersionDiffService $diffService, Version $version1, ?Version $version2 = null): View + { + $this->authorize('viewAny', Ville::class); + + /** @var Ville $model1 */ + /** @var Ville $model2 */ + $model1 = $version1->getModel(); + if($version2 === null) { + $model2 = new ($model1::class); + } else { + $model2 = $version2->getModel(); + } + + $diffs = $diffService->generate($model1, $model2); + + return view('version.diff', compact('diffs')); + } +} diff --git a/app/Models/Organisation.php b/app/Models/Organisation.php index 85ca0bc4..2c2cd8f1 100644 --- a/app/Models/Organisation.php +++ b/app/Models/Organisation.php @@ -22,6 +22,7 @@ use Roxayl\MondeGC\Models\Traits\Infrastructurable as HasInfrastructures; use Roxayl\MondeGC\Models\Traits\Resourceable as HasResources; use Roxayl\MondeGC\Models\Traits\Roleplayable as ParticipatesInRoleplay; +use Roxayl\MondeGC\Models\Traits\Versionable; use Roxayl\MondeGC\Services\EconomyService; use Spatie\Searchable\Searchable; use Spatie\Searchable\SearchResult; @@ -82,6 +83,7 @@ class Organisation extends Model implements Searchable, Infrastructurable, Resou use SoftDeletes; use HasFactory, HasInfrastructures, HasResources, ParticipatesInRoleplay; use InfrastructurablePresenter, OrganisationPresenter; + use Versionable; protected $table = 'organisation'; @@ -105,6 +107,14 @@ class Organisation extends Model implements Searchable, Infrastructurable, Resou 'allow_temperance' => false, ]; + protected array $dontVersionFields = [ + 'id', + 'type_migrated_at', + 'created_at', + 'updated_at', + 'deleted_at', + ]; + public const PERMISSION_OWNER = 100; public const PERMISSION_ADMINISTRATOR = 50; public const PERMISSION_MEMBER = 10; diff --git a/app/Models/Pays.php b/app/Models/Pays.php index f38f2657..26d840a7 100644 --- a/app/Models/Pays.php +++ b/app/Models/Pays.php @@ -215,7 +215,7 @@ class Pays extends Model implements Searchable, Infrastructurable, Resourceable, 'ch_pay_text_patrimoine', ]; - protected $dontVersionFields = [ + protected array $dontVersionFields = [ 'ch_pay_label', 'ch_pay_publication', 'ch_pay_date', diff --git a/app/Models/Ville.php b/app/Models/Ville.php index 2e9355de..b79a6084 100644 --- a/app/Models/Ville.php +++ b/app/Models/Ville.php @@ -21,6 +21,7 @@ use Roxayl\MondeGC\Models\Traits\Infrastructurable as HasInfrastructures; use Roxayl\MondeGC\Models\Traits\Resourceable as HasResources; use Roxayl\MondeGC\Models\Traits\Roleplayable as ParticipatesInRoleplay; +use Roxayl\MondeGC\Models\Traits\Versionable; use Roxayl\MondeGC\Services\EconomyService; use Spatie\Searchable\Searchable; use Spatie\Searchable\SearchResult; @@ -109,6 +110,7 @@ class Ville extends Model implements Searchable, Infrastructurable, Resourceable { use HasFactory, HasInfrastructures, HasResources, ParticipatesInRoleplay; use InfrastructurablePresenter, VillePresenter; + use Versionable; protected $table = 'villes'; protected $primaryKey = 'ch_vil_ID'; @@ -162,6 +164,16 @@ class Ville extends Model implements Searchable, Infrastructurable, Resourceable 'ch_vil_culture' ]; + protected array $dontVersionFields = [ + 'ch_vil_ID', + 'ch_vil_paysID', + 'ch_vil_user', + 'ch_vil_label', + 'ch_vil_date_enregistrement', + 'ch_vil_mis_jour', + 'ch_vil_nb_update', + ]; + /** * @return string */ diff --git a/app/Policies/OrganisationPolicy.php b/app/Policies/OrganisationPolicy.php index 0569cb0e..19e39a6d 100644 --- a/app/Policies/OrganisationPolicy.php +++ b/app/Policies/OrganisationPolicy.php @@ -3,11 +3,14 @@ namespace Roxayl\MondeGC\Policies; use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Database\Eloquent\Model; use Roxayl\MondeGC\Models\CustomUser; use Roxayl\MondeGC\Models\Organisation; +use Roxayl\MondeGC\Policies\Contracts\VersionablePolicy; use Roxayl\MondeGC\Policies\Traits\ManagesInfrastructures; -class OrganisationPolicy +class OrganisationPolicy implements VersionablePolicy { use HandlesAuthorization, ManagesInfrastructures; @@ -110,4 +113,14 @@ public function administrate(CustomUser $user, Organisation $organisation): bool return $organisation->maxPermission($user) >= Organisation::$permissions['administrator']; } + + /** + * @inheritDoc + */ + public function revert(CustomUser|Authenticatable $user, Organisation|Model $model): bool + { + if($user->hasMinPermission('ocgc')) return true; + + return $this->administrate($user, $model); + } } diff --git a/app/Policies/VillePolicy.php b/app/Policies/VillePolicy.php index 431ea4ec..5a2df1ed 100644 --- a/app/Policies/VillePolicy.php +++ b/app/Policies/VillePolicy.php @@ -3,23 +3,45 @@ namespace Roxayl\MondeGC\Policies; use Illuminate\Auth\Access\HandlesAuthorization; +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Database\Eloquent\Model; use Roxayl\MondeGC\Models\CustomUser; use Roxayl\MondeGC\Models\Ville; +use Roxayl\MondeGC\Policies\Contracts\VersionablePolicy; use Roxayl\MondeGC\Policies\Traits\ManagesInfrastructures; -class VillePolicy +class VillePolicy implements VersionablePolicy { use HandlesAuthorization, ManagesInfrastructures; + /** + * @param CustomUser|null $user + * @return bool + */ public function viewAny(?CustomUser $user): bool { return true; } + /** + * @param CustomUser $user + * @param Ville $ville + * @return bool + */ public function delete(CustomUser $user, Ville $ville): bool { if($user->hasMinPermission('admin')) return true; return $ville->getUsers()->contains($user); } + + /** + * @inheritDoc + */ + public function revert(CustomUser|Authenticatable $user, Ville|Model $model): bool + { + if($user->hasMinPermission('ocgc')) return true; + + return $model->getUsers()->contains($user); + } } diff --git a/database/migrations/2024_01_14_140145_create_ville_and_organisation_versions.php b/database/migrations/2024_01_14_140145_create_ville_and_organisation_versions.php new file mode 100644 index 00000000..75b59ae3 --- /dev/null +++ b/database/migrations/2024_01_14_140145_create_ville_and_organisation_versions.php @@ -0,0 +1,29 @@ + - Historique + Historique Partager sur le forum diff --git a/legacy/page-ville.php b/legacy/page-ville.php index 5f632a28..e1d0cfd7 100644 --- a/legacy/page-ville.php +++ b/legacy/page-ville.php @@ -368,6 +368,11 @@ + + + Historique + Partager sur le forum diff --git a/resources/views/organisation/components/history-breadcrumb.blade.php b/resources/views/organisation/components/history-breadcrumb.blade.php new file mode 100644 index 00000000..6b08d3a8 --- /dev/null +++ b/resources/views/organisation/components/history-breadcrumb.blade.php @@ -0,0 +1,6 @@ + diff --git a/resources/views/organisation/show.blade.php b/resources/views/organisation/show.blade.php index 6ba476c0..76b1f518 100644 --- a/resources/views/organisation/show.blade.php +++ b/resources/views/organisation/show.blade.php @@ -78,6 +78,10 @@
+ + Historique + @can('update', $organisation) diff --git a/resources/views/version/history.blade.php b/resources/views/version/history.blade.php index 26c02ac2..389ea326 100644 --- a/resources/views/version/history.blade.php +++ b/resources/views/version/history.blade.php @@ -47,7 +47,7 @@ @foreach($versions as $version) {{ $version->responsible_user?->ch_use_login }} - {{ $version->created_at->format('Y/m/d à H:i:s') }} + {{ $version->created_at->format('d/m/Y à H:i') }} {{ $version->reason }} +
  • + Pays + / +
  • +
  • + {{ $ville->pays->ch_pay_nom }} + / +
  • +
  • + Villes + / +
  • +
  • + + {{ $ville->ch_vil_nom }} + / +
  • +
  • + Historique +
  • + diff --git a/routes/web.php b/routes/web.php index 8a7aa35a..a4d6038a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -57,6 +57,15 @@ Route::get('pays/diff/{version1}/{version2?}', [Controllers\PaysController::class, 'diff']) ->name('pays.diff'); +/* +|-------------------------------------------------------------------------- +| Ville +|-------------------------------------------------------------------------- +*/ +Route::get('ville/history/{ville}', [Controllers\VilleController::class, 'history'])->name('ville.history'); +Route::get('ville/diff/{version1}/{version2?}', [Controllers\VilleController::class, 'diff']) + ->name('ville.diff'); + /* |-------------------------------------------------------------------------- | Organisation @@ -71,6 +80,10 @@ ->name('organisation.delete'); Route::match(['put', 'patch'], 'organisation/{organisation}/migrate', [Controllers\OrganisationController::class, 'runMigration']) ->name('organisation.run-migration'); +Route::get('organisation/history/{organisation}', [Controllers\OrganisationController::class, 'history']) + ->name('organisation.history'); +Route::get('organisation/diff/{version1}/{version2?}', [Controllers\OrganisationController::class, 'diff']) + ->name('organisation.diff'); /* |-------------------------------------------------------------------------- From 0ea7a8ad34f3585bd80e1c9cc6954246dfab85ee Mon Sep 17 00:00:00 2001 From: Roxel Lay Date: Sun, 14 Jan 2024 20:56:29 +0100 Subject: [PATCH 5/8] Cleanup constructeur de classes Command --- app/Console/Commands/GenerateHtaccess.php | 10 ---------- app/Console/Commands/InitializeDatabase.php | 10 ---------- app/Console/Commands/InitializeEnvironment.php | 10 ---------- app/Console/Commands/InitializeTesting.php | 10 ---------- app/Console/Commands/OverrideVendorFiles.php | 10 ---------- 5 files changed, 50 deletions(-) diff --git a/app/Console/Commands/GenerateHtaccess.php b/app/Console/Commands/GenerateHtaccess.php index 01bb2d80..4cc59366 100644 --- a/app/Console/Commands/GenerateHtaccess.php +++ b/app/Console/Commands/GenerateHtaccess.php @@ -21,16 +21,6 @@ class GenerateHtaccess extends Command protected $description = "Génère un fichier .htaccess au répertoire racine, " . "selon la configuration de l'application"; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * diff --git a/app/Console/Commands/InitializeDatabase.php b/app/Console/Commands/InitializeDatabase.php index de500c6b..db2f5449 100644 --- a/app/Console/Commands/InitializeDatabase.php +++ b/app/Console/Commands/InitializeDatabase.php @@ -20,16 +20,6 @@ class InitializeDatabase extends Initializer */ protected $description = "Initialise la base de données en créant le schéma de la base et les données"; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * diff --git a/app/Console/Commands/InitializeEnvironment.php b/app/Console/Commands/InitializeEnvironment.php index cc6f9fff..cc020dac 100644 --- a/app/Console/Commands/InitializeEnvironment.php +++ b/app/Console/Commands/InitializeEnvironment.php @@ -21,16 +21,6 @@ class InitializeEnvironment extends Initializer */ protected $description = "Initialise l'application et les variables d'environnement"; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * diff --git a/app/Console/Commands/InitializeTesting.php b/app/Console/Commands/InitializeTesting.php index bd32867d..2aaf9626 100644 --- a/app/Console/Commands/InitializeTesting.php +++ b/app/Console/Commands/InitializeTesting.php @@ -18,16 +18,6 @@ class InitializeTesting extends Initializer */ protected $description = "Initialise l'environnement de test"; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * diff --git a/app/Console/Commands/OverrideVendorFiles.php b/app/Console/Commands/OverrideVendorFiles.php index de11442b..8fcdacc7 100644 --- a/app/Console/Commands/OverrideVendorFiles.php +++ b/app/Console/Commands/OverrideVendorFiles.php @@ -30,16 +30,6 @@ class OverrideVendorFiles extends Command 'app/Overrides/Searchable/SearchResult.php' => 'vendor/spatie/laravel-searchable/src/SearchResult.php' ]; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * From 0c6f5924c9da720f522b11ddac69343142141b71 Mon Sep 17 00:00:00 2001 From: Roxel Lay Date: Sun, 14 Jan 2024 20:57:17 +0100 Subject: [PATCH 6/8] =?UTF-8?q?Refactor=20regen=20influences=20ds=20servic?= =?UTF-8?q?e=20+=20d=C3=A9ploiement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 1 + app/Console/Commands/RegenerateInfluences.php | 45 ++++++++++++ app/Http/Controllers/BackOfficeController.php | 27 ++----- app/Services/RegenerateInfluenceService.php | 71 +++++++++++++++++++ 4 files changed, 124 insertions(+), 20 deletions(-) create mode 100644 app/Console/Commands/RegenerateInfluences.php create mode 100644 app/Services/RegenerateInfluenceService.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 50ac0679..fe34b877 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -136,4 +136,5 @@ jobs: find ./.env -type f -exec sed -i '' -e "/^APP_BUILD=/s/=.*/=\'$BUILD_NUMBER\'/" {} \; php artisan optimize:clear php artisan migrate --force + php artisan monde:regenerate-influences php artisan up diff --git a/app/Console/Commands/RegenerateInfluences.php b/app/Console/Commands/RegenerateInfluences.php new file mode 100644 index 00000000..e35f3aaf --- /dev/null +++ b/app/Console/Commands/RegenerateInfluences.php @@ -0,0 +1,45 @@ +line('Régénération des influences (' + . $regenerateInfluenceService->influenceCount() . ' influence(s) actuellement dans la base de données)...'); + $regenerateInfluenceService->regenerate(); + $this->info('Influences regénérées avec succès (' + . $regenerateInfluenceService->influenceCount() . ' influence(s) actuellement dans la base de données).'); + } + catch (\Throwable $ex) { + $this->error("Une erreur s'est produite : " . $ex->getMessage()); + return 1; + } + return 0; + } +} diff --git a/app/Http/Controllers/BackOfficeController.php b/app/Http/Controllers/BackOfficeController.php index fd7643ae..558427f2 100644 --- a/app/Http/Controllers/BackOfficeController.php +++ b/app/Http/Controllers/BackOfficeController.php @@ -4,12 +4,9 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; use Illuminate\View\View; -use Roxayl\MondeGC\Models\Contracts\Influencable; -use Roxayl\MondeGC\Models\Factories\InfluencableFactory; -use Roxayl\MondeGC\Models\Influence; use Roxayl\MondeGC\Services\HelperService; +use Roxayl\MondeGC\Services\RegenerateInfluenceService; use YlsIdeas\FeatureFlags\Facades\Features; class BackOfficeController extends Controller @@ -26,9 +23,10 @@ public function __construct() } /** + * @param RegenerateInfluenceService $regenerateInfluenceService * @return View */ - public function advancedParameters(): View + public function advancedParameters(RegenerateInfluenceService $regenerateInfluenceService): View { $cacheSize = HelperService::formatBytes(HelperService::directorySize( storage_path('framework/cache/data') @@ -36,7 +34,7 @@ public function advancedParameters(): View $cacheEnabled = Features::accessible('cache'); - $influenceTableSize = Influence::count(); + $influenceTableSize = $regenerateInfluenceService->influenceCount(); return view('back-office.advanced-parameters', compact( 'cacheSize', 'cacheEnabled', 'influenceTableSize' @@ -55,23 +53,12 @@ public function purgeCache(): RedirectResponse } /** - * @param InfluencableFactory $influencableFactory + * @param RegenerateInfluenceService $regenerateInfluenceService * @return RedirectResponse */ - public function regenerateInfluences(InfluencableFactory $influencableFactory): RedirectResponse + public function regenerateInfluences(RegenerateInfluenceService $regenerateInfluenceService): RedirectResponse { - /** @var Influencable[] $influencables */ - $influencables = $influencableFactory->listEnabled(); - - DB::transaction(function() use ($influencables) { - DB::table('influence')->delete(); - - foreach($influencables as $influencable) { - $influencable->generateInfluence(); - } - }); - - cache()->flush(); + $regenerateInfluenceService->regenerate(); return redirect()->route('back-office.advanced-parameters') ->with('message', 'success|Les influences ont été regénérées avec succès.'); diff --git a/app/Services/RegenerateInfluenceService.php b/app/Services/RegenerateInfluenceService.php new file mode 100644 index 00000000..597d2569 --- /dev/null +++ b/app/Services/RegenerateInfluenceService.php @@ -0,0 +1,71 @@ +influencableFactory = $influencableFactory; + $this->db = $databaseManager; + $this->cache = $cache; + } + + /** + * Régénère les influences générées par les entités influençables. + */ + public function regenerate(): void + { + /** @var Influencable[] $influencables */ + $influencables = $this->influencableFactory->listEnabled(); + + $this->db->transaction(function() use ($influencables) { + $this->db->table('influence')->delete(); + + foreach($influencables as $influencable) { + $influencable->generateInfluence(); + } + }); + + $this->cache->flush(); + } + + /** + * Donne le nombre d'enregistrements dans la table "influences". + * + * @return int + */ + public function influenceCount(): int + { + return Influence::count(); + } +} From e2fe12445d3dd655121637eb12db0091e1fb886b Mon Sep 17 00:00:00 2001 From: Roxel Lay Date: Sun, 14 Jan 2024 20:57:28 +0100 Subject: [PATCH 7/8] =?UTF-8?q?MAJ=20.htaccess=20apr=C3=A8s=20d=C3=A9ploie?= =?UTF-8?q?ment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe34b877..8006c959 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -136,5 +136,6 @@ jobs: find ./.env -type f -exec sed -i '' -e "/^APP_BUILD=/s/=.*/=\'$BUILD_NUMBER\'/" {} \; php artisan optimize:clear php artisan migrate --force + php artisan monde:generate-htaccess php artisan monde:regenerate-influences php artisan up From a6babfa5c2d7c15d8b08a64b173e0265dc6c86d4 Mon Sep 17 00:00:00 2001 From: Roxel Lay Date: Sun, 14 Jan 2024 21:03:45 +0100 Subject: [PATCH 8/8] Ajoute v2.21 dans changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5afa0c9c..5ad7ac89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ # Notes de mise à jour -## [master](https://github.com/Roxayl/mondegc/compare/release-2.20...master) +## [master](https://github.com/Roxayl/mondegc/compare/release-2.21...master) -## [v2.20](https://github.com/Roxayl/mondegc/compare/release-2.18...release-2.19) - 2024-01-13 +## [v2.21](https://github.com/Roxayl/mondegc/compare/release-2.20...release-2.21) - 2024-01-14 + +## [v2.20](https://github.com/Roxayl/mondegc/compare/release-2.19...release-2.20) - 2024-01-13 ## [v2.19](https://github.com/Roxayl/mondegc/compare/release-2.18...release-2.19) - 2023-12-24