/** * @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; }
/** * returns the name of the domain repository class name, if it is an aggregateroot. * * @return string */ public function getDomainRepositoryClassName() { if (!$this->aggregateRoot) { return ''; } return 'Tx_' . t3lib_div::underscoredToUpperCamelCase($this->extension->getExtensionKey()) . '_Domain_Repository_' . $this->getName() . 'Repository'; }
/** * * @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); }
protected function generateDomainObjectRelatedFiles() { if (count($this->extension->getDomainObjects()) > 0) { $this->classBuilder->initialize($this, $this->extension, $this->roundTripEnabled); // Generate Domain Model try { $domainModelDirectory = 'Classes/Domain/Model/'; $this->mkdir_deep($this->extensionDirectory, $domainModelDirectory); $domainRepositoryDirectory = 'Classes/Domain/Repository/'; $this->mkdir_deep($this->extensionDirectory, $domainRepositoryDirectory); $this->mkdir_deep($this->extensionDirectory, 'Tests/Unit/Domain/Model'); $domainModelTestsDirectory = $this->extensionDirectory . 'Tests/Unit/Domain/Model/'; $this->mkdir_deep($this->extensionDirectory, 'Tests/Unit/Controller'); $crudEnabledControllerTestsDirectory = $this->extensionDirectory . 'Tests/Unit/Controller/'; foreach ($this->extension->getDomainObjects() as $domainObject) { $destinationFile = $domainModelDirectory . $domainObject->getName() . '.php'; if ($this->roundTripEnabled && Tx_ExtensionBuilder_Service_RoundTrip::getOverWriteSettingForPath($destinationFile, $this->extension) > 0) { $mergeWithExistingClass = TRUE; } else { $mergeWithExistingClass = FALSE; } $fileContents = $this->generateDomainObjectCode($domainObject, $mergeWithExistingClass); $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents); t3lib_div::devlog('Generated ' . $domainObject->getName() . '.php', 'extension_builder', 0); $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile); if ($domainObject->isAggregateRoot()) { $iconFileName = 'aggregate_root.gif'; } elseif ($domainObject->isEntity()) { $iconFileName = 'entity.gif'; } else { $iconFileName = 'value_object.gif'; } $this->upload_copy_move(t3lib_extMgm::extPath('extension_builder') . 'Resources/Private/Icons/' . $iconFileName, $this->iconsDirectory . $domainObject->getDatabaseTableName() . '.gif'); if ($domainObject->isAggregateRoot()) { $destinationFile = $domainRepositoryDirectory . $domainObject->getName() . 'Repository.php'; if ($this->roundTripEnabled && Tx_ExtensionBuilder_Service_RoundTrip::getOverWriteSettingForPath($destinationFile, $this->extension) > 0) { $mergeWithExistingClass = TRUE; } else { $mergeWithExistingClass = FALSE; } $fileContents = $this->generateDomainRepositoryCode($domainObject, $mergeWithExistingClass); $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents); t3lib_div::devlog('Generated ' . $domainObject->getName() . 'Repository.php', 'extension_builder', 0); $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile); } // Generate basic UnitTests $fileContents = $this->generateDomainModelTests($domainObject); $this->writeFile($domainModelTestsDirectory . $domainObject->getName() . 'Test.php', $fileContents); } } catch (Exception $e) { throw new Exception('Could not generate domain model, error: ' . $e->getMessage()); } // Generate Action Controller try { $this->mkdir_deep($this->extensionDirectory, 'Classes/Controller'); $controllerDirectory = 'Classes/Controller/'; foreach ($this->extension->getDomainObjectsForWhichAControllerShouldBeBuilt() as $domainObject) { $destinationFile = $controllerDirectory . $domainObject->getName() . 'Controller.php'; if ($this->roundTripEnabled && Tx_ExtensionBuilder_Service_RoundTrip::getOverWriteSettingForPath($destinationFile, $this->extension) > 0) { $mergeWithExistingClass = TRUE; } else { $mergeWithExistingClass = FALSE; } $fileContents = $this->generateActionControllerCode($domainObject, $mergeWithExistingClass); $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents); t3lib_div::devlog('Generated ' . $domainObject->getName() . 'Controller.php', 'extension_builder', 0); $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile); // Generate basic UnitTests $fileContents = $this->generateControllerTests($domainObject->getName() . 'Controller', $domainObject); $this->writeFile($crudEnabledControllerTestsDirectory . $domainObject->getName() . 'ControllerTest.php', $fileContents); } } catch (Exception $e) { throw new Exception('Could not generate action controller, error: ' . $e->getMessage()); } // Generate Domain Templates try { if ($this->extension->getPlugins()) { $this->generateTemplateFiles(); } if ($this->extension->getBackendModules()) { $this->generateTemplateFiles('Backend/'); } } catch (Exception $e) { throw new Exception('Could not generate domain templates, error: ' . $e->getMessage()); } try { $settings = $this->extension->getSettings(); if (isset($settings['createAutoloadRegistry']) && $settings['createAutoloadRegistry'] == TRUE) { Tx_Extbase_Utility_Extension::createAutoloadRegistryForExtension($this->extension->getExtensionKey(), $this->extensionDirectory); } } catch (Exception $e) { throw new Exception('Could not generate ext_autoload.php, error: ' . $e->getMessage()); } } else { t3lib_div::devlog('No domainObjects in this extension', 'extension_builder', 3, (array) $this->extension); } }
/** * @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); }