You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/Paths/RegionalData.php
+91-83
Original file line number
Diff line number
Diff line change
@@ -400,70 +400,68 @@ private function createRegionalCalendar(): void
400
400
*
401
401
* It is private as it is called from {@see updateRegionalCalendar}.
402
402
*
403
-
* The resource is created or updated in the `jsondata/sourcedata/nations/` directory.
404
-
*
405
-
* If the payload is valid according to {@see LitSchema::NATIONAL}, the response will be a JSON object
406
-
* containing a success message.
407
-
*
408
-
* If the payload is invalid, the response will be a JSON error response with a 422 status code.
403
+
* If the resource to update is not found in the national calendars index, the response will be a JSON error response with a status code of 404 Not Found.
404
+
* If the resource to update is not writable or the write was not successful, the response will be a JSON error response with a status code of 503 Service Unavailable.
405
+
* The resource is updated in the `jsondata/sourcedata/calendars/nations/` directory.
409
406
*/
410
407
privatefunctionhandleNationalCalendarUpdate()
411
408
{
412
-
$response = new \stdClass();
409
+
$nationEntry = array_values(array_filter($this->CalendarsMetadata->national_calendars, function ($item) {
410
+
return$item->calendar_id === $this->params->key;
411
+
}));
412
+
413
+
if ( empty($nationEntry) ) {
414
+
self::produceErrorResponse(StatusCode::NOT_FOUND, "Cannot update unknown national calendar resource {$this->params->key}.");
self::produceErrorResponse(StatusCode::SERVICE_UNAVAILABLE, "Cannot update national calendar i18n resource for {$this->params->key} at {$calendarI18nFile}, check file and folder permissions.");
self::produceErrorResponse(StatusCode::SERVICE_UNAVAILABLE, "Could not update national calendar i18n resource {$this->params->key} in path {$calendarI18nFile}.");
self::produceErrorResponse(StatusCode::SERVICE_UNAVAILABLE, "Could not update national calendar resource {$this->params->key} in path {$calendarFile}.");
466
460
}
461
+
462
+
$response = new \stdClass();
463
+
$response->success = "Calendar data created or updated for Nation \"{$this->params->key}\"";
464
+
self::produceResponse(json_encode($response));
467
465
}
468
466
469
467
/**
@@ -512,37 +510,30 @@ private function handleWiderRegionCalendarUpdate()
$response->success = "Calendar data created or updated for Wider Region \"{$widerRegion}\"";
522
+
self::produceResponse(json_encode($response));
530
523
}
531
524
532
525
/**
533
526
* Handle PATCH requests to create or update a diocesan calendar data resource.
534
527
*
535
528
* It is private as it is called from {@see updateRegionalCalendar}.
536
529
*
537
-
* The resource is created or updated in the `jsondata/sourcedata/nations/` directory.
530
+
* The resource is created or updated in the `jsondata/sourcedata/calendars/dioceses/` directory.
538
531
*
539
532
* If the payload is valid according to {@see LitSchema::DIOCESAN}, the response will be a JSON object
540
533
* containing a success message.
541
534
*
542
-
* If the resource to update is not found in the diocesan calendars index or in the `jsondata/sourcedata/nations/{nation}/` directory, the response will be a JSON error response with a status code of 404 Not Found.
543
-
* If the payload is not an object, the response will be a JSON error response with a status code of 400 Bad Request.
535
+
* If the resource to update is not found in the diocesan calendars index, the response will be a JSON error response with a status code of 404 Not Found.
544
536
* If the resource to update is not writable or the write was not successful, the response will be a JSON error response with a status code of 503 Service Unavailable.
545
-
* If the payload is not valid according to {@see LitSchema::DIOCESAN}, the response will be a JSON error response with a status code of 422 Unprocessable Content.
546
537
*
547
538
*/
548
539
privatefunctionhandleDiocesanCalendarUpdate()
@@ -552,13 +543,7 @@ private function handleDiocesanCalendarUpdate()
@@ -637,15 +622,38 @@ private function handleDiocesanCalendarUpdate()
637
622
*/
638
623
privatefunctionupdateRegionalCalendar()
639
624
{
625
+
if (false === $this->params->payloadinstanceof \stdClass) {
626
+
$payloadType = gettype($this->params->payload);
627
+
self::produceErrorResponse(StatusCode::BAD_REQUEST, "`payload` param expected to be serialized object, instead it was of type `{$payloadType}` after unserialization");
0 commit comments