Uploaded image for project: 'Ibexa IBX'
  1. Ibexa IBX
  2. IBX-929

Function deleteLocation throw errors

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Medium Medium
    • Customer request, 3.3.7
    • 3.3.6
    • None

    Description

      When we try to use Function deleteLocation then throw errors and not correctly clear SOLR - still visible this content but it's not accessibly

       
      Steps to reproduce

      1. Install clean Ibexa DXP 3.3
      2. Create article
      3. create Command and run php bin/console app:delete-location articleLocationId
      <?php
      
      namespace App\Command;
      
      use Exception;
      use eZ\Publish\API\Repository\Exceptions\NotFoundException;
      use eZ\Publish\API\Repository\LocationService;
      use eZ\Publish\API\Repository\Repository;
      use Symfony\Component\Console\Command\Command;
      use Symfony\Component\Console\Input\InputArgument;
      use Symfony\Component\Console\Input\InputInterface;
      use Symfony\Component\Console\Output\OutputInterface;
      use Symfony\Component\Console\Style\SymfonyStyle;
      
      class DeleteLocationCommand extends Command
      {
          protected static $defaultName = 'app:delete-location';
          protected static $defaultDescription = 'Command to delete a location by location id';
          /**
           * @var \eZ\Publish\API\Repository\LocationService
           */
          private $locationService;
          /**
           * @var Repository
           */
          private $repository;
      
          public function __construct(
              LocationService $locationService,
              Repository $repository
          )
          {
              parent::__construct();
              $this->locationService = $locationService;
              $this->repository = $repository;
          }
      
          protected function configure(): void
          {
              $this
                  ->addArgument('locationId', InputArgument::REQUIRED, 'Location ID to delete')
              ;
          }
      
          protected function execute(InputInterface $input, OutputInterface $output): int
          {
              $io = new SymfonyStyle($input, $output);
              $locationId = $input->getArgument('locationId');
      
              $result = $this->repository->sudo(function () use ($locationId, $io) {
                  try {
                      $location = $this->locationService->loadLocation($locationId);
                  } catch (NotFoundException $e) {
                      $io->error($e->getMessage());
                      return Command::FAILURE;
                  }
      
                  $this->repository->beginTransaction();
                  try {
                      $this->locationService->deleteLocation($location);
                      $this->repository->commit();
                  } catch (Exception $e) {
                      $this->repository->rollback();
                      $io->error($e->getMessage());
                      $io->error($e->getFile() . '-- #' . $e->getLine());
                      $io->comment($e->getTraceAsString());
                      return Command::FAILURE;
                  }
      
                  return Command::SUCCESS;
              });
      
              return $result;
          }
      }
      
      

      Result

       

      Expected result

      Location delete without any errors

      Designs

        Attachments

          Activity

            People

              Unassigned Unassigned
              mateusz.debinski@ibexa.co Mateusz Dębiński
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: