From 31475043564c739a6ee3e2b4098d0116d9f5356e Mon Sep 17 00:00:00 2001 From: FredPeal Date: Fri, 23 Aug 2024 01:05:23 -0400 Subject: [PATCH 001/108] feat: add defaults field dashboard --- .../KanvasDashboardDefaultFieldCommand.php | 26 +++++++++++++++++ .../Auth/Actions/RegisterUsersAction.php | 1 - .../SetDefaultDashboardFieldAction.php | 28 +++++++++++++++++++ src/Kanvas/Dashboard/Enums/DashboardEnum.php | 8 ++++++ .../Repositories/DashboardRepositories.php | 19 +++++++++++++ .../DefaultFieldsDashboardActivities.php | 24 ++++++++++++++++ 6 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/KanvasDashboardDefaultFieldCommand.php create mode 100644 src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php create mode 100644 src/Kanvas/Dashboard/Enums/DashboardEnum.php create mode 100644 src/Kanvas/Dashboard/Repositories/DashboardRepositories.php create mode 100644 src/Kanvas/Dashboard/Workflows/Activities/DefaultFieldsDashboardActivities.php diff --git a/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php b/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php new file mode 100644 index 000000000..1752335ed --- /dev/null +++ b/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php @@ -0,0 +1,26 @@ +info("Setting default dashboard field..."); + $app = Apps::findOrFail($this->argument('app_id')); + foreach($app->companies as $company) { + (new SetDefaultDashboardFieldAction($company))->execute(); + } + } +} diff --git a/src/Kanvas/Auth/Actions/RegisterUsersAction.php b/src/Kanvas/Auth/Actions/RegisterUsersAction.php index fffb1e5f4..27993a822 100644 --- a/src/Kanvas/Auth/Actions/RegisterUsersAction.php +++ b/src/Kanvas/Auth/Actions/RegisterUsersAction.php @@ -63,7 +63,6 @@ public function execute(): Users if ($newUser) { $this->onBoarding($user, $company); } - if ($this->runWorkflow) { $user->fireWorkflow( WorkflowEnum::REGISTERED->value, diff --git a/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php b/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php new file mode 100644 index 000000000..0d9621d01 --- /dev/null +++ b/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php @@ -0,0 +1,28 @@ +company->get(DashboardEnum::DEFAULT_ENUM->value)) { + $defaultFields = DashboardRepositories::getDefaultFields(); + $fields = array_merge($defaultFields, $fields); + $this->company->set(DashboardEnum::DEFAULT_ENUM->value, $fields); + } else { + $defaultFields = DashboardRepositories::getDefaultFields(); + $this->company->set(DashboardEnum::DEFAULT_ENUM->value, $defaultFields); + } + } +} diff --git a/src/Kanvas/Dashboard/Enums/DashboardEnum.php b/src/Kanvas/Dashboard/Enums/DashboardEnum.php new file mode 100644 index 000000000..2cdffa69d --- /dev/null +++ b/src/Kanvas/Dashboard/Enums/DashboardEnum.php @@ -0,0 +1,8 @@ + 0, + 'total_users' => 0, + 'total_people' => 0, + 'total_companies' => 0, + 'total_products' => 0, + 'total_categories' => 0, + ]; + } +} diff --git a/src/Kanvas/Dashboard/Workflows/Activities/DefaultFieldsDashboardActivities.php b/src/Kanvas/Dashboard/Workflows/Activities/DefaultFieldsDashboardActivities.php new file mode 100644 index 000000000..89a1d4933 --- /dev/null +++ b/src/Kanvas/Dashboard/Workflows/Activities/DefaultFieldsDashboardActivities.php @@ -0,0 +1,24 @@ +execute(); + return [ + 'message' => 'Default fields dashboard activity executed', + ]; + } + +} From 3850c4adbc09244aace76905f0dc0b1941954fa0 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 23 Aug 2024 05:06:10 +0000 Subject: [PATCH 002/108] Apply fixes from StyleCI --- app/Console/Commands/KanvasDashboardDefaultFieldCommand.php | 3 ++- .../Dashboard/Actions/SetDefaultDashboardFieldAction.php | 3 ++- src/Kanvas/Dashboard/Enums/DashboardEnum.php | 2 ++ src/Kanvas/Dashboard/Repositories/DashboardRepositories.php | 1 + .../Workflows/Activities/DefaultFieldsDashboardActivities.php | 4 +--- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php b/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php index 1752335ed..713ac1a71 100644 --- a/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php +++ b/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php @@ -1,4 +1,5 @@ info("Setting default dashboard field..."); $app = Apps::findOrFail($this->argument('app_id')); - foreach($app->companies as $company) { + foreach ($app->companies as $company) { (new SetDefaultDashboardFieldAction($company))->execute(); } } diff --git a/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php b/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php index 0d9621d01..684aa6b45 100644 --- a/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php +++ b/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php @@ -1,4 +1,5 @@ company->get(DashboardEnum::DEFAULT_ENUM->value)) { + if ($fields = $this->company->get(DashboardEnum::DEFAULT_ENUM->value)) { $defaultFields = DashboardRepositories::getDefaultFields(); $fields = array_merge($defaultFields, $fields); $this->company->set(DashboardEnum::DEFAULT_ENUM->value, $fields); diff --git a/src/Kanvas/Dashboard/Enums/DashboardEnum.php b/src/Kanvas/Dashboard/Enums/DashboardEnum.php index 2cdffa69d..7c348a0fe 100644 --- a/src/Kanvas/Dashboard/Enums/DashboardEnum.php +++ b/src/Kanvas/Dashboard/Enums/DashboardEnum.php @@ -1,5 +1,7 @@ execute(); @@ -20,5 +19,4 @@ public function execute(Model $entity, AppInterface $app, array $params): array 'message' => 'Default fields dashboard activity executed', ]; } - } From 8a51b78ae2778979744de21c1ed299e15ffa3f46 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Fri, 23 Aug 2024 01:12:32 -0400 Subject: [PATCH 003/108] refactor: dashboard --- .../Queries/Companies/DashboardQuery.php | 25 +++++++++++++++++++ graphql/schemas/Ecosystem/company.graphql | 10 +++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/GraphQL/Ecosystem/Queries/Companies/DashboardQuery.php diff --git a/app/GraphQL/Ecosystem/Queries/Companies/DashboardQuery.php b/app/GraphQL/Ecosystem/Queries/Companies/DashboardQuery.php new file mode 100644 index 000000000..d0e8a39d1 --- /dev/null +++ b/app/GraphQL/Ecosystem/Queries/Companies/DashboardQuery.php @@ -0,0 +1,25 @@ +user()->getCurrentCompany(); + $fields = $company->get(DashboardEnum::DEFAULT_ENUM->value); + return [ + "name" => "dashboard", + "fields" => $fields + ]; + } +} diff --git a/graphql/schemas/Ecosystem/company.graphql b/graphql/schemas/Ecosystem/company.graphql index e66e5e1c6..0f4eaaa35 100644 --- a/graphql/schemas/Ecosystem/company.graphql +++ b/graphql/schemas/Ecosystem/company.graphql @@ -152,7 +152,10 @@ enum CompanyOrderColumn{ CREATED_AT @enum(value: "companies.created_at") UPDATED_AT @enum(value: "companies.updated_at") } - +type Dashboard { + name: String! + fields: JSON! +} extend type Query @guard { companies( search: String @search @@ -237,6 +240,11 @@ extend type Query @guard { @field( resolver: "App\\GraphQL\\Ecosystem\\Queries\\Companies\\CompanySettingQuery@getAllSettings" ) + + dashboard: Dashboard! + @field( + resolver: "App\\GraphQL\\Ecosystem\\Queries\\Companies\\DashboardQuery@getDashboard" + ) } extend type Mutation @guardByAdmin { From 600ac49f74f4300efc5ca340161a5867eed060c3 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Fri, 23 Aug 2024 12:24:04 -0400 Subject: [PATCH 004/108] refactor: set by cli --- .../Commands/KanvasDashboardDefaultFieldCommand.php | 6 ++++-- .../Dashboard/Actions/SetDefaultDashboardFieldAction.php | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php b/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php index 713ac1a71..c805fd750 100644 --- a/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php +++ b/app/Console/Commands/KanvasDashboardDefaultFieldCommand.php @@ -12,7 +12,7 @@ class KanvasDashboardDefaultFieldCommand extends Command { - protected $signature = "kanvas:dashboard-default-field {app_id}"; + protected $signature = "kanvas:dashboard-default-field {app_id} {field} {value}"; protected $description = "Set default dashboard field"; @@ -20,8 +20,10 @@ public function handle(): void { $this->info("Setting default dashboard field..."); $app = Apps::findOrFail($this->argument('app_id')); + $field = $this->argument('field'); + $value = $this->argument('value'); foreach ($app->companies as $company) { - (new SetDefaultDashboardFieldAction($company))->execute(); + (new SetDefaultDashboardFieldAction($company, $field, $value))->execute(); } } } diff --git a/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php b/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php index 684aa6b45..efad03168 100644 --- a/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php +++ b/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php @@ -12,11 +12,18 @@ class SetDefaultDashboardFieldAction { public function __construct( public Companies $company, + public string $field, + public string $value ) { } public function execute() { + if($this->field){ + $fields = $this->company->get(DashboardEnum::DEFAULT_ENUM->value); + $fields[$this->field] = $this->value; + $this->company->set(DashboardEnum::DEFAULT_ENUM->value, $fields); + } if ($fields = $this->company->get(DashboardEnum::DEFAULT_ENUM->value)) { $defaultFields = DashboardRepositories::getDefaultFields(); $fields = array_merge($defaultFields, $fields); From 634b443a1c24d3655cf9060e2e10d182c771c6a3 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 23 Aug 2024 17:02:46 +0000 Subject: [PATCH 005/108] Apply fixes from StyleCI --- src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php b/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php index efad03168..746824d64 100644 --- a/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php +++ b/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php @@ -19,7 +19,7 @@ public function __construct( public function execute() { - if($this->field){ + if ($this->field) { $fields = $this->company->get(DashboardEnum::DEFAULT_ENUM->value); $fields[$this->field] = $this->value; $this->company->set(DashboardEnum::DEFAULT_ENUM->value, $fields); From 720d2a8d375295e87e76c38f8e8dead9897f1c33 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Mon, 26 Aug 2024 02:13:24 -0400 Subject: [PATCH 006/108] refactor: move to dashboard --- .../SetDefaultDashboardFieldAction.php | 35 ++++++++++++++++++ .../Dashboard/Enums/DashboardEnum.php | 0 .../Repositories/DashboardRepositories.php | 0 .../DefaultFieldsDashboardActivities.php | 0 .../SetDefaultDashboardFieldAction.php | 36 ------------------- 5 files changed, 35 insertions(+), 36 deletions(-) create mode 100644 src/Domains/Dashboard/Actions/SetDefaultDashboardFieldAction.php rename src/{Kanvas => Domains}/Dashboard/Enums/DashboardEnum.php (100%) rename src/{Kanvas => Domains}/Dashboard/Repositories/DashboardRepositories.php (100%) rename src/{Kanvas => Domains}/Dashboard/Workflows/Activities/DefaultFieldsDashboardActivities.php (100%) delete mode 100644 src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php diff --git a/src/Domains/Dashboard/Actions/SetDefaultDashboardFieldAction.php b/src/Domains/Dashboard/Actions/SetDefaultDashboardFieldAction.php new file mode 100644 index 000000000..c4224f08c --- /dev/null +++ b/src/Domains/Dashboard/Actions/SetDefaultDashboardFieldAction.php @@ -0,0 +1,35 @@ +value; + $fields = $this->company->get($defaultEnumValue) ?? []; + + if (!is_null($this->field)) { + $fields[$this->field] = $this->value; + $this->company->set($defaultEnumValue, $fields); + } + + $defaultFields = DashboardRepositories::getDefaultFields(); + $mergedFields = array_merge($defaultFields, $fields); + + $this->company->set($defaultEnumValue, $mergedFields); + } +} diff --git a/src/Kanvas/Dashboard/Enums/DashboardEnum.php b/src/Domains/Dashboard/Enums/DashboardEnum.php similarity index 100% rename from src/Kanvas/Dashboard/Enums/DashboardEnum.php rename to src/Domains/Dashboard/Enums/DashboardEnum.php diff --git a/src/Kanvas/Dashboard/Repositories/DashboardRepositories.php b/src/Domains/Dashboard/Repositories/DashboardRepositories.php similarity index 100% rename from src/Kanvas/Dashboard/Repositories/DashboardRepositories.php rename to src/Domains/Dashboard/Repositories/DashboardRepositories.php diff --git a/src/Kanvas/Dashboard/Workflows/Activities/DefaultFieldsDashboardActivities.php b/src/Domains/Dashboard/Workflows/Activities/DefaultFieldsDashboardActivities.php similarity index 100% rename from src/Kanvas/Dashboard/Workflows/Activities/DefaultFieldsDashboardActivities.php rename to src/Domains/Dashboard/Workflows/Activities/DefaultFieldsDashboardActivities.php diff --git a/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php b/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php deleted file mode 100644 index 746824d64..000000000 --- a/src/Kanvas/Dashboard/Actions/SetDefaultDashboardFieldAction.php +++ /dev/null @@ -1,36 +0,0 @@ -field) { - $fields = $this->company->get(DashboardEnum::DEFAULT_ENUM->value); - $fields[$this->field] = $this->value; - $this->company->set(DashboardEnum::DEFAULT_ENUM->value, $fields); - } - if ($fields = $this->company->get(DashboardEnum::DEFAULT_ENUM->value)) { - $defaultFields = DashboardRepositories::getDefaultFields(); - $fields = array_merge($defaultFields, $fields); - $this->company->set(DashboardEnum::DEFAULT_ENUM->value, $fields); - } else { - $defaultFields = DashboardRepositories::getDefaultFields(); - $this->company->set(DashboardEnum::DEFAULT_ENUM->value, $defaultFields); - } - } -} From d5d125704f9bcc4f539ce3bf94031fb0302123ac Mon Sep 17 00:00:00 2001 From: FredPeal Date: Mon, 26 Aug 2024 02:13:36 -0400 Subject: [PATCH 007/108] refactor: add dashboard composer json --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index c1eecf08a..90fe5a9a1 100644 --- a/composer.json +++ b/composer.json @@ -77,6 +77,7 @@ "Kanvas\\Souk\\": "src/Domains/Souk", "Kanvas\\Workflow\\": "src/Domains/Workflow", "Kanvas\\Connectors\\": "src/Domains/Connectors", + "Kanvas\\Dashboard\\": "src/Domains/Dashboard", "Kanvas\\ActionEngine\\": "src/Domains/ActionEngine", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" From 0c7e4e02fea32a035febeecc8aa2696371137f5a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 26 Aug 2024 21:16:57 +0000 Subject: [PATCH 008/108] Apply fixes from StyleCI --- .../Dashboard/Actions/SetDefaultDashboardFieldAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Dashboard/Actions/SetDefaultDashboardFieldAction.php b/src/Domains/Dashboard/Actions/SetDefaultDashboardFieldAction.php index c4224f08c..f0fdd288f 100644 --- a/src/Domains/Dashboard/Actions/SetDefaultDashboardFieldAction.php +++ b/src/Domains/Dashboard/Actions/SetDefaultDashboardFieldAction.php @@ -22,7 +22,7 @@ public function execute(): void $defaultEnumValue = DashboardEnum::DEFAULT_ENUM->value; $fields = $this->company->get($defaultEnumValue) ?? []; - if (!is_null($this->field)) { + if (! is_null($this->field)) { $fields[$this->field] = $this->value; $this->company->set($defaultEnumValue, $fields); } From 98649be8a5e9438604a5ed3f60b88403eaccbd72 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Tue, 27 Aug 2024 05:01:29 -0400 Subject: [PATCH 009/108] fix: Deletion restriction of linked elements --- app/Providers/EventServiceProvider.php | 3 +++ .../ProductsTypes/Models/ProductsTypes.php | 5 +++++ .../Observers/ProductsTypesObserver.php | 18 ++++++++++++++++++ src/Domains/Inventory/Status/Models/Status.php | 11 ++++++++--- .../Status/Observers/StatusObserver.php | 4 ++++ .../Inventory/Variants/Models/Variants.php | 11 +++++++++++ .../Variants/Observers/VariantObserver.php | 10 +++++++++- 7 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/Domains/Inventory/ProductsTypes/Observers/ProductsTypesObserver.php diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 94546f30a..d06d73fb2 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -22,6 +22,8 @@ use Kanvas\Inventory\Products\Models\Products; use Kanvas\Inventory\Products\Models\ProductsCategories; use Kanvas\Inventory\Products\Observers\ProductsObserver; +use Kanvas\Inventory\ProductsTypes\Models\ProductsTypes; +use Kanvas\Inventory\ProductsTypes\Observers\ProductsTypesObserver; use Kanvas\Inventory\Regions\Models\Regions; use Kanvas\Inventory\Regions\Observers\RegionObserver; use Kanvas\Inventory\Status\Models\Status; @@ -84,6 +86,7 @@ public function boot() VariantsWarehouses::observe(VariantsWarehouseObserver::class); Channels::observe(ChannelObserver::class); Products::observe(ProductsObserver::class); + ProductsTypes::observe(ProductsTypesObserver::class); Variants::observe(VariantObserver::class); VariantsChannels::observe(VariantsChannelObserver::class); UsersAssociatedApps::observe(UsersAssociatedAppsObserver::class); diff --git a/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php b/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php index 936022192..c51ad851a 100644 --- a/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php +++ b/src/Domains/Inventory/ProductsTypes/Models/ProductsTypes.php @@ -126,4 +126,9 @@ public static function newFactory() { return new ProductTypeFactory(); } + + public function hasDependencies(): bool + { + return $this->products()->exists(); + } } diff --git a/src/Domains/Inventory/ProductsTypes/Observers/ProductsTypesObserver.php b/src/Domains/Inventory/ProductsTypes/Observers/ProductsTypesObserver.php new file mode 100644 index 000000000..85fdf5ea4 --- /dev/null +++ b/src/Domains/Inventory/ProductsTypes/Observers/ProductsTypesObserver.php @@ -0,0 +1,18 @@ +hasDependencies()) { + throw new ValidationException('Can\'t delete, ProductType has products associated'); + } + } +} diff --git a/src/Domains/Inventory/Status/Models/Status.php b/src/Domains/Inventory/Status/Models/Status.php index 7b3641164..1d785071c 100644 --- a/src/Domains/Inventory/Status/Models/Status.php +++ b/src/Domains/Inventory/Status/Models/Status.php @@ -9,7 +9,7 @@ use Kanvas\Inventory\Models\BaseModel; use Baka\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\DefaultTrait; -use Kanvas\Inventory\Variants\Models\Variants; +use Kanvas\Inventory\Products\Models\Products; use Kanvas\Inventory\Variants\Models\VariantsWarehouses; /** @@ -34,13 +34,18 @@ class Status extends BaseModel /** * Get the user that owns the Variants. */ - public function variants(): HasMany + public function products(): HasMany { - return $this->hasMany(Variants::class, 'status_id'); + return $this->hasMany(Products::class, 'status_id'); } public function variantWarehouses(): HasMany { return $this->hasMany(VariantsWarehouses::class, 'products_variants_id'); } + + public function hasDependencies():bool + { + return $this->products()->exists(); + } } diff --git a/src/Domains/Inventory/Status/Observers/StatusObserver.php b/src/Domains/Inventory/Status/Observers/StatusObserver.php index e880ce303..9c7d634b8 100644 --- a/src/Domains/Inventory/Status/Observers/StatusObserver.php +++ b/src/Domains/Inventory/Status/Observers/StatusObserver.php @@ -45,6 +45,10 @@ public function updating(Status $status): void public function deleting(Status $status): void { + if ($status->hasDependencies()) { + throw new ValidationException('Can\'t delete, Status has products associated'); + } + $defaultStatus = $status::getDefault($status->company); if ($defaultStatus->getId() == $status->getId()) { diff --git a/src/Domains/Inventory/Variants/Models/Variants.php b/src/Domains/Inventory/Variants/Models/Variants.php index bdb2ed0bb..db249ef6f 100644 --- a/src/Domains/Inventory/Variants/Models/Variants.php +++ b/src/Domains/Inventory/Variants/Models/Variants.php @@ -368,4 +368,15 @@ public function setTotalQuantity(): int return (int) $total; } + + /** + * Determine if this is the last variant for the product. + */ + public function isLastVariant(): bool + { + return self::where('products_id', $this->product_id) + ->where('companies_id', $this->company_id) + ->where('is_deleted', 0) + ->count() === 1; + } } diff --git a/src/Domains/Inventory/Variants/Observers/VariantObserver.php b/src/Domains/Inventory/Variants/Observers/VariantObserver.php index 977f31c90..a20b0bc05 100644 --- a/src/Domains/Inventory/Variants/Observers/VariantObserver.php +++ b/src/Domains/Inventory/Variants/Observers/VariantObserver.php @@ -4,12 +4,20 @@ namespace Kanvas\Inventory\Variants\Observers; +use Kanvas\Exceptions\ValidationException; use Kanvas\Inventory\Variants\Models\Variants; class VariantObserver -{ +{ public function saved(Variants $variant): void { $variant->clearLightHouseCache(); } + + public function deleting(Variants $variant): void + { + if ($variant->isLastVariant()) { + throw new ValidationException('Can\'t delete, you have to have at least one Variant per product'); + } + } } From 872efa8746ab2f82fba76045c618f2fa403ce756 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Tue, 20 Aug 2024 14:23:45 +0000 Subject: [PATCH 010/108] Fix Prevent Duplicate Attribute Slug --- .../Attributes/Actions/CreateAttribute.php | 14 +- .../Attributes/Actions/UpdateAttribute.php | 20 +- .../Support/Validations/UniqueSlugRule.php | 3 +- tests/GraphQL/Inventory/AttributesTest.php | 173 ++++++++++-------- 4 files changed, 125 insertions(+), 85 deletions(-) diff --git a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php index 18e210fb4..1ad9ce85f 100644 --- a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php @@ -8,6 +8,9 @@ use Kanvas\Companies\Repositories\CompaniesRepository; use Kanvas\Inventory\Attributes\DataTransferObject\Attributes as AttributeDto; use Kanvas\Inventory\Attributes\Models\Attributes; +use Kanvas\Inventory\Support\Validations\UniqueSlugRule; +use Illuminate\Support\Facades\Validator; +use Illuminate\Validation\ValidationException; class CreateAttribute { @@ -23,7 +26,16 @@ public function __construct( * @return Attributes */ public function execute(): Attributes - { + { + $validator = Validator::make( + ['slug' => $this->dto->slug], + ['slug' => [new UniqueSlugRule($this->dto->app, $this->dto->company, null)]] + ); + + if ($validator->fails()) { + throw new ValidationException($validator); + } + CompaniesRepository::userAssociatedToCompany( $this->dto->company, $this->user diff --git a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php index 392b7fbca..16b8ce142 100644 --- a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php @@ -8,6 +8,9 @@ use Kanvas\Companies\Repositories\CompaniesRepository; use Kanvas\Inventory\Attributes\DataTransferObject\Attributes as AttributeDto; use Kanvas\Inventory\Attributes\Models\Attributes; +use Kanvas\Inventory\Support\Validations\UniqueSlugRule; +use Illuminate\Support\Facades\Validator; +use Illuminate\Validation\ValidationException; class UpdateAttribute { @@ -24,10 +27,19 @@ public function __construct( * @return Attributes */ public function execute(): Attributes - { - CompaniesRepository::userAssociatedToCompany( - $this->dto->company, - $this->user + { + $validator = Validator::make( + ['slug' => $this->dto->slug], + ['slug' => [new UniqueSlugRule($this->dto->app, $this->dto->company, $this->attribute)]] + ); + + if ($validator->fails()) { + throw new ValidationException($validator); + } + + CompaniesRepository::userAssociatedToCompany( + $this->dto->company, + $this->user ); $this->attribute->update([ diff --git a/src/Domains/Inventory/Support/Validations/UniqueSlugRule.php b/src/Domains/Inventory/Support/Validations/UniqueSlugRule.php index 337319140..15f491922 100644 --- a/src/Domains/Inventory/Support/Validations/UniqueSlugRule.php +++ b/src/Domains/Inventory/Support/Validations/UniqueSlugRule.php @@ -9,6 +9,7 @@ use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Kanvas\Inventory\Models\BaseModel; +use Kanvas\Inventory\Attributes\Models\Attributes; class UniqueSlugRule implements ValidationRule { @@ -21,7 +22,7 @@ public function __construct( public function validate(string $attribute, mixed $value, Closure $fail): void { - $query = $this->model::where('slug', $value) + $query = $this->model ? $this->model::where('slug', $value) : Attributes::where('slug', $value) ->fromCompany($this->company) ->fromApp($this->app); diff --git a/tests/GraphQL/Inventory/AttributesTest.php b/tests/GraphQL/Inventory/AttributesTest.php index b867ca69d..3ed954998 100644 --- a/tests/GraphQL/Inventory/AttributesTest.php +++ b/tests/GraphQL/Inventory/AttributesTest.php @@ -15,27 +15,9 @@ class AttributesTest extends TestCase */ public function testCreate(): void { - $data = [ - 'name' => fake()->name, - 'values' => [ - [ - 'value' => fake()->name - ] - ] - ]; + $response = $this->createAttribute(); - $response = $this->graphQL(' - mutation($data: AttributeInput!) { - createAttribute(input: $data) - { - name - values { - value - } - } - }', ['data' => $data]); - - $this->assertArrayHasKey('name', $response->json()['data']['createAttribute']); + $this->assertArrayHasKey('name', $response['data']['createAttribute']); } /** @@ -45,26 +27,9 @@ public function testCreate(): void */ public function testSearch(): void { - $data = [ - 'name' => fake()->name, - 'values' => [ - [ - 'value' => fake()->name - ] - ] - ]; - $response = $this->graphQL(' - mutation($data: AttributeInput!) { - createAttribute(input: $data) - { - name - values { - value - } - } - }', ['data' => $data]); + $response = $this->createAttribute(); - $this->assertArrayHasKey('name', $response->json()['data']['createAttribute']); + $this->assertArrayHasKey('name', $response['data']['createAttribute']); $response = $this->graphQL(' query { @@ -77,6 +42,7 @@ public function testSearch(): void } } }'); + $this->assertArrayHasKey('name', $response->json()['data']['attributes']['data'][0]); } @@ -87,30 +53,9 @@ public function testSearch(): void */ public function testUpdate(): void { - $data = [ - 'name' => fake()->name, - 'values' => [ - [ - 'value' => fake()->name - ] - ] - ]; - $response = $this->graphQL(' - mutation($data: AttributeInput!) { - createAttribute(input: $data) - { - id - name - values { - value - } - } - }', ['data' => $data])->json()['data']['createAttribute']; - - $this->assertArrayHasKey('name', $response); - + $response = $this->createAttribute(); + $id = $response['data']['createAttribute']['id']; - $id = $response['id']; $dataUpdate = [ 'name' => fake()->name ]; @@ -135,36 +80,106 @@ public function testUpdate(): void * @return void */ public function testDelete(): void + { + $response = $this->createAttribute(); + $id = $response['data']['createAttribute']['id']; + + $this->graphQL(' + mutation($id: ID!) { + deleteAttribute(id: $id) + }', ['id' => $id])->assertJson([ + 'data' => ['deleteAttribute' => true] + ]); + } + + /** + * testCreateDuplicatedSlug. + * + * @return void + */ + public function testCreateDuplicatedSlug(): void + { + $slug = 'unique-slug-test-' . fake()->uuid; + + $response = $this->createAttribute($slug); + + if (isset($response['errors'])) { + $this->fail('Unexpected error: ' . json_encode($response['errors'])); + } + + $response2 = $this->createAttribute($slug); + + $this->assertArrayHasKey('errors', $response2, 'Expected error not found.'); + $this->assertStringContainsString('slug', json_encode($response2['errors']), 'Error does not mention slug.'); + } + + /** + * testUpdateDuplicatedSlug. + * + * @return void + */ + public function testUpdateDuplicatedSlug(): void + { + $slug = 'unique-slug-update-test-' . fake()->uuid; + $response = $this->createAttribute($slug); + + $slug2 = 'another-unique-slug-' . fake()->uuid; + $response2 = $this->createAttribute($slug2); + + $response3 = $this->graphQL(' + mutation($id: ID!, $data: AttributeUpdateInput!) { + updateAttribute(id: $id, input: $data) + { + id + name + slug + } + }', [ + 'id' => $response2['data']['createAttribute']['id'], + 'data' => [ + 'name' => 'Updated Name', + 'slug' => $slug, + ] + ])->json(); + + $this->assertArrayHasKey('errors', $response3); + $this->assertEquals( + 'The slug has already been taken.', + $response3['errors'][0]['message'] + ); + } + + /** + * Helper function createAttribute. + * + * @param string|null $slug + * + * @return array + */ + private function createAttribute(?string $slug = null): array { $data = [ 'name' => fake()->name, 'values' => [ - [ - 'value' => fake()->name - ] - ] + ['value' => fake()->name], + ], ]; - $response = $this->graphQL(' + + if ($slug) { + $data['slug'] = $slug; + } + + return $this->graphQL(' mutation($data: AttributeInput!) { createAttribute(input: $data) { id name + slug values { value } } - }', ['data' => $data])->json()['data']['createAttribute']; - - $this->assertArrayHasKey('name', $response); - - - $id = $response['id']; - $this->graphQL(' - mutation($id: ID!) { - deleteAttribute(id: $id) - }', ['id' => $id])->assertJson([ - 'data' => ['deleteAttribute' => true] - ]); + }', ['data' => $data])->json(); } } From 6abfb6778f25447752cfd4e68138bf5405d2517f Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Tue, 20 Aug 2024 18:05:42 +0000 Subject: [PATCH 011/108] Implement feedback: [Return current attributes in case of duplicate slugs] --- .../Attributes/Actions/CreateAttribute.php | 16 ++--------- .../Attributes/Actions/UpdateAttribute.php | 27 +++++++++---------- .../Support/Validations/UniqueSlugRule.php | 3 +-- tests/GraphQL/Inventory/AttributesTest.php | 21 +++++++-------- 4 files changed, 24 insertions(+), 43 deletions(-) diff --git a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php index 1ad9ce85f..39795107a 100644 --- a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php @@ -8,9 +8,6 @@ use Kanvas\Companies\Repositories\CompaniesRepository; use Kanvas\Inventory\Attributes\DataTransferObject\Attributes as AttributeDto; use Kanvas\Inventory\Attributes\Models\Attributes; -use Kanvas\Inventory\Support\Validations\UniqueSlugRule; -use Illuminate\Support\Facades\Validator; -use Illuminate\Validation\ValidationException; class CreateAttribute { @@ -27,27 +24,18 @@ public function __construct( */ public function execute(): Attributes { - $validator = Validator::make( - ['slug' => $this->dto->slug], - ['slug' => [new UniqueSlugRule($this->dto->app, $this->dto->company, null)]] - ); - - if ($validator->fails()) { - throw new ValidationException($validator); - } - CompaniesRepository::userAssociatedToCompany( $this->dto->company, $this->user ); return Attributes::firstOrCreate([ - 'name' => $this->dto->name, + 'slug' => $this->dto->slug, 'companies_id' => $this->dto->company->getId(), 'apps_id' => $this->dto->app->getId(), ], [ + 'name' => $this->dto->name, 'users_id' => $this->user->getId(), - 'slug' => $this->dto->slug, 'attributes_type_id' => $this->dto->attributeType?->getId(), 'is_visible' => $this->dto->isVisible, 'is_searchable' => $this->dto->isSearchable, diff --git a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php index 16b8ce142..b2485cf20 100644 --- a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php @@ -8,9 +8,6 @@ use Kanvas\Companies\Repositories\CompaniesRepository; use Kanvas\Inventory\Attributes\DataTransferObject\Attributes as AttributeDto; use Kanvas\Inventory\Attributes\Models\Attributes; -use Kanvas\Inventory\Support\Validations\UniqueSlugRule; -use Illuminate\Support\Facades\Validator; -use Illuminate\Validation\ValidationException; class UpdateAttribute { @@ -28,27 +25,27 @@ public function __construct( */ public function execute(): Attributes { - $validator = Validator::make( - ['slug' => $this->dto->slug], - ['slug' => [new UniqueSlugRule($this->dto->app, $this->dto->company, $this->attribute)]] + CompaniesRepository::userAssociatedToCompany( + $this->dto->company, + $this->user ); + + $existingAttribute = Attributes::where('slug', $this->dto->slug) + ->fromCompany($this->dto->company) + ->fromApp($this->dto->app) + ->first(); - if ($validator->fails()) { - throw new ValidationException($validator); - } - - CompaniesRepository::userAssociatedToCompany( - $this->dto->company, - $this->user - ); + $slug = ($existingAttribute && $existingAttribute->id !== $this->attribute->id) + ? $this->attribute->slug + : $this->dto->slug; $this->attribute->update([ + 'slug' => $slug, 'name' => $this->dto->name, 'attributes_type_id' => $this->dto->attributeType?->getId(), 'is_visible' => $this->dto->isVisible, 'is_searchable' => $this->dto->isSearchable, 'is_filtrable' => $this->dto->isFiltrable, - 'slug' => $this->dto->slug, ]); return $this->attribute; diff --git a/src/Domains/Inventory/Support/Validations/UniqueSlugRule.php b/src/Domains/Inventory/Support/Validations/UniqueSlugRule.php index 15f491922..337319140 100644 --- a/src/Domains/Inventory/Support/Validations/UniqueSlugRule.php +++ b/src/Domains/Inventory/Support/Validations/UniqueSlugRule.php @@ -9,7 +9,6 @@ use Closure; use Illuminate\Contracts\Validation\ValidationRule; use Kanvas\Inventory\Models\BaseModel; -use Kanvas\Inventory\Attributes\Models\Attributes; class UniqueSlugRule implements ValidationRule { @@ -22,7 +21,7 @@ public function __construct( public function validate(string $attribute, mixed $value, Closure $fail): void { - $query = $this->model ? $this->model::where('slug', $value) : Attributes::where('slug', $value) + $query = $this->model::where('slug', $value) ->fromCompany($this->company) ->fromApp($this->app); diff --git a/tests/GraphQL/Inventory/AttributesTest.php b/tests/GraphQL/Inventory/AttributesTest.php index 3ed954998..d44cc506c 100644 --- a/tests/GraphQL/Inventory/AttributesTest.php +++ b/tests/GraphQL/Inventory/AttributesTest.php @@ -102,15 +102,14 @@ public function testCreateDuplicatedSlug(): void $slug = 'unique-slug-test-' . fake()->uuid; $response = $this->createAttribute($slug); - - if (isset($response['errors'])) { - $this->fail('Unexpected error: ' . json_encode($response['errors'])); - } + $firstAttributeId = $response['data']['createAttribute']['id']; $response2 = $this->createAttribute($slug); - $this->assertArrayHasKey('errors', $response2, 'Expected error not found.'); - $this->assertStringContainsString('slug', json_encode($response2['errors']), 'Error does not mention slug.'); + $this->assertEquals( + $firstAttributeId, + $response2['data']['createAttribute']['id'] + ); } /** @@ -128,8 +127,7 @@ public function testUpdateDuplicatedSlug(): void $response3 = $this->graphQL(' mutation($id: ID!, $data: AttributeUpdateInput!) { - updateAttribute(id: $id, input: $data) - { + updateAttribute(id: $id, input: $data) { id name slug @@ -142,13 +140,12 @@ public function testUpdateDuplicatedSlug(): void ] ])->json(); - $this->assertArrayHasKey('errors', $response3); $this->assertEquals( - 'The slug has already been taken.', - $response3['errors'][0]['message'] + $slug2, + $response3['data']['updateAttribute']['slug'] ); } - + /** * Helper function createAttribute. * From 492ad9fbce97b6c918d26839598aa42aa97a07e1 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Tue, 20 Aug 2024 16:46:38 -0400 Subject: [PATCH 012/108] Implement feedback: [Refactor attribute creation] --- .../Attributes/Actions/CreateAttribute.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php index 39795107a..1a82823d9 100644 --- a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php @@ -23,23 +23,34 @@ public function __construct( * @return Attributes */ public function execute(): Attributes - { + { CompaniesRepository::userAssociatedToCompany( $this->dto->company, $this->user ); + if ($this->dto->slug) { + $existingAttribute = Attributes::where('slug', $this->dto->slug) + ->fromCompany($this->dto->company) + ->fromApp($this->dto->app) + ->first(); + + if ($existingAttribute) { + return $existingAttribute; + } + } + return Attributes::firstOrCreate([ 'slug' => $this->dto->slug, 'companies_id' => $this->dto->company->getId(), 'apps_id' => $this->dto->app->getId(), ], [ - 'name' => $this->dto->name, 'users_id' => $this->user->getId(), + 'name' => $this->dto->name, 'attributes_type_id' => $this->dto->attributeType?->getId(), 'is_visible' => $this->dto->isVisible, 'is_searchable' => $this->dto->isSearchable, 'is_filtrable' => $this->dto->isFiltrable, ]); } -} +} \ No newline at end of file From 1501028bac2fe068e86ca316b04e3b8b505d4024 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Thu, 22 Aug 2024 11:42:14 -0400 Subject: [PATCH 013/108] Implement feedback: [Refactor actions using SlugTrait] --- src/Baka/Traits/SlugTrait.php | 10 ++++++---- .../Attributes/Actions/CreateAttribute.php | 15 +++++++-------- .../Attributes/Actions/UpdateAttribute.php | 9 +++++---- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Baka/Traits/SlugTrait.php b/src/Baka/Traits/SlugTrait.php index 6dae823b7..421131544 100644 --- a/src/Baka/Traits/SlugTrait.php +++ b/src/Baka/Traits/SlugTrait.php @@ -29,11 +29,13 @@ public static function bootSlugTrait() /** * Get Model. */ - public static function getBySlug(string $slug, CompanyInterface $company): self + public static function getBySlug(string $slug, CompanyInterface $company, int $appId, bool $fail = false): ?self { - return self::where('slug', $slug) + $query = self::where('slug', $slug) ->where('companies_id', $company->getId()) - ->where('is_deleted', StateEnums::NO->getValue()) - ->firstOrFail(); + ->where('apps_id', $appId) + ->where('is_deleted', StateEnums::NO->getValue()); + + return $fail ? $query->firstOrFail() : $query->first(); } } diff --git a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php index 1a82823d9..b3fe54956 100644 --- a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php @@ -29,17 +29,16 @@ public function execute(): Attributes $this->user ); - if ($this->dto->slug) { - $existingAttribute = Attributes::where('slug', $this->dto->slug) - ->fromCompany($this->dto->company) - ->fromApp($this->dto->app) - ->first(); - + $existingAttribute = Attributes::getBySlug( + $this->dto->slug, + $this->dto->company, + $this->dto->app->getId() + ); + if ($existingAttribute) { return $existingAttribute; } - } - + return Attributes::firstOrCreate([ 'slug' => $this->dto->slug, 'companies_id' => $this->dto->company->getId(), diff --git a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php index b2485cf20..da2ba639e 100644 --- a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php @@ -30,10 +30,11 @@ public function execute(): Attributes $this->user ); - $existingAttribute = Attributes::where('slug', $this->dto->slug) - ->fromCompany($this->dto->company) - ->fromApp($this->dto->app) - ->first(); + $existingAttribute = Attributes::getBySlug( + $this->dto->slug, + $this->dto->company, + $this->dto->app->getId() + ); $slug = ($existingAttribute && $existingAttribute->id !== $this->attribute->id) ? $this->attribute->slug From 294c10b816e1645522a4ec91f84d9d1c0a2f8c25 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Thu, 22 Aug 2024 23:50:27 -0400 Subject: [PATCH 014/108] Implement feedback: [split SlugTrait methods] --- src/Baka/Traits/SlugTrait.php | 23 +++++++++++++------ .../Attributes/Actions/CreateAttribute.php | 1 - .../Attributes/Actions/UpdateAttribute.php | 1 - 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Baka/Traits/SlugTrait.php b/src/Baka/Traits/SlugTrait.php index 421131544..a8890743d 100644 --- a/src/Baka/Traits/SlugTrait.php +++ b/src/Baka/Traits/SlugTrait.php @@ -27,15 +27,24 @@ public static function bootSlugTrait() } /** - * Get Model. + * Get Model by Slug firstOrFail. */ - public static function getBySlug(string $slug, CompanyInterface $company, int $appId, bool $fail = false): ?self + public static function getBySlugOrFail(string $slug, CompanyInterface $company): self { - $query = self::where('slug', $slug) + return self::where('slug', $slug) ->where('companies_id', $company->getId()) - ->where('apps_id', $appId) - ->where('is_deleted', StateEnums::NO->getValue()); - - return $fail ? $query->firstOrFail() : $query->first(); + ->where('is_deleted', StateEnums::NO->getValue()) + ->firstOrFail(); } + /** + * Get Model by Slug. + */ + public static function getBySlug(string $slug, CompanyInterface $company): ?self + { + return self::where('slug', $slug) + ->where('companies_id', $company->getId()) + ->where('is_deleted', StateEnums::NO->getValue()) + ->first(); + } + } diff --git a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php index b3fe54956..06c222dbc 100644 --- a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php @@ -32,7 +32,6 @@ public function execute(): Attributes $existingAttribute = Attributes::getBySlug( $this->dto->slug, $this->dto->company, - $this->dto->app->getId() ); if ($existingAttribute) { diff --git a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php index da2ba639e..079c98abd 100644 --- a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php @@ -33,7 +33,6 @@ public function execute(): Attributes $existingAttribute = Attributes::getBySlug( $this->dto->slug, $this->dto->company, - $this->dto->app->getId() ); $slug = ($existingAttribute && $existingAttribute->id !== $this->attribute->id) From da945981743176623c627633dbfd21b8be739fa1 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Fri, 23 Aug 2024 11:52:33 -0400 Subject: [PATCH 015/108] Implement feedback: [Refactor actions using SlugTrait, 3 methods] --- src/Baka/Traits/SlugTrait.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Baka/Traits/SlugTrait.php b/src/Baka/Traits/SlugTrait.php index a8890743d..50f8e75e9 100644 --- a/src/Baka/Traits/SlugTrait.php +++ b/src/Baka/Traits/SlugTrait.php @@ -7,6 +7,8 @@ use Baka\Contracts\CompanyInterface; use Baka\Enums\StateEnums; use Illuminate\Support\Str; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; trait SlugTrait { @@ -29,22 +31,27 @@ public static function bootSlugTrait() /** * Get Model by Slug firstOrFail. */ - public static function getBySlugOrFail(string $slug, CompanyInterface $company): self + public static function getBySlugOrFail(string $slug, CompanyInterface $company): Model { - return self::where('slug', $slug) - ->where('companies_id', $company->getId()) - ->where('is_deleted', StateEnums::NO->getValue()) - ->firstOrFail(); + return self::query($slug, $company)->firstOrFail(); } + /** * Get Model by Slug. */ public static function getBySlug(string $slug, CompanyInterface $company): ?self { - return self::where('slug', $slug) + return self::query($slug, $company)->first(); + } + + /** + * Query by Slug. + */ + public static function query(string $slug, CompanyInterface $company): Builder + { + return static::where('slug', $slug) ->where('companies_id', $company->getId()) - ->where('is_deleted', StateEnums::NO->getValue()) - ->first(); + ->where('is_deleted', StateEnums::NO->getValue()); } } From eb60e37c8a2c08692482e3edd95813698ac6bfb5 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Fri, 23 Aug 2024 13:36:44 -0400 Subject: [PATCH 016/108] Change QueryBySlug name method --- src/Baka/Traits/SlugTrait.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Baka/Traits/SlugTrait.php b/src/Baka/Traits/SlugTrait.php index 50f8e75e9..08e12e666 100644 --- a/src/Baka/Traits/SlugTrait.php +++ b/src/Baka/Traits/SlugTrait.php @@ -33,7 +33,7 @@ public static function bootSlugTrait() */ public static function getBySlugOrFail(string $slug, CompanyInterface $company): Model { - return self::query($slug, $company)->firstOrFail(); + return self::queryBySlug($slug, $company)->firstOrFail(); } /** @@ -41,13 +41,13 @@ public static function getBySlugOrFail(string $slug, CompanyInterface $company): */ public static function getBySlug(string $slug, CompanyInterface $company): ?self { - return self::query($slug, $company)->first(); + return self::queryBySlug($slug, $company)->first(); } /** * Query by Slug. */ - public static function query(string $slug, CompanyInterface $company): Builder + public static function queryBySlug(string $slug, CompanyInterface $company): Builder { return static::where('slug', $slug) ->where('companies_id', $company->getId()) From 058f619cd1e625ec91b89eadf82b31de2864e160 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Tue, 27 Aug 2024 09:38:09 -0400 Subject: [PATCH 017/108] Refactor isLastVariant method --- src/Domains/Inventory/Variants/Models/Variants.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Domains/Inventory/Variants/Models/Variants.php b/src/Domains/Inventory/Variants/Models/Variants.php index db249ef6f..eabbc5ed7 100644 --- a/src/Domains/Inventory/Variants/Models/Variants.php +++ b/src/Domains/Inventory/Variants/Models/Variants.php @@ -374,9 +374,11 @@ public function setTotalQuantity(): int */ public function isLastVariant(): bool { - return self::where('products_id', $this->product_id) - ->where('companies_id', $this->company_id) - ->where('is_deleted', 0) - ->count() === 1; + $otherVariantExists = self::where('products_id', $this->products_id) + ->where('companies_id', $this->companies_id) + ->where('id', '!=', $this->id) + ->exists(); + + return !$otherVariantExists; } } From a3a6b8ce957ff60e2763acbdf10d33173a3f3676 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Tue, 27 Aug 2024 09:59:54 -0400 Subject: [PATCH 018/108] Refactor: adjust code formatting --- src/Baka/Traits/SlugTrait.php | 1 - .../Inventory/Attributes/Actions/CreateAttribute.php | 9 +++++---- .../Inventory/Attributes/Actions/UpdateAttribute.php | 4 ++-- tests/GraphQL/Inventory/AttributesTest.php | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Baka/Traits/SlugTrait.php b/src/Baka/Traits/SlugTrait.php index 08e12e666..ea2b306d7 100644 --- a/src/Baka/Traits/SlugTrait.php +++ b/src/Baka/Traits/SlugTrait.php @@ -53,5 +53,4 @@ public static function queryBySlug(string $slug, CompanyInterface $company): Bui ->where('companies_id', $company->getId()) ->where('is_deleted', StateEnums::NO->getValue()); } - } diff --git a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php index 06c222dbc..b360a279d 100644 --- a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php @@ -34,9 +34,9 @@ public function execute(): Attributes $this->dto->company, ); - if ($existingAttribute) { - return $existingAttribute; - } + if ($existingAttribute) { + return $existingAttribute; + } return Attributes::firstOrCreate([ 'slug' => $this->dto->slug, @@ -51,4 +51,5 @@ public function execute(): Attributes 'is_filtrable' => $this->dto->isFiltrable, ]); } -} \ No newline at end of file + +} diff --git a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php index 079c98abd..ff60d06fa 100644 --- a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php @@ -24,12 +24,12 @@ public function __construct( * @return Attributes */ public function execute(): Attributes - { + { CompaniesRepository::userAssociatedToCompany( $this->dto->company, $this->user ); - + $existingAttribute = Attributes::getBySlug( $this->dto->slug, $this->dto->company, diff --git a/tests/GraphQL/Inventory/AttributesTest.php b/tests/GraphQL/Inventory/AttributesTest.php index d44cc506c..ae16e508b 100644 --- a/tests/GraphQL/Inventory/AttributesTest.php +++ b/tests/GraphQL/Inventory/AttributesTest.php @@ -148,9 +148,9 @@ public function testUpdateDuplicatedSlug(): void /** * Helper function createAttribute. - * + * * @param string|null $slug - * + * * @return array */ private function createAttribute(?string $slug = null): array From 644a83ac6bd2ecbd3ea8771ee8104ac7ade23a27 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Tue, 27 Aug 2024 10:06:08 -0400 Subject: [PATCH 019/108] Refactor: adjust code formatting v2 --- .../Inventory/Attributes/Actions/CreateAttribute.php | 7 +++---- .../Inventory/Attributes/Actions/UpdateAttribute.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php index b360a279d..31d4f7ada 100644 --- a/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/CreateAttribute.php @@ -33,11 +33,11 @@ public function execute(): Attributes $this->dto->slug, $this->dto->company, ); - + if ($existingAttribute) { return $existingAttribute; - } - + } + return Attributes::firstOrCreate([ 'slug' => $this->dto->slug, 'companies_id' => $this->dto->company->getId(), @@ -51,5 +51,4 @@ public function execute(): Attributes 'is_filtrable' => $this->dto->isFiltrable, ]); } - } diff --git a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php index ff60d06fa..b898aea1f 100644 --- a/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php +++ b/src/Domains/Inventory/Attributes/Actions/UpdateAttribute.php @@ -29,7 +29,7 @@ public function execute(): Attributes $this->dto->company, $this->user ); - + $existingAttribute = Attributes::getBySlug( $this->dto->slug, $this->dto->company, From 00ad5bddf740d7e3a4b80f91e48eaec24ca27a5c Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Tue, 27 Aug 2024 15:39:20 -0400 Subject: [PATCH 020/108] Fix: Prevent Attribute Deletion if Linked to Products --- app/Providers/EventServiceProvider.php | 3 +++ .../Inventory/Attributes/Models/Attributes.php | 13 ++++++++++++- .../Attributes/Observers/AttributeObserver.php | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/Domains/Inventory/Attributes/Observers/AttributeObserver.php diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index d06d73fb2..1f314aae5 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -15,6 +15,8 @@ use Kanvas\Guild\Customers\Observers\PeopleObserver; use Kanvas\Guild\Leads\Models\Lead; use Kanvas\Guild\Leads\Observers\LeadObserver; +use Kanvas\Inventory\Attributes\Models\Attributes; +use Kanvas\Inventory\Attributes\Observers\AttributeObserver; use Kanvas\Inventory\Categories\Observers\ProductsCategoriesObserver; use Kanvas\Inventory\Channels\Models\Channels; use Kanvas\Inventory\Channels\Observers\ChannelObserver; @@ -89,6 +91,7 @@ public function boot() ProductsTypes::observe(ProductsTypesObserver::class); Variants::observe(VariantObserver::class); VariantsChannels::observe(VariantsChannelObserver::class); + Attributes::observe(AttributeObserver::class); UsersAssociatedApps::observe(UsersAssociatedAppsObserver::class); UserCompanyApps::observe(UsersAssociatedCompaniesObserver::class); ProductsCategories::observe(ProductsCategoriesObserver::class); diff --git a/src/Domains/Inventory/Attributes/Models/Attributes.php b/src/Domains/Inventory/Attributes/Models/Attributes.php index 761377836..cd4fc1526 100644 --- a/src/Domains/Inventory/Attributes/Models/Attributes.php +++ b/src/Domains/Inventory/Attributes/Models/Attributes.php @@ -15,6 +15,7 @@ use Kanvas\Apps\Models\Apps; use Kanvas\Inventory\Models\BaseModel; use Kanvas\Inventory\Variants\Models\VariantsAttributes; +use Kanvas\Inventory\Products\Models\ProductsAttributes; /** * Class Attributes. @@ -37,7 +38,7 @@ class Attributes extends BaseModel public $table = 'attributes'; public $guarded = []; - protected $cascadeDeletes = ['variantAttributes', 'defaultValues']; + protected $cascadeDeletes = ['defaultValues']; /** * apps. @@ -60,6 +61,11 @@ public function variantAttributes(): HasMany return $this->hasMany(VariantsAttributes::class, 'attributes_id'); } + public function productsAttributes(): HasMany + { + return $this->hasMany(ProductsAttributes::class, 'attributes_id'); + } + /** * attributes values from pivot */ @@ -77,4 +83,9 @@ public function defaultValues(): HasMany { return $this->hasMany(AttributesValues::class, 'attributes_id'); } + + public function hasDependencies(): bool + { + return $this->productsAttributes()->exists() || $this->variantAttributes()->exists(); + } } diff --git a/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php b/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php new file mode 100644 index 000000000..0d1254392 --- /dev/null +++ b/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php @@ -0,0 +1,18 @@ +hasDependencies()) { + throw new ValidationException('Can\'t delete, Attribute has products or variants associated'); + } + } +} \ No newline at end of file From b4fc57d0cdd4b4c3319030637299b7824c85d1bd Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Tue, 27 Aug 2024 16:29:32 -0400 Subject: [PATCH 021/108] Refactor: Styles --- src/Domains/Inventory/Attributes/Models/Attributes.php | 2 +- .../Inventory/Attributes/Observers/AttributeObserver.php | 2 +- src/Domains/Inventory/Status/Models/Status.php | 2 +- src/Domains/Inventory/Status/Observers/StatusObserver.php | 2 +- src/Domains/Inventory/Variants/Models/Variants.php | 4 ++-- src/Domains/Inventory/Variants/Observers/VariantObserver.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Domains/Inventory/Attributes/Models/Attributes.php b/src/Domains/Inventory/Attributes/Models/Attributes.php index cd4fc1526..ddfa1f705 100644 --- a/src/Domains/Inventory/Attributes/Models/Attributes.php +++ b/src/Domains/Inventory/Attributes/Models/Attributes.php @@ -83,7 +83,7 @@ public function defaultValues(): HasMany { return $this->hasMany(AttributesValues::class, 'attributes_id'); } - + public function hasDependencies(): bool { return $this->productsAttributes()->exists() || $this->variantAttributes()->exists(); diff --git a/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php b/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php index 0d1254392..c18d5e642 100644 --- a/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php +++ b/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php @@ -15,4 +15,4 @@ public function deleting(Attributes $attribute): void throw new ValidationException('Can\'t delete, Attribute has products or variants associated'); } } -} \ No newline at end of file +} diff --git a/src/Domains/Inventory/Status/Models/Status.php b/src/Domains/Inventory/Status/Models/Status.php index 1d785071c..dd3d5b85f 100644 --- a/src/Domains/Inventory/Status/Models/Status.php +++ b/src/Domains/Inventory/Status/Models/Status.php @@ -44,7 +44,7 @@ public function variantWarehouses(): HasMany return $this->hasMany(VariantsWarehouses::class, 'products_variants_id'); } - public function hasDependencies():bool + public function hasDependencies(): bool { return $this->products()->exists(); } diff --git a/src/Domains/Inventory/Status/Observers/StatusObserver.php b/src/Domains/Inventory/Status/Observers/StatusObserver.php index 9c7d634b8..61671ccd1 100644 --- a/src/Domains/Inventory/Status/Observers/StatusObserver.php +++ b/src/Domains/Inventory/Status/Observers/StatusObserver.php @@ -48,7 +48,7 @@ public function deleting(Status $status): void if ($status->hasDependencies()) { throw new ValidationException('Can\'t delete, Status has products associated'); } - + $defaultStatus = $status::getDefault($status->company); if ($defaultStatus->getId() == $status->getId()) { diff --git a/src/Domains/Inventory/Variants/Models/Variants.php b/src/Domains/Inventory/Variants/Models/Variants.php index eabbc5ed7..01e983cb4 100644 --- a/src/Domains/Inventory/Variants/Models/Variants.php +++ b/src/Domains/Inventory/Variants/Models/Variants.php @@ -376,9 +376,9 @@ public function isLastVariant(): bool { $otherVariantExists = self::where('products_id', $this->products_id) ->where('companies_id', $this->companies_id) - ->where('id', '!=', $this->id) + ->where('id', '!=', $this->id) ->exists(); - return !$otherVariantExists; + return ! $otherVariantExists; } } diff --git a/src/Domains/Inventory/Variants/Observers/VariantObserver.php b/src/Domains/Inventory/Variants/Observers/VariantObserver.php index a20b0bc05..7beef38dc 100644 --- a/src/Domains/Inventory/Variants/Observers/VariantObserver.php +++ b/src/Domains/Inventory/Variants/Observers/VariantObserver.php @@ -8,7 +8,7 @@ use Kanvas\Inventory\Variants\Models\Variants; class VariantObserver -{ +{ public function saved(Variants $variant): void { $variant->clearLightHouseCache(); From d1ba5cea8c60cc62b0ac57d90c1bceeb469bd3bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:23:37 +0000 Subject: [PATCH 022/108] build(deps-dev): bump phpstan/phpstan from 1.11.11 to 1.12.0 Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.11.11 to 1.12.0. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.12.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.11.11...1.12.0) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index 7d5060b06..b1c1389f9 100644 --- a/composer.lock +++ b/composer.lock @@ -14135,16 +14135,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.11.11", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "707c2aed5d8d0075666e673a5e71440c1d01a5a3" + "reference": "384af967d35b2162f69526c7276acadce534d0e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/707c2aed5d8d0075666e673a5e71440c1d01a5a3", - "reference": "707c2aed5d8d0075666e673a5e71440c1d01a5a3", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", + "reference": "384af967d35b2162f69526c7276acadce534d0e1", "shasum": "" }, "require": { @@ -14189,7 +14189,7 @@ "type": "github" } ], - "time": "2024-08-19T14:37:29+00:00" + "time": "2024-08-27T09:18:05+00:00" }, { "name": "phpunit/php-code-coverage", From d8e0600f73d86efe335f421b76f33501498e2bb1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:23:47 +0000 Subject: [PATCH 023/108] build(deps): bump meilisearch/meilisearch-php from 1.9.1 to 1.10.0 Bumps [meilisearch/meilisearch-php](https://github.com/meilisearch/meilisearch-php) from 1.9.1 to 1.10.0. - [Release notes](https://github.com/meilisearch/meilisearch-php/releases) - [Commits](https://github.com/meilisearch/meilisearch-php/compare/v1.9.1...v1.10.0) --- updated-dependencies: - dependency-name: meilisearch/meilisearch-php dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 7d5060b06..249fabf0c 100644 --- a/composer.lock +++ b/composer.lock @@ -5498,16 +5498,16 @@ }, { "name": "meilisearch/meilisearch-php", - "version": "v1.9.1", + "version": "v1.10.0", "source": { "type": "git", "url": "https://github.com/meilisearch/meilisearch-php.git", - "reference": "c4eb8ecd08799abd65d00dc74f4372b61af1fc37" + "reference": "110be455194fda42ae3a3b8b6a9243479c3a6d19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/meilisearch/meilisearch-php/zipball/c4eb8ecd08799abd65d00dc74f4372b61af1fc37", - "reference": "c4eb8ecd08799abd65d00dc74f4372b61af1fc37", + "url": "https://api.github.com/repos/meilisearch/meilisearch-php/zipball/110be455194fda42ae3a3b8b6a9243479c3a6d19", + "reference": "110be455194fda42ae3a3b8b6a9243479c3a6d19", "shasum": "" }, "require": { @@ -5559,9 +5559,9 @@ ], "support": { "issues": "https://github.com/meilisearch/meilisearch-php/issues", - "source": "https://github.com/meilisearch/meilisearch-php/tree/v1.9.1" + "source": "https://github.com/meilisearch/meilisearch-php/tree/v1.10.0" }, - "time": "2024-07-25T15:54:07+00:00" + "time": "2024-08-26T23:09:54+00:00" }, { "name": "mll-lab/graphql-php-scalars", From 08efdc8a6352e026f985a378ea9a916b82454289 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 28 Aug 2024 10:29:00 -0400 Subject: [PATCH 024/108] refact: filter --- graphql/schemas/Social/message.graphql | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/graphql/schemas/Social/message.graphql b/graphql/schemas/Social/message.graphql index 792748712..6b8a8ec12 100644 --- a/graphql/schemas/Social/message.graphql +++ b/graphql/schemas/Social/message.graphql @@ -167,9 +167,16 @@ extend type Query @guard { relation: "user" columns: ["id", "displayname"] ) - hasTags: _ @whereHasConditions(relation: "tags", columns: ["name"]) + hasTags: _ + @whereHasConditions( + relation: "tags" + columns: ["id", "name", "slug"] + ) hasType: _ - @whereHasConditions(relation: "messageType", columns: ["name"]) + @whereHasConditions( + relation: "messageType" + columns: ["id", "name", "verb"] + ) hasAppModuleMessage: _ @whereHasConditions(columns: ["entity_id", "system_modules"]) orderBy: _ @orderBy(columns: ["created_at", "updated_at", "id"]) @@ -227,6 +234,21 @@ extend type Query @guard { "total_shared" ] ) + hasUser: _ + @whereHasConditions( + relation: "user" + columns: ["id", "displayname"] + ) + hasTags: _ + @whereHasConditions( + relation: "tags" + columns: ["id", "name", "slug"] + ) + hasType: _ + @whereHasConditions( + relation: "messageType" + columns: ["id", "name", "verb"] + ) hasAppModuleMessage: _ @whereHasConditions(columns: ["entity_id", "system_modules"]) orderBy: _ @orderBy(columns: ["created_at", "updated_at", "id"]) From 2d076856c4c334d6abb07e4e263c48d42f37c457 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 28 Aug 2024 10:49:26 -0400 Subject: [PATCH 025/108] feat : filter by tags and type --- graphql/schemas/Guild/people.graphql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/graphql/schemas/Guild/people.graphql b/graphql/schemas/Guild/people.graphql index a62dc77a9..535e8cc18 100644 --- a/graphql/schemas/Guild/people.graphql +++ b/graphql/schemas/Guild/people.graphql @@ -12,6 +12,8 @@ type People { organizations: [Organization!] @belongsToMany contacts: [Contact!]! @hasMany address: [Address!]! @hasMany + created_at: DateTime! + updated_at: DateTime employment_history: [PeopleEmploymentHistory!] @hasMany(relation: "employmentHistory") files: [Filesystem!]! From 723bd6e5862d812ed50af881f6be99b151d7acbe Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Wed, 28 Aug 2024 18:40:49 -0400 Subject: [PATCH 026/108] Refactor: Dependencies --- src/Domains/Inventory/Attributes/Models/Attributes.php | 4 +++- .../Inventory/Attributes/Observers/AttributeObserver.php | 2 +- src/Domains/Inventory/Status/Models/Status.php | 8 +++++++- src/Domains/Inventory/Status/Observers/StatusObserver.php | 2 +- src/Domains/Inventory/Variants/Models/Variants.php | 7 +++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Domains/Inventory/Attributes/Models/Attributes.php b/src/Domains/Inventory/Attributes/Models/Attributes.php index ddfa1f705..a66240d1e 100644 --- a/src/Domains/Inventory/Attributes/Models/Attributes.php +++ b/src/Domains/Inventory/Attributes/Models/Attributes.php @@ -86,6 +86,8 @@ public function defaultValues(): HasMany public function hasDependencies(): bool { - return $this->productsAttributes()->exists() || $this->variantAttributes()->exists(); + return $this->productsAttributes()->exists() + || $this->variantAttributes()->exists() + || $this->productType()->exists(); } } diff --git a/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php b/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php index c18d5e642..e6264cd61 100644 --- a/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php +++ b/src/Domains/Inventory/Attributes/Observers/AttributeObserver.php @@ -12,7 +12,7 @@ class AttributeObserver public function deleting(Attributes $attribute): void { if ($attribute->hasDependencies()) { - throw new ValidationException('Can\'t delete, Attribute has products or variants associated'); + throw new ValidationException('Can\'t delete, Attribute has associated items'); } } } diff --git a/src/Domains/Inventory/Status/Models/Status.php b/src/Domains/Inventory/Status/Models/Status.php index dd3d5b85f..7cf1c87e0 100644 --- a/src/Domains/Inventory/Status/Models/Status.php +++ b/src/Domains/Inventory/Status/Models/Status.php @@ -9,6 +9,7 @@ use Kanvas\Inventory\Models\BaseModel; use Baka\Traits\DatabaseSearchableTrait; use Kanvas\Inventory\Traits\DefaultTrait; +use Kanvas\Inventory\Variants\Models\Variants; use Kanvas\Inventory\Products\Models\Products; use Kanvas\Inventory\Variants\Models\VariantsWarehouses; @@ -34,6 +35,11 @@ class Status extends BaseModel /** * Get the user that owns the Variants. */ + public function variants(): HasMany + { + return $this->hasMany(Variants::class, 'status_id'); + } + public function products(): HasMany { return $this->hasMany(Products::class, 'status_id'); @@ -46,6 +52,6 @@ public function variantWarehouses(): HasMany public function hasDependencies(): bool { - return $this->products()->exists(); + return $this->products()->exists() || $this->variants()->exists(); } } diff --git a/src/Domains/Inventory/Status/Observers/StatusObserver.php b/src/Domains/Inventory/Status/Observers/StatusObserver.php index 61671ccd1..fcb605d45 100644 --- a/src/Domains/Inventory/Status/Observers/StatusObserver.php +++ b/src/Domains/Inventory/Status/Observers/StatusObserver.php @@ -46,7 +46,7 @@ public function updating(Status $status): void public function deleting(Status $status): void { if ($status->hasDependencies()) { - throw new ValidationException('Can\'t delete, Status has products associated'); + throw new ValidationException('Can\'t delete, Attribute has products or variants associated'); } $defaultStatus = $status::getDefault($status->company); diff --git a/src/Domains/Inventory/Variants/Models/Variants.php b/src/Domains/Inventory/Variants/Models/Variants.php index 01e983cb4..59520f403 100644 --- a/src/Domains/Inventory/Variants/Models/Variants.php +++ b/src/Domains/Inventory/Variants/Models/Variants.php @@ -374,6 +374,13 @@ public function setTotalQuantity(): int */ public function isLastVariant(): bool { + $product = $this->product; + + // Check if the product is being deleted + if ($product && $product->is_deleted) { + return false; + } + $otherVariantExists = self::where('products_id', $this->products_id) ->where('companies_id', $this->companies_id) ->where('id', '!=', $this->id) From ea0e7efd50044e2696a202353f307c4cfccb241a Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Wed, 28 Aug 2024 18:42:11 -0400 Subject: [PATCH 027/108] Refactor: Cascade --- src/Domains/Inventory/Attributes/Models/Attributes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Inventory/Attributes/Models/Attributes.php b/src/Domains/Inventory/Attributes/Models/Attributes.php index a66240d1e..68ab5e0a7 100644 --- a/src/Domains/Inventory/Attributes/Models/Attributes.php +++ b/src/Domains/Inventory/Attributes/Models/Attributes.php @@ -38,7 +38,7 @@ class Attributes extends BaseModel public $table = 'attributes'; public $guarded = []; - protected $cascadeDeletes = ['defaultValues']; + protected $cascadeDeletes = ['variantAttributes','defaultValues']; /** * apps. From 2a372a18860a76538fb76b9651f3bdfecb62bc6c Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Wed, 28 Aug 2024 18:47:56 -0400 Subject: [PATCH 028/108] Refactor: Styles --- src/Domains/Inventory/Attributes/Models/Attributes.php | 2 +- src/Domains/Inventory/Variants/Models/Variants.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Domains/Inventory/Attributes/Models/Attributes.php b/src/Domains/Inventory/Attributes/Models/Attributes.php index 68ab5e0a7..a8eab7ad1 100644 --- a/src/Domains/Inventory/Attributes/Models/Attributes.php +++ b/src/Domains/Inventory/Attributes/Models/Attributes.php @@ -86,7 +86,7 @@ public function defaultValues(): HasMany public function hasDependencies(): bool { - return $this->productsAttributes()->exists() + return $this->productsAttributes()->exists() || $this->variantAttributes()->exists() || $this->productType()->exists(); } diff --git a/src/Domains/Inventory/Variants/Models/Variants.php b/src/Domains/Inventory/Variants/Models/Variants.php index 59520f403..b1975f3e2 100644 --- a/src/Domains/Inventory/Variants/Models/Variants.php +++ b/src/Domains/Inventory/Variants/Models/Variants.php @@ -375,7 +375,7 @@ public function setTotalQuantity(): int public function isLastVariant(): bool { $product = $this->product; - + // Check if the product is being deleted if ($product && $product->is_deleted) { return false; From 7e70c374249300b0116c7682803cd435fc3eaea4 Mon Sep 17 00:00:00 2001 From: Keysie27 Date: Wed, 28 Aug 2024 19:10:01 -0400 Subject: [PATCH 029/108] Fix: Prevent Attribute Delection if Linked to ProductTypes --- src/Domains/Inventory/Attributes/Models/Attributes.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Domains/Inventory/Attributes/Models/Attributes.php b/src/Domains/Inventory/Attributes/Models/Attributes.php index a8eab7ad1..438e57049 100644 --- a/src/Domains/Inventory/Attributes/Models/Attributes.php +++ b/src/Domains/Inventory/Attributes/Models/Attributes.php @@ -15,6 +15,7 @@ use Kanvas\Apps\Models\Apps; use Kanvas\Inventory\Models\BaseModel; use Kanvas\Inventory\Variants\Models\VariantsAttributes; +use Kanvas\Inventory\ProductsTypes\Models\ProductsTypesAttributes; use Kanvas\Inventory\Products\Models\ProductsAttributes; /** @@ -66,6 +67,11 @@ public function productsAttributes(): HasMany return $this->hasMany(ProductsAttributes::class, 'attributes_id'); } + public function productsTypesAttributes(): HasMany + { + return $this->hasMany(ProductsTypesAttributes::class, 'attributes_id'); + } + /** * attributes values from pivot */ @@ -88,6 +94,6 @@ public function hasDependencies(): bool { return $this->productsAttributes()->exists() || $this->variantAttributes()->exists() - || $this->productType()->exists(); + || $this->productsTypesAttributes()->exists(); } } From 517f8aacea751aed33cf60a3a99772068d8841d3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:51:34 +0000 Subject: [PATCH 030/108] build(deps): bump stripe/stripe-php from 15.7.0 to 15.8.0 Bumps [stripe/stripe-php](https://github.com/stripe/stripe-php) from 15.7.0 to 15.8.0. - [Release notes](https://github.com/stripe/stripe-php/releases) - [Changelog](https://github.com/stripe/stripe-php/blob/master/CHANGELOG.md) - [Commits](https://github.com/stripe/stripe-php/compare/v15.7.0...v15.8.0) --- updated-dependencies: - dependency-name: stripe/stripe-php dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 578906d98..ba05c194f 100644 --- a/composer.lock +++ b/composer.lock @@ -9697,16 +9697,16 @@ }, { "name": "stripe/stripe-php", - "version": "v15.7.0", + "version": "v15.8.0", "source": { "type": "git", "url": "https://github.com/stripe/stripe-php.git", - "reference": "3e8161c1d7d1e9fb79751a693cd6123550f6ce21" + "reference": "5ed133fa45987771f80ad300be2316c05832f6a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/stripe/stripe-php/zipball/3e8161c1d7d1e9fb79751a693cd6123550f6ce21", - "reference": "3e8161c1d7d1e9fb79751a693cd6123550f6ce21", + "url": "https://api.github.com/repos/stripe/stripe-php/zipball/5ed133fa45987771f80ad300be2316c05832f6a7", + "reference": "5ed133fa45987771f80ad300be2316c05832f6a7", "shasum": "" }, "require": { @@ -9750,9 +9750,9 @@ ], "support": { "issues": "https://github.com/stripe/stripe-php/issues", - "source": "https://github.com/stripe/stripe-php/tree/v15.7.0" + "source": "https://github.com/stripe/stripe-php/tree/v15.8.0" }, - "time": "2024-08-15T21:17:26+00:00" + "time": "2024-08-29T21:58:14+00:00" }, { "name": "swoole/ide-helper", From 703652d914ad18227ea7f0bf5ab12c061f744a5e Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 30 Aug 2024 08:17:22 -0400 Subject: [PATCH 031/108] refact: is admin --- src/Kanvas/Users/Models/Users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kanvas/Users/Models/Users.php b/src/Kanvas/Users/Models/Users.php index ca734613a..ae2fdeb93 100644 --- a/src/Kanvas/Users/Models/Users.php +++ b/src/Kanvas/Users/Models/Users.php @@ -652,7 +652,7 @@ public function isAppOwner(): bool public function isAdmin(): bool { - return $this->isAppOwner() || $this->isAn(RolesEnums::ADMIN->value); + return $this->isAppOwner() || $this->isAn(RolesEnums::ADMIN->value) || $this->isAn(RolesEnums::OWNER->value); } /** From f4603686286dbcfb79f895ee9b7235373161d80e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 22:45:34 +0000 Subject: [PATCH 032/108] build(deps): bump symfony/expression-language from 7.1.1 to 7.1.4 Bumps [symfony/expression-language](https://github.com/symfony/expression-language) from 7.1.1 to 7.1.4. - [Release notes](https://github.com/symfony/expression-language/releases) - [Changelog](https://github.com/symfony/expression-language/blob/7.1/CHANGELOG.md) - [Commits](https://github.com/symfony/expression-language/compare/v7.1.1...v7.1.4) --- updated-dependencies: - dependency-name: symfony/expression-language dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index ba05c194f..c2da21e07 100644 --- a/composer.lock +++ b/composer.lock @@ -9788,16 +9788,16 @@ }, { "name": "symfony/cache", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/cache.git", - "reference": "8ac37acee794372f9732fe8a61a8221f6762148e" + "reference": "b61e464d7687bb7e8f677d5031c632bf3820df18" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/cache/zipball/8ac37acee794372f9732fe8a61a8221f6762148e", - "reference": "8ac37acee794372f9732fe8a61a8221f6762148e", + "url": "https://api.github.com/repos/symfony/cache/zipball/b61e464d7687bb7e8f677d5031c632bf3820df18", + "reference": "b61e464d7687bb7e8f677d5031c632bf3820df18", "shasum": "" }, "require": { @@ -9865,7 +9865,7 @@ "psr6" ], "support": { - "source": "https://github.com/symfony/cache/tree/v7.1.3" + "source": "https://github.com/symfony/cache/tree/v7.1.4" }, "funding": [ { @@ -9881,7 +9881,7 @@ "type": "tidelift" } ], - "time": "2024-07-17T06:10:24+00:00" + "time": "2024-08-12T09:59:40+00:00" }, { "name": "symfony/cache-contracts", @@ -10491,16 +10491,16 @@ }, { "name": "symfony/expression-language", - "version": "v7.1.1", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/expression-language.git", - "reference": "463cb95f80c14136175f4e03f7f6199b01c6b8b4" + "reference": "b9e4bc6685d513c10235145ed1042a6081635806" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/expression-language/zipball/463cb95f80c14136175f4e03f7f6199b01c6b8b4", - "reference": "463cb95f80c14136175f4e03f7f6199b01c6b8b4", + "url": "https://api.github.com/repos/symfony/expression-language/zipball/b9e4bc6685d513c10235145ed1042a6081635806", + "reference": "b9e4bc6685d513c10235145ed1042a6081635806", "shasum": "" }, "require": { @@ -10535,7 +10535,7 @@ "description": "Provides an engine that can compile and evaluate expressions", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/expression-language/tree/v7.1.1" + "source": "https://github.com/symfony/expression-language/tree/v7.1.4" }, "funding": [ { @@ -10551,7 +10551,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-08-12T09:59:40+00:00" }, { "name": "symfony/finder", From ebb9075bfe8a9d750902f4c3d303931193efeda8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 22:45:42 +0000 Subject: [PATCH 033/108] build(deps): bump symfony/http-client from 7.1.3 to 7.1.4 Bumps [symfony/http-client](https://github.com/symfony/http-client) from 7.1.3 to 7.1.4. - [Release notes](https://github.com/symfony/http-client/releases) - [Changelog](https://github.com/symfony/http-client/blob/7.1/CHANGELOG.md) - [Commits](https://github.com/symfony/http-client/compare/v7.1.3...v7.1.4) --- updated-dependencies: - dependency-name: symfony/http-client dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index ba05c194f..de56e1452 100644 --- a/composer.lock +++ b/composer.lock @@ -10619,16 +10619,16 @@ }, { "name": "symfony/http-client", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "b79858aa7a051ea791b0d50269a234a0b50cb231" + "reference": "a8f8d60b30b331cf4b743b3632e5acdba3f8285c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/b79858aa7a051ea791b0d50269a234a0b50cb231", - "reference": "b79858aa7a051ea791b0d50269a234a0b50cb231", + "url": "https://api.github.com/repos/symfony/http-client/zipball/a8f8d60b30b331cf4b743b3632e5acdba3f8285c", + "reference": "a8f8d60b30b331cf4b743b3632e5acdba3f8285c", "shasum": "" }, "require": { @@ -10693,7 +10693,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.1.3" + "source": "https://github.com/symfony/http-client/tree/v7.1.4" }, "funding": [ { @@ -10709,7 +10709,7 @@ "type": "tidelift" } ], - "time": "2024-07-17T06:10:24+00:00" + "time": "2024-08-26T06:32:37+00:00" }, { "name": "symfony/http-client-contracts", From d13b7401331825a5db878c5df5e6918a2b51684f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 22:45:58 +0000 Subject: [PATCH 034/108] build(deps): bump spatie/laravel-data from 4.8.1 to 4.8.2 Bumps [spatie/laravel-data](https://github.com/spatie/laravel-data) from 4.8.1 to 4.8.2. - [Release notes](https://github.com/spatie/laravel-data/releases) - [Changelog](https://github.com/spatie/laravel-data/blob/main/CHANGELOG.md) - [Commits](https://github.com/spatie/laravel-data/compare/4.8.1...4.8.2) --- updated-dependencies: - dependency-name: spatie/laravel-data dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 144 +++++++++++++++++++++++++------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/composer.lock b/composer.lock index ba05c194f..18d330c9d 100644 --- a/composer.lock +++ b/composer.lock @@ -7369,16 +7369,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.29.1", + "version": "1.30.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4" + "reference": "5ceb0e384997db59f38774bf79c2a6134252c08f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fcaefacf2d5c417e928405b71b400d4ce10daaf4", - "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/5ceb0e384997db59f38774bf79c2a6134252c08f", + "reference": "5ceb0e384997db59f38774bf79c2a6134252c08f", "shasum": "" }, "require": { @@ -7410,9 +7410,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.30.0" }, - "time": "2024-05-31T08:52:43+00:00" + "time": "2024-08-29T09:54:52+00:00" }, { "name": "powersync/authorizenet-sdk-php", @@ -8948,16 +8948,16 @@ }, { "name": "spatie/laravel-data", - "version": "4.8.1", + "version": "4.8.2", "source": { "type": "git", "url": "https://github.com/spatie/laravel-data.git", - "reference": "597961b02b2f7722246f21dad432bf24c2abb9d6" + "reference": "1732519693ac738cbc9cb21fdd00446c7a6a46e6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-data/zipball/597961b02b2f7722246f21dad432bf24c2abb9d6", - "reference": "597961b02b2f7722246f21dad432bf24c2abb9d6", + "url": "https://api.github.com/repos/spatie/laravel-data/zipball/1732519693ac738cbc9cb21fdd00446c7a6a46e6", + "reference": "1732519693ac738cbc9cb21fdd00446c7a6a46e6", "shasum": "" }, "require": { @@ -9020,7 +9020,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-data/issues", - "source": "https://github.com/spatie/laravel-data/tree/4.8.1" + "source": "https://github.com/spatie/laravel-data/tree/4.8.2" }, "funding": [ { @@ -9028,7 +9028,7 @@ "type": "github" } ], - "time": "2024-08-13T13:53:42+00:00" + "time": "2024-08-30T13:53:18+00:00" }, { "name": "spatie/laravel-google-cloud-storage", @@ -9274,16 +9274,16 @@ }, { "name": "spatie/laravel-package-tools", - "version": "1.16.4", + "version": "1.16.5", "source": { "type": "git", "url": "https://github.com/spatie/laravel-package-tools.git", - "reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53" + "reference": "c7413972cf22ffdff97b68499c22baa04eddb6a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53", - "reference": "ddf678e78d7f8b17e5cdd99c0c3413a4a6592e53", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/c7413972cf22ffdff97b68499c22baa04eddb6a2", + "reference": "c7413972cf22ffdff97b68499c22baa04eddb6a2", "shasum": "" }, "require": { @@ -9322,7 +9322,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-package-tools/issues", - "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.4" + "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.5" }, "funding": [ { @@ -9330,7 +9330,7 @@ "type": "github" } ], - "time": "2024-03-20T07:29:11+00:00" + "time": "2024-08-27T18:56:10+00:00" }, { "name": "spatie/laravel-queueable-action", @@ -9493,16 +9493,16 @@ }, { "name": "spatie/php-structure-discoverer", - "version": "2.1.2", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/spatie/php-structure-discoverer.git", - "reference": "0bfebf609b2047360cdca102d2c08fb78b393927" + "reference": "271542206169d95dd2ffe346ddf11f37672553a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/php-structure-discoverer/zipball/0bfebf609b2047360cdca102d2c08fb78b393927", - "reference": "0bfebf609b2047360cdca102d2c08fb78b393927", + "url": "https://api.github.com/repos/spatie/php-structure-discoverer/zipball/271542206169d95dd2ffe346ddf11f37672553a2", + "reference": "271542206169d95dd2ffe346ddf11f37672553a2", "shasum": "" }, "require": { @@ -9561,7 +9561,7 @@ ], "support": { "issues": "https://github.com/spatie/php-structure-discoverer/issues", - "source": "https://github.com/spatie/php-structure-discoverer/tree/2.1.2" + "source": "https://github.com/spatie/php-structure-discoverer/tree/2.2.0" }, "funding": [ { @@ -9569,7 +9569,7 @@ "type": "github" } ], - "time": "2024-08-13T15:00:59+00:00" + "time": "2024-08-29T10:43:45+00:00" }, { "name": "spatie/regex", @@ -10035,16 +10035,16 @@ }, { "name": "symfony/console", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9" + "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", - "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", + "url": "https://api.github.com/repos/symfony/console/zipball/1eed7af6961d763e7832e874d7f9b21c3ea9c111", + "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111", "shasum": "" }, "require": { @@ -10108,7 +10108,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.3" + "source": "https://github.com/symfony/console/tree/v7.1.4" }, "funding": [ { @@ -10124,7 +10124,7 @@ "type": "tidelift" } ], - "time": "2024-07-26T12:41:01+00:00" + "time": "2024-08-15T22:48:53+00:00" }, { "name": "symfony/css-selector", @@ -10555,16 +10555,16 @@ }, { "name": "symfony/finder", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "717c6329886f32dc65e27461f80f2a465412fdca" + "reference": "d95bbf319f7d052082fb7af147e0f835a695e823" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/717c6329886f32dc65e27461f80f2a465412fdca", - "reference": "717c6329886f32dc65e27461f80f2a465412fdca", + "url": "https://api.github.com/repos/symfony/finder/zipball/d95bbf319f7d052082fb7af147e0f835a695e823", + "reference": "d95bbf319f7d052082fb7af147e0f835a695e823", "shasum": "" }, "require": { @@ -10599,7 +10599,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.1.3" + "source": "https://github.com/symfony/finder/tree/v7.1.4" }, "funding": [ { @@ -10615,7 +10615,7 @@ "type": "tidelift" } ], - "time": "2024-07-24T07:08:44+00:00" + "time": "2024-08-13T14:28:19+00:00" }, { "name": "symfony/http-client", @@ -10868,16 +10868,16 @@ }, { "name": "symfony/http-kernel", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "db9702f3a04cc471ec8c70e881825db26ac5f186" + "reference": "6efcbd1b3f444f631c386504fc83eeca25963747" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/db9702f3a04cc471ec8c70e881825db26ac5f186", - "reference": "db9702f3a04cc471ec8c70e881825db26ac5f186", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/6efcbd1b3f444f631c386504fc83eeca25963747", + "reference": "6efcbd1b3f444f631c386504fc83eeca25963747", "shasum": "" }, "require": { @@ -10962,7 +10962,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v7.1.3" + "source": "https://github.com/symfony/http-kernel/tree/v7.1.4" }, "funding": [ { @@ -10978,7 +10978,7 @@ "type": "tidelift" } ], - "time": "2024-07-26T14:58:15+00:00" + "time": "2024-08-30T17:02:28+00:00" }, { "name": "symfony/mailer", @@ -11131,16 +11131,16 @@ }, { "name": "symfony/mime", - "version": "v7.1.2", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "26a00b85477e69a4bab63b66c5dce64f18b0cbfc" + "reference": "ccaa6c2503db867f472a587291e764d6a1e58758" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/26a00b85477e69a4bab63b66c5dce64f18b0cbfc", - "reference": "26a00b85477e69a4bab63b66c5dce64f18b0cbfc", + "url": "https://api.github.com/repos/symfony/mime/zipball/ccaa6c2503db867f472a587291e764d6a1e58758", + "reference": "ccaa6c2503db867f472a587291e764d6a1e58758", "shasum": "" }, "require": { @@ -11195,7 +11195,7 @@ "mime-type" ], "support": { - "source": "https://github.com/symfony/mime/tree/v7.1.2" + "source": "https://github.com/symfony/mime/tree/v7.1.4" }, "funding": [ { @@ -11211,7 +11211,7 @@ "type": "tidelift" } ], - "time": "2024-06-28T10:03:55+00:00" + "time": "2024-08-13T14:28:19+00:00" }, { "name": "symfony/options-resolver", @@ -12136,16 +12136,16 @@ }, { "name": "symfony/routing", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "8a908a3f22d5a1b5d297578c2ceb41b02fa916d0" + "reference": "1500aee0094a3ce1c92626ed8cf3c2037e86f5a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/8a908a3f22d5a1b5d297578c2ceb41b02fa916d0", - "reference": "8a908a3f22d5a1b5d297578c2ceb41b02fa916d0", + "url": "https://api.github.com/repos/symfony/routing/zipball/1500aee0094a3ce1c92626ed8cf3c2037e86f5a7", + "reference": "1500aee0094a3ce1c92626ed8cf3c2037e86f5a7", "shasum": "" }, "require": { @@ -12197,7 +12197,7 @@ "url" ], "support": { - "source": "https://github.com/symfony/routing/tree/v7.1.3" + "source": "https://github.com/symfony/routing/tree/v7.1.4" }, "funding": [ { @@ -12213,7 +12213,7 @@ "type": "tidelift" } ], - "time": "2024-07-17T06:10:24+00:00" + "time": "2024-08-29T08:16:25+00:00" }, { "name": "symfony/service-contracts", @@ -12300,16 +12300,16 @@ }, { "name": "symfony/string", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "ea272a882be7f20cad58d5d78c215001617b7f07" + "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/ea272a882be7f20cad58d5d78c215001617b7f07", - "reference": "ea272a882be7f20cad58d5d78c215001617b7f07", + "url": "https://api.github.com/repos/symfony/string/zipball/6cd670a6d968eaeb1c77c2e76091c45c56bc367b", + "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b", "shasum": "" }, "require": { @@ -12367,7 +12367,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.3" + "source": "https://github.com/symfony/string/tree/v7.1.4" }, "funding": [ { @@ -12383,7 +12383,7 @@ "type": "tidelift" } ], - "time": "2024-07-22T10:25:37+00:00" + "time": "2024-08-12T09:59:40+00:00" }, { "name": "symfony/translation", @@ -12559,16 +12559,16 @@ }, { "name": "symfony/uid", - "version": "v7.1.1", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/uid.git", - "reference": "bb59febeecc81528ff672fad5dab7f06db8c8277" + "reference": "82177535395109075cdb45a70533aa3d7a521cdf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/uid/zipball/bb59febeecc81528ff672fad5dab7f06db8c8277", - "reference": "bb59febeecc81528ff672fad5dab7f06db8c8277", + "url": "https://api.github.com/repos/symfony/uid/zipball/82177535395109075cdb45a70533aa3d7a521cdf", + "reference": "82177535395109075cdb45a70533aa3d7a521cdf", "shasum": "" }, "require": { @@ -12613,7 +12613,7 @@ "uuid" ], "support": { - "source": "https://github.com/symfony/uid/tree/v7.1.1" + "source": "https://github.com/symfony/uid/tree/v7.1.4" }, "funding": [ { @@ -12629,20 +12629,20 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-08-12T09:59:40+00:00" }, { "name": "symfony/var-dumper", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "86af4617cca75a6e28598f49ae0690f3b9d4591f" + "reference": "a5fa7481b199090964d6fd5dab6294d5a870c7aa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/86af4617cca75a6e28598f49ae0690f3b9d4591f", - "reference": "86af4617cca75a6e28598f49ae0690f3b9d4591f", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/a5fa7481b199090964d6fd5dab6294d5a870c7aa", + "reference": "a5fa7481b199090964d6fd5dab6294d5a870c7aa", "shasum": "" }, "require": { @@ -12696,7 +12696,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v7.1.3" + "source": "https://github.com/symfony/var-dumper/tree/v7.1.4" }, "funding": [ { @@ -12712,7 +12712,7 @@ "type": "tidelift" } ], - "time": "2024-07-26T12:41:01+00:00" + "time": "2024-08-30T16:12:47+00:00" }, { "name": "symfony/var-exporter", From 223ceaa439ca41da71a4aedebc588232191a6e2b Mon Sep 17 00:00:00 2001 From: FredPeal Date: Fri, 30 Aug 2024 18:53:53 -0400 Subject: [PATCH 035/108] refactor: mutation update photo profile --- .../Companies/CompanyManagementMutation.php | 27 +++++++++++++++++++ graphql/schemas/Ecosystem/company.graphql | 12 ++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/GraphQL/Ecosystem/Mutations/Companies/CompanyManagementMutation.php b/app/GraphQL/Ecosystem/Mutations/Companies/CompanyManagementMutation.php index def8dba4a..c8bda3172 100644 --- a/app/GraphQL/Ecosystem/Mutations/Companies/CompanyManagementMutation.php +++ b/app/GraphQL/Ecosystem/Mutations/Companies/CompanyManagementMutation.php @@ -23,6 +23,8 @@ use Kanvas\Users\Models\UsersAssociatedApps; use Kanvas\Users\Models\UsersAssociatedCompanies; use Kanvas\Users\Repositories\UsersRepository; +use Kanvas\Filesystem\Actions\AttachFilesystemAction; +use Kanvas\Filesystem\Services\FilesystemServices; class CompanyManagementMutation { @@ -60,6 +62,31 @@ public function updateCompany(mixed $root, array $request): Companies return $action->execute((int) $request['id']); } + + public function updatePhotoProfile(mixed $root, array $request): Companies + { + $company = Companies::getById($request['id']); + if(!auth()->user()->isAdmin()) { + $company = Companies::getById($request['id']); + CompaniesRepository::userAssociatedToCompany( + $company, + auth()->user() + ); + } + $filesystem = new FilesystemServices(app(Apps::class)); + $file = $request['file']; + in_array($file->extension(), ['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp']) ?: throw new Exception('Invalid file format'); + + $filesystemEntity = $filesystem->upload($file, auth()->user()); + $action = new AttachFilesystemAction( + $filesystemEntity, + $company + ); + $action->execute('photo'); + + return $company; + } + /** * deleteCompany */ diff --git a/graphql/schemas/Ecosystem/company.graphql b/graphql/schemas/Ecosystem/company.graphql index 0f4eaaa35..ce97e5613 100644 --- a/graphql/schemas/Ecosystem/company.graphql +++ b/graphql/schemas/Ecosystem/company.graphql @@ -134,7 +134,8 @@ enum CompanyUserColumn { ID @enum(value: "users.id") UUID @enum(value: "users.uuid") COMPANIES_ID @enum(value: "users_associated_company.companies_id") - COMPANIES_BRANCHES_ID @enum(value: "users_associated_company.companies_branches_id") + COMPANIES_BRANCHES_ID + @enum(value: "users_associated_company.companies_branches_id") DISPLAYNAME @enum(value: "users_associated_apps.displayname") FIRSTNAME @enum(value: "users_associated_apps.firstname") LASTNAME @enum(value: "users_associated_apps.lastname") @@ -144,7 +145,7 @@ enum CompanyUserColumn { UPDATE_AT @enum(value: "users_associated_apps.updated_at") } -enum CompanyOrderColumn{ +enum CompanyOrderColumn { ID @enum(value: "companies.id") NAME @enum(value: "companies.name") ADDRESS @enum(value: "companies.address") @@ -240,7 +241,7 @@ extend type Query @guard { @field( resolver: "App\\GraphQL\\Ecosystem\\Queries\\Companies\\CompanySettingQuery@getAllSettings" ) - + dashboard: Dashboard! @field( resolver: "App\\GraphQL\\Ecosystem\\Queries\\Companies\\DashboardQuery@getDashboard" @@ -256,6 +257,11 @@ extend type Mutation @guardByAdmin { @field( resolver: "App\\GraphQL\\Ecosystem\\Mutations\\Companies\\CompanyManagementMutation@updateCompany" ) + updateCompanyPhotoProfile(file: Upload!, id: ID!): User! + @guard + @field( + resolver: "App\\GraphQL\\Ecosystem\\Mutations\\Companies\\CompanyManagementMutation@updatePhotoProfile" + ) deleteCompany(id: ID!): Boolean! @field( resolver: "App\\GraphQL\\Ecosystem\\Mutations\\Companies\\CompanyManagementMutation@deleteCompany" From 999cfe05fb9d2dc5790a818f746f9a8f3c25401d Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 30 Aug 2024 23:00:13 +0000 Subject: [PATCH 036/108] Apply fixes from StyleCI --- .../Ecosystem/Mutations/Companies/CompanyManagementMutation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/GraphQL/Ecosystem/Mutations/Companies/CompanyManagementMutation.php b/app/GraphQL/Ecosystem/Mutations/Companies/CompanyManagementMutation.php index c8bda3172..5f2c9f30d 100644 --- a/app/GraphQL/Ecosystem/Mutations/Companies/CompanyManagementMutation.php +++ b/app/GraphQL/Ecosystem/Mutations/Companies/CompanyManagementMutation.php @@ -66,7 +66,7 @@ public function updateCompany(mixed $root, array $request): Companies public function updatePhotoProfile(mixed $root, array $request): Companies { $company = Companies::getById($request['id']); - if(!auth()->user()->isAdmin()) { + if (! auth()->user()->isAdmin()) { $company = Companies::getById($request['id']); CompaniesRepository::userAssociatedToCompany( $company, From c8ea6768015fd4b6d365747a390057228ff5c7de Mon Sep 17 00:00:00 2001 From: Rafael White Date: Fri, 30 Aug 2024 19:25:56 -0400 Subject: [PATCH 037/108] add explore feed email notification --- .../PromptMine/ExploreFeedCommand.php | 52 +++++++++++++++++++ .../Templates/PromptMine/ExploreFeed.php | 16 ++++++ 2 files changed, 68 insertions(+) create mode 100644 app/Console/Commands/PromptMine/ExploreFeedCommand.php create mode 100644 src/Kanvas/Notifications/Templates/PromptMine/ExploreFeed.php diff --git a/app/Console/Commands/PromptMine/ExploreFeedCommand.php b/app/Console/Commands/PromptMine/ExploreFeedCommand.php new file mode 100644 index 000000000..9e763f49c --- /dev/null +++ b/app/Console/Commands/PromptMine/ExploreFeedCommand.php @@ -0,0 +1,52 @@ +argument('app_id')); + $users = Users::select('users.firstname') + ->join('users_associated_apps', 'users_associated_apps.users_id', '=', 'users.id') + ->where('users.is_deleted', StateEnums::NO->getValue()) + ->where('users_associated_apps.apps_id', $app->getId()) + ->where('users_associated_apps.is_deleted', StateEnums::NO->getValue()) + ->get(); + + foreach ($users as $user) { + $exploreFeedNotification = new ExploreFeed( + $user, + [ + 'userFirstname' => $user->firstname + ] + ); + + $user->notify($exploreFeedNotification); + } + } +} diff --git a/src/Kanvas/Notifications/Templates/PromptMine/ExploreFeed.php b/src/Kanvas/Notifications/Templates/PromptMine/ExploreFeed.php new file mode 100644 index 000000000..c50c9481f --- /dev/null +++ b/src/Kanvas/Notifications/Templates/PromptMine/ExploreFeed.php @@ -0,0 +1,16 @@ + Date: Fri, 30 Aug 2024 20:44:20 -0400 Subject: [PATCH 038/108] Update company.graphql --- graphql/schemas/Ecosystem/company.graphql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql/schemas/Ecosystem/company.graphql b/graphql/schemas/Ecosystem/company.graphql index ce97e5613..d9caa5618 100644 --- a/graphql/schemas/Ecosystem/company.graphql +++ b/graphql/schemas/Ecosystem/company.graphql @@ -257,7 +257,7 @@ extend type Mutation @guardByAdmin { @field( resolver: "App\\GraphQL\\Ecosystem\\Mutations\\Companies\\CompanyManagementMutation@updateCompany" ) - updateCompanyPhotoProfile(file: Upload!, id: ID!): User! + updateCompanyPhotoProfile(file: Upload!, id: ID!): Company! @guard @field( resolver: "App\\GraphQL\\Ecosystem\\Mutations\\Companies\\CompanyManagementMutation@updatePhotoProfile" From b529c83b15d4e4962b12450b1bf6fa7539a5da5c Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 1 Sep 2024 23:01:25 -0400 Subject: [PATCH 039/108] feat: simple command to send daily emails --- .../UserEngagementReminderCommand.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php diff --git a/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php b/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php new file mode 100644 index 000000000..31a07bfaf --- /dev/null +++ b/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php @@ -0,0 +1,86 @@ +argument('app_id')); + $this->overwriteAppService($app); + + $this->info('Sending User Engagement Reminder for app ' . $app->name . ' - ' . date('Y-m-d')); + //get the list of user form UsersAssociatedApps chuck by 100 records + $users = UsersAssociatedApps::fromApp($app) + ->where('is_delete', StateEnums::NO) + ->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue()) + ->chunk(100, function ($users) use ($app) { + foreach ($users as $user) { + //send email to user + $this->sendEmail($user, $app); + } + }); + } + + public function sendEmail(UsersAssociatedApps $user, Apps $app): void + { + //send email to user + $this->info('Sending email to user ' . $user->email); + + $lastVisitInDays = Carbon::parse($user->lastvisit)->diffInDays(Carbon::now()); + $this->info('Last visit in days ' . $lastVisitInDays); + + $engagementEmailTemplateConfiguration = $app->get('engagement_email_template') ?? []; + + if (empty($engagementEmailTemplateConfiguration)) { + $this->info('No email template configuration found'); + + return; + } + + if (empty($engagementEmailTemplateConfiguration[$lastVisitInDays])) { + $this->info('No email template configuration found for ' . $lastVisitInDays . ' days'); + + return; + } + + $emailTemplate = $engagementEmailTemplateConfiguration[$lastVisitInDays]; + $notification = new Blank( + $emailTemplate, + ['app' => $app, 'user' => $user->user], + ['mail'], + $user + ); + + Notification::route('mail', $user->email)->notify($notification); + $this->info('Email sent to ' . $user->email); + } +} From 7c40a1822e5e16b9a67b7c11623907f5c79bbc86 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 1 Sep 2024 23:02:03 -0400 Subject: [PATCH 040/108] feat: simple command to send daily emails --- app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php b/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php index 31a07bfaf..68f1e9fe0 100644 --- a/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php +++ b/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php @@ -81,6 +81,7 @@ public function sendEmail(UsersAssociatedApps $user, Apps $app): void ); Notification::route('mail', $user->email)->notify($notification); + //@todo save it in user activity log on social? $this->info('Email sent to ' . $user->email); } } From 7628c09e2e5a2684c3fe53b0599d864d7cead5e1 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 1 Sep 2024 23:15:29 -0400 Subject: [PATCH 041/108] feat: allow user to set message as private --- graphql/schemas/Social/message.graphql | 1 + .../Messages/Actions/CreateMessageAction.php | 1 + .../DataTransferObject/MessageInput.php | 6 ++- tests/GraphQL/Social/MessageTest.php | 37 +++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/graphql/schemas/Social/message.graphql b/graphql/schemas/Social/message.graphql index 6b8a8ec12..1559f3498 100644 --- a/graphql/schemas/Social/message.graphql +++ b/graphql/schemas/Social/message.graphql @@ -58,6 +58,7 @@ input MessageInput { message: Mixed! parent_id: ID system_modules_id: ID + is_public: Int entity_id: Mixed distribution: DistributionInput tags: [TagInput!] diff --git a/src/Domains/Social/Messages/Actions/CreateMessageAction.php b/src/Domains/Social/Messages/Actions/CreateMessageAction.php index 49875b661..66347983b 100644 --- a/src/Domains/Social/Messages/Actions/CreateMessageAction.php +++ b/src/Domains/Social/Messages/Actions/CreateMessageAction.php @@ -37,6 +37,7 @@ public function execute(): Message 'total_saved' => $this->messageInput->total_saved, 'total_shared' => $this->messageInput->total_shared, 'ip_address' => $this->messageInput->ip_address, + 'is_public' => $this->messageInput->is_public, ]; $validator = Validator::make($data, [ diff --git a/src/Domains/Social/Messages/DataTransferObject/MessageInput.php b/src/Domains/Social/Messages/DataTransferObject/MessageInput.php index b8059d190..9962af6c8 100644 --- a/src/Domains/Social/Messages/DataTransferObject/MessageInput.php +++ b/src/Domains/Social/Messages/DataTransferObject/MessageInput.php @@ -36,7 +36,8 @@ public function __construct( public ?int $total_shared = 0, public ?string $parent_unique_id = null, public ?string $ip_address = null, - public array $tags = [] + public array $tags = [], + public ?int $is_public = 1 ) { } @@ -76,7 +77,8 @@ public static function fromArray( $data['total_shared'] ?? 0, $parent ? $parent->uuid : null, $data['ip_address'] ?? null, - $data['tags'] ?? [] + $data['tags'] ?? [], + $data['is_public'] ?? 1 ); } } diff --git a/tests/GraphQL/Social/MessageTest.php b/tests/GraphQL/Social/MessageTest.php index 1fd2fc461..486a974ea 100644 --- a/tests/GraphQL/Social/MessageTest.php +++ b/tests/GraphQL/Social/MessageTest.php @@ -27,6 +27,7 @@ public function testCreateMessage() createMessage(input: $input) { id message + is_public } } ', @@ -42,6 +43,42 @@ public function testCreateMessage() 'data' => [ 'createMessage' => [ 'message' => $message, + 'is_public' => 1, + ], + ], + ]); + } + + public function testCreatePrivateMessage() + { + $messageType = MessageType::factory()->create(); + $message = fake()->text(); + Message::makeAllSearchable(); + + $this->graphQL( + ' + mutation createMessage($input: MessageInput!) { + createMessage(input: $input) { + id + message + is_public + } + } + ', + [ + 'input' => [ + 'message' => $message, + 'message_verb' => $messageType->verb, + 'system_modules_id' => 1, + 'entity_id' => '1', + 'is_public' => 0, + ], + ] + )->assertJson([ + 'data' => [ + 'createMessage' => [ + 'message' => $message, + 'is_public' => 0, ], ], ]); From 8d428115f48ee915bbff19fe5b6719e3b6541f3e Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 1 Sep 2024 23:17:52 -0400 Subject: [PATCH 042/108] Refact: class --- .../Commands/Ecosystem/UserEngagementReminderCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php b/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php index 68f1e9fe0..b87bb77d2 100644 --- a/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php +++ b/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Console\Commands\Guild; +namespace App\Console\Commands\Ecosystem; use Baka\Enums\StateEnums; use Baka\Traits\KanvasJobsTrait; From 6c713bc8adcea12a3c3bfd01b1136b8e9c13e490 Mon Sep 17 00:00:00 2001 From: kaioken Date: Mon, 2 Sep 2024 12:41:53 -0400 Subject: [PATCH 043/108] hotfix: subcription with octane --- config/octane.php | 1 + 1 file changed, 1 insertion(+) diff --git a/config/octane.php b/config/octane.php index 5436ca9a6..3a3ebca39 100644 --- a/config/octane.php +++ b/config/octane.php @@ -140,6 +140,7 @@ 'warm' => [ ...Octane::defaultServicesToWarm(), + Nuwave\Lighthouse\Subscriptions\SubscriptionRegistry::class, ], 'flush' => [ From 6c3fd4010e2ecde5cef70daf06f7e83fe0508b69 Mon Sep 17 00:00:00 2001 From: kaioken Date: Mon, 2 Sep 2024 14:58:59 -0400 Subject: [PATCH 044/108] hotfix: subcription with octane --- .env.example | 1 + app/Providers/EventServiceProvider.php | 3 +++ .../Tasks/Observers/TaskListItemObserver.php | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 src/Domains/ActionEngine/Tasks/Observers/TaskListItemObserver.php diff --git a/.env.example b/.env.example index 4f6e2bddc..a8d1cf128 100644 --- a/.env.example +++ b/.env.example @@ -111,6 +111,7 @@ RABBITMQ_HOST=rabbitmq LIGHTHOUSE_CACHE_ENABLE=false LIGHTHOUSE_SCHEMA_CACHE_ENABLE=false LIGHTHOUSE_CACHE_VERSION=2 +LIGHTHOUSE_SUBSCRIPTION_STORAGE_TTL=3600 #SEACH CONFIGURATION SCOUT_DRIVER=meilisearch diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 1f314aae5..e5fd4c397 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -5,6 +5,8 @@ namespace App\Providers; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; +use Kanvas\ActionEngine\Tasks\Models\TaskListItem; +use Kanvas\ActionEngine\Tasks\Observers\TaskListItemObserver; use Kanvas\Companies\Groups\Observers\CompaniesGroupsObserver; use Kanvas\Companies\Models\Companies; use Kanvas\Companies\Models\CompaniesGroups; @@ -97,6 +99,7 @@ public function boot() ProductsCategories::observe(ProductsCategoriesObserver::class); PeopleEmploymentHistory::observe(PeopleEmploymentHistoryObserver::class); People::observe(PeopleObserver::class); + TaskListItem::observe(TaskListItemObserver::class); } /** diff --git a/src/Domains/ActionEngine/Tasks/Observers/TaskListItemObserver.php b/src/Domains/ActionEngine/Tasks/Observers/TaskListItemObserver.php new file mode 100644 index 000000000..160eab436 --- /dev/null +++ b/src/Domains/ActionEngine/Tasks/Observers/TaskListItemObserver.php @@ -0,0 +1,17 @@ + Date: Mon, 2 Sep 2024 17:35:04 -0400 Subject: [PATCH 045/108] Refact: add brodcast event --- ...tion.php => LeadTaskUpdatedSubscription.php} | 6 +++--- app/Providers/EventServiceProvider.php | 6 +++--- graphql/schemas/ActionEngine/task.graphql | 15 +++++++++++---- .../Observers/TaskEngagementItemObserver.php | 17 +++++++++++++++++ .../Tasks/Observers/TaskListItemObserver.php | 17 ----------------- tests/GraphQL/ActionEngine/CompanyTaskTest.php | 4 ++-- 6 files changed, 36 insertions(+), 29 deletions(-) rename app/GraphQL/ActionEngine/Subscriptions/{TaskItemSubscription.php => LeadTaskUpdatedSubscription.php} (90%) create mode 100644 src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php delete mode 100644 src/Domains/ActionEngine/Tasks/Observers/TaskListItemObserver.php diff --git a/app/GraphQL/ActionEngine/Subscriptions/TaskItemSubscription.php b/app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php similarity index 90% rename from app/GraphQL/ActionEngine/Subscriptions/TaskItemSubscription.php rename to app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php index 59019e704..c9a291986 100644 --- a/app/GraphQL/ActionEngine/Subscriptions/TaskItemSubscription.php +++ b/app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php @@ -13,7 +13,7 @@ use Nuwave\Lighthouse\Subscriptions\Subscriber; use Nuwave\Lighthouse\Support\Contracts\GraphQLContext; -class TaskItemSubscription extends GraphQLSubscription +class LeadTaskUpdatedSubscription extends GraphQLSubscription { public function authorize(Subscriber $subscriber, Request $request): bool { @@ -25,8 +25,8 @@ public function filter(Subscriber $subscriber, mixed $root): bool try { UsersRepository::belongsToCompany($subscriber->context->user, $root->companyAction->company); } catch (Exception $e) { - return false; - } + return true; + } return true; } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index e5fd4c397..c9daddbd2 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -5,8 +5,8 @@ namespace App\Providers; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -use Kanvas\ActionEngine\Tasks\Models\TaskListItem; -use Kanvas\ActionEngine\Tasks\Observers\TaskListItemObserver; +use Kanvas\ActionEngine\Tasks\Models\TaskEngagementItem; +use Kanvas\ActionEngine\Tasks\Observers\TaskEngagementItemObserver; use Kanvas\Companies\Groups\Observers\CompaniesGroupsObserver; use Kanvas\Companies\Models\Companies; use Kanvas\Companies\Models\CompaniesGroups; @@ -99,7 +99,7 @@ public function boot() ProductsCategories::observe(ProductsCategoriesObserver::class); PeopleEmploymentHistory::observe(PeopleEmploymentHistoryObserver::class); People::observe(PeopleObserver::class); - TaskListItem::observe(TaskListItemObserver::class); + TaskEngagementItem::observe(TaskEngagementItemObserver::class); } /** diff --git a/graphql/schemas/ActionEngine/task.graphql b/graphql/schemas/ActionEngine/task.graphql index 7b61b5050..49eabec7f 100644 --- a/graphql/schemas/ActionEngine/task.graphql +++ b/graphql/schemas/ActionEngine/task.graphql @@ -29,8 +29,11 @@ type LeadTaskEngagementItem { updated_at: DateTime } -type Subscription { - leadTaskItemUpdated(lead_id: ID!): LeadTaskEngagementItem @subscription(class: "App\\GraphQL\\ActionEngine\\Subscriptions\\TaskItemSubscription") @guard +type Subscription @guard { + leadTaskUpdated(lead_id: ID!): LeadTaskEngagementItem + @subscription( + class: "App\\GraphQL\\ActionEngine\\Subscriptions\\LeadTaskUpdatedSubscription" + ) } extend type Query @guard { @@ -43,8 +46,12 @@ extend type Query @guard { } extend type Mutation @guard { - changeTaskEngagementItemStatus(id: ID!, lead_id: ID!, status: String!): Boolean! + changeTaskEngagementItemStatus( + id: ID! + lead_id: ID! + status: String! + ): Boolean! @field( resolver: "App\\GraphQL\\ActionEngine\\Mutations\\Engagements\\TaskEngagementMutation@changeEngagementTaskItemStatus" ) -} \ No newline at end of file +} diff --git a/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php new file mode 100644 index 000000000..5f9338229 --- /dev/null +++ b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php @@ -0,0 +1,17 @@ +item, true); + } +} diff --git a/src/Domains/ActionEngine/Tasks/Observers/TaskListItemObserver.php b/src/Domains/ActionEngine/Tasks/Observers/TaskListItemObserver.php deleted file mode 100644 index 160eab436..000000000 --- a/src/Domains/ActionEngine/Tasks/Observers/TaskListItemObserver.php +++ /dev/null @@ -1,17 +0,0 @@ -graphQL(' - subscription leadTaskItemUpdated($lead_id: ID!) { - leadTaskItemUpdated(lead_id: $lead_id) { + subscription leadTaskUpdated($lead_id: ID!) { + leadTaskUpdated(lead_id: $lead_id) { id status } From 7e22cb7290093cdeb033ee964dfe4838da2bc032 Mon Sep 17 00:00:00 2001 From: Rafael White Date: Mon, 2 Sep 2024 18:04:24 -0400 Subject: [PATCH 046/108] rename command and removed Explore Feed notification --- app/Console/Commands/MailAppUsersCommand.php | 57 +++++++++++++++++++ .../PromptMine/ExploreFeedCommand.php | 52 ----------------- .../Templates/PromptMine/ExploreFeed.php | 16 ------ 3 files changed, 57 insertions(+), 68 deletions(-) create mode 100644 app/Console/Commands/MailAppUsersCommand.php delete mode 100644 app/Console/Commands/PromptMine/ExploreFeedCommand.php delete mode 100644 src/Kanvas/Notifications/Templates/PromptMine/ExploreFeed.php diff --git a/app/Console/Commands/MailAppUsersCommand.php b/app/Console/Commands/MailAppUsersCommand.php new file mode 100644 index 000000000..5cb407dde --- /dev/null +++ b/app/Console/Commands/MailAppUsersCommand.php @@ -0,0 +1,57 @@ +argument('apps_id')); + $users = Users::select('users.id,users.firstname, users.email') + ->join('users_associated_apps', 'users_associated_apps.users_id', '=', 'users.id') + ->where('users.is_deleted', StateEnums::NO->getValue()) + ->where('users_associated_apps.apps_id', $app->getId()) + ->where('users_associated_apps.is_deleted', StateEnums::NO->getValue()) + ->get(); + + foreach ($users as $user) { + $notification = new Blank( + $this->argument('email_template_name'), + ['userFirstname' => $user->firstname], + ['mail'], + $user + ); + + $notification->setSubject('New on Prompt Mine: Explore, Create, and Share'); + Notification::route('mail', $user->email)->notify($notification); + $this->info('Email Succesfully sent to: ' . $user->getId() . " on app: " . $app->getId()); + $this->newLine(); + } + } +} diff --git a/app/Console/Commands/PromptMine/ExploreFeedCommand.php b/app/Console/Commands/PromptMine/ExploreFeedCommand.php deleted file mode 100644 index 9e763f49c..000000000 --- a/app/Console/Commands/PromptMine/ExploreFeedCommand.php +++ /dev/null @@ -1,52 +0,0 @@ -argument('app_id')); - $users = Users::select('users.firstname') - ->join('users_associated_apps', 'users_associated_apps.users_id', '=', 'users.id') - ->where('users.is_deleted', StateEnums::NO->getValue()) - ->where('users_associated_apps.apps_id', $app->getId()) - ->where('users_associated_apps.is_deleted', StateEnums::NO->getValue()) - ->get(); - - foreach ($users as $user) { - $exploreFeedNotification = new ExploreFeed( - $user, - [ - 'userFirstname' => $user->firstname - ] - ); - - $user->notify($exploreFeedNotification); - } - } -} diff --git a/src/Kanvas/Notifications/Templates/PromptMine/ExploreFeed.php b/src/Kanvas/Notifications/Templates/PromptMine/ExploreFeed.php deleted file mode 100644 index c50c9481f..000000000 --- a/src/Kanvas/Notifications/Templates/PromptMine/ExploreFeed.php +++ /dev/null @@ -1,16 +0,0 @@ - Date: Mon, 2 Sep 2024 18:05:03 -0400 Subject: [PATCH 047/108] refact: style --- .../ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php b/app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php index c9a291986..e28cbc7ce 100644 --- a/app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php +++ b/app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php @@ -26,7 +26,7 @@ public function filter(Subscriber $subscriber, mixed $root): bool UsersRepository::belongsToCompany($subscriber->context->user, $root->companyAction->company); } catch (Exception $e) { return true; - } + } return true; } From 5b2b0367f92bb85f3df86914eb24124bff1a5600 Mon Sep 17 00:00:00 2001 From: Rafael White Date: Mon, 2 Sep 2024 18:07:54 -0400 Subject: [PATCH 048/108] add subject as command argument --- app/Console/Commands/MailAppUsersCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/MailAppUsersCommand.php b/app/Console/Commands/MailAppUsersCommand.php index 5cb407dde..a90a5abba 100644 --- a/app/Console/Commands/MailAppUsersCommand.php +++ b/app/Console/Commands/MailAppUsersCommand.php @@ -18,7 +18,7 @@ class MailAppUsersCommand extends Command * * @var string */ - protected $signature = 'notifications:SentMailToAll {apps_id} {email_template_name}'; + protected $signature = 'notifications:SentMailToAll {apps_id} {email_template_name} {subject}'; /** * The console command description. @@ -48,7 +48,7 @@ public function handle() $user ); - $notification->setSubject('New on Prompt Mine: Explore, Create, and Share'); + $notification->setSubject($this->argument('subject')); Notification::route('mail', $user->email)->notify($notification); $this->info('Email Succesfully sent to: ' . $user->getId() . " on app: " . $app->getId()); $this->newLine(); From 4feba61b1179a583663d90f058b8963a7822170c Mon Sep 17 00:00:00 2001 From: Rafael White Date: Mon, 2 Sep 2024 18:12:56 -0400 Subject: [PATCH 049/108] add new name to command --- app/Console/Commands/MailAppUsersCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/MailAppUsersCommand.php b/app/Console/Commands/MailAppUsersCommand.php index a90a5abba..763142b53 100644 --- a/app/Console/Commands/MailAppUsersCommand.php +++ b/app/Console/Commands/MailAppUsersCommand.php @@ -18,7 +18,7 @@ class MailAppUsersCommand extends Command * * @var string */ - protected $signature = 'notifications:SentMailToAll {apps_id} {email_template_name} {subject}'; + protected $signature = 'kanvas:mail-notification-to-all-app-users {apps_id} {email_template_name} {subject}'; /** * The console command description. From 72e43aa49fbe45c6d6839a5f0dff20a0be1654f0 Mon Sep 17 00:00:00 2001 From: kaioken Date: Mon, 2 Sep 2024 18:42:17 -0400 Subject: [PATCH 050/108] refact: move subscription to lead --- .../Subscriptions/LeadUpdatedSubscription.php} | 10 +++++----- graphql/schemas/ActionEngine/task.graphql | 7 ------- graphql/schemas/Guild/lead.graphql | 7 +++++++ .../Observers/TaskEngagementItemObserver.php | 2 +- tests/GraphQL/ActionEngine/CompanyTaskTest.php | 18 ------------------ tests/GraphQL/Guild/LeadTest.php | 18 ++++++++++++++++++ 6 files changed, 31 insertions(+), 31 deletions(-) rename app/GraphQL/{ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php => Guild/Subscriptions/LeadUpdatedSubscription.php} (73%) diff --git a/app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php b/app/GraphQL/Guild/Subscriptions/LeadUpdatedSubscription.php similarity index 73% rename from app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php rename to app/GraphQL/Guild/Subscriptions/LeadUpdatedSubscription.php index e28cbc7ce..824595edc 100644 --- a/app/GraphQL/ActionEngine/Subscriptions/LeadTaskUpdatedSubscription.php +++ b/app/GraphQL/Guild/Subscriptions/LeadUpdatedSubscription.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace App\GraphQL\ActionEngine\Subscriptions; +namespace App\GraphQL\Guild\Subscriptions; use Exception; use Illuminate\Http\Request; -use Kanvas\ActionEngine\Tasks\Models\TaskListItem; +use Kanvas\Guild\Leads\Models\Lead; use Kanvas\Users\Repositories\UsersRepository; use Nuwave\Lighthouse\Execution\ResolveInfo; use Nuwave\Lighthouse\Schema\Types\GraphQLSubscription; use Nuwave\Lighthouse\Subscriptions\Subscriber; use Nuwave\Lighthouse\Support\Contracts\GraphQLContext; -class LeadTaskUpdatedSubscription extends GraphQLSubscription +class LeadUpdatedSubscription extends GraphQLSubscription { public function authorize(Subscriber $subscriber, Request $request): bool { @@ -23,7 +23,7 @@ public function authorize(Subscriber $subscriber, Request $request): bool public function filter(Subscriber $subscriber, mixed $root): bool { try { - UsersRepository::belongsToCompany($subscriber->context->user, $root->companyAction->company); + UsersRepository::belongsToThisApp($subscriber->context->user, $root->app, $root->company); } catch (Exception $e) { return true; } @@ -36,7 +36,7 @@ public function resolve( array $args, GraphQLContext $context, ResolveInfo $resolveInfo - ): TaskListItem { + ): Lead { return $root; } } diff --git a/graphql/schemas/ActionEngine/task.graphql b/graphql/schemas/ActionEngine/task.graphql index 49eabec7f..d18fb164d 100644 --- a/graphql/schemas/ActionEngine/task.graphql +++ b/graphql/schemas/ActionEngine/task.graphql @@ -29,13 +29,6 @@ type LeadTaskEngagementItem { updated_at: DateTime } -type Subscription @guard { - leadTaskUpdated(lead_id: ID!): LeadTaskEngagementItem - @subscription( - class: "App\\GraphQL\\ActionEngine\\Subscriptions\\LeadTaskUpdatedSubscription" - ) -} - extend type Query @guard { leadTaskItems(lead_id: ID!): [LeadTaskEngagementItem!]! @paginate( diff --git a/graphql/schemas/Guild/lead.graphql b/graphql/schemas/Guild/lead.graphql index 67d0630e7..325beceb7 100644 --- a/graphql/schemas/Guild/lead.graphql +++ b/graphql/schemas/Guild/lead.graphql @@ -171,6 +171,13 @@ extend type Mutation @guard { ) } +type Subscription @guard { + leadUpdate(id: ID!): Lead + @subscription( + class: "App\\GraphQL\\Guild\\Subscriptions\\LeadUpdatedSubscription" + ) +} + extend type Query @guard { leads( search: String @search diff --git a/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php index 5f9338229..aa716befb 100644 --- a/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php +++ b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php @@ -12,6 +12,6 @@ class TaskEngagementItemObserver public function saved(TaskEngagementItem $taskEngagementItem): void { // broadcast graphql subscription - Subscription::broadcast('leadTaskUpdated', $taskEngagementItem->item, true); + Subscription::broadcast('leadUpdate', $taskEngagementItem->lead, true); } } diff --git a/tests/GraphQL/ActionEngine/CompanyTaskTest.php b/tests/GraphQL/ActionEngine/CompanyTaskTest.php index 1b4da3609..de1a7f140 100644 --- a/tests/GraphQL/ActionEngine/CompanyTaskTest.php +++ b/tests/GraphQL/ActionEngine/CompanyTaskTest.php @@ -105,22 +105,4 @@ public function testGetLeadTaskEngagement() 'lead_id' => $leadId, // Passing the lead ID to the GraphQL query ])->assertOk(); } - - public function testSubscribeToLeadTask() - { - $lead = $this->createLeadAndGetResponse(); - $leadId = $lead['data']['createLead']['id']; - - $this->graphQL(' - subscription leadTaskUpdated($lead_id: ID!) { - leadTaskUpdated(lead_id: $lead_id) { - id - status - } - } - - ', [ - 'lead_id' => $leadId, // Passing the lead ID to the GraphQL query - ])->assertOk(); - } } diff --git a/tests/GraphQL/Guild/LeadTest.php b/tests/GraphQL/Guild/LeadTest.php index b43abe62b..90818a909 100644 --- a/tests/GraphQL/Guild/LeadTest.php +++ b/tests/GraphQL/Guild/LeadTest.php @@ -619,4 +619,22 @@ public function testChannelMessage() ], ]); } + + public function testLeadSubscription() + { + $lead = $this->createLeadAndGetResponse(); + $leadId = $lead['data']['createLead']['id']; + + $this->graphQL(' + subscription leadUpdate($lead_id: ID!) { + leadUpdate(id: $lead_id) { + id + title + } + } + + ', [ + 'lead_id' => $leadId, // Passing the lead ID to the GraphQL query + ])->assertOk(); + } } From 3d877008a4bdcb069db92aa87d2b744e6543630f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:47:25 +0000 Subject: [PATCH 051/108] build(deps): bump nuwave/lighthouse from 6.43.1 to 6.44.1 Bumps [nuwave/lighthouse](https://github.com/nuwave/lighthouse) from 6.43.1 to 6.44.1. - [Release notes](https://github.com/nuwave/lighthouse/releases) - [Changelog](https://github.com/nuwave/lighthouse/blob/master/CHANGELOG.md) - [Commits](https://github.com/nuwave/lighthouse/compare/v6.43.1...v6.44.1) --- updated-dependencies: - dependency-name: nuwave/lighthouse dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.lock b/composer.lock index e37d2aec7..f63951e22 100644 --- a/composer.lock +++ b/composer.lock @@ -6320,16 +6320,16 @@ }, { "name": "nuwave/lighthouse", - "version": "v6.43.1", + "version": "v6.44.1", "source": { "type": "git", "url": "https://github.com/nuwave/lighthouse.git", - "reference": "39f86b2efdab9808eed4aa42a9955f3da1a1260e" + "reference": "d924efec78d451f408d6a8c1c3b257025f0d4c83" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nuwave/lighthouse/zipball/39f86b2efdab9808eed4aa42a9955f3da1a1260e", - "reference": "39f86b2efdab9808eed4aa42a9955f3da1a1260e", + "url": "https://api.github.com/repos/nuwave/lighthouse/zipball/d924efec78d451f408d6a8c1c3b257025f0d4c83", + "reference": "d924efec78d451f408d6a8c1c3b257025f0d4c83", "shasum": "" }, "require": { @@ -6446,7 +6446,7 @@ "type": "patreon" } ], - "time": "2024-08-23T09:11:14+00:00" + "time": "2024-09-02T12:43:29+00:00" }, { "name": "nyholm/psr7", @@ -13439,16 +13439,16 @@ }, { "name": "webonyx/graphql-php", - "version": "v15.12.5", + "version": "v15.13.0", "source": { "type": "git", "url": "https://github.com/webonyx/graphql-php.git", - "reference": "7bcd31d1dcf67781ed5cb493b22c519c539c05e6" + "reference": "b3b8c5bba097b0db95098fadb63e8980e184a03b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/7bcd31d1dcf67781ed5cb493b22c519c539c05e6", - "reference": "7bcd31d1dcf67781ed5cb493b22c519c539c05e6", + "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/b3b8c5bba097b0db95098fadb63e8980e184a03b", + "reference": "b3b8c5bba097b0db95098fadb63e8980e184a03b", "shasum": "" }, "require": { @@ -13461,12 +13461,12 @@ "amphp/http-server": "^2.1", "dms/phpunit-arraysubset-asserts": "dev-master", "ergebnis/composer-normalize": "^2.28", - "friendsofphp/php-cs-fixer": "3.59.3", + "friendsofphp/php-cs-fixer": "3.63.2", "mll-lab/php-cs-fixer-config": "^5", "nyholm/psr7": "^1.5", "phpbench/phpbench": "^1.2", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "1.11.5", + "phpstan/phpstan": "1.12.0", "phpstan/phpstan-phpunit": "1.4.0", "phpstan/phpstan-strict-rules": "1.6.0", "phpunit/phpunit": "^9.5 || ^10.5.21", @@ -13501,7 +13501,7 @@ ], "support": { "issues": "https://github.com/webonyx/graphql-php/issues", - "source": "https://github.com/webonyx/graphql-php/tree/v15.12.5" + "source": "https://github.com/webonyx/graphql-php/tree/v15.13.0" }, "funding": [ { @@ -13509,7 +13509,7 @@ "type": "open_collective" } ], - "time": "2024-06-23T11:30:58+00:00" + "time": "2024-08-29T10:55:21+00:00" } ], "packages-dev": [ From 91f3b626f2db01d84ec730345e877e79695fd3c5 Mon Sep 17 00:00:00 2001 From: kaioken Date: Mon, 2 Sep 2024 23:10:20 -0400 Subject: [PATCH 052/108] refact: email notification --- .../MailAllAppUsersCommand.php} | 37 ++++++++++++------- .../UserEngagementReminderCommand.php | 15 +++++++- 2 files changed, 36 insertions(+), 16 deletions(-) rename app/Console/Commands/{MailAppUsersCommand.php => Ecosystem/MailAllAppUsersCommand.php} (59%) diff --git a/app/Console/Commands/MailAppUsersCommand.php b/app/Console/Commands/Ecosystem/MailAllAppUsersCommand.php similarity index 59% rename from app/Console/Commands/MailAppUsersCommand.php rename to app/Console/Commands/Ecosystem/MailAllAppUsersCommand.php index 763142b53..39c6c1e19 100644 --- a/app/Console/Commands/MailAppUsersCommand.php +++ b/app/Console/Commands/Ecosystem/MailAllAppUsersCommand.php @@ -1,18 +1,22 @@ argument('apps_id')); - $users = Users::select('users.id,users.firstname, users.email') - ->join('users_associated_apps', 'users_associated_apps.users_id', '=', 'users.id') - ->where('users.is_deleted', StateEnums::NO->getValue()) - ->where('users_associated_apps.apps_id', $app->getId()) - ->where('users_associated_apps.is_deleted', StateEnums::NO->getValue()) - ->get(); + $this->overwriteAppService($app); + + $users = UsersAssociatedApps::fromApp($app) + ->where('is_delete', StateEnums::NO) + ->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue()) + ->chunk(100, function ($users) use ($app) { + foreach ($users as $user) { + //send email to user + $this->sendEmail($user, $app); + } + }); foreach ($users as $user) { $notification = new Blank( @@ -50,7 +59,7 @@ public function handle() $notification->setSubject($this->argument('subject')); Notification::route('mail', $user->email)->notify($notification); - $this->info('Email Succesfully sent to: ' . $user->getId() . " on app: " . $app->getId()); + $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); $this->newLine(); } } diff --git a/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php b/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php index b87bb77d2..28ec01765 100644 --- a/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php +++ b/app/Console/Commands/Ecosystem/UserEngagementReminderCommand.php @@ -73,9 +73,20 @@ public function sendEmail(UsersAssociatedApps $user, Apps $app): void } $emailTemplate = $engagementEmailTemplateConfiguration[$lastVisitInDays]; + + if (! isset($emailTemplate['template'])) { + $this->info('No email template found for ' . $lastVisitInDays . ' days'); + + return; + } + $notification = new Blank( - $emailTemplate, - ['app' => $app, 'user' => $user->user], + $emailTemplate['template'], + [ + 'app' => $app, + 'user' => $user->user, + 'config' => $emailTemplate, + ], ['mail'], $user ); From 90cc51e094aa8e7ca0eba3e5e9e86b63167d0780 Mon Sep 17 00:00:00 2001 From: kaioken Date: Mon, 2 Sep 2024 23:20:25 -0400 Subject: [PATCH 053/108] refact : commands --- .../{ => AccessControl}/CreateRoleCommand.php | 2 +- .../AccessControl/UpdateAbilitiesCommand.php | 5 ++-- .../Companies}/DeleteCompanyCommand.php | 2 +- .../KanvasAppCreateKeyCommand.php | 2 +- .../KanvasEmailTemplateSync.php | 2 +- .../MailAllAppUsersCommand.php | 2 +- .../UserEngagementReminderCommand.php | 2 +- .../Users}/DeleteUsersRequestedCommand.php | 5 ++-- .../Users}/KanvasAppUserMigration.php | 2 +- .../Users}/KanvasUserAddToCompany.php | 5 ++-- .../Users}/KanvasUserRemoveFromCompany.php | 4 ++- .../{ => Setup}/FilesystemSetupCommand.php | 2 +- .../{Guild => Setup}/GuildSetupCommand.php | 2 +- .../{ => Setup}/InventorySetupCommand.php | 2 +- .../KanvasInventoryDefaultUpdate.php | 27 ++++++++++--------- .../{ => Setup}/SocialSetupCommand.php | 2 +- .../{ => Social}/CreateGlobalReaction.php | 4 ++- .../KanvasDashboardDefaultFieldCommand.php | 10 +++---- .../{ => Support}/KanvasFakeMigration.php | 4 ++- 19 files changed, 46 insertions(+), 40 deletions(-) rename app/Console/Commands/{ => AccessControl}/CreateRoleCommand.php (95%) rename app/Console/Commands/{ => Ecosystem/Companies}/DeleteCompanyCommand.php (96%) rename app/Console/Commands/{ => Ecosystem}/KanvasAppCreateKeyCommand.php (97%) rename app/Console/Commands/{ => Ecosystem}/KanvasEmailTemplateSync.php (97%) rename app/Console/Commands/Ecosystem/{ => Notifications}/MailAllAppUsersCommand.php (97%) rename app/Console/Commands/Ecosystem/{ => Notifications}/UserEngagementReminderCommand.php (98%) rename app/Console/Commands/{ => Ecosystem/Users}/DeleteUsersRequestedCommand.php (94%) rename app/Console/Commands/{ => Ecosystem/Users}/KanvasAppUserMigration.php (97%) rename app/Console/Commands/{ => Ecosystem/Users}/KanvasUserAddToCompany.php (96%) rename app/Console/Commands/{ => Ecosystem/Users}/KanvasUserRemoveFromCompany.php (94%) rename app/Console/Commands/{ => Setup}/FilesystemSetupCommand.php (97%) rename app/Console/Commands/{Guild => Setup}/GuildSetupCommand.php (96%) rename app/Console/Commands/{ => Setup}/InventorySetupCommand.php (96%) rename app/Console/Commands/{ => Setup}/KanvasInventoryDefaultUpdate.php (91%) rename app/Console/Commands/{ => Setup}/SocialSetupCommand.php (96%) rename app/Console/Commands/{ => Social}/CreateGlobalReaction.php (94%) rename app/Console/Commands/{ => Support}/KanvasDashboardDefaultFieldCommand.php (62%) rename app/Console/Commands/{ => Support}/KanvasFakeMigration.php (91%) diff --git a/app/Console/Commands/CreateRoleCommand.php b/app/Console/Commands/AccessControl/CreateRoleCommand.php similarity index 95% rename from app/Console/Commands/CreateRoleCommand.php rename to app/Console/Commands/AccessControl/CreateRoleCommand.php index bee21141f..f1b56b5ad 100644 --- a/app/Console/Commands/CreateRoleCommand.php +++ b/app/Console/Commands/AccessControl/CreateRoleCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Console\Commands; +namespace App\Console\Commands\AccessControl; use Illuminate\Console\Command; use Kanvas\AccessControlList\Actions\CreateRoleAction; diff --git a/app/Console/Commands/AccessControl/UpdateAbilitiesCommand.php b/app/Console/Commands/AccessControl/UpdateAbilitiesCommand.php index e5a4ede9b..7d1157a5f 100644 --- a/app/Console/Commands/AccessControl/UpdateAbilitiesCommand.php +++ b/app/Console/Commands/AccessControl/UpdateAbilitiesCommand.php @@ -1,13 +1,12 @@ info("Working company {$companyData->getId()} default region \n"); + try { $defaultRegion = Regions::firstOrCreate([ 'apps_id' => $app->getId(), 'companies_id' => $companyData->getId(), - 'slug' => Str::slug("Default"), + 'slug' => Str::slug('Default'), ], [ - 'name' => "Default", + 'name' => 'Default', 'is_default' => true, 'currency_id' => Currencies::where('code', 'USD')->firstOrFail()->getId(), 'users_id' => $companyData->users_id, - 'short_slug' => Str::slug("Default") + 'short_slug' => Str::slug('Default'), ]); } catch (Throwable $e) { $this->error('Error creating default region for : ' . $companyData->getId() . ' ' . $e->getMessage()); @@ -82,16 +82,17 @@ public function handle() if (! $defaultWarehouses) { $this->info("Working company {$companyData->getId()} default warehouse \n"); + try { $defaultWarehouses = Warehouses::firstOrCreate([ - 'name' => "Default", + 'name' => 'Default', 'companies_id' => $companyData->getId(), 'apps_id' => $app->getId(), 'regions_id' => $defaultRegion->getId(), ], [ 'is_default' => true, 'users_id' => $companyData->users_id, - 'is_published' => true + 'is_published' => true, ]); } catch (Throwable $e) { $this->error('Error creating default warehouse for : ' . $companyData->getId() . ' ' . $e->getMessage()); @@ -100,13 +101,14 @@ public function handle() if (! $defaultStatus) { $this->info("Working company {$companyData->getId()} default status \n"); + try { $defaultStatus = Status::firstOrCreate([ 'apps_id' => $app->getId(), 'companies_id' => $companyData->getId(), - 'slug' => Str::slug("Default"), + 'slug' => Str::slug('Default'), ], [ - 'name' => "Default", + 'name' => 'Default', 'is_default' => true, ]); } catch (Throwable $e) { @@ -116,13 +118,14 @@ public function handle() if (! $defaultChannel) { $this->info("Working company {$companyData->getId()} default channel \n"); + try { $defaultChannel = Channels::firstOrCreate([ 'companies_id' => $companyData->getId(), 'apps_id' => $app->getId(), - 'slug' => Str::slug("Default"), + 'slug' => Str::slug('Default'), ], [ - 'name' => "Default", + 'name' => 'Default', 'users_id' => $companyData->users_id, 'is_default' => true, ]); @@ -141,7 +144,7 @@ public function handle() $variant, $defaultWarehouses, [ - 'status_id' => $defaultStatus->getId() + 'status_id' => $defaultStatus->getId(), ] ); (new AddToWarehouseAction($variant, $defaultWarehouses, $variantWarehouseDto))->execute(); diff --git a/app/Console/Commands/SocialSetupCommand.php b/app/Console/Commands/Setup/SocialSetupCommand.php similarity index 96% rename from app/Console/Commands/SocialSetupCommand.php rename to app/Console/Commands/Setup/SocialSetupCommand.php index 435fd5fd9..3f055e1c0 100644 --- a/app/Console/Commands/SocialSetupCommand.php +++ b/app/Console/Commands/Setup/SocialSetupCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Console\Commands; +namespace App\Console\Commands\Setup; use Illuminate\Console\Command; use Kanvas\Apps\Models\Apps; diff --git a/app/Console/Commands/CreateGlobalReaction.php b/app/Console/Commands/Social/CreateGlobalReaction.php similarity index 94% rename from app/Console/Commands/CreateGlobalReaction.php rename to app/Console/Commands/Social/CreateGlobalReaction.php index 33f986a45..af009a8a7 100644 --- a/app/Console/Commands/CreateGlobalReaction.php +++ b/app/Console/Commands/Social/CreateGlobalReaction.php @@ -1,6 +1,8 @@ info("Setting default dashboard field..."); + $this->info('Setting default dashboard field...'); $app = Apps::findOrFail($this->argument('app_id')); $field = $this->argument('field'); $value = $this->argument('value'); diff --git a/app/Console/Commands/KanvasFakeMigration.php b/app/Console/Commands/Support/KanvasFakeMigration.php similarity index 91% rename from app/Console/Commands/KanvasFakeMigration.php rename to app/Console/Commands/Support/KanvasFakeMigration.php index e459c6a45..bbeef8381 100644 --- a/app/Console/Commands/KanvasFakeMigration.php +++ b/app/Console/Commands/Support/KanvasFakeMigration.php @@ -1,6 +1,8 @@ Date: Mon, 2 Sep 2024 23:27:06 -0400 Subject: [PATCH 054/108] refact: commands --- .../Ecosystem/Users/DeleteUsersRequestedCommand.php | 11 +++++++++++ app/Console/Kernel.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php b/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php index 37d7cfd43..d9418b457 100644 --- a/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php +++ b/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php @@ -4,6 +4,7 @@ namespace App\Console\Commands\Ecosystem\Users; +use Baka\Traits\KanvasJobsTrait; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; use Kanvas\Apps\Models\Apps; @@ -11,6 +12,8 @@ class DeleteUsersRequestedCommand extends Command { + use KanvasJobsTrait; + /** * The name and signature of the console command. * @@ -35,8 +38,16 @@ public function handle() $appsId = $this->argument('apps_id'); if ($appsId) { $app = Apps::findFirstOrFail($appsId); + $this->overwriteAppService($app); $this->info('Deleting user from app: ' . $app->name); } + + if (! $app->get('delete_users_request_process')) { + $this->info('Delete users request process is disabled'); + + return; + } + $days = $appsId ? $app->get('days_to_delete') : 30; $users = RequestDeletedAccount::when($appsId, function ($query) use ($appsId) { return $query->where('apps_id', $appsId); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 77014a276..1e4fb79a0 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -3,7 +3,7 @@ namespace App\Console; use App\Console\Commands\Connectors\Notifications\MailCaddieLabCommand; -use App\Console\Commands\DeleteUsersRequestedCommand; +use App\Console\Commands\Ecosystem\Users\DeleteUsersRequestedCommand; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Spatie\Health\Commands\DispatchQueueCheckJobsCommand; From 27e8a6dd39021f98e475606cb940bc22d8b3f935 Mon Sep 17 00:00:00 2001 From: kaioken Date: Mon, 2 Sep 2024 23:27:48 -0400 Subject: [PATCH 055/108] refact: commands --- .../Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php b/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php index d9418b457..fd5f9c16a 100644 --- a/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php +++ b/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php @@ -49,11 +49,13 @@ public function handle() } $days = $appsId ? $app->get('days_to_delete') : 30; + $users = RequestDeletedAccount::when($appsId, function ($query) use ($appsId) { return $query->where('apps_id', $appsId); })->where(DB::raw('DATEDIFF(request_date, CURDATE())'), '>', $days) ->where('is_deleted', 0) ->get(); + foreach ($users as $user) { echo 'Deleting user: ' . $user->email . PHP_EOL; $user->associateUsers()->deActive(); From 8795e37e188830c3fb16f16b0016cc454a7ea1be Mon Sep 17 00:00:00 2001 From: kaioken Date: Mon, 2 Sep 2024 23:43:36 -0400 Subject: [PATCH 056/108] fix: format --- .../Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php b/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php index fd5f9c16a..3fddd08a0 100644 --- a/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php +++ b/app/Console/Commands/Ecosystem/Users/DeleteUsersRequestedCommand.php @@ -49,7 +49,7 @@ public function handle() } $days = $appsId ? $app->get('days_to_delete') : 30; - + $users = RequestDeletedAccount::when($appsId, function ($query) use ($appsId) { return $query->where('apps_id', $appsId); })->where(DB::raw('DATEDIFF(request_date, CURDATE())'), '>', $days) From 14bc2cad0e3620934b231b0d930c500a5fb0cb96 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 00:41:36 -0400 Subject: [PATCH 057/108] hotfix: delete searchable records --- src/Baka/Traits/KanvasModelTrait.php | 9 +++++++++ src/Domains/Guild/Customers/Models/People.php | 4 +++- .../Inventory/Products/Models/Products.php | 18 +++++++++++++----- .../Inventory/Variants/Models/Variants.php | 4 +++- src/Domains/Social/Messages/Models/Message.php | 4 +++- src/Domains/Social/Tags/Models/Tag.php | 4 +++- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/Baka/Traits/KanvasModelTrait.php b/src/Baka/Traits/KanvasModelTrait.php index 1a1b74560..fbd7b5743 100644 --- a/src/Baka/Traits/KanvasModelTrait.php +++ b/src/Baka/Traits/KanvasModelTrait.php @@ -264,4 +264,13 @@ public function hasWorkflow(): bool { return method_exists($this, 'fireWorkflow'); } + + /** + * When you delete records and send it to searchable, you will only get id and is_deleted info, no relationship + * we need this method to do special delete on the searchable side. + */ + public function searchableDeleteRecord(): bool + { + return isset($this->id) && isset($this->is_deleted) && ! isset($this->companies_id); + } } diff --git a/src/Domains/Guild/Customers/Models/People.php b/src/Domains/Guild/Customers/Models/People.php index 6bdd74826..3bd6be26c 100644 --- a/src/Domains/Guild/Customers/Models/People.php +++ b/src/Domains/Guild/Customers/Models/People.php @@ -208,7 +208,9 @@ public function shouldBeSearchable(): bool public function searchableAs(): string { - $customIndex = $this->app ? $this->app->get('app_custom_people_index') : null; + $people = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + + $customIndex = $people->app ? $people->app->get('app_custom_people_index') : null; return config('scout.prefix') . ($customIndex ?? 'peoples'); } diff --git a/src/Domains/Inventory/Products/Models/Products.php b/src/Domains/Inventory/Products/Models/Products.php index 11ae19fb9..f339518d3 100644 --- a/src/Domains/Inventory/Products/Models/Products.php +++ b/src/Domains/Inventory/Products/Models/Products.php @@ -5,8 +5,8 @@ namespace Kanvas\Inventory\Products\Models; use Awobaz\Compoships\Compoships; -use Baka\Traits\HasLightHouseCache; use Baka\Support\Str; +use Baka\Traits\HasLightHouseCache; use Baka\Traits\SlugTrait; use Baka\Traits\UuidTrait; use Baka\Users\Contracts\UserInterface; @@ -16,12 +16,12 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Kanvas\Apps\Models\Apps; use Kanvas\Connectors\Shopify\Traits\HasShopifyCustomField; -use Kanvas\Inventory\Attributes\Models\Attributes; -use Kanvas\Inventory\Attributes\DataTransferObject\Attributes as AttributesDto; use Kanvas\Inventory\Attributes\Actions\CreateAttribute; -use Kanvas\Inventory\Products\Actions\AddAttributeAction; +use Kanvas\Inventory\Attributes\DataTransferObject\Attributes as AttributesDto; +use Kanvas\Inventory\Attributes\Models\Attributes; use Kanvas\Inventory\Categories\Models\Categories; use Kanvas\Inventory\Models\BaseModel; +use Kanvas\Inventory\Products\Actions\AddAttributeAction; use Kanvas\Inventory\Products\Factories\ProductFactory; use Kanvas\Inventory\ProductsTypes\Models\ProductsTypes; use Kanvas\Inventory\Status\Models\Status; @@ -220,7 +220,15 @@ public function toSearchableArray(): array public function searchableAs(): string { - $customIndex = $this->app ? $this->app->get('app_custom_product_index') : null; + $product = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + $customIndex = $product->app ? $product->app->get('app_custom_product_index') : null; + + //log info + logger('searchableAs', [ + 'prefix' => config('scout.prefix'), + 'customIndex' => $customIndex, + 'info' => $this->toArray(), + ]); return config('scout.prefix') . ($customIndex ?? 'product_index'); } diff --git a/src/Domains/Inventory/Variants/Models/Variants.php b/src/Domains/Inventory/Variants/Models/Variants.php index b1975f3e2..678b65875 100644 --- a/src/Domains/Inventory/Variants/Models/Variants.php +++ b/src/Domains/Inventory/Variants/Models/Variants.php @@ -316,7 +316,9 @@ public function toSearchableArray(): array public function searchableAs(): string { - $customIndex = $this->app ? $this->app->get('app_custom_product_variant_index') : null; + $variant = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + + $customIndex = $variant->app ? $variant->app->get('app_custom_product_variant_index') : null; return config('scout.prefix') . ($customIndex ?? 'product_variant_index'); } diff --git a/src/Domains/Social/Messages/Models/Message.php b/src/Domains/Social/Messages/Models/Message.php index a58103738..11527460b 100644 --- a/src/Domains/Social/Messages/Models/Message.php +++ b/src/Domains/Social/Messages/Models/Message.php @@ -142,7 +142,9 @@ public function getMyInteraction(): array public function searchableAs(): string { - $customIndex = $this->app ? $this->app->get('app_custom_message_index') : null; + $message = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + + $customIndex = $message->app ? $message->app->get('app_custom_message_index') : null; return config('scout.prefix') . ($customIndex ?? 'message_index'); } diff --git a/src/Domains/Social/Tags/Models/Tag.php b/src/Domains/Social/Tags/Models/Tag.php index 3f4460902..61d9bbb84 100644 --- a/src/Domains/Social/Tags/Models/Tag.php +++ b/src/Domains/Social/Tags/Models/Tag.php @@ -57,7 +57,9 @@ public function shouldBeSearchable(): bool public function searchableAs(): string { - $customIndex = $this->app ? $this->app->get('app_custom_tag_index') : null; + $tag = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + + $customIndex = $tag->app ? $tag->app->get('app_custom_tag_index') : null; return config('scout.prefix') . ($customIndex ?? 'tag_index'); } From ee803053ae877e6d8e8f3f054c35fcc4a8916843 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 00:41:57 -0400 Subject: [PATCH 058/108] hotfix: delete searchable records --- src/Domains/Inventory/Products/Models/Products.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Domains/Inventory/Products/Models/Products.php b/src/Domains/Inventory/Products/Models/Products.php index f339518d3..2d5e7c14e 100644 --- a/src/Domains/Inventory/Products/Models/Products.php +++ b/src/Domains/Inventory/Products/Models/Products.php @@ -223,13 +223,6 @@ public function searchableAs(): string $product = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); $customIndex = $product->app ? $product->app->get('app_custom_product_index') : null; - //log info - logger('searchableAs', [ - 'prefix' => config('scout.prefix'), - 'customIndex' => $customIndex, - 'info' => $this->toArray(), - ]); - return config('scout.prefix') . ($customIndex ?? 'product_index'); } From 6f1b8dfa8ffab5016bcc21cc287b439f98a8de70 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 00:49:50 -0400 Subject: [PATCH 059/108] hotfix: delete searchable records --- src/Kanvas/Enums/AppEnums.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kanvas/Enums/AppEnums.php b/src/Kanvas/Enums/AppEnums.php index ddb20fcee..aae07b03f 100644 --- a/src/Kanvas/Enums/AppEnums.php +++ b/src/Kanvas/Enums/AppEnums.php @@ -96,7 +96,7 @@ public function getValue(): mixed self::KANVAS_APP_REGION_HEADER => 'X-Kanvas-Region', self::KANVAS_APP_COMPANY_AUTH_HEADER => 'Company-Authorization', //@deprecated self::DISPLAYNAME_LOGIN => 'displayname_login', - self::VERSION => '1.0-RC3', + self::VERSION => '1.2', self::ANONYMOUS_USER_ID => -1, self::DEFAULT_APP_JWT_TOKEN_NAME => 'kanvas-login', }; From ba2efcddfeec83bc4299b1ee28a6c0e6d76ff60c Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 08:00:16 -0400 Subject: [PATCH 060/108] feat: message index filter --- src/Baka/Traits/KanvasModelTrait.php | 8 ++++++++ src/Domains/Guild/Leads/Observers/LeadObserver.php | 2 ++ src/Domains/Social/Messages/Models/Message.php | 11 +++++++++++ src/Domains/Social/Tags/Models/Tag.php | 5 ----- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Baka/Traits/KanvasModelTrait.php b/src/Baka/Traits/KanvasModelTrait.php index fbd7b5743..0ff15b259 100644 --- a/src/Baka/Traits/KanvasModelTrait.php +++ b/src/Baka/Traits/KanvasModelTrait.php @@ -273,4 +273,12 @@ public function searchableDeleteRecord(): bool { return isset($this->id) && isset($this->is_deleted) && ! isset($this->companies_id); } + + /** + * for scout don't index the record if is deleted. + */ + public function shouldBeSearchable(): bool + { + return ! $this->isDeleted(); + } } diff --git a/src/Domains/Guild/Leads/Observers/LeadObserver.php b/src/Domains/Guild/Leads/Observers/LeadObserver.php index b0cd91276..43b3a65ce 100644 --- a/src/Domains/Guild/Leads/Observers/LeadObserver.php +++ b/src/Domains/Guild/Leads/Observers/LeadObserver.php @@ -14,6 +14,7 @@ use Kanvas\Social\Channels\Actions\CreateChannelAction; use Kanvas\Social\Channels\DataTransferObject\Channel; use Kanvas\Workflow\Enums\WorkflowEnum; +use Nuwave\Lighthouse\Execution\Utils\Subscription; class LeadObserver { @@ -90,6 +91,7 @@ public function created(Lead $lead): void public function updated(Lead $lead): void { $lead->fireWorkflow(WorkflowEnum::UPDATED->value); + Subscription::broadcast('leadUpdate', $lead, true); $lead->clearLightHouseCache(); } } diff --git a/src/Domains/Social/Messages/Models/Message.php b/src/Domains/Social/Messages/Models/Message.php index 11527460b..b742aee33 100644 --- a/src/Domains/Social/Messages/Models/Message.php +++ b/src/Domains/Social/Messages/Models/Message.php @@ -149,6 +149,17 @@ public function searchableAs(): string return config('scout.prefix') . ($customIndex ?? 'message_index'); } + public function shouldBeSearchable(): bool + { + if ($this->isDeleted()) { + return false; + } + + $filterByMessageType = $this->app->get('index_message_by_type'); + + return ! $filterByMessageType || $this->messageType->name === $filterByMessageType; + } + protected static function newFactory(): Factory { return MessageFactory::new(); diff --git a/src/Domains/Social/Tags/Models/Tag.php b/src/Domains/Social/Tags/Models/Tag.php index 61d9bbb84..851b4f7ea 100644 --- a/src/Domains/Social/Tags/Models/Tag.php +++ b/src/Domains/Social/Tags/Models/Tag.php @@ -50,11 +50,6 @@ public function getTable() return $databaseName . '.tags'; } - public function shouldBeSearchable(): bool - { - return $this->is_deleted == 0; - } - public function searchableAs(): string { $tag = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); From af36ac172ef885e714ee4e4fed732efc86b7b75e Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 08:04:01 -0400 Subject: [PATCH 061/108] feat: message index filter --- src/Baka/Traits/KanvasModelTrait.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Baka/Traits/KanvasModelTrait.php b/src/Baka/Traits/KanvasModelTrait.php index 0ff15b259..2d40316ec 100644 --- a/src/Baka/Traits/KanvasModelTrait.php +++ b/src/Baka/Traits/KanvasModelTrait.php @@ -276,8 +276,10 @@ public function searchableDeleteRecord(): bool /** * for scout don't index the record if is deleted. + * cant use return type because of laravel scout class + * @return bool */ - public function shouldBeSearchable(): bool + public function shouldBeSearchable() { return ! $this->isDeleted(); } From 24f07382c3e3ca25fe44f91cf8272b7848ad44ea Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 08:05:05 -0400 Subject: [PATCH 062/108] feat: message index filter --- src/Baka/Traits/KanvasModelTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Baka/Traits/KanvasModelTrait.php b/src/Baka/Traits/KanvasModelTrait.php index 2d40316ec..ca9e4d0c3 100644 --- a/src/Baka/Traits/KanvasModelTrait.php +++ b/src/Baka/Traits/KanvasModelTrait.php @@ -276,7 +276,7 @@ public function searchableDeleteRecord(): bool /** * for scout don't index the record if is deleted. - * cant use return type because of laravel scout class + * cant use return type because of laravel scout class * @return bool */ public function shouldBeSearchable() From b72ecc1d3ed8d69b0bb589481692e9a003c8aa41 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 08:15:08 -0400 Subject: [PATCH 063/108] feat: message index filter --- src/Domains/Social/Messages/Models/Message.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Social/Messages/Models/Message.php b/src/Domains/Social/Messages/Models/Message.php index b742aee33..9aaa8adce 100644 --- a/src/Domains/Social/Messages/Models/Message.php +++ b/src/Domains/Social/Messages/Models/Message.php @@ -157,7 +157,7 @@ public function shouldBeSearchable(): bool $filterByMessageType = $this->app->get('index_message_by_type'); - return ! $filterByMessageType || $this->messageType->name === $filterByMessageType; + return ! $filterByMessageType || $this->messageType->verb === $filterByMessageType; } protected static function newFactory(): Factory From ac9ff4ea15b05a4dac5261b3df36f7ceeadb2814 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 08:45:07 -0400 Subject: [PATCH 064/108] feat: message index filter --- src/Domains/Social/Messages/Models/Message.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Domains/Social/Messages/Models/Message.php b/src/Domains/Social/Messages/Models/Message.php index 9aaa8adce..1f04f757e 100644 --- a/src/Domains/Social/Messages/Models/Message.php +++ b/src/Domains/Social/Messages/Models/Message.php @@ -17,6 +17,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Kanvas\AccessControlList\Traits\HasPermissions; +use Kanvas\Apps\Models\Apps; use Kanvas\Social\Channels\Models\Channel; use Kanvas\Social\Messages\Factories\MessageFactory; use Kanvas\Social\MessagesComments\Models\MessageComment; @@ -143,8 +144,20 @@ public function getMyInteraction(): array public function searchableAs(): string { $message = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + $app = $message->app; + + /** + * @todo move this to a global behavior + * in normal search , id is not set, so we need to use global app + * [null,{"is_deleted":"1970-01-01T00:00:00.000000Z","app":null}] where null is the id record + */ + if (! isset($this->id)) { + $app = app(Apps::class); + } + + $customIndex = $app ? $app->get('app_custom_message_index') : null; - $customIndex = $message->app ? $message->app->get('app_custom_message_index') : null; + logger('customIndex', [$customIndex, $message->toArray(), $this->toArray(), $this->id]); return config('scout.prefix') . ($customIndex ?? 'message_index'); } From 1544fd35d61b568858b36607f8335996a55e7f93 Mon Sep 17 00:00:00 2001 From: Rafael White Date: Tue, 3 Sep 2024 10:45:52 -0400 Subject: [PATCH 065/108] update from development --- .../Notifications/MailAllAppUsersCommand.php | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php index 59e8e2d79..f20887696 100644 --- a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php +++ b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php @@ -44,23 +44,20 @@ public function handle() ->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue()) ->chunk(100, function ($users) use ($app) { foreach ($users as $user) { - //send email to user - $this->sendEmail($user, $app); + $notification = new Blank( + $this->argument('email_template_name'), + ['userFirstname' => $user->firstname], + ['mail'], + $user + ); + + $notification->setSubject($this->argument('subject')); + Notification::route('mail', $user->email)->notify($notification); + $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); + $this->newLine(); } }); - foreach ($users as $user) { - $notification = new Blank( - $this->argument('email_template_name'), - ['userFirstname' => $user->firstname], - ['mail'], - $user - ); - - $notification->setSubject($this->argument('subject')); - Notification::route('mail', $user->email)->notify($notification); - $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); - $this->newLine(); - } + } } From d35c0cf79200825ad99345ec2b18863396e80183 Mon Sep 17 00:00:00 2001 From: Rafael White Date: Tue, 3 Sep 2024 10:47:11 -0400 Subject: [PATCH 066/108] fix format --- .../Ecosystem/Notifications/MailAllAppUsersCommand.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php index f20887696..de4c18f42 100644 --- a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php +++ b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php @@ -50,14 +50,11 @@ public function handle() ['mail'], $user ); - $notification->setSubject($this->argument('subject')); Notification::route('mail', $user->email)->notify($notification); $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); $this->newLine(); } }); - - } } From af66578038000521d8fe7ff045cb87882392d971 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 12:29:47 -0400 Subject: [PATCH 067/108] feat: apollo app sync --- .../Apollo/SyncAllPeopleInCompanyCommand.php | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php diff --git a/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php new file mode 100644 index 000000000..4ab8c17a7 --- /dev/null +++ b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php @@ -0,0 +1,116 @@ +argument('app_id')); + $perPage = (int) $this->argument('perPage'); + $total = (int) $this->argument('total'); + $this->overwriteAppService($app); + $company = Companies::getById((int) $this->argument('company_id')); + + $this->line('Syncing all people in company ' . $company->name . ' from app ' . $app->name . ' total ' . $total . ' per page ' . $perPage); + + $rateLimit = 400; // Maximum API calls per hour + $batchSize = 100; // Number of people to process per batch + $cacheKey = 'api_rate_limit'; + $resetKey = 'api_rate_limit_reset'; + $timeWindow = 60 * 60; // 1 hour in seconds + + // Check the current count of API calls + $currentCount = Cache::get($cacheKey, 0); + $resetTime = Cache::get($resetKey); + echo $currentCount; + + if ($currentCount >= $rateLimit) { + // If the limit is reached, calculate the remaining cooldown period + $waitTime = $resetTime->diffInSeconds(now()); + echo "Rate limit reached. Please wait $waitTime seconds to run the process again."; + + return; + } + + People::fromApp($app) + ->fromCompany($company) + ->leftJoinSub( + AppsCustomFields::select('entity_id') + ->where('name', ConfigurationEnum::APOLLO_DATA_ENRICHMENT_CUSTOM_FIELDS->value), + 'acf', + 'peoples.id', + '=', + 'acf.entity_id' + ) + ->whereNull('acf.entity_id') // Ensure only people without the custom field are listed + ->orderBy('peoples.id', 'asc') + ->chunk($batchSize, function ($peoples) use (&$currentCount, $rateLimit, $cacheKey, $resetKey, $timeWindow) { + foreach ($peoples as $people) { + if ($currentCount >= $rateLimit) { + // If the rate limit is reached, stop the operation and set the cooldown period + Cache::put($resetKey, now()->addSeconds($timeWindow), $timeWindow); + echo "Rate limit reached. Please wait $timeWindow seconds to run the process again."; + + return false; // Stop chunk processing + } + + $this->line('Syncing people ' . $people->id . ' ' . $people->firstname . ' ' . $people->lastname); + + + //sync people + /* $people->fireWorkflow( + WorkflowEnum::UPDATED->value, + true, + [ + 'app' => $people->app, + ] + ); + $people->clearLightHouseCache(); */ + + // Increment the API call counter for each person processed + $currentCount++; + Cache::put($cacheKey, $currentCount, $timeWindow); + + // Optional: Add a small delay between requests to avoid bursts + usleep(100000); // 100ms delay between each request + } + }); + + $this->line('All people in company ' . $company->name . ' from app ' . $app->name . ' synced'); + + return; + } +} From 1edc5d3b67a05909919901b069f0a5a37ff7c39a Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 12:34:15 -0400 Subject: [PATCH 068/108] refact: attribute types --- graphql/schemas/Inventory/attributestype.graphql | 6 +++--- tests/GraphQL/Inventory/AttributesTypesTest.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/graphql/schemas/Inventory/attributestype.graphql b/graphql/schemas/Inventory/attributestype.graphql index cbc37f317..1b7ada05a 100644 --- a/graphql/schemas/Inventory/attributestype.graphql +++ b/graphql/schemas/Inventory/attributestype.graphql @@ -25,7 +25,7 @@ type AttributesType { } -extend type Mutation @guard { +extend type Mutation @guardByAdmin { createAttributeType(input: AttributesTypeInput!): AttributesType! @field( resolver: "App\\GraphQL\\Inventory\\Mutations\\Attributes\\AttributeTypeMutation@create" @@ -41,7 +41,7 @@ extend type Mutation @guard { } extend type Query @guard { - attributestypes( + attributesTypes( search: String @search where: _ @whereConditions( @@ -64,6 +64,6 @@ extend type Query @guard { @paginate( defaultCount: 25 model: "Kanvas\\Inventory\\Attributes\\Models\\AttributesTypes" - scopes: ["fromApp", "fromCompany", "notDeleted"] + scopes: ["fromApp", "notDeleted"] ) } diff --git a/tests/GraphQL/Inventory/AttributesTypesTest.php b/tests/GraphQL/Inventory/AttributesTypesTest.php index e057a2198..3a5d0072b 100644 --- a/tests/GraphQL/Inventory/AttributesTypesTest.php +++ b/tests/GraphQL/Inventory/AttributesTypesTest.php @@ -52,13 +52,13 @@ public function testSearch(): void $response = $this->graphQL(' query { - attributestypes { + attributesTypes { data { name } } }'); - $this->assertArrayHasKey('name', $response->json()['data']['attributestypes']['data'][0]); + $this->assertArrayHasKey('name', $response->json()['data']['attributesTypes']['data'][0]); } /** From 1a458529c077478ceee22f15c2d0bc061e828e6c Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 13:34:00 -0400 Subject: [PATCH 069/108] refact: attribute types --- .../Apollo/SyncAllPeopleInCompanyCommand.php | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php index 4ab8c17a7..61cd81a9c 100644 --- a/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php +++ b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php @@ -5,6 +5,7 @@ namespace App\Console\Commands\Connectors\Apollo; use Baka\Traits\KanvasJobsTrait; +use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\Cache; use Kanvas\Apps\Models\Apps; @@ -44,8 +45,6 @@ public function handle() $this->overwriteAppService($app); $company = Companies::getById((int) $this->argument('company_id')); - $this->line('Syncing all people in company ' . $company->name . ' from app ' . $app->name . ' total ' . $total . ' per page ' . $perPage); - $rateLimit = 400; // Maximum API calls per hour $batchSize = 100; // Number of people to process per batch $cacheKey = 'api_rate_limit'; @@ -54,15 +53,22 @@ public function handle() // Check the current count of API calls $currentCount = Cache::get($cacheKey, 0); - $resetTime = Cache::get($resetKey); - echo $currentCount; + $resetTimestamp = Cache::get($resetKey); + + $this->line('Syncing ' . $currentCount . ' all people in company ' . $company->name . ' from app ' . $app->name . ' total ' . $total . ' per page ' . $perPage); + + if ($resetTimestamp) { + // Ensure $resetTimestamp is a Carbon instance + $resetTime = Carbon::parse($resetTimestamp); + $currentTimestamp = now()->timestamp; + $waitTime = $resetTime->timestamp - $currentTimestamp; - if ($currentCount >= $rateLimit) { - // If the limit is reached, calculate the remaining cooldown period - $waitTime = $resetTime->diffInSeconds(now()); - echo "Rate limit reached. Please wait $waitTime seconds to run the process again."; + if ($currentCount >= $rateLimit && $waitTime > 0) { + // If the limit is reached, calculate the remaining cooldown period + $this->line("Rate limit reached. Please wait $waitTime seconds to run the process again."); - return; + return; + } } People::fromApp($app) @@ -89,16 +95,15 @@ public function handle() $this->line('Syncing people ' . $people->id . ' ' . $people->firstname . ' ' . $people->lastname); - //sync people - /* $people->fireWorkflow( + $people->fireWorkflow( WorkflowEnum::UPDATED->value, true, [ - 'app' => $people->app, - ] + 'app' => $people->app, + ] ); - $people->clearLightHouseCache(); */ + $people->clearLightHouseCache(); // Increment the API call counter for each person processed $currentCount++; From 3fe4ab8a34057c72c82e0a00b6057a716471a4f5 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 14:01:21 -0400 Subject: [PATCH 070/108] refact: sync individual --- .../Connectors/Apollo/SyncAllPeopleInCompanyCommand.php | 2 +- .../Apollo/Workflows/Activities/ScreeningPeopleActivity.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php index 61cd81a9c..b37826e72 100644 --- a/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php +++ b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php @@ -23,7 +23,7 @@ class SyncAllPeopleInCompanyCommand extends Command * * @var string */ - protected $signature = 'kanvas:guild-apollo-people-sync {app_id} {company_id} {total=2000} {perPage=200}'; + protected $signature = 'kanvas:guild-apollo-people-sync {app_id} {company_id} {total=400} {perPage=200}'; /** * The console command description. diff --git a/src/Domains/Connectors/Apollo/Workflows/Activities/ScreeningPeopleActivity.php b/src/Domains/Connectors/Apollo/Workflows/Activities/ScreeningPeopleActivity.php index 494e44c13..277e8109f 100644 --- a/src/Domains/Connectors/Apollo/Workflows/Activities/ScreeningPeopleActivity.php +++ b/src/Domains/Connectors/Apollo/Workflows/Activities/ScreeningPeopleActivity.php @@ -152,6 +152,10 @@ private function updateEmploymentHistory(Model $people, AppInterface $app, array ) ))->execute(); + if (empty($employment['title'])) { + continue; + } + PeopleEmploymentHistory::firstOrCreate([ 'status' => (int)$employment['current'], 'start_date' => $employment['start_date'], From 072e7fcf85a5c606e83f95e7356fa2c3536d4acd Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 14:02:56 -0400 Subject: [PATCH 071/108] refact: sync individual --- .../Apollo/Workflows/Activities/ScreeningPeopleActivity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Connectors/Apollo/Workflows/Activities/ScreeningPeopleActivity.php b/src/Domains/Connectors/Apollo/Workflows/Activities/ScreeningPeopleActivity.php index 277e8109f..be346838d 100644 --- a/src/Domains/Connectors/Apollo/Workflows/Activities/ScreeningPeopleActivity.php +++ b/src/Domains/Connectors/Apollo/Workflows/Activities/ScreeningPeopleActivity.php @@ -155,7 +155,7 @@ private function updateEmploymentHistory(Model $people, AppInterface $app, array if (empty($employment['title'])) { continue; } - + PeopleEmploymentHistory::firstOrCreate([ 'status' => (int)$employment['current'], 'start_date' => $employment['start_date'], From b783f8b4b2fe004a55128e1a3b262b8513d44107 Mon Sep 17 00:00:00 2001 From: Rafael White Date: Tue, 3 Sep 2024 14:41:45 -0400 Subject: [PATCH 072/108] test mail using an example user --- .../Notifications/MailAllAppUsersCommand.php | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php index de4c18f42..edac6350c 100644 --- a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php +++ b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php @@ -12,6 +12,7 @@ use Kanvas\Enums\AppEnums; use Kanvas\Notifications\Templates\Blank; use Kanvas\Users\Models\UsersAssociatedApps; +use Kanvas\Users\Models\Users; class MailAllAppUsersCommand extends Command { @@ -39,22 +40,34 @@ public function handle() $app = Apps::getById((int) $this->argument('apps_id')); $this->overwriteAppService($app); - $users = UsersAssociatedApps::fromApp($app) - ->where('is_delete', StateEnums::NO) - ->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue()) - ->chunk(100, function ($users) use ($app) { - foreach ($users as $user) { - $notification = new Blank( - $this->argument('email_template_name'), - ['userFirstname' => $user->firstname], - ['mail'], - $user - ); - $notification->setSubject($this->argument('subject')); - Notification::route('mail', $user->email)->notify($notification); - $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); - $this->newLine(); - } - }); + // $users = UsersAssociatedApps::fromApp($app) + // ->where('is_delete', StateEnums::NO) + // ->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue()) + // ->chunk(100, function ($users) use ($app) { + // foreach ($users as $user) { + // $notification = new Blank( + // $this->argument('email_template_name'), + // ['userFirstname' => $user->firstname], + // ['mail'], + // $user + // ); + // $notification->setSubject($this->argument('subject')); + // Notification::route('mail', $user->email)->notify($notification); + // $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); + // $this->newLine(); + // } + // }); + + $user = Users::find(1817); + $notification = new Blank( + $this->argument('email_template_name'), + ['userFirstname' => $user->firstname], + ['mail'], + $user + ); + $notification->setSubject($this->argument('subject')); + Notification::route('mail', $user->email)->notify($notification); + $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); + $this->newLine(); } -} +} \ No newline at end of file From 8962d5a3ae053d86c1e0ecbf79f8a642713181c0 Mon Sep 17 00:00:00 2001 From: Rafael White Date: Tue, 3 Sep 2024 14:43:32 -0400 Subject: [PATCH 073/108] fix format --- .../Ecosystem/Notifications/MailAllAppUsersCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php index edac6350c..ed586ecaf 100644 --- a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php +++ b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php @@ -70,4 +70,5 @@ public function handle() $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); $this->newLine(); } -} \ No newline at end of file + +} From 7a29ec7a0f6dbbdc3127570330488544237ec95b Mon Sep 17 00:00:00 2001 From: Rafael White Date: Tue, 3 Sep 2024 14:44:37 -0400 Subject: [PATCH 074/108] fix format --- .../Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php index ed586ecaf..fa3e770b0 100644 --- a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php +++ b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php @@ -70,5 +70,4 @@ public function handle() $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); $this->newLine(); } - } From 369210a00114c9859c2f36b12c7d0c45cf58090a Mon Sep 17 00:00:00 2001 From: Rafael White Date: Tue, 3 Sep 2024 14:58:08 -0400 Subject: [PATCH 075/108] add watch arg to octane start to watch for changes in files --- docker-compose.development.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.development.yml b/docker-compose.development.yml index c20abc170..d1b5e63ad 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -34,7 +34,7 @@ services: command: - "sh" - "-c" - - "php artisan octane:start --server=swoole" + - "php artisan octane:start --watch --server=swoole" environment: WWWUSER: "${WWWUSER}" LARAVEL_SAIL: 1 From 7ed8c4237eb7ad7fea6b88df500c02318ad1d2e9 Mon Sep 17 00:00:00 2001 From: Rafael White Date: Tue, 3 Sep 2024 15:04:54 -0400 Subject: [PATCH 076/108] rollback changes --- docker-compose.development.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.development.yml b/docker-compose.development.yml index d1b5e63ad..c20abc170 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -34,7 +34,7 @@ services: command: - "sh" - "-c" - - "php artisan octane:start --watch --server=swoole" + - "php artisan octane:start --server=swoole" environment: WWWUSER: "${WWWUSER}" LARAVEL_SAIL: 1 From f67880cf0793ae885f108ad5ccee0fa49bae7611 Mon Sep 17 00:00:00 2001 From: Rafael White Date: Tue, 3 Sep 2024 15:14:18 -0400 Subject: [PATCH 077/108] remove testing code --- .../Notifications/MailAllAppUsersCommand.php | 46 +++++++------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php index fa3e770b0..10021f83a 100644 --- a/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php +++ b/app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php @@ -40,34 +40,22 @@ public function handle() $app = Apps::getById((int) $this->argument('apps_id')); $this->overwriteAppService($app); - // $users = UsersAssociatedApps::fromApp($app) - // ->where('is_delete', StateEnums::NO) - // ->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue()) - // ->chunk(100, function ($users) use ($app) { - // foreach ($users as $user) { - // $notification = new Blank( - // $this->argument('email_template_name'), - // ['userFirstname' => $user->firstname], - // ['mail'], - // $user - // ); - // $notification->setSubject($this->argument('subject')); - // Notification::route('mail', $user->email)->notify($notification); - // $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); - // $this->newLine(); - // } - // }); - - $user = Users::find(1817); - $notification = new Blank( - $this->argument('email_template_name'), - ['userFirstname' => $user->firstname], - ['mail'], - $user - ); - $notification->setSubject($this->argument('subject')); - Notification::route('mail', $user->email)->notify($notification); - $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); - $this->newLine(); + $users = UsersAssociatedApps::fromApp($app) + ->where('is_delete', StateEnums::NO) + ->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue()) + ->chunk(100, function ($users) use ($app) { + foreach ($users as $user) { + $notification = new Blank( + $this->argument('email_template_name'), + ['userFirstname' => $user->firstname], + ['mail'], + $user + ); + $notification->setSubject($this->argument('subject')); + Notification::route('mail', $user->email)->notify($notification); + $this->info('Email Successfully sent to: ' . $user->getId() . ' on app: ' . $app->getId()); + $this->newLine(); + } + }); } } From afba30117829fe9737542d1b32b9558304bf3aaa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:32:25 +0000 Subject: [PATCH 078/108] build(deps): bump swoole/ide-helper from 5.1.3 to 5.1.4 Bumps [swoole/ide-helper](https://github.com/swoole/ide-helper) from 5.1.3 to 5.1.4. - [Release notes](https://github.com/swoole/ide-helper/releases) - [Commits](https://github.com/swoole/ide-helper/compare/5.1.3...5.1.4) --- updated-dependencies: - dependency-name: swoole/ide-helper dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index f63951e22..639adfd1e 100644 --- a/composer.lock +++ b/composer.lock @@ -9756,16 +9756,16 @@ }, { "name": "swoole/ide-helper", - "version": "5.1.3", + "version": "5.1.4", "source": { "type": "git", "url": "https://github.com/swoole/ide-helper.git", - "reference": "9cfc6669b83be0fa6fface91a6f372a0bb84bf1a" + "reference": "e63299f488bf8332404ce4f80142a2ed1397edde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swoole/ide-helper/zipball/9cfc6669b83be0fa6fface91a6f372a0bb84bf1a", - "reference": "9cfc6669b83be0fa6fface91a6f372a0bb84bf1a", + "url": "https://api.github.com/repos/swoole/ide-helper/zipball/e63299f488bf8332404ce4f80142a2ed1397edde", + "reference": "e63299f488bf8332404ce4f80142a2ed1397edde", "shasum": "" }, "type": "library", @@ -9782,9 +9782,9 @@ "description": "IDE help files for Swoole.", "support": { "issues": "https://github.com/swoole/ide-helper/issues", - "source": "https://github.com/swoole/ide-helper/tree/5.1.3" + "source": "https://github.com/swoole/ide-helper/tree/5.1.4" }, - "time": "2024-06-17T05:45:20+00:00" + "time": "2024-09-03T04:39:02+00:00" }, { "name": "symfony/cache", From e0157c32e59c9565606b202d25b548760befa2e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:32:31 +0000 Subject: [PATCH 079/108] build(deps-dev): bump phpunit/phpunit from 11.3.1 to 11.3.2 Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 11.3.1 to 11.3.2. - [Release notes](https://github.com/sebastianbergmann/phpunit/releases) - [Changelog](https://github.com/sebastianbergmann/phpunit/blob/11.3.2/ChangeLog-11.3.md) - [Commits](https://github.com/sebastianbergmann/phpunit/compare/11.3.1...11.3.2) --- updated-dependencies: - dependency-name: phpunit/phpunit dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.lock b/composer.lock index f63951e22..1ce21947d 100644 --- a/composer.lock +++ b/composer.lock @@ -14271,16 +14271,16 @@ }, { "name": "phpunit/php-file-iterator", - "version": "5.0.1", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26" + "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6ed896bf50bbbfe4d504a33ed5886278c78e4a26", - "reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/118cfaaa8bc5aef3287bf315b6060b1174754af6", + "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6", "shasum": "" }, "require": { @@ -14320,7 +14320,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.0.1" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.1.0" }, "funding": [ { @@ -14328,7 +14328,7 @@ "type": "github" } ], - "time": "2024-07-03T05:06:37+00:00" + "time": "2024-08-27T05:02:59+00:00" }, { "name": "phpunit/php-invoker", @@ -14516,16 +14516,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.3.1", + "version": "11.3.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "fe179875ef0c14e90b75617002767eae0a742641" + "reference": "8a4de85cc4a78c59dd31cc4ef454b0029f8440dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fe179875ef0c14e90b75617002767eae0a742641", - "reference": "fe179875ef0c14e90b75617002767eae0a742641", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/8a4de85cc4a78c59dd31cc4ef454b0029f8440dc", + "reference": "8a4de85cc4a78c59dd31cc4ef454b0029f8440dc", "shasum": "" }, "require": { @@ -14539,8 +14539,8 @@ "phar-io/manifest": "^2.0.4", "phar-io/version": "^3.2.1", "php": ">=8.2", - "phpunit/php-code-coverage": "^11.0.5", - "phpunit/php-file-iterator": "^5.0.1", + "phpunit/php-code-coverage": "^11.0.6", + "phpunit/php-file-iterator": "^5.1.0", "phpunit/php-invoker": "^5.0.1", "phpunit/php-text-template": "^4.0.1", "phpunit/php-timer": "^7.0.1", @@ -14596,7 +14596,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.3.1" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.3.2" }, "funding": [ { @@ -14612,7 +14612,7 @@ "type": "tidelift" } ], - "time": "2024-08-13T06:14:23+00:00" + "time": "2024-09-03T12:00:26+00:00" }, { "name": "sebastian/cli-parser", From 0fc048b07700f00d8d50023286385da95d3501ab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:32:44 +0000 Subject: [PATCH 080/108] build(deps): bump laravel/socialite from 5.15.1 to 5.16.0 Bumps [laravel/socialite](https://github.com/laravel/socialite) from 5.15.1 to 5.16.0. - [Release notes](https://github.com/laravel/socialite/releases) - [Changelog](https://github.com/laravel/socialite/blob/5.x/CHANGELOG.md) - [Commits](https://github.com/laravel/socialite/compare/v5.15.1...v5.16.0) --- updated-dependencies: - dependency-name: laravel/socialite dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.lock b/composer.lock index f63951e22..8d4302bd5 100644 --- a/composer.lock +++ b/composer.lock @@ -3843,16 +3843,16 @@ }, { "name": "laravel/framework", - "version": "v11.21.0", + "version": "v11.22.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "9d9d36708d56665b12185493f684abce38ad2d30" + "reference": "868c75beacc47d0f361b919bbc155c0b619bf3d5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/9d9d36708d56665b12185493f684abce38ad2d30", - "reference": "9d9d36708d56665b12185493f684abce38ad2d30", + "url": "https://api.github.com/repos/laravel/framework/zipball/868c75beacc47d0f361b919bbc155c0b619bf3d5", + "reference": "868c75beacc47d0f361b919bbc155c0b619bf3d5", "shasum": "" }, "require": { @@ -4045,7 +4045,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-08-20T15:00:52+00:00" + "time": "2024-09-03T15:27:15+00:00" }, { "name": "laravel/octane", @@ -4400,16 +4400,16 @@ }, { "name": "laravel/socialite", - "version": "v5.15.1", + "version": "v5.16.0", "source": { "type": "git", "url": "https://github.com/laravel/socialite.git", - "reference": "cc02625f0bd1f95dc3688eb041cce0f1e709d029" + "reference": "40a2dc98c53d9dc6d55eadb0d490d3d72b73f1bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/socialite/zipball/cc02625f0bd1f95dc3688eb041cce0f1e709d029", - "reference": "cc02625f0bd1f95dc3688eb041cce0f1e709d029", + "url": "https://api.github.com/repos/laravel/socialite/zipball/40a2dc98c53d9dc6d55eadb0d490d3d72b73f1bf", + "reference": "40a2dc98c53d9dc6d55eadb0d490d3d72b73f1bf", "shasum": "" }, "require": { @@ -4468,7 +4468,7 @@ "issues": "https://github.com/laravel/socialite/issues", "source": "https://github.com/laravel/socialite" }, - "time": "2024-06-28T20:09:34+00:00" + "time": "2024-09-03T09:46:57+00:00" }, { "name": "laravel/tinker", From 2805ba8d8dc159af22b7e3b7798cdf2b5e32c145 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:32:55 +0000 Subject: [PATCH 081/108] build(deps): bump laravel/scout from 10.11.1 to 10.11.2 Bumps [laravel/scout](https://github.com/laravel/scout) from 10.11.1 to 10.11.2. - [Release notes](https://github.com/laravel/scout/releases) - [Changelog](https://github.com/laravel/scout/blob/10.x/CHANGELOG.md) - [Commits](https://github.com/laravel/scout/compare/v10.11.1...v10.11.2) --- updated-dependencies: - dependency-name: laravel/scout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.lock b/composer.lock index f63951e22..c352796e5 100644 --- a/composer.lock +++ b/composer.lock @@ -3843,16 +3843,16 @@ }, { "name": "laravel/framework", - "version": "v11.21.0", + "version": "v11.22.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "9d9d36708d56665b12185493f684abce38ad2d30" + "reference": "868c75beacc47d0f361b919bbc155c0b619bf3d5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/9d9d36708d56665b12185493f684abce38ad2d30", - "reference": "9d9d36708d56665b12185493f684abce38ad2d30", + "url": "https://api.github.com/repos/laravel/framework/zipball/868c75beacc47d0f361b919bbc155c0b619bf3d5", + "reference": "868c75beacc47d0f361b919bbc155c0b619bf3d5", "shasum": "" }, "require": { @@ -4045,7 +4045,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-08-20T15:00:52+00:00" + "time": "2024-09-03T15:27:15+00:00" }, { "name": "laravel/octane", @@ -4261,16 +4261,16 @@ }, { "name": "laravel/scout", - "version": "v10.11.1", + "version": "v10.11.2", "source": { "type": "git", "url": "https://github.com/laravel/scout.git", - "reference": "b31056d49ae0540a475947391d7ea8617d779aee" + "reference": "74f007d0f5b78f589014899094f7ddb4855b771d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/scout/zipball/b31056d49ae0540a475947391d7ea8617d779aee", - "reference": "b31056d49ae0540a475947391d7ea8617d779aee", + "url": "https://api.github.com/repos/laravel/scout/zipball/74f007d0f5b78f589014899094f7ddb4855b771d", + "reference": "74f007d0f5b78f589014899094f7ddb4855b771d", "shasum": "" }, "require": { @@ -4335,7 +4335,7 @@ "issues": "https://github.com/laravel/scout/issues", "source": "https://github.com/laravel/scout" }, - "time": "2024-08-06T15:13:57+00:00" + "time": "2024-09-03T15:30:25+00:00" }, { "name": "laravel/serializable-closure", From a948e09d6934bc39e6299330c57db7bfb4d1d24d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:33:10 +0000 Subject: [PATCH 082/108] build(deps): bump laravel/framework from 11.21.0 to 11.22.0 Bumps [laravel/framework](https://github.com/laravel/framework) from 11.21.0 to 11.22.0. - [Release notes](https://github.com/laravel/framework/releases) - [Changelog](https://github.com/laravel/framework/blob/11.x/CHANGELOG.md) - [Commits](https://github.com/laravel/framework/compare/v11.21.0...v11.22.0) --- updated-dependencies: - dependency-name: laravel/framework dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index f63951e22..ff441ff53 100644 --- a/composer.lock +++ b/composer.lock @@ -3843,16 +3843,16 @@ }, { "name": "laravel/framework", - "version": "v11.21.0", + "version": "v11.22.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "9d9d36708d56665b12185493f684abce38ad2d30" + "reference": "868c75beacc47d0f361b919bbc155c0b619bf3d5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/9d9d36708d56665b12185493f684abce38ad2d30", - "reference": "9d9d36708d56665b12185493f684abce38ad2d30", + "url": "https://api.github.com/repos/laravel/framework/zipball/868c75beacc47d0f361b919bbc155c0b619bf3d5", + "reference": "868c75beacc47d0f361b919bbc155c0b619bf3d5", "shasum": "" }, "require": { @@ -4045,7 +4045,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-08-20T15:00:52+00:00" + "time": "2024-09-03T15:27:15+00:00" }, { "name": "laravel/octane", From 6628c2fc358d35dbeefdbb8a79ade50618969cad Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 20:47:29 -0400 Subject: [PATCH 083/108] feat: add task brocast events --- .../UserEngagementReminderCommand.php | 9 +++-- .../Tasks/Events/TaskEngagementItemEvent.php | 40 +++++++++++++++++++ .../Observers/TaskEngagementItemObserver.php | 9 ++++- 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php diff --git a/app/Console/Commands/Ecosystem/Notifications/UserEngagementReminderCommand.php b/app/Console/Commands/Ecosystem/Notifications/UserEngagementReminderCommand.php index 1c6e51926..a7212fc18 100644 --- a/app/Console/Commands/Ecosystem/Notifications/UserEngagementReminderCommand.php +++ b/app/Console/Commands/Ecosystem/Notifications/UserEngagementReminderCommand.php @@ -8,6 +8,7 @@ use Baka\Traits\KanvasJobsTrait; use Carbon\Carbon; use Illuminate\Console\Command; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Notification; use Kanvas\Apps\Models\Apps; use Kanvas\Enums\AppEnums; @@ -39,12 +40,14 @@ public function handle(): void $this->info('Sending User Engagement Reminder for app ' . $app->name . ' - ' . date('Y-m-d')); //get the list of user form UsersAssociatedApps chuck by 100 records - $users = UsersAssociatedApps::fromApp($app) - ->where('is_delete', StateEnums::NO) + DB::table('users_associated_apps') + ->where('apps_id', $app->id) // Assuming 'app_id' is the foreign key + ->where('is_deleted', StateEnums::NO->getValue()) ->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue()) + ->orderBy('users_id') // Order by primary or unique key for consistency ->chunk(100, function ($users) use ($app) { + $users = UsersAssociatedApps::hydrate($users->toArray()); foreach ($users as $user) { - //send email to user $this->sendEmail($user, $app); } }); diff --git a/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php b/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php new file mode 100644 index 000000000..0c9cc60b2 --- /dev/null +++ b/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php @@ -0,0 +1,40 @@ + $this->leadTaskInfo->lead_id, + 'task_list_item_id' => $this->leadTaskInfo->task_list_item_id, + // other necessary data + ]; + } + + public function broadcastOn(): Channel + { + return new Channel('lead-tasks-' . $this->leadTaskInfo->lead_id); + } +} diff --git a/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php index aa716befb..115f73581 100644 --- a/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php +++ b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php @@ -4,14 +4,21 @@ namespace Kanvas\ActionEngine\Tasks\Observers; +use Kanvas\ActionEngine\Tasks\Events\TaskEngagementItemEvent; use Kanvas\ActionEngine\Tasks\Models\TaskEngagementItem; use Nuwave\Lighthouse\Execution\Utils\Subscription; +use stdClass; class TaskEngagementItemObserver { public function saved(TaskEngagementItem $taskEngagementItem): void { // broadcast graphql subscription - Subscription::broadcast('leadUpdate', $taskEngagementItem->lead, true); + //Subscription::broadcast('leadUpdate', $taskEngagementItem->lead, true); + $leadInfo = new stdClass(); + $leadInfo->lead_id = $taskEngagementItem->lead_id; + $leadInfo->task_list_item_id = $taskEngagementItem->task_list_item_id; + + TaskEngagementItemEvent::dispatch($leadInfo); } } From ea03963ee9f0cecc1d23005cfe61586763205830 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 20:58:29 -0400 Subject: [PATCH 084/108] refact: apollo daily 2k sync limit --- .../Apollo/SyncAllPeopleInCompanyCommand.php | 73 +++++++++----- composer.lock | 94 +++++++++---------- 2 files changed, 94 insertions(+), 73 deletions(-) diff --git a/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php index b37826e72..a06d1f733 100644 --- a/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php +++ b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php @@ -45,27 +45,43 @@ public function handle() $this->overwriteAppService($app); $company = Companies::getById((int) $this->argument('company_id')); - $rateLimit = 400; // Maximum API calls per hour + $hourlyRateLimit = 400; // Maximum API calls per hour + $dailyRateLimit = 2000; // Maximum API calls per day $batchSize = 100; // Number of people to process per batch - $cacheKey = 'api_rate_limit'; - $resetKey = 'api_rate_limit_reset'; - $timeWindow = 60 * 60; // 1 hour in seconds + $hourlyCacheKey = 'api_hourly_rate_limit_' . $app->getId(); + $dailyCacheKey = 'api_daily_rate_limit_' . $app->getId(); + $resetHourlyKey = 'api_hourly_rate_limit_reset_' . $app->getId(); + $resetDailyKey = 'api_daily_rate_limit_reset_' . $app->getId(); + $hourlyTimeWindow = 60 * 60; // 1 hour in seconds + $dailyTimeWindow = 24 * 60 * 60; // 24 hours in seconds // Check the current count of API calls - $currentCount = Cache::get($cacheKey, 0); - $resetTimestamp = Cache::get($resetKey); + $currentHourlyCount = Cache::get($hourlyCacheKey, 0); + $currentDailyCount = Cache::get($dailyCacheKey, 0); + $resetHourlyTimestamp = Cache::get($resetHourlyKey); + $resetDailyTimestamp = Cache::get($resetDailyKey); - $this->line('Syncing ' . $currentCount . ' all people in company ' . $company->name . ' from app ' . $app->name . ' total ' . $total . ' per page ' . $perPage); + $this->line('Syncing ' . $currentHourlyCount . ' people in company ' . $company->name . ' from app ' . $app->name . ' total ' . $total . ' per page ' . $perPage); - if ($resetTimestamp) { - // Ensure $resetTimestamp is a Carbon instance - $resetTime = Carbon::parse($resetTimestamp); + if ($resetHourlyTimestamp) { + $resetHourlyTime = Carbon::parse($resetHourlyTimestamp); $currentTimestamp = now()->timestamp; - $waitTime = $resetTime->timestamp - $currentTimestamp; + $hourlyWaitTime = $resetHourlyTime->timestamp - $currentTimestamp; - if ($currentCount >= $rateLimit && $waitTime > 0) { - // If the limit is reached, calculate the remaining cooldown period - $this->line("Rate limit reached. Please wait $waitTime seconds to run the process again."); + if ($currentHourlyCount >= $hourlyRateLimit && $hourlyWaitTime > 0) { + $this->line("Hourly rate limit reached. Please wait $hourlyWaitTime seconds to run the process again."); + + return; + } + } + + if ($resetDailyTimestamp) { + $resetDailyTime = Carbon::parse($resetDailyTimestamp); + $currentTimestamp = now()->timestamp; + $dailyWaitTime = $resetDailyTime->timestamp - $currentTimestamp; + + if ($currentDailyCount >= $dailyRateLimit && $dailyWaitTime > 0) { + $this->line("Daily rate limit reached. Please wait $dailyWaitTime seconds to run the process again."); return; } @@ -81,21 +97,26 @@ public function handle() '=', 'acf.entity_id' ) - ->whereNull('acf.entity_id') // Ensure only people without the custom field are listed + ->whereNull('acf.entity_id') ->orderBy('peoples.id', 'asc') - ->chunk($batchSize, function ($peoples) use (&$currentCount, $rateLimit, $cacheKey, $resetKey, $timeWindow) { + ->chunk($batchSize, function ($peoples) use (&$currentHourlyCount, &$currentDailyCount, $hourlyRateLimit, $dailyRateLimit, $hourlyCacheKey, $dailyCacheKey, $resetHourlyKey, $resetDailyKey, $hourlyTimeWindow, $dailyTimeWindow) { foreach ($peoples as $people) { - if ($currentCount >= $rateLimit) { - // If the rate limit is reached, stop the operation and set the cooldown period - Cache::put($resetKey, now()->addSeconds($timeWindow), $timeWindow); - echo "Rate limit reached. Please wait $timeWindow seconds to run the process again."; + if ($currentHourlyCount >= $hourlyRateLimit) { + Cache::put($resetHourlyKey, now()->addSeconds($hourlyTimeWindow), $hourlyTimeWindow); + $this->line("Hourly rate limit reached. Please wait $hourlyTimeWindow seconds to run the process again."); + + return false; + } + + if ($currentDailyCount >= $dailyRateLimit) { + Cache::put($resetDailyKey, now()->addSeconds($dailyTimeWindow), $dailyTimeWindow); + $this->line("Daily rate limit reached. Please wait $dailyTimeWindow seconds to run the process again."); - return false; // Stop chunk processing + return false; } $this->line('Syncing people ' . $people->id . ' ' . $people->firstname . ' ' . $people->lastname); - //sync people $people->fireWorkflow( WorkflowEnum::UPDATED->value, true, @@ -105,11 +126,11 @@ public function handle() ); $people->clearLightHouseCache(); - // Increment the API call counter for each person processed - $currentCount++; - Cache::put($cacheKey, $currentCount, $timeWindow); + $currentHourlyCount++; + $currentDailyCount++; + Cache::put($hourlyCacheKey, $currentHourlyCount, $hourlyTimeWindow); + Cache::put($dailyCacheKey, $currentDailyCount, $dailyTimeWindow); - // Optional: Add a small delay between requests to avoid bursts usleep(100000); // 100ms delay between each request } }); diff --git a/composer.lock b/composer.lock index 355ba4f74..cc350b682 100644 --- a/composer.lock +++ b/composer.lock @@ -1195,16 +1195,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.320.7", + "version": "3.321.3", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "702b9955160d2dacdf2cdf4d4476fcf95eae1aaf" + "reference": "92e5d5fbfd3b29522b763d49d8f2fdf32e58fc1e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/702b9955160d2dacdf2cdf4d4476fcf95eae1aaf", - "reference": "702b9955160d2dacdf2cdf4d4476fcf95eae1aaf", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/92e5d5fbfd3b29522b763d49d8f2fdf32e58fc1e", + "reference": "92e5d5fbfd3b29522b763d49d8f2fdf32e58fc1e", "shasum": "" }, "require": { @@ -1287,9 +1287,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.320.7" + "source": "https://github.com/aws/aws-sdk-php/tree/3.321.3" }, - "time": "2024-08-23T18:13:50+00:00" + "time": "2024-09-03T18:04:21+00:00" }, { "name": "berkayk/onesignal-laravel", @@ -2440,16 +2440,16 @@ }, { "name": "google/apiclient-services", - "version": "v0.370.0", + "version": "v0.371.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-api-php-client-services.git", - "reference": "25ad8515701dd832313d0f5f0a828670d60e541a" + "reference": "2bebce17e419fb69917f8e807dc56298de38ea4e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/25ad8515701dd832313d0f5f0a828670d60e541a", - "reference": "25ad8515701dd832313d0f5f0a828670d60e541a", + "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/2bebce17e419fb69917f8e807dc56298de38ea4e", + "reference": "2bebce17e419fb69917f8e807dc56298de38ea4e", "shasum": "" }, "require": { @@ -2478,22 +2478,22 @@ ], "support": { "issues": "https://github.com/googleapis/google-api-php-client-services/issues", - "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.370.0" + "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.371.0" }, - "time": "2024-08-26T01:04:18+00:00" + "time": "2024-09-01T00:58:42+00:00" }, { "name": "google/auth", - "version": "v1.41.0", + "version": "v1.42.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-auth-library-php.git", - "reference": "1043ea18fe7f5dfbf5b208ce3ee6d6b6ab8cb038" + "reference": "0c25599a91530b5847f129b271c536f75a7563f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/1043ea18fe7f5dfbf5b208ce3ee6d6b6ab8cb038", - "reference": "1043ea18fe7f5dfbf5b208ce3ee6d6b6ab8cb038", + "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/0c25599a91530b5847f129b271c536f75a7563f5", + "reference": "0c25599a91530b5847f129b271c536f75a7563f5", "shasum": "" }, "require": { @@ -2538,9 +2538,9 @@ "support": { "docs": "https://googleapis.github.io/google-auth-library-php/main/", "issues": "https://github.com/googleapis/google-auth-library-php/issues", - "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.41.0" + "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.42.0" }, - "time": "2024-07-10T15:21:07+00:00" + "time": "2024-08-26T18:33:48+00:00" }, { "name": "google/cloud-core", @@ -2865,16 +2865,16 @@ }, { "name": "google/protobuf", - "version": "v4.27.3", + "version": "v4.28.0", "source": { "type": "git", "url": "https://github.com/protocolbuffers/protobuf-php.git", - "reference": "ff079fe467bf86ac8f3359e2eb77a1613ebd204d" + "reference": "17e3d804bf6631c2744c99575698f9cd4878b84f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/ff079fe467bf86ac8f3359e2eb77a1613ebd204d", - "reference": "ff079fe467bf86ac8f3359e2eb77a1613ebd204d", + "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/17e3d804bf6631c2744c99575698f9cd4878b84f", + "reference": "17e3d804bf6631c2744c99575698f9cd4878b84f", "shasum": "" }, "require": { @@ -2903,9 +2903,9 @@ "proto" ], "support": { - "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.27.3" + "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.28.0" }, - "time": "2024-07-31T13:27:16+00:00" + "time": "2024-08-28T17:54:02+00:00" }, { "name": "graham-campbell/result-type", @@ -6731,16 +6731,16 @@ }, { "name": "php-amqplib/php-amqplib", - "version": "v3.7.0", + "version": "v3.7.1", "source": { "type": "git", "url": "https://github.com/php-amqplib/php-amqplib.git", - "reference": "91fd00e74cd2eea624fd50a321d926b1c124bb99" + "reference": "5db9a68435fdde9ba4248a8fd2fae6d07b442b65" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-amqplib/php-amqplib/zipball/91fd00e74cd2eea624fd50a321d926b1c124bb99", - "reference": "91fd00e74cd2eea624fd50a321d926b1c124bb99", + "url": "https://api.github.com/repos/php-amqplib/php-amqplib/zipball/5db9a68435fdde9ba4248a8fd2fae6d07b442b65", + "reference": "5db9a68435fdde9ba4248a8fd2fae6d07b442b65", "shasum": "" }, "require": { @@ -6806,9 +6806,9 @@ ], "support": { "issues": "https://github.com/php-amqplib/php-amqplib/issues", - "source": "https://github.com/php-amqplib/php-amqplib/tree/v3.7.0" + "source": "https://github.com/php-amqplib/php-amqplib/tree/v3.7.1" }, - "time": "2024-07-09T21:10:28+00:00" + "time": "2024-09-03T19:18:03+00:00" }, { "name": "php-http/discovery", @@ -8482,16 +8482,16 @@ }, { "name": "rize/uri-template", - "version": "0.3.6", + "version": "0.3.8", "source": { "type": "git", "url": "https://github.com/rize/UriTemplate.git", - "reference": "34efe65c79710eed0883884f2285ae6d4a0aad19" + "reference": "34a5b96d0b65a5dddb7d20f09b6527a43faede24" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rize/UriTemplate/zipball/34efe65c79710eed0883884f2285ae6d4a0aad19", - "reference": "34efe65c79710eed0883884f2285ae6d4a0aad19", + "url": "https://api.github.com/repos/rize/UriTemplate/zipball/34a5b96d0b65a5dddb7d20f09b6527a43faede24", + "reference": "34a5b96d0b65a5dddb7d20f09b6527a43faede24", "shasum": "" }, "require": { @@ -8524,7 +8524,7 @@ ], "support": { "issues": "https://github.com/rize/UriTemplate/issues", - "source": "https://github.com/rize/UriTemplate/tree/0.3.6" + "source": "https://github.com/rize/UriTemplate/tree/0.3.8" }, "funding": [ { @@ -8540,7 +8540,7 @@ "type": "open_collective" } ], - "time": "2024-03-10T08:07:49+00:00" + "time": "2024-08-30T07:09:40+00:00" }, { "name": "sentry/sentry", @@ -12053,16 +12053,16 @@ }, { "name": "symfony/psr-http-message-bridge", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/psr-http-message-bridge.git", - "reference": "1365d10f5476f74a27cf9c2d1eee70c069019db0" + "reference": "405a7bcd872f1563966f64be19f1362d94ce71ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/psr-http-message-bridge/zipball/1365d10f5476f74a27cf9c2d1eee70c069019db0", - "reference": "1365d10f5476f74a27cf9c2d1eee70c069019db0", + "url": "https://api.github.com/repos/symfony/psr-http-message-bridge/zipball/405a7bcd872f1563966f64be19f1362d94ce71ab", + "reference": "405a7bcd872f1563966f64be19f1362d94ce71ab", "shasum": "" }, "require": { @@ -12116,7 +12116,7 @@ "psr-7" ], "support": { - "source": "https://github.com/symfony/psr-http-message-bridge/tree/v7.1.3" + "source": "https://github.com/symfony/psr-http-message-bridge/tree/v7.1.4" }, "funding": [ { @@ -12132,7 +12132,7 @@ "type": "tidelift" } ], - "time": "2024-07-17T06:10:24+00:00" + "time": "2024-08-15T22:48:53+00:00" }, { "name": "symfony/routing", @@ -14135,16 +14135,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.0", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "384af967d35b2162f69526c7276acadce534d0e1" + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", - "reference": "384af967d35b2162f69526c7276acadce534d0e1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", "shasum": "" }, "require": { @@ -14189,7 +14189,7 @@ "type": "github" } ], - "time": "2024-08-27T09:18:05+00:00" + "time": "2024-09-03T19:55:22+00:00" }, { "name": "phpunit/php-code-coverage", From 712b587349cb79c456638448ecbc1248133acaec Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 23:11:29 -0400 Subject: [PATCH 085/108] refact: task items channel brodcast --- .../Engagements/TaskEngagementBuilder.php | 18 ++--------- .../DataTransferObject/TaskEngagementItem.php | 16 ++++++++++ .../Tasks/Events/TaskEngagementItemEvent.php | 16 +++------- .../Observers/TaskEngagementItemObserver.php | 14 ++++----- .../TaskEngagementItemRepository.php | 31 +++++++++++++++++++ 5 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 src/Domains/ActionEngine/Tasks/DataTransferObject/TaskEngagementItem.php create mode 100644 src/Domains/ActionEngine/Tasks/Repositories/TaskEngagementItemRepository.php diff --git a/app/GraphQL/ActionEngine/Builders/Engagements/TaskEngagementBuilder.php b/app/GraphQL/ActionEngine/Builders/Engagements/TaskEngagementBuilder.php index 3282811b0..8f1307557 100644 --- a/app/GraphQL/ActionEngine/Builders/Engagements/TaskEngagementBuilder.php +++ b/app/GraphQL/ActionEngine/Builders/Engagements/TaskEngagementBuilder.php @@ -6,7 +6,7 @@ use GraphQL\Type\Definition\ResolveInfo; use Illuminate\Database\Eloquent\Builder; -use Kanvas\ActionEngine\Tasks\Models\TaskListItem; +use Kanvas\ActionEngine\Tasks\Repositories\TaskEngagementItemRepository; use Kanvas\Apps\Models\Apps; use Kanvas\Guild\Leads\Models\Lead; use Nuwave\Lighthouse\Support\Contracts\GraphQLContext; @@ -26,20 +26,6 @@ public function getLeadTaskItems( $lead = Lead::getByIdFromCompanyApp($args['lead_id'], $company, $app); $leadId = $lead->getId(); - return TaskListItem::leftJoin('company_task_engagement_items', function ($join) use ($lead) { - $join->on('company_task_list_items.id', '=', 'company_task_engagement_items.task_list_item_id') - ->where('company_task_engagement_items.lead_id', '=', $lead->getId()); - }) - ->leftJoin('company_task_list', 'company_task_list.id', '=', 'company_task_list_items.task_list_id') - ->where('company_task_list.companies_id', '=', $lead->companies_id) - ->select( - 'company_task_list_items.*', - 'company_task_engagement_items.lead_id', - 'company_task_engagement_items.status', - 'company_task_engagement_items.engagement_start_id', - 'company_task_engagement_items.engagement_end_id', - 'company_task_engagement_items.created_at', - 'company_task_engagement_items.updated_at' - ); + return TaskEngagementItemRepository::getLeadsTaskItems($lead); } } diff --git a/src/Domains/ActionEngine/Tasks/DataTransferObject/TaskEngagementItem.php b/src/Domains/ActionEngine/Tasks/DataTransferObject/TaskEngagementItem.php new file mode 100644 index 000000000..735acc6c1 --- /dev/null +++ b/src/Domains/ActionEngine/Tasks/DataTransferObject/TaskEngagementItem.php @@ -0,0 +1,16 @@ + $this->leadTaskInfo->lead_id, - 'task_list_item_id' => $this->leadTaskInfo->task_list_item_id, - // other necessary data - ]; + return TaskEngagementItemRepository::getLeadsTaskItems(Lead::getById($this->taskEngagementItem->leadId))->get()?->toArray(); } public function broadcastOn(): Channel { - return new Channel('lead-tasks-' . $this->leadTaskInfo->lead_id); + return new Channel('lead-tasks-' . $this->taskEngagementItem->leadId); } } diff --git a/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php index 115f73581..d82af87b1 100644 --- a/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php +++ b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php @@ -4,21 +4,21 @@ namespace Kanvas\ActionEngine\Tasks\Observers; +use Kanvas\ActionEngine\Tasks\DataTransferObject\TaskEngagementItem as DataTransferObjectTaskEngagementItem; use Kanvas\ActionEngine\Tasks\Events\TaskEngagementItemEvent; use Kanvas\ActionEngine\Tasks\Models\TaskEngagementItem; use Nuwave\Lighthouse\Execution\Utils\Subscription; -use stdClass; class TaskEngagementItemObserver { public function saved(TaskEngagementItem $taskEngagementItem): void { // broadcast graphql subscription - //Subscription::broadcast('leadUpdate', $taskEngagementItem->lead, true); - $leadInfo = new stdClass(); - $leadInfo->lead_id = $taskEngagementItem->lead_id; - $leadInfo->task_list_item_id = $taskEngagementItem->task_list_item_id; - - TaskEngagementItemEvent::dispatch($leadInfo); + Subscription::broadcast('leadUpdate', $taskEngagementItem->lead, true); + + TaskEngagementItemEvent::dispatch(DataTransferObjectTaskEngagementItem::from([ + 'leadId' => $taskEngagementItem->lead_id, + 'taskListItemId' => $taskEngagementItem->task_list_item_id, + ])); } } diff --git a/src/Domains/ActionEngine/Tasks/Repositories/TaskEngagementItemRepository.php b/src/Domains/ActionEngine/Tasks/Repositories/TaskEngagementItemRepository.php new file mode 100644 index 000000000..65242abc8 --- /dev/null +++ b/src/Domains/ActionEngine/Tasks/Repositories/TaskEngagementItemRepository.php @@ -0,0 +1,31 @@ +on('company_task_list_items.id', '=', 'company_task_engagement_items.task_list_item_id') + ->where('company_task_engagement_items.lead_id', '=', $lead->getId()); + }) + ->leftJoin('company_task_list', 'company_task_list.id', '=', 'company_task_list_items.task_list_id') + ->where('company_task_list.companies_id', '=', $lead->companies_id) + ->select( + 'company_task_list_items.*', + 'company_task_engagement_items.lead_id', + 'company_task_engagement_items.status', + 'company_task_engagement_items.engagement_start_id', + 'company_task_engagement_items.engagement_end_id', + 'company_task_engagement_items.created_at', + 'company_task_engagement_items.updated_at' + ); + } +} From c4373145e9c5103aed26b4341e16842ac2f24889 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 23:20:05 -0400 Subject: [PATCH 086/108] refact: code style --- .../ActionEngine/Tasks/Events/TaskEngagementItemEvent.php | 6 ++++-- .../Tasks/Observers/TaskEngagementItemObserver.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php b/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php index 8106253ea..8699b7c41 100644 --- a/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php +++ b/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php @@ -22,9 +22,11 @@ public function __construct( ) { } - public function broadcastWith() + public function broadcastWith(): array { - return TaskEngagementItemRepository::getLeadsTaskItems(Lead::getById($this->taskEngagementItem->leadId))->get()?->toArray(); + return TaskEngagementItemRepository::getLeadsTaskItems( + Lead::getById($this->taskEngagementItem->leadId) + )->get()?->toArray(); } public function broadcastOn(): Channel diff --git a/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php index d82af87b1..9cda8e3f9 100644 --- a/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php +++ b/src/Domains/ActionEngine/Tasks/Observers/TaskEngagementItemObserver.php @@ -16,9 +16,11 @@ public function saved(TaskEngagementItem $taskEngagementItem): void // broadcast graphql subscription Subscription::broadcast('leadUpdate', $taskEngagementItem->lead, true); - TaskEngagementItemEvent::dispatch(DataTransferObjectTaskEngagementItem::from([ + TaskEngagementItemEvent::dispatch( + DataTransferObjectTaskEngagementItem::from([ 'leadId' => $taskEngagementItem->lead_id, 'taskListItemId' => $taskEngagementItem->task_list_item_id, - ])); + ]) + ); } } From 190378849e7c6ef62b04795129fb916b81275d91 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 23:31:04 -0400 Subject: [PATCH 087/108] feat: add integartion test --- .../TaskEngagementItemTaskTest.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php diff --git a/tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php b/tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php new file mode 100644 index 000000000..cd5f30abf --- /dev/null +++ b/tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php @@ -0,0 +1,44 @@ +user()->getCurrentCompany(); + + /** + * @todo move to factory + */ + $people = new People(); + $people->users_id = auth()->user()->getId(); + $people->companies_id = $company->getId(); + $people->name = 'Test People'; + $people->saveOrFail(); + + $lead = new Lead(); + $lead->companies_id = $company->getId(); + $lead->companies_branches_id = $company->branch()->firstOrFail()->getId(); + $lead->users_id = auth()->user()->getId(); + $lead->people_id = $people->getId(); + $lead->title = 'Test Lead'; + $lead->leads_receivers_id = 0; + $lead->leads_owner_id = $lead->users_id; + $lead->saveOrFail(); + + $leadTaskItems = TaskEngagementItemRepository::getLeadsTaskItems($lead); + + $this->assertInstanceOf(Builder::class, $leadTaskItems); + $this->assertIsArray($leadTaskItems->get()->toArray()); + + } +} From 30c9b70ed444d599205cb712f13f85ea30f0d7ee Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 3 Sep 2024 23:35:22 -0400 Subject: [PATCH 088/108] feat: add integartion test --- tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php b/tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php index cd5f30abf..1da0c5fce 100644 --- a/tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php +++ b/tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php @@ -39,6 +39,5 @@ public function testGetLeadTaskItems(): void $this->assertInstanceOf(Builder::class, $leadTaskItems); $this->assertIsArray($leadTaskItems->get()->toArray()); - } } From 97ca26da84cabf2e6b9fd9158e6c6f758538c0e9 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 11:04:00 -0400 Subject: [PATCH 089/108] refact: delete algolia --- src/Baka/Search/DeleteInAlgoliaJob.php | 39 +++++++++++++++++++ src/Baka/Search/DeleteInMeiliSearchJob.php | 2 + src/Baka/Search/IndexInMeiliSearchJob.php | 2 + src/Baka/Search/MeiliSearchService.php | 2 + src/Baka/Traits/KanvasModelTrait.php | 2 +- .../Products/Actions/CreateProductAction.php | 2 +- .../Inventory/Products/Models/Products.php | 18 +++++++++ .../Products/Observers/ProductsObserver.php | 13 +++++++ .../Inventory/Variants/Models/Variants.php | 2 +- .../TaskEngagementItemTaskTest.php | 0 10 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/Baka/Search/DeleteInAlgoliaJob.php rename tests/ActionEngine/{Integrations => Integration}/TaskEngagementItemTaskTest.php (100%) diff --git a/src/Baka/Search/DeleteInAlgoliaJob.php b/src/Baka/Search/DeleteInAlgoliaJob.php new file mode 100644 index 000000000..962690d46 --- /dev/null +++ b/src/Baka/Search/DeleteInAlgoliaJob.php @@ -0,0 +1,39 @@ +model->refresh(); + $this->model->unsearchable(); + } +} diff --git a/src/Baka/Search/DeleteInMeiliSearchJob.php b/src/Baka/Search/DeleteInMeiliSearchJob.php index b99acb8fd..ec08288e0 100644 --- a/src/Baka/Search/DeleteInMeiliSearchJob.php +++ b/src/Baka/Search/DeleteInMeiliSearchJob.php @@ -1,5 +1,7 @@ id) && isset($this->is_deleted) && ! isset($this->companies_id); + return ! isset($this->app); } /** diff --git a/src/Domains/Inventory/Products/Actions/CreateProductAction.php b/src/Domains/Inventory/Products/Actions/CreateProductAction.php index 71c22e99b..2a647bb43 100644 --- a/src/Domains/Inventory/Products/Actions/CreateProductAction.php +++ b/src/Domains/Inventory/Products/Actions/CreateProductAction.php @@ -95,7 +95,7 @@ public function execute(): Products 'isVisible' => false, 'isSearchable' => false, 'isFiltrable' => false, - 'slug' => Str::slug($attribute['name']) + 'slug' => Str::slug($attribute['name']), ]); $attributeModel = (new CreateAttribute($attributesDto, $this->user))->execute(); diff --git a/src/Domains/Inventory/Products/Models/Products.php b/src/Domains/Inventory/Products/Models/Products.php index 2d5e7c14e..96dfa73d8 100644 --- a/src/Domains/Inventory/Products/Models/Products.php +++ b/src/Domains/Inventory/Products/Models/Products.php @@ -5,6 +5,7 @@ namespace Kanvas\Inventory\Products\Models; use Awobaz\Compoships\Compoships; +use Baka\Search\DeleteInAlgoliaSearchJob; use Baka\Support\Str; use Baka\Traits\HasLightHouseCache; use Baka\Traits\SlugTrait; @@ -164,6 +165,16 @@ public function shouldBeSearchable(): bool public function toSearchableArray(): array { + $this->load([ + 'company', // Load the company relationship + 'company.user', // Load the user through the company + 'categories', // Load categories + 'variants', // Load variants + 'status', // Load status + 'files', // Load files (if it's a relationship) + 'attributes', // Load attributes + ]); + $product = [ 'objectID' => $this->uuid, 'id' => $this->id, @@ -223,9 +234,16 @@ public function searchableAs(): string $product = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); $customIndex = $product->app ? $product->app->get('app_custom_product_index') : null; + logger('searchableAs', ['customIndex' => $customIndex, 'searchble' => (int) $this->shouldBeSearchable(), 'rpooduct' => $this->toArray()]); + return config('scout.prefix') . ($customIndex ?? 'product_index'); } + public function searchableSoftDelete(): void + { + DeleteInAlgoliaSearchJob::dispatch($this); + } + public static function search($query = '', $callback = null) { $query = self::traitSearch($query, $callback)->where('apps_id', app(Apps::class)->getId()); diff --git a/src/Domains/Inventory/Products/Observers/ProductsObserver.php b/src/Domains/Inventory/Products/Observers/ProductsObserver.php index 718f79128..9f417a4d5 100644 --- a/src/Domains/Inventory/Products/Observers/ProductsObserver.php +++ b/src/Domains/Inventory/Products/Observers/ProductsObserver.php @@ -24,5 +24,18 @@ public function created(Products $products): void } $products->clearLightHouseCache(); + + $products->load([ + 'company', // Load the company relationship + 'company.user', // Load the user through the company + 'categories', // Load categories + 'variants', // Load variants + 'status', // Load status + 'files', // Load files (if it's a relationship) + 'attributes', // Load attributes + ]); + + // Call searchable after loading relationships + $products->searchable(); } } diff --git a/src/Domains/Inventory/Variants/Models/Variants.php b/src/Domains/Inventory/Variants/Models/Variants.php index 678b65875..07ed3a07f 100644 --- a/src/Domains/Inventory/Variants/Models/Variants.php +++ b/src/Domains/Inventory/Variants/Models/Variants.php @@ -318,7 +318,7 @@ public function searchableAs(): string { $variant = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); - $customIndex = $variant->app ? $variant->app->get('app_custom_product_variant_index') : null; + $customIndex = isset($variant->app) ? $variant->app->get('app_custom_product_variant_index') : null; return config('scout.prefix') . ($customIndex ?? 'product_variant_index'); } diff --git a/tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php b/tests/ActionEngine/Integration/TaskEngagementItemTaskTest.php similarity index 100% rename from tests/ActionEngine/Integrations/TaskEngagementItemTaskTest.php rename to tests/ActionEngine/Integration/TaskEngagementItemTaskTest.php From ca5bd58d1be023bb3af53f3af99558991c31d84c Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 11:04:43 -0400 Subject: [PATCH 090/108] refact: delete algolia --- .../Products/Observers/ProductsObserver.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Domains/Inventory/Products/Observers/ProductsObserver.php b/src/Domains/Inventory/Products/Observers/ProductsObserver.php index 9f417a4d5..718f79128 100644 --- a/src/Domains/Inventory/Products/Observers/ProductsObserver.php +++ b/src/Domains/Inventory/Products/Observers/ProductsObserver.php @@ -24,18 +24,5 @@ public function created(Products $products): void } $products->clearLightHouseCache(); - - $products->load([ - 'company', // Load the company relationship - 'company.user', // Load the user through the company - 'categories', // Load categories - 'variants', // Load variants - 'status', // Load status - 'files', // Load files (if it's a relationship) - 'attributes', // Load attributes - ]); - - // Call searchable after loading relationships - $products->searchable(); } } From d0b933ce4829188065cd76b92fbebc01a5497842 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 11:15:47 -0400 Subject: [PATCH 091/108] hotfix: app --- .../{DeleteInAlgoliaJob.php => DeleteInAlgoliaSearchJob.php} | 0 src/Domains/Guild/Customers/Models/People.php | 2 +- src/Domains/Inventory/Products/Models/Products.php | 2 +- src/Domains/Social/Messages/Models/Message.php | 2 +- src/Domains/Social/Tags/Models/Tag.php | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename src/Baka/Search/{DeleteInAlgoliaJob.php => DeleteInAlgoliaSearchJob.php} (100%) diff --git a/src/Baka/Search/DeleteInAlgoliaJob.php b/src/Baka/Search/DeleteInAlgoliaSearchJob.php similarity index 100% rename from src/Baka/Search/DeleteInAlgoliaJob.php rename to src/Baka/Search/DeleteInAlgoliaSearchJob.php diff --git a/src/Domains/Guild/Customers/Models/People.php b/src/Domains/Guild/Customers/Models/People.php index 3bd6be26c..61d2d22d8 100644 --- a/src/Domains/Guild/Customers/Models/People.php +++ b/src/Domains/Guild/Customers/Models/People.php @@ -210,7 +210,7 @@ public function searchableAs(): string { $people = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); - $customIndex = $people->app ? $people->app->get('app_custom_people_index') : null; + $customIndex = isset($people->app) ? $people->app->get('app_custom_people_index') : null; return config('scout.prefix') . ($customIndex ?? 'peoples'); } diff --git a/src/Domains/Inventory/Products/Models/Products.php b/src/Domains/Inventory/Products/Models/Products.php index 96dfa73d8..da1b05e9c 100644 --- a/src/Domains/Inventory/Products/Models/Products.php +++ b/src/Domains/Inventory/Products/Models/Products.php @@ -232,7 +232,7 @@ public function toSearchableArray(): array public function searchableAs(): string { $product = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); - $customIndex = $product->app ? $product->app->get('app_custom_product_index') : null; + $customIndex = isset($product->app) ? $product->app->get('app_custom_product_index') : null; logger('searchableAs', ['customIndex' => $customIndex, 'searchble' => (int) $this->shouldBeSearchable(), 'rpooduct' => $this->toArray()]); diff --git a/src/Domains/Social/Messages/Models/Message.php b/src/Domains/Social/Messages/Models/Message.php index 1f04f757e..68efa6bc9 100644 --- a/src/Domains/Social/Messages/Models/Message.php +++ b/src/Domains/Social/Messages/Models/Message.php @@ -144,7 +144,7 @@ public function getMyInteraction(): array public function searchableAs(): string { $message = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); - $app = $message->app; + $app = $message->app ?? null; /** * @todo move this to a global behavior diff --git a/src/Domains/Social/Tags/Models/Tag.php b/src/Domains/Social/Tags/Models/Tag.php index 851b4f7ea..842b46a76 100644 --- a/src/Domains/Social/Tags/Models/Tag.php +++ b/src/Domains/Social/Tags/Models/Tag.php @@ -54,7 +54,7 @@ public function searchableAs(): string { $tag = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); - $customIndex = $tag->app ? $tag->app->get('app_custom_tag_index') : null; + $customIndex = isset($tag->app) ? $tag->app->get('app_custom_tag_index') : null; return config('scout.prefix') . ($customIndex ?? 'tag_index'); } From 1c13492b3fefdc374df4f99b3633f8dd413e11fa Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 11:24:38 -0400 Subject: [PATCH 092/108] hotfix: app --- src/Domains/Social/Messages/Models/Message.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Domains/Social/Messages/Models/Message.php b/src/Domains/Social/Messages/Models/Message.php index 68efa6bc9..637ff2f71 100644 --- a/src/Domains/Social/Messages/Models/Message.php +++ b/src/Domains/Social/Messages/Models/Message.php @@ -157,8 +157,6 @@ public function searchableAs(): string $customIndex = $app ? $app->get('app_custom_message_index') : null; - logger('customIndex', [$customIndex, $message->toArray(), $this->toArray(), $this->id]); - return config('scout.prefix') . ($customIndex ?? 'message_index'); } From ace18f5fbaf0540fd93efcb5815137505fbdbf3f Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 12:19:11 -0400 Subject: [PATCH 093/108] refact: figure out the usage of withTrashed --- src/Baka/Search/DeleteInAlgoliaSearchJob.php | 39 ------------------- src/Domains/Guild/Customers/Models/People.php | 2 +- .../Inventory/Products/Models/Products.php | 11 +----- .../Inventory/Variants/Models/Variants.php | 2 +- .../Social/Messages/Models/Message.php | 2 +- src/Domains/Social/Tags/Models/Tag.php | 2 +- 6 files changed, 6 insertions(+), 52 deletions(-) delete mode 100644 src/Baka/Search/DeleteInAlgoliaSearchJob.php diff --git a/src/Baka/Search/DeleteInAlgoliaSearchJob.php b/src/Baka/Search/DeleteInAlgoliaSearchJob.php deleted file mode 100644 index 962690d46..000000000 --- a/src/Baka/Search/DeleteInAlgoliaSearchJob.php +++ /dev/null @@ -1,39 +0,0 @@ -model->refresh(); - $this->model->unsearchable(); - } -} diff --git a/src/Domains/Guild/Customers/Models/People.php b/src/Domains/Guild/Customers/Models/People.php index 61d2d22d8..c3246c8be 100644 --- a/src/Domains/Guild/Customers/Models/People.php +++ b/src/Domains/Guild/Customers/Models/People.php @@ -208,7 +208,7 @@ public function shouldBeSearchable(): bool public function searchableAs(): string { - $people = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + $people = ! $this->searchableDeleteRecord() ? $this : $this->withTrashed()->find($this->id); $customIndex = isset($people->app) ? $people->app->get('app_custom_people_index') : null; diff --git a/src/Domains/Inventory/Products/Models/Products.php b/src/Domains/Inventory/Products/Models/Products.php index da1b05e9c..c9f36f603 100644 --- a/src/Domains/Inventory/Products/Models/Products.php +++ b/src/Domains/Inventory/Products/Models/Products.php @@ -5,7 +5,6 @@ namespace Kanvas\Inventory\Products\Models; use Awobaz\Compoships\Compoships; -use Baka\Search\DeleteInAlgoliaSearchJob; use Baka\Support\Str; use Baka\Traits\HasLightHouseCache; use Baka\Traits\SlugTrait; @@ -165,6 +164,7 @@ public function shouldBeSearchable(): bool public function toSearchableArray(): array { + $this->refresh(); $this->load([ 'company', // Load the company relationship 'company.user', // Load the user through the company @@ -231,19 +231,12 @@ public function toSearchableArray(): array public function searchableAs(): string { - $product = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + $product = ! $this->searchableDeleteRecord() ? $this : $this->withTrashed()->find($this->id); $customIndex = isset($product->app) ? $product->app->get('app_custom_product_index') : null; - logger('searchableAs', ['customIndex' => $customIndex, 'searchble' => (int) $this->shouldBeSearchable(), 'rpooduct' => $this->toArray()]); - return config('scout.prefix') . ($customIndex ?? 'product_index'); } - public function searchableSoftDelete(): void - { - DeleteInAlgoliaSearchJob::dispatch($this); - } - public static function search($query = '', $callback = null) { $query = self::traitSearch($query, $callback)->where('apps_id', app(Apps::class)->getId()); diff --git a/src/Domains/Inventory/Variants/Models/Variants.php b/src/Domains/Inventory/Variants/Models/Variants.php index 07ed3a07f..6000b2558 100644 --- a/src/Domains/Inventory/Variants/Models/Variants.php +++ b/src/Domains/Inventory/Variants/Models/Variants.php @@ -316,7 +316,7 @@ public function toSearchableArray(): array public function searchableAs(): string { - $variant = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + $variant = ! $this->searchableDeleteRecord() ? $this : $this->withTrashed()->find($this->id); $customIndex = isset($variant->app) ? $variant->app->get('app_custom_product_variant_index') : null; diff --git a/src/Domains/Social/Messages/Models/Message.php b/src/Domains/Social/Messages/Models/Message.php index 637ff2f71..8dfb2ce95 100644 --- a/src/Domains/Social/Messages/Models/Message.php +++ b/src/Domains/Social/Messages/Models/Message.php @@ -143,7 +143,7 @@ public function getMyInteraction(): array public function searchableAs(): string { - $message = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + $message = ! $this->searchableDeleteRecord() ? $this : $this->withTrashed()->find($this->id); $app = $message->app ?? null; /** diff --git a/src/Domains/Social/Tags/Models/Tag.php b/src/Domains/Social/Tags/Models/Tag.php index 842b46a76..e4647dd9a 100644 --- a/src/Domains/Social/Tags/Models/Tag.php +++ b/src/Domains/Social/Tags/Models/Tag.php @@ -52,7 +52,7 @@ public function getTable() public function searchableAs(): string { - $tag = ! $this->searchableDeleteRecord() ? $this : $this->find($this->id); + $tag = ! $this->searchableDeleteRecord() ? $this : $this->withTrashed()->find($this->id); $customIndex = isset($tag->app) ? $tag->app->get('app_custom_tag_index') : null; From a84fe7e3b7406e128d4dc2719ea6e789352e1aff Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 14:29:07 -0400 Subject: [PATCH 094/108] refact: index --- .../Products/Actions/CreateProductAction.php | 3 ++ .../Products/Jobs/IndexProductJob.php | 44 +++++++++++++++++++ .../Inventory/Products/Models/Products.php | 15 ++----- 3 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 src/Domains/Inventory/Products/Jobs/IndexProductJob.php diff --git a/src/Domains/Inventory/Products/Actions/CreateProductAction.php b/src/Domains/Inventory/Products/Actions/CreateProductAction.php index 2a647bb43..9588c8dfe 100644 --- a/src/Domains/Inventory/Products/Actions/CreateProductAction.php +++ b/src/Domains/Inventory/Products/Actions/CreateProductAction.php @@ -14,6 +14,7 @@ use Kanvas\Inventory\Attributes\Models\Attributes; use Kanvas\Inventory\Categories\Repositories\CategoriesRepository; use Kanvas\Inventory\Products\DataTransferObject\Product as ProductDto; +use Kanvas\Inventory\Products\Jobs\IndexProductJob; use Kanvas\Inventory\Products\Models\Products; use Kanvas\Inventory\Variants\Services\VariantService; use Throwable; @@ -111,6 +112,8 @@ public function execute(): Products } DB::connection('inventory')->commit(); + + IndexProductJob::dispatch($products)->delay(now()->addSeconds(2)); } catch (Throwable $e) { DB::connection('inventory')->rollback(); diff --git a/src/Domains/Inventory/Products/Jobs/IndexProductJob.php b/src/Domains/Inventory/Products/Jobs/IndexProductJob.php new file mode 100644 index 000000000..6105555bf --- /dev/null +++ b/src/Domains/Inventory/Products/Jobs/IndexProductJob.php @@ -0,0 +1,44 @@ +product = $product; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + // Ensure all relationships are loaded before indexing + $this->product->load(['files', 'categories', 'attributes', 'variants']); + + // Re-index product in Algolia + $this->product->searchable(); + } +} diff --git a/src/Domains/Inventory/Products/Models/Products.php b/src/Domains/Inventory/Products/Models/Products.php index c9f36f603..e76fb6a7e 100644 --- a/src/Domains/Inventory/Products/Models/Products.php +++ b/src/Domains/Inventory/Products/Models/Products.php @@ -164,17 +164,6 @@ public function shouldBeSearchable(): bool public function toSearchableArray(): array { - $this->refresh(); - $this->load([ - 'company', // Load the company relationship - 'company.user', // Load the user through the company - 'categories', // Load categories - 'variants', // Load variants - 'status', // Load status - 'files', // Load files (if it's a relationship) - 'attributes', // Load attributes - ]); - $product = [ 'objectID' => $this->uuid, 'id' => $this->id, @@ -250,6 +239,10 @@ public static function search($query = '', $callback = null) public function isPublished(): bool { + if (isset($this->app) && $this->app->get('allow_unpublished_products')) { + return ! $this->is_deleted; + } + return ! $this->is_deleted && $this->is_published; } From a710246e55639a897651c19f30e8bf1d6d2e1c8b Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 14:32:39 -0400 Subject: [PATCH 095/108] refact: index --- src/Domains/Inventory/Products/Jobs/IndexProductJob.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Domains/Inventory/Products/Jobs/IndexProductJob.php b/src/Domains/Inventory/Products/Jobs/IndexProductJob.php index 6105555bf..b5ef43c3d 100644 --- a/src/Domains/Inventory/Products/Jobs/IndexProductJob.php +++ b/src/Domains/Inventory/Products/Jobs/IndexProductJob.php @@ -18,14 +18,12 @@ class IndexProductJob implements ShouldQueue use Queueable; use SerializesModels; - protected Products $product; - /** * Create a new job instance. */ - public function __construct(Products $product) - { - $this->product = $product; + public function __construct( + protected Products $product + ) { } /** From 18dc73959ea4436847dab535a2964994de160c7c Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 15:28:08 -0400 Subject: [PATCH 096/108] refact: rename event --- .../ActionEngine/Tasks/Events/TaskEngagementItemEvent.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php b/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php index 8699b7c41..c18955842 100644 --- a/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php +++ b/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php @@ -33,4 +33,9 @@ public function broadcastOn(): Channel { return new Channel('lead-tasks-' . $this->taskEngagementItem->leadId); } + + public function broadcastAs(): string +{ + return 'lead.tasks'; +} } From af02ffbd844699185e40a4a9b92b2000887729dd Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 15:28:58 -0400 Subject: [PATCH 097/108] refact: rename event --- .../ActionEngine/Tasks/Events/TaskEngagementItemEvent.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php b/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php index c18955842..c5fa76272 100644 --- a/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php +++ b/src/Domains/ActionEngine/Tasks/Events/TaskEngagementItemEvent.php @@ -35,7 +35,7 @@ public function broadcastOn(): Channel } public function broadcastAs(): string -{ - return 'lead.tasks'; -} + { + return 'lead.tasks'; + } } From 9381b2a15a5ccfff9f662c3d67b28b3e3596b007 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Sep 2024 22:09:38 +0000 Subject: [PATCH 098/108] build(deps-dev): bump phpunit/phpunit from 11.3.2 to 11.3.3 Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 11.3.2 to 11.3.3. - [Release notes](https://github.com/sebastianbergmann/phpunit/releases) - [Changelog](https://github.com/sebastianbergmann/phpunit/blob/11.3.3/ChangeLog-11.3.md) - [Commits](https://github.com/sebastianbergmann/phpunit/compare/11.3.2...11.3.3) --- updated-dependencies: - dependency-name: phpunit/phpunit dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index cc350b682..ce1e28c8b 100644 --- a/composer.lock +++ b/composer.lock @@ -14516,16 +14516,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.3.2", + "version": "11.3.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "8a4de85cc4a78c59dd31cc4ef454b0029f8440dc" + "reference": "8ed08766d9a2ed979a2f5fdbb95a0671523419c1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/8a4de85cc4a78c59dd31cc4ef454b0029f8440dc", - "reference": "8a4de85cc4a78c59dd31cc4ef454b0029f8440dc", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/8ed08766d9a2ed979a2f5fdbb95a0671523419c1", + "reference": "8ed08766d9a2ed979a2f5fdbb95a0671523419c1", "shasum": "" }, "require": { @@ -14596,7 +14596,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.3.2" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.3.3" }, "funding": [ { @@ -14612,7 +14612,7 @@ "type": "tidelift" } ], - "time": "2024-09-03T12:00:26+00:00" + "time": "2024-09-04T13:34:52+00:00" }, { "name": "sebastian/cli-parser", From 38eb671aaf37bdb9ca9053bfe6b699d0b0168ea0 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 20:42:04 -0400 Subject: [PATCH 099/108] feat: optimize graph customfield cache --- src/Baka/Traits/HasLightHouseCache.php | 23 +++++++++++++++++++ .../CustomFields/Traits/HasCustomFields.php | 6 +++++ .../Actions/AttachFilesystemAction.php | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/src/Baka/Traits/HasLightHouseCache.php b/src/Baka/Traits/HasLightHouseCache.php index 1cbf05ea6..0b95b8e04 100644 --- a/src/Baka/Traits/HasLightHouseCache.php +++ b/src/Baka/Traits/HasLightHouseCache.php @@ -26,5 +26,28 @@ public function clearLightHouseCache(): void foreach ($keys as $key) { $redis->del(str_replace(config('database.redis.options.prefix'), '', $key)); } + + $this->generateCustomFieldsLighthouseCache(); + $this->generateFilesLighthouseCache(); + } + + public function generateRelationshipLighthouseCache(string $relationship, int $items = 25): void + { + $graphTypeName = $this->getGraphTypeName(); + $separator = CacheKeyAndTagsGenerator::SEPARATOR; + $key = CacheKeyAndTagsGenerator::PREFIX . $separator . $graphTypeName . $separator . $this->getId() . ':' . $relationship . ':first:' . $items; + $redis = Redis::connection('graph-cache'); + $result = $this->customFields()->paginate($items); + $redis->set($key, $result); + } + + public function generateCustomFieldsLighthouseCache(int $items = 25): void + { + $this->generateRelationshipLighthouseCache('custom_fields', $items); + } + + public function generateFilesLighthouseCache(int $items = 25): void + { + $this->generateRelationshipLighthouseCache('files', $items); } } diff --git a/src/Kanvas/CustomFields/Traits/HasCustomFields.php b/src/Kanvas/CustomFields/Traits/HasCustomFields.php index 1fb2f7213..947e1f797 100644 --- a/src/Kanvas/CustomFields/Traits/HasCustomFields.php +++ b/src/Kanvas/CustomFields/Traits/HasCustomFields.php @@ -193,6 +193,7 @@ public function set(string $name, mixed $value): AppsCustomFields if (method_exists($this, 'fireWorkflow')) { $this->fireWorkflow(WorkflowEnum::CREATE_CUSTOM_FIELD->value); } + return $customField; } @@ -282,6 +283,11 @@ public function saveCustomFields(): bool if (method_exists($this, 'fireWorkflow')) { $this->fireWorkflow(WorkflowEnum::CREATE_CUSTOM_FIELDS->value); } + + if (method_exists($this, 'generateCustomFieldsLighthouseCache')) { + $this->generateCustomFieldsLighthouseCache(); + } + return true; } diff --git a/src/Kanvas/Filesystem/Actions/AttachFilesystemAction.php b/src/Kanvas/Filesystem/Actions/AttachFilesystemAction.php index b2940ca46..2c500758a 100644 --- a/src/Kanvas/Filesystem/Actions/AttachFilesystemAction.php +++ b/src/Kanvas/Filesystem/Actions/AttachFilesystemAction.php @@ -60,6 +60,10 @@ public function execute(string $fieldName, ?int $id = null): FilesystemEntities $this->entity->clearLightHouseCache(); } + if (method_exists($this->entity, 'generateFilesLighthouseCache')) { + $this->entity->generateFilesLighthouseCache(); + } + return $fileEntity; } } From acdad4128facee506889adf11d9890769780d811 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 22:46:52 -0400 Subject: [PATCH 100/108] feat: add cli method --- .../KanvasLighthouseRedisCacheCommand.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php diff --git a/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php b/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php new file mode 100644 index 000000000..44697179d --- /dev/null +++ b/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php @@ -0,0 +1,65 @@ +argument('class'); + $appId = $this->argument('app_id'); + + $app = Apps::getById($appId); + $this->overwriteAppService($app); + + if (! class_exists($class)) { + $this->error('Class does not exist ' . $class); + + return; + } + + $entities = new $class(); + + //check if class has a trait + if (! method_exists($entities, 'clearLightHouseCache')) { + $this->error('Class does not have the trait HasLightHouseCache ' . $class); + + return; + } + + $entities->fromApp($app) + ->orderBy('id', 'asc') + ->chunk(100, function ($entitiesChunk, $class) { + foreach ($entitiesChunk as $entity) { + $this->info('Generating cache for ' . $class . ' ' . $entity->getId()); + + $entity->clearLightHouseCache(); + } + }); + } +} From cdedca5c2b01bd434136019cabc72a872f9af898 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 4 Sep 2024 23:21:44 -0400 Subject: [PATCH 101/108] feat: add test --- .../Unit/LightHouseCacheGenerationTest.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/Baka/Unit/LightHouseCacheGenerationTest.php diff --git a/tests/Baka/Unit/LightHouseCacheGenerationTest.php b/tests/Baka/Unit/LightHouseCacheGenerationTest.php new file mode 100644 index 000000000..9fea1991c --- /dev/null +++ b/tests/Baka/Unit/LightHouseCacheGenerationTest.php @@ -0,0 +1,48 @@ +user(); + + // Create a model instance for testing + $peopleData = [ + 'apps_id' => $app->getId(), + 'users_id' => $user->getId(), + 'firstname' => fake()->firstName, + 'middlename' => fake()->lastName, + 'lastname' => fake()->lastName, + 'name' => fake()->name, + 'dob' => fake()->date(), + 'companies_id' => $user->getCurrentCompany()->getId(), + ]; + + $people = People::create($peopleData); + $people->setCustomFields(['custom_field' => 'value']); + $people->saveCustomFields(); + + $redis = Redis::connection('graph-cache'); + $graphTypeName = $people->getGraphTypeName(); + $relationship = 'custom_fields'; + $items = 25; + + $separator = CacheKeyAndTagsGenerator::SEPARATOR; + $key = CacheKeyAndTagsGenerator::PREFIX . $separator . $graphTypeName . $separator . $people->getId() . ':' . $relationship . ':first:' . $items; + $this->assertInstanceOf(LengthAwarePaginator::class, $redis->get($key)); + } +} From bfb53d93f24f751024b1e21b5884ae5df5535c70 Mon Sep 17 00:00:00 2001 From: kaioken Date: Thu, 5 Sep 2024 13:56:07 -0400 Subject: [PATCH 102/108] refact: key genration --- .../KanvasLighthouseRedisCacheCommand.php | 12 ++++++-- .../Queries/Filesystem/FilesystemQuery.php | 2 +- src/Baka/Traits/HasLightHouseCache.php | 30 ++++++++++++++----- .../CustomFields/Traits/HasCustomFields.php | 8 +++++ .../Filesystem/Traits/HasFilesystemTrait.php | 30 +++++++++++++++++++ 5 files changed, 71 insertions(+), 11 deletions(-) diff --git a/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php b/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php index 44697179d..5734f5600 100644 --- a/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php +++ b/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php @@ -53,12 +53,18 @@ public function handle() } $entities->fromApp($app) - ->orderBy('id', 'asc') - ->chunk(100, function ($entitiesChunk, $class) { + ->notDeleted() + ->orderBy('created_at', 'DESC') + ->chunk(100, function ($entitiesChunk) use ($class) { foreach ($entitiesChunk as $entity) { - $this->info('Generating cache for ' . $class . ' ' . $entity->getId()); + $start = microtime(true); $entity->clearLightHouseCache(); + + $end = microtime(true); + $executionTime = round($end - $start, 4); + + $this->info("Generating cache for {$class} {$entity->getId()} - Execution time: {$executionTime} seconds"); } }); } diff --git a/app/GraphQL/Ecosystem/Queries/Filesystem/FilesystemQuery.php b/app/GraphQL/Ecosystem/Queries/Filesystem/FilesystemQuery.php index c8005e11b..902517780 100644 --- a/app/GraphQL/Ecosystem/Queries/Filesystem/FilesystemQuery.php +++ b/app/GraphQL/Ecosystem/Queries/Filesystem/FilesystemQuery.php @@ -28,7 +28,7 @@ public function getFileByGraphType( $app = $systemModule->app; /** - * @var Builder + * @todo use directly from the entity via fileQueryBuilder */ $files = Filesystem::select( 'filesystem_entities.uuid', diff --git a/src/Baka/Traits/HasLightHouseCache.php b/src/Baka/Traits/HasLightHouseCache.php index 0b95b8e04..cf1a0f9df 100644 --- a/src/Baka/Traits/HasLightHouseCache.php +++ b/src/Baka/Traits/HasLightHouseCache.php @@ -13,13 +13,13 @@ abstract public function getGraphTypeName(): string; public function clearLightHouseCache(): void { - $graphTypeName = $this->getGraphTypeName(); - - $separator = CacheKeyAndTagsGenerator::SEPARATOR; - $key = CacheKeyAndTagsGenerator::PREFIX . $separator . $graphTypeName . $separator . $this->getId() . '*'; + $key = $this->generateLighthouseCacheKey() . '*'; $redis = Redis::connection('graph-cache'); $keys = $redis->keys($key); if (empty($keys)) { + $this->generateCustomFieldsLighthouseCache(); + $this->generateFilesLighthouseCache(); + return; } @@ -33,11 +33,10 @@ public function clearLightHouseCache(): void public function generateRelationshipLighthouseCache(string $relationship, int $items = 25): void { - $graphTypeName = $this->getGraphTypeName(); $separator = CacheKeyAndTagsGenerator::SEPARATOR; - $key = CacheKeyAndTagsGenerator::PREFIX . $separator . $graphTypeName . $separator . $this->getId() . ':' . $relationship . ':first:' . $items; + $key = $this->generateLighthouseCacheKey() . $separator . $relationship . $separator . 'first' . $separator . $items; $redis = Redis::connection('graph-cache'); - $result = $this->customFields()->paginate($items); + $result = $this->getRelationshipQueryBuilder($relationship)->paginate($items); $redis->set($key, $result); } @@ -50,4 +49,21 @@ public function generateFilesLighthouseCache(int $items = 25): void { $this->generateRelationshipLighthouseCache('files', $items); } + + protected function generateLighthouseCacheKey(): string + { + $graphTypeName = $this->getGraphTypeName(); + $separator = CacheKeyAndTagsGenerator::SEPARATOR; + + return CacheKeyAndTagsGenerator::PREFIX . $separator . $graphTypeName . $separator . $this->getId(); + } + + protected function getRelationshipQueryBuilder(string $relationship) + { + return match ($relationship) { + 'custom_fields' => $this->getCustomFieldsQueryBuilder(), + 'files' => $this->getFilesQueryBuilder(), + default => $this->$relationship(), + }; + } } diff --git a/src/Kanvas/CustomFields/Traits/HasCustomFields.php b/src/Kanvas/CustomFields/Traits/HasCustomFields.php index 947e1f797..0a70716c8 100644 --- a/src/Kanvas/CustomFields/Traits/HasCustomFields.php +++ b/src/Kanvas/CustomFields/Traits/HasCustomFields.php @@ -7,6 +7,7 @@ use Baka\Enums\StateEnums; use Baka\Support\Str; use Baka\Traits\HasSchemaAccessors; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Facades\Auth; @@ -86,6 +87,13 @@ public function getAll(): array return $listOfCustomFields; } + public function getCustomFieldsQueryBuilder(): Builder + { + return AppsCustomFields::where('entity_id', '=', $this->getKey()) + ->where('model_name', '=', static::class) + ->where('is_deleted', '=', StateEnums::NO->getValue()); + } + /** * Get all the custom fields from redis. */ diff --git a/src/Kanvas/Filesystem/Traits/HasFilesystemTrait.php b/src/Kanvas/Filesystem/Traits/HasFilesystemTrait.php index 0bf30db51..e7744977f 100644 --- a/src/Kanvas/Filesystem/Traits/HasFilesystemTrait.php +++ b/src/Kanvas/Filesystem/Traits/HasFilesystemTrait.php @@ -5,11 +5,13 @@ namespace Kanvas\Filesystem\Traits; use Baka\Enums\StateEnums; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Kanvas\Apps\Models\Apps; use Kanvas\Companies\Models\Companies; use Kanvas\Enums\AppEnums; +use Kanvas\Enums\AppSettingsEnums; use Kanvas\Exceptions\ValidationException; use Kanvas\Filesystem\Actions\AttachFilesystemAction; use Kanvas\Filesystem\Models\Filesystem; @@ -185,4 +187,32 @@ protected function cleanExtension(string $extension): string return $validExtension; } + + public function getFilesQueryBuilder(): Builder + { + $app = $this->app ?? app(Apps::class); + $systemModule = SystemModulesRepository::getByModelName(static::class, $app); + + $files = Filesystem::select( + 'filesystem_entities.uuid', + 'filesystem_entities.field_name', + 'filesystem.name', + 'filesystem.url', + 'filesystem.size', + 'filesystem.file_type', + 'filesystem.file_type as type', + 'filesystem_entities.id', + ) + ->join('filesystem_entities', 'filesystem_entities.filesystem_id', '=', 'filesystem.id') + ->where('filesystem_entities.entity_id', '=', $this->getKey()) + ->where('filesystem_entities.system_modules_id', '=', $systemModule->getKey()) + ->where('filesystem_entities.is_deleted', '=', StateEnums::NO->getValue()) + ->where('filesystem.is_deleted', '=', StateEnums::NO->getValue()); + + $files->when(isset($this->companies_id) && ! $app->get(AppSettingsEnums::GLOBAL_APP_IMAGES->getValue()), function ($query) { + $query->where('filesystem_entities.companies_id', $this->companies_id); + }); + + return $files; + } } From 8fcafe4361b8177ed00436e729309bcb8f37b0e0 Mon Sep 17 00:00:00 2001 From: kaioken Date: Thu, 5 Sep 2024 13:58:08 -0400 Subject: [PATCH 103/108] refact: key genration --- app/GraphQL/Ecosystem/Queries/CustomFields/CustomFieldQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/GraphQL/Ecosystem/Queries/CustomFields/CustomFieldQuery.php b/app/GraphQL/Ecosystem/Queries/CustomFields/CustomFieldQuery.php index c9b00367b..cfc6a083c 100644 --- a/app/GraphQL/Ecosystem/Queries/CustomFields/CustomFieldQuery.php +++ b/app/GraphQL/Ecosystem/Queries/CustomFields/CustomFieldQuery.php @@ -24,7 +24,7 @@ public function getAllByGraphType( ResolveInfo $resolveInfo ): Builder { /** - * @var Builder + * @todo move to use the entity queryBuilder */ $customFields = AppsCustomFields::where('entity_id', '=', $root->getKey()) ->where('model_name', '=', $root::class) From 0b8be09c529e259dcb057662f50b2ac248621e28 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:29:12 +0000 Subject: [PATCH 104/108] build(deps): bump twilio/sdk from 8.2.3 to 8.3.0 Bumps [twilio/sdk](https://github.com/twilio/twilio-php) from 8.2.3 to 8.3.0. - [Release notes](https://github.com/twilio/twilio-php/releases) - [Changelog](https://github.com/twilio/twilio-php/blob/main/CHANGES.md) - [Commits](https://github.com/twilio/twilio-php/compare/8.2.3...8.3.0) --- updated-dependencies: - dependency-name: twilio/sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index ce1e28c8b..82fbb2a5d 100644 --- a/composer.lock +++ b/composer.lock @@ -12984,16 +12984,16 @@ }, { "name": "twilio/sdk", - "version": "8.2.3", + "version": "8.3.0", "source": { "type": "git", "url": "https://github.com/twilio/twilio-php.git", - "reference": "9b0297df39cadcae857387e86d0e062887d59c15" + "reference": "da842421814abaacb1c57eaacd7e8de19bbdbee6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twilio/twilio-php/zipball/9b0297df39cadcae857387e86d0e062887d59c15", - "reference": "9b0297df39cadcae857387e86d0e062887d59c15", + "url": "https://api.github.com/repos/twilio/twilio-php/zipball/da842421814abaacb1c57eaacd7e8de19bbdbee6", + "reference": "da842421814abaacb1c57eaacd7e8de19bbdbee6", "shasum": "" }, "require": { @@ -13031,9 +13031,9 @@ ], "support": { "issues": "https://github.com/twilio/twilio-php/issues", - "source": "https://github.com/twilio/twilio-php/tree/8.2.3" + "source": "https://github.com/twilio/twilio-php/tree/8.3.0" }, - "time": "2024-08-26T11:24:31+00:00" + "time": "2024-09-05T13:01:28+00:00" }, { "name": "vladimir-yuldashev/laravel-queue-rabbitmq", From 3a446218eb0bac967aedec64c6d4d4d96261580d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:29:18 +0000 Subject: [PATCH 105/108] build(deps-dev): bump phpstan/phpstan from 1.12.1 to 1.12.2 Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.12.1 to 1.12.2. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/2.0.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.12.1...1.12.2) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index ce1e28c8b..edec88f02 100644 --- a/composer.lock +++ b/composer.lock @@ -14135,16 +14135,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.1", + "version": "1.12.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" + "reference": "0ca1c7bb55fca8fe6448f16fff0f311ccec960a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0ca1c7bb55fca8fe6448f16fff0f311ccec960a1", + "reference": "0ca1c7bb55fca8fe6448f16fff0f311ccec960a1", "shasum": "" }, "require": { @@ -14189,7 +14189,7 @@ "type": "github" } ], - "time": "2024-09-03T19:55:22+00:00" + "time": "2024-09-05T16:09:28+00:00" }, { "name": "phpunit/php-code-coverage", From a641bfde5841d1158d15fc0bc9e5e3a5e5b62e16 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:29:23 +0000 Subject: [PATCH 106/108] build(deps): bump mll-lab/graphql-php-scalars from 6.2.0 to 6.3.0 Bumps [mll-lab/graphql-php-scalars](https://github.com/mll-lab/graphql-php-scalars) from 6.2.0 to 6.3.0. - [Release notes](https://github.com/mll-lab/graphql-php-scalars/releases) - [Changelog](https://github.com/mll-lab/graphql-php-scalars/blob/master/CHANGELOG.md) - [Commits](https://github.com/mll-lab/graphql-php-scalars/compare/v6.2.0...v6.3.0) --- updated-dependencies: - dependency-name: mll-lab/graphql-php-scalars dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index ce1e28c8b..36d735a4c 100644 --- a/composer.lock +++ b/composer.lock @@ -5565,16 +5565,16 @@ }, { "name": "mll-lab/graphql-php-scalars", - "version": "v6.2.0", + "version": "v6.3.0", "source": { "type": "git", "url": "https://github.com/mll-lab/graphql-php-scalars.git", - "reference": "f0922636f090bc1e56f6a9efb3ebb8272aa5cff3" + "reference": "c2a38af86a68b550a0dc15d1363f22997146b17e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mll-lab/graphql-php-scalars/zipball/f0922636f090bc1e56f6a9efb3ebb8272aa5cff3", - "reference": "f0922636f090bc1e56f6a9efb3ebb8272aa5cff3", + "url": "https://api.github.com/repos/mll-lab/graphql-php-scalars/zipball/c2a38af86a68b550a0dc15d1363f22997146b17e", + "reference": "c2a38af86a68b550a0dc15d1363f22997146b17e", "shasum": "" }, "require": { @@ -5620,9 +5620,9 @@ ], "support": { "issues": "https://github.com/mll-lab/graphql-php-scalars/issues", - "source": "https://github.com/mll-lab/graphql-php-scalars/tree/v6.2.0" + "source": "https://github.com/mll-lab/graphql-php-scalars/tree/v6.3.0" }, - "time": "2023-05-09T13:20:50+00:00" + "time": "2024-09-05T11:04:51+00:00" }, { "name": "mll-lab/laravel-graphiql", From 6a7ad96ffaea7155bae33d5f973a1cdc0b3a090e Mon Sep 17 00:00:00 2001 From: kaioken Date: Thu, 5 Sep 2024 21:26:13 -0400 Subject: [PATCH 107/108] Feat: allow company id --- .../Commands/Support/KanvasLighthouseRedisCacheCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php b/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php index 5734f5600..1703c1c4a 100644 --- a/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php +++ b/app/Console/Commands/Support/KanvasLighthouseRedisCacheCommand.php @@ -17,7 +17,7 @@ class KanvasLighthouseRedisCacheCommand extends Command * * @var string */ - protected $signature = 'kanvas:lighthouse-redis-cache {class} {app_id}'; + protected $signature = 'kanvas:lighthouse-redis-cache {class} {app_id} {company_id?}'; /** * The console command description. @@ -33,6 +33,7 @@ public function handle() { $class = $this->argument('class'); $appId = $this->argument('app_id'); + $companyId = $this->argument('company_id'); $app = Apps::getById($appId); $this->overwriteAppService($app); @@ -54,6 +55,9 @@ public function handle() $entities->fromApp($app) ->notDeleted() + ->when($companyId, function ($query, $companyId) { + return $query->where('companies_id', $companyId); + }) ->orderBy('created_at', 'DESC') ->chunk(100, function ($entitiesChunk) use ($class) { foreach ($entitiesChunk as $entity) { From 162903a303992772f20b4db077da13b25b10b0a3 Mon Sep 17 00:00:00 2001 From: kaioken Date: Thu, 5 Sep 2024 23:31:37 -0400 Subject: [PATCH 108/108] refact: clear cache to use queue --- .../Apollo/SyncAllPeopleInCompanyCommand.php | 2 +- src/Baka/Jobs/LightHouseCacheCleanUpJob.php | 32 +++++++++++++++++++ src/Baka/Traits/HasLightHouseCache.php | 6 ++++ .../Customers/Actions/UpdatePeopleAction.php | 2 +- .../Customers/Observers/PeopleObserver.php | 4 +-- .../Guild/Leads/Observers/LeadObserver.php | 4 +-- .../Products/Observers/ProductsObserver.php | 4 +-- .../Variants/Observers/VariantObserver.php | 2 +- .../Messages/Observers/MessageObserver.php | 4 +-- .../CustomFields/Traits/HasCustomFields.php | 4 +-- .../Actions/AttachFilesystemAction.php | 6 +--- 11 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 src/Baka/Jobs/LightHouseCacheCleanUpJob.php diff --git a/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php index a06d1f733..b0e35f8a1 100644 --- a/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php +++ b/app/Console/Commands/Connectors/Apollo/SyncAllPeopleInCompanyCommand.php @@ -124,7 +124,7 @@ public function handle() 'app' => $people->app, ] ); - $people->clearLightHouseCache(); + $people->clearLightHouseCacheJob(); $currentHourlyCount++; $currentDailyCount++; diff --git a/src/Baka/Jobs/LightHouseCacheCleanUpJob.php b/src/Baka/Jobs/LightHouseCacheCleanUpJob.php new file mode 100644 index 000000000..08d371b2e --- /dev/null +++ b/src/Baka/Jobs/LightHouseCacheCleanUpJob.php @@ -0,0 +1,32 @@ +model, 'clearLightHouseCache')) { + $this->model->clearLightHouseCache(); + } + } +} diff --git a/src/Baka/Traits/HasLightHouseCache.php b/src/Baka/Traits/HasLightHouseCache.php index cf1a0f9df..c02ab3ae1 100644 --- a/src/Baka/Traits/HasLightHouseCache.php +++ b/src/Baka/Traits/HasLightHouseCache.php @@ -4,6 +4,7 @@ namespace Baka\Traits; +use Baka\Jobs\LightHouseCacheCleanUpJob; use Illuminate\Support\Facades\Redis; use Nuwave\Lighthouse\Cache\CacheKeyAndTagsGenerator; @@ -31,6 +32,11 @@ public function clearLightHouseCache(): void $this->generateFilesLighthouseCache(); } + public function clearLightHouseCacheJob(): void + { + LightHouseCacheCleanUpJob::dispatch($this); + } + public function generateRelationshipLighthouseCache(string $relationship, int $items = 25): void { $separator = CacheKeyAndTagsGenerator::SEPARATOR; diff --git a/src/Domains/Guild/Customers/Actions/UpdatePeopleAction.php b/src/Domains/Guild/Customers/Actions/UpdatePeopleAction.php index fec2a4ca6..d70ecb274 100644 --- a/src/Domains/Guild/Customers/Actions/UpdatePeopleAction.php +++ b/src/Domains/Guild/Customers/Actions/UpdatePeopleAction.php @@ -94,7 +94,7 @@ public function execute(): People } } - $this->people->clearLightHouseCache(); + $this->people->clearLightHouseCacheJob(); return $this->people; } } diff --git a/src/Domains/Guild/Customers/Observers/PeopleObserver.php b/src/Domains/Guild/Customers/Observers/PeopleObserver.php index d10fbf19d..52e05a3c0 100644 --- a/src/Domains/Guild/Customers/Observers/PeopleObserver.php +++ b/src/Domains/Guild/Customers/Observers/PeopleObserver.php @@ -19,7 +19,7 @@ public function created(People $people): void ] ); - $people->clearLightHouseCache(); + $people->clearLightHouseCacheJob(); } public function updated(People $people): void @@ -32,6 +32,6 @@ public function updated(People $people): void ] ); - $people->clearLightHouseCache(); + $people->clearLightHouseCacheJob(); } } diff --git a/src/Domains/Guild/Leads/Observers/LeadObserver.php b/src/Domains/Guild/Leads/Observers/LeadObserver.php index 43b3a65ce..c52f206dc 100644 --- a/src/Domains/Guild/Leads/Observers/LeadObserver.php +++ b/src/Domains/Guild/Leads/Observers/LeadObserver.php @@ -85,13 +85,13 @@ public function created(Lead $lead): void )->execute(); } - $lead->clearLightHouseCache(); + $lead->clearLightHouseCacheJob(); } public function updated(Lead $lead): void { $lead->fireWorkflow(WorkflowEnum::UPDATED->value); Subscription::broadcast('leadUpdate', $lead, true); - $lead->clearLightHouseCache(); + $lead->clearLightHouseCacheJob(); } } diff --git a/src/Domains/Inventory/Products/Observers/ProductsObserver.php b/src/Domains/Inventory/Products/Observers/ProductsObserver.php index 718f79128..fcbf78da8 100644 --- a/src/Domains/Inventory/Products/Observers/ProductsObserver.php +++ b/src/Domains/Inventory/Products/Observers/ProductsObserver.php @@ -14,7 +14,7 @@ public function saved(Products $products): void $products->productsTypes->setTotalProducts(); } - $products->clearLightHouseCache(); + $products->clearLightHouseCacheJob(); } public function created(Products $products): void @@ -23,6 +23,6 @@ public function created(Products $products): void $products->productsTypes->setTotalProducts(); } - $products->clearLightHouseCache(); + $products->clearLightHouseCacheJob(); } } diff --git a/src/Domains/Inventory/Variants/Observers/VariantObserver.php b/src/Domains/Inventory/Variants/Observers/VariantObserver.php index 7beef38dc..89c9aa2ca 100644 --- a/src/Domains/Inventory/Variants/Observers/VariantObserver.php +++ b/src/Domains/Inventory/Variants/Observers/VariantObserver.php @@ -11,7 +11,7 @@ class VariantObserver { public function saved(Variants $variant): void { - $variant->clearLightHouseCache(); + $variant->clearLightHouseCacheJob(); } public function deleting(Variants $variant): void diff --git a/src/Domains/Social/Messages/Observers/MessageObserver.php b/src/Domains/Social/Messages/Observers/MessageObserver.php index 38c564e83..9eaf409fa 100644 --- a/src/Domains/Social/Messages/Observers/MessageObserver.php +++ b/src/Domains/Social/Messages/Observers/MessageObserver.php @@ -12,12 +12,12 @@ class MessageObserver public function created(Message $message): void { $message->fireWorkflow(WorkflowEnum::CREATED->value, true, ['app' => $message->app]); - $message->clearLightHouseCache(); + $message->clearLightHouseCacheJob(); } public function updated(Message $message): void { $message->fireWorkflow(WorkflowEnum::UPDATED->value, true, ['app' => $message->app]); - $message->clearLightHouseCache(); + $message->clearLightHouseCacheJob(); } } diff --git a/src/Kanvas/CustomFields/Traits/HasCustomFields.php b/src/Kanvas/CustomFields/Traits/HasCustomFields.php index 0a70716c8..be2b3e9e7 100644 --- a/src/Kanvas/CustomFields/Traits/HasCustomFields.php +++ b/src/Kanvas/CustomFields/Traits/HasCustomFields.php @@ -293,7 +293,7 @@ public function saveCustomFields(): bool } if (method_exists($this, 'generateCustomFieldsLighthouseCache')) { - $this->generateCustomFieldsLighthouseCache(); + $this->clearLightHouseCacheJob(); } return true; @@ -394,7 +394,7 @@ public static function getByCustomField(string $name, mixed $value, ?Companies $ protected function clearCustomFieldsCacheIfNeeded(): void { if (method_exists($this, 'clearLightHouseCache')) { - $this->clearLightHouseCache(); + $this->clearLightHouseCacheJob(); } } } diff --git a/src/Kanvas/Filesystem/Actions/AttachFilesystemAction.php b/src/Kanvas/Filesystem/Actions/AttachFilesystemAction.php index 2c500758a..0e65baf83 100644 --- a/src/Kanvas/Filesystem/Actions/AttachFilesystemAction.php +++ b/src/Kanvas/Filesystem/Actions/AttachFilesystemAction.php @@ -57,11 +57,7 @@ public function execute(string $fieldName, ?int $id = null): FilesystemEntities } if (method_exists($this->entity, 'clearLightHouseCache')) { - $this->entity->clearLightHouseCache(); - } - - if (method_exists($this->entity, 'generateFilesLighthouseCache')) { - $this->entity->generateFilesLighthouseCache(); + $this->entity->clearLightHouseCacheJob(); } return $fileEntity;