Files
jandl-taskmanager-app/be/app/Console/Commands/FinishOffice365Subtasks.php
T
2025-03-17 09:54:13 +01:00

54 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\SubTask;
use App\Services\Office365\Office365Service;
use Illuminate\Console\Command;
class FinishOffice365Subtasks extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'office365:finish-subtasks';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Prida is_finished a timesheet subtaskom (eventom), ktore uz skoncili';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$events = Office365Service::getCalendarEvents();
// vrati vsetky office365 subtasky z nasej DB, ktore maju is_finished = 0 a porovna to s eventami z office365. ak je nejaky end time v office365 v minulosti, tak vrati tento subtask
$subtasksThatFinished = SubTask::where('is_finished', 0)->get()->filter(function ($subtask) use ($events) {
$event = collect($events)->firstWhere('id', $subtask->office365_id);
if ( ! $event) {
return false;
}
return strtotime($event['end']['dateTime']) < time();
});
// ak neexistuju ziadne subtasky, ktore uz skoncili
if ($subtasksThatFinished->isEmpty()) {
return Command::SUCCESS;
}
Office365Service::finishSubtasks($subtasksThatFinished);
return Command::SUCCESS;
}
}