2017-10-06 22:58:00 -07:00
< ? php
namespace App\Console\Commands ;
use Illuminate\Console\Command ;
use App\Models\Asset ;
use App\Models\Actionlog ;
use App\Models\Accessory ;
use App\Models\AssetModel ;
use App\Models\AssetMaintenance ;
use App\Models\Category ;
use App\Models\Company ;
use App\Models\Consumable ;
use App\Models\Component ;
use App\Models\License ;
use App\Models\CustomField ;
use App\Models\CustomFieldset ;
use App\Models\Department ;
use App\Models\Depreciation ;
use App\Models\Group ;
use App\Models\Import ;
use App\Models\LicenseSeat ;
use App\Models\Location ;
use App\Models\Manufacturer ;
use App\Models\Statuslabel ;
use App\Models\Supplier ;
use App\Models\User ;
use Illuminate\Support\Facades\Schema ;
use Illuminate\Database\Schema\Blueprint ;
use DB ;
class DemoData extends Command
{
/**
* The name and signature of the console command .
*
* @ var string
*/
2017-10-07 00:02:37 -07:00
protected $signature = 'snipeit:demo-seed {--nukeusers}' ;
2017-10-06 22:58:00 -07:00
/**
* The console command description .
*
* @ var string
*/
protected $description = 'This will seed the Snipe-IT database with realistic-looking data. ' ;
/**
* Create a new command instance .
*
* @ return void
*/
public function __construct ()
{
parent :: __construct ();
}
/**
* Execute the console command .
*
* @ return mixed
*/
public function handle ()
{
if ( config ( 'app.env' ) == 'production' ) {
$this -> error ( 'This action cannot be performed on a production system.' );
$this -> info ( 'If you wish to reset a production system, please put your' );
$this -> info ( 'app into develop mode. This is for your protection.' );
return false ;
}
if ( $this -> confirm ( " !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n This will overwrite your existing database. Do you wish to continue? " )) {
2017-10-07 00:02:37 -07:00
Import :: truncate ();
AssetMaintenance :: truncate ();
Group :: truncate ();
Company :: truncate ();
CustomField :: truncate ();
Group :: truncate ();
CustomFieldset :: truncate ();
DB :: table ( 'custom_field_custom_fieldset' ) -> truncate ();
DB :: table ( 'checkout_requests' ) -> truncate ();
2017-10-06 22:58:00 -07:00
$this -> dropRealCustomFieldsColumns ();
$this -> dropAndCreateCategories ();
$this -> dropAndCreateManufacturers ();
$this -> dropAndCreateAssetModels ();
$this -> dropAndCreateStatusLabels ();
$this -> dropAndCreateDepreciations ();
$this -> dropAndCreateSuppliers ();
$this -> dropAndCreateAccessories ();
$this -> dropAndCreateLicenses ();
$this -> dropAndCreateComponents ();
$this -> dropAndCreateConsumables ();
2017-10-07 00:02:37 -07:00
$this -> dropAndCreateLocations ();
if ( $this -> option ( 'nukeusers' )) {
$this -> dropAndCreateUsers ();
}
2017-10-06 22:58:00 -07:00
2017-10-07 00:02:37 -07:00
$this -> dropAndCreateAssets ();
$this -> dropAndCreateActionlogs ();
$this -> dropAndCreateDepartments ();
2017-10-06 22:58:00 -07:00
}
}
public function dropAndCreateAssets () {
Asset :: truncate ();
$assets = [
// Assets
[
'id' => 1 ,
'user_id' => 1 ,
'name' => 'Brady Laptop' ,
'model_id' => 1 ,
'assigned_to' => null ,
'assigned_type' => null ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000341'
],
[
'id' => 2 ,
'user_id' => 1 ,
'name' => 'Alison Laptop' ,
'model_id' => 1 ,
'assigned_to' => null ,
'assigned_type' => null ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000342'
],
[
'id' => 3 ,
'user_id' => 1 ,
'name' => 'Frontdesk Laptop' ,
'model_id' => 1 ,
'assigned_to' => null ,
'assigned_type' => null ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 2 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000343'
],
[
'id' => 4 ,
'user_id' => 1 ,
'name' => null ,
'model_id' => 2 ,
'assigned_to' => 1 ,
'assigned_type' => User :: class ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000344'
],
[
'id' => 5 ,
'user_id' => 1 ,
'name' => null ,
'model_id' => 3 ,
'assigned_to' => 1 ,
'assigned_type' => User :: class ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000345'
],
[
'id' => 6 ,
'user_id' => 1 ,
'name' => 'Backroom Desktop' ,
'model_id' => 3 ,
'assigned_to' => 2 ,
'assigned_type' => Location :: class ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000346'
],
[
'id' => 7 ,
'user_id' => 1 ,
'name' => 'Lobby Laptop' ,
'model_id' => 4 ,
'assigned_to' => 2 ,
'assigned_type' => Location :: class ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000347'
],
[
'id' => 8 ,
'user_id' => 1 ,
'name' => 'Conference Room A Polycom' ,
'model_id' => 11 ,
'assigned_to' => 2 ,
'assigned_type' => Location :: class ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000348'
],
[
'id' => 9 ,
'user_id' => 1 ,
'name' => null ,
'model_id' => 12 ,
'assigned_to' => null ,
'assigned_type' => null ,
'purchase_cost' => '799.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000349'
],
[
'id' => 10 ,
'user_id' => 1 ,
'name' => null ,
'model_id' => 13 ,
'assigned_to' => 1 ,
'assigned_type' => User :: class ,
'purchase_cost' => '799.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000310'
],
[
'id' => 11 ,
'user_id' => 1 ,
'name' => null ,
'model_id' => 14 ,
'assigned_to' => null ,
'assigned_type' => null ,
'purchase_cost' => '899.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000311'
],
2017-10-07 00:02:37 -07:00
[
'id' => 12 ,
'user_id' => 1 ,
'name' => null ,
'model_id' => 14 ,
'assigned_to' => null ,
'assigned_type' => null ,
'purchase_cost' => '899.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000312'
],
[
'id' => 13 ,
'user_id' => 1 ,
'name' => null ,
'model_id' => 14 ,
'assigned_to' => null ,
'assigned_type' => null ,
'purchase_cost' => '899.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000313'
],
[
'id' => 14 ,
'user_id' => 1 ,
'name' => null ,
'model_id' => 14 ,
'assigned_to' => null ,
'assigned_type' => null ,
'purchase_cost' => '899.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 4 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000314'
],
[
'id' => 15 ,
'user_id' => 1 ,
'name' => 'Reception Laptop' ,
'model_id' => 4 ,
'assigned_to' => 3 ,
'assigned_type' => Location :: class ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000315'
],
[
'id' => 16 ,
'user_id' => 1 ,
'name' => 'Testing Laptop' ,
'model_id' => 4 ,
'assigned_to' => 2 ,
'assigned_type' => User :: class ,
'purchase_cost' => '3025.56' ,
'purchase_date' => date ( 'Y-m-d' ),
'supplier_id' => rand ( 1 , 4 ),
'status_id' => 1 ,
'rtd_location_id' => rand ( 1 , 4 ),
'serial' => self :: generateRandomString (),
'asset_tag' => '1000316'
],
2017-10-06 22:58:00 -07:00
];
// Create assets
DB :: table ( 'assets' ) -> insert ( $assets );
return $assets ;
}
public function dropAndCreateManufacturers () {
Manufacturer :: truncate ();
$manufacturers = [
// Asset Manufacturers
[
'id' => 1 ,
'user_id' => 1 ,
'name' => 'Apple' ,
],
[
'id' => 2 ,
'user_id' => 1 ,
'name' => 'Microsoft' ,
],
[
'id' => 3 ,
'user_id' => 1 ,
'name' => 'Dell' ,
],
[
'id' => 4 ,
'user_id' => 1 ,
'name' => 'Asus' ,
],
[
'id' => 5 ,
'user_id' => 1 ,
'name' => 'HP' ,
],
[
'id' => 6 ,
'user_id' => 1 ,
'name' => 'Lenovo' ,
],
[
'id' => 7 ,
'user_id' => 1 ,
'name' => 'LG' ,
],
[
'id' => 8 ,
'user_id' => 1 ,
'name' => 'Polycom' ,
],
[
'id' => 9 ,
'user_id' => 1 ,
'name' => 'Adobe' ,
],
];
// Create Manufacturers
DB :: table ( 'manufacturers' ) -> insert ( $manufacturers );
return $manufacturers ;
}
public function dropAndCreateSuppliers () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping suppliers data' );
2017-10-06 22:58:00 -07:00
Supplier :: truncate ();
$supppliers = [
[
'id' => 1 ,
'user_id' => 1 ,
'name' => 'Best Buy' ,
],
[
'id' => 2 ,
'user_id' => 1 ,
'name' => 'Frys' ,
],
[
'id' => 3 ,
'user_id' => 1 ,
'name' => 'New Egg' ,
],
[
'id' => 4 ,
'user_id' => 1 ,
'name' => 'Mikes Tech Shop' ,
],
];
// Create Depreciations
DB :: table ( 'suppliers' ) -> insert ( $supppliers );
2017-10-07 00:02:37 -07:00
$this -> info ( 'Generating suppliers data' );
2017-10-06 22:58:00 -07:00
return $supppliers ;
}
public function dropAndCreateDepreciations () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping depreciations data' );
2017-10-06 22:58:00 -07:00
Depreciation :: truncate ();
$depreciations = [
[
'id' => 1 ,
'months' => 36 ,
'user_id' => 1 ,
'name' => 'Computers Depreciation' ,
],
[
'id' => 2 ,
'months' => 24 ,
'user_id' => 1 ,
'name' => 'Mobile Phone Depreciation' ,
],
];
// Create Depreciations
2017-10-07 00:02:37 -07:00
$this -> info ( 'Generating suppliers data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'depreciations' ) -> insert ( $depreciations );
2017-10-07 00:02:37 -07:00
2017-10-06 22:58:00 -07:00
return $depreciations ;
}
public function dropAndCreateAssetModels () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping asset model data' );
2017-10-06 22:58:00 -07:00
AssetModel :: truncate ();
$models = [
// Asset models
[
'id' => 1 ,
'user_id' => 1 ,
'manufacturer_id' => 1 ,
'depreciation_id' => 1 ,
'category_id' => 1 ,
'name' => 'Macbook Pro Retina 13"' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 2 ,
'user_id' => 1 ,
'manufacturer_id' => 1 ,
'depreciation_id' => 1 ,
'category_id' => 1 ,
'name' => 'Macbook Air' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 3 ,
'user_id' => 1 ,
'manufacturer_id' => 1 ,
'depreciation_id' => 1 ,
'category_id' => 2 ,
'name' => 'iMac Pro' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 4 ,
'user_id' => 1 ,
'manufacturer_id' => 2 ,
'depreciation_id' => 1 ,
'category_id' => 1 ,
'name' => 'Surface Pro' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 5 ,
'user_id' => 1 ,
'manufacturer_id' => 3 ,
'depreciation_id' => 1 ,
'category_id' => 1 ,
'name' => 'XPS 13' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 6 ,
'user_id' => 1 ,
'manufacturer_id' => 4 ,
'depreciation_id' => 1 ,
'category_id' => 1 ,
'name' => 'ZenBook UX310' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 7 ,
'user_id' => 1 ,
'manufacturer_id' => 5 ,
'depreciation_id' => 1 ,
'category_id' => 1 ,
'name' => 'Spectre' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 8 ,
'user_id' => 1 ,
'manufacturer_id' => 6 ,
'depreciation_id' => 1 ,
'category_id' => 1 ,
'name' => 'Yoga 910' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 9 ,
'user_id' => 1 ,
'manufacturer_id' => 7 ,
'depreciation_id' => 1 ,
'category_id' => 4 ,
'name' => '4G Ultrafine' ,
'eol' => 24 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 10 ,
'user_id' => 1 ,
'manufacturer_id' => 5 ,
'depreciation_id' => 1 ,
'category_id' => 4 ,
'name' => '20.7" LED FHD Monitor - Black' ,
'eol' => 24 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 11 ,
'user_id' => 1 ,
'manufacturer_id' => 8 ,
'depreciation_id' => 1 ,
'category_id' => 7 ,
'name' => 'Soundstation 2' ,
'eol' => 24 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 12 ,
'user_id' => 1 ,
'manufacturer_id' => 1 ,
'depreciation_id' => 2 ,
'category_id' => 3 ,
'name' => 'iPhone 6S' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 13 ,
'user_id' => 1 ,
'manufacturer_id' => 1 ,
'depreciation_id' => 2 ,
'category_id' => 5 ,
'name' => 'iPad Pro' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
[
'id' => 14 ,
'user_id' => 1 ,
'manufacturer_id' => 1 ,
'depreciation_id' => 2 ,
'category_id' => 3 ,
'name' => 'iPhone 7' ,
'eol' => 36 ,
'notes' => 'Created by demo seeder' ,
'model_number' => rand ( 111111 , 99999 )
],
2017-10-07 00:02:37 -07:00
2017-10-06 22:58:00 -07:00
];
// Create Models
2017-10-07 00:02:37 -07:00
$this -> info ( 'generating asset model data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'models' ) -> insert ( $models );
return $models ;
}
public function dropAndCreateCategories () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping category data' );
2017-10-06 22:58:00 -07:00
Category :: truncate ();
$categories = [
[
'id' => 1 ,
'name' => 'Laptops' ,
'category_type' => 'asset' ,
'require_acceptance' => rand ( 0 , 1 )
],
[
'id' => 2 ,
'name' => 'Desktops' ,
'category_type' => 'asset' ,
'require_acceptance' => rand ( 0 , 1 )
],
[
'id' => 3 ,
'name' => 'Mobile Phones' ,
'category_type' => 'asset' ,
'require_acceptance' => rand ( 0 , 1 )
],
[
'id' => 4 ,
'name' => 'Displays' ,
'category_type' => 'asset' ,
'require_acceptance' => rand ( 0 , 1 )
],
[
'id' => 5 ,
'name' => 'Tablets' ,
'category_type' => 'asset' ,
'require_acceptance' => rand ( 0 , 1 )
],
[
'id' => 6 ,
'name' => 'VOIP Phones' ,
'category_type' => 'asset' ,
'require_acceptance' => rand ( 0 , 1 )
],
[
'id' => 7 ,
'name' => 'Conference Phones' ,
'category_type' => 'asset' ,
'require_acceptance' => rand ( 0 , 1 )
],
// Accessory categories: 8-9
[
'id' => 8 ,
'name' => 'Keyboard' ,
'category_type' => 'accessory' ,
'require_acceptance' => rand ( 0 , 1 )
],
[
'id' => 9 ,
'name' => 'Mouse' ,
'category_type' => 'accessory' ,
'require_acceptance' => rand ( 0 , 1 )
],
[
'id' => 10 ,
'name' => 'Printer Paper' ,
'category_type' => 'consumable' ,
'require_acceptance' => 0 ,
],
[
'id' => 11 ,
'name' => 'Printer Toner' ,
'category_type' => 'consumable' ,
'require_acceptance' => 0 ,
],
[
'id' => 12 ,
'name' => 'RAM' ,
'category_type' => 'component' ,
'require_acceptance' => 0 ,
],
[
'id' => 13 ,
'name' => 'Hard Drives' ,
'category_type' => 'component' ,
'require_acceptance' => 0 ,
],
];
// Create Categories
2017-10-07 00:02:37 -07:00
$this -> info ( 'Generating category data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'categories' ) -> insert ( $categories );
return $categories ;
}
public function dropAndCreateLocations () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping location data' );
2017-10-06 22:58:00 -07:00
Location :: truncate ();
$locations = [
// Locations
[
'id' => 1 ,
'user_id' => 1 ,
'name' => 'San Diego HQ' ,
],
[
'id' => 2 ,
'user_id' => 1 ,
'name' => 'Ocean Beach HQ' ,
],
[
'id' => 3 ,
'user_id' => 1 ,
'name' => 'Point Loma HQ' ,
],
[
'id' => 4 ,
'user_id' => 1 ,
'name' => 'Pacific Beach HQ' ,
],
];
// Create Locations
2017-10-07 00:02:37 -07:00
$this -> info ( 'Generating location data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'locations' ) -> insert ( $locations );
return $locations ;
}
public function dropAndCreateLicenses () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping licenses and seat data' );
2017-10-06 22:58:00 -07:00
License :: truncate ();
LicenseSeat :: truncate ();
$licenses = [
// Licenses
[
'id' => 1 ,
'user_id' => 1 ,
'name' => 'Adobe Acrobat Pro' ,
'serial' => self :: generateRandomString (),
'purchase_cost' => '99.99' ,
'license_name' => 'Alison Gianotto' ,
'license_email' => 'foo@example.com' ,
'depreciate' => 0 ,
'supplier_id' => 1 ,
'manufacturer_id' => 9 ,
'seats' => rand ( 2 , 20 ),
],
[
'id' => 2 ,
'user_id' => 1 ,
'name' => 'Adobe Photoshop' ,
'serial' => self :: generateRandomString (),
'purchase_cost' => '299.99' ,
'license_name' => 'Alison Gianotto' ,
'license_email' => 'foo@example.com' ,
'depreciate' => 0 ,
'supplier_id' => 1 ,
'manufacturer_id' => 9 ,
'seats' => rand ( 2 , 20 ),
],
[
'id' => 3 ,
'user_id' => 1 ,
'name' => 'Garageband' ,
'serial' => self :: generateRandomString (),
'purchase_cost' => '39.99' ,
'license_name' => 'Alison Gianotto' ,
'license_email' => 'foo@example.com' ,
'depreciate' => 0 ,
'supplier_id' => 1 ,
'manufacturer_id' => 1 ,
'seats' => rand ( 2 , 20 ),
],
[
'id' => 4 ,
'user_id' => 1 ,
'name' => 'Office' ,
'serial' => self :: generateRandomString (),
'purchase_cost' => '39.99' ,
'license_name' => 'Alison Gianotto' ,
'license_email' => 'foo@example.com' ,
'depreciate' => 0 ,
'supplier_id' => 1 ,
'manufacturer_id' => 2 ,
'seats' => rand ( 2 , 20 ),
],
];
// Create Licenses
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping license and seat data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'licenses' ) -> insert ( $licenses );
foreach ( $licenses as $license ) {
$license_seats =
[
'license_id' => $license [ 'id' ],
'notes' => 'Created by demo seeder' ,
'user_id' => 1
];
for ( $x = 0 ; $x < $license [ 'seats' ]; $x ++ ) {
DB :: table ( 'license_seats' ) -> insert ( $license_seats );
}
}
return $licenses ;
}
public function dropAndCreateAccessories () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping accessory data' );
2017-10-06 22:58:00 -07:00
Accessory :: truncate ();
DB :: table ( 'accessories_users' ) -> truncate ();
$accessories = [
// Accessories
[
'id' => 1 ,
'user_id' => 1 ,
'name' => 'Bluetooth Keyboard' ,
'category_id' => 8 ,
'manufacturer_id' => 1 ,
'location_id' => 1 ,
'model_number' => rand ( 123 , 12345677 ),
'purchase_cost' => '99.99' ,
'qty' => 10 ,
'min_amt' => 2 ,
],
[
'id' => 2 ,
'user_id' => 1 ,
'name' => 'USB Keyboard' ,
'category_id' => 8 ,
'manufacturer_id' => 1 ,
'location_id' => 1 ,
'model_number' => rand ( 123 , 12345677 ),
'purchase_cost' => '69.99' ,
'qty' => 5 ,
'min_amt' => 1 ,
],
[
'id' => 3 ,
'user_id' => 1 ,
'name' => 'Magic Mouse 2' ,
'category_id' => 9 ,
'manufacturer_id' => 1 ,
'location_id' => 2 ,
'model_number' => rand ( 123 , 12345677 ),
'purchase_cost' => '59.99' ,
'qty' => 15 ,
'min_amt' => 2 ,
],
[
'id' => 4 ,
'user_id' => 1 ,
'name' => 'Sculpt Comfort Mouse' ,
'category_id' => 9 ,
'manufacturer_id' => 2 ,
'location_id' => 3 ,
'model_number' => rand ( 123 , 12345677 ),
'purchase_cost' => '24.99' ,
'qty' => 10 ,
'min_amt' => 2 ,
],
];
// Create Locations
2017-10-07 00:02:37 -07:00
$this -> info ( 'Generating accessory data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'accessories' ) -> insert ( $accessories );
return $accessories ;
}
public function dropAndCreateComponents () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping component data' );
2017-10-06 22:58:00 -07:00
Component :: truncate ();
DB :: table ( 'components_assets' ) -> truncate ();
$components = [
// Components
[
'id' => 1 ,
'user_id' => 1 ,
'name' => 'Seagate 1TB' ,
'category_id' => 12 ,
'location_id' => 1 ,
'purchase_cost' => '99.99' ,
'qty' => 10 ,
'min_amt' => 2 ,
],
];
// Create Locations
2017-10-07 00:02:37 -07:00
$this -> info ( 'Generating component data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'components' ) -> insert ( $components );
return $components ;
}
public function dropAndCreateConsumables () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping consumable data' );
2017-10-06 22:58:00 -07:00
Consumable :: truncate ();
DB :: table ( 'consumables_users' ) -> truncate ();
$consumables = [
// Consumables
[
'id' => 1 ,
'user_id' => 1 ,
'name' => 'Bone White Cardstock' ,
'category_id' => 10 ,
'location_id' => 1 ,
'purchase_cost' => '29.99' ,
'qty' => 10 ,
'min_amt' => 2 ,
],
];
// Create Locations
2017-10-07 00:02:37 -07:00
$this -> info ( 'Generating consumable data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'consumables' ) -> insert ( $consumables );
return $consumables ;
}
2017-10-07 00:02:37 -07:00
public function dropAndCreateUsers () {
$this -> info ( 'Dropping users data (except user: admin)' );
User :: where ( 'username' , '!=' , 'snipe' )
-> where ( 'username' , '!=' , 'admin' )
-> forceDelete ();
$users = [
// Users
[
'first_name' => 'Test' ,
'last_name' => 'User' ,
'username' => 'testuser' ,
'email' => 'testuser@snipe.net' ,
'jobtitle' => 'Just a test user' ,
'notes' => 'Created by demo seeder' ,
'location_id' => 1 ,
'department_id' => 1 ,
'password' => bcrypt ( 'password' ),
'activated' => 1 ,
],
[
'first_name' => 'Donald' ,
'last_name' => 'Duck' ,
'username' => 'donaldduck' ,
'email' => 'donaldduck@example.com' ,
'jobtitle' => 'Director of Engineering' ,
'notes' => 'Created by demo seeder' ,
'location_id' => 2 ,
'department_id' => 3 ,
'password' => bcrypt ( 'password' ),
'activated' => 1 ,
],
[
'first_name' => 'Adrian' ,
'last_name' => 'Whapcaplet' ,
'username' => 'adrianwhapcaplet' ,
'email' => 'adrianwhapcaplet@example.com' ,
'jobtitle' => 'HR Manager' ,
'notes' => 'Created by demo seeder' ,
'location_id' => 2 ,
'department_id' => 1 ,
'password' => bcrypt ( 'password' ),
'activated' => 1 ,
],
[
'first_name' => 'Arthur' ,
'last_name' => 'Nudge' ,
'username' => 'arthurnudge' ,
'email' => 'arthurnudge@example.com' ,
'jobtitle' => 'Social Media Manager' ,
'notes' => 'Created by demo seeder' ,
'location_id' => 2 ,
'department_id' => 2 ,
'password' => bcrypt ( 'password' ),
'activated' => 1 ,
],
[
'first_name' => 'Spiny' ,
'last_name' => 'Norman' ,
'username' => 'spinynorman' ,
'email' => 'spinynorman@example.com' ,
'jobtitle' => 'CEO' ,
'notes' => 'Created by demo seeder' ,
'location_id' => 2 ,
'department_id' => 2 ,
'password' => bcrypt ( 'password' ),
'activated' => 1 ,
],
];
// Create Locations
$this -> info ( 'Generating user data' );
DB :: table ( 'users' ) -> insert ( $users );
return $users ;
}
public function dropAndCreateDepartments () {
$this -> info ( 'Dropping department data' );
Department :: truncate ();
$departments = [
// Departments
[
'id' => 1 ,
'name' => 'Human Resources' ,
],
[
'id' => 2 ,
'name' => 'Dept of Silly Walks' ,
],
[
'id' => 3 ,
'name' => 'Engineering' ,
],
[
'id' => 4 ,
'name' => 'Marketing' ,
],
[
'id' => 5 ,
'name' => 'Client Services' ,
],
];
// Create Locations
$this -> info ( 'Generating suppliers data' );
DB :: table ( 'departments' ) -> insert ( $departments );
return $departments ;
}
2017-10-06 22:58:00 -07:00
public function dropAndCreateActionlogs () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping actionlog data' );
2017-10-06 22:58:00 -07:00
Actionlog :: truncate ();
2017-10-07 00:02:37 -07:00
2017-10-06 22:58:00 -07:00
$action_logs = [
// Action logs
[
'user_id' => 1 ,
'action_type' => 'checkout' ,
'target_id' => 1 ,
'target_type' => User :: class ,
'item_type' => Asset :: class ,
'item_id' => 4 ,
'created_at' => date ( 'Y-m-d' ),
'note' => 'Created by demo seeder' ,
],
[
'user_id' => 1 ,
'action_type' => 'checkout' ,
'target_id' => 1 ,
'target_type' => User :: class ,
'item_type' => Asset :: class ,
'item_id' => 5 ,
'created_at' => date ( 'Y-m-d' ),
'note' => 'Created by demo seeder' ,
],
[
'user_id' => 1 ,
'action_type' => 'checkout' ,
'target_id' => 2 ,
'target_type' => Location :: class ,
'item_type' => Asset :: class ,
'item_id' => 5 ,
'created_at' => date ( 'Y-m-d' ),
'note' => 'Created by demo seeder' ,
],
[
'user_id' => 1 ,
'action_type' => 'checkout' ,
'target_id' => 2 ,
'target_type' => Location :: class ,
'item_type' => Asset :: class ,
'item_id' => 7 ,
'created_at' => date ( 'Y-m-d' ),
'note' => 'Created by demo seeder' ,
],
[
'user_id' => 1 ,
'action_type' => 'checkout' ,
'target_id' => 2 ,
'target_type' => Location :: class ,
'item_type' => Asset :: class ,
'item_id' => 8 ,
'created_at' => date ( 'Y-m-d' ),
'note' => 'Created by demo seeder' ,
],
[
'user_id' => 1 ,
'action_type' => 'checkin from' ,
'target_id' => 2 ,
'target_type' => Location :: class ,
'item_type' => Asset :: class ,
'item_id' => 8 ,
'created_at' => date ( 'Y-m-d' ),
'note' => 'Created by demo seeder' ,
],
[
'user_id' => 1 ,
'action_type' => 'checkout' ,
'target_id' => 2 ,
'target_type' => Location :: class ,
'item_type' => Asset :: class ,
'item_id' => 8 ,
'created_at' => date ( 'Y-m-d' ),
'note' => 'Created by demo seeder' ,
],
2017-10-07 00:02:37 -07:00
[
'user_id' => 1 ,
'action_type' => 'checkout' ,
'target_id' => 3 ,
'target_type' => Location :: class ,
'item_type' => Asset :: class ,
'item_id' => 15 ,
'created_at' => date ( 'Y-m-d' ),
'note' => 'Created by demo seeder' ,
],
[
'user_id' => 1 ,
'action_type' => 'checkout' ,
'target_id' => 1 ,
'target_type' => User :: class ,
'item_type' => Asset :: class ,
'item_id' => 16 ,
'created_at' => date ( 'Y-m-d' ),
'note' => 'Created by demo seeder' ,
],
2017-10-06 22:58:00 -07:00
];
// Create Logs
2017-10-07 00:02:37 -07:00
$this -> info ( 'Generating actionlog data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'action_logs' ) -> insert ( $action_logs );
return $action_logs ;
}
public function dropAndCreateStatusLabels () {
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping statuslabel data' );
2017-10-06 22:58:00 -07:00
Statuslabel :: truncate ();
$statuslabels = [
// Status Labels
[
'id' => 1 ,
'user_id' => 1 ,
'name' => 'New - Ready for Deployment' ,
'deployable' => 1 ,
'pending' => 0 ,
'archived' => 0 ,
'notes' => 'Created by demo seeder' ,
],
// Status Labels
[
'id' => 2 ,
'user_id' => 1 ,
'name' => 'Awaiting Repair' ,
'deployable' => 0 ,
'pending' => 1 ,
'archived' => 0 ,
'notes' => 'Created by demo seeder' ,
],
// Status Labels
[
'id' => 3 ,
'user_id' => 1 ,
'name' => 'Archived - Keep for Records' ,
'deployable' => 0 ,
'pending' => 0 ,
'archived' => 1 ,
'notes' => 'Created by demo seeder' ,
],
// Status Labels
[
'id' => 4 ,
'user_id' => 1 ,
'name' => 'Broken - Not Fixable' ,
'deployable' => 0 ,
'pending' => 0 ,
'archived' => 1 ,
'notes' => 'Created by demo seeder' ,
],
];
// Create status labels
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping statuslabel data' );
2017-10-06 22:58:00 -07:00
DB :: table ( 'status_labels' ) -> insert ( $statuslabels );
return $statuslabels ;
}
public function dropRealCustomFieldsColumns () {
// delete custom field columns on the asset table
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropping custom fields from asset table' );
2017-10-06 22:58:00 -07:00
$fields = Customfield :: all ();
2017-10-07 00:02:37 -07:00
$fieldcount = 0 ;
2017-10-06 22:58:00 -07:00
foreach ( $fields as $field ) {
if ( $field -> db_column != '' ) {
2017-10-07 00:02:37 -07:00
$fieldcount ++ ;
2017-10-06 22:58:00 -07:00
$this -> info ( 'Dropping DB column: ' . $field -> db_column );
Schema :: table ( 'assets' , function ( Blueprint $table ) {
$table -> dropColumn ( $field -> db_column );
});
}
}
2017-10-07 00:02:37 -07:00
$this -> info ( 'Dropped ' . $fieldcount . ' fields from asset table' );
2017-10-06 22:58:00 -07:00
}
2017-10-07 00:02:37 -07:00
2017-10-06 22:58:00 -07:00
public function generateRandomString ( $length = 10 ) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ;
$charactersLength = strlen ( $characters );
$randomString = '' ;
for ( $i = 0 ; $i < $length ; $i ++ ) {
$randomString .= $characters [ rand ( 0 , $charactersLength - 1 )];
}
return $randomString ;
}
}