/** * @param string $id * @param SnapshotSource $snapshotSource * @param AggregationService $aggregationService * @return array */ public function removeSnapshotAction($id, SnapshotSource $snapshotSource, AggregationService $aggregationService) { /** * @var Snapshot $snapshot * @var Aggregation $aggregation */ $snapshot = $snapshotSource->findByPK($id); if (empty($snapshot)) { throw new NotFoundException(); } if (!$snapshot->stored()) { throw new ForbiddenException(); } $aggregation = $aggregationService->getSource()->findBySnapshot($snapshot); if (empty($aggregation)) { throw new NotFoundException(); } $this->authorize('remove', compact('aggregation', 'snapshot')); $aggregationService->deleteSnapshots($aggregation, 1); $aggregationService->getSource()->save($aggregation); $snapshotSource->delete($snapshot); $uri = $this->vault->uri('snapshots:edit', ['id' => $aggregation->id]); if ($this->input->isAjax()) { return ['status' => 200, 'message' => $this->say('Snapshot deleted.'), 'action' => ['redirect' => $uri]]; } else { return $this->responses->redirect($uri); } }