Cronjobs implemented
This commit is contained in:
@@ -158,6 +158,9 @@ class ProductionDataSeeder {
|
||||
|
||||
private function installCronTasks() {
|
||||
CronTask::create(['name' => 'UploadInvoices', 'execution_type' => CronTaskType::CRON_TASK_TYPE_REALTIME]);
|
||||
CronTask::create(['name' => 'CloseCostUnit', 'execution_type' => CronTaskType::CRON_TASK_TYPE_DAILY, 'schedule_time' => '00:05']);
|
||||
CronTask::create(['name' => 'CloseEvent', 'execution_type' => CronTaskType::CRON_TASK_TYPE_DAILY, 'schedule_time' => '00:10']);
|
||||
CronTask::create(['name' => 'NotifyTeam', 'execution_type' => CronTaskType::CRON_TASK_TYPE_DAILY, 'schedule_time' => '20:00']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
73
app/Mail/EventReportMails/InformLocalGroupMail.php
Normal file
73
app/Mail/EventReportMails/InformLocalGroupMail.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail\EventReportMails;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventParticipant;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Attachment;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
|
||||
class InformLocalGroupMail extends Mailable
|
||||
{
|
||||
public function __construct(
|
||||
private Event $event,
|
||||
private Collection $participants,
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
$subject = sprintf(
|
||||
'Teilnehmendenübersicht %1$s %2$s',
|
||||
'für die Veranstaltung',
|
||||
$this->event->name
|
||||
);
|
||||
|
||||
|
||||
return new Envelope(
|
||||
subject: $subject,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
$event = $this->event->toResource()->toArray(new Request());
|
||||
$participants = [];
|
||||
foreach ($this->participants as $participant) {
|
||||
$_t = $participant->toResource()->toArray(new Request());
|
||||
$participants[$_t['participationType']][] = $_t;
|
||||
}
|
||||
|
||||
return new Content(
|
||||
view: 'emails.events.participant_report_localgroups',
|
||||
with: [
|
||||
'participantGroups' => $participants,
|
||||
'eventTitle' => $event['name'],
|
||||
'eventEmail' => $event['email'],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,8 @@ class CronTask extends CommonModel
|
||||
protected $table = 'cron_tasks';
|
||||
protected $fillable = ['name', 'execution_type', 'schedule_time', 'last_run'];
|
||||
protected $dates = ['last_run'];
|
||||
|
||||
protected $casts = [
|
||||
'last_run' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -17,11 +17,25 @@ class EventRepository {
|
||||
|
||||
}
|
||||
|
||||
public function getAvailable(bool $accessCheck = true) : array {
|
||||
public function getUpcomming() : array {
|
||||
return $this->getEventsByCriteria([
|
||||
'archived' => false,
|
||||
'registration_allowed' => true
|
||||
],$accessCheck);
|
||||
'upcomming' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function getAvailable(bool $accessCheck = true) : array {
|
||||
$events = [];
|
||||
foreach ( $this->getEventsByCriteria([
|
||||
'archived' => false,
|
||||
|
||||
],$accessCheck) as $event) {
|
||||
if ($event->start_date > now()) {
|
||||
$events[] = $event;
|
||||
}
|
||||
};
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
public function getForRegistration(int $id) : ?Event {
|
||||
|
||||
21
app/Tasks/CloseCostUnit.php
Normal file
21
app/Tasks/CloseCostUnit.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tasks;
|
||||
|
||||
use App\Models\CostUnit;
|
||||
use App\Repositories\CostUnitRepository;
|
||||
|
||||
class CloseCostUnit implements CronTask {
|
||||
public function handle(): void
|
||||
{
|
||||
$now = now();
|
||||
$costUnitRepository = new CostUnitRepository();
|
||||
/** @var CostUnit $costUnit */
|
||||
foreach ($costUnitRepository->getCurrentEvents() as $costUnit) {
|
||||
if (\DateTime::createFromFormat('Y-m-d', $costUnit->billing_deadline) < $now ) {
|
||||
$costUnit->allow_new = false;
|
||||
$costUnit->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
app/Tasks/CloseEvent.php
Normal file
21
app/Tasks/CloseEvent.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tasks;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Repositories\EventRepository;
|
||||
|
||||
class CloseEvent implements CronTask {
|
||||
public function handle(): void
|
||||
{
|
||||
$now = now();
|
||||
$eventRepository = new EventRepository();
|
||||
/** @var Event $event */
|
||||
foreach ($eventRepository->getAvailable(false) as $event) {
|
||||
if ($event->registration_final_end < $now ) {
|
||||
$event->registration_allowed = false;
|
||||
$event->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
app/Tasks/NotifyTeam.php
Normal file
41
app/Tasks/NotifyTeam.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tasks;
|
||||
|
||||
use App\Domains\Invoice\Actions\UploadInvoice\UploadInvoiceCommand;
|
||||
use App\Domains\Invoice\Actions\UploadInvoice\UploadInvoiceRequest;
|
||||
use App\Mail\EventReportMails\InformLocalGroupMail;
|
||||
use App\Mail\ParticipantParticipationMails\ParticipantSignOffMail;
|
||||
use App\Models\Event;
|
||||
use App\Models\Tenant;
|
||||
use App\Repositories\EventRepository;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class NotifyTeam implements CronTask {
|
||||
public function handle(): void
|
||||
{
|
||||
if (date('w') !== 0) {
|
||||
// return;
|
||||
}
|
||||
|
||||
$eventRepository = new EventRepository();
|
||||
/** @var Event $event */
|
||||
foreach ($eventRepository->getAvailable(false) as $event) {
|
||||
foreach (Tenant::all() as $tenant) {
|
||||
$participants = $event->participants()->where('local_group', $tenant->slug)->whereNull('unregistered_at')->get();
|
||||
}
|
||||
|
||||
if ($participants->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Mail::to($tenant->email)->send(new InformLocalGroupMail(
|
||||
event: $event,
|
||||
participants: $participants,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user