コード例 #1
0
 /**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     $data = ['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible];
     // Link with the component.
     if ($command->component_id) {
         $data['component_id'] = $command->component_id;
     }
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
         $data['created_at'] = $incidentDate;
         $data['updated_at'] = $incidentDate;
     }
     // Create the incident
     $incident = Incident::create($data);
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     // Notify subscribers.
     if ($command->notify) {
         event(new IncidentWasReportedEvent($incident));
     }
     return $incident;
 }
コード例 #2
0
 /**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     if ($command->template) {
         $command->message = $this->parseIncidentTemplate($command->template, $command->template_vars);
     }
     $data = ['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible];
     // Link with the component.
     if ($command->component_id) {
         $data['component_id'] = $command->component_id;
     }
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = $this->dates->createNormalized('d/m/Y H:i', $command->incident_date);
         $data['created_at'] = $incidentDate;
         $data['updated_at'] = $incidentDate;
     }
     // Create the incident
     $incident = Incident::create($data);
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     $incident->notify = (bool) $command->notify;
     event(new IncidentWasReportedEvent($incident));
     return $incident;
 }
コード例 #3
0
ファイル: ApiController.php プロジェクト: kulado/Cachet
 /**
  * Updates a components ordering.
  *
  * @return array
  */
 public function postUpdateComponentOrder()
 {
     $componentData = Binput::get('ids');
     foreach ($componentData as $order => $componentId) {
         // Ordering should be 1-based, data comes in 0-based
         Component::find($componentId)->update(['order' => $order + 1]);
     }
     return $componentData;
 }
コード例 #4
0
 /**
  * Updates a components ordering.
  *
  * @return array
  */
 public function postUpdateComponentOrder()
 {
     $componentData = Binput::all();
     unset($componentData['component'][0]);
     // Remove random 0 index.
     foreach ($componentData['component'] as $componentId => $order) {
         $component = Component::find($componentId);
         $component->update(['order' => $order]);
     }
     return $componentData;
 }
コード例 #5
0
 /**
  * Find the status on a component.
  *
  * @param string $componentId
  *
  * @return string
  */
 protected function getComponentStatus($componentId = '')
 {
     if ('' == $componentId) {
         return 'n/a';
     }
     $statuses = trans('cachet.components.status');
     $component = Component::find($componentId);
     if ($component instanceof Component) {
         return $component->name . ': *' . $statuses[$component->status] . '*';
     }
     return 'n/a';
 }
コード例 #6
0
 /**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     $incident = Incident::create(['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible, 'component' => $command->component_id]);
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     // Notify subscribers.
     if ($command->notify) {
         event(new IncidentWasReportedEvent($incident));
     }
     return $incident;
 }
コード例 #7
0
ファイル: ApiController.php プロジェクト: aksalj/Cachet
 /**
  * Updates a components ordering.
  *
  * @return array
  */
 public function postUpdateComponentOrder()
 {
     $componentData = Binput::get('ids');
     foreach ($componentData as $order => $componentId) {
         try {
             $component = Component::find($componentId);
             dispatch(new UpdateComponentCommand($component, $component->name, $component->description, $component->status, $component->link, $order + 1, $component->group_id, $component->enabled));
         } catch (QueryException $e) {
             throw new BadRequestHttpException();
         }
     }
     return $this->collection(Component::query()->orderBy('order')->get());
 }
コード例 #8
0
 /**
  * Handle the update incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(UpdateIncidentCommand $command)
 {
     $incident = $command->incident;
     $incident->update($this->filterIncidentData($command));
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = $this->dates->createNormalized('d/m/Y H:i', $command->incident_date);
         $incident->update(['created_at' => $incidentDate, 'updated_at' => $incidentDate]);
     }
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     event(new IncidentWasUpdatedEvent($incident));
     return $incident;
 }
コード例 #9
0
 /**
  * Handle the update incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(UpdateIncidentCommand $command)
 {
     $incident = $command->incident;
     $incident->update($this->filterIncidentData($command));
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
         $incident->update(['created_at' => $incidentDate, 'updated_at' => $incidentDate]);
     }
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     // Notify subscribers.
     event(new IncidentWasUpdatedEvent($incident));
     return $incident;
 }
コード例 #10
0
 /**
  * Creates a new incident.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function createIncidentAction()
 {
     $incidentData = Binput::get('incident');
     $componentStatus = array_pull($incidentData, 'component_status');
     if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
         $incidentData['created_at'] = $incidentDate;
         $incidentData['updated_at'] = $incidentDate;
     } else {
         unset($incidentData['created_at']);
     }
     try {
         $incident = Incident::create($incidentData);
     } catch (ValidationException $e) {
         return Redirect::route('dashboard.incidents.add')->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))->withErrors($e->getMessageBag());
     }
     // Update the component.
     if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) {
         Component::find($incidentData['component_id'])->update(['status' => $componentStatus]);
     }
     if (array_get($incidentData, 'notify') && subscribers_enabled()) {
         event(new IncidentHasReportedEvent($incident));
     }
     return Redirect::route('dashboard.incidents.add')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success')));
 }
コード例 #11
0
 /**
  * Creates a new incident.
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function createIncidentAction()
 {
     $incidentData = Binput::get('incident');
     $componentStatus = array_pull($incidentData, 'component_status');
     if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
         $incidentData['created_at'] = $incidentDate;
         $incidentData['updated_at'] = $incidentDate;
     } else {
         unset($incidentData['created_at']);
     }
     $incident = Incident::create($incidentData);
     if (!$incident->isValid()) {
         segment_track('Dashboard', ['event' => 'Created Incident', 'success' => false]);
         return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))->with('errors', $incident->getErrors());
     }
     // Update the component.
     if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) {
         Component::find($incidentData['component_id'])->update(['status' => $componentStatus]);
     }
     segment_track('Dashboard', ['event' => 'Created Incident', 'success' => true]);
     $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success'));
     $isEnabled = (bool) Setting::get('enable_subscribers', false);
     $mailAddress = env('MAIL_ADDRESS', false);
     $mailFrom = env('MAIL_NAME', false);
     $subscribersEnabled = $isEnabled && $mailAddress && $mailFrom;
     if (array_get($incidentData, 'notify') && $subscribersEnabled) {
         event(new IncidentHasReportedEvent($incident));
     }
     return Redirect::back()->with('success', $successMsg);
 }