mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
parent
76c38c7f9b
commit
a9b811dc44
@ -24,7 +24,7 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
||||
$cat_ids[] = $cat->id;
|
||||
$subCat = $cat->parent_category_id;
|
||||
if ($subCat != null) {
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$parCat = $this->getCat($subCat);
|
||||
if (isset($parCat)) {
|
||||
if ($parCat->parent_category_id == "") {
|
||||
@ -83,9 +83,8 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
||||
public function deleteSubCategories($id)
|
||||
{
|
||||
$subCategories = $this->getAllSubCategories($id);
|
||||
foreach ($subCategories as $subCategory) {
|
||||
$this->find($subCategory)->delete();
|
||||
}
|
||||
$this->newQuery()->whereIn('id', $subCategories)->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -68,37 +68,6 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
|
||||
{
|
||||
$this->model->find($id)->delete();
|
||||
|
||||
$this->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();
|
||||
}
|
||||
$this->model->deleteSubCategories($id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,4 @@ interface CategoryRepositoryInterface extends EntryRepositoryInterface
|
||||
public function getCategories();
|
||||
|
||||
public function DeleteCategories($id);
|
||||
|
||||
public function deleteSubcategories($id);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user