Skip to content

Commit d8df5e9

Browse files
authored
Merge pull request #6683 from bakaphp/release/1.64.0
Release 1.66.0
2 parents 881795c + e754f8a commit d8df5e9

File tree

107 files changed

+6425
-453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+6425
-453
lines changed

.github/workflows/ec2-deploy.yaml

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
environment: ${{ github.ref_name }}
3434
steps:
3535
- name: executing remote ssh commands using password
36-
uses: appleboy/[email protected].2
36+
uses: appleboy/[email protected].3
3737
with:
3838
host: ${{ secrets.AWS_EC2_HOST }}
3939
username: ${{ secrets.AWS_EC2_USERNAME }}
@@ -59,28 +59,18 @@ jobs:
5959
docker restart laravel-scheduler
6060
docker restart queue-sync-shopify-queue
6161
docker restart queue-sync-shopify-queue-worker-1
62-
docker stop queue-sync-shopify-queue-worker-2
62+
docker restart batch-logger-queue
63+
docker restart queue-user-interactions
6364
docker restart queue-scout-worker-1
64-
docker stop queue-scout-worker-2
6565
docker restart queue-workflow-1
66+
docker stop queue-sync-shopify-queue-worker-2
6667
docker stop queue-workflow-2
6768
docker stop queue-workflow-3
68-
docker restart batch-logger-queue
69-
docker restart queue-user-interactions
70-
docker stop queue-scrapper-worker-1
71-
docker stop queue-scrapper-worker-2
72-
docker stop queue-scrapper-worker-3
73-
docker stop queue-scrapper-worker-4
74-
docker stop queue-scout-worker-3
69+
docker stop queue-scrapper-worker-{1..4}
70+
docker stop queue-scout-worker-{2..3}
7571
if [ "docker-compose.${{ github.ref_name }}.yml" == "docker-compose.1.x.yml" ]; then
7672
docker stop queue-imports2
77-
docker stop queue2
78-
docker stop queue3
79-
docker stop queue4
80-
docker stop queue5
81-
docker stop queue6
82-
docker stop queue7
83-
docker stop queue8
73+
docker stop queue{2..8}
8474
docker stop queue-workflow-4
8575
fi
8676

.github/workflows/ecs-deploy.yaml

Lines changed: 0 additions & 62 deletions
This file was deleted.

.github/workflows/queues-ec2-deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
environment: ${{ github.ref_name }}
3232
steps:
3333
- name: executing remote ssh commands using password
34-
uses: appleboy/[email protected].2
34+
uses: appleboy/[email protected].3
3535
with:
3636
host: ${{ secrets.AWS_QUEUE_EC2_HOST }}
3737
username: ${{ secrets.AWS_EC2_USERNAME }}

.github/workflows/test-ec2-deploy.yaml renamed to .github/workflows/secondary-ec2-deploy.yaml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy to Test EC2
1+
name: Deploy to Secondary EC2
22

33
on:
44
push:
@@ -7,7 +7,7 @@ on:
77
workflow_dispatch: {}
88

99
jobs:
10-
deploy-to-test-ec2:
10+
deploy-to-ec2:
1111
runs-on: ubuntu-latest
1212
environment: ${{ github.ref_name }}
1313
permissions:
@@ -27,11 +27,11 @@ jobs:
2727

