* @link http://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 ActionsToArticleOrphans extends AbstractAction { /** * @return int * @throws ContainerExceptionInterface * @throws DoctrineDriverException * @throws DoctrineException * @throws NotFoundExceptionInterface */ public function getAffectedRows(): int { $oQB = $this->getBaseQuery('a2a'); $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('a2a'), 'a2a.oxid', 'oxactions2article', 'D3_CFG_CLRTMP_ASSIGNACT2ART_SUCC' ); } /** * @param string $tableAlias * * @return QueryBuilder * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ protected function getBaseQuery(string $tableAlias): QueryBuilder { $oQB = $this->getQueryBuilder(); $oQB->from('oxactions2article', $tableAlias) ->leftJoin($tableAlias, 'oxactions', 'oa', $oQB->expr()->eq($tableAlias.'.oxactionid', 'oa.oxid')) ->leftJoin($tableAlias, 'oxarticles', 'oar', $oQB->expr()->eq($tableAlias.'.oxartid', 'oar.oxid')) ->where( $oQB->expr()->or( $oQB->expr()->isNull('oa.oxid'), $oQB->expr()->isNull('oar.oxid') ) ); return $oQB; } }