public function removeActivity($id)
    {
        /** @var Activity $activity */
        $activity = $this->em
            ->getRepository('CampaignChainCoreBundle:Activity')
            ->find($id);

        if (!$activity) {
            throw new \Exception(
                'No activity found for id '.$id
            );
        }

        if (!$this->isRemovable($activity)) {
            throw new \LogicException(
                'Deletion of activities is not possible when status is set to closed or there are scheduled reports'
            );
        }

        //Put all belonging operations in an ArrayCollection
        $operations = new ArrayCollection();
        foreach ($activity->getOperations() as $op) {
            $operations->add($op);
        }
        //Set Activity Id of the operations to null and remove the belonging locations
        foreach ($operations as $op) {
            if ($activity->getOperations()->contains($op)) {
                $op->setActivity(null);
                foreach ($op->getLocations() as $opLocation) {
                    $this->em->remove($opLocation);
                    $this->em->flush();
                }
                //Delete the module specific operation i.e. "operation_twitter_status"
                $operationServices = $op->getOperationModule()->getServices();
                if (isset($operationServices['operation'])) {
                    $opService = $this->container->get($operationServices['operation']);
                    $opService->removeOperation($op->getId());
                }
                //Delete the operation from the operation table
                $this->em->remove($op);
            }
        }
        $this->em->flush();
        //Delete the activity
        $this->em->remove($activity);
        $this->em->flush();
    }