Ejemplo n.º 1
0
 /**
  * Create the DCA extract cache files
  */
 public function generateDcaExtracts()
 {
     $included = array();
     $arrExtracts = array();
     // Only check the active modules (see #4541)
     foreach (\ModuleLoader::getActive() as $strModule) {
         $strDir = 'system/modules/' . $strModule . '/dca';
         if (!is_dir(TL_ROOT . '/' . $strDir)) {
             continue;
         }
         foreach (scan(TL_ROOT . '/' . $strDir) as $strFile) {
             // Ignore non PHP files and files which have been included before
             if (strncmp($strFile, '.', 1) === 0 || substr($strFile, -4) != '.php' || in_array($strFile, $included)) {
                 continue;
             }
             $strTable = substr($strFile, 0, -4);
             $objExtract = new \DcaExtractor($strTable);
             if ($objExtract->isDbTable()) {
                 $arrExtracts[$strTable] = $objExtract;
             }
             $included[] = $strFile;
         }
     }
     // Create one file per table
     foreach ($arrExtracts as $strTable => $objExtract) {
         // Create the file
         $objFile = new \File('system/cache/sql/' . $strTable . '.php', true);
         $objFile->write("<?php\n\n");
         // Meta
         $arrMeta = $objExtract->getMeta();
         $objFile->append("\$this->arrMeta = array\n(");
         $objFile->append("\t'engine' => '{$arrMeta['engine']}',");
         $objFile->append("\t'charset' => '{$arrMeta['charset']}',");
         $objFile->append(');', "\n\n");
         // Fields
         $arrFields = $objExtract->getFields();
         $objFile->append("\$this->arrFields = array\n(");
         foreach ($arrFields as $field => $sql) {
             $sql = str_replace('"', '\\"', $sql);
             $objFile->append("\t'{$field}' => \"{$sql}\",");
         }
         $objFile->append(');', "\n\n");
         // Order fields
         $arrFields = $objExtract->getOrderFields();
         $objFile->append("\$this->arrOrderFields = array\n(");
         foreach ($arrFields as $field) {
             $objFile->append("\t'{$field}',");
         }
         $objFile->append(');', "\n\n");
         // Keys
         $arrKeys = $objExtract->getKeys();
         $objFile->append("\$this->arrKeys = array\n(");
         foreach ($arrKeys as $field => $type) {
             $objFile->append("\t'{$field}' => '{$type}',");
         }
         $objFile->append(');', "\n\n");
         // Relations
         $arrRelations = $objExtract->getRelations();
         $objFile->append("\$this->arrRelations = array\n(");
         foreach ($arrRelations as $field => $config) {
             $objFile->append("\t'{$field}' => array\n\t(");
             foreach ($config as $k => $v) {
                 $objFile->append("\t\t'{$k}' => '{$v}',");
             }
             $objFile->append("\t),");
         }
         $objFile->append(');', "\n\n");
         // Set the database table flag
         $objFile->append("\$this->blnIsDbTable = true;", "\n");
         // Close the file (moves it to its final destination)
         $objFile->close();
     }
     // Add a log entry
     $this->log('Generated the DCA extracts', __METHOD__, TL_CRON);
 }
Ejemplo n.º 2
0
 /**
  * Create all extracts
  * 
  * @return array An array of DcaExtractors
  */
 public static function createAllExtracts()
 {
     $included = array();
     $arrExtracts = array();
     // Only check the active modules (see #4541)
     foreach (\Config::getInstance()->getActiveModules() as $strModule) {
         $strDir = TL_ROOT . '/system/modules/' . $strModule . '/dca';
         if (!is_dir($strDir)) {
             continue;
         }
         foreach (scan($strDir) as $strFile) {
             if (in_array($strFile, $included) || $strFile == '.htaccess') {
                 continue;
             }
             $included[] = $strFile;
             $strTable = str_replace('.php', '', $strFile);
             $objExtract = new \DcaExtractor($strTable);
             if ($objExtract->isDbTable()) {
                 $arrExtracts[$strTable] = $objExtract;
             }
         }
     }
     return $arrExtracts;
 }
Ejemplo n.º 3
0
 /**
  * Get the DCA table settings from the DCA cache
  *
  * @return array An array of DCA table settings
  */
 public function getFromDca()
 {
     $return = array();
     $included = array();
     // Ignore the internal cache
     $blnBypassCache = \Config::get('bypassCache');
     \Config::set('bypassCache', true);
     // Only check the active modules (see #4541)
     foreach (\ModuleLoader::getActive() as $strModule) {
         $strDir = 'system/modules/' . $strModule . '/dca';
         if (!is_dir(TL_ROOT . '/' . $strDir)) {
             continue;
         }
         foreach (scan(TL_ROOT . '/' . $strDir) as $strFile) {
             // Ignore non PHP files and files which have been included before
             if (substr($strFile, -4) != '.php' || in_array($strFile, $included)) {
                 continue;
             }
             $strTable = substr($strFile, 0, -4);
             $objExtract = new \DcaExtractor($strTable);
             if ($objExtract->isDbTable()) {
                 $return[$strTable] = $objExtract->getDbInstallerArray();
             }
             $included[] = $strFile;
         }
     }
     // Restore the cache settings
     \Config::set('bypassCache', $blnBypassCache);
     // HOOK: allow third-party developers to modify the array (see #6425)
     if (isset($GLOBALS['TL_HOOKS']['sqlGetFromDca']) && is_array($GLOBALS['TL_HOOKS']['sqlGetFromDca'])) {
         foreach ($GLOBALS['TL_HOOKS']['sqlGetFromDca'] as $callback) {
             $this->import($callback[0]);
             $return = $this->{$callback}[0]->{$callback}[1]($return);
         }
     }
     return $return;
 }