Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Only create one DcaExtractor instance per table (see #7324)
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 24, 2014
1 parent ef15be8 commit a5d82a8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 13 deletions.
12 changes: 6 additions & 6 deletions contao/classes/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ protected function extractThemeFiles($arrFiles, $arrDbFields)
$this->loadDataContainer($table);

// Get the order fields
$objDcaExtractor = new \DcaExtractor($table);
$objDcaExtractor = \DcaExtractor::getInstance($table);
$arrOrder = $objDcaExtractor->getOrderFields();

// Loop through the rows
Expand Down Expand Up @@ -722,7 +722,7 @@ protected function addTableTlTheme(\DOMDocument $xml, \DOMElement $tables, \Data
$this->loadDataContainer('tl_theme');

// Get the order fields
$objDcaExtractor = new \DcaExtractor('tl_theme');
$objDcaExtractor = \DcaExtractor::getInstance('tl_theme');
$arrOrder = $objDcaExtractor->getOrderFields();

// Add the row
Expand All @@ -747,7 +747,7 @@ protected function addTableTlStyleSheet(\DOMDocument $xml, \DOMElement $tables,
$this->loadDataContainer('tl_style_sheet');

// Get the order fields
$objDcaExtractor = new \DcaExtractor('tl_style_sheet');
$objDcaExtractor = \DcaExtractor::getInstance('tl_style_sheet');
$arrOrder = $objDcaExtractor->getOrderFields();

// Get all style sheets
Expand All @@ -771,7 +771,7 @@ protected function addTableTlStyleSheet(\DOMDocument $xml, \DOMElement $tables,
$this->loadDataContainer('tl_style');

// Get the order fields
$objDcaExtractor = new \DcaExtractor('tl_style');
$objDcaExtractor = \DcaExtractor::getInstance('tl_style');
$arrOrder = $objDcaExtractor->getOrderFields();

// Add the child rows
Expand Down Expand Up @@ -807,7 +807,7 @@ protected function addTableTlModule(\DOMDocument $xml, \DOMElement $tables, \Dat
$this->loadDataContainer('tl_module');

// Get the order fields
$objDcaExtractor = new \DcaExtractor('tl_module');
$objDcaExtractor = \DcaExtractor::getInstance('tl_module');
$arrOrder = $objDcaExtractor->getOrderFields();

// Get all modules
Expand Down Expand Up @@ -839,7 +839,7 @@ protected function addTableTlLayout(\DOMDocument $xml, \DOMElement $tables, \Dat
$this->loadDataContainer('tl_layout');

// Get the order fields
$objDcaExtractor = new \DcaExtractor('tl_layout');
$objDcaExtractor = \DcaExtractor::getInstance('tl_layout');
$arrOrder = $objDcaExtractor->getOrderFields();

// Get all layouts
Expand Down
2 changes: 1 addition & 1 deletion contao/classes/Versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function compare()
$this->loadDataContainer($this->strTable);

// Get the order fields
$objDcaExtractor = new \DcaExtractor($this->strTable);
$objDcaExtractor = \DcaExtractor::getInstance($this->strTable);
$arrOrder = $objDcaExtractor->getOrderFields();

// Find the changed fields and highlight the changes
Expand Down
2 changes: 1 addition & 1 deletion contao/drivers/DC_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public function show()
$row = $objRow->row();

// Get the order fields
$objDcaExtractor = new \DcaExtractor($this->strTable);
$objDcaExtractor = \DcaExtractor::getInstance($this->strTable);
$arrOrder = $objDcaExtractor->getOrderFields();

// Get all fields
Expand Down
2 changes: 1 addition & 1 deletion contao/library/Contao/Automator.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public function generateDcaExtracts()
}

$strTable = substr($strFile, 0, -4);
$objExtract = new \DcaExtractor($strTable);
$objExtract = \DcaExtractor::getInstance($strTable);

if ($objExtract->isDbTable())
{
Expand Down
2 changes: 1 addition & 1 deletion contao/library/Contao/Database/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function getFromDca()
}

$strTable = substr($strFile, 0, -4);
$objExtract = new \DcaExtractor($strTable);
$objExtract = \DcaExtractor::getInstance($strTable);

if ($objExtract->isDbTable())
{
Expand Down
24 changes: 24 additions & 0 deletions contao/library/Contao/DcaExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
class DcaExtractor extends \Controller
{

/**
* Instances
* @var string
*/
protected static $arrInstances = array();

/**
* Table name
* @var string
Expand Down Expand Up @@ -122,6 +128,24 @@ public function __construct($strTable)
}


/**
* Get one object instance per table
*
* @param string $strTable The table name
*
* @return \DcaExtractor The object instance
*/
public static function getInstance($strTable)
{
if (!isset(static::$arrInstances[$strTable]))
{
static::$arrInstances[$strTable] = new static($strTable);
}

return static::$arrInstances[$strTable];
}


/**
* Return the meta data as array
*
Expand Down
2 changes: 1 addition & 1 deletion contao/library/Contao/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function __construct(\Database\Result $objResult=null)
{
$this->arrModified = array();

$objDca = new \DcaExtractor(static::$strTable);
$objDca = \DcaExtractor::getInstance(static::$strTable);
$this->arrRelations = $objDca->getRelations();

if ($objResult !== null)
Expand Down
4 changes: 2 additions & 2 deletions contao/library/Contao/Model/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class QueryBuilder
*/
public static function find(array $arrOptions)
{
$objBase = new \DcaExtractor($arrOptions['table']);
$objBase = \DcaExtractor::getInstance($arrOptions['table']);

if (!$objBase->hasRelations())
{
Expand All @@ -55,7 +55,7 @@ public static function find(array $arrOptions)
if ($arrConfig['type'] == 'hasOne' || $arrConfig['type'] == 'belongsTo')
{
++$intCount;
$objRelated = new \DcaExtractor($arrConfig['table']);
$objRelated = \DcaExtractor::getInstance($arrConfig['table']);

foreach (array_keys($objRelated->getFields()) as $strField)
{
Expand Down

0 comments on commit a5d82a8

Please sign in to comment.