/** * Create worker unit */ public function process($signal, $payload, $settings) { //return "blabla"; // increase memory usage to support larger files with up to 10k judgments ini_set('memory_limit', '256M'); set_time_limit(0); $this->status = ['notice' => [], 'success' => [], 'error' => []]; try { if (!empty($payload)) { if ($signal == "new_units") { $settings['units'] = []; $retUnits = json_decode($payload, true); //return $retUnits; // Create activity $activity = $this->createActivity(); if ($settings['documentType'] == "") { $settings['documentType'] = "diveunit"; } if ($settings["batch_description"] == "") { $settings["batch_description"] = "Batch imported from DIVE dashboard"; } foreach ($retUnits as $unitContent) { $hashing = array(); $hashing["project"] = $settings["project"]; $hashing["documentType"] = $settings["documentType"]; $hashing["content"] = $unitContent; $hash = md5(serialize($hashing)); $searchForUnit = \Entity::where("hash", $hash)->first(); if ($searchForUnit != NULL) { //$units[$searchForUnit["_id"]] = $searchForUnit; array_push($settings['units'], $searchForUnit["_id"]); } else { $unit = new Unit(); $unit->project = $settings['project']; $unit->activity_id = $activity->_id; $unit->documentType = $settings['documentType']; $unit->type = "unit"; $unit->parents = []; $unit->content = $unitContent; $unit->hash = $hash; $unit->source = "divedashboard"; //return $unit; $unit->save(); $units[$unit->_id] = $unit; array_push($settings['units'], $unit->_id); // dd($settings['units']); } } // Create Batch $hashBatch = array(); $hashBatch["project"] = $settings["project"]; $hashBatch["batch_description"] = $settings["batch_description"]; $hashBatch["content"] = $settings["units"]; $settings['batch_title'] = "Imported batch from Dive dashboard"; $searchForBatch = \Entity::where("hash", md5(serialize($hashBatch)))->first(); if ($searchForBatch != NULL) { array_push($this->status['notice'], "Batch already exists " . $searchForBatch['_id'] . ""); } else { $batch = Batch::store($settings, $activity); } array_push($this->status['success'], "Successfully imported " . $settings['documentType'] . ""); array_push($this->status['success'], "Logged activities as " . $activity->_id . ""); return $this->status; } else { array_push($this->status['error'], "Unknown request from DIVE dashboard -- " . $signal . ""); return $this->status; } } else { array_push($this->status['error'], "The content of the units is empty -- " . $payload . ""); return $this->status; } } catch (Exception $e) { $activity->forceDelete(); foreach ($this->units as $unit) { if (!$unit->exists()) { $unit->forceDelete(); } } return $e; } }
public function store($documentType, $parameters, $noOfVideos) { //fastcgi_finish_request(); $listOfVideoIdentifiers = array(); $this->listRecords($parameters, $noOfVideos, $listOfVideoIdentifiers); // get list of existing projects $projects = ProjectHandler::listProjects(); // dd("done"); $status = array(); try { $this->createOpenimagesVideoGetterSoftwareAgent(); } catch (Exception $e) { $status['error']['OnlineData'] = $e->getMessage(); return $status; } try { $activity = new Activity(); $activity->softwareAgent_id = "openimagesgetter"; $activity->save(); } catch (Exception $e) { // Something went wrong with creating the Activity $status['error']['OnlineData'] = $e->getMessage(); $activity->forceDelete(); return $status; } $count["count"] = 0; foreach ($listOfVideoIdentifiers as $video) { $title = $video; try { $entity = new Unit(); $entity->_id = $entity->_id; $entity->title = strtolower($title); $entity->documentType = $documentType; $entity->source = "openimages"; $entity->project = "soundandvision"; $entity->type = "unit"; $videoMetadata = $this->getRecord($video, $parameters["metadataPrefix"]); $entity->content = $videoMetadata["content"]; $parents = array(); $entity->parents = $parents; $entity->tags = array("unit"); $entity->segments = $count; $entity->keyframes = $count; $hashing = array(); $hashing["content"] = $entity->content; $hashing["project"] = $entity->project; $entity->hash = md5(serialize($hashing)); $entity->activity_id = $activity->_id; $entity->save(); $status['success'][$title] = $title . " was successfully uploaded. (URI: {$entity->_id})"; // add the project if it doesnt exist yet if (!in_array($entity->project, $projects)) { ProjectHandler::createGroup($entity->project); // add the project to the temporary list array_push($projects, $entity->project); } // add the user to the project if it has no access yet if (!ProjectHandler::inGroup($entity->user_id, $entity->project)) { $user = UserAgent::find($entity->user_id); ProjectHandler::grantUser($user, $entity->project, Roles::PROJECT_MEMBER); } } catch (Exception $e) { // Something went wrong with creating the Entity $activity->forceDelete(); $entity->forceDelete(); $status['error'][$title] = $e->getMessage(); } } $status["recno"] = count($listOfVideoIdentifiers); return $status; }