/** * Returns the relation table name. It is build by having 'tx_myextension_' followed by the * first domain object name followed by the second domain object name followed by '_mm'. * * @return string */ public function getRelationTableName() { if (!empty($this->relationTableName)) { return $this->relationTableName; } $relationTableName = 'tx_' . str_replace('_', '', $this->domainObject->getExtension()->getExtensionKey()) . '_'; $relationTableName .= strtolower($this->domainObject->getName()); if ($this->useExtendedRelationTableName) { $relationTableName .= '_' . strtolower($this->getName()); } $relationTableName .= '_' . strtolower($this->getForeignModelName()) . '_mm'; return $relationTableName; }
/** * Returns a field name used in the database. This is the property name converted * to lowercase underscore (mySpecialProperty -> my_special_property). * * @return string the field name in lowercase underscore */ public function getFieldName() { $fieldName = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->name); if (\EBT\ExtensionBuilder\Service\ValidationService::isReservedMYSQLWord($fieldName)) { $fieldName = $this->domainObject->getExtension()->getShortExtensionKey() . '_' . $fieldName; } return $fieldName; }
/** * Helper function to verify various conditions around possible mapping/inheritance configurations * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * @param string $renderCondition * @return string */ public function render(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject, $renderCondition) { $content = ''; $extensionPrefix = 'Tx_' . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($domainObject->getExtension()->getExtensionKey()); // an external table should have a loadable TCA configuration and the column definitions // for external tables have to be declared in ext_tables.php $isMappedToExternalTable = FALSE; // table name is only set, if the model is mapped to a table or if the domain object extends a class $tableName = $domainObject->getMapToTable(); if ($tableName && strpos($tableName, strtolower($extensionPrefix) . '_domain_model_') === FALSE) { $isMappedToExternalTable = TRUE; } switch ($renderCondition) { case 'isMappedToInternalTable': if (!$isMappedToExternalTable) { $content = $this->renderThenChild(); } else { $content = $this->renderElseChild(); } break; case 'isMappedToExternalTable': if ($isMappedToExternalTable) { $content = $this->renderThenChild(); } else { $content = $this->renderElseChild(); } break; case 'needsTypeField': if ($this->needsTypeField($domainObject, $isMappedToExternalTable)) { $content = $this->renderThenChild(); } else { $content = $this->renderElseChild(); } break; } return $content; }
/** * cover all cases: * 1. extend TYPO3 class like fe_users (no mapping table needed) * * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject */ private function validateMapping(\EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject) { $parentClass = $domainObject->getParentClass(); $tableName = $domainObject->getMapToTable(); $extensionPrefix = 'Tx_' . GeneralUtility::underscoredToUpperCamelCase($domainObject->getExtension()->getExtensionKey()) . '_Domain_Model_'; if (!empty($parentClass)) { $classConfiguration = $this->configurationManager->getExtbaseClassConfiguration($parentClass); GeneralUtility::devlog('class settings ' . $parentClass, 'extension_builder', 0, $classConfiguration); if (!isset($classConfiguration['tableName'])) { if (!$tableName) { $this->validationResult['errors'][] = new ExtensionException('Mapping configuration error in domain object ' . $domainObject->getName() . ': ' . LF . 'The mapping table could not be detected from Extbase Configuration. Please enter a table name', self::ERROR_MAPPING_NO_TABLE); } } else { // get the table name from the parent class configuration $tableName = $classConfiguration['tableName']; } if (!class_exists($parentClass, TRUE)) { $this->validationResult['errors'][] = new ExtensionException('Mapping configuration error in domain object ' . $domainObject->getName() . ': the parent class ' . LF . $parentClass . 'seems not to exist ', self::ERROR_MAPPING_NO_PARENTCLASS); } } if ($tableName) { if (in_array($tableName, array('tt_content', 'pages')) || preg_match("/^(pages_|be_|sys_|static_|cf_)/", $tableName)) { $this->validationResult['warnings'][] = new ExtensionException('The configuration for table "' . $tableName . '" is not compatible' . LF . ' with extbase. You have to configure it yourself if you want to map' . LF . ' to this table', self::ERROR_MAPPING_TO_INCOMPATIBLE_TABLE); } if (strpos($extensionPrefix, $tableName) !== FALSE) { // the domainObject extends a class of the same extension if (!$parentClass) { $this->validationResult['errors'][] = new ExtensionException('Mapping configuration error in domain object ' . $domainObject->getName() . ': you have to define' . LF . 'a parent class if you map to a table of another domain object of the same extension ', self::ERROR_MAPPING_NO_PARENTCLASS); } } if (!isset($GLOBALS['TCA'][$tableName])) { $this->validationResult['errors'][] = new ExtensionException('There is no entry for table "' . $tableName . '" of ' . $domainObject->getName() . ' in TCA. ' . LF . 'For technical reasons you can only extend tables with TCA configuration.', self::ERROR_MAPPING_NO_TCA); } } if (isset($GLOBALS['TCA'][$tableName]['ctrl']['type'])) { $dataTypeRes = $this->getDatabaseConnection()->sql_query('DESCRIBE ' . $tableName); while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($dataTypeRes)) { if ($row['Field'] == $GLOBALS['TCA'][$tableName]['ctrl']['type']) { if (strpos($row['Type'], 'int') !== FALSE) { $this->validationResult['warnings'][] = new ExtensionException('The configured type field for table "' . $tableName . '" is of type ' . $row['Type'] . '' . LF . 'This means the type field can not be used for defining the record type. ' . LF . 'You have to configure the mappings yourself if you want to map to this' . LF . 'table or extend the correlated class', self::ERROR_MAPPING_WRONG_TYPEFIELD_CONFIGURATION); } } } } }
/** * Move custom TCA in files generated by EB versions <= 6.2 * to the appropriate overrides files * * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject */ public static function moveAdditionalTcaToOverrideFile($domainObject) { $tcaDir = $domainObject->getExtension()->getExtensionDir() . 'Configuration/TCA/'; $existingTcaFile = $tcaDir . $domainObject->getName() . '.php'; if (file_exists($existingTcaFile)) { $existingFileContent = file_get_contents($existingTcaFile); $fileParts = explode(self::SPLIT_TOKEN, $existingFileContent); if (count($fileParts) === 2) { $customFileContent = str_replace('$TCA[', '$GLOBALS[\'TCA\'][', $fileParts[1]); $customFileContent = '<?php ' . LF . self::SPLIT_TOKEN . LF . str_replace('?>', '', $customFileContent); if (!empty($customFileContent)) { $overrideDir = $tcaDir . 'Overrides/'; if (!is_dir($overrideDir)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($tcaDir, 'Overrides'); } $success = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($overrideDir . $domainObject->getDatabaseTableName() . '.php', $customFileContent); if (!$success) { throw new \Exception('File ' . $overrideDir . $domainObject->getDatabaseTableName() . '.php could not be created!'); } else { unlink($existingTcaFile); } } } } }