From 6e6a021928956b2cd29db61f62cd031e587f68c1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 13 Mar 2023 16:44:47 -0700 Subject: [PATCH 01/52] Add temporary command to display model counts --- app/Console/Commands/CountModels.php | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 app/Console/Commands/CountModels.php diff --git a/app/Console/Commands/CountModels.php b/app/Console/Commands/CountModels.php new file mode 100644 index 0000000000..8b3de99b78 --- /dev/null +++ b/app/Console/Commands/CountModels.php @@ -0,0 +1,76 @@ +table(['Model', 'Count'], [ + [Accessory::class, Accessory::count()], + [Actionlog::class, Actionlog::count()], + [Asset::class, Asset::count()], + [AssetMaintenance::class, AssetMaintenance::count()], + [AssetModel::class, AssetModel::count()], + [Category::class, Category::count()], + [CheckoutAcceptance::class, CheckoutAcceptance::count()], + [CheckoutRequest::class, CheckoutRequest::count()], + [Company::class, Company::count()], + [Component::class, Component::count()], + [Consumable::class, Consumable::count()], + [ConsumableAssignment::class, ConsumableAssignment::count()], + [CustomField::class, CustomField::count()], + [CustomFieldset::class, CustomFieldset::count()], + [Department::class, Department::count()], + [Depreciation::class, Depreciation::count()], + [Group::class, Group::count()], + [Import::class, Import::count()], + [License::class, License::count()], + [LicenseSeat::class, LicenseSeat::count()], + [Location::class, Location::count()], + [Manufacturer::class, Manufacturer::count()], + [PredefinedKit::class, PredefinedKit::count()], + [SCIMUser::class, SCIMUser::count()], + [Setting::class, Setting::count()], + [Statuslabel::class, Statuslabel::count()], + [Supplier::class, Supplier::count()], + [User::class, User::count()], + ]); + + return 0; + } +} From 099ec3f550c97b0506bdb0eef92481bd48de12ea Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 13 Mar 2023 16:45:43 -0700 Subject: [PATCH 02/52] Remove creation of category within category factory state --- database/factories/CategoryFactory.php | 30 +++++++++++++------------- tests/Unit/AssetTest.php | 2 +- tests/Unit/CategoryTest.php | 2 +- tests/Unit/DepreciationTest.php | 4 ++-- tests/Unit/NotificationTest.php | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index 8f9dd90e3f..d792d6dfe0 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -43,7 +43,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->assetLaptopCategory(); public function assetLaptopCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Laptops', 'category_type' => 'asset', 'require_acceptance' => true, @@ -53,7 +53,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->assetDesktopCategory(); public function assetDesktopCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Desktops', 'category_type' => 'asset', 'require_acceptance' => true, @@ -63,7 +63,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->assetDisplayCategory(); public function assetDisplayCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Displays', 'category_type' => 'asset', ]); @@ -72,7 +72,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->assetTabletCategory(); public function assetTabletCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Tablets', 'category_type' => 'asset', ]); @@ -81,7 +81,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->assetMobileCategory(); public function assetMobileCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Mobile Phones', 'category_type' => 'asset', ]); @@ -90,7 +90,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->assetConferenceCategory(); public function assetConferenceCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Conference Phones', 'category_type' => 'asset', ]); @@ -100,7 +100,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->assetVoipCategory(); public function assetVoipCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'VOIP Phones', 'category_type' => 'asset', ]); @@ -109,7 +109,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->accessoryKeyboardCategory(); public function accessoryKeyboardCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Keyboardss', 'category_type' => 'accessory', ]); @@ -119,7 +119,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->accessoryMouseCategory(); public function accessoryMouseCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Mouse', 'category_type' => 'accessory', ]); @@ -128,7 +128,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->componentHddCategory(); public function componentHddCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'HDD/SSD', 'category_type' => 'component', ]); @@ -137,7 +137,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->componentRamCategory(); public function componentRamCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'RAM', 'category_type' => 'component', ]); @@ -146,7 +146,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->consumablePaperCategory(); public function consumablePaperCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Printer Paper', 'category_type' => 'consumable', ]); @@ -155,7 +155,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->consumableInkCategory(); public function consumableInkCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Printer Ink', 'category_type' => 'consumable', ]); @@ -164,7 +164,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->licenseGraphicsCategory(); public function licenseGraphicsCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Graphics Software', 'category_type' => 'license', ]); @@ -173,7 +173,7 @@ class CategoryFactory extends Factory // usage: Category::factory()->licenseGraphicsCategory(); public function licenseOfficeCategory() { - return Category::factory()->create([ + return $this->state([ 'name' => 'Office Software', 'category_type' => 'license', ]); diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php index f0a9b11f19..e4dc8a803f 100644 --- a/tests/Unit/AssetTest.php +++ b/tests/Unit/AssetTest.php @@ -36,7 +36,7 @@ class AssetTest extends TestCase 'model_id' => AssetModel::factory() ->create( [ - 'category_id' => Category::factory()->assetLaptopCategory()->id + 'category_id' => Category::factory()->assetLaptopCategory()->create()->id ] )->id, 'warranty_months' => 24, diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php index 8d749a3b22..387ed946e0 100644 --- a/tests/Unit/CategoryTest.php +++ b/tests/Unit/CategoryTest.php @@ -26,7 +26,7 @@ class CategoryTest extends TestCase public function testACategoryCanHaveAssets() { - $category = Category::factory()->assetDesktopCategory(); + $category = Category::factory()->assetDesktopCategory()->create(); // Generate 5 models via factory $models = AssetModel::factory() diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php index 900ae73671..4dd8422276 100644 --- a/tests/Unit/DepreciationTest.php +++ b/tests/Unit/DepreciationTest.php @@ -18,7 +18,7 @@ class DepreciationTest extends TestCase ->count(5) ->create( [ - 'category_id' => Category::factory()->assetLaptopCategory(), + 'category_id' => Category::factory()->assetLaptopCategory()->create(), 'depreciation_id' => $depreciation->id ]); @@ -35,7 +35,7 @@ class DepreciationTest extends TestCase ->photoshop() ->create( [ - 'category_id' => Category::factory()->licenseGraphicsCategory(), + 'category_id' => Category::factory()->licenseGraphicsCategory()->create(), 'depreciation_id' => $depreciation->id ]); diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 33687ef639..8005759a1e 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -22,7 +22,7 @@ class NotificationTest extends TestCase 'model_id' => AssetModel::factory() ->create( [ - 'category_id' => Category::factory()->assetLaptopCategory()->id + 'category_id' => Category::factory()->assetLaptopCategory()->create()->id ] )->id, 'warranty_months' => 24, From adba450b40e98205b4a2421c1fcdafa7032a1cba Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 13 Mar 2023 17:27:06 -0700 Subject: [PATCH 03/52] Remove some hard-coded ids in factories --- database/factories/AssetModelFactory.php | 77 ++++++++++++++++++------ database/factories/CategoryFactory.php | 5 +- database/factories/ComponentFactory.php | 5 +- 3 files changed, 66 insertions(+), 21 deletions(-) diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index 187bc539fc..36f030b585 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use App\Models\Category; @@ -81,7 +82,9 @@ class AssetModelFactory extends Factory public function definition() { return [ - 'user_id' => 1, + 'user_id' => function () { + return User::first() ?? User::factory()->firstAdmin(); + }, 'name' => $this->faker->catchPhrase(), 'model_number' => $this->faker->creditCardNumber(), 'notes' => 'Created by demo seeder', @@ -94,7 +97,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Macbook Pro 13"', - 'category_id' => 1, + 'category_id' => function () { + return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + }, 'eol' => '36', 'depreciation_id' => 1, 'image' => 'mbp.jpg', @@ -108,7 +113,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Macbook Air', - 'category_id' => 1, + 'category_id' => function () { + return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + }, 'manufacturer_id' => 1, 'eol' => '36', 'depreciation_id' => 1, @@ -123,7 +130,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Surface', - 'category_id' => 1, + 'category_id' => function () { + return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + }, 'manufacturer_id' => 2, 'eol' => '36', 'depreciation_id' => 1, @@ -138,7 +147,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'XPS 13', - 'category_id' => 1, + 'category_id' => function () { + return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + }, 'manufacturer_id' => 3, 'eol' => '36', 'depreciation_id' => 1, @@ -153,7 +164,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'ZenBook UX310', - 'category_id' => 1, + 'category_id' => function () { + return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + }, 'manufacturer_id' => 4, 'eol' => '36', 'depreciation_id' => 1, @@ -168,7 +181,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Spectre', - 'category_id' => 1, + 'category_id' => function () { + return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + }, 'manufacturer_id' => 5, 'eol' => '36', 'depreciation_id' => 1, @@ -183,7 +198,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Yoga 910', - 'category_id' => 1, + 'category_id' => function () { + return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + }, 'manufacturer_id' => 6, 'eol' => '36', 'depreciation_id' => 1, @@ -198,7 +215,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'iMac Pro', - 'category_id' => 2, + 'category_id' => function (){ + return Category::find(2) ?? Category::factory()->assetDesktopCategory(); + }, 'manufacturer_id' => 1, 'eol' => '24', 'depreciation_id' => 1, @@ -213,7 +232,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Lenovo Intel Core i5', - 'category_id' => 2, + 'category_id' => function () { + return Category::find(2) ?? Category::factory()->assetDesktopCategory(); + }, 'manufacturer_id' => 6, 'eol' => '24', 'depreciation_id' => 1, @@ -228,7 +249,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'OptiPlex', - 'category_id' => 2, + 'category_id' => function (){ + return Category::find(2) ?? Category::factory()->assetDesktopCategory(); + }, 'manufacturer_id' => 3, 'model_number' => '5040 (MRR81)', 'eol' => '24', @@ -244,7 +267,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'SoundStation 2', - 'category_id' => 6, + 'category_id' => function () { + return Category::find(6) ?? Category::factory()->assetVoipCategory(); + }, 'manufacturer_id' => 8, 'eol' => '12', 'depreciation_id' => 1, @@ -258,7 +283,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Polycom CX3000 IP Conference Phone', - 'category_id' => 6, + 'category_id' => function () { + return Category::find(6) ?? Category::factory()->assetVoipCategory(); + }, 'manufacturer_id' => 8, 'eol' => '12', 'depreciation_id' => 1, @@ -272,7 +299,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'iPad Pro', - 'category_id' => 3, + 'category_id' => function () { + return Category::find(3) ?? Category::factory()->assetTabletCategory(); + }, 'manufacturer_id' => 1, 'eol' => '12', 'depreciation_id' => 1, @@ -286,7 +315,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Tab3', - 'category_id' => 3, + 'category_id' => function () { + return Category::find(3) ?? Category::factory()->assetTabletCategory(); + }, 'manufacturer_id' => 6, 'eol' => '12', 'depreciation_id' => 1, @@ -300,7 +331,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'iPhone 11', - 'category_id' => 4, + 'category_id' => function () { + return Category::find(4) ?? Category::factory()->assetMobileCategory(); + }, 'manufacturer_id' => 1, 'eol' => '12', 'depreciation_id' => 3, @@ -315,7 +348,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'iPhone 12', - 'category_id' => 4, + 'category_id' => function () { + return Category::find(4) ?? Category::factory()->assetMobileCategory(); + }, 'manufacturer_id' => 1, 'eol' => '12', 'depreciation_id' => 1, @@ -330,7 +365,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Ultrafine 4k', - 'category_id' => 5, + 'category_id' => function () { + return Category::find(5) ?? Category::factory()->assetDisplayCategory(); + }, 'manufacturer_id' => 7, 'eol' => '12', 'depreciation_id' => 2, @@ -344,7 +381,9 @@ class AssetModelFactory extends Factory return $this->state(function () { return [ 'name' => 'Ultrasharp U2415', - 'category_id' => 5, + 'category_id' => function () { + return Category::find(5) ?? Category::factory()->assetDisplayCategory(); + }, 'manufacturer_id' => 3, 'eol' => '12', 'depreciation_id' => 2, diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index d792d6dfe0..e2e8ecda7a 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use App\Models\Category; @@ -36,7 +37,9 @@ class CategoryFactory extends Factory 'eula_text' => $this->faker->paragraph(), 'require_acceptance' => false, 'use_default_eula' => $this->faker->boolean(), - 'user_id' => 1, + 'user_id' => function () { + return User::first() ?? User::factory()->firstAdmin(); + }, ]; } diff --git a/database/factories/ComponentFactory.php b/database/factories/ComponentFactory.php index bd971162ab..20c035aed6 100644 --- a/database/factories/ComponentFactory.php +++ b/database/factories/ComponentFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Location; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -34,7 +35,9 @@ class ComponentFactory extends Factory 'category_id' => function () { return \App\Models\Category::factory()->create()->id; }, - 'location_id' => 1, + 'location_id' => function () { + return Location::first() ?? Location::factory(); + }, 'serial' => $this->faker->uuid, 'qty' => $this->faker->numberBetween(3, 10), 'order_number' => $this->faker->numberBetween(1000000, 50000000), From e8ff7cc09c748141ad82a1e9a3b1c2ec7986b974 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 14 Mar 2023 11:34:58 -0700 Subject: [PATCH 04/52] Remove hard-coded user_id in factories --- database/factories/AccessoryFactory.php | 5 ++++- database/factories/ActionlogFactory.php | 4 +++- database/factories/AssetFactory.php | 5 ++++- database/factories/CategoryFactory.php | 2 +- database/factories/ConsumableFactory.php | 5 ++++- database/factories/DepartmentFactory.php | 5 ++++- database/factories/DepreciationFactory.php | 5 ++++- database/factories/LicenseFactory.php | 5 ++++- database/factories/ManufacturerFactory.php | 5 ++++- database/factories/SettingFactory.php | 5 ++++- database/factories/StatuslabelFactory.php | 5 ++++- 11 files changed, 40 insertions(+), 11 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index 84edcb705c..54ceed1e43 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -30,7 +31,9 @@ class AccessoryFactory extends Factory public function definition() { return [ - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'model_number' => $this->faker->numberBetween(1000000, 50000000), 'location_id' => rand(1, 5), ]; diff --git a/database/factories/ActionlogFactory.php b/database/factories/ActionlogFactory.php index 382a6412c2..ea4f4bfc7a 100644 --- a/database/factories/ActionlogFactory.php +++ b/database/factories/ActionlogFactory.php @@ -38,7 +38,9 @@ class ActionlogFactory extends Factory return [ 'item_type' => get_class($asset), 'item_id' => 1, - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'action_type' => 'uploaded', ]; } diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 6b77b8b078..5e4a1b3918 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -7,6 +7,7 @@ use App\Models\AssetModel; use App\Models\Category; use App\Models\Location; use App\Models\Supplier; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -41,7 +42,9 @@ class AssetFactory extends Factory 'rtd_location_id' => Location::factory(), 'serial' => $this->faker->uuid(), 'status_id' => 1, - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'asset_tag' => $this->faker->unixTime('now'), 'notes' => 'Created by DB seeder', 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index e2e8ecda7a..9e251931d1 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -38,7 +38,7 @@ class CategoryFactory extends Factory 'require_acceptance' => false, 'use_default_eula' => $this->faker->boolean(), 'user_id' => function () { - return User::first() ?? User::factory()->firstAdmin(); + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, ]; } diff --git a/database/factories/ConsumableFactory.php b/database/factories/ConsumableFactory.php index 50a9db0ba2..45699c7c30 100644 --- a/database/factories/ConsumableFactory.php +++ b/database/factories/ConsumableFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -30,7 +31,9 @@ class ConsumableFactory extends Factory public function definition() { return [ - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'item_no' => $this->faker->numberBetween(1000000, 50000000), 'order_number' => $this->faker->numberBetween(1000000, 50000000), 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()), diff --git a/database/factories/DepartmentFactory.php b/database/factories/DepartmentFactory.php index ad80d32841..c8e14c0235 100644 --- a/database/factories/DepartmentFactory.php +++ b/database/factories/DepartmentFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -30,7 +31,9 @@ class DepartmentFactory extends Factory public function definition() { return [ - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'location_id' => rand(1, 5), ]; } diff --git a/database/factories/DepreciationFactory.php b/database/factories/DepreciationFactory.php index 17940ac515..a203a74773 100644 --- a/database/factories/DepreciationFactory.php +++ b/database/factories/DepreciationFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -31,7 +32,9 @@ class DepreciationFactory extends Factory { return [ 'name' => $this->faker->catchPhrase(), - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'months' => 36, ]; } diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index 399b468581..ca00bf44a9 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; use App\Models\Category; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -40,7 +41,9 @@ class LicenseFactory extends Factory return [ - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'name' => $this->faker->name, 'license_email' => $this->faker->safeEmail, 'serial' => $this->faker->uuid, diff --git a/database/factories/ManufacturerFactory.php b/database/factories/ManufacturerFactory.php index 427cd0b6db..3b913dd7a6 100644 --- a/database/factories/ManufacturerFactory.php +++ b/database/factories/ManufacturerFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -52,7 +53,9 @@ class ManufacturerFactory extends Factory public function definition() { return [ - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'support_phone' => $this->faker->phoneNumber(), 'url' => $this->faker->url(), 'support_email' => $this->faker->safeEmail(), diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index cd88cdaf2f..bae61a1abd 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -20,6 +20,7 @@ use App\Models\Location; use App\Models\Manufacturer; use App\Models\Statuslabel; use App\Models\Supplier; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; class SettingFactory extends Factory @@ -39,7 +40,9 @@ class SettingFactory extends Factory public function definition() { return [ - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'per_page' => 20, 'site_name' => $this->faker->sentence, 'auto_increment_assets' => false, diff --git a/database/factories/StatuslabelFactory.php b/database/factories/StatuslabelFactory.php index 051e8131ee..9150e7b62e 100644 --- a/database/factories/StatuslabelFactory.php +++ b/database/factories/StatuslabelFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use App\Models\Statuslabel; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; class StatuslabelFactory extends Factory @@ -25,7 +26,9 @@ class StatuslabelFactory extends Factory 'name' => $this->faker->sentence, 'created_at' => $this->faker->dateTime(), 'updated_at' => $this->faker->dateTime(), - 'user_id' => 1, + 'user_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, 'deleted_at' => null, 'deployable' => 0, 'pending' => 0, From 7cf424b914b10f4a9a1c5d7de9d32f449ff4893c Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 14 Mar 2023 12:01:23 -0700 Subject: [PATCH 05/52] Remove hard-coded manufacturer_id in factories --- database/factories/AccessoryFactory.php | 17 ++++-- database/factories/AssetModelFactory.php | 69 ++++++++++++++++++------ database/factories/ConsumableFactory.php | 13 +++-- database/factories/LicenseFactory.php | 17 ++++-- 4 files changed, 88 insertions(+), 28 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index 54ceed1e43..3c48830d9e 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -46,7 +47,9 @@ class AccessoryFactory extends Factory 'name' => 'Bluetooth Keyboard', 'image' => 'bluetooth.jpg', 'category_id' => 8, - 'manufacturer_id' => 1, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); + }, 'qty' => 10, 'min_amt' => 2, 'supplier_id' => rand(1, 5), @@ -61,7 +64,9 @@ class AccessoryFactory extends Factory 'name' => 'USB Keyboard', 'image' => 'usb-keyboard.jpg', 'category_id' => 8, - 'manufacturer_id' => 1, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); + }, 'qty' => 15, 'min_amt' => 2, 'supplier_id' => rand(1, 5), @@ -76,7 +81,9 @@ class AccessoryFactory extends Factory 'name' => 'Magic Mouse', 'image' => 'magic-mouse.jpg', 'category_id' => 9, - 'manufacturer_id' => 1, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); + }, 'qty' => 13, 'min_amt' => 2, 'supplier_id' => rand(1, 5), @@ -91,7 +98,9 @@ class AccessoryFactory extends Factory 'name' => 'Sculpt Comfort Mouse', 'image' => 'comfort-mouse.jpg', 'category_id' => 9, - 'manufacturer_id' => 2, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft(); + }, 'qty' => 13, 'min_amt' => 2, ]; diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index 36f030b585..2b52bcff83 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use App\Models\Category; @@ -116,7 +117,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(1) ?? Category::factory()->assetLaptopCategory(); }, - 'manufacturer_id' => 1, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); + }, 'eol' => '36', 'depreciation_id' => 1, 'image' => 'macbookair.jpg', @@ -133,7 +136,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(1) ?? Category::factory()->assetLaptopCategory(); }, - 'manufacturer_id' => 2, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft(); + }, 'eol' => '36', 'depreciation_id' => 1, 'image' => 'surface.jpg', @@ -150,7 +155,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(1) ?? Category::factory()->assetLaptopCategory(); }, - 'manufacturer_id' => 3, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell(); + }, 'eol' => '36', 'depreciation_id' => 1, 'image' => 'xps.jpg', @@ -167,7 +174,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(1) ?? Category::factory()->assetLaptopCategory(); }, - 'manufacturer_id' => 4, + 'manufacturer_id' => function () { + return Manufacturer::where('Asus', 'Asus')->first() ?? Manufacturer::factory()->asus(); + }, 'eol' => '36', 'depreciation_id' => 1, 'image' => 'zenbook.jpg', @@ -184,7 +193,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(1) ?? Category::factory()->assetLaptopCategory(); }, - 'manufacturer_id' => 5, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp(); + }, 'eol' => '36', 'depreciation_id' => 1, 'image' => 'spectre.jpg', @@ -201,7 +212,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(1) ?? Category::factory()->assetLaptopCategory(); }, - 'manufacturer_id' => 6, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo(); + }, 'eol' => '36', 'depreciation_id' => 1, 'image' => 'yoga.png', @@ -218,7 +231,9 @@ class AssetModelFactory extends Factory 'category_id' => function (){ return Category::find(2) ?? Category::factory()->assetDesktopCategory(); }, - 'manufacturer_id' => 1, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); + }, 'eol' => '24', 'depreciation_id' => 1, 'image' => 'imacpro.jpg', @@ -235,7 +250,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(2) ?? Category::factory()->assetDesktopCategory(); }, - 'manufacturer_id' => 6, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo(); + }, 'eol' => '24', 'depreciation_id' => 1, 'image' => 'lenovoi5.png', @@ -252,7 +269,9 @@ class AssetModelFactory extends Factory 'category_id' => function (){ return Category::find(2) ?? Category::factory()->assetDesktopCategory(); }, - 'manufacturer_id' => 3, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell(); + }, 'model_number' => '5040 (MRR81)', 'eol' => '24', 'depreciation_id' => 1, @@ -270,7 +289,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(6) ?? Category::factory()->assetVoipCategory(); }, - 'manufacturer_id' => 8, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom(); + }, 'eol' => '12', 'depreciation_id' => 1, 'image' => 'soundstation.jpg', @@ -286,7 +307,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(6) ?? Category::factory()->assetVoipCategory(); }, - 'manufacturer_id' => 8, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom(); + }, 'eol' => '12', 'depreciation_id' => 1, 'image' => 'cx3000.png', @@ -302,7 +325,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(3) ?? Category::factory()->assetTabletCategory(); }, - 'manufacturer_id' => 1, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); + }, 'eol' => '12', 'depreciation_id' => 1, 'image' => 'ipad.jpg', @@ -318,7 +343,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(3) ?? Category::factory()->assetTabletCategory(); }, - 'manufacturer_id' => 6, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo(); + }, 'eol' => '12', 'depreciation_id' => 1, 'image' => 'tab3.png', @@ -334,7 +361,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(4) ?? Category::factory()->assetMobileCategory(); }, - 'manufacturer_id' => 1, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); + }, 'eol' => '12', 'depreciation_id' => 3, 'image' => 'iphone11.jpeg', @@ -351,7 +380,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(4) ?? Category::factory()->assetMobileCategory(); }, - 'manufacturer_id' => 1, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); + }, 'eol' => '12', 'depreciation_id' => 1, 'image' => 'iphone12.jpeg', @@ -368,7 +399,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(5) ?? Category::factory()->assetDisplayCategory(); }, - 'manufacturer_id' => 7, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'LG')->first() ?? Manufacturer::factory()->lg(); + }, 'eol' => '12', 'depreciation_id' => 2, 'image' => 'ultrafine.jpg', @@ -384,7 +417,9 @@ class AssetModelFactory extends Factory 'category_id' => function () { return Category::find(5) ?? Category::factory()->assetDisplayCategory(); }, - 'manufacturer_id' => 3, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell(); + }, 'eol' => '12', 'depreciation_id' => 2, 'image' => 'ultrasharp.jpg', diff --git a/database/factories/ConsumableFactory.php b/database/factories/ConsumableFactory.php index 45699c7c30..ab28e38880 100644 --- a/database/factories/ConsumableFactory.php +++ b/database/factories/ConsumableFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -49,7 +50,9 @@ class ConsumableFactory extends Factory return [ 'name' => 'Cardstock (White)', 'category_id' => 10, - 'manufacturer_id' => 10, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery(); + }, 'qty' => 10, 'min_amt' => 2, 'company_id' => 3, @@ -63,7 +66,9 @@ class ConsumableFactory extends Factory return [ 'name' => 'Laserjet Paper (Ream)', 'category_id' => 10, - 'manufacturer_id' => 10, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery(); + }, 'qty' => 20, 'min_amt' => 2, ]; @@ -76,7 +81,9 @@ class ConsumableFactory extends Factory return [ 'name' => 'Laserjet Toner (black)', 'category_id' => 11, - 'manufacturer_id' => 5, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp(); + }, 'qty' => 20, 'min_amt' => 2, ]; diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index ca00bf44a9..dd2c186d60 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; use App\Models\Category; +use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -64,7 +65,9 @@ class LicenseFactory extends Factory return $this->state(function () { $data = [ 'name' => 'Photoshop', - 'manufacturer_id' => 9, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Adobe')->first() ?? Manufacturer::factory()->adobe(); + }, 'purchase_cost' => '299.99', 'seats' => 10, 'purchase_order' => '13503Q', @@ -81,7 +84,9 @@ class LicenseFactory extends Factory return $this->state(function () { $data = [ 'name' => 'Acrobat', - 'manufacturer_id' => 9, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Adobe')->first() ?? Manufacturer::factory()->adobe(); + }, 'purchase_cost' => '29.99', 'seats' => 10, 'category_id' => 14, @@ -96,7 +101,9 @@ class LicenseFactory extends Factory return $this->state(function () { $data = [ 'name' => 'InDesign', - 'manufacturer_id' => 9, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Adobe')->first() ?? Manufacturer::factory()->adobe(); + }, 'purchase_cost' => '199.99', 'seats' => 10, 'category_id' => 14, @@ -112,7 +119,9 @@ class LicenseFactory extends Factory return $this->state(function () { $data = [ 'name' => 'Office', - 'manufacturer_id' => 2, + 'manufacturer_id' => function () { + return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft(); + }, 'purchase_cost' => '49.99', 'seats' => 20, 'category_id' => 15, From 4c4101fe64a3132c0a4f3fab71db5cf11a6ce788 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 14 Mar 2023 12:04:31 -0700 Subject: [PATCH 06/52] Fix key name --- database/factories/AssetModelFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index 2b52bcff83..df538e1c7e 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -175,7 +175,7 @@ class AssetModelFactory extends Factory return Category::find(1) ?? Category::factory()->assetLaptopCategory(); }, 'manufacturer_id' => function () { - return Manufacturer::where('Asus', 'Asus')->first() ?? Manufacturer::factory()->asus(); + return Manufacturer::where('name', 'Asus')->first() ?? Manufacturer::factory()->asus(); }, 'eol' => '36', 'depreciation_id' => 1, From a2efe3fa6775123b6156ea6abdfa4bc617add6d1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 14 Mar 2023 12:50:02 -0700 Subject: [PATCH 07/52] Remove hard-coded category_id in factories --- database/factories/AccessoryFactory.php | 17 ++++++++--- database/factories/AssetModelFactory.php | 36 ++++++++++++------------ database/factories/ComponentFactory.php | 26 ++++++++++------- database/factories/ConsumableFactory.php | 13 +++++++-- database/factories/LicenseFactory.php | 16 ++++++++--- 5 files changed, 69 insertions(+), 39 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index 3c48830d9e..d47ac401ec 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Category; use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -46,7 +47,9 @@ class AccessoryFactory extends Factory return [ 'name' => 'Bluetooth Keyboard', 'image' => 'bluetooth.jpg', - 'category_id' => 8, + 'category_id' => function () { + return Category::where('name', 'Keyboardss')->first() ?? Category::factory()->accessoryKeyboardCategory(); + }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); }, @@ -63,7 +66,9 @@ class AccessoryFactory extends Factory return [ 'name' => 'USB Keyboard', 'image' => 'usb-keyboard.jpg', - 'category_id' => 8, + 'category_id' => function () { + return Category::where('name', 'Keyboardss')->first() ?? Category::factory()->accessoryKeyboardCategory(); + }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); }, @@ -80,7 +85,9 @@ class AccessoryFactory extends Factory return [ 'name' => 'Magic Mouse', 'image' => 'magic-mouse.jpg', - 'category_id' => 9, + 'category_id' => function () { + return Category::where('name', 'Mouse')->first() ?? Category::factory()->accessoryMouseCategory(); + }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); }, @@ -97,7 +104,9 @@ class AccessoryFactory extends Factory return [ 'name' => 'Sculpt Comfort Mouse', 'image' => 'comfort-mouse.jpg', - 'category_id' => 9, + 'category_id' => function () { + return Category::where('name', 'Mouse')->first() ?? Category::factory()->accessoryMouseCategory(); + }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft(); }, diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index df538e1c7e..2e88c40806 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -99,7 +99,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Macbook Pro 13"', 'category_id' => function () { - return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory(); }, 'eol' => '36', 'depreciation_id' => 1, @@ -115,7 +115,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Macbook Air', 'category_id' => function () { - return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); @@ -134,7 +134,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Surface', 'category_id' => function () { - return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft(); @@ -153,7 +153,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'XPS 13', 'category_id' => function () { - return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell(); @@ -172,7 +172,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'ZenBook UX310', 'category_id' => function () { - return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Asus')->first() ?? Manufacturer::factory()->asus(); @@ -191,7 +191,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Spectre', 'category_id' => function () { - return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp(); @@ -210,7 +210,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Yoga 910', 'category_id' => function () { - return Category::find(1) ?? Category::factory()->assetLaptopCategory(); + return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo(); @@ -229,7 +229,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'iMac Pro', 'category_id' => function (){ - return Category::find(2) ?? Category::factory()->assetDesktopCategory(); + return Category::where('name', 'Desktops')->first() ?? Category::factory()->assetDesktopCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); @@ -248,7 +248,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Lenovo Intel Core i5', 'category_id' => function () { - return Category::find(2) ?? Category::factory()->assetDesktopCategory(); + return Category::where('name', 'Desktops')->first() ?? Category::factory()->assetDesktopCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo(); @@ -267,7 +267,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'OptiPlex', 'category_id' => function (){ - return Category::find(2) ?? Category::factory()->assetDesktopCategory(); + return Category::where('name', 'Desktops')->first() ?? Category::factory()->assetDesktopCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell(); @@ -287,7 +287,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'SoundStation 2', 'category_id' => function () { - return Category::find(6) ?? Category::factory()->assetVoipCategory(); + return Category::where('name', 'VOIP Phones')->first() ?? Category::factory()->assetVoipCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom(); @@ -305,7 +305,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Polycom CX3000 IP Conference Phone', 'category_id' => function () { - return Category::find(6) ?? Category::factory()->assetVoipCategory(); + return Category::where('name', 'VOIP Phones')->first() ?? Category::factory()->assetVoipCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom(); @@ -323,7 +323,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'iPad Pro', 'category_id' => function () { - return Category::find(3) ?? Category::factory()->assetTabletCategory(); + return Category::where('name', 'Tablets')->first() ?? Category::factory()->assetTabletCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); @@ -341,7 +341,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Tab3', 'category_id' => function () { - return Category::find(3) ?? Category::factory()->assetTabletCategory(); + return Category::where('name', 'Tablets')->first() ?? Category::factory()->assetTabletCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo(); @@ -359,7 +359,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'iPhone 11', 'category_id' => function () { - return Category::find(4) ?? Category::factory()->assetMobileCategory(); + return Category::where('name', 'Mobile Phones')->first() ?? Category::factory()->assetMobileCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); @@ -378,7 +378,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'iPhone 12', 'category_id' => function () { - return Category::find(4) ?? Category::factory()->assetMobileCategory(); + return Category::where('name', 'Mobile Phones')->first() ?? Category::factory()->assetMobileCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); @@ -397,7 +397,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Ultrafine 4k', 'category_id' => function () { - return Category::find(5) ?? Category::factory()->assetDisplayCategory(); + return Category::where('name', 'Displays')->first() ?? Category::factory()->assetDisplayCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'LG')->first() ?? Manufacturer::factory()->lg(); @@ -415,7 +415,7 @@ class AssetModelFactory extends Factory return [ 'name' => 'Ultrasharp U2415', 'category_id' => function () { - return Category::find(5) ?? Category::factory()->assetDisplayCategory(); + return Category::where('name', 'Displays')->first() ?? Category::factory()->assetDisplayCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell(); diff --git a/database/factories/ComponentFactory.php b/database/factories/ComponentFactory.php index 20c035aed6..36e0214350 100644 --- a/database/factories/ComponentFactory.php +++ b/database/factories/ComponentFactory.php @@ -2,6 +2,8 @@ namespace Database\Factories; +use App\Models\Category; +use App\Models\Company; use App\Models\Location; use Illuminate\Database\Eloquent\Factories\Factory; @@ -32,9 +34,7 @@ class ComponentFactory extends Factory { return [ 'name' => $this->faker->text(20), - 'category_id' => function () { - return \App\Models\Category::factory()->create()->id; - }, + 'category_id' => Category::factory(), 'location_id' => function () { return Location::first() ?? Location::factory(); }, @@ -44,9 +44,7 @@ class ComponentFactory extends Factory 'purchase_date' => $this->faker->dateTime(), 'purchase_cost' => $this->faker->randomFloat(2), 'min_amt' => $this->faker->numberBetween($min = 1, $max = 2), - 'company_id' => function () { - return \App\Models\Company::factory()->create()->id; - }, + 'company_id' => Company::factory(), ]; } @@ -55,7 +53,9 @@ class ComponentFactory extends Factory return $this->state(function () { return [ 'name' => 'Crucial 4GB DDR3L-1600 SODIMM', - 'category_id' => 13, + 'category_id' => function () { + return Category::where('name', 'RAM')->first() ?? Category::factory()->componentRamCategory(); + }, 'qty' => 10, 'min_amt' => 2, 'location_id' => 3, @@ -69,7 +69,9 @@ class ComponentFactory extends Factory return $this->state(function () { return [ 'name' => 'Crucial 8GB DDR3L-1600 SODIMM Memory for Mac', - 'category_id' => 13, + 'category_id' => function () { + return Category::where('name', 'RAM')->first() ?? Category::factory()->componentRamCategory(); + }, 'qty' => 10, 'min_amt' => 2, ]; @@ -81,7 +83,9 @@ class ComponentFactory extends Factory return $this->state(function () { return [ 'name' => 'Crucial BX300 120GB SATA Internal SSD', - 'category_id' => 12, + 'category_id' => function () { + return Category::where('name', 'HDD/SSD')->first() ?? Category::factory()->componentHddCategory(); + }, 'qty' => 10, 'min_amt' => 2, ]; @@ -93,7 +97,9 @@ class ComponentFactory extends Factory return $this->state(function () { return [ 'name' => 'Crucial BX300 240GB SATA Internal SSD', - 'category_id' => 12, + 'category_id' => function () { + return Category::where('name', 'HDD/SSD')->first() ?? Category::factory()->componentHddCategory(); + }, 'qty' => 10, 'min_amt' => 2, ]; diff --git a/database/factories/ConsumableFactory.php b/database/factories/ConsumableFactory.php index ab28e38880..085c9811f1 100644 --- a/database/factories/ConsumableFactory.php +++ b/database/factories/ConsumableFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Category; use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -49,7 +50,9 @@ class ConsumableFactory extends Factory return $this->state(function () { return [ 'name' => 'Cardstock (White)', - 'category_id' => 10, + 'category_id' => function () { + return Category::where('name', 'Printer Paper')->first() ?? Category::factory()->consumablePaperCategory(); + }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery(); }, @@ -65,7 +68,9 @@ class ConsumableFactory extends Factory return $this->state(function () { return [ 'name' => 'Laserjet Paper (Ream)', - 'category_id' => 10, + 'category_id' => function () { + return Category::where('name', 'Printer Paper')->first() ?? Category::factory()->consumablePaperCategory(); + }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Avery')->first() ?? Manufacturer::factory()->avery(); }, @@ -80,7 +85,9 @@ class ConsumableFactory extends Factory return $this->state(function () { return [ 'name' => 'Laserjet Toner (black)', - 'category_id' => 11, + 'category_id' => function () { + return Category::where('name', 'Printer Ink')->first() ?? Category::factory()->consumableInkCategory(); + }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp(); }, diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index dd2c186d60..418e296b6c 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -72,7 +72,9 @@ class LicenseFactory extends Factory 'seats' => 10, 'purchase_order' => '13503Q', 'maintained' => true, - 'category_id' => 14, + 'category_id' => function () { + return Category::where('name', 'Graphics Software')->first() ?? Category::factory()->licenseGraphicsCategory(); + }, ]; return $data; @@ -89,7 +91,9 @@ class LicenseFactory extends Factory }, 'purchase_cost' => '29.99', 'seats' => 10, - 'category_id' => 14, + 'category_id' => function () { + return Category::where('name', 'Graphics Software')->first() ?? Category::factory()->licenseGraphicsCategory(); + }, ]; return $data; @@ -106,7 +110,9 @@ class LicenseFactory extends Factory }, 'purchase_cost' => '199.99', 'seats' => 10, - 'category_id' => 14, + 'category_id' => function () { + return Category::where('name', 'Graphics Software')->first() ?? Category::factory()->licenseGraphicsCategory(); + }, ]; @@ -124,7 +130,9 @@ class LicenseFactory extends Factory }, 'purchase_cost' => '49.99', 'seats' => 20, - 'category_id' => 15, + 'category_id' => function () { + return Category::where('name', 'Office Software')->first() ?? Category::factory()->licenseOfficeCategory(); + }, ]; return $data; From ef8007a89035a97d8326e6d19b4209cfa51512da Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 14 Mar 2023 13:24:50 -0700 Subject: [PATCH 08/52] Remove hard-coded status_id in asset factory --- database/factories/AssetFactory.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 5e4a1b3918..aec4769476 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -6,6 +6,7 @@ use App\Models\Asset; use App\Models\AssetModel; use App\Models\Category; use App\Models\Location; +use App\Models\Statuslabel; use App\Models\Supplier; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -41,7 +42,9 @@ class AssetFactory extends Factory 'name' => null, 'rtd_location_id' => Location::factory(), 'serial' => $this->faker->uuid(), - 'status_id' => 1, + 'status_id' => function () { + return Statuslabel::where('name', 'Ready to Deploy')->first() ?? Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']); + }, 'user_id' => function () { return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, @@ -73,7 +76,9 @@ class AssetFactory extends Factory return $this->state(function () { return [ 'model_id' => 1, - 'status_id' => 2, + 'status_id' => function () { + return Statuslabel::where('name', 'Pending')->first() ?? Statuslabel::factory()->pending()->make(['name' => 'Pending']); + }, ]; }); } @@ -83,7 +88,9 @@ class AssetFactory extends Factory return $this->state(function () { return [ 'model_id' => 1, - 'status_id' => 3, + 'status_id' => function () { + return Statuslabel::where('name', 'Archived')->first() ?? Statuslabel::factory()->archived()->make(['name' => 'Archived']); + }, ]; }); } From 1ff094dd47a574f18bdd7ca41e3976195016ead1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 14 Mar 2023 13:56:25 -0700 Subject: [PATCH 09/52] Remove hard-coded model_id in asset factory --- database/factories/AssetFactory.php | 100 +++++++++++++++++++++------- 1 file changed, 75 insertions(+), 25 deletions(-) diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index aec4769476..7d699c0ae0 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -66,7 +66,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 1, + 'model_id' => function () { + return AssetModel::where('name', 'Macbook Pro 13"')->first() ?? AssetModel::factory()->mbp13Model(); + }, ]; }); } @@ -75,7 +77,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 1, + 'model_id' => function () { + return AssetModel::where('name', 'Macbook Pro 13"')->first() ?? AssetModel::factory()->mbp13Model(); + }, 'status_id' => function () { return Statuslabel::where('name', 'Pending')->first() ?? Statuslabel::factory()->pending()->make(['name' => 'Pending']); }, @@ -87,7 +91,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 1, + 'model_id' => function () { + return AssetModel::where('name', 'Macbook Pro 13"')->first() ?? AssetModel::factory()->mbp13Model(); + }, 'status_id' => function () { return Statuslabel::where('name', 'Archived')->first() ?? Statuslabel::factory()->archived()->make(['name' => 'Archived']); }, @@ -99,7 +105,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 2, + 'model_id' => function () { + return AssetModel::where('name', 'Macbook Air')->first() ?? AssetModel::factory()->mbpAirModel(); + }, ]; }); } @@ -108,7 +116,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 3, + 'model_id' => function () { + return AssetModel::where('name', 'Surface')->first() ?? AssetModel::factory()->surfaceModel(); + }, ]; }); } @@ -117,7 +127,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 4, + 'model_id' => function () { + return AssetModel::where('name', 'XPS 13')->first() ?? AssetModel::factory()->xps13Model(); + }, ]; }); } @@ -126,7 +138,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 5, + 'model_id' => function () { + return AssetModel::where('name', 'Spectre')->first() ?? AssetModel::factory()->spectreModel(); + }, ]; }); } @@ -135,7 +149,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 6, + 'model_id' => function () { + return AssetModel::where('name', 'ZenBook UX310')->first() ?? AssetModel::factory()->zenbookModel(); + }, ]; }); } @@ -144,7 +160,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 7, + 'model_id' => function () { + return AssetModel::where('name', 'Yoga 910')->first() ?? AssetModel::factory()->yogaModel(); + }, ]; }); } @@ -153,7 +171,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 8, + 'model_id' => function () { + return AssetModel::where('name', 'iMac Pro')->first() ?? AssetModel::factory()->macproModel(); + }, ]; }); } @@ -162,7 +182,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 9, + 'model_id' => function () { + return AssetModel::where('name', 'Lenovo Intel Core i5')->first() ?? AssetModel::factory()->lenovoI5Model(); + }, ]; }); } @@ -171,7 +193,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 10, + 'model_id' => function () { + return AssetModel::where('name', 'OptiPlex')->first() ?? AssetModel::factory()->optiplexModel(); + }, ]; }); } @@ -180,7 +204,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 11, + 'model_id' => function () { + return AssetModel::where('name', 'SoundStation 2')->first() ?? AssetModel::factory()->polycomModel(); + }, ]; }); } @@ -189,7 +215,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 12, + 'model_id' => function () { + return AssetModel::where('name', 'Polycom CX3000 IP Conference Phone')->first() ?? AssetModel::factory()->polycomcxModel(); + }, ]; }); } @@ -198,7 +226,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 13, + 'model_id' => function () { + return AssetModel::where('name', 'iPad Pro')->first() ?? AssetModel::factory()->ipadModel(); + }, ]; }); } @@ -207,7 +237,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 14, + 'model_id' => function () { + return AssetModel::where('name', 'Tab3')->first() ?? AssetModel::factory()->tab3Model(); + }, ]; }); } @@ -216,7 +248,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 15, + 'model_id' => function () { + return AssetModel::where('name', 'iPhone 11')->first() ?? AssetModel::factory()->iphone11Model(); + }, ]; }); } @@ -225,7 +259,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 16, + 'model_id' => function () { + return AssetModel::where('name', 'iPhone 12')->first() ?? AssetModel::factory()->iphone12Model(); + }, ]; }); } @@ -234,7 +270,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 17, + 'model_id' => function () { + return AssetModel::where('name', 'Ultrafine 4k')->first() ?? AssetModel::factory()->ultrafine(); + }, ]; }); } @@ -243,7 +281,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 18, + 'model_id' => function () { + return AssetModel::where('name', 'Ultrasharp U2415')->first() ?? AssetModel::factory()->ultrasharp(); + }, ]; }); } @@ -252,7 +292,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 1, + 'model_id' => function () { + return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); + }, 'assigned_to' => \App\Models\User::factory()->create()->id, 'assigned_type' => \App\Models\User::class, ]; @@ -263,7 +305,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 1, + 'model_id' => function () { + return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); + }, 'assigned_to' => \App\Models\Location::factory()->create()->id, 'assigned_type' => \App\Models\Location::class, ]; @@ -274,7 +318,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 1, + 'model_id' => function () { + return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); + }, 'assigned_to' => \App\Models\Asset::factory()->create()->id, 'assigned_type' => \App\Models\Asset::class, ]; @@ -285,7 +331,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 1, + 'model_id' => function () { + return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); + }, ]; }); } @@ -294,7 +342,9 @@ class AssetFactory extends Factory { return $this->state(function () { return [ - 'model_id' => 1, + 'model_id' => function () { + return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); + }, 'deleted_at' => $this->faker->dateTime(), ]; }); From 72a61783a30c5855a7119d022a21f6b869733c52 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 14 Mar 2023 14:59:34 -0700 Subject: [PATCH 10/52] Inline two relationships in asset maintenance factory --- database/factories/AssetMaintenanceFactory.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/database/factories/AssetMaintenanceFactory.php b/database/factories/AssetMaintenanceFactory.php index f9351f5188..0d33e9ea15 100644 --- a/database/factories/AssetMaintenanceFactory.php +++ b/database/factories/AssetMaintenanceFactory.php @@ -5,6 +5,7 @@ namespace Database\Factories; use App\Models\Asset; use App\Models\AssetModel; use App\Models\Category; +use App\Models\Supplier; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -33,12 +34,8 @@ class AssetMaintenanceFactory extends Factory public function definition() { return [ - 'asset_id' => function () { - return \App\Models\Asset::factory()->create()->id; - }, - 'supplier_id' => function () { - return \App\Models\Supplier::factory()->create()->id; - }, + 'asset_id' => Asset::factory(), + 'supplier_id' => Supplier::factory(), 'asset_maintenance_type' => $this->faker->randomElement(['maintenance', 'repair', 'upgrade']), 'title' => $this->faker->sentence, 'start_date' => $this->faker->date(), From fb789eb0488d8760120e3d674ba9be12295f0450 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 14 Mar 2023 17:51:20 -0700 Subject: [PATCH 11/52] Remove hard-coded depreciation_id in factories --- database/factories/AssetModelFactory.php | 73 ++++++++++++++++++------ 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index 2e88c40806..99b843adae 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Depreciation; use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -102,7 +103,9 @@ class AssetModelFactory extends Factory return Category::where('name', 'Laptops')->first() ?? Category::factory()->assetLaptopCategory(); }, 'eol' => '36', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'mbp.jpg', 'fieldset_id' => 2, ]; @@ -121,7 +124,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); }, 'eol' => '36', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'macbookair.jpg', 'fieldset_id' => 2, ]; @@ -140,7 +145,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Microsoft')->first() ?? Manufacturer::factory()->microsoft(); }, 'eol' => '36', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'surface.jpg', 'fieldset_id' => 2, ]; @@ -159,7 +166,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell(); }, 'eol' => '36', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'xps.jpg', 'fieldset_id' => 2, ]; @@ -178,7 +187,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Asus')->first() ?? Manufacturer::factory()->asus(); }, 'eol' => '36', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'zenbook.jpg', 'fieldset_id' => 2, ]; @@ -197,7 +208,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'HP')->first() ?? Manufacturer::factory()->hp(); }, 'eol' => '36', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'spectre.jpg', 'fieldset_id' => 2, ]; @@ -216,7 +229,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo(); }, 'eol' => '36', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'yoga.png', 'fieldset_id' => 2, ]; @@ -235,7 +250,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); }, 'eol' => '24', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'imacpro.jpg', 'fieldset_id' => 2, ]; @@ -254,7 +271,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo(); }, 'eol' => '24', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'lenovoi5.png', 'fieldset_id' => 2, ]; @@ -274,7 +293,9 @@ class AssetModelFactory extends Factory }, 'model_number' => '5040 (MRR81)', 'eol' => '24', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'optiplex.jpg', 'fieldset_id' => 2, ]; @@ -293,7 +314,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom(); }, 'eol' => '12', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'soundstation.jpg', ]; }); @@ -311,7 +334,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Polycom')->first() ?? Manufacturer::factory()->polycom(); }, 'eol' => '12', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'cx3000.png', ]; }); @@ -329,7 +354,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); }, 'eol' => '12', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'ipad.jpg', ]; }); @@ -347,7 +374,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Lenovo')->first() ?? Manufacturer::factory()->lenovo(); }, 'eol' => '12', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'tab3.png', ]; }); @@ -365,7 +394,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); }, 'eol' => '12', - 'depreciation_id' => 3, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Mobile Phone Depreciation')->first() ?? Depreciation::factory()->mobilePhones(); + }, 'image' => 'iphone11.jpeg', 'fieldset_id' => 1, ]; @@ -384,7 +415,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); }, 'eol' => '12', - 'depreciation_id' => 1, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); + }, 'image' => 'iphone12.jpeg', 'fieldset_id' => 1, ]; @@ -403,7 +436,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'LG')->first() ?? Manufacturer::factory()->lg(); }, 'eol' => '12', - 'depreciation_id' => 2, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Display Depreciation')->first() ?? Depreciation::factory()->display(); + }, 'image' => 'ultrafine.jpg', ]; }); @@ -421,7 +456,9 @@ class AssetModelFactory extends Factory return Manufacturer::where('name', 'Dell')->first() ?? Manufacturer::factory()->dell(); }, 'eol' => '12', - 'depreciation_id' => 2, + 'depreciation_id' => function () { + return Depreciation::where('name', 'Display Depreciation')->first() ?? Depreciation::factory()->display(); + }, 'image' => 'ultrasharp.jpg', ]; }); From b94494537716738712b119c0f90460e50a2f0cd9 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 15 Mar 2023 14:12:34 -0700 Subject: [PATCH 12/52] Remove hard-coded company_id in factories and update seeders --- database/factories/ComponentFactory.php | 1 - database/factories/ConsumableFactory.php | 3 ++- database/factories/UserFactory.php | 3 ++- database/seeders/ComponentSeeder.php | 16 ++++++++++++---- database/seeders/UserSeeder.php | 18 +++++++++++++----- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/database/factories/ComponentFactory.php b/database/factories/ComponentFactory.php index 8dae9f1314..3c186e4442 100644 --- a/database/factories/ComponentFactory.php +++ b/database/factories/ComponentFactory.php @@ -59,7 +59,6 @@ class ComponentFactory extends Factory 'qty' => 10, 'min_amt' => 2, 'location_id' => 3, - 'company_id' => 2, ]; }); } diff --git a/database/factories/ConsumableFactory.php b/database/factories/ConsumableFactory.php index 2875d3d67a..c52ed35367 100644 --- a/database/factories/ConsumableFactory.php +++ b/database/factories/ConsumableFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use App\Models\Category; +use App\Models\Company; use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -42,6 +43,7 @@ class ConsumableFactory extends Factory 'purchase_cost' => $this->faker->randomFloat(2, 1, 50), 'qty' => $this->faker->numberBetween(5, 10), 'min_amt' => $this->faker->numberBetween($min = 1, $max = 2), + 'company_id' => Company::factory(), ]; } @@ -58,7 +60,6 @@ class ConsumableFactory extends Factory }, 'qty' => 10, 'min_amt' => 2, - 'company_id' => 3, ]; }); } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index bc23625749..91881d2b2d 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Company; use Illuminate\Database\Eloquent\Factories\Factory; use \Auth; @@ -18,7 +19,7 @@ class UserFactory extends Factory 'activated' => 1, 'address' => $this->faker->address(), 'city' => $this->faker->city(), - 'company_id' => rand(1, 4), + 'company_id' => Company::factory(), 'country' => $this->faker->country(), 'department_id' => rand(1, 6), 'email' => $this->faker->safeEmail, diff --git a/database/seeders/ComponentSeeder.php b/database/seeders/ComponentSeeder.php index 46380e1682..82488879bf 100644 --- a/database/seeders/ComponentSeeder.php +++ b/database/seeders/ComponentSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Models\Company; use App\Models\Component; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -12,9 +13,16 @@ class ComponentSeeder extends Seeder { Component::truncate(); DB::table('components_assets')->truncate(); - Component::factory()->count(1)->ramCrucial4()->create(); // 1 - Component::factory()->count(1)->ramCrucial8()->create(); // 1 - Component::factory()->count(1)->ssdCrucial120()->create(); // 1 - Component::factory()->count(1)->ssdCrucial240()->create(); // 1 + + if (! Company::count()) { + $this->call(CompanySeeder::class); + } + + $companyIds = Company::all()->pluck('id'); + + Component::factory()->ramCrucial4()->create(['company_id' => $companyIds->random()]); + Component::factory()->ramCrucial8()->create(['company_id' => $companyIds->random()]); + Component::factory()->ssdCrucial120()->create(['company_id' => $companyIds->random()]); + Component::factory()->ssdCrucial240()->create(['company_id' => $companyIds->random()]); } } diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 04f46e29b4..7b6ad44687 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Models\Company; use App\Models\User; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\Storage; @@ -17,11 +18,18 @@ class UserSeeder extends Seeder public function run() { User::truncate(); - User::factory()->count(1)->firstAdmin()->create(); - User::factory()->count(1)->snipeAdmin()->create(); - User::factory()->count(3)->superuser()->create(); - User::factory()->count(3)->admin()->create(); - User::factory()->count(50)->viewAssets()->create(); + + if (! Company::count()) { + $this->call(CompanySeeder::class); + } + + $companyIds = Company::all()->pluck('id'); + + User::factory()->count(1)->firstAdmin()->create(['company_id' => $companyIds->random()]); + User::factory()->count(1)->snipeAdmin()->create(['company_id' => $companyIds->random()]); + User::factory()->count(3)->superuser()->create(['company_id' => $companyIds->random()]); + User::factory()->count(3)->admin()->create(['company_id' => $companyIds->random()]); + User::factory()->count(50)->viewAssets()->create(['company_id' => $companyIds->random()]); $src = public_path('/img/demo/avatars/'); $dst = 'avatars'.'/'; From dfd6cf0d29fd717e200562ad7f6966ee6a4a77c0 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 15 Mar 2023 18:31:08 -0700 Subject: [PATCH 13/52] Improve factories for location relationships --- database/factories/AccessoryFactory.php | 3 +- database/factories/AssetFactory.php | 4 +- database/factories/ComponentFactory.php | 6 +-- database/factories/DepartmentFactory.php | 3 +- database/factories/LocationFactory.php | 2 - database/seeders/AccessorySeeder.php | 16 ++++++-- database/seeders/ActionlogSeeder.php | 2 - database/seeders/AssetSeeder.php | 48 ++++++++++++++---------- database/seeders/ComponentSeeder.php | 27 +++++++++++-- database/seeders/DepartmentSeeder.php | 20 +++++++--- 10 files changed, 85 insertions(+), 46 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index d47ac401ec..20b415655b 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use App\Models\Category; +use App\Models\Location; use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -37,7 +38,7 @@ class AccessoryFactory extends Factory return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, 'model_number' => $this->faker->numberBetween(1000000, 50000000), - 'location_id' => rand(1, 5), + 'location_id' => Location::factory(), ]; } diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 7d699c0ae0..25c8b7a780 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -308,8 +308,8 @@ class AssetFactory extends Factory 'model_id' => function () { return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); }, - 'assigned_to' => \App\Models\Location::factory()->create()->id, - 'assigned_type' => \App\Models\Location::class, + 'assigned_to' => Location::factory(), + 'assigned_type' => Location::class, ]; }); } diff --git a/database/factories/ComponentFactory.php b/database/factories/ComponentFactory.php index 3c186e4442..2f4972fa81 100644 --- a/database/factories/ComponentFactory.php +++ b/database/factories/ComponentFactory.php @@ -35,9 +35,7 @@ class ComponentFactory extends Factory return [ 'name' => $this->faker->text(20), 'category_id' => Category::factory(), - 'location_id' => function () { - return Location::first() ?? Location::factory(); - }, + 'location_id' => Location::factory(), 'serial' => $this->faker->uuid, 'qty' => $this->faker->numberBetween(3, 10), 'order_number' => $this->faker->numberBetween(1000000, 50000000), @@ -58,7 +56,7 @@ class ComponentFactory extends Factory }, 'qty' => 10, 'min_amt' => 2, - 'location_id' => 3, + 'location_id' => Location::factory(), ]; }); } diff --git a/database/factories/DepartmentFactory.php b/database/factories/DepartmentFactory.php index c8e14c0235..8d10c606cc 100644 --- a/database/factories/DepartmentFactory.php +++ b/database/factories/DepartmentFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Location; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -34,7 +35,7 @@ class DepartmentFactory extends Factory 'user_id' => function () { return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, - 'location_id' => rand(1, 5), + 'location_id' => Location::factory(), ]; } diff --git a/database/factories/LocationFactory.php b/database/factories/LocationFactory.php index f6a4bb973b..6db268e8c1 100644 --- a/database/factories/LocationFactory.php +++ b/database/factories/LocationFactory.php @@ -23,8 +23,6 @@ class LocationFactory extends Factory 'currency' => $this->faker->currencyCode(), 'zip' => $this->faker->postcode(), 'image' => rand(1, 9).'.jpg', - ]; } - } diff --git a/database/seeders/AccessorySeeder.php b/database/seeders/AccessorySeeder.php index 6c4123c08b..0b31dc763d 100644 --- a/database/seeders/AccessorySeeder.php +++ b/database/seeders/AccessorySeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Accessory; +use App\Models\Location; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -14,10 +15,17 @@ class AccessorySeeder extends Seeder { Accessory::truncate(); DB::table('accessories_users')->truncate(); - Accessory::factory()->count(1)->appleUsbKeyboard()->create(); - Accessory::factory()->count(1)->appleBtKeyboard()->create(); - Accessory::factory()->count(1)->appleMouse()->create(); - Accessory::factory()->count(1)->microsoftMouse()->create(); + + if (! Location::count()) { + $this->call(LocationSeeder::class); + } + + $locationIds = Location::all()->pluck('id'); + + Accessory::factory()->count(1)->appleUsbKeyboard()->create(['location_id' => $locationIds->random()]); + Accessory::factory()->count(1)->appleBtKeyboard()->create(['location_id' => $locationIds->random()]); + Accessory::factory()->count(1)->appleMouse()->create(['location_id' => $locationIds->random()]); + Accessory::factory()->count(1)->microsoftMouse()->create(['location_id' => $locationIds->random()]); $src = public_path('/img/demo/accessories/'); $dst = 'accessories'.'/'; diff --git a/database/seeders/ActionlogSeeder.php b/database/seeders/ActionlogSeeder.php index 06eb27bdeb..6ff0645d20 100644 --- a/database/seeders/ActionlogSeeder.php +++ b/database/seeders/ActionlogSeeder.php @@ -12,7 +12,5 @@ class ActionlogSeeder extends Seeder Actionlog::truncate(); Actionlog::factory()->count(300)->assetCheckoutToUser()->create(); Actionlog::factory()->count(100)->assetCheckoutToLocation()->create(); - - } } diff --git a/database/seeders/AssetSeeder.php b/database/seeders/AssetSeeder.php index c5ea479a34..b2346fe653 100644 --- a/database/seeders/AssetSeeder.php +++ b/database/seeders/AssetSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Asset; +use App\Models\Location; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -13,31 +14,38 @@ class AssetSeeder extends Seeder public function run() { Asset::truncate(); - Asset::factory()->count(1000)->laptopMbp()->create(); - Asset::factory()->count(50)->laptopMbpPending()->create(); - Asset::factory()->count(50)->laptopMbpArchived()->create(); - Asset::factory()->count(50)->laptopAir()->create(); - Asset::factory()->count(5)->laptopSurface()->create(); - Asset::factory()->count(5)->laptopXps()->create(); - Asset::factory()->count(5)->laptopSpectre()->create(); - Asset::factory()->count(5)->laptopZenbook()->create(); - Asset::factory()->count(3)->laptopYoga()->create(); - Asset::factory()->count(30)->desktopMacpro()->create(); - Asset::factory()->count(30)->desktopLenovoI5()->create(); - Asset::factory()->count(30)->desktopOptiplex()->create(); + if (! Location::count()) { + $this->call(LocationSeeder::class); + } - Asset::factory()->count(5)->confPolycom()->create(); - Asset::factory()->count(2)->confPolycomcx()->create(); + $locationIds = Location::all()->pluck('id'); - Asset::factory()->count(12)->tabletIpad()->create(); - Asset::factory()->count(4)->tabletTab3()->create(); + Asset::factory()->count(1000)->laptopMbp()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(50)->laptopMbpPending()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(50)->laptopMbpArchived()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(50)->laptopAir()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(5)->laptopSurface()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(5)->laptopXps()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(5)->laptopSpectre()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(5)->laptopZenbook()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(3)->laptopYoga()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(27)->phoneIphone11()->create(); - Asset::factory()->count(40)->phoneIphone12()->create(); + Asset::factory()->count(30)->desktopMacpro()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(30)->desktopLenovoI5()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(30)->desktopOptiplex()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(10)->ultrafine()->create(); - Asset::factory()->count(10)->ultrasharp()->create(); + Asset::factory()->count(5)->confPolycom()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(2)->confPolycomcx()->create(['rtd_location_id' => $locationIds->random()]); + + Asset::factory()->count(12)->tabletIpad()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(4)->tabletTab3()->create(['rtd_location_id' => $locationIds->random()]); + + Asset::factory()->count(27)->phoneIphone11()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(40)->phoneIphone12()->create(['rtd_location_id' => $locationIds->random()]); + + Asset::factory()->count(10)->ultrafine()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(10)->ultrasharp()->create(['rtd_location_id' => $locationIds->random()]); $del_files = Storage::files('assets'); foreach ($del_files as $del_file) { // iterate files diff --git a/database/seeders/ComponentSeeder.php b/database/seeders/ComponentSeeder.php index 82488879bf..5a80243466 100644 --- a/database/seeders/ComponentSeeder.php +++ b/database/seeders/ComponentSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\Company; use App\Models\Component; +use App\Models\Location; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -20,9 +21,27 @@ class ComponentSeeder extends Seeder $companyIds = Company::all()->pluck('id'); - Component::factory()->ramCrucial4()->create(['company_id' => $companyIds->random()]); - Component::factory()->ramCrucial8()->create(['company_id' => $companyIds->random()]); - Component::factory()->ssdCrucial120()->create(['company_id' => $companyIds->random()]); - Component::factory()->ssdCrucial240()->create(['company_id' => $companyIds->random()]); + 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(), + ]); } } diff --git a/database/seeders/DepartmentSeeder.php b/database/seeders/DepartmentSeeder.php index f82e355edd..df3523456b 100644 --- a/database/seeders/DepartmentSeeder.php +++ b/database/seeders/DepartmentSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Department; +use App\Models\Location; use Illuminate\Database\Seeder; class DepartmentSeeder extends Seeder @@ -10,11 +11,18 @@ class DepartmentSeeder extends Seeder public function run() { Department::truncate(); - Department::factory()->count(1)->hr()->create(); // 1 - Department::factory()->count(1)->engineering()->create(); // 2 - Department::factory()->count(1)->marketing()->create(); // 3 - Department::factory()->count(1)->client()->create(); // 4 - Department::factory()->count(1)->product()->create(); // 5 - Department::factory()->count(1)->silly()->create(); // 6 + + if (! Location::count()) { + $this->call(LocationSeeder::class); + } + + $locationIds = Location::all()->pluck('id'); + + Department::factory()->count(1)->hr()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->engineering()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->marketing()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->client()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->product()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->silly()->create(['location_id' => $locationIds->random()]); } } From 0ec885bf1833e8d8f6ee72733ae009bd0eab0e66 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 15 Mar 2023 18:49:21 -0700 Subject: [PATCH 14/52] Remove hard-coded fieldset_id in factories --- database/factories/AssetModelFactory.php | 51 ++++++++++++++++++------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index 99b843adae..6a7da364fc 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -2,7 +2,10 @@ namespace Database\Factories; +use App\Models\AssetMaintenance; +use App\Models\CustomFieldset; use App\Models\Depreciation; +use App\Models\Import; use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -107,7 +110,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'mbp.jpg', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -128,7 +133,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'macbookair.jpg', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -149,7 +156,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'surface.jpg', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -170,7 +179,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'xps.jpg', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -191,7 +202,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'zenbook.jpg', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -212,7 +225,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'spectre.jpg', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -233,7 +248,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'yoga.png', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -254,7 +271,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'imacpro.jpg', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -275,7 +294,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'lenovoi5.png', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -297,7 +318,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'optiplex.jpg', - 'fieldset_id' => 2, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Laptops and Desktops')->first() ?? CustomFieldset::factory()->computer(); + }, ]; }); } @@ -398,7 +421,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Mobile Phone Depreciation')->first() ?? Depreciation::factory()->mobilePhones(); }, 'image' => 'iphone11.jpeg', - 'fieldset_id' => 1, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Mobile Devices')->first() ?? CustomFieldset::factory()->mobile(); + }, ]; }); } @@ -419,7 +444,9 @@ class AssetModelFactory extends Factory return Depreciation::where('name', 'Computer Depreciation')->first() ?? Depreciation::factory()->computer(); }, 'image' => 'iphone12.jpeg', - 'fieldset_id' => 1, + 'fieldset_id' => function () { + return CustomFieldset::where('name', 'Mobile Devices')->first() ?? CustomFieldset::factory()->mobile(); + }, ]; }); } From 7062b0acaad3e1e027265f476e804f7d4c12d619 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 12:41:34 -0700 Subject: [PATCH 15/52] Remove hard-coded supplier_id in factories --- database/factories/AccessoryFactory.php | 7 +- database/factories/LicenseFactory.php | 3 +- database/seeders/AccessorySeeder.php | 27 +++++- database/seeders/AssetSeeder.php | 107 +++++++++++++++++++----- database/seeders/LicenseSeeder.php | 16 +++- 5 files changed, 128 insertions(+), 32 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index 20b415655b..e9c90acd9c 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -5,6 +5,7 @@ namespace Database\Factories; use App\Models\Category; use App\Models\Location; use App\Models\Manufacturer; +use App\Models\Supplier; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -56,7 +57,7 @@ class AccessoryFactory extends Factory }, 'qty' => 10, 'min_amt' => 2, - 'supplier_id' => rand(1, 5), + 'supplier_id' => Supplier::factory(), ]; }); } @@ -75,7 +76,7 @@ class AccessoryFactory extends Factory }, 'qty' => 15, 'min_amt' => 2, - 'supplier_id' => rand(1, 5), + 'supplier_id' => Supplier::factory(), ]; }); } @@ -94,7 +95,7 @@ class AccessoryFactory extends Factory }, 'qty' => 13, 'min_amt' => 2, - 'supplier_id' => rand(1, 5), + 'supplier_id' => Supplier::factory(), ]; }); } diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index 418e296b6c..8a7a4ee770 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use App\Models\Category; use App\Models\Manufacturer; +use App\Models\Supplier; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -55,7 +56,7 @@ class LicenseFactory extends Factory 'expiration_date' => $this->faker->dateTimeBetween('now', '+3 years', date_default_timezone_get())->format('Y-m-d H:i:s'), 'reassignable' => $this->faker->boolean(), 'termination_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d H:i:s'), - 'supplier_id' => $this->faker->numberBetween(1, 5), + 'supplier_id' => Supplier::factory(), 'category_id' => Category::where('category_type', '=', 'license')->inRandomOrder()->first()->id ]; } diff --git a/database/seeders/AccessorySeeder.php b/database/seeders/AccessorySeeder.php index 0b31dc763d..1e21e60f6c 100644 --- a/database/seeders/AccessorySeeder.php +++ b/database/seeders/AccessorySeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\Accessory; use App\Models\Location; +use App\Models\Supplier; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -22,10 +23,28 @@ class AccessorySeeder extends Seeder $locationIds = Location::all()->pluck('id'); - Accessory::factory()->count(1)->appleUsbKeyboard()->create(['location_id' => $locationIds->random()]); - Accessory::factory()->count(1)->appleBtKeyboard()->create(['location_id' => $locationIds->random()]); - Accessory::factory()->count(1)->appleMouse()->create(['location_id' => $locationIds->random()]); - Accessory::factory()->count(1)->microsoftMouse()->create(['location_id' => $locationIds->random()]); + if (! Supplier::count()) { + $this->call(SupplierSeeder::class); + } + + $supplierIds = Supplier::all()->pluck('id'); + + Accessory::factory()->count(1)->appleUsbKeyboard()->create([ + 'location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Accessory::factory()->count(1)->appleBtKeyboard()->create([ + 'location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Accessory::factory()->count(1)->appleMouse()->create([ + 'location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Accessory::factory()->count(1)->microsoftMouse()->create([ + 'location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); $src = public_path('/img/demo/accessories/'); $dst = 'accessories'.'/'; diff --git a/database/seeders/AssetSeeder.php b/database/seeders/AssetSeeder.php index b2346fe653..555654186c 100644 --- a/database/seeders/AssetSeeder.php +++ b/database/seeders/AssetSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\Asset; use App\Models\Location; +use App\Models\Supplier; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -21,31 +22,97 @@ class AssetSeeder extends Seeder $locationIds = Location::all()->pluck('id'); - Asset::factory()->count(1000)->laptopMbp()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(50)->laptopMbpPending()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(50)->laptopMbpArchived()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(50)->laptopAir()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(5)->laptopSurface()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(5)->laptopXps()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(5)->laptopSpectre()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(5)->laptopZenbook()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(3)->laptopYoga()->create(['rtd_location_id' => $locationIds->random()]); + if (! Supplier::count()) { + $this->call(SupplierSeeder::class); + } - Asset::factory()->count(30)->desktopMacpro()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(30)->desktopLenovoI5()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(30)->desktopOptiplex()->create(['rtd_location_id' => $locationIds->random()]); + $supplierIds = Supplier::all()->pluck('id'); - Asset::factory()->count(5)->confPolycom()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(2)->confPolycomcx()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(1000)->laptopMbp()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(50)->laptopMbpPending()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(50)->laptopMbpArchived()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(50)->laptopAir()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(5)->laptopSurface()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(5)->laptopXps()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(5)->laptopSpectre()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(5)->laptopZenbook()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(3)->laptopYoga()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); - Asset::factory()->count(12)->tabletIpad()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(4)->tabletTab3()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(30)->desktopMacpro()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(30)->desktopLenovoI5()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(30)->desktopOptiplex()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); - Asset::factory()->count(27)->phoneIphone11()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(40)->phoneIphone12()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(5)->confPolycom()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(2)->confPolycomcx()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); - Asset::factory()->count(10)->ultrafine()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(10)->ultrasharp()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(12)->tabletIpad()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(4)->tabletTab3()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + + Asset::factory()->count(27)->phoneIphone11()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(40)->phoneIphone12()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + + Asset::factory()->count(10)->ultrafine()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(10)->ultrasharp()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); $del_files = Storage::files('assets'); foreach ($del_files as $del_file) { // iterate files diff --git a/database/seeders/LicenseSeeder.php b/database/seeders/LicenseSeeder.php index 843eeb42f1..88fad2879e 100644 --- a/database/seeders/LicenseSeeder.php +++ b/database/seeders/LicenseSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\License; use App\Models\LicenseSeat; +use App\Models\Supplier; use Illuminate\Database\Seeder; class LicenseSeeder extends Seeder @@ -12,9 +13,16 @@ class LicenseSeeder extends Seeder { License::truncate(); LicenseSeat::truncate(); - License::factory()->count(1)->photoshop()->create(); - License::factory()->count(1)->acrobat()->create(); - License::factory()->count(1)->indesign()->create(); - License::factory()->count(1)->office()->create(); + + if (! Supplier::count()) { + $this->call(SupplierSeeder::class); + } + + $supplierIds = Supplier::all()->pluck('id'); + + License::factory()->count(1)->photoshop()->create(['supplier_id' => $supplierIds->random()]); + License::factory()->count(1)->acrobat()->create(['supplier_id' => $supplierIds->random()]); + License::factory()->count(1)->indesign()->create(['supplier_id' => $supplierIds->random()]); + License::factory()->count(1)->office()->create(['supplier_id' => $supplierIds->random()]); } } From 76861c0c30a154a01db06c188d82f12daeed3030 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 12:46:47 -0700 Subject: [PATCH 16/52] Remove hard-coded manager_id in factory --- database/factories/UserFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 91881d2b2d..c99354648c 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use App\Models\Company; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use \Auth; @@ -79,7 +80,9 @@ class UserFactory extends Factory return $this->state(function () { return [ 'permissions' => '{"admin":"1"}', - 'manager_id' => rand(1, 2), + 'manager_id' => function () { + return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); + }, ]; }); } From 345946d6d47d3dae4ca95890ff5b89afbaa6bd70 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 13:25:02 -0700 Subject: [PATCH 17/52] Remove default department relationship from user factory --- database/factories/UserFactory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index c99354648c..aaed569679 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -22,7 +22,6 @@ class UserFactory extends Factory 'city' => $this->faker->city(), 'company_id' => Company::factory(), 'country' => $this->faker->country(), - 'department_id' => rand(1, 6), 'email' => $this->faker->safeEmail, 'employee_num' => $this->faker->numberBetween(3500, 35050), 'first_name' => $this->faker->firstName(), From a98cc01766e96824c76bb8b34009219454ded4b2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 13:25:35 -0700 Subject: [PATCH 18/52] Seed users with departments --- database/seeders/DatabaseSeeder.php | 2 +- database/seeders/UserSeeder.php | 47 ++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 54fb1e088b..3507a106ef 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -38,9 +38,9 @@ class DatabaseSeeder extends Seeder $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(DepartmentSeeder::class); $this->call(ManufacturerSeeder::class); $this->call(SupplierSeeder::class); $this->call(AssetModelSeeder::class); diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 7b6ad44687..2eba6f3721 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -3,7 +3,9 @@ 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; @@ -25,11 +27,46 @@ class UserSeeder extends Seeder $companyIds = Company::all()->pluck('id'); - User::factory()->count(1)->firstAdmin()->create(['company_id' => $companyIds->random()]); - User::factory()->count(1)->snipeAdmin()->create(['company_id' => $companyIds->random()]); - User::factory()->count(3)->superuser()->create(['company_id' => $companyIds->random()]); - User::factory()->count(3)->admin()->create(['company_id' => $companyIds->random()]); - User::factory()->count(50)->viewAssets()->create(['company_id' => $companyIds->random()]); + 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(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'.'/'; From 2f0f9586b1840651e1f724ebb3b3ff1191386040 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 13:46:30 -0700 Subject: [PATCH 19/52] Remove default category relationship from license factory --- database/factories/LicenseFactory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index 8a7a4ee770..cc58d58c9f 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -57,7 +57,6 @@ class LicenseFactory extends Factory 'reassignable' => $this->faker->boolean(), 'termination_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d H:i:s'), 'supplier_id' => Supplier::factory(), - 'category_id' => Category::where('category_type', '=', 'license')->inRandomOrder()->first()->id ]; } From 31630e3677e61a85b6f494d68488c45c6e86d2e5 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 13:47:02 -0700 Subject: [PATCH 20/52] Seed licenses with categories --- database/seeders/LicenseSeeder.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/database/seeders/LicenseSeeder.php b/database/seeders/LicenseSeeder.php index 88fad2879e..3b2c7f16cc 100644 --- a/database/seeders/LicenseSeeder.php +++ b/database/seeders/LicenseSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Models\Category; use App\Models\License; use App\Models\LicenseSeat; use App\Models\Supplier; @@ -14,15 +15,33 @@ class LicenseSeeder extends Seeder 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'); - License::factory()->count(1)->photoshop()->create(['supplier_id' => $supplierIds->random()]); - License::factory()->count(1)->acrobat()->create(['supplier_id' => $supplierIds->random()]); - License::factory()->count(1)->indesign()->create(['supplier_id' => $supplierIds->random()]); - License::factory()->count(1)->office()->create(['supplier_id' => $supplierIds->random()]); + License::factory()->count(1)->photoshop()->create([ + 'category_id' => $categoryIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + License::factory()->count(1)->acrobat()->create([ + 'category_id' => $categoryIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + License::factory()->count(1)->indesign()->create([ + 'category_id' => $categoryIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + License::factory()->count(1)->office()->create([ + 'category_id' => $categoryIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); } } From daf6e9fa4bd550bedb107ca13a3628ef3658e638 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 14:23:40 -0700 Subject: [PATCH 21/52] Seed assets with randomized locations --- database/seeders/AssetSeeder.php | 259 +++++++++++++++++++++---------- 1 file changed, 177 insertions(+), 82 deletions(-) diff --git a/database/seeders/AssetSeeder.php b/database/seeders/AssetSeeder.php index 555654186c..1b0ca71a4e 100644 --- a/database/seeders/AssetSeeder.php +++ b/database/seeders/AssetSeeder.php @@ -5,6 +5,7 @@ namespace Database\Seeders; use App\Models\Asset; use App\Models\Location; use App\Models\Supplier; +use Illuminate\Database\Eloquent\Factories\Sequence; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -28,97 +29,191 @@ class AssetSeeder extends Seeder $supplierIds = Supplier::all()->pluck('id'); - Asset::factory()->count(1000)->laptopMbp()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(50)->laptopMbpPending()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(50)->laptopMbpArchived()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(50)->laptopAir()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(5)->laptopSurface()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(5)->laptopXps()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(5)->laptopSpectre()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(5)->laptopZenbook()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(3)->laptopYoga()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); + Asset::factory() + ->count(1000) + ->laptopMbp() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); - Asset::factory()->count(30)->desktopMacpro()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(30)->desktopLenovoI5()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(30)->desktopOptiplex()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); + Asset::factory() + ->count(50) + ->laptopMbpPending() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); - Asset::factory()->count(5)->confPolycom()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(2)->confPolycomcx()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); + Asset::factory() + ->count(50) + ->laptopMbpArchived() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); - Asset::factory()->count(12)->tabletIpad()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(4)->tabletTab3()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); + Asset::factory() + ->count(50) + ->laptopAir() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); - Asset::factory()->count(27)->phoneIphone11()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(40)->phoneIphone12()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); + Asset::factory() + ->count(5) + ->laptopSurface() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); - Asset::factory()->count(10)->ultrafine()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); - Asset::factory()->count(10)->ultrasharp()->create([ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ]); + Asset::factory() + ->count(5) + ->laptopXps() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(5) + ->laptopSpectre() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(5) + ->laptopZenbook() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(3) + ->laptopYoga() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(30) + ->desktopMacpro() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(30) + ->desktopLenovoI5() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(30) + ->desktopOptiplex() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(5) + ->confPolycom() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(2) + ->confPolycomcx() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(12) + ->tabletIpad() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(4) + ->tabletTab3() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(27) + ->phoneIphone11() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(40) + ->phoneIphone12() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(10) + ->ultrafine() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); + + Asset::factory() + ->count(10) + ->ultrasharp() + ->state(new Sequence(fn($sequence) => [ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ])) + ->create(); $del_files = Storage::files('assets'); foreach ($del_files as $del_file) { // iterate files - Log::debug('Deleting: '.$del_files); + Log::debug('Deleting: ' . $del_files); try { - Storage::disk('public')->delete('assets'.'/'.$del_files); + Storage::disk('public')->delete('assets' . '/' . $del_files); } catch (\Exception $e) { Log::debug($e); } From a50ddb4a5d10a2931ec20ab246874856730e7fd4 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 15:25:23 -0700 Subject: [PATCH 22/52] Improve actionlog factory and seeder --- database/factories/ActionlogFactory.php | 49 ++++++++++--------------- database/seeders/ActionlogSeeder.php | 22 ++++++++++- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/database/factories/ActionlogFactory.php b/database/factories/ActionlogFactory.php index ea4f4bfc7a..6fdd53c65e 100644 --- a/database/factories/ActionlogFactory.php +++ b/database/factories/ActionlogFactory.php @@ -4,7 +4,6 @@ namespace Database\Factories; use App\Models\Actionlog; use App\Models\Asset; -use App\Models\Company; use App\Models\Location; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -25,7 +24,7 @@ class ActionlogFactory extends Factory * * @var string */ - protected $model = \App\Models\Actionlog::class; + protected $model = Actionlog::class; /** * Define the model's default state. @@ -34,10 +33,9 @@ class ActionlogFactory extends Factory */ public function definition() { - $asset = \App\Models\Asset::factory()->create(); return [ - 'item_type' => get_class($asset), - 'item_id' => 1, + 'item_id' => Asset::factory(), + 'item_type' => Asset::class, 'user_id' => function () { return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, @@ -45,62 +43,53 @@ class ActionlogFactory extends Factory ]; } - public function assetCheckoutToUser() { return $this->state(function () { - $target = \App\Models\User::inRandomOrder()->first(); - $item = \App\Models\Asset::RTD()->inRandomOrder()->first(); - $user_id = rand(1, 2); // keep it simple - make it one of the two superadmins - $asset = Asset::where('id', $item->id) - ->update( + $target = User::inRandomOrder()->first(); + $asset = Asset::RTD()->inRandomOrder()->first(); + + $asset->update( [ 'assigned_to' => $target->id, - 'assigned_type' => \App\Models\User::class, + 'assigned_type' => User::class, 'location_id' => $target->location_id, ] ); return [ 'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()), - 'user_id' => $user_id, 'action_type' => 'checkout', - 'item_id' => $item->id, - 'item_type' => \App\Models\Asset::class, + 'item_id' => $asset->id, + 'item_type' => Asset::class, 'target_id' => $target->id, - 'target_type' => get_class($target), - + 'target_type' => User::class, ]; }); } - public function assetCheckoutToLocation() { return $this->state(function () { - $target = \App\Models\Location::inRandomOrder()->first(); - $item = \App\Models\Asset::inRandomOrder()->RTD()->first(); - $user_id = rand(1, 2); // keep it simple - make it one of the two superadmins - $asset = \App\Models\Asset::where('id', $item->id) - ->update( + $target = Location::inRandomOrder()->first(); + $asset = Asset::inRandomOrder()->RTD()->first(); + + $asset->update( [ 'assigned_to' => $target->id, - 'assigned_type' => \App\Models\Location::class, + 'assigned_type' => Location::class, 'location_id' => $target->id, ] ); return [ 'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()), - 'user_id' => $user_id, 'action_type' => 'checkout', - 'item_id' => $item->id, - 'item_type' => \App\Models\Asset::class, + 'item_id' => $asset->id, + 'item_type' => Asset::class, 'target_id' => $target->id, - 'target_type' => get_class($target), + 'target_type' => Location::class, ]; }); } - - } diff --git a/database/seeders/ActionlogSeeder.php b/database/seeders/ActionlogSeeder.php index 6ff0645d20..b680b87b35 100644 --- a/database/seeders/ActionlogSeeder.php +++ b/database/seeders/ActionlogSeeder.php @@ -3,6 +3,8 @@ namespace Database\Seeders; use App\Models\Actionlog; +use App\Models\Asset; +use App\Models\Location; use Illuminate\Database\Seeder; class ActionlogSeeder extends Seeder @@ -10,7 +12,23 @@ class ActionlogSeeder extends Seeder public function run() { Actionlog::truncate(); - Actionlog::factory()->count(300)->assetCheckoutToUser()->create(); - Actionlog::factory()->count(100)->assetCheckoutToLocation()->create(); + + if (! Asset::count()) { + $this->call(AssetSeeder::class); + } + + if (! Location::count()) { + $this->call(LocationSeeder::class); + } + + Actionlog::factory() + ->count(300) + ->assetCheckoutToUser() + ->create(); + + Actionlog::factory() + ->count(100) + ->assetCheckoutToLocation() + ->create(); } } From ca677038b0bf2f8e4277dbee4ab9a2eee3cb4621 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 15:39:02 -0700 Subject: [PATCH 23/52] Remove unused methods --- database/factories/AssetFactory.php | 67 +++++++++++++---------------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 25c8b7a780..fd8739915b 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -288,44 +288,35 @@ class AssetFactory extends Factory }); } - public function assignedToUser() - { - return $this->state(function () { - return [ - 'model_id' => function () { - return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); - }, - 'assigned_to' => \App\Models\User::factory()->create()->id, - 'assigned_type' => \App\Models\User::class, - ]; - }); - } - - public function assignedToLocation() - { - return $this->state(function () { - return [ - 'model_id' => function () { - return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); - }, - 'assigned_to' => Location::factory(), - 'assigned_type' => Location::class, - ]; - }); - } - - public function assignedToAsset() - { - return $this->state(function () { - return [ - 'model_id' => function () { - return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); - }, - 'assigned_to' => \App\Models\Asset::factory()->create()->id, - 'assigned_type' => \App\Models\Asset::class, - ]; - }); - } + // public function assignedToUser() + // { + // return $this->state(function () { + // return [ + // 'assigned_to' => User::factory(), + // 'assigned_type' => User::class, + // ]; + // }); + // } + // + // public function assignedToLocation() + // { + // return $this->state(function () { + // return [ + // 'assigned_to' => Location::factory(), + // 'assigned_type' => Location::class, + // ]; + // }); + // } + // + // public function assignedToAsset() + // { + // return $this->state(function () { + // return [ + // 'assigned_to' => Asset::factory(), + // 'assigned_type' => Asset::class, + // ]; + // }); + // } public function requiresAcceptance() { From f47a28f7903c9b88fe9575cd93edfa15b91b3ef0 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 15:40:16 -0700 Subject: [PATCH 24/52] Actually remove unused methods --- database/factories/AssetFactory.php | 30 ----------------------------- 1 file changed, 30 deletions(-) diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index fd8739915b..c269d77e36 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -288,36 +288,6 @@ class AssetFactory extends Factory }); } - // public function assignedToUser() - // { - // return $this->state(function () { - // return [ - // 'assigned_to' => User::factory(), - // 'assigned_type' => User::class, - // ]; - // }); - // } - // - // public function assignedToLocation() - // { - // return $this->state(function () { - // return [ - // 'assigned_to' => Location::factory(), - // 'assigned_type' => Location::class, - // ]; - // }); - // } - // - // public function assignedToAsset() - // { - // return $this->state(function () { - // return [ - // 'assigned_to' => Asset::factory(), - // 'assigned_type' => Asset::class, - // ]; - // }); - // } - public function requiresAcceptance() { return $this->state(function () { From 582c3b987b5ff5b6224456561baa5c662de983df Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 16:38:21 -0700 Subject: [PATCH 25/52] Update some faker calls --- database/factories/CompanyFactory.php | 2 +- database/factories/UserFactory.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php index 695a2dbdb5..00dcf911c1 100644 --- a/database/factories/CompanyFactory.php +++ b/database/factories/CompanyFactory.php @@ -39,7 +39,7 @@ class CompanyFactory extends Factory public function definition() { return [ - 'name' => $this->faker->company, + 'name' => $this->faker->company(), ]; } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index aaed569679..f40301753b 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -22,7 +22,7 @@ class UserFactory extends Factory 'city' => $this->faker->city(), 'company_id' => Company::factory(), 'country' => $this->faker->country(), - 'email' => $this->faker->safeEmail, + 'email' => $this->faker->safeEmail(), 'employee_num' => $this->faker->numberBetween(3500, 35050), 'first_name' => $this->faker->firstName(), 'jobtitle' => $this->faker->jobTitle(), @@ -31,10 +31,10 @@ class UserFactory extends Factory 'notes' => 'Created by DB seeder', 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 'permissions' => '{"user":"0"}', - 'phone' => $this->faker->phoneNumber, - 'state' => $this->faker->stateAbbr, - 'username' => $this->faker->username, - 'zip' => $this->faker->postcode, + 'phone' => $this->faker->phoneNumber(), + 'state' => $this->faker->stateAbbr(), + 'username' => $this->faker->username(), + 'zip' => $this->faker->postcode(), ]; } From d9c1a548f1609e2014c9244322492e25ddf6ab89 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 17:07:46 -0700 Subject: [PATCH 26/52] Update deprecated faker calls --- database/factories/AssetMaintenanceFactory.php | 2 +- database/factories/ComponentFactory.php | 2 +- database/factories/CustomFieldFactory.php | 2 +- database/factories/CustomFieldsetFactory.php | 2 +- database/factories/GroupFactory.php | 2 +- database/factories/LicenseFactory.php | 6 +++--- database/factories/SettingFactory.php | 4 ++-- database/factories/StatuslabelFactory.php | 6 +++--- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/database/factories/AssetMaintenanceFactory.php b/database/factories/AssetMaintenanceFactory.php index 0d33e9ea15..1cf7c0d844 100644 --- a/database/factories/AssetMaintenanceFactory.php +++ b/database/factories/AssetMaintenanceFactory.php @@ -37,7 +37,7 @@ class AssetMaintenanceFactory extends Factory 'asset_id' => Asset::factory(), 'supplier_id' => Supplier::factory(), 'asset_maintenance_type' => $this->faker->randomElement(['maintenance', 'repair', 'upgrade']), - 'title' => $this->faker->sentence, + 'title' => $this->faker->sentence(), 'start_date' => $this->faker->date(), 'is_warranty' => $this->faker->boolean(), 'notes' => $this->faker->paragraph(), diff --git a/database/factories/ComponentFactory.php b/database/factories/ComponentFactory.php index 2f4972fa81..23705a573d 100644 --- a/database/factories/ComponentFactory.php +++ b/database/factories/ComponentFactory.php @@ -36,7 +36,7 @@ class ComponentFactory extends Factory 'name' => $this->faker->text(20), 'category_id' => Category::factory(), 'location_id' => Location::factory(), - 'serial' => $this->faker->uuid, + 'serial' => $this->faker->uuid(), 'qty' => $this->faker->numberBetween(3, 10), 'order_number' => $this->faker->numberBetween(1000000, 50000000), 'purchase_date' => $this->faker->dateTime()->format('Y-m-d'), diff --git a/database/factories/CustomFieldFactory.php b/database/factories/CustomFieldFactory.php index c964ea44d1..46ebe70ce9 100644 --- a/database/factories/CustomFieldFactory.php +++ b/database/factories/CustomFieldFactory.php @@ -21,7 +21,7 @@ class CustomFieldFactory extends Factory public function definition() { return [ - 'name' => $this->faker->catchPhrase, + 'name' => $this->faker->catchPhrase(), 'format' => '', 'element' => 'text', ]; diff --git a/database/factories/CustomFieldsetFactory.php b/database/factories/CustomFieldsetFactory.php index 1dd834d052..560775f3bc 100644 --- a/database/factories/CustomFieldsetFactory.php +++ b/database/factories/CustomFieldsetFactory.php @@ -21,7 +21,7 @@ class CustomFieldsetFactory extends Factory public function definition() { return [ - 'name' => $this->faker->catchPhrase, + 'name' => $this->faker->catchPhrase(), ]; } diff --git a/database/factories/GroupFactory.php b/database/factories/GroupFactory.php index 17f3493c2b..6fa4978e93 100644 --- a/database/factories/GroupFactory.php +++ b/database/factories/GroupFactory.php @@ -39,7 +39,7 @@ class GroupFactory extends Factory public function definition() { return [ - 'name' => $this->faker->name, + 'name' => $this->faker->name(), ]; } } diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index cc58d58c9f..b518de2c64 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -46,9 +46,9 @@ class LicenseFactory extends Factory 'user_id' => function () { return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, - 'name' => $this->faker->name, - 'license_email' => $this->faker->safeEmail, - 'serial' => $this->faker->uuid, + 'name' => $this->faker->name(), + 'license_email' => $this->faker->safeEmail(), + 'serial' => $this->faker->uuid(), 'notes' => 'Created by DB seeder', 'seats' => $this->faker->numberBetween(1, 10), 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index bae61a1abd..f08eb26c77 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -44,12 +44,12 @@ class SettingFactory extends Factory return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, 'per_page' => 20, - 'site_name' => $this->faker->sentence, + 'site_name' => $this->faker->sentence(), 'auto_increment_assets' => false, 'alert_email' => $this->faker->safeEmail(), 'alerts_enabled' => true, 'brand' => 1, - 'default_currency' => $this->faker->currencyCode, + 'default_currency' => $this->faker->currencyCode(), 'locale' => 'en', 'pwd_secure_min' => 10, // Match web setup 'email_domain' => 'test.com', diff --git a/database/factories/StatuslabelFactory.php b/database/factories/StatuslabelFactory.php index 9150e7b62e..d863b9cf7f 100644 --- a/database/factories/StatuslabelFactory.php +++ b/database/factories/StatuslabelFactory.php @@ -23,7 +23,7 @@ class StatuslabelFactory extends Factory public function definition() { return [ - 'name' => $this->faker->sentence, + 'name' => $this->faker->sentence(), 'created_at' => $this->faker->dateTime(), 'updated_at' => $this->faker->dateTime(), 'user_id' => function () { @@ -41,7 +41,7 @@ class StatuslabelFactory extends Factory { return $this->state(function () { return [ - 'notes' => $this->faker->sentence, + 'notes' => $this->faker->sentence(), 'deployable' => 1, 'default_label' => 1, ]; @@ -52,7 +52,7 @@ class StatuslabelFactory extends Factory { return $this->state(function () { return [ - 'notes' => $this->faker->sentence, + 'notes' => $this->faker->sentence(), 'pending' => 1, 'default_label' => 1, ]; From 605f2145978fe3cd4dd7d6f22db57faad8cadc5d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 17:08:18 -0700 Subject: [PATCH 27/52] Add properties necessary for factories to be called in isolation --- database/factories/AccessoryFactory.php | 7 +++++++ database/factories/AssetFactory.php | 1 + database/factories/AssetModelFactory.php | 1 + database/factories/CategoryFactory.php | 1 + database/factories/ConsumableFactory.php | 2 ++ database/factories/DepartmentFactory.php | 1 + database/factories/LicenseFactory.php | 1 + database/factories/ManufacturerFactory.php | 1 + 8 files changed, 15 insertions(+) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index e9c90acd9c..5d17fe11c6 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -35,11 +35,18 @@ class AccessoryFactory extends Factory public function definition() { return [ + 'name' => sprintf( + '%s %s', + $this->faker->randomElement(['Bluetooth', 'Wired']), + $this->faker->randomElement(['Keyboard', 'Wired']) + ), 'user_id' => function () { return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, + 'category_id' => Category::factory(), 'model_number' => $this->faker->numberBetween(1000000, 50000000), 'location_id' => Location::factory(), + 'qty' => 1, ]; } diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index c269d77e36..e86cf02562 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -40,6 +40,7 @@ class AssetFactory extends Factory { return [ 'name' => null, + 'model_id' => AssetModel::factory(), 'rtd_location_id' => Location::factory(), 'serial' => $this->faker->uuid(), 'status_id' => function () { diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index 6a7da364fc..02917fb17a 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -91,6 +91,7 @@ class AssetModelFactory extends Factory return User::first() ?? User::factory()->firstAdmin(); }, 'name' => $this->faker->catchPhrase(), + 'category_id' => Category::factory(), 'model_number' => $this->faker->creditCardNumber(), 'notes' => 'Created by demo seeder', diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index 9e251931d1..8802dbb5f6 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -33,6 +33,7 @@ class CategoryFactory extends Factory { return [ 'name' => $this->faker->catchPhrase(), + 'category_type' => 'asset', 'checkin_email' => $this->faker->boolean(), 'eula_text' => $this->faker->paragraph(), 'require_acceptance' => false, diff --git a/database/factories/ConsumableFactory.php b/database/factories/ConsumableFactory.php index c52ed35367..534fcd6a87 100644 --- a/database/factories/ConsumableFactory.php +++ b/database/factories/ConsumableFactory.php @@ -34,6 +34,8 @@ class ConsumableFactory extends Factory public function definition() { return [ + 'name' => $this->faker->word(), + 'category_id' => Category::factory(), 'user_id' => function () { return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, diff --git a/database/factories/DepartmentFactory.php b/database/factories/DepartmentFactory.php index 8d10c606cc..e7a41ff0dd 100644 --- a/database/factories/DepartmentFactory.php +++ b/database/factories/DepartmentFactory.php @@ -32,6 +32,7 @@ class DepartmentFactory extends Factory public function definition() { return [ + 'name' => $this->faker->word() . ' Department', 'user_id' => function () { return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index b518de2c64..364b6fb470 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -57,6 +57,7 @@ class LicenseFactory extends Factory 'reassignable' => $this->faker->boolean(), 'termination_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d H:i:s'), 'supplier_id' => Supplier::factory(), + 'category_id' => Category::factory(), ]; } diff --git a/database/factories/ManufacturerFactory.php b/database/factories/ManufacturerFactory.php index 3b913dd7a6..08be16672a 100644 --- a/database/factories/ManufacturerFactory.php +++ b/database/factories/ManufacturerFactory.php @@ -53,6 +53,7 @@ class ManufacturerFactory extends Factory public function definition() { return [ + 'name' => $this->faker->company(), 'user_id' => function () { return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, From 3849bb838db154e2884bcc0fbfaad763f11036a6 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 18:29:51 -0700 Subject: [PATCH 28/52] Make a few more factories a bit more pure --- database/factories/AccessoryFactory.php | 4 +- database/factories/ActionlogFactory.php | 4 +- database/factories/AssetFactory.php | 4 +- database/seeders/AccessorySeeder.php | 19 +- database/seeders/ActionlogSeeder.php | 7 +- database/seeders/AssetSeeder.php | 242 ++++++------------------ 6 files changed, 76 insertions(+), 204 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index 5d17fe11c6..0622bbeda3 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -40,9 +40,7 @@ class AccessoryFactory extends Factory $this->faker->randomElement(['Bluetooth', 'Wired']), $this->faker->randomElement(['Keyboard', 'Wired']) ), - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->firstAdmin(), 'category_id' => Category::factory(), 'model_number' => $this->faker->numberBetween(1000000, 50000000), 'location_id' => Location::factory(), diff --git a/database/factories/ActionlogFactory.php b/database/factories/ActionlogFactory.php index 6fdd53c65e..b03a68d7c4 100644 --- a/database/factories/ActionlogFactory.php +++ b/database/factories/ActionlogFactory.php @@ -36,9 +36,7 @@ class ActionlogFactory extends Factory return [ 'item_id' => Asset::factory(), 'item_type' => Asset::class, - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->firstAdmin(), 'action_type' => 'uploaded', ]; } diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index e86cf02562..699069bb4e 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -46,9 +46,7 @@ class AssetFactory extends Factory 'status_id' => function () { return Statuslabel::where('name', 'Ready to Deploy')->first() ?? Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']); }, - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->firstAdmin(), 'asset_tag' => $this->faker->unixTime('now'), 'notes' => 'Created by DB seeder', 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), diff --git a/database/seeders/AccessorySeeder.php b/database/seeders/AccessorySeeder.php index 1e21e60f6c..31f0c478d4 100644 --- a/database/seeders/AccessorySeeder.php +++ b/database/seeders/AccessorySeeder.php @@ -5,6 +5,7 @@ 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; @@ -29,23 +30,33 @@ class AccessorySeeder extends Seeder $supplierIds = Supplier::all()->pluck('id'); - Accessory::factory()->count(1)->appleUsbKeyboard()->create([ + $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()->count(1)->appleBtKeyboard()->create([ + + Accessory::factory()->appleBtKeyboard()->create([ 'location_id' => $locationIds->random(), 'supplier_id' => $supplierIds->random(), + 'user_id' => $admin->id, ]); - Accessory::factory()->count(1)->appleMouse()->create([ + + Accessory::factory()->appleMouse()->create([ 'location_id' => $locationIds->random(), 'supplier_id' => $supplierIds->random(), + 'user_id' => $admin->id, ]); - Accessory::factory()->count(1)->microsoftMouse()->create([ + + 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); diff --git a/database/seeders/ActionlogSeeder.php b/database/seeders/ActionlogSeeder.php index b680b87b35..3cbcde0478 100644 --- a/database/seeders/ActionlogSeeder.php +++ b/database/seeders/ActionlogSeeder.php @@ -5,6 +5,7 @@ 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 @@ -21,14 +22,16 @@ class ActionlogSeeder extends Seeder $this->call(LocationSeeder::class); } + $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); + Actionlog::factory() ->count(300) ->assetCheckoutToUser() - ->create(); + ->create(['user_id' => $admin->id]); Actionlog::factory() ->count(100) ->assetCheckoutToLocation() - ->create(); + ->create(['user_id' => $admin->id]); } } diff --git a/database/seeders/AssetSeeder.php b/database/seeders/AssetSeeder.php index 1b0ca71a4e..53af19758b 100644 --- a/database/seeders/AssetSeeder.php +++ b/database/seeders/AssetSeeder.php @@ -5,6 +5,7 @@ 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; @@ -13,201 +14,41 @@ use Illuminate\Support\Facades\Storage; class AssetSeeder extends Seeder { + private $admin; + private $locationIds; + private $supplierIds; + public function run() { Asset::truncate(); - if (! Location::count()) { - $this->call(LocationSeeder::class); - } + $this->ensureLocationsSeeded(); + $this->ensureSuppliersSeeded(); - $locationIds = Location::all()->pluck('id'); + $this->admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); + $this->locationIds = Location::all()->pluck('id'); + $this->supplierIds = Supplier::all()->pluck('id'); - if (! Supplier::count()) { - $this->call(SupplierSeeder::class); - } - - $supplierIds = Supplier::all()->pluck('id'); - - Asset::factory() - ->count(1000) - ->laptopMbp() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(50) - ->laptopMbpPending() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(50) - ->laptopMbpArchived() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(50) - ->laptopAir() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(5) - ->laptopSurface() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(5) - ->laptopXps() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(5) - ->laptopSpectre() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(5) - ->laptopZenbook() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(3) - ->laptopYoga() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(30) - ->desktopMacpro() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(30) - ->desktopLenovoI5() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(30) - ->desktopOptiplex() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(5) - ->confPolycom() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(2) - ->confPolycomcx() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(12) - ->tabletIpad() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(4) - ->tabletTab3() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(27) - ->phoneIphone11() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(40) - ->phoneIphone12() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(10) - ->ultrafine() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); - - Asset::factory() - ->count(10) - ->ultrasharp() - ->state(new Sequence(fn($sequence) => [ - 'rtd_location_id' => $locationIds->random(), - 'supplier_id' => $supplierIds->random(), - ])) - ->create(); + Asset::factory()->count(1000)->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(5)->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(5)->laptopZenbook()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(3)->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(5)->confPolycom()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(2)->confPolycomcx()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(12)->tabletIpad()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(4)->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(10)->ultrafine()->state(new Sequence($this->getState()))->create(); + Asset::factory()->count(10)->ultrasharp()->state(new Sequence($this->getState()))->create(); $del_files = Storage::files('assets'); foreach ($del_files as $del_file) { // iterate files @@ -221,4 +62,27 @@ class AssetSeeder extends Seeder 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, + ]; + } } From a37d69fcf1d08a937ad89e80e2f539672368c32d Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 20 Mar 2023 11:19:34 -0700 Subject: [PATCH 29/52] Replace remaining user_ids in factories --- database/factories/AccessoryFactory.php | 2 +- database/factories/ActionlogFactory.php | 2 +- database/factories/AssetFactory.php | 2 +- database/factories/AssetModelFactory.php | 4 +-- database/factories/CategoryFactory.php | 4 +-- database/factories/ConsumableFactory.php | 4 +-- database/factories/DepartmentFactory.php | 4 +-- database/factories/DepreciationFactory.php | 4 +-- database/factories/LicenseFactory.php | 4 +-- database/factories/ManufacturerFactory.php | 4 +-- database/factories/SettingFactory.php | 4 +-- database/factories/StatuslabelFactory.php | 4 +-- database/seeders/AssetModelSeeder.php | 39 ++++++++++++---------- database/seeders/CategorySeeder.php | 33 +++++++++--------- database/seeders/ConsumableSeeder.php | 10 ++++-- database/seeders/DepartmentSeeder.php | 38 +++++++++++++++++---- database/seeders/DepreciationSeeder.php | 10 ++++-- database/seeders/LicenseSeeder.php | 10 ++++++ database/seeders/ManufacturerSeeder.php | 26 +++++++++------ database/seeders/StatuslabelSeeder.php | 30 +++++++++++++---- 20 files changed, 145 insertions(+), 93 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index 0622bbeda3..cca7297537 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -40,7 +40,7 @@ class AccessoryFactory extends Factory $this->faker->randomElement(['Bluetooth', 'Wired']), $this->faker->randomElement(['Keyboard', 'Wired']) ), - 'user_id' => User::factory()->firstAdmin(), + 'user_id' => User::factory()->superuser(), 'category_id' => Category::factory(), 'model_number' => $this->faker->numberBetween(1000000, 50000000), 'location_id' => Location::factory(), diff --git a/database/factories/ActionlogFactory.php b/database/factories/ActionlogFactory.php index b03a68d7c4..50f6049f1e 100644 --- a/database/factories/ActionlogFactory.php +++ b/database/factories/ActionlogFactory.php @@ -36,7 +36,7 @@ class ActionlogFactory extends Factory return [ 'item_id' => Asset::factory(), 'item_type' => Asset::class, - 'user_id' => User::factory()->firstAdmin(), + 'user_id' => User::factory()->superuser(), 'action_type' => 'uploaded', ]; } diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 699069bb4e..4a786b814b 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -46,7 +46,7 @@ class AssetFactory extends Factory 'status_id' => function () { return Statuslabel::where('name', 'Ready to Deploy')->first() ?? Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']); }, - 'user_id' => User::factory()->firstAdmin(), + 'user_id' => User::factory()->superuser(), 'asset_tag' => $this->faker->unixTime('now'), 'notes' => 'Created by DB seeder', 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index 02917fb17a..208ad8a687 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -87,9 +87,7 @@ class AssetModelFactory extends Factory public function definition() { return [ - 'user_id' => function () { - return User::first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->superuser(), 'name' => $this->faker->catchPhrase(), 'category_id' => Category::factory(), 'model_number' => $this->faker->creditCardNumber(), diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index 8802dbb5f6..d66b714201 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -38,9 +38,7 @@ class CategoryFactory extends Factory 'eula_text' => $this->faker->paragraph(), 'require_acceptance' => false, 'use_default_eula' => $this->faker->boolean(), - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->superuser(), ]; } diff --git a/database/factories/ConsumableFactory.php b/database/factories/ConsumableFactory.php index 534fcd6a87..961e7eeafe 100644 --- a/database/factories/ConsumableFactory.php +++ b/database/factories/ConsumableFactory.php @@ -36,9 +36,7 @@ class ConsumableFactory extends Factory return [ 'name' => $this->faker->word(), 'category_id' => Category::factory(), - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->superuser(), 'item_no' => $this->faker->numberBetween(1000000, 50000000), 'order_number' => $this->faker->numberBetween(1000000, 50000000), 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), diff --git a/database/factories/DepartmentFactory.php b/database/factories/DepartmentFactory.php index e7a41ff0dd..16eade6a02 100644 --- a/database/factories/DepartmentFactory.php +++ b/database/factories/DepartmentFactory.php @@ -33,9 +33,7 @@ class DepartmentFactory extends Factory { return [ 'name' => $this->faker->word() . ' Department', - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->superuser(), 'location_id' => Location::factory(), ]; } diff --git a/database/factories/DepreciationFactory.php b/database/factories/DepreciationFactory.php index a203a74773..b883acff37 100644 --- a/database/factories/DepreciationFactory.php +++ b/database/factories/DepreciationFactory.php @@ -32,9 +32,7 @@ class DepreciationFactory extends Factory { return [ 'name' => $this->faker->catchPhrase(), - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->superuser(), 'months' => 36, ]; } diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index 364b6fb470..5e7ebfa673 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -43,9 +43,7 @@ class LicenseFactory extends Factory return [ - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->superuser(), 'name' => $this->faker->name(), 'license_email' => $this->faker->safeEmail(), 'serial' => $this->faker->uuid(), diff --git a/database/factories/ManufacturerFactory.php b/database/factories/ManufacturerFactory.php index 08be16672a..e42e50c2d0 100644 --- a/database/factories/ManufacturerFactory.php +++ b/database/factories/ManufacturerFactory.php @@ -54,9 +54,7 @@ class ManufacturerFactory extends Factory { return [ 'name' => $this->faker->company(), - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->superuser(), 'support_phone' => $this->faker->phoneNumber(), 'url' => $this->faker->url(), 'support_email' => $this->faker->safeEmail(), diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index f08eb26c77..038788dff5 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -40,9 +40,7 @@ class SettingFactory extends Factory public function definition() { return [ - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->superuser(), 'per_page' => 20, 'site_name' => $this->faker->sentence(), 'auto_increment_assets' => false, diff --git a/database/factories/StatuslabelFactory.php b/database/factories/StatuslabelFactory.php index d863b9cf7f..0b8359dd5b 100644 --- a/database/factories/StatuslabelFactory.php +++ b/database/factories/StatuslabelFactory.php @@ -26,9 +26,7 @@ class StatuslabelFactory extends Factory 'name' => $this->faker->sentence(), 'created_at' => $this->faker->dateTime(), 'updated_at' => $this->faker->dateTime(), - 'user_id' => function () { - return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); - }, + 'user_id' => User::factory()->superuser(), 'deleted_at' => null, 'deployable' => 0, 'pending' => 0, diff --git a/database/seeders/AssetModelSeeder.php b/database/seeders/AssetModelSeeder.php index 0652fbfb84..0a7c4cb897 100755 --- a/database/seeders/AssetModelSeeder.php +++ b/database/seeders/AssetModelSeeder.php @@ -3,6 +3,7 @@ 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; @@ -13,35 +14,37 @@ class AssetModelSeeder extends Seeder { AssetModel::truncate(); + $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); + // Laptops - AssetModel::factory()->count(1)->mbp13Model()->create(); // 1 - AssetModel::factory()->count(1)->mbpAirModel()->create(); // 2 - AssetModel::factory()->count(1)->surfaceModel()->create(); // 3 - AssetModel::factory()->count(1)->xps13Model()->create(); // 4 - AssetModel::factory()->count(1)->spectreModel()->create(); // 5 - AssetModel::factory()->count(1)->zenbookModel()->create(); // 6 - AssetModel::factory()->count(1)->yogaModel()->create(); // 7 + AssetModel::factory()->count(1)->mbp13Model()->create(['user_id' => $admin->id]); // 1 + AssetModel::factory()->count(1)->mbpAirModel()->create(['user_id' => $admin->id]); // 2 + AssetModel::factory()->count(1)->surfaceModel()->create(['user_id' => $admin->id]); // 3 + AssetModel::factory()->count(1)->xps13Model()->create(['user_id' => $admin->id]); // 4 + AssetModel::factory()->count(1)->spectreModel()->create(['user_id' => $admin->id]); // 5 + AssetModel::factory()->count(1)->zenbookModel()->create(['user_id' => $admin->id]); // 6 + AssetModel::factory()->count(1)->yogaModel()->create(['user_id' => $admin->id]); // 7 // Desktops - AssetModel::factory()->count(1)->macproModel()->create(); // 8 - AssetModel::factory()->count(1)->lenovoI5Model()->create(); // 9 - AssetModel::factory()->count(1)->optiplexModel()->create(); // 10 + AssetModel::factory()->count(1)->macproModel()->create(['user_id' => $admin->id]); // 8 + AssetModel::factory()->count(1)->lenovoI5Model()->create(['user_id' => $admin->id]); // 9 + AssetModel::factory()->count(1)->optiplexModel()->create(['user_id' => $admin->id]); // 10 // Conference Phones - AssetModel::factory()->count(1)->polycomModel()->create(); // 11 - AssetModel::factory()->count(1)->polycomcxModel()->create(); // 12 + AssetModel::factory()->count(1)->polycomModel()->create(['user_id' => $admin->id]); // 11 + AssetModel::factory()->count(1)->polycomcxModel()->create(['user_id' => $admin->id]); // 12 // Tablets - AssetModel::factory()->count(1)->ipadModel()->create(); // 13 - AssetModel::factory()->count(1)->tab3Model()->create(); // 14 + AssetModel::factory()->count(1)->ipadModel()->create(['user_id' => $admin->id]); // 13 + AssetModel::factory()->count(1)->tab3Model()->create(['user_id' => $admin->id]); // 14 // Phones - AssetModel::factory()->count(1)->iphone11Model()->create(); // 15 - AssetModel::factory()->count(1)->iphone12Model()->create(); // 16 + AssetModel::factory()->count(1)->iphone11Model()->create(['user_id' => $admin->id]); // 15 + AssetModel::factory()->count(1)->iphone12Model()->create(['user_id' => $admin->id]); // 16 // Displays - AssetModel::factory()->count(1)->ultrafine()->create(); // 17 - AssetModel::factory()->count(1)->ultrasharp()->create(); // 18 + AssetModel::factory()->count(1)->ultrafine()->create(['user_id' => $admin->id]); // 17 + AssetModel::factory()->count(1)->ultrasharp()->create(['user_id' => $admin->id]); // 18 $src = public_path('/img/demo/models/'); $dst = 'models'.'/'; diff --git a/database/seeders/CategorySeeder.php b/database/seeders/CategorySeeder.php index 6a554fc825..f9b6e71d58 100755 --- a/database/seeders/CategorySeeder.php +++ b/database/seeders/CategorySeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Category; +use App\Models\User; use Illuminate\Database\Seeder; class CategorySeeder extends Seeder @@ -11,20 +12,22 @@ class CategorySeeder extends Seeder { Category::truncate(); - Category::factory()->count(1)->assetLaptopCategory()->create(); // 1 - Category::factory()->count(1)->assetDesktopCategory()->create(); // 2 - Category::factory()->count(1)->assetTabletCategory()->create(); // 3 - Category::factory()->count(1)->assetMobileCategory()->create(); // 4 - Category::factory()->count(1)->assetDisplayCategory()->create(); // 5 - Category::factory()->count(1)->assetVoipCategory()->create(); // 6 - Category::factory()->count(1)->assetConferenceCategory()->create(); // 7 - Category::factory()->count(1)->accessoryKeyboardCategory()->create(); // 8 - Category::factory()->count(1)->accessoryMouseCategory()->create(); // 9 - Category::factory()->count(1)->consumablePaperCategory()->create(); // 10 - Category::factory()->count(1)->consumableInkCategory()->create(); // 11 - Category::factory()->count(1)->componentHddCategory()->create(); // 12 - Category::factory()->count(1)->componentRamCategory()->create(); // 13 - Category::factory()->count(1)->licenseGraphicsCategory()->create(); // 14 - Category::factory()->count(1)->licenseOfficeCategory()->create(); // 15 + $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); + + Category::factory()->count(1)->assetLaptopCategory()->create(['user_id' => $admin->id]); // 1 + Category::factory()->count(1)->assetDesktopCategory()->create(['user_id' => $admin->id]); // 2 + Category::factory()->count(1)->assetTabletCategory()->create(['user_id' => $admin->id]); // 3 + Category::factory()->count(1)->assetMobileCategory()->create(['user_id' => $admin->id]); // 4 + Category::factory()->count(1)->assetDisplayCategory()->create(['user_id' => $admin->id]); // 5 + Category::factory()->count(1)->assetVoipCategory()->create(['user_id' => $admin->id]); // 6 + Category::factory()->count(1)->assetConferenceCategory()->create(['user_id' => $admin->id]); // 7 + Category::factory()->count(1)->accessoryKeyboardCategory()->create(['user_id' => $admin->id]); // 8 + Category::factory()->count(1)->accessoryMouseCategory()->create(['user_id' => $admin->id]); // 9 + Category::factory()->count(1)->consumablePaperCategory()->create(['user_id' => $admin->id]); // 10 + Category::factory()->count(1)->consumableInkCategory()->create(['user_id' => $admin->id]); // 11 + Category::factory()->count(1)->componentHddCategory()->create(['user_id' => $admin->id]); // 12 + Category::factory()->count(1)->componentRamCategory()->create(['user_id' => $admin->id]); // 13 + Category::factory()->count(1)->licenseGraphicsCategory()->create(['user_id' => $admin->id]); // 14 + Category::factory()->count(1)->licenseOfficeCategory()->create(['user_id' => $admin->id]); // 15 } } diff --git a/database/seeders/ConsumableSeeder.php b/database/seeders/ConsumableSeeder.php index 240741fe6d..25dbe0c2fd 100644 --- a/database/seeders/ConsumableSeeder.php +++ b/database/seeders/ConsumableSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Consumable; +use App\Models\User; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -12,8 +13,11 @@ class ConsumableSeeder extends Seeder { Consumable::truncate(); DB::table('consumables_users')->truncate(); - Consumable::factory()->count(1)->cardstock()->create(); // 1 - Consumable::factory()->count(1)->paper()->create(); // 2 - Consumable::factory()->count(1)->ink()->create(); // 3 + + $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); + + Consumable::factory()->count(1)->cardstock()->create(['user_id' => $admin->id]); // 1 + Consumable::factory()->count(1)->paper()->create(['user_id' => $admin->id]); // 2 + Consumable::factory()->count(1)->ink()->create(['user_id' => $admin->id]); // 3 } } diff --git a/database/seeders/DepartmentSeeder.php b/database/seeders/DepartmentSeeder.php index df3523456b..7406b97afb 100644 --- a/database/seeders/DepartmentSeeder.php +++ b/database/seeders/DepartmentSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\Department; use App\Models\Location; +use App\Models\User; use Illuminate\Database\Seeder; class DepartmentSeeder extends Seeder @@ -18,11 +19,36 @@ class DepartmentSeeder extends Seeder $locationIds = Location::all()->pluck('id'); - Department::factory()->count(1)->hr()->create(['location_id' => $locationIds->random()]); - Department::factory()->count(1)->engineering()->create(['location_id' => $locationIds->random()]); - Department::factory()->count(1)->marketing()->create(['location_id' => $locationIds->random()]); - Department::factory()->count(1)->client()->create(['location_id' => $locationIds->random()]); - Department::factory()->count(1)->product()->create(['location_id' => $locationIds->random()]); - Department::factory()->count(1)->silly()->create(['location_id' => $locationIds->random()]); + $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, + ]); } } diff --git a/database/seeders/DepreciationSeeder.php b/database/seeders/DepreciationSeeder.php index 1dfebd3062..b5363af613 100644 --- a/database/seeders/DepreciationSeeder.php +++ b/database/seeders/DepreciationSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Depreciation; +use App\Models\User; use Illuminate\Database\Seeder; class DepreciationSeeder extends Seeder @@ -10,8 +11,11 @@ class DepreciationSeeder extends Seeder public function run() { Depreciation::truncate(); - Depreciation::factory()->count(1)->computer()->create(); // 1 - Depreciation::factory()->count(1)->display()->create(); // 2 - Depreciation::factory()->count(1)->mobilePhones()->create(); // 3 + + $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); + + Depreciation::factory()->count(1)->computer()->create(['user_id' => $admin->id]); // 1 + Depreciation::factory()->count(1)->display()->create(['user_id' => $admin->id]); // 2 + Depreciation::factory()->count(1)->mobilePhones()->create(['user_id' => $admin->id]); // 3 } } diff --git a/database/seeders/LicenseSeeder.php b/database/seeders/LicenseSeeder.php index 3b2c7f16cc..4868dd41e1 100644 --- a/database/seeders/LicenseSeeder.php +++ b/database/seeders/LicenseSeeder.php @@ -6,6 +6,7 @@ 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 @@ -27,21 +28,30 @@ class LicenseSeeder extends Seeder $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, ]); } } diff --git a/database/seeders/ManufacturerSeeder.php b/database/seeders/ManufacturerSeeder.php index fc6a3c34e9..5e4c34c82e 100644 --- a/database/seeders/ManufacturerSeeder.php +++ b/database/seeders/ManufacturerSeeder.php @@ -3,6 +3,7 @@ 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; @@ -12,17 +13,20 @@ class ManufacturerSeeder extends Seeder public function run() { Manufacturer::truncate(); - Manufacturer::factory()->count(1)->apple()->create(); // 1 - Manufacturer::factory()->count(1)->microsoft()->create(); // 2 - Manufacturer::factory()->count(1)->dell()->create(); // 3 - Manufacturer::factory()->count(1)->asus()->create(); // 4 - Manufacturer::factory()->count(1)->hp()->create(); // 5 - Manufacturer::factory()->count(1)->lenovo()->create(); // 6 - Manufacturer::factory()->count(1)->lg()->create(); // 7 - Manufacturer::factory()->count(1)->polycom()->create(); // 8 - Manufacturer::factory()->count(1)->adobe()->create(); // 9 - Manufacturer::factory()->count(1)->avery()->create(); // 10 - Manufacturer::factory()->count(1)->crucial()->create(); // 10 + + $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); + + Manufacturer::factory()->count(1)->apple()->create(['user_id' => $admin->id]); // 1 + Manufacturer::factory()->count(1)->microsoft()->create(['user_id' => $admin->id]); // 2 + Manufacturer::factory()->count(1)->dell()->create(['user_id' => $admin->id]); // 3 + Manufacturer::factory()->count(1)->asus()->create(['user_id' => $admin->id]); // 4 + Manufacturer::factory()->count(1)->hp()->create(['user_id' => $admin->id]); // 5 + Manufacturer::factory()->count(1)->lenovo()->create(['user_id' => $admin->id]); // 6 + Manufacturer::factory()->count(1)->lg()->create(['user_id' => $admin->id]); // 7 + Manufacturer::factory()->count(1)->polycom()->create(['user_id' => $admin->id]); // 8 + Manufacturer::factory()->count(1)->adobe()->create(['user_id' => $admin->id]); // 9 + Manufacturer::factory()->count(1)->avery()->create(['user_id' => $admin->id]); // 10 + Manufacturer::factory()->count(1)->crucial()->create(['user_id' => $admin->id]); // 10 $src = public_path('/img/demo/manufacturers/'); $dst = 'manufacturers'.'/'; diff --git a/database/seeders/StatuslabelSeeder.php b/database/seeders/StatuslabelSeeder.php index 94cd2140ae..fbc6a9fb66 100755 --- a/database/seeders/StatuslabelSeeder.php +++ b/database/seeders/StatuslabelSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Statuslabel; +use App\Models\User; use Illuminate\Database\Seeder; class StatuslabelSeeder extends Seeder @@ -10,12 +11,27 @@ class StatuslabelSeeder extends Seeder public function run() { Statuslabel::truncate(); - Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']); - Statuslabel::factory()->pending()->create(['name' => 'Pending']); - Statuslabel::factory()->archived()->create(['name' => 'Archived']); - Statuslabel::factory()->outForDiagnostics()->create(); - Statuslabel::factory()->outForRepair()->create(); - Statuslabel::factory()->broken()->create(); - Statuslabel::factory()->lost()->create(); + + $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]); } } From 1fd574779bf9a8f060c84309bef3909ffcf869b7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 20 Mar 2023 11:39:27 -0700 Subject: [PATCH 30/52] Remove unneeded or outdated comments and update imports --- database/factories/AccessoryFactory.php | 12 +--- database/factories/ActionlogFactory.php | 9 --- database/factories/AssetFactory.php | 12 ---- .../factories/AssetMaintenanceFactory.php | 14 +--- database/factories/AssetModelFactory.php | 64 +------------------ database/factories/CategoryFactory.php | 11 +--- database/factories/CompanyFactory.php | 19 +----- database/factories/ComponentFactory.php | 12 +--- database/factories/ConsumableFactory.php | 12 +--- database/factories/CustomFieldFactory.php | 3 +- database/factories/CustomFieldsetFactory.php | 3 +- database/factories/DepartmentFactory.php | 12 +--- database/factories/DepreciationFactory.php | 12 +--- database/factories/GroupFactory.php | 21 +----- database/factories/LicenseFactory.php | 22 +------ database/factories/ManufacturerFactory.php | 34 +--------- database/factories/SettingFactory.php | 21 +----- database/factories/SupplierFactory.php | 19 +----- 18 files changed, 29 insertions(+), 283 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index cca7297537..124a72c4a7 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Accessory; use App\Models\Category; use App\Models\Location; use App\Models\Manufacturer; @@ -9,15 +10,6 @@ use App\Models\Supplier; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; -/* -|-------------------------------------------------------------------------- -| Asset Model Factories -|-------------------------------------------------------------------------- -| -| Factories related exclusively to creating models .. -| -*/ - class AccessoryFactory extends Factory { /** @@ -25,7 +17,7 @@ class AccessoryFactory extends Factory * * @var string */ - protected $model = \App\Models\Accessory::class; + protected $model = Accessory::class; /** * Define the model's default state. diff --git a/database/factories/ActionlogFactory.php b/database/factories/ActionlogFactory.php index 50f6049f1e..1064524b1a 100644 --- a/database/factories/ActionlogFactory.php +++ b/database/factories/ActionlogFactory.php @@ -8,15 +8,6 @@ use App\Models\Location; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; -/* -|-------------------------------------------------------------------------- -| Action Log Factories -|-------------------------------------------------------------------------- -| -| This simulates checkin/checkout/etc activities -| -*/ - class ActionlogFactory extends Factory { /** diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 4a786b814b..47834167ce 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -4,24 +4,12 @@ namespace Database\Factories; use App\Models\Asset; use App\Models\AssetModel; -use App\Models\Category; use App\Models\Location; use App\Models\Statuslabel; use App\Models\Supplier; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; -/* -|-------------------------------------------------------------------------- -| Model Factories -|-------------------------------------------------------------------------- -| -| Factories related exclusively to modelling assets. -| -*/ - -// These are just for unit tests, not to generate data - class AssetFactory extends Factory { /** diff --git a/database/factories/AssetMaintenanceFactory.php b/database/factories/AssetMaintenanceFactory.php index 1cf7c0d844..ada73f7ed8 100644 --- a/database/factories/AssetMaintenanceFactory.php +++ b/database/factories/AssetMaintenanceFactory.php @@ -3,20 +3,10 @@ namespace Database\Factories; use App\Models\Asset; -use App\Models\AssetModel; -use App\Models\Category; +use App\Models\AssetMaintenance; use App\Models\Supplier; use Illuminate\Database\Eloquent\Factories\Factory; -/* -|-------------------------------------------------------------------------- -| Model Factories -|-------------------------------------------------------------------------- -| -| Factories related exclusively to modelling assets. -| -*/ - class AssetMaintenanceFactory extends Factory { /** @@ -24,7 +14,7 @@ class AssetMaintenanceFactory extends Factory * * @var string */ - protected $model = \App\Models\AssetMaintenance::class; + protected $model = AssetMaintenance::class; /** * Define the model's default state. diff --git a/database/factories/AssetModelFactory.php b/database/factories/AssetModelFactory.php index 208ad8a687..4881d6560b 100644 --- a/database/factories/AssetModelFactory.php +++ b/database/factories/AssetModelFactory.php @@ -2,74 +2,14 @@ namespace Database\Factories; -use App\Models\AssetMaintenance; +use App\Models\AssetModel; use App\Models\CustomFieldset; use App\Models\Depreciation; -use App\Models\Import; use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use App\Models\Category; -/* -|-------------------------------------------------------------------------- -| Asset Model Factories -|-------------------------------------------------------------------------- -| -| Factories related exclusively to creating models .. -| -*/ - -/* -|-------------------------------------------------------------------------- -| Laptops -|-------------------------------------------------------------------------- -*/ - -// 1 - -// 2 - -// 3 - -// 4 - -// 5 - -// 6 - -// 7 - -/* -|-------------------------------------------------------------------------- -| Desktops -|-------------------------------------------------------------------------- -*/ - -/* -|-------------------------------------------------------------------------- -| Conference Phones -|-------------------------------------------------------------------------- -*/ - -/* -|-------------------------------------------------------------------------- -| Tablets -|-------------------------------------------------------------------------- -*/ - -/* -|-------------------------------------------------------------------------- -| Mobile Phones -|-------------------------------------------------------------------------- -*/ - -/* -|-------------------------------------------------------------------------- -| Displays -|-------------------------------------------------------------------------- -*/ - class AssetModelFactory extends Factory { /** @@ -77,7 +17,7 @@ class AssetModelFactory extends Factory * * @var string */ - protected $model = \App\Models\AssetModel::class; + protected $model = AssetModel::class; /** * Define the model's default state. diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index d66b714201..2cabb54a21 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -6,15 +6,6 @@ use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use App\Models\Category; -/* -|-------------------------------------------------------------------------- -| Category Factories -|-------------------------------------------------------------------------- -| -| Factories related exclusively to creating categories and the various states.. -| -*/ - class CategoryFactory extends Factory { /** @@ -22,7 +13,7 @@ class CategoryFactory extends Factory * * @var string */ - protected $model = \App\Models\Category::class; + protected $model = Category::class; /** * Define the model's default state. diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php index 00dcf911c1..bf4b7ce242 100644 --- a/database/factories/CompanyFactory.php +++ b/database/factories/CompanyFactory.php @@ -1,25 +1,8 @@ User::factory()->superuser(), 'name' => $this->faker->name(), diff --git a/database/factories/ManufacturerFactory.php b/database/factories/ManufacturerFactory.php index e42e50c2d0..ab22262a78 100644 --- a/database/factories/ManufacturerFactory.php +++ b/database/factories/ManufacturerFactory.php @@ -2,40 +2,10 @@ namespace Database\Factories; +use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; -/* -|-------------------------------------------------------------------------- -| Asset Model Factories -|-------------------------------------------------------------------------- -| -| Factories related exclusively to creating models .. -| -*/ - -// 1 - -// 2 - -// 3 - -// 4 - -// 5 - -// 6 - -// 7 - -// 8 - -// 9 - -// 10 - -// 11 - class ManufacturerFactory extends Factory { /** @@ -43,7 +13,7 @@ class ManufacturerFactory extends Factory * * @var string */ - protected $model = \App\Models\Manufacturer::class; + protected $model = Manufacturer::class; /** * Define the model's default state. diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index 038788dff5..1aa173fd15 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -1,25 +1,8 @@ Date: Mon, 20 Mar 2023 11:42:15 -0700 Subject: [PATCH 31/52] Remove outdated comments --- database/seeders/AssetModelSeeder.php | 36 ++++++++++++------------- database/seeders/CategorySeeder.php | 30 ++++++++++----------- database/seeders/ConsumableSeeder.php | 6 ++--- database/seeders/DepreciationSeeder.php | 6 ++--- database/seeders/ManufacturerSeeder.php | 22 +++++++-------- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/database/seeders/AssetModelSeeder.php b/database/seeders/AssetModelSeeder.php index 0a7c4cb897..1fc0b28cd3 100755 --- a/database/seeders/AssetModelSeeder.php +++ b/database/seeders/AssetModelSeeder.php @@ -17,34 +17,34 @@ class AssetModelSeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); // Laptops - AssetModel::factory()->count(1)->mbp13Model()->create(['user_id' => $admin->id]); // 1 - AssetModel::factory()->count(1)->mbpAirModel()->create(['user_id' => $admin->id]); // 2 - AssetModel::factory()->count(1)->surfaceModel()->create(['user_id' => $admin->id]); // 3 - AssetModel::factory()->count(1)->xps13Model()->create(['user_id' => $admin->id]); // 4 - AssetModel::factory()->count(1)->spectreModel()->create(['user_id' => $admin->id]); // 5 - AssetModel::factory()->count(1)->zenbookModel()->create(['user_id' => $admin->id]); // 6 - AssetModel::factory()->count(1)->yogaModel()->create(['user_id' => $admin->id]); // 7 + 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]); // 8 - AssetModel::factory()->count(1)->lenovoI5Model()->create(['user_id' => $admin->id]); // 9 - AssetModel::factory()->count(1)->optiplexModel()->create(['user_id' => $admin->id]); // 10 + 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]); // 11 - AssetModel::factory()->count(1)->polycomcxModel()->create(['user_id' => $admin->id]); // 12 + 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]); // 13 - AssetModel::factory()->count(1)->tab3Model()->create(['user_id' => $admin->id]); // 14 + 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]); // 15 - AssetModel::factory()->count(1)->iphone12Model()->create(['user_id' => $admin->id]); // 16 + 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]); // 17 - AssetModel::factory()->count(1)->ultrasharp()->create(['user_id' => $admin->id]); // 18 + 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'.'/'; diff --git a/database/seeders/CategorySeeder.php b/database/seeders/CategorySeeder.php index f9b6e71d58..da542cff9e 100755 --- a/database/seeders/CategorySeeder.php +++ b/database/seeders/CategorySeeder.php @@ -14,20 +14,20 @@ class CategorySeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); - Category::factory()->count(1)->assetLaptopCategory()->create(['user_id' => $admin->id]); // 1 - Category::factory()->count(1)->assetDesktopCategory()->create(['user_id' => $admin->id]); // 2 - Category::factory()->count(1)->assetTabletCategory()->create(['user_id' => $admin->id]); // 3 - Category::factory()->count(1)->assetMobileCategory()->create(['user_id' => $admin->id]); // 4 - Category::factory()->count(1)->assetDisplayCategory()->create(['user_id' => $admin->id]); // 5 - Category::factory()->count(1)->assetVoipCategory()->create(['user_id' => $admin->id]); // 6 - Category::factory()->count(1)->assetConferenceCategory()->create(['user_id' => $admin->id]); // 7 - Category::factory()->count(1)->accessoryKeyboardCategory()->create(['user_id' => $admin->id]); // 8 - Category::factory()->count(1)->accessoryMouseCategory()->create(['user_id' => $admin->id]); // 9 - Category::factory()->count(1)->consumablePaperCategory()->create(['user_id' => $admin->id]); // 10 - Category::factory()->count(1)->consumableInkCategory()->create(['user_id' => $admin->id]); // 11 - Category::factory()->count(1)->componentHddCategory()->create(['user_id' => $admin->id]); // 12 - Category::factory()->count(1)->componentRamCategory()->create(['user_id' => $admin->id]); // 13 - Category::factory()->count(1)->licenseGraphicsCategory()->create(['user_id' => $admin->id]); // 14 - Category::factory()->count(1)->licenseOfficeCategory()->create(['user_id' => $admin->id]); // 15 + 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]); } } diff --git a/database/seeders/ConsumableSeeder.php b/database/seeders/ConsumableSeeder.php index 25dbe0c2fd..42527e1df8 100644 --- a/database/seeders/ConsumableSeeder.php +++ b/database/seeders/ConsumableSeeder.php @@ -16,8 +16,8 @@ class ConsumableSeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); - Consumable::factory()->count(1)->cardstock()->create(['user_id' => $admin->id]); // 1 - Consumable::factory()->count(1)->paper()->create(['user_id' => $admin->id]); // 2 - Consumable::factory()->count(1)->ink()->create(['user_id' => $admin->id]); // 3 + 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]); } } diff --git a/database/seeders/DepreciationSeeder.php b/database/seeders/DepreciationSeeder.php index b5363af613..349d8aff53 100644 --- a/database/seeders/DepreciationSeeder.php +++ b/database/seeders/DepreciationSeeder.php @@ -14,8 +14,8 @@ class DepreciationSeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); - Depreciation::factory()->count(1)->computer()->create(['user_id' => $admin->id]); // 1 - Depreciation::factory()->count(1)->display()->create(['user_id' => $admin->id]); // 2 - Depreciation::factory()->count(1)->mobilePhones()->create(['user_id' => $admin->id]); // 3 + 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]); } } diff --git a/database/seeders/ManufacturerSeeder.php b/database/seeders/ManufacturerSeeder.php index 5e4c34c82e..cbd70f4c3d 100644 --- a/database/seeders/ManufacturerSeeder.php +++ b/database/seeders/ManufacturerSeeder.php @@ -16,17 +16,17 @@ class ManufacturerSeeder extends Seeder $admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create(); - Manufacturer::factory()->count(1)->apple()->create(['user_id' => $admin->id]); // 1 - Manufacturer::factory()->count(1)->microsoft()->create(['user_id' => $admin->id]); // 2 - Manufacturer::factory()->count(1)->dell()->create(['user_id' => $admin->id]); // 3 - Manufacturer::factory()->count(1)->asus()->create(['user_id' => $admin->id]); // 4 - Manufacturer::factory()->count(1)->hp()->create(['user_id' => $admin->id]); // 5 - Manufacturer::factory()->count(1)->lenovo()->create(['user_id' => $admin->id]); // 6 - Manufacturer::factory()->count(1)->lg()->create(['user_id' => $admin->id]); // 7 - Manufacturer::factory()->count(1)->polycom()->create(['user_id' => $admin->id]); // 8 - Manufacturer::factory()->count(1)->adobe()->create(['user_id' => $admin->id]); // 9 - Manufacturer::factory()->count(1)->avery()->create(['user_id' => $admin->id]); // 10 - Manufacturer::factory()->count(1)->crucial()->create(['user_id' => $admin->id]); // 10 + 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'.'/'; From 92e0c59f89a1daaed30e36eee191ae778bacfa4b Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 20 Mar 2023 12:01:39 -0700 Subject: [PATCH 32/52] Fix typo in Keyboard accessory name --- database/factories/AccessoryFactory.php | 4 ++-- database/factories/CategoryFactory.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index 124a72c4a7..8ce34303b3 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -47,7 +47,7 @@ class AccessoryFactory extends Factory 'name' => 'Bluetooth Keyboard', 'image' => 'bluetooth.jpg', 'category_id' => function () { - return Category::where('name', 'Keyboardss')->first() ?? Category::factory()->accessoryKeyboardCategory(); + return Category::where('name', 'Keyboards')->first() ?? Category::factory()->accessoryKeyboardCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); @@ -66,7 +66,7 @@ class AccessoryFactory extends Factory 'name' => 'USB Keyboard', 'image' => 'usb-keyboard.jpg', 'category_id' => function () { - return Category::where('name', 'Keyboardss')->first() ?? Category::factory()->accessoryKeyboardCategory(); + return Category::where('name', 'Keyboards')->first() ?? Category::factory()->accessoryKeyboardCategory(); }, 'manufacturer_id' => function () { return Manufacturer::where('name', 'Apple')->first() ?? Manufacturer::factory()->apple(); diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index 2cabb54a21..94a9626da4 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -103,7 +103,7 @@ class CategoryFactory extends Factory public function accessoryKeyboardCategory() { return $this->state([ - 'name' => 'Keyboardss', + 'name' => 'Keyboards', 'category_type' => 'accessory', ]); } From 44a91f0a2ba02c6e9430d5927f0e8a589dcf6d50 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 20 Mar 2023 14:18:54 -0700 Subject: [PATCH 33/52] Seed license checkouts --- database/factories/ActionlogFactory.php | 24 ++++++++++++++++++++++++ database/seeders/ActionlogSeeder.php | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/database/factories/ActionlogFactory.php b/database/factories/ActionlogFactory.php index 1064524b1a..c25fdcc70a 100644 --- a/database/factories/ActionlogFactory.php +++ b/database/factories/ActionlogFactory.php @@ -4,6 +4,8 @@ namespace Database\Factories; use App\Models\Actionlog; use App\Models\Asset; +use App\Models\License; +use App\Models\LicenseSeat; use App\Models\Location; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -81,4 +83,26 @@ class ActionlogFactory extends Factory ]; }); } + + public function licenseCheckoutToUser() + { + return $this->state(function () { + $target = User::inRandomOrder()->first(); + $licenseSeat = LicenseSeat::whereNull('assigned_to')->inRandomOrder()->first(); + + $licenseSeat->update([ + 'assigned_to' => $target->id, + 'user_id' => 1, // not ideal but works + ]); + + return [ + 'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()), + 'action_type' => 'checkout', + 'item_id' => $licenseSeat->license->id, + 'item_type' => License::class, + 'target_id' => $target->id, + 'target_type' => User::class, + ]; + }); + } } diff --git a/database/seeders/ActionlogSeeder.php b/database/seeders/ActionlogSeeder.php index 3cbcde0478..28191d53b0 100644 --- a/database/seeders/ActionlogSeeder.php +++ b/database/seeders/ActionlogSeeder.php @@ -33,5 +33,10 @@ class ActionlogSeeder extends Seeder ->count(100) ->assetCheckoutToLocation() ->create(['user_id' => $admin->id]); + + Actionlog::factory() + ->count(20) + ->licenseCheckoutToUser() + ->create(['user_id' => $admin->id]); } } From a0e547c7fba4d93a2eabc06b85bf5a9e3b66280f Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 20 Mar 2023 14:18:59 -0700 Subject: [PATCH 34/52] Remove some unused imports --- database/seeders/DatabaseSeeder.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 3507a106ef..1429604139 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -3,15 +3,6 @@ namespace Database\Seeders; use App\Models\Setting; -use Database\Seeders\AccessorySeeder; -use Database\Seeders\ActionlogSeeder; -use Database\Seeders\AssetModelSeeder; -use Database\Seeders\AssetSeeder; -use Database\Seeders\CategorySeeder; -use Database\Seeders\CompanySeeder; -use Database\Seeders\ComponentSeeder; -use Database\Seeders\ConsumableSeeder; -use Database\Seeders\CustomFieldSeeder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\Artisan; From 16e341622546b78725b29c6acecf9aeab0aa5554 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 20 Mar 2023 14:27:45 -0700 Subject: [PATCH 35/52] Update test case --- tests/Feature/Api/Users/UsersForSelectListTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index b4ede4b117..afd60855cf 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -15,9 +15,11 @@ class UsersForSelectListTest extends TestCase { Setting::factory()->create(); - User::factory()->count(3)->create(); + $users = User::factory()->superuser()->count(3)->create(); - Passport::actingAs(User::factory()->firstAdmin()->create()); + $userCount = User::count(); + + Passport::actingAs($users->first()); $this->getJson(route('api.users.selectlist')) ->assertOk() ->assertJsonStructure([ @@ -27,7 +29,7 @@ class UsersForSelectListTest extends TestCase 'page', 'page_count', ]) - ->assertJson(fn(AssertableJson $json) => $json->has('results', 4)->etc()); + ->assertJson(fn(AssertableJson $json) => $json->has('results', $userCount)->etc()); } public function testUsersScopedToCompanyWhenMultipleFullCompanySupportEnabled() From 272cc1adac79ae930a891eea2de3f4dccb29b9e4 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 20 Mar 2023 15:33:40 -0700 Subject: [PATCH 36/52] Skip creating user when creating a setting since it isn't needed --- database/factories/SettingFactory.php | 2 -- tests/Feature/Api/Users/UsersForSelectListTest.php | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index 1aa173fd15..970d00cd68 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -3,7 +3,6 @@ namespace Database\Factories; use App\Models\Setting; -use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; class SettingFactory extends Factory @@ -23,7 +22,6 @@ class SettingFactory extends Factory public function definition() { return [ - 'user_id' => User::factory()->superuser(), 'per_page' => 20, 'site_name' => $this->faker->sentence(), 'auto_increment_assets' => false, diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index afd60855cf..8b2c01bcf3 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -17,8 +17,6 @@ class UsersForSelectListTest extends TestCase $users = User::factory()->superuser()->count(3)->create(); - $userCount = User::count(); - Passport::actingAs($users->first()); $this->getJson(route('api.users.selectlist')) ->assertOk() @@ -29,7 +27,7 @@ class UsersForSelectListTest extends TestCase 'page', 'page_count', ]) - ->assertJson(fn(AssertableJson $json) => $json->has('results', $userCount)->etc()); + ->assertJson(fn(AssertableJson $json) => $json->has('results', 3)->etc()); } public function testUsersScopedToCompanyWhenMultipleFullCompanySupportEnabled() From 918239961ab166e2f09d462c22e52adee76a355b Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 20 Mar 2023 15:47:57 -0700 Subject: [PATCH 37/52] Add simple test case for assets --- tests/Feature/Api/Assets/AssetIndexTest.php | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/Feature/Api/Assets/AssetIndexTest.php diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.php new file mode 100644 index 0000000000..2190c791f6 --- /dev/null +++ b/tests/Feature/Api/Assets/AssetIndexTest.php @@ -0,0 +1,35 @@ +create(); + + Asset::factory()->count(3)->create(); + + Passport::actingAs(User::factory()->superuser()->create()); + $this->getJson( + route('api.assets.index', [ + 'sort' => 'name', + 'order' => 'asc', + 'offset' => '0', + 'limit' => '20', + ])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + } +} From d214bd0b0601692ffe3d3ec539928839aeb6f9da Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 20 Mar 2023 16:41:33 -0700 Subject: [PATCH 38/52] Remove temporary command --- app/Console/Commands/CountModels.php | 76 ---------------------------- 1 file changed, 76 deletions(-) delete mode 100644 app/Console/Commands/CountModels.php diff --git a/app/Console/Commands/CountModels.php b/app/Console/Commands/CountModels.php deleted file mode 100644 index 8b3de99b78..0000000000 --- a/app/Console/Commands/CountModels.php +++ /dev/null @@ -1,76 +0,0 @@ -table(['Model', 'Count'], [ - [Accessory::class, Accessory::count()], - [Actionlog::class, Actionlog::count()], - [Asset::class, Asset::count()], - [AssetMaintenance::class, AssetMaintenance::count()], - [AssetModel::class, AssetModel::count()], - [Category::class, Category::count()], - [CheckoutAcceptance::class, CheckoutAcceptance::count()], - [CheckoutRequest::class, CheckoutRequest::count()], - [Company::class, Company::count()], - [Component::class, Component::count()], - [Consumable::class, Consumable::count()], - [ConsumableAssignment::class, ConsumableAssignment::count()], - [CustomField::class, CustomField::count()], - [CustomFieldset::class, CustomFieldset::count()], - [Department::class, Department::count()], - [Depreciation::class, Depreciation::count()], - [Group::class, Group::count()], - [Import::class, Import::count()], - [License::class, License::count()], - [LicenseSeat::class, LicenseSeat::count()], - [Location::class, Location::count()], - [Manufacturer::class, Manufacturer::count()], - [PredefinedKit::class, PredefinedKit::count()], - [SCIMUser::class, SCIMUser::count()], - [Setting::class, Setting::count()], - [Statuslabel::class, Statuslabel::count()], - [Supplier::class, Supplier::count()], - [User::class, User::count()], - ]); - - return 0; - } -} From 751abe1438e2b8478f4f6045cea953b810a8a156 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 21 Mar 2023 09:54:55 -0700 Subject: [PATCH 39/52] Re-add asset factory states --- database/factories/AssetFactory.php | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 47834167ce..cd3e0f8391 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -275,6 +275,37 @@ class AssetFactory extends Factory }); } + public function assignedToUser() + { + return $this->state(function () { + return [ + 'assigned_to' => User::factory(), + 'assigned_type' => User::class, + ]; + }); + } + + public function assignedToLocation() + { + return $this->state(function () { + return [ + 'assigned_to' => Location::factory(), + 'assigned_type' => Location::class, + ]; + }); + } + + public function assignedToAsset() + { + return $this->state(function () { + return [ + 'model_id' => 1, + 'assigned_to' => Asset::factory(), + 'assigned_type' => Asset::class, + ]; + }); + } + public function requiresAcceptance() { return $this->state(function () { From 3c28242a2ea8ba626a5cfbe02662cd5fd8f35bc1 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 21 Mar 2023 15:53:09 -0700 Subject: [PATCH 40/52] save button updates accordingly --- app/Http/Livewire/SlackSettingsForm.php | 54 +++++++-- resources/lang/en/admin/settings/general.php | 1 + .../livewire/slack-settings-form.blade.php | 111 +++++++++--------- 3 files changed, 100 insertions(+), 66 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index d2760cb890..6ba3b5b1a9 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -11,7 +11,7 @@ class SlackSettingsForm extends Component public $webhook_endpoint; public $webhook_channel; public $webhook_botname; - public $isDisabled ='disabled' ; + public $isDisabled ='' ; public $webhook_name; public $webhook_link; public $webhook_placeholder; @@ -27,7 +27,6 @@ class SlackSettingsForm extends Component 'webhook_botname' => 'string|nullable', ]; - public function mount(){ $this->webhook_text= [ "slack" => array( @@ -45,6 +44,7 @@ class SlackSettingsForm extends Component ]; $this->setting = Setting::getSettings(); + $this->save_button = trans('general.save'); $this->webhook_selected = $this->setting->webhook_selected; $this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"]; $this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"]; @@ -54,6 +54,12 @@ class SlackSettingsForm extends Component $this->webhook_botname = $this->setting->webhook_botname; $this->webhook_options = $this->setting->webhook_selected; + if($this->setting->webhook_selected == 'general'){ + $this->isDisabled=''; + } + if($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null){ + $this->isDisabled= ''; + } } public function updated($field){ @@ -66,17 +72,28 @@ class SlackSettingsForm extends Component $this->webhook_icon = $this->webhook_text[$this->webhook_selected]["icon"]; ; $this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"]; $this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"]; - + if($this->webhook_selected != 'slack'){ + $this->isDisabled= ''; + $this->save_button = trans('general.save'); + } } + private function isButtonDisabled(){ + if($this->webhook_selected == 'slack') { + if (empty($this->webhook_endpoint)) { + $this->isDisabled = 'disabled'; + $this->save_button = trans('admin/settings/general.webhook_presave'); + } + if (empty($this->webhook_channel)) { + $this->isDisabled = 'disabled'; + $this->save_button = trans('admin/settings/general.webhook_presave'); + } + } + + } public function render() { - if(empty($this->webhook_channel || $this->webhook_endpoint)){ - $this->isDisabled= 'disabled'; - } - if(empty($this->webhook_endpoint && $this->webhook_channel)){ - $this->isDisabled= ''; - } + $this->isButtonDisabled(); return view('livewire.slack-settings-form'); } @@ -100,6 +117,7 @@ class SlackSettingsForm extends Component try { $webhook->post($this->webhook_endpoint, ['body' => $payload]); $this->isDisabled=''; + $this->save_button = trans('general.save'); return session()->flash('success' , 'Your '.$this->webhook_name.' Integration works!'); } catch (\Exception $e) { @@ -110,9 +128,21 @@ class SlackSettingsForm extends Component //} return session()->flash('message' , trans('admin/settings/message.webhook.error_misc')); - - } + + public function clearSettings(){ + $this->webhook_endpoint = ''; + $this->webhook_channel = ''; + $this->webhook_botname = ''; + $this->setting->webhook_endpoint = ''; + $this->setting->webhook_channel = ''; + $this->setting->webhook_botname = ''; + + $this->setting->save(); + + session()->flash('save',trans('admin/settings/message.update.success')); + } + public function submit() { if($this->webhook_selected != 'general') { @@ -124,11 +154,9 @@ class SlackSettingsForm extends Component $this->setting->webhook_channel = $this->webhook_channel; $this->setting->webhook_botname = $this->webhook_botname; - $this->setting->save(); session()->flash('save',trans('admin/settings/message.update.success')); - } } diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index 3316ed09ff..4c8bdcb629 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -202,6 +202,7 @@ return [ 'slack' => 'Slack', 'general_webhook' => 'General Webhook', 'webhook' => ':app', + 'webhook_presave' => 'Test to Save', 'webhook_title' => 'Update Webhook Settings', 'webhook_help' => 'Integration settings', 'webhook_botname' => ':app Botname', diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index ce6ba52c0e..e7a22978ff 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -13,9 +13,6 @@ @section('content')
-
- {{csrf_field()}} -
@@ -34,7 +31,7 @@
-
+
@if (session()->has('save'))
{{session('save')}} @@ -58,66 +55,72 @@ @endif -
+
-
+
+


+ + {{csrf_field()}} - -
- -
- {{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => ucwords($webhook_selected) ])) }} + +
+
+ {{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => $webhook_name ])) }} +
+
+ @if (config('app.lock_passwords')===true) +

