mirror of
https://github.com/openclassify/openclassify.git
synced 2026-02-09 23:06:08 -06:00
parent
76c38c7f9b
commit
a9b811dc44
@ -24,7 +24,7 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
|||||||
$cat_ids[] = $cat->id;
|
$cat_ids[] = $cat->id;
|
||||||
$subCat = $cat->parent_category_id;
|
$subCat = $cat->parent_category_id;
|
||||||
if ($subCat != null) {
|
if ($subCat != null) {
|
||||||
for ($i = 0; $i < 7; $i++) {
|
for ($i = 0; $i < 10; $i++) {
|
||||||
$parCat = $this->getCat($subCat);
|
$parCat = $this->getCat($subCat);
|
||||||
if (isset($parCat)) {
|
if (isset($parCat)) {
|
||||||
if ($parCat->parent_category_id == "") {
|
if ($parCat->parent_category_id == "") {
|
||||||
@ -83,9 +83,8 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
|||||||
public function deleteSubCategories($id)
|
public function deleteSubCategories($id)
|
||||||
{
|
{
|
||||||
$subCategories = $this->getAllSubCategories($id);
|
$subCategories = $this->getAllSubCategories($id);
|
||||||
foreach ($subCategories as $subCategory) {
|
$this->newQuery()->whereIn('id', $subCategories)->delete();
|
||||||
$this->find($subCategory)->delete();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -68,37 +68,6 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
|
|||||||
{
|
{
|
||||||
$this->model->find($id)->delete();
|
$this->model->find($id)->delete();
|
||||||
|
|
||||||
$this->deleteSubcategories($id);
|
$this->model->deleteSubCategories($id);
|
||||||
}
|
|
||||||
|
|
||||||
public function deleteSubcategories($id)
|
|
||||||
{
|
|
||||||
// Get all subcategories
|
|
||||||
$allSubcategories = array();
|
|
||||||
$subcategories = $this->getSubCatById($id);
|
|
||||||
if (count($subcategories)) {
|
|
||||||
foreach ($subcategories as $subcategory) {
|
|
||||||
$allSubcategories[$subcategory->id] = ['id' => $subcategory->id, 'processed' => false];
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
$unprocessedCategories = array_filter($allSubcategories, function ($unprocessedCategory) {
|
|
||||||
return $unprocessedCategory['processed'] === false;
|
|
||||||
});
|
|
||||||
foreach ($unprocessedCategories as $unprocessedCategory) {
|
|
||||||
$subcategories = $this->getSubCatById($unprocessedCategory['id']);
|
|
||||||
foreach ($subcategories as $subcategory) {
|
|
||||||
$allSubcategories[$subcategory->id] = ['id' => $subcategory->id, 'processed' => false];
|
|
||||||
}
|
|
||||||
$allSubcategories[$unprocessedCategory['id']]['processed'] = true;
|
|
||||||
}
|
|
||||||
} while (count($unprocessedCategories));
|
|
||||||
|
|
||||||
// Delete all subcategories
|
|
||||||
$whereIn = array();
|
|
||||||
foreach ($allSubcategories as $category) {
|
|
||||||
$whereIn[] = $category['id'];
|
|
||||||
}
|
|
||||||
$this->newQuery()->whereIn('id', $whereIn)->delete();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,4 @@ interface CategoryRepositoryInterface extends EntryRepositoryInterface
|
|||||||
public function getCategories();
|
public function getCategories();
|
||||||
|
|
||||||
public function DeleteCategories($id);
|
public function DeleteCategories($id);
|
||||||
|
|
||||||
public function deleteSubcategories($id);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user