From 298475d7de6f4ac751b45f045eed970e6cfe625a Mon Sep 17 00:00:00 2001 From: Spitfire Date: Thu, 22 Aug 2024 10:44:18 -0600 Subject: [PATCH 1/3] PostRecove --- .../Campaign/PostRecoveryController.php | 77 ------------------- .../Campaign/RecoveryController.php | 56 ++++++-------- lang/en/campaigns/recovery.php | 14 +--- .../views/campaigns/recovery/_table.blade.php | 23 ++++++ .../views/campaigns/recovery/index.blade.php | 36 ++------- routes/campaigns/campaign.php | 3 - 6 files changed, 59 insertions(+), 150 deletions(-) delete mode 100644 app/Http/Controllers/Campaign/PostRecoveryController.php create mode 100644 resources/views/campaigns/recovery/_table.blade.php diff --git a/app/Http/Controllers/Campaign/PostRecoveryController.php b/app/Http/Controllers/Campaign/PostRecoveryController.php deleted file mode 100644 index 806396bbef..0000000000 --- a/app/Http/Controllers/Campaign/PostRecoveryController.php +++ /dev/null @@ -1,77 +0,0 @@ -middleware('auth'); - - $this->service = $service; - } - - /** - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\JsonResponse - * @throws \Illuminate\Auth\Access\AuthorizationException - */ - public function index(Campaign $campaign) - { - $this->authorize('recover', $campaign); - - Datagrid::layout(\App\Renderers\Layouts\Campaign\PostRecovery::class) - ->permissions(false); - - $rows = $campaign->posts()->onlyTrashed() - ->sort(request()->only(['o', 'k']), ['deleted_at' => 'DESC']) - ->whereDate('posts.deleted_at', '>=', Carbon::today()->subDays(config('entities.hard_delete_posts'))) - ->paginate(); - - // Ajax Datagrid - if (request()->ajax()) { - $html = view('layouts.datagrid._table') - ->with('rows', $rows) - ->render(); - return response()->json([ - 'success' => true, - 'html' => $html, - ]); - } - $isPost = true; - return view('campaigns.recovery.index', compact('rows', 'campaign', 'isPost')); - } - - public function recover(Request $request, Campaign $campaign) - { - if (request()->ajax()) { - return response()->json(['success' => true]); - } - if (!$campaign->boosted()) { - return redirect() - ->route('recovery', $campaign) - ->with('boosted-pitch', true) - ; - } - - try { - $count = $this->service->recover($request->get('model', [])); - return redirect() - ->route('recovery.posts', $campaign) - ->with('success', trans_choice('campaigns/recovery.posts.success', $count, ['count' => $count])); - } catch (Exception $e) { - return redirect() - ->route('recovery.posts', $campaign) - ->with('error', __('campaigns/recovery.posts.error')); - } - } -} diff --git a/app/Http/Controllers/Campaign/RecoveryController.php b/app/Http/Controllers/Campaign/RecoveryController.php index dd4a78f4e2..9b0d1cba8b 100644 --- a/app/Http/Controllers/Campaign/RecoveryController.php +++ b/app/Http/Controllers/Campaign/RecoveryController.php @@ -2,24 +2,25 @@ namespace App\Http\Controllers\Campaign; -use App\Facades\Datagrid; use App\Http\Controllers\Controller; use App\Models\Campaign; -use App\Models\Entity; -use App\Services\Entity\RecoveryService; -use Carbon\Carbon; +use App\Services\Entity\RecoveryService as EntityRecoveryService; +use App\Services\Posts\RecoveryService; use Exception; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; class RecoveryController extends Controller { - protected RecoveryService $service; + protected RecoveryService $postService; + protected EntityRecoveryService $entityService; - public function __construct(RecoveryService $service) + public function __construct(RecoveryService $postService, EntityRecoveryService $entityService) { $this->middleware('auth'); - $this->service = $service; + $this->postService = $postService; + $this->entityService = $entityService; } /** @@ -30,34 +31,24 @@ public function index(Campaign $campaign) { $this->authorize('recover', $campaign); - Datagrid::layout(\App\Renderers\Layouts\Campaign\Recovery::class) - ->permissions(false); + $elements = DB::select( + 'select id, name, deleted_at, deleted_by, "entity" as type + from entities + where deleted_at is not null and campaign_id = ' . $campaign->id . ' + union all + select p.id, p.name, p.deleted_at, p.deleted_by, "post" as type + from posts as p + left join entities as e on e.id = p.entity_id + where p.deleted_at is not null and e.deleted_at is null and e.campaign_id = ' . $campaign->id . + ' order by deleted_at DESC' - $rows = Entity::onlyTrashed() - ->with('image') - ->sort(request()->only(['o', 'k']), ['deleted_at' => 'DESC']) - ->whereDate('deleted_at', '>=', Carbon::today()->subDays(config('entities.hard_delete'))) - ->paginate(); + ); - // Ajax Datagrid - if (request()->ajax()) { - $html = view('layouts.datagrid._table') - ->with('rows', $rows) - ->render(); - return response()->json([ - 'success' => true, - 'html' => $html, - ]); - } - - return view('campaigns.recovery.index', compact('rows', 'campaign')); + return view('campaigns.recovery.index', compact('elements', 'campaign')); } public function recover(Request $request, Campaign $campaign) { - if (request()->ajax()) { - return response()->json(['success' => true]); - } if (!$campaign->boosted()) { return redirect() ->route('recovery', $campaign) @@ -66,10 +57,13 @@ public function recover(Request $request, Campaign $campaign) } try { - $count = $this->service->recover($request->get('model', [])); + $countEntity = $this->entityService->recover($request->get('entity', [])); + $countPost = $this->postService->recover($request->get('post', [])); + + $count = $countEntity + $countPost; return redirect() ->route('recovery', $campaign) - ->with('success', trans_choice('campaigns/recovery.success', $count, ['count' => $count])); + ->with('success', trans_choice('campaigns/recovery.success_v2', $count, ['count' => $count])); } catch (Exception $e) { return redirect() ->route('recovery', $campaign) diff --git a/lang/en/campaigns/recovery.php b/lang/en/campaigns/recovery.php index 55ebbb7c7d..d4ba1e1c02 100644 --- a/lang/en/campaigns/recovery.php +++ b/lang/en/campaigns/recovery.php @@ -6,18 +6,10 @@ ], 'error' => 'An error occurred trying to recover entities.', 'fields' => [ - 'deleted' => 'Deleted', + 'deleted' => 'Deleted', + 'deleted_at' => 'Deleted :date' ], 'helper' => 'Deleted entities of the campaign can be recovered for up to :count days. Entities deleted while the campaign isn\'t upgraded to premium status are still recoverable once the campaign is upgraded.', - 'post-title' => 'Post Recovery', - 'posts' => [ - 'error' => 'An error occurred trying to recover posts.', - 'success' => '{1} :count post was recovered.|[2,*] :count posts were recovered.', - ], - 'success' => '{1} :count entity was recovered.|[2,*] :count entities were recovered.', + 'success_v2' => '{1} :count post or entity was recovered.|[2,*] :count posts and/or entities were recovered.', 'title' => 'Entity Recovery', - 'toggle' => [ - 'entity' => 'Switch to entity recovery', - 'post' => 'Switch to post recovery', - ], ]; diff --git a/resources/views/campaigns/recovery/_table.blade.php b/resources/views/campaigns/recovery/_table.blade.php new file mode 100644 index 0000000000..98fe82cf43 --- /dev/null +++ b/resources/views/campaigns/recovery/_table.blade.php @@ -0,0 +1,23 @@ +
+ @foreach ($elements as $element) +
+
+
+ +
+
{{ $element->name }}
+ +
+ @if ($element->type == 'entity') + {{ __('crud.fields.entity') }} + @else + {{ __('entities.post') }} + @endif +
+
+
+ {{ __('campaigns/recovery.fields.deleted_at', ['date' => \Carbon\Carbon::createFromTimeStamp(strtotime($element->deleted_at))->diffForHumans()]) }} +
+
+ @endforeach +
diff --git a/resources/views/campaigns/recovery/index.blade.php b/resources/views/campaigns/recovery/index.blade.php index f5bfc12e12..d366b8fffa 100644 --- a/resources/views/campaigns/recovery/index.blade.php +++ b/resources/views/campaigns/recovery/index.blade.php @@ -9,51 +9,31 @@ ]) @section('content') - +
@include('partials.errors')

