public function update(SubscriptionService $subscriptionService, DeltaVCalculator $deltaV, $object_id) { if (Input::has(['status', 'visibility'])) { $object = Object::find($object_id); if (Input::get('status') == ObjectPublicationStatus::PublishedStatus) { DB::transaction(function () use($object, $subscriptionService, $deltaV) { // Put the necessary files to S3 (and maybe local) if (Input::get('visibility') == VisibilityStatus::PublicStatus) { $object->putToLocal(); } $job = (new PutObjectToCloudJob($object))->onQueue('uploads'); $this->dispatch($job); // Update the object properties $object->fill(Input::only(['status', 'visibility'])); $object->actioned_at = Carbon::now(); // Save the object if there's no errors $object->save(); // Add the object to our elasticsearch node Search::index($object->search()); // Create an award wih DeltaV $award = Award::create(['user_id' => $object->user_id, 'object_id' => $object->object_id, 'type' => 'Created', 'value' => $deltaV->calculate($object)]); // Once done, extend subscription $subscriptionService->incrementSubscription($object->user, $award); }); } elseif (Input::get('status') == "Deleted") { $object->delete(); } return response()->json(null, 204); } return response()->json(false, 400); }
public function create() { $this->object = Object::find($this->input['object_id']); // Global object DB::transaction(function () { $this->object->title = array_get($this->input, 'title', null); $this->object->summary = array_get($this->input, 'summary', null); $this->object->subtype = array_get($this->input, 'subtype', null); $this->object->originated_at = array_get($this->input, 'originated_at', null); $this->object->anonymous = array_get($this->input, 'anonymous', false); $this->object->attribution = array_get($this->input, 'attribution', null); $this->object->author = array_get($this->input, 'author', null); $this->object->external_url = array_get($this->input, 'external_url', null); $this->object->originated_at = array_get($this->input, 'originated_at', null); $this->object->status = ObjectPublicationStatus::QueuedStatus; $this->createMissionRelation(); $this->createTagRelations(); $this->object->push(); }); return $this->object; }
public function download($object_id) { $object = Object::find($object_id); // Only increment the downloads table if the same user has not downloaded it in the last hour (just like views) $mostRecentDownload = Download::where('user_id', Auth::id())->where('object_id', $object_id)->first(); if ($mostRecentDownload === null || $mostRecentDownload->created_at->diffInSeconds(Carbon::now()) > 3600) { Download::create(array('user_id' => Auth::id(), 'object_id' => $object_id)); // Reindex object Redis::sadd('objects:toReindex', $object_id); } if ($object->hasFile()) { return response()->json(null, 204); } else { if ($object->type == MissionControlType::Tweet) { $data = $object->tweet_text; } else { if ($object->type == MissionControlType::Comment) { if ($object->subtype == MissionControlSubtype::RedditComment) { $data = $object->reddit_comment_text; } else { if ($object->subtype == MissionControlSubtype::NSFComment) { $data = $object->nsf_comment_text; } } } else { if ($object->type == MissionControlType::Article) { $data = $object->article_text; } else { if ($object->type == MissionControlType::Text) { $data = $object->summary; } } } } return response()->make($data, 200, array('Content-type' => 'text/plain', 'Content-Disposition' => 'attachment;filename="' . str_slug($object->title) . '.txt"')); } }
public function commentsForObject($object_id) { $object = Object::find($object_id); return response()->json($object->commentTree); }