/**
  * Helper function to find the parents class recordType
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  * @return string
  */
 public function render(Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject)
 {
     $classSettings = $this->configurationManager->getExtbaseClassConfiguration($domainObject->getParentClass());
     if (isset($classSettings['recordType'])) {
         $parentRecordType = $classSettings['recordType'];
     } else {
         $parentRecordType = str_replace('Domain_Model_', '', $domainObject->getParentClass());
         if (!isset($TCA[$domainObject->getDatabaseTableName()]['types'][$parentRecordType])) {
             $parentRecordType = 1;
         }
     }
     $this->templateVariableContainer->add('parentRecordType', $parentRecordType);
     $content = $this->renderChildren();
     $this->templateVariableContainer->remove('parentRecordType');
     return $content;
 }
 /**
  * This is a hack to handle confirm requests in the GUI
  * @param $warnings
  * @return array confirm (Question to confirm), confirmFieldName (is set to TRUE if confirmed)
  */
 protected function handleValidationWarnings($warnings)
 {
     $messagesPerErrorcode = array();
     foreach ($warnings as $exception) {
         if (!is_array($messagesPerErrorcode[$exception->getCode()])) {
             $messagesPerErrorcode[$exception->getCode()] = array();
         }
         $messagesPerErrorcode[$exception->getCode()][] = $exception->getMessage();
     }
     foreach ($messagesPerErrorcode as $errorCode => $messages) {
         if (!$this->configurationManager->isConfirmed('allow' . $errorCode)) {
             if ($errorCode == Tx_ExtensionBuilder_Domain_Validator_ExtensionValidator::ERROR_PROPERTY_RESERVED_SQL_WORD) {
                 $confirmMessage = 'SQL reserved names were found for these properties:<br />' . '<ol class="warnings"><li>' . implode('</li><li>', $messages) . '</li></ol>' . 'This will result in a different column name in the database.<br />' . '<strong>Are you sure, you want to use them?</strong>';
             } else {
                 $confirmMessage = '<ol class="warnings"><li>' . implode('</li><li>', $messages) . '</li></ol>' . '<strong>Do you want to save anyway?</strong>';
             }
             return array('confirm' => '<span style="color:red">Warning!</span></br>' . $confirmMessage, 'confirmFieldName' => 'allow' . $errorCode);
         }
     }
     return array();
 }
Ejemplo n.º 3
0
 /**
  * This method is the main part of the roundtrip functionality
  * It looks for a previous version of the current domain object and
  * parses the existing class file for that domain model
  * compares all properties and methods with the previous version.
  *
  * Methods are either removed/added or updated according to the new property names
  *
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject The new domain object
  *
  * @return Tx_ExtensionBuilder_Domain_Model_Class OR NULL
  */
 public function getDomainModelClass(Tx_ExtensionBuilder_Domain_Model_DomainObject $currentDomainObject)
 {
     if (isset($this->oldDomainObjects[$currentDomainObject->getUniqueIdentifier()])) {
         t3lib_div::devlog('domainObject identified:' . $currentDomainObject->getName(), 'extension_builder', 0);
         $oldDomainObject = $this->oldDomainObjects[$currentDomainObject->getUniqueIdentifier()];
         $extensionDir = $this->previousExtensionDirectory;
         $fileName = Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($extensionDir, 'Model', FALSE) . $oldDomainObject->getName() . '.php';
         if (file_exists($fileName)) {
             // import the classObject from the existing file
             include_once $fileName;
             $className = $oldDomainObject->getClassName();
             $this->classObject = $this->classParser->parse($className);
             //t3lib_div::devlog('Model class methods','extension_builder',0,$this->classObject->getMethods());
             if ($oldDomainObject->getName() != $currentDomainObject->getName() || $this->extensionRenamed) {
                 if (!$this->extensionRenamed) {
                     t3lib_div::devlog('domainObject renamed. old: ' . $oldDomainObject->getName() . ' new: ' . $currentDomainObject->getName(), 'extension_builder');
                 }
                 $newClassName = $currentDomainObject->getClassName();
                 $this->classObject->setName($newClassName);
                 $this->classObject->setFileName($currentDomainObject->getName() . '.php');
                 $this->cleanUp(Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($extensionDir, 'Model'), $oldDomainObject->getName() . '.php');
                 $this->cleanUp($extensionDir . 'Configuration/TCA/', $oldDomainObject->getName() . '.php');
             }
             $this->updateModelClassProperties($oldDomainObject, $currentDomainObject);
             $newActions = array();
             foreach ($currentDomainObject->getActions() as $newAction) {
                 $newActions[$newAction->getName()] = $newAction;
             }
             $oldActions = $oldDomainObject->getActions();
             if (empty($newActions) && !$currentDomainObject->isAggregateRoot() && (!empty($oldActions) || $oldDomainObject->isAggregateRoot())) {
                 // remove the controller
                 $this->cleanUp(Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($extensionDir, 'Controller'), $oldDomainObject->getName() . 'Controller.php');
             }
             // the parent class settings configuration
             $parentClass = $currentDomainObject->getParentClass();
             $oldParentClass = $oldDomainObject->getParentClass();
             if (!empty($parentClass)) {
                 if ($oldParentClass != $parentClass) {
                     // the parent class was just new added
                     $this->classObject->setParentClass($parentClass);
                 }
             } else {
                 if (!empty($oldParentClass)) {
                     // the old object had a parent class setting, but it's removed now
                     if ($currentDomainObject->isEntity()) {
                         $parentClass = $this->configurationManager->getParentClassForEntityObject($this->extension->getExtensionKey());
                     } else {
                         $parentClass = $this->configurationManager->getParentClassForValueObject($this->extension->getExtensionKey());
                     }
                     $this->classObject->setParentClass($parentClass);
                 }
             }
             if ($currentDomainObject->isEntity() && !$oldDomainObject->isEntity()) {
                 // the object type was changed in the modeler
                 $this->classObject->setParentClass($this->configurationManager->getParentClassForEntityObject($this->extension->getExtensionKey()));
             } elseif (!$currentDomainObject->isEntity() && $oldDomainObject->isEntity()) {
                 // the object type was changed in the modeler
                 $this->classObject->setParentClass($this->configurationManager->getParentClassForValueObject($this->extension->getExtensionKey()));
             }
             return $this->classObject;
         } else {
             t3lib_div::devLog('class file didn\'t exist:' . $fileName, 'extension_builder', 0);
         }
     } else {
         t3lib_div::devlog('domainObject not identified:' . $currentDomainObject->getName(), 'extension_builder', 0, $this->oldDomainObjects);
         $fileName = Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($this->extensionDirectory, 'Model', FALSE) . $currentDomainObject->getName() . '.php';
         if (file_exists($fileName)) {
             // import the classObject from the existing file
             include_once $fileName;
             $className = $currentDomainObject->getClassName();
             $this->classObject = $this->classParser->parse($className);
             t3lib_div::devLog('class file found:' . $currentDomainObject->getName() . '.php', 'extension_builder', 0, (array) $this->classObject->getAnnotations());
             return $this->classObject;
         }
     }
     return NULL;
 }
 /**
  *
  * @param array $jsonDomainObject
  * @return Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  */
 public function build(array $jsonDomainObject)
 {
     //t3lib_div::devlog('Building domain object '.$jsonDomainObject['name'],'extension_builder',0,$jsonDomainObject);
     $domainObject = t3lib_div::makeInstance('Tx_ExtensionBuilder_Domain_Model_DomainObject');
     $domainObject->setUniqueIdentifier($jsonDomainObject['objectsettings']['uid']);
     $domainObject->setName($jsonDomainObject['name']);
     $domainObject->setDescription($jsonDomainObject['objectsettings']['description']);
     if ($jsonDomainObject['objectsettings']['type'] === 'Entity') {
         $domainObject->setEntity(TRUE);
     } else {
         $domainObject->setEntity(FALSE);
     }
     $domainObject->setAggregateRoot($jsonDomainObject['objectsettings']['aggregateRoot']);
     $domainObject->setSorting($jsonDomainObject['objectsettings']['sorting']);
     // extended settings
     if (!empty($jsonDomainObject['objectsettings']['mapToTable'])) {
         $domainObject->setMapToTable($jsonDomainObject['objectsettings']['mapToTable']);
     }
     if (!empty($jsonDomainObject['objectsettings']['parentClass'])) {
         $domainObject->setParentClass($jsonDomainObject['objectsettings']['parentClass']);
     }
     // properties
     foreach ($jsonDomainObject['propertyGroup']['properties'] as $jsonProperty) {
         $propertyType = $jsonProperty['propertyType'];
         $propertyClassName = 'Tx_ExtensionBuilder_Domain_Model_DomainObject_' . $propertyType . 'Property';
         if (!class_exists($propertyClassName)) {
             t3lib_div::devlog('Property of type ' . $propertyType . ' not found', 'extension_builder', 2, $jsonProperty);
             throw new Exception('Property of type ' . $propertyType . ' not found');
         }
         $property = t3lib_div::makeInstance($propertyClassName);
         $property->setUniqueIdentifier($jsonProperty['uid']);
         $property->setName($jsonProperty['propertyName']);
         $property->setDescription($jsonProperty['propertyDescription']);
         if (isset($jsonProperty['propertyIsRequired'])) {
             $property->setRequired($jsonProperty['propertyIsRequired']);
         }
         if (isset($jsonProperty['propertyIsExcludeField'])) {
             $property->setExcludeField($jsonProperty['propertyIsExcludeField']);
         }
         //t3lib_div::devlog('Adding property ' . $jsonProperty['propertyName'] . ' to domain object '.$jsonDomainObject['name'],'extension_builder',0,$jsonDomainObject);
         $domainObject->addProperty($property);
     }
     $relatedForeignTables = array();
     foreach ($jsonDomainObject['relationGroup']['relations'] as $jsonRelation) {
         $relation = self::buildRelation($jsonRelation);
         if (!empty($jsonRelation['foreignRelationClass'])) {
             // relations without wires
             $relation->setForeignClassName($jsonRelation['foreignRelationClass']);
             $relation->setRelatedToExternalModel(TRUE);
             $extbaseClassConfiguration = $this->configurationManager->getExtbaseClassConfiguration($jsonRelation['foreignRelationClass']);
             if (isset($extbaseClassConfiguration['tableName'])) {
                 $foreignDatabaseTableName = $extbaseClassConfiguration['tableName'];
             } else {
                 $foreignDatabaseTableName = strtolower($jsonRelation['foreignRelationClass']);
             }
             $relation->setForeignDatabaseTableName($foreignDatabaseTableName);
             if (is_a($relation, Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ZeroToManyRelation)) {
                 $foreignKeyName = strtolower($domainObject->getName());
                 if (isset($relatedForeignTables[$foreignDatabaseTableName])) {
                     $foreignKeyName .= $relatedForeignTables[$foreignDatabaseTableName];
                     $relatedForeignTables[$foreignDatabaseTableName] += 1;
                 } else {
                     $relatedForeignTables[$foreignDatabaseTableName] = 1;
                 }
                 $relation->setForeignKeyName($foreignKeyName);
             }
         }
         //t3lib_div::devlog('Adding relation ' . $jsonRelation['relationName'] . ' to domain object '.$jsonDomainObject['name'],'extension_builder',0,$jsonRelation);
         $domainObject->addProperty($relation);
     }
     //actions
     foreach ($jsonDomainObject['actionGroup'] as $jsonActionName => $actionValue) {
         if ($jsonActionName == 'customActions' && !empty($actionValue)) {
             $actionNames = $actionValue;
         } else {
             if ($actionValue == 1) {
                 $jsonActionName = preg_replace('/^_default[0-9]_*/', '', $jsonActionName);
                 if ($jsonActionName == 'edit_update' || $jsonActionName == 'new_create') {
                     $actionNames = explode('_', $jsonActionName);
                 } else {
                     $actionNames = array($jsonActionName);
                 }
             } else {
                 $actionNames = array();
             }
         }
         if (!empty($actionNames)) {
             foreach ($actionNames as $actionName) {
                 $action = t3lib_div::makeInstance('Tx_ExtensionBuilder_Domain_Model_DomainObject_Action');
                 $action->setName($actionName);
                 $domainObject->addAction($action);
             }
         }
     }
     return $domainObject;
 }
 /**
  * @param Tx_ExtensionBuilder_Domain_Model_Extension $extension
  */
 public function saveExtensionConfiguration(Tx_ExtensionBuilder_Domain_Model_Extension $extension)
 {
     $extensionBuildConfiguration = $this->configurationManager->getConfigurationFromModeler();
     $extensionBuildConfiguration['log'] = array('last_modified' => date('Y-m-d h:i'), 'extension_builder_version' => t3lib_extMgm::getExtensionVersion('extension_builder'), 'be_user' => $GLOBALS['BE_USER']->user['realName'] . ' (' . $GLOBALS['BE_USER']->user['uid'] . ')');
     t3lib_div::writeFile($extension->getExtensionDir() . Tx_ExtensionBuilder_Configuration_ConfigurationManager::EXTENSION_BUILDER_SETTINGS_FILE, json_encode($extensionBuildConfiguration));
 }
 /**
  * @param Tx_ExtensionBuilder_Domain_Model_Extension $extension
  * @param array $propertyConfiguration
  * @return void
  */
 protected function setExtensionProperties(&$extension, $propertyConfiguration)
 {
     // name
     $extension->setName(trim($propertyConfiguration['name']));
     // description
     $extension->setDescription($propertyConfiguration['description']);
     // extensionKey
     $extension->setExtensionKey(trim($propertyConfiguration['extensionKey']));
     if ($propertyConfiguration['emConf']['disableVersioning']) {
         $extension->setSupportVersioning(FALSE);
     }
     // various extension properties
     $extension->setVersion($propertyConfiguration['emConf']['version']);
     if (!empty($propertyConfiguration['emConf']['dependsOn'])) {
         $dependencies = array();
         $lines = t3lib_div::trimExplode("\n", $propertyConfiguration['emConf']['dependsOn']);
         foreach ($lines as $line) {
             if (strpos($line, '=>')) {
                 list($extensionKey, $version) = t3lib_div::trimExplode('=>', $line);
                 $dependencies[$extensionKey] = $version;
             }
         }
         $extension->setDependencies($dependencies);
     }
     if (!empty($propertyConfiguration['emConf']['targetVersion'])) {
         $extension->setTargetVersion(floatval($propertyConfiguration['emConf']['targetVersion']));
     }
     if (!empty($propertyConfiguration['emConf']['custom_category'])) {
         $category = $propertyConfiguration['emConf']['custom_category'];
     } else {
         $category = $propertyConfiguration['emConf']['category'];
     }
     $extension->setCategory($category);
     $extension->setShy($propertyConfiguration['emConf']['shy']);
     $extension->setPriority($propertyConfiguration['emConf']['priority']);
     // state
     $state = 0;
     switch ($propertyConfiguration['emConf']['state']) {
         case 'alpha':
             $state = Tx_ExtensionBuilder_Domain_Model_Extension::STATE_ALPHA;
             break;
         case 'beta':
             $state = Tx_ExtensionBuilder_Domain_Model_Extension::STATE_BETA;
             break;
         case 'stable':
             $state = Tx_ExtensionBuilder_Domain_Model_Extension::STATE_STABLE;
             break;
         case 'experimental':
             $state = Tx_ExtensionBuilder_Domain_Model_Extension::STATE_EXPERIMENTAL;
             break;
         case 'test':
             $state = Tx_ExtensionBuilder_Domain_Model_Extension::STATE_TEST;
             break;
     }
     $extension->setState($state);
     if (!empty($propertyConfiguration['originalExtensionKey'])) {
         // handle renaming of extensions
         // original extensionKey
         $extension->setOriginalExtensionKey($propertyConfiguration['originalExtensionKey']);
         t3lib_div::devlog('Extension setOriginalExtensionKey:' . $extension->getOriginalExtensionKey(), 'extbase', 0, $propertyConfiguration);
     }
     if (!empty($propertyConfiguration['originalExtensionKey']) && $extension->getOriginalExtensionKey() != $extension->getExtensionKey()) {
         $settings = $this->configurationManager->getExtensionSettings($extension->getOriginalExtensionKey());
         // if an extension was renamed, a new extension dir is created and we
         // have to copy the old settings file to the new extension dir
         copy($this->configurationManager->getSettingsFile($extension->getOriginalExtensionKey()), $this->configurationManager->getSettingsFile($extension->getExtensionKey()));
     } else {
         $settings = $this->configurationManager->getExtensionSettings($extension->getExtensionKey());
     }
     if (!empty($settings)) {
         $extension->setSettings($settings);
         t3lib_div::devlog('Extension settings:' . $extension->getExtensionKey(), 'extbase', 0, $extension->getSettings());
     }
 }