{{ trans('general.feature_disabled') }}

+ + @else + + @endif + {!! $errors->first('webhook_endpoint', '') !!} +
-
- @if (config('app.lock_passwords')===true) -

- - {{ trans('general.feature_disabled') }} -

- - @else - - @endif - {!! $errors->first('webhook_endpoint', ':message') !!} -
-
+ +
+
+ {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }} +
+
+ @if (config('app.lock_passwords')===true) + +

{{ trans('general.feature_disabled') }}

- -
-
- {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => ucwords($webhook_selected) ])) }} + @else + + @endif + {!! $errors->first('webhook_channel', '') !!} +
-
- - @if (config('app.lock_passwords')===true) - -

- {{ trans('general.feature_disabled') }}

- @else - - @endif - {!! $errors->first('webhook_channel', ':message') !!} -
- -
-
-
- {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => ucwords($webhook_selected) ])) }} +
+
+ {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }}
@if (config('app.lock_passwords')===true) @@ -127,7 +130,8 @@ {{ trans('general.feature_disabled') }}

@else - + @endif {!! $errors->first('webhook_botname', '') !!}
@@ -136,9 +140,8 @@ @if($webhook_selected == 'slack') @if($webhook_endpoint != null && $webhook_channel != null) -
- @endif @@ -157,17 +159,20 @@ + +
-
- +
+
- From 2754277068b4de9bf046a43d3cda46771bdc0e11 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 21 Mar 2023 16:12:46 -0700 Subject: [PATCH 41/52] adds csrf token and missing divs --- resources/views/livewire/slack-settings-form.blade.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index e7a22978ff..b94d273176 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -13,6 +13,8 @@ @section('content')
+
+ {{csrf_field()}}
@@ -107,7 +109,6 @@ value="{{old('webhook_channel', $webhook_channel)}}">

