* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ declare(strict_types=1); namespace PrestaShop\PrestaShop\Adapter\Title\CommandHandler; use Gender; use PrestaShop\PrestaShop\Core\Domain\Title\Command\BulkDeleteTitleCommand; use PrestaShop\PrestaShop\Core\Domain\Title\CommandHandler\BulkDeleteTitleHandlerInterface; use PrestaShop\PrestaShop\Core\Domain\Title\Exception\DeleteTitleException; use PrestaShop\PrestaShop\Core\Domain\Title\Exception\TitleNotFoundException; /** * Handles command that bulk delete titles */ class BulkDeleteTitleHandler implements BulkDeleteTitleHandlerInterface { /** * {@inheritdoc} */ public function handle(BulkDeleteTitleCommand $command): void { foreach ($command->getTitleIds() as $titleId) { $title = new Gender($titleId->getValue()); if (0 >= $title->id) { throw new TitleNotFoundException(sprintf('Unable to find title with id "%d" for deletion', $titleId->getValue())); } if (!$title->delete()) { throw DeleteTitleException::createBulkDeleteFailure($titleId); } } } }