public function adminEditSidecarPOST(Request $request, Response $response, $args) { // unpack json body $json = $request->getParsedBody(); // var_dump($json); $service = new SearchService(); $return = 'return'; $unit = 'disk:default'; $terms = ['uuid:' . $json['uuid']]; $asset = $service->search(compact('return', 'unit', 'terms')); $asset = $asset[$terms[0]][$json['uuid']]; $path = 'default://' . $asset->parent()->parent()->name() . DS . $asset->parent()->name() . DS . $json['uuid'] . '.png'; $this->logger->info(__CLASS__ . '::' . __FUNCTION__ . ': BUILT path: ' . $path); $assignedProps = $asset->assignedProperties(); // this will reload the asset from json file // create this before we attempt to overwrite the props $assetService = new AssetService($asset, ['path' => $path, 'filename' => $json['uuid']]); $this->logger->info(__CLASS__ . '::' . __FUNCTION__ . ': asset service is setup and loaded'); unset($json['uuid']); // overwrite each edited (submitted) prop // readonly props are not submittable foreach ($json as $key => $value) { $assignedProps->{'properties'}->{$key} = $value; } $asset->assignedProperties($assignedProps); // $this->logger->info(__CLASS__.'::'.__FUNCTION__.': asset to json: '.$asset->toJson()); $resp = []; // commit changes to file if ($assetService->storeJsonData()) { $resp['response'] = 'updated'; } else { $resp['response'] = 'failed'; } return $response->getBody()->write(json_encode($resp)); }
/** * Fetch one asset instance object * * @param Request $request * @param Response $response * @param $args * @return asset serialized asset object */ public function adminAssetPOST(Request $request, Response $response, $args) { if (array_key_exists('uuid', $args) && $args['uuid']) { $uuid = $args['uuid']; } $service = new SearchService(); $return = 'return'; $unit = 'disk:default'; $terms = ['uuid:' . $uuid]; $asset = $service->search(compact('return', 'unit', 'terms')); $asset = $asset['uuid:' . $uuid]; $asset = $asset[$uuid]; $this->logger->info(__CLASS__ . '::' . __FUNCTION__ . ': ' . serialize($asset)); if ($asset instanceof Asset) { $asset->parent = $asset->parent->name(); $asset = serialize($asset); } return $response->withStatus(200)->write($asset); }