Project

General

Profile

Feature #23051 » 14937_caching_core.diff

Administrator Admin, 2010-07-17 16:20

View differences:

t3lib/class.t3lib_sqlparser.php (working copy)
return $query;
}
/**
* Checks if the submitted feature index contains a default value definition and the default value
*
* @param array $featureIndex A feature index as produced by parseFieldDef()
* @return boolean
* @see t3lib_sqlparser::parseFieldDef()
*/
public function checkEmptyDefaultValue($featureIndex) {
if (is_array($featureIndex['DEFAULT']['value'])) {
if (!is_numeric($featureIndex['DEFAULT']['value'][0]) && empty($featureIndex['DEFAULT']['value'][0])) {
return TRUE;
} else {
return FALSE;
}
}
return TRUE;
}
......
/**************************************
*
* Compiling queries, helper functions for parts of queries
t3lib/class.t3lib_db.php (working copy)
// Default character set, applies unless character set or collation are explicitely set
var $default_charset = 'utf8';
public $cache_autoIncFields = array(); // parsed SQL from standard DB dump file
public $cache_fieldType = array(); // field types for tables/fields
public $cache_primaryKeys = array(); // primary keys
/**
* SQL parser
*
* @var tx_dbal_sqlengine
*/
protected $SQLparser;
/**
* Installer
*
* @var t3lib_install
*/
protected $Installer;
/**
* Default constructor.
*/
public function __construct() {
// Set SQL parser object for internal use:
$this->SQLparser = t3lib_div::makeInstance('t3lib_sqlparser');
$this->Installer = t3lib_div::makeInstance('t3lib_install');
$this->initInternalVariables();
}
/**
* Setting internal variables.
*
* @return void
*/
protected function initInternalVariables() {
$this->cacheFieldInfo();
}
/**
* Clears the cached field information file.
*
* @return void
*/
public function clearCachedFieldInfo() {
if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) {
unlink(PATH_typo3conf . 'temp_fieldInfo.php');
}
}
/**
* Caches the field information.
*
* @return void
*/
public function cacheFieldInfo() {
$extSQL = '';
$parsedExtSQL = array();
// try to fetch cached file first
// file is removed when admin_query() is called
if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) {
$fdata = unserialize(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php'));
$this->cache_autoIncFields = $fdata['incFields'];
$this->cache_fieldType = $fdata['fieldTypes'];
$this->cache_primaryKeys = $fdata['primaryKeys'];
} else {
// handle stddb.sql, parse and analyze
$extSQL = t3lib_div::getUrl(PATH_site . 't3lib/stddb/tables.sql');
$parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL);
$this->analyzeFields($parsedExtSQL);
// loop over all installed extensions
foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $ext => $v) {
if (!is_array($v) || !isset($v['ext_tables.sql'])) {
continue;
}
// fetch db dump (if any) and parse it, then analyze
$extSQL = t3lib_div::getUrl($v['ext_tables.sql']);
$parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL);
$this->analyzeFields($parsedExtSQL);
}
$cachedFieldInfo = array(
'incFields' => $this->cache_autoIncFields,
'fieldTypes' => $this->cache_fieldType,
'primaryKeys' => $this->cache_primaryKeys
);
$cachedFieldInfo = serialize($this->mapCachedFieldInfo($cachedFieldInfo));
// write serialized content to file
t3lib_div::writeFile(PATH_typo3conf . 'temp_fieldInfo.php', $cachedFieldInfo);
if (strcmp(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php'), $cachedFieldInfo)) {
die('typo3temp/temp_incfields.php was NOT updated properly (written content didn\'t match file content) - maybe write access problem?');
}
}
}
/**
* Analyzes fields and adds the extracted information to the field type, auto increment and
* primary key info caches.
*
* @param array $parsedExtSQL The output produced by t3lib_install::getFieldDefinitions_fileContent()
* @return void
* @see t3lib_install::getFieldDefinitions_fileContent()
*/
protected function analyzeFields($parsedExtSQL) {
foreach ($parsedExtSQL as $table => $tdef) {
if (is_array($tdef['fields'])) {
foreach ($tdef['fields'] as $field => $fdef) {
$fdef = $this->SQLparser->parseFieldDef($fdef);
$this->cache_fieldType[$table][$field]['type'] = $fdef['fieldType'];
$this->cache_fieldType[$table][$field]['metaType'] = $this->MySQLMetaType($fdef['fieldType']);
$this->cache_fieldType[$table][$field]['notnull'] = (isset($fdef['featureIndex']['NOTNULL']) && !$this->SQLparser->checkEmptyDefaultValue($fdef['featureIndex'])) ? 1 : 0;
if (isset($fdef['featureIndex']['DEFAULT'])) {
$default = $fdef['featureIndex']['DEFAULT']['value'][0];
if (isset($fdef['featureIndex']['DEFAULT']['value'][1])) {
$default = $fdef['featureIndex']['DEFAULT']['value'][1] . $default . $fdef['featureIndex']['DEFAULT']['value'][1];
}
$this->cache_fieldType[$table][$field]['default'] = $default;
}
if (isset($fdef['featureIndex']['AUTO_INCREMENT'])) {
$this->cache_autoIncFields[$table] = $field;
}
if (isset($tdef['keys']['PRIMARY'])) {
$this->cache_primaryKeys[$table] = substr($tdef['keys']['PRIMARY'], 13, -1);
}
}
}
}
}
/**
* This function builds all definitions for mapped tables and fields
* This method is overriden in DBAL.
* @see cacheFieldInfo()
*/
protected function mapCachedFieldInfo($fieldInfo) {
return $fieldInfo;
}
/************************************
*
* Query execution
......
}
/**
* Return MetaType for native MySQL field type
*
* @param string native type as reported as in mysqldump files
* @return string Meta type (currenly ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype)
*/
public function MySQLMetaType($t) {
switch (strtoupper($t)) {
case 'STRING':
case 'CHAR':
case 'VARCHAR':
case 'TINYBLOB':
case 'TINYTEXT':
case 'ENUM':
case 'SET': return 'C';
case 'TEXT':
case 'LONGTEXT':
case 'MEDIUMTEXT': return 'XL';
case 'IMAGE':
case 'LONGBLOB':
case 'BLOB':
case 'MEDIUMBLOB': return 'B';
case 'YEAR':
case 'DATE': return 'D';
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP': return 'T';
case 'FLOAT':
case 'DOUBLE': return 'F';
case 'INT':
case 'INTEGER':
case 'TINYINT':
case 'SMALLINT':
case 'MEDIUMINT':
case 'BIGINT': return 'I8'; // we always return I8 to be on the safe side. Under some circumstances the fields are to small otherwise...
default: return 'N';
}
}
/**
* Escaping values for SQL LIKE statements.
*
* @param string Input string
typo3/tce_db.php (working copy)
// Clearing cache:
$this->tce->clear_cacheCmd($this->cacheCmd);
// Clearing table/field type cache
$GLOBALS['TYPO3_DB']->clearCachedFieldInfo();
// Update page tree?
if ($this->uPT && (isset($this->data['pages'])||isset($this->cmd['pages']))) {
t3lib_BEfunc::setUpdateSignal('updatePageTree');
(3-3/5)