-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1397 from bakaphp/cronjob-caddielab
Cronjob caddielab
- Loading branch information
Showing
9 changed files
with
154 additions
and
30 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/Console/Commands/Connectors/Notifications/MailCaddieLabCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\Connectors\Notifications; | ||
|
||
use Illuminate\Console\Command; | ||
use Kanvas\Apps\Repositories\AppsRepository; | ||
use Kanvas\Connectors\Notifications\Jobs\MailCaddieLabJob; | ||
|
||
class MailCaddieLabCommand extends Command | ||
{ | ||
protected $signature = 'kanvas:internal-mail-caddie-lab {apps_id}'; | ||
|
||
public function handle() | ||
{ | ||
$this->info('Sending internal mail to Caddie Lab'); | ||
MailCaddieLabJob::dispatch(AppsRepository::findFirstByKey($this->argument('apps_id'))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
database/migrations/Guild/2024_05_28_030618_apps_id_people.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('peoples', function (Blueprint $table) { | ||
// | ||
$table->bigInteger('apps_id')->unsigned()->nullable()->after('companies_id'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('peoples', function (Blueprint $table) { | ||
// | ||
$table->dropColumn('apps_id'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/Domains/Connectors/Notifications/Jobs/MailCaddieLabJob.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanvas\Connectors\Notifications\Jobs; | ||
|
||
use Baka\Traits\KanvasJobsTrait; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\Notification; | ||
use Kanvas\Apps\Models\Apps; | ||
use Kanvas\Guild\Customers\Repositories\PeoplesRepository; | ||
use Kanvas\Notifications\Templates\Blank; | ||
|
||
class MailCaddieLabJob implements ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use SerializesModels; | ||
use KanvasJobsTrait; | ||
use Queueable; | ||
|
||
public function __construct( | ||
public Apps $app | ||
) { | ||
} | ||
|
||
public function handle() | ||
{ | ||
$peoples = PeoplesRepository::getByDaysCreated(7, $this->app); | ||
$this->sendMails($peoples, 'join-caddie'); | ||
|
||
$peoples = PeoplesRepository::getByDaysCreated(28, $this->app); | ||
$this->sendMails($peoples, 'join-caddie'); | ||
} | ||
|
||
public function sendMails(Collection $peoples, string $template) | ||
{ | ||
foreach ($peoples as $people) { | ||
$email = $people->emails()->first(); | ||
$url = $this->app->get('billing_url') . '/' . '?email=' . $email->value . '&paid=false'; | ||
$notification = new Blank( | ||
$template, | ||
['membershipUpgradeUrl' => $url, 'app' => $this->app], | ||
['mail'], | ||
$people | ||
); | ||
$notification->setSubject('Join to Caddie Lab'); | ||
echo ' Sending email to ' . $email->value . "\n"; | ||
if (! $people->get('paid_subscription')) { | ||
Notification::route('mail', $email->value)->notify($notification); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters