diff --git a/src/Commands/JsonApiDrushCommands.php b/src/Commands/JsonApiDrushCommands.php index 14b72bf..0227173 100644 --- a/src/Commands/JsonApiDrushCommands.php +++ b/src/Commands/JsonApiDrushCommands.php @@ -247,13 +247,22 @@ class JsonApiDrushCommands extends DrushCommands { } JSON; - /** * Wraps a JSON API node post call back with added files. * * @param string $jsonfilepath * A file containing either a full JSON API data payload or just SBF JSON * data. + * @param array $options + * 'files' => A folder or file that will be attached to the ADO + * 'user' => Drupal user that will do the action via JSON API + * 'password' => password for 'user' + * 'bundle' => 'digital_object', + * 'fieldname' => 'field_descriptive_metadata', + * 'uuid' => If provided and ADO exists ingest will not happen, + * 'moderation_state' => draft/published. Anything that is valid. + * + * @throws \Exception if ingest is not possible * * @command archipelago:jsonapi-ingest * @aliases ap-jsonapi-ingest @@ -370,6 +379,15 @@ public function ingest( // Check if JSON is a full JSON API data payload or just our SBF. // If just SBF, we need to have the machine name of the field to push data $data = json_decode($json_data, TRUE); + $json_error = json_last_error(); + if ($json_error != JSON_ERROR_NONE) { + // Well this is how life ends. + throw new \Exception( + dt( + 'The provided JSON could not be parsed or is not a valid JSON. Suspending the ingest' + ) + ); + } if (isset($data['data']['type']) && $data['data']['type'] == 'node--' . $bundle) { try { // @see https://github.com/swaggest/php-json-schema @@ -455,10 +473,10 @@ public function ingest( if (isset($response['data']['attributes']['drupal_internal__fid'])) { $this->output()->writeln( dt( - 'File @file sucessfully uploaded with file ID @fileid ', + 'File @file sucessfully uploaded with Internal Drupal file ID @fileid ', [ '@file' => $file->filename, - '@fileod' => $response['data']['attributes']['drupal_internal__fid'], + '@fileid' => $response['data']['attributes']['drupal_internal__fid'], ] ) );