Feature #83846
Updated by John Miller almost 7 years ago
It would be nice to let developers determine which characters they want included in naming their database tables and or fields. Advantanges: ---------------------------------------- # It increases the amount of freedom a TYPO3 developer enjoys in the database creation process since one is now able to define his own rules as opposed to being construed to traditional characters [a-z0-9_] # Developer is subsequently able to get the most out of working with the database. # Importance of working with own characters in the database also increases innovation. Reasons (Examples) ---------------------------------------- # Simple reasons: Certain people just like to work that way - varying reasons. # Complex reasons: Use in partialy or fuly automated Scripts or could even be in inteligent systems where tables are arrange in a systematic fashion and codes are used to determine which tables are accesed next and which ones belong under which tables and so on. Easy to do ---------------------------------------- To allow users to determine own rules in naming conventions in TYPO3 is really easy. As of version 9.1, only 3 changes to code would need to take place. *First:* In LocalConfiguration file under DB definition block where database name, pasword, etc is provided, an additional key-value pair could be introduced as an option to carry the regex definition. Example block would look as follows <pre><code class="php"> 'DB' => [ 'Connections' => [ 'Default' => [ 'driver' => 'mysqli', 'dbname' => 'typo3_database', 'password' => 'typo3', 'host' => '127.0.0.1', 'port' => 3306, 'user' => 'typo3', 'socket' => '' 'charset' => 'utf-8', 'regex' => '[a-z0-9$_][\w$]*' ], ], ], </code></pre> *Second:* In the @\TYPO3\CMS\Core\Database\Schema\Parser\Lexer@ class inside @getCatchablePatterns()@ function, the unquoted identifiers pattern @'[a-z0-9$_][\w$]*'@ would be changed to @(string)$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['dbname'] ?? '[a-z0-9$_][\w$]*', // unquoted identifiers@. This way, if the regex key is absent in the database definition block, the statement has a fallback to what is commonly used. *Finally:* In the @\TYPO3\CMS\Core\Database\Schema\SchemaMigrator@ class inside @importStaticData()@ function, the pattern @'/^INSERT\s+INTO\s+`?(\w+)`?(.*)/i'@ would be changed to @'/^INSERT\s+INTO\s+`?('. ((string)$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'][ConnectionPool::DEFAULT_CONNECTION_NAME]['dbname'] ?? '\w+') .')`?(.*)/i'@ so that the pattern matches that in Lexer file. That's all that's needed. In fact, the above two lines could be copied and pasted 'as is' in their respective files. Namespace will need to be added in Lexer file since it doesn't already have it. Only takes less than two minutes, then state in the manual that if one want to define own naming rules, one has to add a 'regex' key in the DB definition block and provide pattern. That's it. No changes to Doctrine will need to be done. Effects of changes ---------------------------------------- The changes only affect patters only. First change will affect ext_tables.sql entries. Second change will affect ext_tables_static+tt.sql file entries - both based on supplied pattern. Tests ---------------------------------------- I tried the on version 9 LTS. Changes work perfectly. No additional changes required. Could such a simple change be incorporated in upcoming versions?