Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.2] Version 1.2 #1875

Merged
merged 167 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
3147504
feat: add defaults field dashboard
FredPeal Aug 23, 2024
3850c4a
Apply fixes from StyleCI
StyleCIBot Aug 23, 2024
5db0423
Merge pull request #1851 from bakaphp/analysis-223pa9
FredPeal Aug 23, 2024
8a51b78
refactor: dashboard
FredPeal Aug 23, 2024
82e74a4
Merge branch 'dashboard' of github.com:bakaphp/kanvas-ecosystem-api i…
FredPeal Aug 23, 2024
600ac49
refactor: set by cli
FredPeal Aug 23, 2024
634b443
Apply fixes from StyleCI
StyleCIBot Aug 23, 2024
a8ee322
Merge pull request #1853 from bakaphp/analysis-jlr4g2
FredPeal Aug 23, 2024
288ca68
Merge branch 'development' of github.com:bakaphp/kanvas-ecosystem-api…
FredPeal Aug 26, 2024
720d2a8
refactor: move to dashboard
FredPeal Aug 26, 2024
d5d1257
refactor: add dashboard composer json
FredPeal Aug 26, 2024
0c7e4e0
Apply fixes from StyleCI
StyleCIBot Aug 26, 2024
b5df0e5
Merge pull request #1861 from bakaphp/analysis-ma2P1a
kaioken Aug 27, 2024
98649be
fix: Deletion restriction of linked elements
Keysie27 Aug 27, 2024
872efa8
Fix Prevent Duplicate Attribute Slug
Keysie27 Aug 20, 2024
6abfb67
Implement feedback: [Return current attributes in case of duplicate s…
Keysie27 Aug 20, 2024
492ad9f
Implement feedback: [Refactor attribute creation]
Keysie27 Aug 20, 2024
1501028
Implement feedback: [Refactor actions using SlugTrait]
Keysie27 Aug 22, 2024
294c10b
Implement feedback: [split SlugTrait methods]
Keysie27 Aug 23, 2024
da94598
Implement feedback: [Refactor actions using SlugTrait, 3 methods]
Keysie27 Aug 23, 2024
eb60e37
Change QueryBySlug name method
Keysie27 Aug 23, 2024
058f619
Refactor isLastVariant method
Keysie27 Aug 27, 2024
a3a6b8c
Refactor: adjust code formatting
Keysie27 Aug 27, 2024
644a83a
Refactor: adjust code formatting v2
Keysie27 Aug 27, 2024
22b2656
Merge pull request #1867 from bakaphp/fix/KTC-126
Keysie27 Aug 27, 2024
00ad5bd
Fix: Prevent Attribute Deletion if Linked to Products
Keysie27 Aug 27, 2024
3b608f9
Merge branch 'development' into KTC-122
Keysie27 Aug 27, 2024
b4fc57d
Refactor: Styles
Keysie27 Aug 27, 2024
d1ba5ce
build(deps-dev): bump phpstan/phpstan from 1.11.11 to 1.12.0
dependabot[bot] Aug 27, 2024
d8e0600
build(deps): bump meilisearch/meilisearch-php from 1.9.1 to 1.10.0
dependabot[bot] Aug 27, 2024
4abb66b
Merge pull request #1871 from bakaphp/dependabot/composer/meilisearch…
kaioken Aug 28, 2024
aad09f4
Merge pull request #1870 from bakaphp/dependabot/composer/phpstan/php…
kaioken Aug 28, 2024
08efdc8
refact: filter
kaioken Aug 28, 2024
a39ce18
Merge pull request #1872 from bakaphp/hotfix-social-engagement
kaioken Aug 28, 2024
2d07685
feat : filter by tags and type
kaioken Aug 28, 2024
d4697de
Merge pull request #1873 from bakaphp/hotfix-social-engagement
kaioken Aug 28, 2024
7e12975
Merge pull request #1850 from bakaphp/dashboard
FredPeal Aug 28, 2024
723bd6e
Refactor: Dependencies
Keysie27 Aug 28, 2024
ea0e7ef
Refactor: Cascade
Keysie27 Aug 28, 2024
2a372a1
Refactor: Styles
Keysie27 Aug 28, 2024
7e70c37
Fix: Prevent Attribute Delection if Linked to ProductTypes
Keysie27 Aug 28, 2024
2ceba15
Merge pull request #1869 from bakaphp/KTC-122
Keysie27 Aug 29, 2024
517f8aa
build(deps): bump stripe/stripe-php from 15.7.0 to 15.8.0
dependabot[bot] Aug 29, 2024
96f44cc
Merge pull request #1876 from bakaphp/dependabot/composer/stripe/stri…
kaioken Aug 30, 2024
703652d
refact: is admin
kaioken Aug 30, 2024
871daf5
Merge pull request #1879 from bakaphp/hotfix-is-admin
kaioken Aug 30, 2024
f460368
build(deps): bump symfony/expression-language from 7.1.1 to 7.1.4
dependabot[bot] Aug 30, 2024
ebb9075
build(deps): bump symfony/http-client from 7.1.3 to 7.1.4
dependabot[bot] Aug 30, 2024
d13b740
build(deps): bump spatie/laravel-data from 4.8.1 to 4.8.2
dependabot[bot] Aug 30, 2024
223ceaa
refactor: mutation update photo profile
FredPeal Aug 30, 2024
999cfe0
Apply fixes from StyleCI
StyleCIBot Aug 30, 2024
fe4ac0f
Merge pull request #1884 from bakaphp/analysis-kYA3J4
FredPeal Aug 30, 2024
dddc9f9
Merge pull request #1882 from bakaphp/dependabot/composer/spatie/lara…
kaioken Aug 30, 2024
0dea95c
Merge pull request #1881 from bakaphp/dependabot/composer/symfony/htt…
kaioken Aug 30, 2024
35188ac
Merge pull request #1880 from bakaphp/dependabot/composer/symfony/exp…
kaioken Aug 30, 2024
c8ea676
add explore feed email notification
rwhite27 Aug 30, 2024
8c38691
Merge pull request #1883 from bakaphp/upload-photo-company
kaioken Aug 30, 2024
640da73
Update company.graphql
kaioken Aug 31, 2024
b529c83
feat: simple command to send daily emails
kaioken Sep 2, 2024
7c40a18
feat: simple command to send daily emails
kaioken Sep 2, 2024
7628c09
feat: allow user to set message as private
kaioken Sep 2, 2024
8d42811
Refact: class
kaioken Sep 2, 2024
df071b1
Merge pull request #1888 from bakaphp/feat-set-private-message
kaioken Sep 2, 2024
6c713bc
hotfix: subcription with octane
kaioken Sep 2, 2024
7bd4a33
Merge pull request #1889 from bakaphp/hotfix-subcription-with-octane
kaioken Sep 2, 2024
6c3fd40
hotfix: subcription with octane
kaioken Sep 2, 2024
373cb70
Refact: add brodcast event
kaioken Sep 2, 2024
7e22cb7
rename command and removed Explore Feed notification
rwhite27 Sep 2, 2024
b76ffb1
refact: style
kaioken Sep 2, 2024
5b2b036
add subject as command argument
rwhite27 Sep 2, 2024
4feba61
add new name to command
rwhite27 Sep 2, 2024
72e43aa
refact: move subscription to lead
kaioken Sep 2, 2024
3d87700
build(deps): bump nuwave/lighthouse from 6.43.1 to 6.44.1
dependabot[bot] Sep 2, 2024
ebb27ca
Merge pull request #1891 from bakaphp/dependabot/composer/nuwave/ligh…
kaioken Sep 2, 2024
615ce41
Merge pull request #1890 from bakaphp/hotfix-subcription-with-octane
kaioken Sep 3, 2024
6f7f8ca
Merge branch 'development' into feat-engagement-daily-emails
kaioken Sep 3, 2024
f5792e0
Merge pull request #1885 from bakaphp/explore-feed-mail
kaioken Sep 3, 2024
3604ad4
Merge branch 'development' into feat-engagement-daily-emails
kaioken Sep 3, 2024
91f3b62
refact: email notification
kaioken Sep 3, 2024
90cc51e
refact : commands
kaioken Sep 3, 2024
1f9028f
refact: commands
kaioken Sep 3, 2024
27e8a6d
refact: commands
kaioken Sep 3, 2024
8795e37
fix: format
kaioken Sep 3, 2024
9778cef
Merge pull request #1887 from bakaphp/feat-engagement-daily-emails
kaioken Sep 3, 2024
14bc2ca
hotfix: delete searchable records
kaioken Sep 3, 2024
ee80305
hotfix: delete searchable records
kaioken Sep 3, 2024
6f1b8df
hotfix: delete searchable records
kaioken Sep 3, 2024
c031049
Merge pull request #1892 from bakaphp/hotfix-delete-searchable-records
kaioken Sep 3, 2024
ba2efcd
feat: message index filter
kaioken Sep 3, 2024
af36ac1
feat: message index filter
kaioken Sep 3, 2024
24f0738
feat: message index filter
kaioken Sep 3, 2024
354078e
Merge pull request #1893 from bakaphp/feat-message-index-filter
kaioken Sep 3, 2024
b72ecc1
feat: message index filter
kaioken Sep 3, 2024
ea7fc80
Merge pull request #1894 from bakaphp/feat-message-index-filter
kaioken Sep 3, 2024
ac9ff4e
feat: message index filter
kaioken Sep 3, 2024
d7f83a6
Merge pull request #1895 from bakaphp/feat-message-index-filter
kaioken Sep 3, 2024
1544fd3
update from development
rwhite27 Sep 3, 2024
d35c0cf
fix format
rwhite27 Sep 3, 2024
c513ece
Merge pull request #1897 from bakaphp/explore-feed-mail
rwhite27 Sep 3, 2024
af66578
feat: apollo app sync
kaioken Sep 3, 2024
1edc5d3
refact: attribute types
kaioken Sep 3, 2024
d34a112
Merge pull request #1899 from bakaphp/refact-attribute-type-filter
kaioken Sep 3, 2024
1a45852
refact: attribute types
kaioken Sep 3, 2024
3fe4ab8
refact: sync individual
kaioken Sep 3, 2024
072e7fc
refact: sync individual
kaioken Sep 3, 2024
b783f8b
test mail using an example user
rwhite27 Sep 3, 2024
8962d5a
fix format
rwhite27 Sep 3, 2024
7a29ec7
fix format
rwhite27 Sep 3, 2024
9f8e6aa
Merge branch 'development' of github.com:bakaphp/kanvas-ecosystem-api…
rwhite27 Sep 3, 2024
3b221cf
Merge pull request #1900 from bakaphp/explore-feed-mail
rwhite27 Sep 3, 2024
369210a
add watch arg to octane start to watch for changes in files
rwhite27 Sep 3, 2024
c4cdf45
Merge pull request #1901 from bakaphp/explore-feed-mail
rwhite27 Sep 3, 2024
7ed8c42
rollback changes
rwhite27 Sep 3, 2024
0115a65
Merge pull request #1902 from bakaphp/explore-feed-mail
rwhite27 Sep 3, 2024
f67880c
remove testing code
rwhite27 Sep 3, 2024
bba9507
Merge pull request #1903 from bakaphp/explore-feed-mail
rwhite27 Sep 3, 2024
afba301
build(deps): bump swoole/ide-helper from 5.1.3 to 5.1.4
dependabot[bot] Sep 3, 2024
e0157c3
build(deps-dev): bump phpunit/phpunit from 11.3.1 to 11.3.2
dependabot[bot] Sep 3, 2024
0fc048b
build(deps): bump laravel/socialite from 5.15.1 to 5.16.0
dependabot[bot] Sep 3, 2024
2805ba8
build(deps): bump laravel/scout from 10.11.1 to 10.11.2
dependabot[bot] Sep 3, 2024
a948e09
build(deps): bump laravel/framework from 11.21.0 to 11.22.0
dependabot[bot] Sep 3, 2024
da78952
Merge pull request #1908 from bakaphp/dependabot/composer/laravel/fra…
kaioken Sep 3, 2024
5bee5b9
Merge pull request #1907 from bakaphp/dependabot/composer/laravel/sco…
kaioken Sep 3, 2024
fbeb8e6
Merge pull request #1906 from bakaphp/dependabot/composer/laravel/soc…
kaioken Sep 3, 2024
ee846a6
Merge pull request #1905 from bakaphp/dependabot/composer/phpunit/php…
kaioken Sep 3, 2024
531b741
Merge pull request #1904 from bakaphp/dependabot/composer/swoole/ide-…
kaioken Sep 3, 2024
067dcf0
Merge pull request #1898 from bakaphp/feat-apollo-app-sync
kaioken Sep 4, 2024
6628c2f
feat: add task brocast events
kaioken Sep 4, 2024
d3968fa
Merge branch 'development' into feat-lead-stask-broadcast
kaioken Sep 4, 2024
ea03963
refact: apollo daily 2k sync limit
kaioken Sep 4, 2024
712b587
refact: task items channel brodcast
kaioken Sep 4, 2024
c437314
refact: code style
kaioken Sep 4, 2024
1903788
feat: add integartion test
kaioken Sep 4, 2024
30c9b70
feat: add integartion test
kaioken Sep 4, 2024
82228f8
Merge pull request #1910 from bakaphp/feat-lead-stask-broadcast
kaioken Sep 4, 2024
97ca26d
refact: delete algolia
kaioken Sep 4, 2024
ca5bd58
refact: delete algolia
kaioken Sep 4, 2024
d0b933c
hotfix: app
kaioken Sep 4, 2024
1c13492
hotfix: app
kaioken Sep 4, 2024
bbd5269
Merge pull request #1911 from bakaphp/hotfix-softdelete-algolia
kaioken Sep 4, 2024
ace18f5
refact: figure out the usage of withTrashed
kaioken Sep 4, 2024
618c755
Merge pull request #1912 from bakaphp/hotfix-softdelete-algolia
kaioken Sep 4, 2024
a84fe7e
refact: index
kaioken Sep 4, 2024
a710246
refact: index
kaioken Sep 4, 2024
22dd7d1
Merge pull request #1914 from bakaphp/hotfix-softdelete-algolia
kaioken Sep 4, 2024
18dc739
refact: rename event
kaioken Sep 4, 2024
af02ffb
refact: rename event
kaioken Sep 4, 2024
0f35f49
Merge pull request #1915 from bakaphp/hotfix-softdelete-algolia
kaioken Sep 4, 2024
9381b2a
build(deps-dev): bump phpunit/phpunit from 11.3.2 to 11.3.3
dependabot[bot] Sep 4, 2024
9d84743
Merge pull request #1916 from bakaphp/dependabot/composer/phpunit/php…
kaioken Sep 4, 2024
38eb671
feat: optimize graph customfield cache
kaioken Sep 5, 2024
acdad41
feat: add cli method
kaioken Sep 5, 2024
cdedca5
feat: add test
kaioken Sep 5, 2024
c605d2d
Merge pull request #1917 from bakaphp/feat-optimize-graph-customfield…
kaioken Sep 5, 2024
bfb53d9
refact: key genration
kaioken Sep 5, 2024
8fcafe4
refact: key genration
kaioken Sep 5, 2024
b3c99ad
Merge pull request #1918 from bakaphp/feat-optimize-graph-customfield…
kaioken Sep 5, 2024
0b8be09
build(deps): bump twilio/sdk from 8.2.3 to 8.3.0
dependabot[bot] Sep 5, 2024
3a44621
build(deps-dev): bump phpstan/phpstan from 1.12.1 to 1.12.2
dependabot[bot] Sep 5, 2024
a641bfd
build(deps): bump mll-lab/graphql-php-scalars from 6.2.0 to 6.3.0
dependabot[bot] Sep 5, 2024
6a7ad96
Feat: allow company id
kaioken Sep 6, 2024
e51af22
Merge pull request #1922 from bakaphp/feat-optimize-graph-customfield…
kaioken Sep 6, 2024
162903a
refact: clear cache to use queue
kaioken Sep 6, 2024
6f46432
Merge pull request #1919 from bakaphp/dependabot/composer/twilio/sdk-…
kaioken Sep 6, 2024
371bb29
Merge pull request #1920 from bakaphp/dependabot/composer/phpstan/php…
kaioken Sep 6, 2024
2044b62
Merge pull request #1921 from bakaphp/dependabot/composer/mll-lab/gra…
kaioken Sep 6, 2024
833f641
Merge pull request #1923 from bakaphp/feat-optimize-graph-customfield…
kaioken Sep 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions app/Console/Commands/AccessControl/UpdateAbilitiesCommand.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands\AccessControl;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
use Kanvas\AccessControlList\Actions\CreateAbilitiesByModule;
use Kanvas\Apps\Models\Apps;
use Kanvas\AccessControlList\Enums\ModuleEnum;
use Kanvas\AccessControlList\Repositories\RolesRepository;

class UpdateAbilitiesCommand extends Command
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

declare(strict_types=1);

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;
use Kanvas\Companies\Models\Companies;
use Kanvas\Connectors\Apollo\Enums\ConfigurationEnum;
use Kanvas\CustomFields\Models\AppsCustomFields;
use Kanvas\Guild\Customers\Models\People;
use Kanvas\Workflow\Enums\WorkflowEnum;

class SyncAllPeopleInCompanyCommand extends Command
{
use KanvasJobsTrait;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kanvas:guild-apollo-people-sync {app_id} {company_id} {total=400} {perPage=200}';

/**
* The console command description.
*
* @var string|null
*/
protected $description = 'Download all leads from Zoho to this branch';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$app = Apps::getById((int) $this->argument('app_id'));
$perPage = (int) $this->argument('perPage');
$total = (int) $this->argument('total');
$this->overwriteAppService($app);
$company = Companies::getById((int) $this->argument('company_id'));

$hourlyRateLimit = 400; // Maximum API calls per hour
$dailyRateLimit = 2000; // Maximum API calls per day
$batchSize = 100; // Number of people to process per batch
$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
$currentHourlyCount = Cache::get($hourlyCacheKey, 0);
$currentDailyCount = Cache::get($dailyCacheKey, 0);
$resetHourlyTimestamp = Cache::get($resetHourlyKey);
$resetDailyTimestamp = Cache::get($resetDailyKey);

$this->line('Syncing ' . $currentHourlyCount . ' people in company ' . $company->name . ' from app ' . $app->name . ' total ' . $total . ' per page ' . $perPage);

if ($resetHourlyTimestamp) {
$resetHourlyTime = Carbon::parse($resetHourlyTimestamp);
$currentTimestamp = now()->timestamp;
$hourlyWaitTime = $resetHourlyTime->timestamp - $currentTimestamp;

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;
}
}

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')
->orderBy('peoples.id', 'asc')
->chunk($batchSize, function ($peoples) use (&$currentHourlyCount, &$currentDailyCount, $hourlyRateLimit, $dailyRateLimit, $hourlyCacheKey, $dailyCacheKey, $resetHourlyKey, $resetDailyKey, $hourlyTimeWindow, $dailyTimeWindow) {
foreach ($peoples as $people) {
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;
}

$this->line('Syncing people ' . $people->id . ' ' . $people->firstname . ' ' . $people->lastname);

$people->fireWorkflow(
WorkflowEnum::UPDATED->value,
true,
[
'app' => $people->app,
]
);
$people->clearLightHouseCacheJob();

$currentHourlyCount++;
$currentDailyCount++;
Cache::put($hourlyCacheKey, $currentHourlyCount, $hourlyTimeWindow);
Cache::put($dailyCacheKey, $currentDailyCount, $dailyTimeWindow);

usleep(100000); // 100ms delay between each request
}
});

