/**
  * @param $hash
  * @param $teaser
  * @return null|Aggregation
  */
 public function findOrCreateByHash($hash, $teaser)
 {
     /**
      * @var Aggregation $aggregation
      */
     $aggregation = $this->source->findByHash($hash);
     if (empty($aggregation)) {
         $aggregation = $this->source->create(['exception_hash' => $hash, 'exception_teaser' => $teaser]);
         $this->source->save($aggregation);
     }
     return $aggregation;
 }
 /**
  * @param AggregationService $aggregationService
  * @param AggregationSource  $aggregationSource
  * @param SnapshotSource     $snapshotSource
  * @return array
  */
 public function removeAllAction(AggregationService $aggregationService, AggregationSource $aggregationSource, SnapshotSource $snapshotSource)
 {
     $this->authorize('remove');
     foreach ($aggregationSource->find() as $aggregation) {
         $countDeleted = 0;
         if (!empty($snapshotSource->findStored($aggregation)->count())) {
             foreach ($snapshotSource->findStored($aggregation) as $snapshot) {
                 $countDeleted++;
                 $snapshotSource->delete($snapshot);
             }
         }
         if (!empty($countDeleted)) {
             $aggregationService->deleteSnapshots($aggregation, $countDeleted);
             $aggregationSource->save($aggregation);
         }
     }
     $uri = $this->vault->uri('snapshots');
     if ($this->input->isAjax()) {
         return ['status' => 200, 'message' => $this->say('Snapshot deleted.'), 'action' => ['redirect' => $uri]];
     } else {
         return $this->responses->redirect($uri);
     }
 }