public function deleteResource(PersistentResource $resource, $unpublishResource = true)
    {
        $this->initialize();

        $collectionName = $resource->getCollectionName();

        $result = $this->resourceRepository->findBySha1AndCollectionName($resource->getSha1(), $collectionName);
        if (count($result) > 1) {
            $this->logger->debug(sprintf('Not removing storage data of resource %s (%s) because it is still in use by %s other PersistentResource object(s).', $resource->getFilename(), $resource->getSha1(), count($result) - 1));
        } else {
            if (!isset($this->collections[$collectionName])) {
                $this->logger->warning(sprintf('Could not remove storage data of resource %s (%s) because it refers to the unknown collection "%s".', $resource->getFilename(), $resource->getSha1(), $collectionName), LogEnvironment::fromMethodName(__METHOD__));

                return false;
            }
            $storage = $this->collections[$collectionName]->getStorage();
            if (!$storage instanceof WritableStorageInterface) {
                $this->logger->warning(sprintf('Could not remove storage data of resource %s (%s) because it its collection "%s" is read-only.', $resource->getFilename(), $resource->getSha1(), $collectionName), LogEnvironment::fromMethodName(__METHOD__));

                return false;
            }
            try {
                $storage->deleteResource($resource);
            } catch (\Exception $exception) {
                $this->logger->warning(sprintf('Could not remove storage data of resource %s (%s): %s.', $resource->getFilename(), $resource->getSha1(), $exception->getMessage()), LogEnvironment::fromMethodName(__METHOD__));

                return false;
            }
            if ($unpublishResource) {
                /** @var TargetInterface $target */
                $target = $this->collections[$collectionName]->getTarget();
                $target->unpublishResource($resource);
                $this->logger->debug(sprintf('Removed storage data and unpublished resource %s (%s) because it not used by any other PersistentResource object.', $resource->getFilename(), $resource->getSha1()));
            } else {
                $this->logger->debug(sprintf('Removed storage data of resource %s (%s) because it not used by any other PersistentResource object.', $resource->getFilename(), $resource->getSha1()));
            }
        }

        $resource->setDeleted();
        $this->resourceRepository->remove($resource);

        return true;
    }