Skip to content

Commit 1fe2fd9

Browse files
authored
Merge pull request #17573 from spencerrlongg/feature/8709-bulk-deletion-of-asset-categories-suppliers-manufacturers
Fixed #8709 - Bulk Deletion of Categories, Suppliers, Manufa...
2 parents 5a38d9c + 5fdb999 commit 1fe2fd9

38 files changed

+947
-103
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace App\Actions\Categories;
4+
5+
use App\Exceptions\ItemStillHasAccessories;
6+
use App\Exceptions\ItemStillHasAssetModels;
7+
use App\Exceptions\ItemStillHasAssets;
8+
use App\Exceptions\ItemStillHasComponents;
9+
use App\Exceptions\ItemStillHasConsumables;
10+
use App\Exceptions\ItemStillHasLicenses;
11+
use App\Models\Category;
12+
use Illuminate\Support\Facades\Storage;
13+
14+
class DestroyCategoryAction
15+
{
16+
/**
17+
* @throws ItemStillHasAssets
18+
* @throws ItemStillHasAssetModels
19+
* @throws ItemStillHasComponents
20+
* @throws ItemStillHasAccessories
21+
* @throws ItemStillHasLicenses
22+
* @throws ItemStillHasConsumables
23+
*/
24+
static function run(Category $category): bool
25+
{
26+
$category->loadCount([
27+
'assets as assets_count',
28+
'accessories as accessories_count',
29+
'consumables as consumables_count',
30+
'components as components_count',
31+
'licenses as licenses_count',
32+
'models as models_count'
33+
]);
34+
35+
if ($category->assets_count > 0) {
36+
throw new ItemStillHasAssets($category);
37+
}
38+
if ($category->accessories_count > 0) {
39+
throw new ItemStillHasAccessories($category);
40+
}
41+
if ($category->consumables_count > 0) {
42+
throw new ItemStillHasConsumables($category);
43+
}
44+
if ($category->components_count > 0) {
45+
throw new ItemStillHasComponents($category);
46+
}
47+
if ($category->licenses_count > 0) {
48+
throw new ItemStillHasLicenses($category);
49+
}
50+
if ($category->models_count > 0) {
51+
throw new ItemStillHasAssetModels($category);
52+
}
53+
54+
Storage::disk('public')->delete('categories'.'/'.$category->image);
55+
$category->delete();
56+
57+
return true;
58+
}
59+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace App\Actions\Manufacturers;
4+
5+
use App\Exceptions\ItemStillHasAccessories;
6+
use App\Exceptions\ItemStillHasAssets;
7+
use App\Exceptions\ItemStillHasComponents;
8+
use App\Exceptions\ItemStillHasConsumables;
9+
use App\Exceptions\ItemStillHasLicenses;
10+
use App\Models\Manufacturer;
11+
use Illuminate\Support\Facades\Log;
12+
use Illuminate\Support\Facades\Storage;
13+
14+
class DeleteManufacturerAction
15+
{
16+
/**
17+
* @throws ItemStillHasAssets
18+
* @throws ItemStillHasComponents
19+
* @throws ItemStillHasAccessories
20+
* @throws ItemStillHasLicenses
21+
* @throws ItemStillHasConsumables
22+
*/
23+
static function run(Manufacturer $manufacturer): bool
24+
{
25+
$manufacturer->loadCount([
26+
'assets as assets_count',
27+
'accessories as accessories_count',
28+
'consumables as consumables_count',
29+
'components as components_count',
30+
'licenses as licenses_count',
31+
]);
32+
33+
if ($manufacturer->assets_count > 0) {
34+
throw new ItemStillHasAssets($manufacturer);
35+
}
36+
if ($manufacturer->accessories_count > 0) {
37+
throw new ItemStillHasAccessories($manufacturer);
38+
}
39+
if ($manufacturer->consumables_count > 0) {
40+
throw new ItemStillHasConsumables($manufacturer);
41+
}
42+
if ($manufacturer->components_count > 0) {
43+
throw new ItemStillHasComponents($manufacturer);
44+
}
45+
if ($manufacturer->licenses_count > 0) {
46+
throw new ItemStillHasLicenses($manufacturer);
47+
}
48+
49+
if ($manufacturer->image) {
50+
try {
51+
Storage::disk('public')->delete('manufacturers/'.$manufacturer->image);
52+
} catch (\Exception $e) {
53+
Log::info($e);
54+
}
55+
}
56+
57+
$manufacturer->delete();
58+
//dd($manufacturer);
59+
60+
return true;
61+
}
62+
63+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace App\Actions\Suppliers;
4+
5+
use App\Exceptions\ItemStillHasAccessories;
6+
use App\Exceptions\ItemStillHasComponents;
7+
use App\Exceptions\ItemStillHasConsumables;
8+
use App\Models\Supplier;
9+
use App\Exceptions\ItemStillHasAssets;
10+
use App\Exceptions\ItemStillHasMaintenances;
11+
use App\Exceptions\ItemStillHasLicenses;
12+
use Illuminate\Support\Facades\Log;
13+
use Illuminate\Support\Facades\Storage;
14+
15+
class DestroySupplierAction
16+
{
17+
/**
18+
*
19+
* @throws ItemStillHasLicenses
20+
* @throws ItemStillHasAssets
21+
* @throws ItemStillHasMaintenances
22+
* @throws ItemStillHasAccessories
23+
* @throws ItemStillHasConsumables
24+
* @throws ItemStillHasComponents
25+
*/
26+
static function run(Supplier $supplier): bool
27+
{
28+
$supplier->loadCount([
29+
'maintenances as maintenances_count',
30+
'assets as assets_count',
31+
'licenses as licenses_count',
32+
'accessories as accessories_count',
33+
'consumables as consumables_count',
34+
'components as components_count',
35+
]);
36+
if ($supplier->assets_count > 0) {
37+
throw new ItemStillHasAssets($supplier);
38+
}
39+
40+
if ($supplier->maintenances_count > 0) {
41+
throw new ItemStillHasMaintenances($supplier);
42+
}
43+
44+
if ($supplier->licenses_count > 0) {
45+
throw new ItemStillHasLicenses($supplier);
46+
}
47+
48+
if ($supplier->accessories_count > 0) {
49+
throw new ItemStillHasAccessories($supplier);
50+
}
51+
52+
if ($supplier->consumables_count > 0) {
53+
throw new ItemStillHasConsumables($supplier);
54+
}
55+
56+
if ($supplier->components_count > 0) {
57+
throw new ItemStillHasComponents($supplier);
58+
}
59+
60+
if ($supplier->image) {
61+
try {
62+
Storage::disk('public')->delete('suppliers/'.$supplier->image);
63+
} catch (\Exception $e) {
64+
Log::info($e->getMessage());
65+
}
66+
}
67+
68+
$supplier->delete();
69+
70+
return true;
71+
}
72+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
class ItemStillHasAccessories extends ItemStillHasChildren
8+
{
9+
//
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
class ItemStillHasAssetModels extends ItemStillHasChildren
8+
{
9+
//
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
class ItemStillHasAssets extends ItemStillHasChildren
8+
{
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
class ItemStillHasChildren extends Exception
8+
{
9+
//public function __construct($message, $code = 0, Exception $previous = null, $parent, $children)
10+
//{
11+
// trans()
12+
//
13+
//}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
class ItemStillHasComponents extends ItemStillHasChildren
8+
{
9+
//
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
class ItemStillHasConsumables extends ItemStillHasChildren
8+
{
9+
//
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
7+
class ItemStillHasLicenses extends ItemStillHasChildren
8+
{
9+
//
10+
}

0 commit comments

Comments
 (0)