$this->line('All people in company ' . $company->name . ' from app ' . $app->name . ' synced');

return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Console\Commands;
namespace App\Console\Commands\Ecosystem\Companies;

use Illuminate\Console\Command;
use Kanvas\Companies\Actions\DeleteCompaniesAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Console\Commands;
namespace App\Console\Commands\Ecosystem;

use Illuminate\Console\Command;
use Kanvas\Apps\Actions\CreateAppKeyAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Console\Commands;
namespace App\Console\Commands\Ecosystem;

use Baka\Users\Contracts\UserInterface;
use Illuminate\Console\Command;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands\Ecosystem\Notifications;

use Baka\Enums\StateEnums;
use Baka\Traits\KanvasJobsTrait;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Notification;
use Kanvas\Apps\Models\Apps;
use Kanvas\Enums\AppEnums;
use Kanvas\Notifications\Templates\Blank;
use Kanvas\Users\Models\UsersAssociatedApps;
use Kanvas\Users\Models\Users;

class MailAllAppUsersCommand extends Command
{
use KanvasJobsTrait;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kanvas:mail-notification-to-all-app-users {apps_id} {email_template_name} {subject}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'send specific email to all users of an app';

/**
* Execute the console command.
*/
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();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands\Ecosystem\Notifications;

use Baka\Enums\StateEnums;
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;
use Kanvas\Notifications\Templates\Blank;
use Kanvas\Users\Models\UsersAssociatedApps;

class UserEngagementReminderCommand extends Command
{
use KanvasJobsTrait;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kanvas:users-engagement-reminder {app_id?} ';

/**
* The console command description.
*
* @var string|null
*/
protected $description = 'Simple daily email reminder to get users to engage with the app again';

public function handle(): void
{
$app = Apps::getById($this->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
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) {
$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];

if (! isset($emailTemplate['template'])) {
$this->info('No email template found for ' . $lastVisitInDays . ' days');

return;
}

$notification = new Blank(
$emailTemplate['template'],
[
'app' => $app,
'user' => $user->user,
'config' => $emailTemplate,
],
['mail'],
$user
);

Notification::route('mail', $user->email)->notify($notification);
//@todo save it in user activity log on social?
$this->info('Email sent to ' . $user->email);
}
}
Loading
Loading