/** * Determine all create table statements which create the sys_file* tables * * @return array */ protected function getRequiredUpdates() { $requiredUpdates = array(); $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('core') . 'ext_tables.sql'); $FDfile = $this->installerSql->getFieldDefinitions_fileContent($fileContent); $FDdb = $this->installerSql->getFieldDefinitions_database(TYPO3_db); $diff = $this->installerSql->getDatabaseExtra($FDfile, $FDdb); $update_statements = $this->installerSql->getUpdateSuggestions($diff); foreach ((array) $update_statements['create_table'] as $string) { if (preg_match('/^CREATE TABLE sys_file($|_)?/', $string)) { $requiredUpdates[] = $string; } } return $requiredUpdates; }
/** * @test */ public function getFieldDefinitionsFileContentHandlesMultipleWhitespacesInFieldDefinitions() { $subject = new SqlSchemaMigrationService(); // Multiple whitespaces and tabs in field definition $inputString = 'CREATE table atable (' . LF . 'aFieldName int(11)' . TAB . TAB . TAB . 'unsigned DEFAULT \'0\'' . LF . ');'; $result = $subject->getFieldDefinitions_fileContent($inputString); $this->assertEquals(array('atable' => array('fields' => array('aFieldName' => 'int(11) unsigned default \'0\''), 'extra' => array('COLLATE' => ''))), $result); }
/** * Gets the sql data dump for a specific sql file (for example ext_tables.sql) * * @param string $sqlFile * @return string */ protected function getSqlDataDumpForFile($sqlFile) { $sqlData = ''; if (file_exists($sqlFile)) { $sqlContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($sqlFile); $fieldDefinitions = $this->installToolSqlParser->getFieldDefinitions_fileContent($sqlContent); $sqlData = $this->databaseUtility->dumpStaticTables($fieldDefinitions); } return $sqlData; }
/** * Gets the sql data dump for a specific sql file (for example ext_tables.sql) * * @param string $sqlFile * @return string */ protected function getSqlDataDumpForFile($sqlFile) { $sqlData = ''; if (file_exists($sqlFile)) { $sqlContent = file_get_contents($sqlFile); $fieldDefinitions = $this->installToolSqlParser->getFieldDefinitions_fileContent($sqlContent); $sqlData = $this->databaseUtility->dumpStaticTables($fieldDefinitions); } return $sqlData; }
/** * Gets all create, add and change queries from core/ext_tables.sql * * @return array */ protected function getUpdateStatements() { $updateStatements = array(); // Get all necessary statements for ext_tables.sql file $rawDefinitions = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('core') . '/ext_tables.sql'); $fieldDefinitionsFromFile = $this->installToolSqlParser->getFieldDefinitions_fileContent($rawDefinitions); if (count($fieldDefinitionsFromFile)) { $fieldDefinitionsFromCurrentDatabase = $this->installToolSqlParser->getFieldDefinitions_database(); $diff = $this->installToolSqlParser->getDatabaseExtra($fieldDefinitionsFromFile, $fieldDefinitionsFromCurrentDatabase); $updateStatements = $this->installToolSqlParser->getUpdateSuggestions($diff); } return $updateStatements; }
/** * Gets the defined field definitions from the ext_tables.sql files. * * @return array The accordant definitions */ protected function getDefinedFieldDefinitions() { $content = ''; $cacheTables = ''; if (class_exists('t3lib_cache') && method_exists(t3lib_cache, 'getDatabaseTableDefinitions')) { $cacheTables = \TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions(); } if (method_exists($this->install, 'getFieldDefinitions_fileContent')) { $content = $this->install->getFieldDefinitions_fileContent(implode(chr(10), $this->getAllRawStructureDefinitions()) . $cacheTables); } else { $content = $this->install->getFieldDefinitions_sqlContent(implode(chr(10), $this->getAllRawStructureDefinitions()) . $cacheTables); } return $content; }
/** * Parse and analyze given SQL string * * @param $sql * @return void */ protected function parseAndAnalyzeSql($sql) { $parsedSql = $this->installerSql->getFieldDefinitions_fileContent($sql); $this->analyzeFields($parsedSql); }