mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 05:47:28 -08:00
Fixes asset purge
This commit is contained in:
parent
74400eb9a1
commit
a8ff632740
|
@ -55,76 +55,78 @@ class Purge extends Command
|
||||||
|
|
||||||
if ($this->confirm("\n****************************************************\nTHIS WILL PURGE ALL SOFT-DELETED ITEMS IN YOUR SYSTEM. \nThere is NO undo. This WILL permanently destroy \nALL of your deleted data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) {
|
if ($this->confirm("\n****************************************************\nTHIS WILL PURGE ALL SOFT-DELETED ITEMS IN YOUR SYSTEM. \nThere is NO undo. This WILL permanently destroy \nALL of your deleted data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) {
|
||||||
|
|
||||||
$assets = Asset::whereNotNull('deleted_at');
|
/**
|
||||||
|
* Delete assets
|
||||||
|
*/
|
||||||
|
$assets = Asset::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
|
$assetcount = $assets->count();
|
||||||
|
$this->info($assets->count().' assets purged.');
|
||||||
|
$asset_assoc = 0;
|
||||||
|
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
|
$this->info('- Asset "'.$asset->showAssetName().'" deleted.');
|
||||||
|
$asset_assoc += $asset->assetlog()->count();
|
||||||
$asset->assetlog()->forceDelete();
|
$asset->assetlog()->forceDelete();
|
||||||
|
$asset->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
$assets->forceDelete();
|
$this->info($asset_assoc.' corresponding log records purged.');
|
||||||
|
|
||||||
$locations = Location::whereNotNull('deleted_at');
|
$locations = Location::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
|
$this->info($locations->count().' locations purged.');
|
||||||
$locations->forceDelete();
|
$locations->forceDelete();
|
||||||
|
|
||||||
$accessories = Accessory::whereNotNull('deleted_at');
|
|
||||||
|
$accessories = Accessory::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
foreach ($accessories as $accessory) {
|
foreach ($accessories as $accessory) {
|
||||||
$accessory->assetlog()->forceDelete();
|
$accessory->assetlog()->forceDelete();
|
||||||
}
|
}
|
||||||
$accessories->forceDelete();
|
$accessories->forceDelete();
|
||||||
|
|
||||||
$consumables = Consumable::whereNotNull('deleted_at');
|
$consumables = Consumable::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
foreach ($consumables as $consumable) {
|
foreach ($consumables as $consumable) {
|
||||||
$consumable->assetlog()->forceDelete();
|
$consumable->assetlog()->forceDelete();
|
||||||
}
|
}
|
||||||
$consumables->forceDelete();
|
$consumables->forceDelete();
|
||||||
|
|
||||||
$components = Component::whereNotNull('deleted_at');
|
$components = Component::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
foreach ($components as $component) {
|
foreach ($components as $component) {
|
||||||
$component->assetlog()->forceDelete();
|
$component->assetlog()->forceDelete();
|
||||||
}
|
}
|
||||||
$components->forceDelete();
|
$components->forceDelete();
|
||||||
|
|
||||||
$licenses = License::whereNotNull('deleted_at');
|
$licenses = License::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$licenses->forceDelete();
|
$licenses->forceDelete();
|
||||||
|
|
||||||
$models = AssetModel::whereNotNull('deleted_at');
|
$models = AssetModel::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$models->forceDelete();
|
$models->forceDelete();
|
||||||
|
|
||||||
$categories = Category::whereNotNull('deleted_at');
|
$categories = Category::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$categories->forceDelete();
|
$categories->forceDelete();
|
||||||
|
|
||||||
$suppliers = Supplier::whereNotNull('deleted_at');
|
$suppliers = Supplier::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$suppliers->forceDelete();
|
$suppliers->forceDelete();
|
||||||
|
|
||||||
$users = User::whereNotNull('deleted_at');
|
$users = User::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
|
$this->info($users->count().' users purged.');
|
||||||
|
$user_assoc = 0;
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
|
$this->info('- User "'.$user->username.'" deleted.');
|
||||||
|
$user_assoc += $user->userlog()->count();
|
||||||
$user->userlog()->forceDelete();
|
$user->userlog()->forceDelete();
|
||||||
|
$user->forceDelete();
|
||||||
}
|
}
|
||||||
$users->forceDelete();
|
$this->info($user_assoc.' corresponding log records purged.');
|
||||||
|
|
||||||
$manufacturers = Manufacturer::whereNotNull('deleted_at');
|
$manufacturers = Manufacturer::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$manufacturers->forceDelete();
|
$manufacturers->forceDelete();
|
||||||
|
|
||||||
$status_labels = StatusLabel::whereNotNull('deleted_at');
|
$status_labels = StatusLabel::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$status_labels->forceDelete();
|
$status_labels->forceDelete();
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
// \DB::update('drop table IF EXISTS accessories_users');
|
$this->info('Action canceled. Nothing was purged.');
|
||||||
// \DB::statement('drop table IF EXISTS asset_logs');
|
|
||||||
// \DB::statement('drop table IF EXISTS asset_maintenances');
|
|
||||||
// \DB::statement('drop table IF EXISTS asset_uploads');
|
|
||||||
// \DB::statement('drop table IF EXISTS consumables_users');
|
|
||||||
// \DB::statement('drop table IF EXISTS groups');
|
|
||||||
// //\DB::statement('drop table IF EXISTS history');
|
|
||||||
// \DB::statement('drop table IF EXISTS license_seats');
|
|
||||||
// \DB::statement('drop table IF EXISTS licenses');
|
|
||||||
// \DB::statement('drop table IF EXISTS requested_assets');
|
|
||||||
// \DB::statement('drop table IF EXISTS requests');
|
|
||||||
// \DB::statement('drop table IF EXISTS users_groups');
|
|
||||||
// \DB::statement('drop table IF EXISTS users');
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue