public function apiObjectQuery($table, $request)
 {
     $params = config('harvester-transaction.valid_params');
     // check that all params are valid.
     foreach ($request->all() as $key => $value) {
         if (!in_array($key, $params)) {
             return ['error' => $key . ' is not a valid request parameter.'];
         }
     }
     $take = $request->has('take') ? $request->input('take') : config('harvester-transaction.defaults.take');
     $action = $request->has('action') ? $request->input('action') : null;
     $actions = config('harvester-transaction.valid_actions');
     if (!in_array($action, $actions)) {
         return ['error' => 'action=' . $action . ' is not a valid request parameter.'];
     }
     if ($action != 'deleted') {
         $query = Object::select();
         if (in_array($action, ['updated', 'created', 'modified'])) {
             $query->whereHas('transactions', function ($q) use($table, $request, $action) {
                 $hours = $request->has('since') ? $request->input('since') : config('harvester-transaction.defaults.since');
                 $since = Carbon::now()->subhours($hours);
                 $q->where('created_at', '>=', $since);
                 // ?action=modified will find both created and update objects
                 if ($action == 'modified') {
                     $q->whereIn('action', ['created', 'updated']);
                 }
                 // ?action=[created,updated]
                 if ($action != 'modified') {
                     $q->where('action', '=', $action);
                 }
                 $q->where('table', '=', $table);
             })->with(['transactions' => function ($q) use($table) {
                 $q->where('table', '=', $table);
             }]);
         }
         $query->with(['actors', 'assets', 'assets.type', 'assets.source', 'terms', 'terms.type', 'texts', 'texts.type', 'locations', 'locations.type', 'dates', 'dates.type']);
     }
     if ($action == 'deleted') {
         $query = Transaction::where('table', '=', $table)->where('action', '=', $action)->distinct();
     }
     $request = $query->paginate($take);
     return $request;
 }
예제 #2
0
 public function handle()
 {
     $only = $this->option('only');
     $source = $this->option('source');
     // if id is set find object
     if ($this->option('id')) {
         $id = $this->option('id');
         $object = Object::findOrFail($id);
         $object_uid = $object->object_uid;
     }
     // if accession is set find object
     if ($this->option('uid')) {
         $object_uid = $this->option('uid');
     }
     if ($only == 'data' || $only == 'null') {
         $this->harvester->initialOrUpdateObject($object_uid, $source);
     }
     if ($only == 'images' || $only == 'null') {
         // Queue command to process images
         $command = new HarvestImages($object_uid);
         $this->dispatch($command);
     }
 }
예제 #3
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     // get object
     $object = Object::with('assets', 'assets.type', 'source')->where('object_uid', '=', $this->object_uid)->firstOrFail();
     $this->deepzoom = DeepzoomFactory::create(['path' => public_path('images/' . $object->id), 'driver' => config('harvester.image.driver')]);
     // delete directory if it exists
     if ($this->filesystem->has('images/' . $object->id)) {
         $this->filesystem->deleteDir('images/' . $object->id);
         $this->deleteAssetRecords($object);
     }
     foreach ($object->source as $asset) {
         // load image into memory for this asset
         $img = $this->imageManager->make($asset->source_uri);
         // if object has proper rights
         if ($object->can_zoom == 1 || $object->can_download == 1) {
             // create deepzoom tiles
             if ($object->can_zoom == 1) {
                 // get result back form deepzoom
                 $result = $this->deepzoom->makeTiles($asset->source_uri, 'dzi' . $asset->source_sequence, $asset->source_sequence);
                 foreach ($result['data']['output'] as $key => $value) {
                     $asset_type = AssetType::where('asset_type_name', '=', strtolower($key))->first();
                     if ($asset_type) {
                         $asset_type_id = $asset_type->id;
                         $imgPath = 'images/' . $object->id . '/' . $asset->source_sequence . '/' . basename($value);
                         $this->createAsset($imgPath, $asset_type_id, $object->id, $asset->source_sequence, $asset->id);
                     }
                 }
             }
             foreach ($this->sizes as $type => $width) {
                 $this->generateAsset($img, $object->id, $asset, $type, $width);
             }
             if ($object->can_download == 1) {
                 $this->generateAsset($img, $object->id, $asset, 'original', $img->width(), $img->height());
             }
         }
         // generate the sizes below the protected width
         if ($object->protected_size != null) {
             $protected_size = $this->protected[$object->protected_size];
             $img_width = $img->width();
             $img_height = $img->height();
             $aspect_ratio = $img_width / $img_height;
             foreach ($this->sizes as $type => $width) {
                 if ($width <= $protected_size['width']) {
                     if ($aspect_ratio < 1) {
                         $this->generateAsset($img, $object->id, $asset, $type, $width, $protected_size['height']);
                     } else {
                         $this->generateAsset($img, $object->id, $asset, $type, $width, $protected_size['width']);
                     }
                 }
             }
             // check is aspect ratio is horizontal of vertical
             if ($aspect_ratio < 1) {
                 $this->generateAsset($img, $object->id, $asset, 'protected', $protected_size['width'], $protected_size['height']);
             } else {
                 $this->generateAsset($img, $object->id, $asset, 'protected', $protected_size['height'], $protected_size['width']);
             }
         }
     }
     // touch object updated_at timestamp to record transaction
     $object->touch();
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $source = $this->option('source');
     // get all object ids from source
     $source_object_uids = $this->harvester->getAllIDs($source);
     // get all harvester object uids
     $objects = \DB::table('objects')->lists('object_uid');
     $harvester_object_uids = ['results' => $objects, 'total' => count($objects)];
     $harvester_object_uids = (object) $harvester_object_uids;
     // get harvester_object_uids not in the source_object_uids array
     $harvester_delete = array_diff($harvester_object_uids->results, $source_object_uids->results);
     // delete harvesterUIDs if not in sourceIDs
     foreach ($harvester_delete as $object_uid) {
         $object = Object::where('object_uid', '=', $object_uid)->first();
         $object->delete();
         Source::where('object_id', '=', $object->id)->delete();
         Asset::where('object_id', '=', $object->id)->delete();
     }
     // get source_object_uids not in the harvester_object_uids array
     $harvester_queue = array_diff($source_object_uids->results, $harvester_object_uids->results);
     // queue sourceIDs if not in harvesterIDs
     foreach ($harvester_queue as $object_uid) {
         // Queue artisan command for data only
         \Artisan::queue('harvest:object', ['--uid' => $object_uid, '--only' => 'data', '--source' => $source]);
         // Queue command to process images
         $command = new HarvestImages($object_uid);
         $this->dispatch($command);
     }
     // compare sourece assets to harvester assets
     foreach ($source_object_uids->results as $source_uid) {
         // if source uid has not already been queued then compare assets
         if (!in_array($source_uid, $harvester_queue)) {
             // get source object
             $source_object = $this->harvester->getObject($source_uid, $source);
             // get source object assets
             $source_asset_ids = [];
             foreach ($source_object->images as $asset) {
                 $source_asset_ids[] = $asset->source_id;
             }
             // get harvester object
             $harvester_object = Object::with(['source'])->where('object_uid', '=', $source_uid)->first();
             // get harvester object
             $harvester_asset_ids = [];
             foreach ($harvester_object->source as $asset) {
                 $harvester_asset_ids[] = $asset->origin_id;
             }
             // get harvester_asset_ids not in the source_asset_ids array
             $harvester_asset_delete = array_diff($harvester_asset_ids, $source_asset_ids);
             // delete harvester source assets no longer found in the source
             $harvester_delete_queue = false;
             foreach ($harvester_asset_delete as $origin_id) {
                 // remove source reference from database
                 Source::where('object_id', '=', $harvester_object->id)->delete();
                 Asset::where('object_id', '=', $harvester_object->id)->delete();
                 $harvester_delete_queue = true;
             }
             // regenerate images associated with object
             if ($harvester_delete_queue) {
                 // Queue artisan command for data only
                 \Artisan::queue('harvest:object', ['--uid' => $source_uid, '--only' => 'data', '--source' => $source]);
                 // Queue command to process images
                 $command = new HarvestImages($source_uid);
                 $this->dispatch($command);
             }
             // get source_asset_ids not in the harvester_object_ids array
             $harvester_asset_queue = array_diff($source_asset_ids, $harvester_asset_ids);
             if (!empty($harvester_asset_queue)) {
                 // Queue artisan command for data only
                 \Artisan::queue('harvest:object', ['--uid' => $source_uid, '--only' => 'data', '--source' => $source]);
                 // Queue command to process images
                 $command = new HarvestImages($source_uid);
                 $this->dispatch($command);
             }
         }
     }
     // Queue the export command
     if ($this->option('export')) {
         \Artisan::queue('harvest:export', ['--deleted' => true]);
         \Artisan::queue('harvest:export', ['--modified' => true]);
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function object_show($id)
 {
     $results = Object::with(['actors', 'assets', 'assets.type', 'assets.source', 'terms', 'terms.type', 'texts', 'texts.type', 'locations', 'locations.type', 'dates', 'dates.type'])->findOrFail($id);
     $results = $this->transformer->item($results);
     return response()->json($results, 200);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $source = $this->option('source');
     $only = $this->option('only');
     $objects = \DB::table('objects')->pluck('object_uid');
     $objects = ['results' => $objects, 'total' => count($objects)];
     $objects = (object) $objects;
     $deleted_uids = [];
     if ($this->option('initial')) {
         $this->info('Getting all object IDs for seeding.');
     }
     if ($this->option('refresh')) {
         $this->info('Getting all object IDs for refresh.');
     }
     if ($this->option('update')) {
         $this->info('Getting all updated object IDs.');
     }
     // create extended types maybe should of a harvester config
     if ($this->option('initial')) {
         $this->harvester->createTypes();
     }
     // get all object_uid from piction
     if ($this->option('initial')) {
         $response = $this->harvester->getAllIDs($source);
     }
     // set response to objects in harvester
     if ($this->option('refresh')) {
         $response = $this->harvester->getAllIDs($source);
         // get object ids that are still part of piciton response
         $intersectResponse = array_intersect($objects->results, $response->results);
         // get items that have been deleted from source
         $deleted_uids = array_diff($objects->results, $response->results);
         // set response to intersectResponse
         $response->results = $intersectResponse;
         $response->total = count($intersectResponse);
     }
     if ($this->option('update')) {
         // get updated ids from piciton
         $response = $this->harvester->getUpdateIDs($source);
         // get all ids from piction
         $allResponse = $this->harvester->getAllIDs($source);
         // get deleted ids not in the all response
         $deleted_uids = array_diff($objects->results, $allResponse->results);
         // get ids from all response not currently in harvester
         $added_uids = array_diff($allResponse->results, $objects->results);
         // get ids that are also not in the updated response
         $diffAdded_uids = array_diff($added_uids, $response->results);
         // merge response with diff added
         $response->results = array_merge($response->results, $diffAdded_uids);
         // set count of response
         $response->total = count($response->results);
     }
     $objectIDs = $response->results;
     if (count($objectIDs) > 0) {
         // start progress display in console
         $this->output->progressStart($response->total);
         foreach ($objectIDs as $objectID) {
             if ($only == 'null') {
                 // Queue artisan command for data only
                 \Artisan::queue('harvest:object', ['--uid' => $objectID, '--only' => 'data', '--source' => $source]);
                 // Queue command to process images
                 $command = new HarvestImages($objectID);
                 $this->dispatch($command);
             }
             if ($only == 'data') {
                 // Queue artisan command for data only
                 \Artisan::queue('harvest:object', ['--uid' => $objectID, '--only' => 'data', '--source' => $source]);
             }
             if ($only == 'images') {
                 // Queue command to process images
                 $command = new HarvestImages($objectID);
                 $this->dispatch($command);
             }
             // advance progress display in console
             $this->output->progressAdvance();
         }
         // complete progress display in console
         $this->output->progressFinish();
     } else {
         $this->info('No objects have been updated.');
     }
     if (!empty($deleted_uids)) {
         foreach ($deleted_uids as $object_uid) {
             $object = Object::where('object_uid', '=', $object_uid)->first();
             $object->delete();
             Source::where('object_id', '=', $object->id)->delete();
             Asset::where('object_id', '=', $object->id)->delete();
         }
     }
     // Queue the export command
     if ($this->option('export')) {
         \Artisan::queue('harvest:export', ['--modified' => true]);
         \Artisan::queue('harvest:export', ['--deleted' => true]);
     }
 }