{{ trans('general.feature_disabled') }}

- @else {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }}
-
+
@if (config('app.lock_passwords')===true) @@ -168,11 +169,11 @@ aria-hidden="true"> {{ $save_button }}
-
+
From 658252125e0d9730d97c3ede32e07b3010d2539c Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 21 Mar 2023 18:57:27 -0700 Subject: [PATCH 42/52] =?UTF-8?q?Added=20new=20partial=20for=20the=20form?= =?UTF-8?q?=20inline=20=E2=80=9Cdemo=20mode=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- resources/views/partials/forms/demo-mode.blade.php | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 resources/views/partials/forms/demo-mode.blade.php diff --git a/resources/views/partials/forms/demo-mode.blade.php b/resources/views/partials/forms/demo-mode.blade.php new file mode 100644 index 0000000000..4a942204e4 --- /dev/null +++ b/resources/views/partials/forms/demo-mode.blade.php @@ -0,0 +1,5 @@ +
+
+ {!! Helper::showDemoModeFieldWarning() !!} +
+
\ No newline at end of file From d8830848307e66d4902a2d0d7b8bf35c375ed372 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 21 Mar 2023 18:58:26 -0700 Subject: [PATCH 43/52] Fixed some funky HTML tags Signed-off-by: snipe --- .../livewire/slack-settings-form.blade.php | 238 ++++++++---------- 1 file changed, 110 insertions(+), 128 deletions(-) diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index b94d273176..8fc6ac2c87 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -12,33 +12,33 @@ {{-- Page content --}} @section('content') -
+
{{csrf_field()}} +
+
-
-
-

