vendor/alnv/catalog-manager/library/alnv/ReviseRelatedTables.php line 42

Open in your IDE?
  1. <?php
  2. namespace CatalogManager;
  3. class ReviseRelatedTables extends \Controller {
  4.     private $arrErrorTables = [];
  5.     public function __construct() {
  6.         $this->import('Database');
  7.     }
  8.     public function reviseCatalogTables($strTable$strPTable$arrCTables) {
  9.         $objCatalogDb $this->Database->prepare('SELECT id FROM tl_catalog WHERE tablename = ?')->execute($strTable);
  10.         if (!$objCatalogDb->count()) {
  11.             return false;
  12.         }
  13.         if ($strPTable && $this->Database->TableExists($strPTable)) {
  14.             if (isset($GLOBALS['TL_DCA'][ $strTable ]['config']['dynamicPtable']) && $GLOBALS['TL_DCA'][$strTable]['config']['dynamicPtable']) {
  15.                 $objStmt $this->Database->prepare(sprintf(' SELECT * FROM %s WHERE ptable=? AND NOT EXISTS( SELECT * FROM %s WHERE %s.pid = %s.id )'$strTable$strPTable$strTable$strPTable))->execute($strPTable);
  16.             } else {
  17.                 $objStmt $this->Database->prepare(sprintf('SELECT * FROM %s WHERE NOT EXISTS( SELECT * FROM %s WHERE %s.pid = %s.id )'$strTable$strPTable$strTable$strPTable))->execute();
  18.             }
  19.             if ($objStmt->count() > 0) {
  20.                 $this->arrErrorTables[] = $strPTable;
  21.                 return true;
  22.             }
  23.         }
  24.         if (!empty($arrCTables) && is_array($arrCTables)) {
  25.             foreach ($arrCTables as $v) {
  26.                 if ($v && $this->Database->TableExists($v)) {
  27.                     if (!isset($GLOBALS['TL_DCA'][$v])) {
  28.                         $objLoader = new \DcaLoader$strTable );
  29.                         $objLoader->load(false);
  30.                     }
  31.                     if (!($GLOBALS['TL_DCA'][$v]??'')) {
  32.                         continue;
  33.                     }
  34.                     if (isset($GLOBALS['TL_DCA'][$v]['config']['dynamicPtable']) && $GLOBALS['TL_DCA'][$v]['config']['dynamicPtable']) {
  35.                         $objStmt $this->Database->prepare(sprintf(' SELECT * FROM %s  WHERE ptable=? AND NOT EXISTS( SELECT * FROM %s WHERE %s.pid = %s.id)'$v$strTable$v$strTable))->execute($v);
  36.                     } else {
  37.                         $objStmt $this->Database->prepare(sprintf('SELECT * FROM %s WHERE NOT EXISTS( SELECT * FROM %s WHERE %s.pid = %s.id)'$v$strTable$v$strTable))->execute();
  38.                     }
  39.                     if ($objStmt->count() > 0) {
  40.                         $this->arrErrorTables[] = $v;
  41.                         return true;
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.         return false;
  47.     }
  48.     public function getErrorTables() {
  49.         return $this->arrErrorTables;
  50.     }
  51. }