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()
 {
     DB::transaction(function () {
         $twitterClient = new TwitterOAuth(Config::get('services.twitter.consumerKey'), Config::get('services.twitter.consumerSecret'), Config::get('services.twitter.accessToken'), Config::get('services.twitter.accessSecret'));
         // Fetch the tweet information from Twitter, if a tweet id was passed through (it is possible the tweet was created manually without an id)
         if (array_key_exists('tweet_id', $this->input)) {
             $tweet = $twitterClient->get('statuses/show', ['id' => $this->input['tweet_id']]);
             $tweetOwner = $tweet->user;
             $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $tweet->text, 'tweet_id' => $tweet->id, 'tweet_parent_id' => $tweet->in_reply_to_status_id, 'size' => strlen($tweet->text), 'title' => $tweet->text, 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $tweet->text), 'originated_at' => Carbon::createFromFormat('D M d H:i:s P Y', $tweet->created_at)->toDateTimeString(), 'status' => ObjectPublicationStatus::QueuedStatus]);
         } else {
             $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Tweet, 'tweet_text' => $this->input['tweet_text'], 'size' => strlen($this->input['tweet_text']), 'title' => $this->input['tweet_text'], 'summary' => $this->input['summary'], 'cryptographic_hash' => hash('sha256', $this->input['tweet_text']), 'originated_at' => $this->input['originated_at'], 'status' => ObjectPublicationStatus::QueuedStatus]);
         }
         try {
             if (!isset($tweetOwner)) {
                 $tweetOwner = $twitterClient->get('users/show', ['screen_name' => $this->input['tweet_screen_name']]);
             }
             $tweeter = Tweeter::byScreenName($tweetOwner->screen_name)->firstOrFail();
         } catch (ModelNotFoundException $e) {
             $tweeter = Tweeter::create(['screen_name' => $tweetOwner->screen_name, 'user_name' => $tweetOwner->name, 'description' => $tweetOwner->description]);
             $tweeter->saveProfilePicture();
         }
         $this->object->tweeter()->associate($tweeter);
         $this->createMissionRelation();
         $this->createTagRelations();
         $this->object->push();
     });
     return $this->object;
 }
 /**
  * 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);
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $orphanedObjects = Object::where('status', ObjectPublicationStatus::NewStatus)->where('created_at', '<', Carbon::now()->subWeek())->get();
     $trashedObjectsByKey = $orphanedObjects->each(function ($orphanedObject) {
         $orphanedObject->deleteFromTemporary();
     })->keyBy('object_id');
     Object::destroy($trashedObjectsByKey->keys());
 }
 public function create()
 {
     DB::transaction(function () {
         $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Text, 'title' => $this->input['title'], 'size' => strlen($this->input['summary']), 'summary' => $this->input['summary'], 'anonymous' => array_get($this->input, 'anonymous', false), 'cryptographic_hash' => hash('sha256', $this->input['summary']), 'originated_at' => Carbon::now(), 'original_content' => true, 'status' => ObjectPublicationStatus::QueuedStatus]);
         $this->createMissionRelation();
         $this->createTagRelations();
         $this->object->push();
     });
     return $this->object;
 }
 public function create()
 {
     DB::transaction(function () {
         $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Comment, 'subtype' => MissionControlSubtype::NSFComment, 'title' => $this->input['title'], 'size' => strlen($this->input['comment']), 'summary' => $this->input['comment'], 'cryptographic_hash' => hash('sha256', $this->input['comment']), 'external_url' => $this->input['external_url'], 'originated_at' => \Carbon\Carbon::now(), 'status' => ObjectPublicationStatus::QueuedStatus]);
         $this->createMissionRelation();
         $this->createTagRelations();
         $this->object->push();
     });
     return $this->object;
 }
 public function create()
 {
     DB::transaction(function () {
         $this->object = Object::create(['user_id' => Auth::id(), 'type' => MissionControlType::Article, 'subtype' => MissionControlSubtype::PressRelease, 'title' => $this->input['title'], 'size' => strlen($this->input['article']), 'article' => $this->input['article'], 'cryptographic_hash' => hash('sha256', $this->input['article']), 'originated_at' => \Carbon\Carbon::now(), 'publisher_id' => Publisher::where('name', 'SpaceX')->first()->publisher_id, 'status' => ObjectPublicationStatus::QueuedStatus]);
         $this->createMissionRelation();
         $this->createTagRelations();
         $this->object->push();
     });
     return $this->object;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  String $model
  * @return mixed
  */
 public function handle($request, Closure $next, $model)
 {
     if ($model == 'Mission') {
         Mission::whereSlug(Route::input('slug'))->firstOrFail();
     } elseif ($model == 'Object') {
         Object::findOrFail(Route::input('object_id'));
     } elseif ($model == 'Tag') {
         Tag::where('name', Route::input('slug'))->firstOrFail();
     }
     return $next($request);
 }
 public function index()
 {
     $publishers = Publisher::with('objects')->get()->map(function ($publisher) {
         $publisher->articleCount = $publisher->objects->count();
         $publisher->mostRecentArticle = $publisher->objects->sortByDesc('originated_at')->first();
         unset($publisher->objects);
         return $publisher;
     });
     JavaScript::put(['publishers' => $publishers, 'articleCount' => Object::where('type', MissionControlType::Article)->inMissionControl()->count()]);
     return view('missionControl.publishers.index');
 }
