From 7429db5768ffc3d465439727553fa76d0a691021 Mon Sep 17 00:00:00 2001 From: vedatakd Date: Fri, 26 Jun 2020 14:02:35 +0300 Subject: [PATCH] fix add remove error --- .../advs-module/resources/lang/en/message.php | 1 + .../advs-module/src/Adv/AdvRepository.php | 10 +++------- .../src/Adv/Contract/AdvRepositoryInterface.php | 2 -- .../src/Http/Controller/advsController.php | 14 +++++++++----- .../src/Http/Controller/MyProfileController.php | 3 --- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/message.php b/addons/default/visiosoft/advs-module/resources/lang/en/message.php index 6b458b4ff..353e62a2a 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/message.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/message.php @@ -22,4 +22,5 @@ return [ 'currency_converted' => 'Currency Converted Successfully.', 'choose_user' => 'Choose a user', 'owner_updated_successfully' => 'The Owner Has Been Updated Successfully!', + 'no_add_found' => 'No Ad Found!', ]; diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index 13f96caad..1e8f9ac7b 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -340,12 +340,6 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface $adv->update(['cover_photo' => $coverPhoto]); } - public function delete_empty_advs() - { - AdvsAdvsEntryModel::query()->where('slug', "")->forceDelete(); - DB::table('advs_advs_translations')->where('name', NULL)->delete(); - } - public function getRecommendedAds($id) { return AdvModel::query() @@ -364,7 +358,9 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface public function getAdvArray($id) { - return AdvsAdvsEntryModel::query()->where('advs_advs.id', $id)->first()->toArray(); + $ad = AdvsAdvsEntryModel::query()->where('advs_advs.id', $id)->first(); + + return ($ad !== null) ? $ad->toArray() : null; } public function getQuantity($quantity, $type, $item) diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php index 5b4309af8..8ee44cdb3 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php @@ -20,8 +20,6 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface public function cover_image_update($adv); - public function delete_empty_advs(); - public function getRecommendedAds($id); public function getLastAd($id); diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php index bc9e7955a..2a992af33 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -567,11 +567,10 @@ class AdvsController extends PublicController $adv = AdvsAdvsEntryModel::find($request->update_id); if ($advModel->is_enabled('packages') and $adv->slug == "") { - $cat = app('Visiosoft\PackagesModule\Http\Controller\PackageFEController')->AdLimitForNewAd($request); - if(!is_null($cat)) - { - return redirect('/'); - } + $cat = app('Visiosoft\PackagesModule\Http\Controller\PackageFEController')->AdLimitForNewAd($request); + if (!is_null($cat)) { + return redirect('/'); + } } // Create options @@ -695,6 +694,11 @@ class AdvsController extends PublicController $isActive = new AdvModel(); $adv = $advRepository->getAdvArray($id); + if (is_null($adv)) { + $this->messages->error(trans('visiosoft.module.advs::message.no_add_found')); + return $this->redirect->to(route('advs::create_adv')); + } + if ($adv['created_by_id'] != auth()->id() && !auth()->user()->hasPermission('visiosoft.module.advs::advs.write')) { abort(403); diff --git a/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php b/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php index cfe7fdd95..8dd0758d1 100644 --- a/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php +++ b/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php @@ -50,9 +50,6 @@ class MyProfileController extends PublicController public function home(ProfileFormBuilder $form, AdvRepositoryInterface $advRepository) { - //clear empty ads - $advRepository->delete_empty_advs(); - $advs_count = new AdvModel(); $advs_count = count($advs_count->myAdvsByUser()->get());