mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-23 03:32:32 -08:00
Add a 'soft' delete option to the pave tool. This leaves db structure and migrations in place but removes everything inside the db except the first user.
This commit is contained in:
parent
9f6eb02afc
commit
6ba37a3a8d
|
@ -5,6 +5,22 @@ namespace App\Console\Commands;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use DB;
|
use DB;
|
||||||
|
|
||||||
|
use App\Models\Accessory;
|
||||||
|
use App\Models\Asset;
|
||||||
|
use App\Models\AssetModel;
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Component;
|
||||||
|
use App\Models\Consumable;
|
||||||
|
use App\Models\Depreciation;
|
||||||
|
use App\Models\Group;
|
||||||
|
use App\Models\License;
|
||||||
|
use App\Models\LicenseSeat;
|
||||||
|
use App\Models\Location;
|
||||||
|
use App\Models\Manufacturer;
|
||||||
|
use App\Models\Statuslabel;
|
||||||
|
use App\Models\Supplier;
|
||||||
|
|
||||||
class PaveIt extends Command
|
class PaveIt extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +28,8 @@ class PaveIt extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'snipeit:pave';
|
protected $signature = 'snipeit:pave
|
||||||
|
{--soft: Perform a "Soft" Delete, leaving all migrations, table structure, and the first user in place.}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
|
@ -38,9 +55,42 @@ class PaveIt extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE DATA IN YOUR DATABASE. \nThere is NO undo. This WILL destroy ALL of your data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]"))
|
||||||
|
{
|
||||||
|
if( $this->option('soft'))
|
||||||
|
{
|
||||||
|
Accessory::getQuery()->delete();
|
||||||
|
Asset::getQuery()->delete();
|
||||||
|
Category::getQuery()->delete();
|
||||||
|
Company::getQuery()->delete();
|
||||||
|
Component::getQuery()->delete();
|
||||||
|
Consumable::getQuery()->delete();
|
||||||
|
Depreciation::getQuery()->delete();
|
||||||
|
License::getQuery()->delete();
|
||||||
|
LicenseSeat::getQuery()->delete();
|
||||||
|
Location::getQuery()->delete();
|
||||||
|
Manufacturer::getQuery()->delete();
|
||||||
|
AssetModel::getQuery()->delete();
|
||||||
|
Statuslabel::getQuery()->delete();
|
||||||
|
Supplier::getQuery()->delete();
|
||||||
|
Group::getQuery()->delete();
|
||||||
|
|
||||||
if ($this->confirm("\n****************************************************\nTHIS WILL DROP ALL OF THE TABLES IN YOUR DATABASE. \nThere is NO undo. This WILL destroy ALL of your data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) {
|
DB::statement('delete from accessories_users');
|
||||||
|
DB::statement('delete from asset_logs');
|
||||||
|
DB::statement('delete from asset_maintenances');
|
||||||
|
DB::statement('delete from asset_uploads');
|
||||||
|
DB::statement('delete from consumables_users');
|
||||||
|
DB::statement('delete from custom_field_custom_fieldset');
|
||||||
|
DB::statement('delete from custom_fields');
|
||||||
|
DB::statement('delete from custom_fieldsets');
|
||||||
|
DB::statement('delete from components_assets');
|
||||||
|
DB::statement('delete from password_resets');
|
||||||
|
DB::statement('delete from requested_assets');
|
||||||
|
DB::statement('delete from requests');
|
||||||
|
DB::statement('delete from throttle');
|
||||||
|
DB::statement('delete from users_groups');
|
||||||
|
DB::statement('delete from users WHERE id!=1');
|
||||||
|
} else {
|
||||||
\DB::statement('drop table IF EXISTS accessories_users');
|
\DB::statement('drop table IF EXISTS accessories_users');
|
||||||
\DB::statement('drop table IF EXISTS accessories');
|
\DB::statement('drop table IF EXISTS accessories');
|
||||||
\DB::statement('drop table IF EXISTS asset_logs');
|
\DB::statement('drop table IF EXISTS asset_logs');
|
||||||
|
@ -74,9 +124,7 @@ class PaveIt extends Command
|
||||||
\DB::statement('drop table IF EXISTS throttle');
|
\DB::statement('drop table IF EXISTS throttle');
|
||||||
\DB::statement('drop table IF EXISTS users_groups');
|
\DB::statement('drop table IF EXISTS users_groups');
|
||||||
\DB::statement('drop table IF EXISTS users');
|
\DB::statement('drop table IF EXISTS users');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue