Merge pull request #602 from openclassify/vedatakd

fix category delete
This commit is contained in:
Ozcan Durak 2020-06-25 12:48:15 +03:00 committed by GitHub
commit d9c3d34118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 17 deletions

View File

@ -76,10 +76,12 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
return $this->model->orderBy('sort_order')->get();
}
public function removeCatFromAds($id)
public function removeCatFromAds($category)
{
$category = $this->find($id);
$catLevelNum = is_null($category->parent_category_id) ? 1 : $this->model->getCatLevel($category->id);
$catLevelNum = 1;
if (!is_null($category->parent_category_id)) {
$catLevelNum = $this->model->getCatLevel($category->id);
}
$catLevelText = "cat" . $catLevelNum;
$advs = $this->advRepository->newQuery()->where($catLevelText, $category->id)->get();
@ -94,13 +96,15 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
public function DeleteCategories($id)
{
// Remove deleted category from ads
$this->removeCatFromAds($id);
if (!is_null($category = $this->find($id))) {
// Remove deleted category from ads
$this->removeCatFromAds($category);
// Delete the category
$this->model->find($id)->delete();
// Delete the category
$this->model->find($id)->delete();
// Delete the subcategories
$this->model->deleteSubCategories($id);
// Delete the subcategories
$this->model->deleteSubCategories($id);
}
}
}

View File

@ -47,8 +47,7 @@ class CategoryController extends AdminController
$this->messages->error('Selected category has no sub-categories.');
return back();
}
if($request->view != "trash")
{
if ($request->view != "trash") {
$table->setTableEntries($categories);
}
@ -157,7 +156,8 @@ class CategoryController extends AdminController
return $this->view->make('visiosoft.module.cats::cats/admin-cat');
}
public function endsWith($string, $test) {
public function endsWith($string, $test)
{
$strlen = strlen($string);
$testlen = strlen($test);
if ($testlen > $strlen) return false;
@ -185,12 +185,13 @@ class CategoryController extends AdminController
public function delete(CategoryRepositoryInterface $categoryRepository, Request $request, CategoryModel $categoryModel, $id)
{
$categoryRepository->DeleteCategories($id);
$subCats = $categoryRepository->getSubCatById($request->parent);
if (count($subCats)) {
return redirect('admin/cats?cat=' . $request->parent)->with('success', ['Category and related sub-categories deleted successfully.']);
} else {
return redirect('admin/cats')->with('success', ['Category and related sub-categories deleted successfully.']);
if ($request->parent != "") {
$subCats = $categoryRepository->getSubCatById($request->parent);
if (count($subCats)) {
return redirect('admin/cats?cat=' . $request->parent)->with('success', ['Category and related sub-categories deleted successfully.']);
}
}
return redirect('admin/cats')->with('success', ['Category and related sub-categories deleted successfully.']);
}
public function cleanSubcats()