- @if (isset($isPost)) - {{ __('campaigns/recovery.post-title') }} - @else {{ __('campaigns/recovery.title') }} - @endif

+ - @if(isset($isPost)) - - - {{ __('campaigns/recovery.toggle.entity') }} - - @else - - - {{ __('campaigns/recovery.toggle.post') }} - - @endif
@if (session()->get('boosted-pitch')) @endif - - @if(Datagrid::hasBulks()) - -
- @include('layouts.datagrid._table') -
-
- @else -
- @include('layouts.datagrid._table') -
- @endif + @include('campaigns.recovery._table')
+
+ @endsection diff --git a/routes/campaigns/campaign.php b/routes/campaigns/campaign.php index c3f4750627..cc789d7ea0 100644 --- a/routes/campaigns/campaign.php +++ b/routes/campaigns/campaign.php @@ -52,9 +52,6 @@ Route::get('/w/{campaign}/recovery', 'Campaign\RecoveryController@index')->name('recovery'); Route::post('/w/{campaign}/recovery', 'Campaign\RecoveryController@recover')->name('recovery.save'); -Route::get('/w/{campaign}/recovery/posts', 'Campaign\PostRecoveryController@index')->name('recovery.posts'); -Route::post('/w/{campaign}/recovery/posts', 'Campaign\PostRecoveryController@recover')->name('recovery.save.posts'); - // Stats Route::get('/w/{campaign}/achievements', 'Campaign\AchievementController@index')->name('stats'); From dab558196590e7a138df7c1727dbd0f470f5f9a9 Mon Sep 17 00:00:00 2001 From: spitfire305 Date: Thu, 22 Aug 2024 16:47:46 +0000 Subject: [PATCH 2/3] Fix styling --- app/Http/Controllers/Campaign/RecoveryController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Campaign/RecoveryController.php b/app/Http/Controllers/Campaign/RecoveryController.php index 9b0d1cba8b..608859ce09 100644 --- a/app/Http/Controllers/Campaign/RecoveryController.php +++ b/app/Http/Controllers/Campaign/RecoveryController.php @@ -32,7 +32,7 @@ public function index(Campaign $campaign) $this->authorize('recover', $campaign); $elements = DB::select( - 'select id, name, deleted_at, deleted_by, "entity" as type + 'select id, name, deleted_at, deleted_by, "entity" as type from entities where deleted_at is not null and campaign_id = ' . $campaign->id . ' union all @@ -41,8 +41,7 @@ public function index(Campaign $campaign) left join entities as e on e.id = p.entity_id where p.deleted_at is not null and e.deleted_at is null and e.campaign_id = ' . $campaign->id . ' order by deleted_at DESC' - - ); + ); return view('campaigns.recovery.index', compact('elements', 'campaign')); } From 583ca1e99ea245dafbe8b77da8a9ff5caafd2389 Mon Sep 17 00:00:00 2001 From: Spitfire Date: Wed, 28 Aug 2024 07:46:56 -0600 Subject: [PATCH 3/3] Fixed translation --- lang/en/campaigns/recovery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/en/campaigns/recovery.php b/lang/en/campaigns/recovery.php index d4ba1e1c02..14937edcf2 100644 --- a/lang/en/campaigns/recovery.php +++ b/lang/en/campaigns/recovery.php @@ -10,6 +10,6 @@ 'deleted_at' => 'Deleted :date' ], 'helper' => 'Deleted entities of the campaign can be recovered for up to :count days. Entities deleted while the campaign isn\'t upgraded to premium status are still recoverable once the campaign is upgraded.', - 'success_v2' => '{1} :count post or entity was recovered.|[2,*] :count posts and/or entities were recovered.', + 'success_v2' => '{1} :count element was recovered.|[2,*] :count elements were recovered.', 'title' => 'Entity Recovery', ];