- {{ trans('admin/settings/general.webhook', ['app' => $webhook_name] ) }} -

-
-
-
- @if($webhook_selected != 'general') -

- {!! trans('admin/settings/general.webhook_integration_help',array('webhook_link' => $webhook_link, 'app' => $webhook_name)) !!} -

- @endif -
-
+ +
+ +
+

+ {{ trans('admin/settings/general.webhook', ['app' => $webhook_name] ) }} +

+
+ +
+ @if($webhook_selected != 'general') +
+

+ {!! trans('admin/settings/general.webhook_integration_help',array('webhook_link' => $webhook_link, 'app' => $webhook_name)) !!} +

+
+
+ @endif
- @if (session()->has('save')) -
- {{session('save')}} -
- @endif @if(session()->has('success'))
@@ -50,130 +50,112 @@ {{session('error')}}
@endif - @if(session()->has('message')) -
- {{session('message')}} -
- @endif - -
-
+
+
- -
-
-


-
- - {{csrf_field()}} - -
-
- {{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => $webhook_name ])) }} -
-
- @if (config('app.lock_passwords')===true) -

{{ trans('general.feature_disabled') }}

- - @else - - @endif - {!! $errors->first('webhook_endpoint', '') !!} -
+ @if (app('demo_mode')) + @include('partials.forms.demo-mode') + @endif + + +
+
+ {{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => $webhook_name ])) }}
- - -
-
- {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }} -
-
- @if (config('app.lock_passwords')===true) - -

