* @link https://www.oxidmodule.com */ declare(strict_types=1); namespace D3\ModCfg\Application\Model\Maintenance\Actions; use Doctrine\DBAL\Driver\Exception as DoctrineDriverException; use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Query\QueryBuilder; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; class DeliveryToDeliverySetOrphans extends AbstractAction { /** * @return int * @throws ContainerExceptionInterface * @throws DoctrineDriverException * @throws DoctrineException * @throws NotFoundExceptionInterface */ public function getAffectedRows(): int { $oQB = $this->getBaseQuery('d2ds'); $oQB->select('count(*)') ->setMaxResults(1); return (int) $oQB->execute()->fetchOne(); } /** * @throws ContainerExceptionInterface * @throws DoctrineDriverException * @throws DoctrineException * @throws NotFoundExceptionInterface */ public function fixIt(): void { $this->fixAction( $this->getBaseQuery('d2ds'), 'd2ds.oxid', 'oxdel2delset', 'D3_CFG_CLRTMP_ASSIGNDEL2DELSET_SUCC' ); } /** * @param string $tableAlias * * @return QueryBuilder * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ protected function getBaseQuery(string $tableAlias): QueryBuilder { $oQB = $this->getQueryBuilder(); $oQB->from('oxdel2delset', $tableAlias) ->leftJoin($tableAlias, 'oxdelivery', 'od', $oQB->expr()->eq($tableAlias.'.oxdelid', 'od.oxid')) ->leftJoin($tableAlias, 'oxdeliveryset', 'ods', $oQB->expr()->eq($tableAlias.'.oxdelsetid', 'ods.oxid')) ->where( $oQB->expr()->or( $oQB->expr()->isNull('od.oxid'), $oQB->expr()->isNull('ods.oxid') ) ); return $oQB; } }