* @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 CategoryToAttributeOrphans extends AbstractAction { /** * @return int * @throws ContainerExceptionInterface * @throws DoctrineDriverException * @throws DoctrineException * @throws NotFoundExceptionInterface */ public function getAffectedRows(): int { $oQB = $this->getBaseQuery('c2a'); $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('c2a'), 'c2a.oxid', 'oxcategory2attribute', 'D3_CFG_CLRTMP_ASSIGNCAT2ATTRIB_SUCC' ); } /** * @param string $tableAlias * * @return QueryBuilder * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ protected function getBaseQuery(string $tableAlias): QueryBuilder { $oQB = $this->getQueryBuilder(); $oQB->from('oxcategory2attribute', $tableAlias) ->leftJoin($tableAlias, 'oxcategories', 'oc', $oQB->expr()->eq($tableAlias.'.oxobjectid', 'oc.oxid')) ->leftJoin($tableAlias, 'oxattribute', 'oa', $oQB->expr()->eq($tableAlias.'.oxattrid', 'oa.oxid')) ->where( $oQB->expr()->or( $oQB->expr()->isNull('oc.oxid'), $oQB->expr()->isNull('oa.oxid') ) ); return $oQB; } }