2828
docker-command:
2929
runs-on: ubuntu-latest
30-
needs: deploy-to-test-ec2
30+
needs: deploy-to-ec2
3131
environment: ${{ github.ref_name }}
3232
steps:
3333
- name: executing remote ssh commands using password
34-
uses: appleboy/[email protected].2
34+
uses: appleboy/[email protected].3
3535
with:
3636
host: ${{ secrets.AWS_TEST_EC2_HOST }}
3737
username: ${{ secrets.AWS_TEST_EC2_USERNAME }}
@@ -46,36 +46,25 @@ jobs:
4646
docker exec -i phpkanvas-ecosystem php artisan lighthouse:clear-cache all
4747
docker exec -i phpkanvas-ecosystem php artisan config:cache
4848
docker restart queue-scrapper
49-
docker stop queue-scrapper-worker-1
50-
docker stop queue-scrapper-worker-2
51-
docker stop queue-scrapper-worker-3
52-
docker stop queue-scrapper-worker-4
49+
docker stop queue-scrapper-worker-{1..4}
5350
docker restart queue
5451
docker restart queue-imports
5552
docker stop queue-notifications
5653
docker stop queue-social
5754
docker restart laravel-scheduler
5855
docker stop queue-sync-shopify-queue
59-
docker stop queue-sync-shopify-queue-worker-1
60-
docker stop queue-sync-shopify-queue-worker-1
61-
docker stop queue-sync-shopify-queue-worker-2
56+
docker stop queue-sync-shopify-queue-worker-{1..2}
6257
docker restart queue-scout-worker-1
6358
docker stop queue-scout-worker-2
6459
docker stop queue-scout-worker-3
65-
docker restart queue-workflow-1
66-
docker restart queue-workflow-2
60+
docker restart queue-workflow-{1..2}
6761
docker stop queue-workflow-3
6862
docker stop batch-logger-queue
6963
docker stop queue-user-interactions
7064
if [ "docker-compose.${{ github.ref_name }}.yml" == "docker-compose.1.x.yml" ]; then
7165
docker stop queue-imports2
7266
docker restart queue2
73-
docker stop queue3
74-
docker stop queue4
75-
docker stop queue5
76-
docker stop queue6
77-
docker stop queue7
78-
docker stop queue8
67+
docker stop queue{3..8}
7968
docker stop queue-workflow-4
8069
fi
8170

app/Console/Commands/Ecosystem/Notifications/MailAllAppUsersCommand.php

Lines changed: 82 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
use Baka\Enums\StateEnums;
88
use Baka\Traits\KanvasJobsTrait;
9+
use Baka\Validations\Date;
910
use Exception;
1011
use Illuminate\Console\Command;
12+
use Illuminate\Contracts\Database\Query\Builder;
1113
use Illuminate\Support\Facades\DB;
1214
use Illuminate\Support\Facades\Notification;
1315
use Kanvas\Apps\Models\Apps;
@@ -32,66 +34,100 @@ class MailAllAppUsersCommand extends Command
3234
{subject : The subject of the email}
3335
{--test-email= : Email address to send a test email instead of sending to all users}
3436
{--production : Flag to confirm sending to all users in production}
35-
{--delay=500 : Delay in milliseconds between each email}';
37+
{--delay=500 : Delay in milliseconds between each email}
38+
{--created-after= : Filter users created after this date (Y-m-d H:i:s format)}
39+
{--created-before= : Filter users created before this date (Y-m-d H:i:s format)}';
3640

3741
/**
3842
* The console command description.
3943
*
4044
* @var string
4145
*/
42-
protected $description = 'Send specific email to all users of an app or to a test email address';
46+
protected $description = 'Send specific email to all users of an app or to a test email address with optional date filtering';
4347

