/** * Execute the console command. * * @return mixed */ public function handle() { // Fetch objects and delete redis sets $objects = Object::whereIn('object_id', Redis::smembers('objects:toReindex'))->get(); $collections = Collection::whereIn('collection_id', Redis::smembers('collections:toReindex'))->get(); $dataViews = DataView::whereIn('dataview_id', Redis::smembers('dataviews:toReindex'))->get(); Redis::del(['objects:toReindex', 'collections:toReindex', 'dataviews:toReindex']); // Map to return searchable interfaces and reindex if ($objects->count() > 0) { foreach ($objects as $object) { $searchableObjects[] = $object->search(); } Search::bulkReindex($searchableObjects); } if ($collections->count() > 0) { foreach ($collections as $collection) { $searchableCollections[] = $collection->search(); } Search::bulkReindex($searchableCollections); } if ($dataViews->count() > 0) { foreach ($dataViews as $dataView) { $searchableDataViews[] = $dataView->search(); } Search::bulkReindex($searchableDataViews); } }
public function submitFiles() { $files = Input::get('data'); $objectValidities = $objectManagers = $queuedObjects = []; $doesNotContainErrors = true; // Find each object from file for ($i = 0; $i < count($files); $i++) { $objectManagers[$i] = App::make('SpaceXStats\\ModelManagers\\Objects\\ObjectFromFile'); $objectValidities[$i] = $objectManagers[$i]->isValid($files[$i]) ? true : $objectManagers[$i]->getErrors(); if ($objectValidities[$i] !== true) { $doesNotContainErrors = false; } } // Check if there are errors, if no, add all to db, if yes, return with errors. if ($doesNotContainErrors) { // add all objects to db for ($i = 0; $i < count($files); $i++) { $queuedObjects[$i] = $objectManagers[$i]->create(); } // nothing bad happened, let's also create an optional collection if asked to if (Input::get('collection') != null) { $collection = Collection::create(['creating_user_id' => Auth::id(), 'title' => Input::get('collection.title'), 'summary' => Input::get('collection.summary')]); // and associate it with the given files $collection->objects()->saveMany($queuedObjects); } } else { return response()->json($objectValidities, 400); } // redirect to mission control Session::flash('flashMessage', 'Done!'); return response()->json(null, 204); }
public function delete($collection_id) { Collection::find($collection_id)->delete(); return response()->json(null, 204); }