/** * @param string $extKey * @return boolean */ protected function dbUpdateNeeded() { if (t3lib_extMgm::isLoaded($this->extension->getExtensionKey()) && !empty($this->installTool)) { $updateNeeded = $this->installTool->checkDBupdates($this->extension->getExtensionKey(), array('type' => 'L', 'files' => array('ext_tables.sql')), 1); if (!empty($updateNeeded['structure']['diff']['extra'])) { return TRUE; } } return FALSE; }
/** * * @param Tx_ExtensionBuilder_Service_CodeGenerator $codeGenerator * @param Tx_ExtensionBuilder_Domain_Model_Extension $extension * @param boolean roundtrip enabled? * * @return void */ public function initialize(Tx_ExtensionBuilder_Service_CodeGenerator $codeGenerator, Tx_ExtensionBuilder_Domain_Model_Extension $extension, $roundTripEnabled) { $this->codeGenerator = $codeGenerator; $this->extension = $extension; $settings = $extension->getSettings(); if ($roundTripEnabled) { $this->roundTripService->initialize($this->extension); } $this->settings = $settings['classBuilder']; $this->extensionDirectory = $this->extension->getExtensionDir(); $this->extClassPrefix = 'Tx_' . t3lib_div::underscoredToUpperCamelCase($this->extension->getExtensionKey()); }
/** * generate a docComment for class files. Add a license haeder if none found * @param unknown_type $classObject * @param unknown_type $domainObject */ protected function renderDocComment($classObject, $domainObject) { if (!$classObject->hasDocComment()) { $docComment = $this->renderTemplate('Partials/Classes/classDocComment.phpt', array('domainObject' => $domainObject, 'extension' => $this->extension, 'classObject' => $classObject)); } else { $docComment = $classObject->getDocComment(); } $precedingBlock = $classObject->getPrecedingBlock(); if (empty($precedingBlock) || strpos($precedingBlock, 'GNU General Public License') < 1) { $licenseHeader = $this->renderTemplate('Partials/Classes/licenseHeader.phpt', array('persons' => $this->extension->getPersons())); $docComment = "\n" . $licenseHeader . "\n\n\n" . $docComment; } else { $docComment = $precedingBlock . "\n" . $docComment; } return $docComment; }
/** * * @param Tx_ExtensionBuilder_Domain_Model_Extension $extension * @param string $backupDir * * @return void */ static function backupExtension($extension, $backupDir) { if (empty($backupDir)) { throw new Exception('Please define a backup directory in extension configuration!'); } else { if (!t3lib_div::validPathStr($backupDir)) { throw new Exception('Backup directory is not a valid path: ' . $backupDir); } else { if (t3lib_div::isAbsPath($backupDir)) { if (!t3lib_div::isAllowedAbsPath($backupDir)) { throw new Exception('Backup directory is not an allowed absolute path: ' . $backupDir); } } else { $backupDir = PATH_site . $backupDir; } } } if (strrpos($backupDir, '/') < strlen($backupDir) - 1) { $backupDir .= '/'; } if (!is_dir($backupDir)) { throw new Exception('Backup directory does not exist: ' . $backupDir); } else { if (!is_writable($backupDir)) { throw new Exception('Backup directory is not writable: ' . $backupDir); } } $backupDir .= $extension->getExtensionKey(); // create a subdirectory for this extension if (!is_dir($backupDir)) { t3lib_div::mkdir($backupDir); } if (strrpos($backupDir, '/') < strlen($backupDir) - 1) { $backupDir .= '/'; } $backupDir .= date('Y-m-d-') . time(); if (!is_dir($backupDir)) { t3lib_div::mkdir($backupDir); } $extensionDir = substr($extension->getExtensionDir(), 0, strlen($extension->getExtensionDir()) - 1); try { self::recurse_copy($extensionDir, $backupDir); } catch (Exception $e) { throw new Exception('Code generation aborted:' . $e->getMessage()); } t3lib_div::devlog('Backup created in ' . $backupDir, 'extension_builder', 0); }
/** * @param Tx_ExtensionBuilder_Domain_Model_Extension $extension * @return void */ private function validateBackendModules($extension) { if (count($extension->getBackendModules()) < 1) { return; } $backendModuleKeys = array(); foreach ($extension->getBackendModules() as $backendModule) { if (self::validateModuleKey($backendModule->getKey()) === 0) { $this->validationResult['errors'][] = new Exception('Invalid key in backend module ' . $backendModule->getName() . '. Only alphanumeric character without spaces are allowed', self::ERROR_BACKENDMODULE_INVALID_KEY); } if (in_array($backendModule->getKey(), $backendModuleKeys)) { $this->validationResult['errors'][] = new Exception('Duplicate backend module key: "' . $backendModule->getKey() . '". Backend module keys must be unique.', self::ERROR_BACKENDMODULE_DUPLICATE_KEY); } $backendModuleKeys[] = $backendModule->getKey(); $this->validateBackendModuleConfiguration($backendModule, $extension); } }
/** * @return string */ public function getLabelNamespace() { return $this->extension->getShortExtensionKey() . '_domain_model_' . strtolower($this->getName()); }
/** * @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)); }
/** * @test */ public function conversionExtractsWholeExtensionMetadataWithRelations() { $input = array('modules' => array(0 => array('value' => array('name' => 'Blog', 'objectsettings' => array('description' => 'A blog object', 'aggregateRoot' => FALSE, 'type' => 'Entity'), 'propertyGroup' => array('properties' => array(0 => array('propertyName' => 'name', 'propertyType' => 'String'), 1 => array('propertyName' => 'description', 'propertyType' => 'String'))), 'relationGroup' => array('relations' => array(0 => array('relationName' => 'posts', 'relationType' => 'zeroToMany', 'propertyIsExcludeField' => 1))))), 1 => array('value' => array('name' => 'Post', 'objectsettings' => array('description' => 'A blog post', 'aggregateRoot' => FALSE, 'type' => 'Entity'), 'propertyGroup' => array('properties' => array()), 'relationGroup' => array('relations' => array(0 => array('relationName' => 'comments', 'relationType' => 'zeroToMany', 'propertyIsExcludeField' => 1))))), 2 => array('value' => array('name' => 'Comment', 'objectsettings' => array('description' => '', 'aggregateRoot' => FALSE, 'type' => 'Entity'), 'propertyGroup' => array('properties' => array()), 'relationGroup' => array('relations' => array())))), 'properties' => array('description' => 'Some description', 'extensionKey' => $this->extensionKey, 'name' => 'My ext name', 'emConf' => array('state' => 'beta')), 'wires' => array(0 => array('tgt' => array('moduleId' => 1, 'terminal' => 'SOURCES'), 'src' => array('moduleId' => 0, 'terminal' => 'relationWire_0')), 1 => array('tgt' => array('moduleId' => 2, 'terminal' => 'SOURCES'), 'src' => array('moduleId' => 1, 'terminal' => 'relationWire_0')))); $extension = new Tx_ExtensionBuilder_Domain_Model_Extension(); $extension->setName('My ext name'); $extension->setState(Tx_ExtensionBuilder_Domain_Model_Extension::STATE_BETA); $extension->setExtensionKey($this->extensionKey); $extension->setDescription('Some description'); $extension->setExtensionDir(''); $blog = new Tx_ExtensionBuilder_Domain_Model_DomainObject(); $blog->setName('Blog'); $blog->setDescription('A blog object'); $blog->setEntity(TRUE); $blog->setAggregateRoot(FALSE); $property = new Tx_ExtensionBuilder_Domain_Model_DomainObject_StringProperty('name'); $blog->addProperty($property); $property = new Tx_ExtensionBuilder_Domain_Model_DomainObject_StringProperty('description'); $blog->addProperty($property); $extension->addDomainObject($blog); $post = new Tx_ExtensionBuilder_Domain_Model_DomainObject(); $post->setName('Post'); $post->setDescription('A blog post'); $post->setEntity(TRUE); $post->setAggregateRoot(FALSE); $extension->addDomainObject($post); $comment = new Tx_ExtensionBuilder_Domain_Model_DomainObject(); $comment->setName('Comment'); $comment->setDescription(''); $comment->setEntity(TRUE); $comment->setAggregateRoot(FALSE); $extension->addDomainObject($comment); $relation = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ZeroToManyRelation('posts'); $relation->setForeignModel($post); $relation->setExcludeField(1); $blog->addProperty($relation); $relation = new Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ZeroToManyRelation('comments'); $relation->setForeignModel($comment); $relation->setExcludeField(1); $post->addProperty($relation); $actualExtension = $this->extensionSchemaBuilder->build($input); $this->assertEquals($extension->getDomainObjects(), $actualExtension->getDomainObjects(), 'The extensions differ'); }
/** * @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()); } }
/** * * @param Tx_ExtensionBuilder_Domain_Model_Extension $extension * @param string $codeTemplateRootPath */ public function createInitialSettingsFile($extension, $codeTemplateRootPath) { t3lib_div::mkdir_deep($extension->getExtensionDir(), self::SETTINGS_DIR); $settings = file_get_contents($codeTemplateRootPath . 'Configuration/ExtensionBuilder/settings.yamlt'); $settings = str_replace('{extension.extensionKey}', $extension->getExtensionKey(), $settings); $settings = str_replace('<f:format.date>now</f:format.date>', date('Y-m-d H:i'), $settings); t3lib_div::writeFile($extension->getExtensionDir() . self::SETTINGS_DIR . 'settings.yaml', $settings); }
/** * @test */ public function anyToManyRelationHasExpectedProperties() { $domainObjectName1 = 'DomainObject1'; $domainObjectName2 = 'DomainObject2'; $description = 'My long domain object description'; $relationName = 'Relation1'; $input = array('name' => $domainObjectName1, 'objectsettings' => array('description' => $description, 'aggregateRoot' => TRUE, 'type' => 'Entity'), 'relationGroup' => array('relations' => array(0 => array('relationName' => $relationName, 'relationType' => 'zeroToMany', 'propertyIsExcludeField' => FALSE)))); $domainObject1 = $this->objectSchemaBuilder->build($input); $input['name'] = $domainObjectName2; $domainObject2 = $this->objectSchemaBuilder->build($input); $dummyExtension = new Tx_ExtensionBuilder_Domain_Model_Extension(); $dummyExtension->setExtensionKey('dummy'); $domainObject1->setExtension($dummyExtension); $domainObject2->setExtension($dummyExtension); $relation = $domainObject1->getPropertyByName($relationName); $relation->setForeignModel($domainObject2); $this->assertFalse($relation->getUseMMTable(), 'ZeroToMany Relation->getUseMMTable() returned TRUE.'); $this->assertEquals('tx_dummy_domain_model_domainobject2', $relation->getForeignDatabaseTableName()); }