4448
/**
4549
* Execute the console command.
4650
*/
47-
public function handle()
51+
public function handle(): void
4852
{
4953
$app = Apps::getById((int) $this->argument('apps_id'));
5054
$this->app = $app;
5155
$this->overwriteAppService($app);
52-
$emailTemplateName = $this->argument('email_template_name');
53-
$emailSubject = $this->argument('subject');
56+
$emailTemplateName = (string) $this->argument('email_template_name');
57+
$emailSubject = (string) $this->argument('subject');
5458
$testEmail = $this->option('test-email');
5559
$isProduction = $this->option('production');
5660
$delayMs = (int) $this->option('delay');
61+
$createdAfter = $this->option('created-after') ?? '';
62+
$createdBefore = $this->option('created-before') ?? '';
63+
64+
// Validate date format if provided
65+
if ($createdAfter !== '' && ! Date::isValid($createdAfter, 'Y-m-d H:i:s')) {
66+
$this->error('Invalid created-after date format. Use Y-m-d H:i:s format (e.g., 2024-01-01 00:00:00)');
67+
68+
return;
69+
}
70+
71+
if ($createdBefore !== '' && ! Date::isValid($createdBefore, 'Y-m-d H:i:s')) {
72+
$this->error('Invalid created-before date format. Use Y-m-d H:i:s format (e.g., 2024-12-31 23:59:59)');
73+
74+
return;
75+
}
5776

5877
// Check if we're just testing to a single email
59-
if ($testEmail) {
78+
if (is_string($testEmail) && ! empty($testEmail)) {
6079
try {
6180
$userModelEntity = Users::getByEmail($testEmail);
6281
$this->sendEmailToUser($userModelEntity, $emailTemplateName, $emailSubject);
6382
$this->info('Test email successfully sent to: ' . $userModelEntity->getId() . ' on app: ' . $app->getId());
6483
} catch (Exception $e) {
6584
$this->error('Failed to send test email: ' . $e->getMessage());
6685

67-
return 1;
86+
return;
6887
}
6988

70-
return 0;
89+
return;
7190
}
7291

7392
// Check if we're in production mode and have the production flag
7493
if (! app()->isProduction() || ! $isProduction) {
7594
$this->error('This command can only send emails to all users in production with the --production flag.');
7695
$this->info('Use [email protected] to send a test email instead.');
7796

78-
return 1;
97+
return;
7998
}
8099

100+
// Build the base query for counting and processing users
101+
$baseQuery = $this->buildUserQuery($app->getId(), $createdAfter, $createdBefore);
102+
81103
// Count total users to process for progress bar
82-
$totalUsers = DB::table('users_associated_apps')
83-
->where('apps_id', $app->id)
84-
->where('is_deleted', StateEnums::NO->getValue())
85-
->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue())
86-
->count();
104+
$totalUsers = $baseQuery->count();
87105

88106
if ($totalUsers === 0) {
89-
$this->warn('No users found for this app.');
107+
$this->warn('No users found for this app with the given criteria.');
108+
if ($createdAfter !== '' || $createdBefore !== '') {
109+
$this->info('Date filters applied:');
110+
if ($createdAfter !== '') {
111+
$this->info(' - Created after: ' . $createdAfter);
112+
}
113+
if ($createdBefore !== '') {
114+
$this->info(' - Created before: ' . $createdBefore);
115+
}
116+
}
90117

91-
return 0;
118+
return;
92119
}
93120

94121
$this->info("Found {$totalUsers} users to process.");
122+
if ($createdAfter !== '' || $createdBefore !== '') {
123+
$this->info('Date filters applied:');
124+
if ($createdAfter !== '') {
125+
$this->info(' - Created after: ' . $createdAfter);
126+
}
127+
if ($createdBefore !== '') {
128+
$this->info(' - Created before: ' . $createdBefore);
129+
}
130+
}
95131

96132
// Initialize counters
97133
$successCount = 0;
@@ -103,10 +139,7 @@ public function handle()
103139
$progressBar->start();
104140

105141
// Only runs if we're in production and have the production flag
106-
DB::table('users_associated_apps')
107-
->where('apps_id', $app->id)
108-
->where('is_deleted', StateEnums::NO->getValue())
109-
->where('companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue())
142+
$this->buildUserQuery($app->getId(), $createdAfter, $createdBefore)
110143
->orderBy('users_id')
111144
->chunk(100, function ($users) use (
112145
$app,
@@ -154,12 +187,10 @@ public function handle()
154187
if ($failCount > 0) {
155188
$this->error(" - Failed: {$failCount}");
156189

157-
return 1;
190+
return;
158191
}
159192

160193
$this->info('All emails have been sent successfully.');
161-
162-
return 0;
163194
}
164195

165196
/**
@@ -182,4 +213,32 @@ private function sendEmailToUser(Users $user, string $emailTemplateName, string
182213
$notification->setSubject($emailSubject);
183214
Notification::route('mail', $user->email)->notify($notification);
184215
}
216+
217+
/**
218+
* Build the user query with optional date filters
219+
*/
220+
private function buildUserQuery(
221+
int $appId,
222+
?string $createdAfter = null,
223+
?string $createdBefore = null
224+
): Builder {
225+
$query = DB::table('users_associated_apps')
226+
->join('users', 'users_associated_apps.users_id', '=', 'users.id')
227+
->selectRaw('users_associated_apps.*, users.email')
228+
->where('users_associated_apps.apps_id', $appId)
229+
->where('users_associated_apps.is_deleted', StateEnums::NO->getValue())
230+
->where('users_associated_apps.companies_id', AppEnums::GLOBAL_COMPANY_ID->getValue())
231+
->where('users.is_deleted', StateEnums::NO->getValue());
232+
233+
// Apply created_at filters if provided
234+
if ($createdAfter !== null && ! empty($createdAfter)) {
235+
$query->where('users.created_at', '>=', $createdAfter);
236+
}
237+
238+
if ($createdBefore !== null && ! empty($createdBefore)) {
239+
$query->where('users.created_at', '<=', $createdBefore);
240+
}
241+
242+
return $query;
243+
}
185244
}

0 commit comments

Comments
 (0)