no message

This commit is contained in:
StudioTem committed 2025-03-24 10:48:38 +01:00
1 parent 58addf77f0
commit b9bfaaa8ce
6 files changed
+319 -203

No files matched your search

+10 -92
View File
@@ -2,9 +2,6 @@
namespace App\Console\Commands;
use App\Models\Blocker;
use App\Models\Project;
use App\Models\SubTask;
use App\Services\Office365\Office365Service;
use Illuminate\Console\Command;
@@ -32,9 +29,6 @@ class SyncOffice365 extends Command
public function handle()
{
$events = Office365Service::getCalendarEvents();
// TODO: asi prerobit na CreateAndUpdate
// determine if event is blocker or subtask. if the first word in event name is project code, then it is subtask. otherwise it is blocker
// but first, remove "Canceled: " from the event name in case of canceled event
@@ -46,93 +40,17 @@ class SyncOffice365 extends Command
return $event;
}, $events);
$blockers_from_office365 = array_filter($events, function ($event) {
$projectCode = explode(' ', $event['subject'])[0];
$blockers_from_office365 = Office365Service::getBlockers_from_office_365_events($events);
$subtasks_from_office365 = Office365Service::getSubtasks_from_office_365_events($events);
// if project code doesnt exist in database, then it is blocker
return ! Project::where('code', $projectCode)->exists();
});
Office365Service::addBlockers($blockers_from_office365);
Office365Service::editBlockers($blockers_from_office365);
Office365Service::removeBlockers($blockers_from_office365);
$subtasks_from_office365 = array_filter($events, function ($event) {
$projectCode = explode(' ', $event['subject'])[0];
// if project code exist in database, then it is subtask
return Project::where('code', $projectCode)->exists();
});
// get only new events - the ones that doesnt have any office365_id in blockers table and only events that doesnt have isCancelled => true
$newBlockers = array_filter($blockers_from_office365, function ($event) {
return ! Blocker::where('office365_id', $event['id'])->exists() && ! $event['isCancelled'];
});
$newSubtasks = array_filter($subtasks_from_office365, function ($event) {
return ! SubTask::where('office365_id', $event['id'])->exists() && ! $event['isCancelled'];
});
Office365Service::addBlockers($newBlockers);
Office365Service::addSubtasks($newSubtasks);
// get edited blockers - the ones, that has different changeKey from our database
$editedBlockers = array_filter($blockers_from_office365, function ($event) {
$blocker = Blocker::where('office365_id', $event['id'])->first();
return $blocker && $blocker->office365_change_key !== $event['changeKey'];
});
// get edited subtasks - the ones, that has different changeKey from our database
$editedSubtasks = array_filter($subtasks_from_office365, function ($event) {
$subtask = SubTask::where('office365_id', $event['id'])->first();
return $subtask && $subtask->office365_change_key !== $event['changeKey'];
});
Office365Service::editBlockers($editedBlockers);
Office365Service::editSubtasks($editedSubtasks);
// get all canceled blockers - the ones, that are in our database and in the response they have isCancelled => true
$removedBlockers = Blocker::whereNotNull('office365_id')->get()->filter(function ($blocker) use (
$blockers_from_office365
) {
$event = collect($blockers_from_office365)->firstWhere('id', $blocker->office365_id);
return $event && $event['isCancelled'];
});
// TODO dat do service
$removedBlockers->each(function ($blocker) {
$blocker->delete();
});
// get all canceled subtasks - the ones, that are in our database and in the response they have isCancelled => true
$removedSubtasks = SubTask::where('is_finished', 0)->whereNotNull('office365_id')->get()->filter(function (
$subtask
) use (
$subtasks_from_office365
) {
$event = collect($subtasks_from_office365)->firstWhere('id', $subtask->office365_id);
return $event && $event['isCancelled'];
});
//dd($removedSubtasks);
foreach ($removedSubtasks as $subtaskToDelete) {
// vymazanie timeblockov
foreach ($subtaskToDelete->timeblocks as $timeblock) {
$timeblock->delete();
}
// vymazanie timesheetov
foreach ($subtaskToDelete->timesheets as $timesheet) {
$timesheet->delete();
}
$subtaskToDelete->delete();
}
dd('he');
Office365Service::addSubtasks($subtasks_from_office365);
Office365Service::editSubtasks($subtasks_from_office365);
Office365Service::removeSubtasks($subtasks_from_office365);
return Command::SUCCESS;
}
}