We can try:
$cmsBlock = $this->blockInterfaceFactory->create();
$copyrightBlock = $cmsBlock->load('copy-right','identifier');
//And then check
if (!$copyrightBlock->getId()) {
......
}
Take a look: vendor/magento/module-cms/Setup/InstallData.php
$footerLinksBlock = $this->createPage()->load('footer_links', 'identifier');
[EDIT]
Seem that load
method will be deprecated in the future.
[EDIT - Regarding load
method being marked deprecated]
The Magento\Cms\Model\BlockRepository::save()
method does throw an \Exception
(type: Magento\Framework\Exception\CouldNotSaveException
), so you could wrap it in a try/catch to skip over blocks that already exist.
try {
$this->blockRepository->save($cmsBlock);
} catch (\Exception $e) {
// Do nothing, block likely already exists
}