Ejemplo n.º 7
0
 /**
  * This method generates the class schema object, which is passed to the template
  * it keeps all methods and properties including user modified method bodies and comments
  * needed to create a domain object class file
  *
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  * @param boolean mergeWithExistingClass
  *
  * @return Tx_ExtensionBuilder_Domain_Model_Class_Class
  */
 public function generateModelClassObject($domainObject, $mergeWithExistingClass)
 {
     t3lib_div::devlog('------------------------------------- generateModelClassObject(' . $domainObject->getName() . ') ---------------------------------', 'extension_builder', 0);
     $this->classObject = NULL;
     // reference to the resulting class file,
     $className = $domainObject->getClassName();
     if ($mergeWithExistingClass) {
         try {
             $this->classObject = $this->roundTripService->getDomainModelClass($domainObject);
         } catch (Exception $e) {
             t3lib_div::devLog('Class ' . $className . ' could not be imported: ' . $e->getMessage(), 'extension_builder', 2);
         }
     }
     if ($this->classObject == NULL) {
         $this->classObject = new Tx_ExtensionBuilder_Domain_Model_Class_Class($className);
         if ($domainObject->isEntity()) {
             $parentClass = $domainObject->getParentClass();
             if (empty($parentClass)) {
                 $parentClass = $this->configurationManager->getParentClassForEntityObject($this->extension->getExtensionKey());
             }
         } else {
             $parentClass = $this->configurationManager->getParentClassForValueObject($this->extension->getExtensionKey());
         }
         $this->classObject->setParentClass($parentClass);
     }
     if (!$this->classObject->hasDescription()) {
         $this->classObject->setDescription($domainObject->getDescription());
     }
     $this->addInitStorageObjectCalls($domainObject);
     //TODO the following part still needs some enhancement:
     //what should be obligatory in existing properties and methods
     foreach ($domainObject->getProperties() as $domainProperty) {
         $propertyName = $domainProperty->getName();
         // add the property to class Object (or update an existing class Object property)
         if ($this->classObject->propertyExists($propertyName)) {
             $classProperty = $this->classObject->getProperty($propertyName);
             //$classPropertyTags = $classProperty->getTags();
             //t3lib_div::devLog('Property found: ' . $propertyName . ':' . $domainProperty->getTypeForComment(), 'extension_builder', 1, (array)$classProperty);
         } else {
             $classProperty = new Tx_ExtensionBuilder_Domain_Model_Class_Property($propertyName);
             $classProperty->setTag('var', $domainProperty->getTypeForComment());
             $classProperty->addModifier('protected');
             //t3lib_div::devLog('New property: ' . $propertyName . ':' . $domainProperty->getTypeForComment(), 'extension_builder', 1);
         }
         $classProperty->setAssociatedDomainObjectProperty($domainProperty);
         if ($domainProperty->getRequired()) {
             if (!$classProperty->isTaggedWith('validate')) {
                 $validateTag = explode(' ', trim($domainProperty->getValidateAnnotation()));
                 $classProperty->setTag('validate', $validateTag[1]);
             }
         }
         if ($domainProperty->isRelation() && $domainProperty->getLazyLoading()) {
             if (!$classProperty->isTaggedWith('lazy')) {
                 $classProperty->setTag('lazy', '');
             }
         }
         if ($domainProperty->getHasDefaultValue()) {
             $classProperty->setDefault($domainProperty->getDefaultValue());
         }
         $this->classObject->setProperty($classProperty);
         if ($domainProperty->isNew()) {
             $this->setPropertyRelatedMethods($domainProperty);
         }
     }
     //t3lib_div::devlog('Methods before sorting','extension_builder',0,array_keys($this->classObject->getMethods()));
     //$this->sortMethods($domainObject);
     return $this->classObject;
 }