{{ trans('general.feature_disabled') }}

- @else - - @endif - {!! $errors->first('webhook_channel', '') !!} -
+
+ + {!! $errors->first('webhook_endpoint', '') !!}
+
- -
-
- {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }} -
-
- @if (config('app.lock_passwords')===true) - -

- {{ trans('general.feature_disabled') }} -

- @else - - @endif - {!! $errors->first('webhook_botname', '') !!} -
+ @if (app('demo_mode')) + @include('partials.forms.demo-mode') + @endif + + + +
+
+ {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }}
+
+ - - @if($webhook_selected == 'slack') - @if($webhook_endpoint != null && $webhook_channel != null) -
-
- - - {!! trans('admin/settings/general.webhook_test',['app' => ucwords($webhook_selected) ]) !!} - -
- - - -
+ {!! $errors->first('webhook_channel', '') !!} +
+
+ + @if (!app('demo_mode')) + @include('partials.forms.demo-mode') + @endif + + +
+
+ {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }} +
+
+ + {!! $errors->first('webhook_botname', '') !!} +
+
+ + @if (app('demo_mode')) + @include('partials.forms.demo-mode') + @endif + + + @if($webhook_selected == 'slack') + @if($webhook_endpoint != null && $webhook_channel != null) +
+ - @endif - @endif - - + @endif + @endif +
+
+ + + +
+
+
+ +
+ -
-
-
-
-
- -
From f29e81333292e5625372ad9111f30b4cf756177d Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 21 Mar 2023 18:58:35 -0700 Subject: [PATCH 44/52] =?UTF-8?q?Translated=20=E2=80=9CClear=20&=20Save?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- resources/lang/en/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 8b6063f421..48e61d540e 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -417,6 +417,6 @@ return [ 'merged' => 'merged', 'merged_log_this_user_into' => 'Merged this user (ID :to_id - :to_username) into user ID :from_id (:from_username) ', 'merged_log_this_user_from' => 'Merged user ID :from_id (:from_username) into this user (ID :to_id - :to_username)', - + 'clear_and_save' => 'Clear & Save', ]; \ No newline at end of file From d55ae44638841fe1d4a7360453ee24222ba19214 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 21 Mar 2023 18:59:03 -0700 Subject: [PATCH 45/52] Helper method to make it easier (shorter) to determine if the app is in demo mode Signed-off-by: snipe --- app/Providers/SettingsServiceProvider.php | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.php index 8ab77c6631..f525cd1b09 100644 --- a/app/Providers/SettingsServiceProvider.php +++ b/app/Providers/SettingsServiceProvider.php @@ -150,6 +150,32 @@ class SettingsServiceProvider extends ServiceProvider // Set the monetary locale to the configured locale to make helper::parseFloat work. setlocale(LC_MONETARY, config('app.locale')); setlocale(LC_NUMERIC, config('app.locale')); + + + /* + * This is a shorter way to see if the app is in demo mode. + * + * This makes it cleanly available in blades and in controllers, e.g. + * + * Blade: + * {{ app('demo_mode') ? ' disabled' : ''}} for form blades where we need to disable a form + * + * Controller: + * if (app('demo_mode')) { + * // don't allow the thing + * } + * @todo - use this everywhere else in the app where we have very long if/else config('app.lock_passwords') stuff + */ + \App::singleton('demo_mode', function () { + if (config('app.lock_passwords') === true) { + return true; + } + return false; + }); + + + + } /** From b28a25f54402b42b2fd2f3a8546ca298380290d5 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 21 Mar 2023 18:59:18 -0700 Subject: [PATCH 46/52] Normalize the flash session to the way we do it elsewhere Signed-off-by: snipe --- app/Http/Livewire/SlackSettingsForm.php | 31 ++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index 6ba3b5b1a9..97750cd198 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -126,7 +126,7 @@ class SlackSettingsForm extends Component } //} - return session()->flash('message' , trans('admin/settings/message.webhook.error_misc')); + return session()->flash('error' , trans('admin/settings/message.webhook.error_misc')); } @@ -140,23 +140,28 @@ class SlackSettingsForm extends Component $this->setting->save(); - session()->flash('save',trans('admin/settings/message.update.success')); + session()->flash('success',trans('admin/settings/message.update.success')); } public function submit() { - if($this->webhook_selected != 'general') { - $this->validate($this->rules); + if (app('demo_mode')) { + session()->flash('error',trans('general.feature_disabled')); + } else { + if ($this->webhook_selected != 'general') { + $this->validate($this->rules); + } + + $this->setting->webhook_selected = $this->webhook_selected; + $this->setting->webhook_endpoint = $this->webhook_endpoint; + $this->setting->webhook_channel = $this->webhook_channel; + $this->setting->webhook_botname = $this->webhook_botname; + + $this->setting->save(); + + session()->flash('success',trans('admin/settings/message.update.success')); + } - $this->setting->webhook_selected = $this->webhook_selected; - $this->setting->webhook_endpoint = $this->webhook_endpoint; - $this->setting->webhook_channel = $this->webhook_channel; - $this->setting->webhook_botname = $this->webhook_botname; - - $this->setting->save(); - - session()->flash('save',trans('admin/settings/message.update.success')); - } } From 5217141dfb60a33a49e28aff932276c0403d9a5e Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 21 Mar 2023 18:59:34 -0700 Subject: [PATCH 47/52] Yuck, but added helper function to return the demo mode form warning Signed-off-by: snipe --- app/Helpers/Helper.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 1913c86286..095add6af4 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1147,4 +1147,14 @@ class Helper return $age; } + + /* + * I know it's gauche to return a shitty HTML string, but this is just a helper and since it will be the same every single time, + * it seemed pretty safe to do here. Don't you judge me. + */ + public function showDemoModeFieldWarning() { + if (app('demo_mode')) { + return "

