/** * Handle the report maintenance command. * * @param \CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand $command * * @return \CachetHQ\Cachet\Models\Incident */ public function handle(ReportMaintenanceCommand $command) { $scheduledAt = $this->dates->createNormalized('d/m/Y H:i', $command->timestamp); $maintenanceEvent = Incident::create(['name' => $command->name, 'message' => $command->message, 'scheduled_at' => $scheduledAt, 'status' => 0, 'visible' => 1]); event(new MaintenanceWasScheduledEvent($maintenanceEvent)); return $maintenanceEvent; }
/** * 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; }
/** * 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; }
/** * Updates the given incident. * * @param \CachetHQ\Cachet\Models\Incident $schedule * @param \CachetHQ\Cachet\Dates\DateFactory $dates * * @return \Illuminate\Http\RedirectResponse */ public function editScheduleAction(Incident $schedule, DateFactory $dates) { $scheduleData = Binput::get('incident'); // Parse the schedule date. $scheduledAt = $dates->createNormalized('d/m/Y H:i', $scheduleData['scheduled_at']); if ($scheduledAt->isPast()) { $messageBag = new MessageBag(); $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied'])); return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withErrors($messageBag); } $scheduleData['scheduled_at'] = $scheduledAt; // Bypass the incident.status field. $scheduleData['status'] = 0; try { $schedule->update($scheduleData); } catch (ValidationException $e) { return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))->withErrors($e->getMessageBag()); } return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success'))); }