Ejemplo n.º 1
0
 /**
  *
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject_Action $action
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  *
  * @return Tx_ExtensionBuilder_Domain_Model_Class_Method
  */
 protected function buildActionMethod(Tx_ExtensionBuilder_Domain_Model_DomainObject_Action $action, Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject)
 {
     $actionName = $action->getName();
     $actionMethodName = $actionName . 'Action';
     $actionMethod = new Tx_ExtensionBuilder_Domain_Model_Class_Method($actionMethodName);
     $actionMethod->setDescription('action ' . $action->getName());
     $actionMethod->setBody($this->codeGenerator->getDefaultMethodBody($domainObject, NULL, 'Controller', '', $actionMethodName));
     $actionMethod->addModifier('public');
     if (in_array($actionName, array('show', 'edit', 'create', 'new', 'update', 'delete'))) {
         // these actions need a parameter
         if (in_array($actionName, array('create', 'new'))) {
             $parameterName = 'new' . $domainObject->getName();
         } else {
             $parameterName = t3lib_div::lcfirst($domainObject->getName());
         }
         $parameter = new Tx_ExtensionBuilder_Domain_Model_Class_MethodParameter($parameterName);
         $parameter->setTypeHint($domainObject->getClassName());
         $parameter->setVarType($domainObject->getClassName());
         $parameter->setPosition(0);
         if ($actionName == 'new') {
             $parameter->setOptional(TRUE);
             $actionMethod->setTag('dontvalidate', '$' . $parameterName);
         }
         $actionMethod->setParameter($parameter);
     }
     $actionMethod->setTag('return', 'void');
     return $actionMethod;
 }
Ejemplo n.º 2
0
 /**
  * remove domainObject related files if a domainObject was deleted
  *
  * @return void
  */
 protected function removeDomainObjectFiles($domainObject)
 {
     t3lib_div::devlog('Remove domainObject ' . $domainObject->getName(), 'extension_builder', 0);
     $this->cleanUp(Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($this->previousExtensionDirectory, 'Model', FALSE), $domainObject->getName() . '.php');
     $this->cleanUp($this->previousExtensionDirectory . 'Configuration/TCA/', $domainObject->getName() . '.php');
     if ($domainObject->isAggregateRoot()) {
         $this->cleanUp(Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($this->previousExtensionDirectory, 'Controller', FALSE), $domainObject->getName() . 'Controller.php');
         $this->cleanUp(Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($this->previousExtensionDirectory, 'Repository', FALSE), $domainObject->getName() . 'Repository.php');
     }
     if (count($domainObject->getActions()) > 0) {
         $this->cleanUp(Tx_ExtensionBuilder_Service_CodeGenerator::getFolderForClassFile($this->previousExtensionDirectory, 'Controller', FALSE), $domainObject->getName() . 'Controller.php');
     }
     // other files
     $iconsDirectory = $this->extensionDirectory . 'Resources/Public/Icons/';
     $languageDirectory = $this->extensionDirectory . 'Resources/Private/Language/';
     $locallang_cshFile = $languageDirectory . 'locallang_csh_' . $domainObject->getDatabaseTableName() . '.xml';
     $iconFile = $iconsDirectory . $domainObject->getDatabaseTableName() . '.gif';
     if (file_exists($locallang_cshFile)) {
         // no overwrite settings check here...
         unlink($locallang_cshFile);
         t3lib_div::devLog('locallang_csh file removed: ' . $locallang_cshFile, 'extension_builder', 1);
     }
     if (file_exists($iconFile)) {
         unlink($iconFile);
         t3lib_div::devLog('icon file removed: ' . $iconFile, 'extension_builder', 1);
     }
 }
 /**
  * Generate the code files according to the transferred JSON configuration
  *
  * @throws Exception
  * @return array (status => message)
  */
 protected function rpcAction_save()
 {
     try {
         $extensionBuildConfiguration = $this->configurationManager->getConfigurationFromModeler();
         t3lib_div::devlog('Modeler Configuration', 'extension_builder', 0, $extensionBuildConfiguration);
         $validationConfigurationResult = $this->extensionValidator->validateConfigurationFormat($extensionBuildConfiguration);
         if (!empty($validationConfigurationResult['warnings'])) {
             $confirmationRequired = $this->handleValidationWarnings($validationConfigurationResult['warnings']);
             if (!empty($confirmationRequired)) {
                 return $confirmationRequired;
             }
         }
         $extension = $this->extensionSchemaBuilder->build($extensionBuildConfiguration);
     } catch (Exception $e) {
         throw $e;
     }
     // Validate the extension
     $validationResult = $this->extensionValidator->isValid($extension);
     if (!empty($validationResult['errors'])) {
         $errorMessage = '';
         foreach ($validationResult['errors'] as $exception) {
             $errorMessage .= '<br />' . $exception->getMessage();
         }
         throw new Exception($errorMessage);
     }
     if (!empty($validationResult['warnings'])) {
         $confirmationRequired = $this->handleValidationWarnings($validationResult['warnings']);
         if (!empty($confirmationRequired)) {
             return $confirmationRequired;
         }
     }
     $extensionDirectory = $extension->getExtensionDir();
     if (!is_dir($extensionDirectory)) {
         t3lib_div::mkdir($extensionDirectory);
     } else {
         if ($this->settings['extConf']['backupExtension'] == 1) {
             try {
                 Tx_ExtensionBuilder_Service_RoundTrip::backupExtension($extension, $this->settings['extConf']['backupDir']);
             } catch (Exception $e) {
                 throw $e;
             }
         }
         $extensionSettings = $this->configurationManager->getExtensionSettings($extension->getExtensionKey());
         if ($this->settings['extConf']['enableRoundtrip'] == 1) {
             if (empty($extensionSettings)) {
                 // no config file in an existing extension!
                 // this would result in a total overwrite so we create one and give a warning
                 $this->configurationManager->createInitialSettingsFile($extension, $this->settings['codeTemplateRootPath']);
                 return array('warning' => "<span class='error'>Roundtrip is enabled but no configuration file was found.</span><br />This might happen if you use the extension builder the first time for this extension. <br />A settings file was generated in <br /><b>typo3conf/ext/" . $extension->getExtensionKey() . "/Configuration/ExtensionBuilder/settings.yaml.</b><br />Configure the overwrite settings, then save again.");
             }
             try {
                 Tx_ExtensionBuilder_Service_RoundTrip::prepareExtensionForRoundtrip($extension);
             } catch (Exception $e) {
                 throw $e;
             }
         }
     }
     try {
         $this->codeGenerator->build($extension);
         $this->extensionInstallationStatus->setExtension($extension);
         $message = '<p>The Extension was saved</p>' . $this->extensionInstallationStatus->getStatusMessage();
         if ($extension->getNeedsUploadFolder()) {
             $message .= '<br />Notice: File upload is not yet implemented.';
         }
         $result = array('success' => $message);
     } catch (Exception $e) {
         throw $e;
     }
     $this->extensionRepository->saveExtensionConfiguration($extension);
     return $result;
 }