/**
  * This method generates the repository class object, which is passed to the template
  * it keeps all methods and properties including user modified method bodies and comments
  * needed to create a repository class file
  *
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  * @param boolean $mergeWithExistingClass
  *
  * @return Tx_ExtensionBuilder_Domain_Model_Class_Class
  */
 public function generateRepositoryClassObject($domainObject, $mergeWithExistingClass)
 {
     t3lib_div::devlog('------------------------------------- generateRepositoryClassObject(' . $domainObject->getName() . ') ---------------------------------', 'extension_builder', 1);
     $this->classObject = NULL;
     $className = $domainObject->getDomainRepositoryClassName();
     if ($mergeWithExistingClass) {
         try {
             $this->classObject = $this->roundTripService->getRepositoryClass($domainObject);
         } catch (Exception $e) {
             t3lib_div::devLog('Class ' . $className . ' could not be imported: ' . $e->getMessage(), 'extension_builder');
         }
     }
     if ($this->classObject == NULL) {
         $this->classObject = new Tx_ExtensionBuilder_Domain_Model_Class_Class($className);
         if (isset($this->settings['Repository']['parentClass'])) {
             $parentClass = $this->settings['Repository']['parentClass'];
         } else {
             $parentClass = 'Tx_Extbase_Persistence_Repository';
         }
         $this->classObject->setParentClass($parentClass);
     }
     return $this->classObject;
 }
 /**
  * wrapper for t3lib_div::mkdir_deep
  * checks for overwrite settings
  *
  * @param string $directory base path
  * @param string $deepDirectory
  */
 protected function mkdir_deep($directory, $deepDirectory)
 {
     $subDirectories = explode('/', $deepDirectory);
     $tmpBasePath = $directory;
     foreach ($subDirectories as $subDirectory) {
         $overWriteMode = Tx_ExtensionBuilder_Service_RoundTrip::getOverWriteSettingForPath($tmpBasePath . $subDirectory, $this->extension);
         //throw new Exception($directory . $subDirectory . '/' . $overWriteMode);
         if ($overWriteMode === -1) {
             // skip creation
             return;
         }
         if (!is_dir($deepDirectory) || $this->roundTripEnabled && $overWriteMode < 2) {
             t3lib_div::mkdir_deep($tmpBasePath, $subDirectory);
         }
         $tmpBasePath .= $subDirectory . '/';
     }
 }
 /**
  * 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;
 }