" . trans('general.feature_disabled') . "

"; + } + } } From a14d1b981d733a403c6ed2052ea2b4d0bead50b5 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 21 Mar 2023 19:22:18 -0700 Subject: [PATCH 48/52] Switched singleton to static helper method Signed-off-by: snipe --- app/Helpers/Helper.php | 27 ++++++++++++++++++- app/Providers/SettingsServiceProvider.php | 24 ----------------- .../livewire/slack-settings-form.blade.php | 20 +++++++------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 095add6af4..276aa4db33 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -1148,12 +1148,37 @@ class Helper } + + /* + * This is a shorter way to see if the app is in demo mode. + * + * This makes it cleanly available in blades and in controllers, e.g. + * + * Blade: + * {{ app('demo_mode') ? ' disabled' : ''}} for form blades where we need to disable a form + * + * Controller: + * if (app('demo_mode')) { + * // don't allow the thing + * } + * @todo - use this everywhere else in the app where we have very long if/else config('app.lock_passwords') stuff + */ + public function isDemoMode() { + if (config('app.lock_passwords') === true) { + return true; + \Log::debug('app locked!'); + } + + return false; + } + + /* * I know it's gauche to return a shitty HTML string, but this is just a helper and since it will be the same every single time, * it seemed pretty safe to do here. Don't you judge me. */ public function showDemoModeFieldWarning() { - if (app('demo_mode')) { + if (Helper::isDemoMode()) { return "

