protected static function boot() { parent::boot(); static::creating(function ($entity) { if (!Schema::hasCollection('entities')) { static::createSchema(); } if (empty($entity->project)) { throw new Exception("No project was given"); } if (!empty($entity->hash) && !empty($entity->project)) { if (Entity::withTrashed()->where('hash', $entity->hash)->where('project', $entity->project)->first()) { throw new Exception("Hash already exists for: " . $entity->title . " in project " . $entity->project); } } $entity->_id = static::generateIncrementedBaseURI($entity); if (Auth::check()) { $entity->user_id = Auth::user()->_id; } else { $entity->user_id = "crowdtruth"; } }); static::saved(function ($entity) { Temp::truncate(); Cache::flush(); }); static::deleted(function ($entity) { Cache::flush(); }); }
/** * Store to the database the given entities as entities decendent from the given * document. * * @param $document Parent document -- Must be a document entity on the database. * @param $entities List of entities to be created as decendents from the given document. * * @return multitype:string A status array containing the result status information. */ public function store($parent, $units, $type) { if (count($units) <= 0 && count($units) >= 10000) { // We will have problems processing empty files or more than 10,000 entities return ['error' => 'Unable to process files with more than 10,000 lines: ' . $nEnts . 'found']; } $activity = new \Activity(); $activity->softwareAgent_id = $this->softwareComponent->_id; $activity->save(); $entities = []; foreach ($units as $unit) { try { $entity = new Unit(); $entity->project = $parent->project; $entity->activity_id = $activity->_id; $entity->documentType = $type; $entity->parents = [$parent->_id]; $entity->content = $unit; $entity->hash = md5(serialize($entity)); $entity->save(); array_push($entities, $entity); } catch (Exception $e) { foreach ($entities as $en) { $en->forceDelete(); } throw $e; } } \Temp::truncate(); return ['success' => 'Sentences created successfully']; }
public function store(&$parentEntity, $relexStructuredSentences, $inc) { // dd('test'); $allEntities = array(); foreach ($relexStructuredSentences as $tKey => &$relexStructuredSentence) { $title = $parentEntity['title'] . "_index_" . $inc; $hash = md5(serialize(array_except($relexStructuredSentence, ['properties']))); if ($dup = Entity::where('hash', $hash)->first()) { array_push($this->status['store']['error']['skipped_duplicates'], $tKey . " ---> " . $dup->_id); continue; } if (Auth::check()) { $user_id = Auth::user()->_id; } else { $user_id = "crowdwatson"; } $entity = ["_id" => 'entity/text/medical/relex-structured-sentence/' . $inc, "title" => strtolower($title), "domain" => $parentEntity['domain'], "format" => $parentEntity['format'], "tags" => ['unit'], "documentType" => "relex-structured-sentence", "parents" => [$parentEntity['_id']], "content" => $relexStructuredSentence, "hash" => $hash, "activity_id" => $this->activity->_id, "user_id" => $user_id, "updated_at" => new MongoDate(time()), "created_at" => new MongoDate(time())]; array_push($allEntities, $entity); $inc++; array_push($this->status['store']['success'], $tKey . " ---> URI: {$entity['_id']}"); } if (count($allEntities) > 1) { \DB::collection('entities')->insert($allEntities); Temp::truncate(); } return $inc; }
public function getDeletepl($id) { $platform = App::make('cf2'); //dd($id); $platform->deleteJobPL($id); Temp::truncate(); return Redirect::to("jobs"); }