Пример #10
0
 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;
 }
 /**
  * GET POST, /missions/{slug}/edit. Edit a mission.
  *
  * @param $slug
  * @return \Illuminate\View\View
  */
 public function getEdit($slug)
 {
     // Fetch all objects at once and then organize into collection to reduce queries
     $missionObjects = Object::wherePublic()->inMissionControl()->whereHas('mission', function ($q) use($slug) {
         $q->whereSlug($slug);
     })->get();
     JavaScript::put(['mission' => Mission::whereSlug($slug)->with('payloads', 'spacecraftFlight.spacecraft', 'spacecraftFlight.astronautFlights.astronaut', 'partFlights.part', 'prelaunchEvents', 'telemetry')->first(), 'destinations' => Destination::all(['destination_id', 'destination'])->toArray(), 'missionTypes' => MissionType::all(['name', 'mission_type_id'])->toArray(), 'launchSites' => Location::where('type', 'Launch Site')->get()->toArray(), 'landingSites' => Location::where('type', 'Landing Site')->orWhere('type', 'ASDS')->get()->toArray(), 'vehicles' => Vehicle::all(['vehicle', 'vehicle_id'])->toArray(), 'parts' => Part::whereDoesntHave('partFlights', function ($q) {
         $q->where('landed', false);
     })->get()->toArray(), 'spacecraft' => Spacecraft::all()->toArray(), 'astronauts' => Astronaut::all()->toArray(), 'launchVideos' => $missionObjects->where('subtype', MissionControlSubtype::LaunchVideo)->filter(function ($item) {
         return $item->external_url != null;
     })->values(), 'featuredImages' => $missionObjects->where('subtype', MissionControlSubtype::Photo)->values(), 'missionPatches' => $missionObjects->where('subtype', MissionControlSubtype::MissionPatch)->values(), 'pressKits' => $missionObjects->where('subtype', MissionControlSubtype::PressKit)->values(), 'cargoManifests' => $missionObjects->where('subtype', MissionControlSubtype::CargoManifest)->values(), 'pressConferences' => $missionObjects->where('subtype', MissionControlSubtype::PressConference)->filter(function ($item) {
         return $item->external_url != null;
     })->values()]);
     return view('missions.edit');
 }
 public function aboutTotalData()
 {
     return response()->json(['size' => round(Object::inMissionControl()->sum('size') / 1000000000, 1) . ' GB', 'images' => Object::where('type', MissionControlType::Image)->count(), 'videos' => Object::where('type', MissionControlType::Video)->count(), 'documents' => Object::where('type', MissionControlType::Document)->count()]);
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $this->object->putToCloud();
     $this->object->deleteFromTemporary();
     $this->object->save();
 }
