ajout app
This commit is contained in:
0
SNIPE-IT/database/seeders/.gitkeep
Normal file
0
SNIPE-IT/database/seeders/.gitkeep
Normal file
85
SNIPE-IT/database/seeders/AccessorySeeder.php
Normal file
85
SNIPE-IT/database/seeders/AccessorySeeder.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Location;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AccessorySeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Accessory::truncate();
|
||||
DB::table('accessories_users')->truncate();
|
||||
|
||||
if (! Location::count()) {
|
||||
$this->call(LocationSeeder::class);
|
||||
}
|
||||
|
||||
$locationIds = Location::all()->pluck('id');
|
||||
|
||||
if (! Supplier::count()) {
|
||||
$this->call(SupplierSeeder::class);
|
||||
}
|
||||
|
||||
$supplierIds = Supplier::all()->pluck('id');
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
Accessory::factory()->appleUsbKeyboard()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'supplier_id' => $supplierIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Accessory::factory()->appleBtKeyboard()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'supplier_id' => $supplierIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Accessory::factory()->appleMouse()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'supplier_id' => $supplierIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Accessory::factory()->microsoftMouse()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'supplier_id' => $supplierIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
|
||||
$src = public_path('/img/demo/accessories/');
|
||||
$dst = 'accessories'.'/';
|
||||
$del_files = Storage::files($dst);
|
||||
|
||||
foreach ($del_files as $del_file) { // iterate files
|
||||
$file_to_delete = str_replace($src, '', $del_file);
|
||||
Log::debug('Deleting: '.$file_to_delete);
|
||||
try {
|
||||
Storage::disk('public')->delete($dst.$del_file);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
|
||||
$add_files = glob($src.'/*.*');
|
||||
foreach ($add_files as $add_file) {
|
||||
$file_to_copy = str_replace($src, '', $add_file);
|
||||
Log::debug('Copying: '.$file_to_copy);
|
||||
try {
|
||||
Storage::disk('public')->put($dst.$file_to_copy, file_get_contents($src.$file_to_copy));
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
42
SNIPE-IT/database/seeders/ActionlogSeeder.php
Normal file
42
SNIPE-IT/database/seeders/ActionlogSeeder.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ActionlogSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Actionlog::truncate();
|
||||
|
||||
if (! Asset::count()) {
|
||||
$this->call(AssetSeeder::class);
|
||||
}
|
||||
|
||||
if (! Location::count()) {
|
||||
$this->call(LocationSeeder::class);
|
||||
}
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
Actionlog::factory()
|
||||
->count(300)
|
||||
->assetCheckoutToUser()
|
||||
->create(['user_id' => $admin->id]);
|
||||
|
||||
Actionlog::factory()
|
||||
->count(100)
|
||||
->assetCheckoutToLocation()
|
||||
->create(['user_id' => $admin->id]);
|
||||
|
||||
Actionlog::factory()
|
||||
->count(20)
|
||||
->licenseCheckoutToUser()
|
||||
->create(['user_id' => $admin->id]);
|
||||
}
|
||||
}
|
74
SNIPE-IT/database/seeders/AssetModelSeeder.php
Normal file
74
SNIPE-IT/database/seeders/AssetModelSeeder.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AssetModelSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
AssetModel::truncate();
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
// Laptops
|
||||
AssetModel::factory()->count(1)->mbp13Model()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->mbpAirModel()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->surfaceModel()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->xps13Model()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->spectreModel()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->zenbookModel()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->yogaModel()->create(['user_id' => $admin->id]);
|
||||
|
||||
// Desktops
|
||||
AssetModel::factory()->count(1)->macproModel()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->lenovoI5Model()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->optiplexModel()->create(['user_id' => $admin->id]);
|
||||
|
||||
// Conference Phones
|
||||
AssetModel::factory()->count(1)->polycomModel()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->polycomcxModel()->create(['user_id' => $admin->id]);
|
||||
|
||||
// Tablets
|
||||
AssetModel::factory()->count(1)->ipadModel()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->tab3Model()->create(['user_id' => $admin->id]);
|
||||
|
||||
// Phones
|
||||
AssetModel::factory()->count(1)->iphone11Model()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->iphone12Model()->create(['user_id' => $admin->id]);
|
||||
|
||||
// Displays
|
||||
AssetModel::factory()->count(1)->ultrafine()->create(['user_id' => $admin->id]);
|
||||
AssetModel::factory()->count(1)->ultrasharp()->create(['user_id' => $admin->id]);
|
||||
|
||||
$src = public_path('/img/demo/models/');
|
||||
$dst = 'models'.'/';
|
||||
$del_files = Storage::files($dst);
|
||||
|
||||
foreach ($del_files as $del_file) { // iterate files
|
||||
$file_to_delete = str_replace($src, '', $del_file);
|
||||
Log::debug('Deleting: '.$file_to_delete);
|
||||
try {
|
||||
Storage::disk('public')->delete($dst.$del_file);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
|
||||
$add_files = glob($src.'/*.*');
|
||||
foreach ($add_files as $add_file) {
|
||||
$file_to_copy = str_replace($src, '', $add_file);
|
||||
Log::debug('Copying: '.$file_to_copy);
|
||||
try {
|
||||
Storage::disk('public')->put($dst.$file_to_copy, file_get_contents($src.$file_to_copy));
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
88
SNIPE-IT/database/seeders/AssetSeeder.php
Normal file
88
SNIPE-IT/database/seeders/AssetSeeder.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\Location;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Sequence;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AssetSeeder extends Seeder
|
||||
{
|
||||
private $admin;
|
||||
private $locationIds;
|
||||
private $supplierIds;
|
||||
|
||||
public function run()
|
||||
{
|
||||
Asset::truncate();
|
||||
|
||||
$this->ensureLocationsSeeded();
|
||||
$this->ensureSuppliersSeeded();
|
||||
|
||||
$this->admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
$this->locationIds = Location::all()->pluck('id');
|
||||
$this->supplierIds = Supplier::all()->pluck('id');
|
||||
|
||||
Asset::factory()->count(2000)->laptopMbp()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(50)->laptopMbpPending()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(50)->laptopMbpArchived()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(50)->laptopAir()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(50)->laptopSurface()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(5)->laptopXps()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(5)->laptopSpectre()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(50)->laptopZenbook()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(30)->laptopYoga()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(30)->desktopMacpro()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(30)->desktopLenovoI5()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(30)->desktopOptiplex()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(50)->confPolycom()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(20)->confPolycomcx()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(30)->tabletIpad()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(10)->tabletTab3()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(27)->phoneIphone11()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(40)->phoneIphone12()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(20)->ultrafine()->state(new Sequence($this->getState()))->create();
|
||||
Asset::factory()->count(20)->ultrasharp()->state(new Sequence($this->getState()))->create();
|
||||
|
||||
$del_files = Storage::files('assets');
|
||||
foreach ($del_files as $del_file) { // iterate files
|
||||
Log::debug('Deleting: ' . $del_files);
|
||||
try {
|
||||
Storage::disk('public')->delete('assets' . '/' . $del_files);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
|
||||
DB::table('checkout_requests')->truncate();
|
||||
}
|
||||
|
||||
private function ensureLocationsSeeded()
|
||||
{
|
||||
if (! Location::count()) {
|
||||
$this->call(LocationSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
private function ensureSuppliersSeeded()
|
||||
{
|
||||
if (! Supplier::count()) {
|
||||
$this->call(SupplierSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
private function getState()
|
||||
{
|
||||
return fn($sequence) => [
|
||||
'rtd_location_id' => $this->locationIds->random(),
|
||||
'supplier_id' => $this->supplierIds->random(),
|
||||
'user_id' => $this->admin->id,
|
||||
];
|
||||
}
|
||||
}
|
33
SNIPE-IT/database/seeders/CategorySeeder.php
Normal file
33
SNIPE-IT/database/seeders/CategorySeeder.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class CategorySeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Category::truncate();
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
Category::factory()->count(1)->assetLaptopCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->assetDesktopCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->assetTabletCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->assetMobileCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->assetDisplayCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->assetVoipCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->assetConferenceCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->accessoryKeyboardCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->accessoryMouseCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->consumablePaperCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->consumableInkCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->componentHddCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->componentRamCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->licenseGraphicsCategory()->create(['user_id' => $admin->id]);
|
||||
Category::factory()->count(1)->licenseOfficeCategory()->create(['user_id' => $admin->id]);
|
||||
}
|
||||
}
|
48
SNIPE-IT/database/seeders/CompanySeeder.php
Normal file
48
SNIPE-IT/database/seeders/CompanySeeder.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Company;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class CompanySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Log::debug('Seed companies');
|
||||
Company::truncate();
|
||||
Company::factory()->count(4)->create();
|
||||
|
||||
$src = public_path('/img/demo/companies/');
|
||||
$dst = 'companies'.'/';
|
||||
$del_files = Storage::files('companies/'.$dst);
|
||||
|
||||
foreach ($del_files as $del_file) { // iterate files
|
||||
$file_to_delete = str_replace($src, '', $del_file);
|
||||
Log::debug('Deleting: '.$file_to_delete);
|
||||
try {
|
||||
Storage::disk('public')->delete($dst.$del_file);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
|
||||
$add_files = glob($src.'/*.*');
|
||||
foreach ($add_files as $add_file) {
|
||||
$file_to_copy = str_replace($src, '', $add_file);
|
||||
Log::debug('Copying: '.$file_to_copy);
|
||||
try {
|
||||
Storage::disk('public')->put($dst.$file_to_copy, file_get_contents($src.$file_to_copy));
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
47
SNIPE-IT/database/seeders/ComponentSeeder.php
Normal file
47
SNIPE-IT/database/seeders/ComponentSeeder.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Component;
|
||||
use App\Models\Location;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ComponentSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Component::truncate();
|
||||
DB::table('components_assets')->truncate();
|
||||
|
||||
if (! Company::count()) {
|
||||
$this->call(CompanySeeder::class);
|
||||
}
|
||||
|
||||
$companyIds = Company::all()->pluck('id');
|
||||
|
||||
if (! Location::count()) {
|
||||
$this->call(LocationSeeder::class);
|
||||
}
|
||||
|
||||
$locationIds = Location::all()->pluck('id');
|
||||
|
||||
Component::factory()->ramCrucial4()->create([
|
||||
'company_id' => $companyIds->random(),
|
||||
'location_id' => $locationIds->random(),
|
||||
]);
|
||||
Component::factory()->ramCrucial8()->create([
|
||||
'company_id' => $companyIds->random(),
|
||||
'location_id' => $locationIds->random(),
|
||||
]);
|
||||
Component::factory()->ssdCrucial120()->create([
|
||||
'company_id' => $companyIds->random(),
|
||||
'location_id' => $locationIds->random(),
|
||||
]);
|
||||
Component::factory()->ssdCrucial240()->create([
|
||||
'company_id' => $companyIds->random(),
|
||||
'location_id' => $locationIds->random(),
|
||||
]);
|
||||
}
|
||||
}
|
23
SNIPE-IT/database/seeders/ConsumableSeeder.php
Normal file
23
SNIPE-IT/database/seeders/ConsumableSeeder.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Consumable;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ConsumableSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Consumable::truncate();
|
||||
DB::table('consumables_users')->truncate();
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
Consumable::factory()->count(1)->cardstock()->create(['user_id' => $admin->id]);
|
||||
Consumable::factory()->count(1)->paper()->create(['user_id' => $admin->id]);
|
||||
Consumable::factory()->count(1)->ink()->create(['user_id' => $admin->id]);
|
||||
}
|
||||
}
|
115
SNIPE-IT/database/seeders/CustomFieldSeeder.php
Normal file
115
SNIPE-IT/database/seeders/CustomFieldSeeder.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\CustomField;
|
||||
use App\Models\CustomFieldset;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CustomFieldSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$columns = DB::getSchemaBuilder()->getColumnListing('assets');
|
||||
|
||||
foreach ($columns as $column) {
|
||||
if (strpos($column, '_snipeit_') !== false) {
|
||||
Schema::table('assets', function (Blueprint $table) use ($column) {
|
||||
$table->dropColumn($column);
|
||||
});
|
||||
}
|
||||
}
|
||||
CustomField::truncate();
|
||||
CustomFieldset::truncate();
|
||||
DB::table('custom_field_custom_fieldset')->truncate();
|
||||
|
||||
CustomFieldset::factory()->count(1)->mobile()->create();
|
||||
CustomFieldset::factory()->count(1)->computer()->create();
|
||||
CustomField::factory()->count(1)->imei()->create();
|
||||
CustomField::factory()->count(1)->phone()->create();
|
||||
CustomField::factory()->count(1)->ram()->create();
|
||||
CustomField::factory()->count(1)->cpu()->create();
|
||||
CustomField::factory()->count(1)->macAddress()->create();
|
||||
CustomField::factory()->count(1)->testEncrypted()->create();
|
||||
CustomField::factory()->count(1)->testCheckbox()->create();
|
||||
CustomField::factory()->count(1)->testRadio()->create();
|
||||
|
||||
|
||||
DB::table('custom_field_custom_fieldset')->insert([
|
||||
[
|
||||
'custom_field_id' => '1',
|
||||
'custom_fieldset_id' => '1',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
[
|
||||
'custom_field_id' => '2',
|
||||
'custom_fieldset_id' => '1',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
[
|
||||
'custom_field_id' => '3',
|
||||
'custom_fieldset_id' => '2',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
[
|
||||
'custom_field_id' => '4',
|
||||
'custom_fieldset_id' => '2',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
[
|
||||
'custom_field_id' => '5',
|
||||
'custom_fieldset_id' => '2',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
|
||||
[
|
||||
'custom_field_id' => '6',
|
||||
'custom_fieldset_id' => '2',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
|
||||
[
|
||||
'custom_field_id' => '6',
|
||||
'custom_fieldset_id' => '1',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
|
||||
[
|
||||
'custom_field_id' => '7',
|
||||
'custom_fieldset_id' => '2',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
[
|
||||
'custom_field_id' => '7',
|
||||
'custom_fieldset_id' => '1',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
|
||||
[
|
||||
'custom_field_id' => '8',
|
||||
'custom_fieldset_id' => '2',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
[
|
||||
'custom_field_id' => '8',
|
||||
'custom_fieldset_id' => '1',
|
||||
'order' => 0,
|
||||
'required' => 0,
|
||||
],
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
59
SNIPE-IT/database/seeders/DatabaseSeeder.php
Normal file
59
SNIPE-IT/database/seeders/DatabaseSeeder.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Model::unguard();
|
||||
|
||||
// Only create default settings if they do not exist in the db.
|
||||
if (! Setting::first()) {
|
||||
// factory(Setting::class)->create();
|
||||
$this->call(SettingsSeeder::class);
|
||||
}
|
||||
|
||||
$this->call(CompanySeeder::class);
|
||||
$this->call(CategorySeeder::class);
|
||||
$this->call(LocationSeeder::class);
|
||||
$this->call(DepartmentSeeder::class);
|
||||
$this->call(UserSeeder::class);
|
||||
$this->call(DepreciationSeeder::class);
|
||||
$this->call(ManufacturerSeeder::class);
|
||||
$this->call(SupplierSeeder::class);
|
||||
$this->call(AssetModelSeeder::class);
|
||||
$this->call(DepreciationSeeder::class);
|
||||
$this->call(StatuslabelSeeder::class);
|
||||
$this->call(AccessorySeeder::class);
|
||||
$this->call(CustomFieldSeeder::class);
|
||||
$this->call(AssetSeeder::class);
|
||||
$this->call(LicenseSeeder::class);
|
||||
$this->call(ComponentSeeder::class);
|
||||
$this->call(ConsumableSeeder::class);
|
||||
$this->call(ActionlogSeeder::class);
|
||||
|
||||
|
||||
Artisan::call('snipeit:sync-asset-locations', ['--output' => 'all']);
|
||||
$output = Artisan::output();
|
||||
Log::info($output);
|
||||
|
||||
Model::reguard();
|
||||
|
||||
DB::table('imports')->truncate();
|
||||
DB::table('asset_maintenances')->truncate();
|
||||
DB::table('requested_assets')->truncate();
|
||||
}
|
||||
}
|
54
SNIPE-IT/database/seeders/DepartmentSeeder.php
Normal file
54
SNIPE-IT/database/seeders/DepartmentSeeder.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DepartmentSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Department::truncate();
|
||||
|
||||
if (! Location::count()) {
|
||||
$this->call(LocationSeeder::class);
|
||||
}
|
||||
|
||||
$locationIds = Location::all()->pluck('id');
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
Department::factory()->count(1)->hr()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Department::factory()->count(1)->engineering()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Department::factory()->count(1)->marketing()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Department::factory()->count(1)->client()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Department::factory()->count(1)->product()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Department::factory()->count(1)->silly()->create([
|
||||
'location_id' => $locationIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
}
|
||||
}
|
21
SNIPE-IT/database/seeders/DepreciationSeeder.php
Normal file
21
SNIPE-IT/database/seeders/DepreciationSeeder.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Depreciation;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DepreciationSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Depreciation::truncate();
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
Depreciation::factory()->count(1)->computer()->create(['user_id' => $admin->id]);
|
||||
Depreciation::factory()->count(1)->display()->create(['user_id' => $admin->id]);
|
||||
Depreciation::factory()->count(1)->mobilePhones()->create(['user_id' => $admin->id]);
|
||||
}
|
||||
}
|
57
SNIPE-IT/database/seeders/LicenseSeeder.php
Normal file
57
SNIPE-IT/database/seeders/LicenseSeeder.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\License;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class LicenseSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
License::truncate();
|
||||
LicenseSeat::truncate();
|
||||
|
||||
if (! Category::count()) {
|
||||
$this->call(CategorySeeder::class);
|
||||
}
|
||||
|
||||
$categoryIds = Category::all()->pluck('id');
|
||||
|
||||
if (! Supplier::count()) {
|
||||
$this->call(SupplierSeeder::class);
|
||||
}
|
||||
|
||||
$supplierIds = Supplier::all()->pluck('id');
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
License::factory()->count(1)->photoshop()->create([
|
||||
'category_id' => $categoryIds->random(),
|
||||
'supplier_id' => $supplierIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
License::factory()->count(1)->acrobat()->create([
|
||||
'category_id' => $categoryIds->random(),
|
||||
'supplier_id' => $supplierIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
License::factory()->count(1)->indesign()->create([
|
||||
'category_id' => $categoryIds->random(),
|
||||
'supplier_id' => $supplierIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
License::factory()->count(1)->office()->create([
|
||||
'category_id' => $categoryIds->random(),
|
||||
'supplier_id' => $supplierIds->random(),
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
}
|
||||
}
|
42
SNIPE-IT/database/seeders/LocationSeeder.php
Normal file
42
SNIPE-IT/database/seeders/LocationSeeder.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Location;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class LocationSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Location::truncate();
|
||||
Location::factory()->count(10)->create();
|
||||
|
||||
$src = public_path('/img/demo/locations/');
|
||||
$dst = 'locations'.'/';
|
||||
$del_files = Storage::files($dst);
|
||||
|
||||
foreach ($del_files as $del_file) { // iterate files
|
||||
$file_to_delete = str_replace($src, '', $del_file);
|
||||
Log::debug('Deleting: '.$file_to_delete);
|
||||
try {
|
||||
Storage::disk('public')->delete($dst.$del_file);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
|
||||
$add_files = glob($src.'/*.*');
|
||||
foreach ($add_files as $add_file) {
|
||||
$file_to_copy = str_replace($src, '', $add_file);
|
||||
Log::debug('Copying: '.$file_to_copy);
|
||||
try {
|
||||
Storage::disk('public')->put($dst.$file_to_copy, file_get_contents($src.$file_to_copy));
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
SNIPE-IT/database/seeders/ManufacturerSeeder.php
Normal file
56
SNIPE-IT/database/seeders/ManufacturerSeeder.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Manufacturer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ManufacturerSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Manufacturer::truncate();
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
Manufacturer::factory()->count(1)->apple()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->microsoft()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->dell()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->asus()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->hp()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->lenovo()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->lg()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->polycom()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->adobe()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->avery()->create(['user_id' => $admin->id]);
|
||||
Manufacturer::factory()->count(1)->crucial()->create(['user_id' => $admin->id]);
|
||||
|
||||
$src = public_path('/img/demo/manufacturers/');
|
||||
$dst = 'manufacturers'.'/';
|
||||
$del_files = Storage::files($dst);
|
||||
|
||||
foreach ($del_files as $del_file) { // iterate files
|
||||
$file_to_delete = str_replace($src, '', $del_file);
|
||||
Log::debug('Deleting: '.$file_to_delete);
|
||||
try {
|
||||
Storage::disk('public')->delete($dst.$del_file);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
|
||||
$add_files = glob($src.'/*.*');
|
||||
foreach ($add_files as $add_file) {
|
||||
$file_to_copy = str_replace($src, '', $add_file);
|
||||
Log::debug('Copying: '.$file_to_copy);
|
||||
try {
|
||||
Storage::disk('public')->put($dst.$file_to_copy, file_get_contents($src.$file_to_copy));
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
SNIPE-IT/database/seeders/SettingsSeeder.php
Normal file
50
SNIPE-IT/database/seeders/SettingsSeeder.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class SettingsSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Setting::truncate();
|
||||
$settings = new Setting;
|
||||
$settings->per_page = 20;
|
||||
$settings->site_name = 'Snipe-IT Demo';
|
||||
$settings->auto_increment_assets = 1;
|
||||
$settings->logo = 'snipe-logo.png';
|
||||
$settings->alert_email = 'service@snipe-it.io';
|
||||
$settings->header_color = null;
|
||||
$settings->barcode_type = 'QRCODE';
|
||||
$settings->default_currency = 'USD';
|
||||
$settings->brand = 3;
|
||||
$settings->ldap_enabled = 0;
|
||||
$settings->full_multiple_companies_support = 0;
|
||||
$settings->alt_barcode = 'C128';
|
||||
$settings->skin = '';
|
||||
$settings->email_domain = 'example.org';
|
||||
$settings->email_format = 'filastname';
|
||||
$settings->username_format = 'filastname';
|
||||
$settings->date_display_format = 'D M d, Y';
|
||||
$settings->time_display_format = 'g:iA';
|
||||
$settings->thumbnail_max_h = '30';
|
||||
$settings->locale = 'en-US';
|
||||
$settings->version_footer = 'on';
|
||||
$settings->support_footer = 'on';
|
||||
$settings->pwd_secure_min = '8';
|
||||
$settings->save();
|
||||
|
||||
if ($user = User::where('username', '=', 'admin')->first()) {
|
||||
$user->locale = 'en-US';
|
||||
$user->save();
|
||||
}
|
||||
|
||||
// Copy the logos from the img/demo directory
|
||||
Storage::disk('local_public')->put('snipe-logo.png', file_get_contents(public_path('img/demo/snipe-logo.png')));
|
||||
Storage::disk('local_public')->put('snipe-logo-lg.png', file_get_contents(public_path('img/demo/snipe-logo-lg.png')));
|
||||
}
|
||||
}
|
37
SNIPE-IT/database/seeders/StatuslabelSeeder.php
Normal file
37
SNIPE-IT/database/seeders/StatuslabelSeeder.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Statuslabel;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class StatuslabelSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Statuslabel::truncate();
|
||||
|
||||
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
||||
|
||||
Statuslabel::factory()->rtd()->create([
|
||||
'name' => 'Ready to Deploy',
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Statuslabel::factory()->pending()->create([
|
||||
'name' => 'Pending',
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Statuslabel::factory()->archived()->create([
|
||||
'name' => 'Archived',
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
Statuslabel::factory()->outForDiagnostics()->create(['user_id' => $admin->id]);
|
||||
Statuslabel::factory()->outForRepair()->create(['user_id' => $admin->id]);
|
||||
Statuslabel::factory()->broken()->create(['user_id' => $admin->id]);
|
||||
Statuslabel::factory()->lost()->create(['user_id' => $admin->id]);
|
||||
}
|
||||
}
|
15
SNIPE-IT/database/seeders/SupplierSeeder.php
Normal file
15
SNIPE-IT/database/seeders/SupplierSeeder.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Supplier;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SupplierSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
Supplier::truncate();
|
||||
Supplier::factory()->count(5)->create();
|
||||
}
|
||||
}
|
116
SNIPE-IT/database/seeders/UserSeeder.php
Normal file
116
SNIPE-IT/database/seeders/UserSeeder.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Department;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Sequence;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
User::truncate();
|
||||
|
||||
if (! Company::count()) {
|
||||
$this->call(CompanySeeder::class);
|
||||
}
|
||||
|
||||
$companyIds = Company::all()->pluck('id');
|
||||
|
||||
if (! Department::count()) {
|
||||
$this->call(DepartmentSeeder::class);
|
||||
}
|
||||
|
||||
$departmentIds = Department::all()->pluck('id');
|
||||
|
||||
User::factory()->count(1)->firstAdmin()
|
||||
->state(new Sequence(fn($sequence) => [
|
||||
'company_id' => $companyIds->random(),
|
||||
'department_id' => $departmentIds->random(),
|
||||
]))
|
||||
->create();
|
||||
|
||||
User::factory()->count(1)->snipeAdmin()
|
||||
->state(new Sequence(fn($sequence) => [
|
||||
'company_id' => $companyIds->random(),
|
||||
'department_id' => $departmentIds->random(),
|
||||
]))
|
||||
->create();
|
||||
|
||||
User::factory()->count(1)->testAdmin()
|
||||
->state(new Sequence(fn($sequence) => [
|
||||
'company_id' => $companyIds->random(),
|
||||
'department_id' => $departmentIds->random(),
|
||||
]))
|
||||
->create();
|
||||
|
||||
User::factory()->count(3)->superuser()
|
||||
->state(new Sequence(fn($sequence) => [
|
||||
'company_id' => $companyIds->random(),
|
||||
'department_id' => $departmentIds->random(),
|
||||
]))
|
||||
->create();
|
||||
|
||||
User::factory()->count(3)->admin()
|
||||
->state(new Sequence(fn($sequence) => [
|
||||
'company_id' => $companyIds->random(),
|
||||
'department_id' => $departmentIds->random(),
|
||||
]))
|
||||
->create();
|
||||
|
||||
User::factory()->count(50)->viewAssets()
|
||||
->state(new Sequence(fn($sequence) => [
|
||||
'company_id' => $companyIds->random(),
|
||||
'department_id' => $departmentIds->random(),
|
||||
]))
|
||||
->create();
|
||||
|
||||
$src = public_path('/img/demo/avatars/');
|
||||
$dst = 'avatars'.'/';
|
||||
$del_files = Storage::files($dst);
|
||||
|
||||
foreach ($del_files as $del_file) { // iterate files
|
||||
$file_to_delete = str_replace($src, '', $del_file);
|
||||
Log::debug('Deleting: '.$file_to_delete);
|
||||
try {
|
||||
Storage::disk('public')->delete($dst.$del_file);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
|
||||
$add_files = glob($src.'/*.*');
|
||||
foreach ($add_files as $add_file) {
|
||||
$file_to_copy = str_replace($src, '', $add_file);
|
||||
Log::debug('Copying: '.$file_to_copy);
|
||||
try {
|
||||
Storage::disk('public')->put($dst.$file_to_copy, file_get_contents($src.$file_to_copy));
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
}
|
||||
|
||||
$users = User::orderBy('id', 'asc')->take(20)->get();
|
||||
$file_number = 1;
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
||||
$user->avatar = $file_number.'.jpg';
|
||||
$user->save();
|
||||
$file_number++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user