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)); }
/** * Scan and cache the assets in a collection. * */ public function collect(\RS\Repose\Core\Objects\Collection $collection) { static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': Adding assets to hierarchy map: ' . $collection->parent()->name() . DS . $collection->name()); if (strpos($collection->parent()->name(), '.') !== 0) { $path = static::$disk->protocol() . $collection->parent()->name() . DS . $collection->name(); foreach (static::$manager->listContents($path, 0) as $info) { if (array_key_exists('extension', $info) && $info['extension'] === 'json') { continue; } // This does not return a "real" fully populated asset yet $service = new AssetService(new Asset(), $info); $asset = $service->asset(); $collection->add($asset->uuid(), $asset); } } }
public function ingest($type) { static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': staged file: ' . $this->staged_filename); // make relative to storage point $file = str_replace($this->staging . DS, '', $this->staged_filename); $file = 'default' . DS . $file; // working with disk level in src paths now - since 0.4.4 // snag collection name from src path (remove volume name if present) $this->collection_name = pathinfo($file, PATHINFO_DIRNAME); $this->collection_name = Util::trimVolumeName($this->collection_name); // if present ... // need the instance to associate with each asset before writing Json file $this->collection = static::$disk->collection($this->collection_name); // preserve for the record $originalName = pathinfo($file, PATHINFO_FILENAME); // without extension $originalExtension = pathinfo($file, PATHINFO_EXTENSION); // normalize $extension = Util::lower($originalExtension); // assign $uuid = Uuid::uuid4()->toString(); $target_filename = $uuid . '.' . $extension; $target_path = $this->collection_name; $target_spec = $target_path . DS . $target_filename; // alias for clarity - convenience // staged_filename has 'staging://' prefix // this does not want it $src_file = $file; if ($this->copyToTarget($src_file, $target_spec)) { static::$logger->addInfo($src_file . ' copied to ' . $target_spec); $this->removeFromStagingDir('staging://' . $src_file); $new_asset = new Asset(); $assetService = new AssetService($new_asset, ['path' => $target_path, 'filename' => $uuid]); // $info comes from Flysystem MountManager - filename is correct here $assetService->path($target_path); // want no protocol or file name here $new_asset->parent($assetService->getCollection()); // whether or not to use sidecar assignedProperties file from spool // or to save only the derived attributes from the ingest service // is there a specified sidecar assignedProperties file for this asset ? ie, in spool/staging // $originalName WITHOUT extension is key for md file, if any $md_key = $this->staging . DS . $this->collection_name . DS . $originalName; // findMetadataSidecarFile also validates the sidecar file $md_file_name = $this->findMetadataSidecarFile($md_key, $extension, $type); if (!is_null($md_file_name)) { $md = static::$manager->read('staging://' . $md_file_name); $new_asset->reload($md); } // set the basics from discovery $new_asset->uuid($uuid); $new_asset->parent($this->collection); $new_asset->mimeType($type); $new_asset->extension($extension); $new_asset->basename($originalName); $this->derivedProperties->{'created'} = time(); static::$logger->addInfo(__CLASS__ . '::' . __FUNCTION__ . ': derivedProps: ' . json_encode($this->derivedProperties, JSON_UNESCAPED_SLASHES)); // append file attributes as collected by ingest service $new_asset->derivedProperties($this->derivedProperties); // store all assignedProperties - derived and specified - in sidecar file $assetService->storeJsonData(); static::$logger->addInfo("Wrote new assignedProperties file: " . $assetService->jsonPath()); return true; } else { $this->reject($src_file); static::$logger->addAlert('Checksum verification failed: file: ' . $src_file . ' not copied to repository (now in rejects folder).'); } return false; }