" . trans('general.feature_disabled') . "

"; } } diff --git a/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.php index f525cd1b09..dc52ae1e3f 100644 --- a/app/Providers/SettingsServiceProvider.php +++ b/app/Providers/SettingsServiceProvider.php @@ -152,30 +152,6 @@ class SettingsServiceProvider extends ServiceProvider setlocale(LC_NUMERIC, config('app.locale')); - /* - * This is a shorter way to see if the app is in demo mode. - * - * This makes it cleanly available in blades and in controllers, e.g. - * - * Blade: - * {{ app('demo_mode') ? ' disabled' : ''}} for form blades where we need to disable a form - * - * Controller: - * if (app('demo_mode')) { - * // don't allow the thing - * } - * @todo - use this everywhere else in the app where we have very long if/else config('app.lock_passwords') stuff - */ - \App::singleton('demo_mode', function () { - if (config('app.lock_passwords') === true) { - return true; - } - return false; - }); - - - - } /** diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index 8fc6ac2c87..5634dfa1dd 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -58,14 +58,14 @@
-
- @if (app('demo_mode')) + @if (Helper::isDemoMode()) @include('partials.forms.demo-mode') @endif @@ -75,12 +75,12 @@ {{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => $webhook_name ])) }}
- + {!! $errors->first('webhook_endpoint', '') !!}
- @if (app('demo_mode')) + @if (Helper::isDemoMode()) @include('partials.forms.demo-mode') @endif @@ -91,13 +91,13 @@ {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }}
- + {!! $errors->first('webhook_channel', '') !!}
- @if (!app('demo_mode')) + @if (Helper::isDemoMode()) @include('partials.forms.demo-mode') @endif @@ -107,12 +107,12 @@ {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }}
- + {!! $errors->first('webhook_botname', '') !!}
- @if (app('demo_mode')) + @if (!Helper::isDemoMode()) @include('partials.forms.demo-mode') @endif @@ -140,13 +140,13 @@