Esempio n. 1
0
 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;
 }