Пример #14
0
 public function addToMissionControl()
 {
     $this->setThumbnails();
     return Object::create(array('user_id' => \Auth::id(), 'type' => MissionControlType::GIF, 'size' => $this->fileinfo['size'], 'filetype' => $this->fileinfo['filetype'], 'mimetype' => $this->fileinfo['mime'], 'original_name' => $this->fileinfo['original_name'], 'filename' => $this->fileinfo['filename'], 'thumb_filename' => $this->getThumbnail(), 'has_temporary_file' => true, 'has_temporary_thumbs' => true, 'cryptographic_hash' => $this->getCryptographicHash(), 'dimension_width' => $this->getDimensions('width'), 'dimension_height' => $this->getDimensions('height'), 'duration' => $this->getLength(), 'status' => ObjectPublicationStatus::NewStatus));
 }
Пример #15
0
 public function addToMissionControl()
 {
     $this->setThumbnails();
     return Object::create(array('user_id' => \Auth::id(), 'type' => MissionControlType::Image, 'size' => $this->fileinfo['size'], 'filetype' => $this->fileinfo['filetype'], 'mimetype' => $this->fileinfo['mime'], 'original_name' => $this->fileinfo['original_name'], 'filename' => $this->fileinfo['filename'], 'thumb_filename' => $this->fileinfo['filename'], 'has_temporary_file' => true, 'has_temporary_thumbs' => true, 'cryptographic_hash' => $this->getCryptographicHash(), 'dimension_width' => $this->getDimensions('width'), 'dimension_height' => $this->getDimensions('height'), 'coord_lat' => $this->exif->latitude(), 'coord_lng' => $this->exif->longitude(), 'camera_manufacturer' => $this->exif->cameraMake(), 'camera_model' => $this->exif->cameraModel(), 'exposure' => $this->exif->exposure(), 'aperture' => $this->exif->aperture(), 'ISO' => $this->exif->iso(), 'originated_at' => $this->exif->datetime(), 'originated_at_specificity' => !is_null($this->exif->datetime()) ? DateSpecificity::Datetime : null, 'status' => ObjectPublicationStatus::NewStatus));
 }
 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);
 }
 public function get($year, $month)
 {
     $newsSummary = Object::where('subtype', MissionControlSubtype::NewsSummary)->whereRaw('YEAR(originated_at) = :year WHERE MONTH(originated_at) = :month', ['year' => $year, 'month' => $month])->firstOrFail();
     return view('newsSummary', ['newsSummary' => $newsSummary, 'year' => $year, 'month' => Carbon::createFromFormat($month, 'm')->format('F')]);
 }
Пример #19
0
 public function addToMissionControl()
 {
     $this->setThumbnails();
     return Object::create(array('user_id' => \Auth::id(), 'type' => MissionControlType::Document, 'size' => $this->fileinfo['size'], 'filetype' => $this->fileinfo['filetype'], 'mimetype' => $this->fileinfo['mime'], 'original_name' => $this->fileinfo['original_name'], 'filename' => $this->fileinfo['filename'], 'thumb_filename' => $this->getThumbnail(), 'has_temporary_file' => true, 'has_temporary_thumbs' => $this->fileinfo['filetype'] == 'pdf' && $this->fileinfo['mime'] == 'application/pdf', 'cryptographic_hash' => $this->getCryptographicHash(), 'length' => $this->getPageCount(), 'status' => ObjectPublicationStatus::NewStatus));
 }
Пример #20
0
 public function addToMissionControl()
 {
     return Object::create(array('user_id' => \Auth::id(), 'type' => MissionControlType::Audio, 'size' => $this->fileinfo['size'], 'filetype' => $this->fileinfo['filetype'], 'mimetype' => $this->fileinfo['mime'], 'original_name' => $this->fileinfo['original_name'], 'filename' => $this->fileinfo['filename'], 'has_temporary_file' => true, 'cryptographic_hash' => $this->getCryptographicHash(), 'duration' => $this->getLength(), 'status' => ObjectPublicationStatus::NewStatus));
 }
 public function show()
 {
     JavaScript::put(['tags' => Tag::all(), 'missions' => Mission::with('featuredImage')->get(), 'publishers' => Publisher::all()]);
     return view('missionControl.create', ['recentUploads' => Object::inMissionControl()->orderBy('created_at', 'desc')->take(10)->get()]);
 }