|
|
|
@ -169,6 +169,8 @@ class ImportSchedule extends BaseController
|
|
|
|
|
public function loadSchedule(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$id = $request->getAttribute('id');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Event[] $newEvents
|
|
|
|
|
* @var Event[] $changeEvents
|
|
|
|
@ -188,7 +190,7 @@ class ImportSchedule extends BaseController
|
|
|
|
|
,
|
|
|
|
|
$scheduleUrl,
|
|
|
|
|
$schedule
|
|
|
|
|
) = $this->getScheduleData($request);
|
|
|
|
|
) = $this->getScheduleData($id);
|
|
|
|
|
} catch (ErrorException $e) {
|
|
|
|
|
$this->addNotification($e->getMessage(), 'errors');
|
|
|
|
|
return back();
|
|
|
|
@ -219,27 +221,41 @@ class ImportSchedule extends BaseController
|
|
|
|
|
public function importSchedule(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
/**
|
|
|
|
|
* @var Event[] $newEvents
|
|
|
|
|
* @var Event[] $changeEvents
|
|
|
|
|
* @var Event[] $deleteEvents
|
|
|
|
|
* @var Room[] $newRooms
|
|
|
|
|
* @var int $shiftType
|
|
|
|
|
* @var ScheduleUrl $scheduleUrl
|
|
|
|
|
*/
|
|
|
|
|
list(
|
|
|
|
|
$newEvents,
|
|
|
|
|
$changeEvents,
|
|
|
|
|
$deleteEvents,
|
|
|
|
|
$newRooms,
|
|
|
|
|
$shiftType,
|
|
|
|
|
$scheduleUrl
|
|
|
|
|
) = $this->getScheduleData($request);
|
|
|
|
|
$id = $request->getAttribute('id');
|
|
|
|
|
$this->doImport($id);
|
|
|
|
|
} catch (ErrorException $e) {
|
|
|
|
|
$this->addNotification($e->getMessage(), 'errors');
|
|
|
|
|
return back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return redirect($this->url, 303)
|
|
|
|
|
->with('messages', ['schedule.import.success']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $id
|
|
|
|
|
*
|
|
|
|
|
* @throws ErrorException
|
|
|
|
|
*/
|
|
|
|
|
public function doImport(string $id): void
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var Event[] $newEvents
|
|
|
|
|
* @var Event[] $changeEvents
|
|
|
|
|
* @var Event[] $deleteEvents
|
|
|
|
|
* @var Room[] $newRooms
|
|
|
|
|
* @var int $shiftType
|
|
|
|
|
* @var ScheduleUrl $scheduleUrl
|
|
|
|
|
*/
|
|
|
|
|
list(
|
|
|
|
|
$newEvents,
|
|
|
|
|
$changeEvents,
|
|
|
|
|
$deleteEvents,
|
|
|
|
|
$newRooms,
|
|
|
|
|
$shiftType,
|
|
|
|
|
$scheduleUrl
|
|
|
|
|
) = $this->getScheduleData($id);
|
|
|
|
|
|
|
|
|
|
$this->log('Started schedule "{name}" import', ['name' => $scheduleUrl->name]);
|
|
|
|
|
|
|
|
|
|
foreach ($newRooms as $room) {
|
|
|
|
@ -274,9 +290,6 @@ class ImportSchedule extends BaseController
|
|
|
|
|
|
|
|
|
|
$scheduleUrl->touch();
|
|
|
|
|
$this->log('Ended schedule "{name}" import', ['name' => $scheduleUrl->name]);
|
|
|
|
|
|
|
|
|
|
return redirect($this->url, 303)
|
|
|
|
|
->with('messages', ['schedule.import.success']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -311,7 +324,7 @@ class ImportSchedule extends BaseController
|
|
|
|
|
'end' => $shift->getEndDate()->unix(),
|
|
|
|
|
'RID' => $room->id,
|
|
|
|
|
'URL' => $shift->getUrl(),
|
|
|
|
|
'created_by_user_id' => $user->id,
|
|
|
|
|
'created_by_user_id' => $user ? $user->id : null,
|
|
|
|
|
'created_at_timestamp' => time(),
|
|
|
|
|
'edited_by_user_id' => null,
|
|
|
|
|
'edited_at_timestamp' => 0,
|
|
|
|
@ -357,7 +370,7 @@ class ImportSchedule extends BaseController
|
|
|
|
|
'end' => $shift->getEndDate()->unix(),
|
|
|
|
|
'RID' => $room->id,
|
|
|
|
|
'URL' => $shift->getUrl(),
|
|
|
|
|
'edited_by_user_id' => $user->id,
|
|
|
|
|
'edited_by_user_id' => $user ? $user->id : null,
|
|
|
|
|
'edited_at_timestamp' => time(),
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
@ -397,13 +410,12 @@ class ImportSchedule extends BaseController
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @param string $id
|
|
|
|
|
* @return Event[]|Room[]|RoomModel[]|ScheduleUrl|Schedule|string
|
|
|
|
|
* @throws ErrorException
|
|
|
|
|
*/
|
|
|
|
|
protected function getScheduleData(Request $request)
|
|
|
|
|
protected function getScheduleData(string $id)
|
|
|
|
|
{
|
|
|
|
|
$id = $request->getAttribute('id');
|
|
|
|
|
/** @var ScheduleUrl $scheduleUrl */
|
|
|
|
|
$scheduleUrl = ScheduleUrl::findOrFail($id);
|
|
|
|
|
|
|
|
|
|