1010 * LICENSE.txt file that was distributed with this source code.
1111 */
1212
13- namespace Kitodo \DbDocs ;
13+ namespace Kitodo \Dlf \ Command \ DbDocs ;
1414
1515use Doctrine \DBAL \Schema \Table ;
1616use Kitodo \Dlf \Common \Helper ;
1717use ReflectionClass ;
18+ use ReflectionProperty ;
1819use TYPO3 \CMS \Core \Database \Schema \Parser \Parser ;
1920use TYPO3 \CMS \Core \Database \Schema \SqlReader ;
2021use TYPO3 \CMS \Core \Localization \LanguageService ;
2122use TYPO3 \CMS \Core \Utility \GeneralUtility ;
2223use TYPO3 \CMS \Extbase \Configuration \ConfigurationManager ;
2324use TYPO3 \CMS \Extbase \Configuration \ConfigurationManagerInterface ;
25+ use TYPO3 \CMS \Extbase \Persistence \ClassesConfiguration ;
26+ use TYPO3 \CMS \Extbase \Persistence \ClassesConfigurationFactory ;
27+ use TYPO3 \CMS \Extbase \Persistence \Generic \Mapper \DataMapFactory ;
2428use TYPO3 \CMS \Extbase \Persistence \Generic \Mapper \DataMapper ;
2529
2630/**
@@ -53,14 +57,6 @@ class Generator
5357 */
5458 protected $ configurationManager ;
5559
56- /**
57- * @param LanguageService $languageService
58- */
59- public function injectLanguageService (LanguageService $ languageService )
60- {
61- $ this ->languageService = $ languageService ;
62- }
63-
6460 /**
6561 * @param DataMapper $dataMapper
6662 */
@@ -72,7 +68,7 @@ public function injectDataMapper(DataMapper $dataMapper)
7268 /**
7369 * @param SqlReader $sqlReader
7470 */
75- public function injectSqlReader (DataMapper $ sqlReader )
71+ public function injectSqlReader (SqlReader $ sqlReader )
7672 {
7773 $ this ->sqlReader = $ sqlReader ;
7874 }
@@ -87,7 +83,7 @@ public function injectConfigurationManager(ConfigurationManager $configurationMa
8783
8884 public function __construct ()
8985 {
90-
86+ $ this -> languageService = GeneralUtility:: makeInstance (LanguageService::class);
9187 }
9288
9389 /**
@@ -125,12 +121,19 @@ public function collectTables(): array
125121 */
126122 public function getTableClassMap (): array
127123 {
128- $ frameworkConfiguration = $ this -> configurationManager -> getConfiguration (ConfigurationManagerInterface:: CONFIGURATION_TYPE_FRAMEWORK );
124+ $ dataMapFactory = GeneralUtility:: makeInstance (DataMapFactory::class );
129125
130- $ result = [];
126+ // access classes configuration through reflection, which is otherwise not available?
127+ $ reflectionProperty = new ReflectionProperty (DataMapFactory::class, 'classesConfiguration ' );
128+ $ reflectionProperty ->setAccessible (true );
129+ $ classesConfiguration = $ reflectionProperty ->getValue ($ dataMapFactory );
130+ $ reflectionProperty = new ReflectionProperty (ClassesConfiguration::class, 'configuration ' );
131+ $ reflectionProperty ->setAccessible (true );
132+ $ configuration = $ reflectionProperty ->getValue ($ classesConfiguration );
131133
132- foreach ($ frameworkConfiguration ['persistence ' ]['classes ' ] as $ className => $ tableConf ) {
133- $ tableName = $ tableConf ['mapping ' ]['tableName ' ];
134+ $ result = [];
135+ foreach ($ configuration as $ className => $ tableConf ) {
136+ $ tableName = $ tableConf ['tableName ' ];
134137 $ result [$ tableName ] = $ className ;
135138 }
136139
@@ -193,7 +196,7 @@ protected function getTableInfo(Table $table, ?string $className): object
193196 : $ column ->getColumnName ();
194197
195198 if (isset ($ result ->columns [$ columnName ])) {
196- $ result ->columns [$ columnName ]->fieldComment = $ this ->parseDocComment ($ property ->getDocComment ());
199+ $ result ->columns [$ columnName ]->fieldComment = $ this ->parsePropertyDocComment ($ property ->getDocComment ());
197200 }
198201 }
199202
@@ -204,6 +207,20 @@ protected function getTableInfo(Table $table, ?string $className): object
204207 return $ result ;
205208 }
206209
210+ protected function parsePropertyDocComment ($ docComment )
211+ {
212+ $ lines = explode ("\n" , $ docComment );
213+ foreach ($ lines as $ line ) {
214+ // extract text from @var line
215+ if ($ line !== '' && strpos ($ line , '@var ' ) !== false ) {
216+ $ text = preg_replace ('# \\s*/?[*/]* \\s?(.*)$# ' , '$1 ' , $ line ) . "\n" ;
217+ $ text = preg_replace ('/@var [^ ]+ ?/ ' , '' , $ text );
218+ return trim ($ text );
219+ }
220+ }
221+ return '' ;
222+ }
223+
207224 protected function parseDocComment ($ docComment )
208225 {
209226 // TODO: Consider using phpDocumentor (though that splits the docblock into summary and description)
@@ -237,7 +254,7 @@ public function generatePage(array $tables)
237254 $ page ->addText (<<<RST
238255This is a reference of all database tables defined by Kitodo.Presentation.
239256
240- .. tip:: This page is auto-generated. If you would like to edit it, please use doc-comments in the model class, COMMENT fields in ``ext_tables.sql`` if the table does not have one, or TCA labels. Then, you may re-generate the page by running ``composer docs:db `` inside the Kitodo.Presentation base folder.
257+ .. tip:: This page is auto-generated. If you would like to edit it, please use doc-comments in the model class, COMMENT fields in ``ext_tables.sql`` if the table does not have one, or TCA labels. Then, you may re-generate the page by running ``typo3 kitodo:dbdocs `` inside the Kitodo.Presentation base folder.
241258RST );
242259
243260 // Sort tables alphabetically
0 commit comments