示例#1
0
 /**
  * If a JSON file is found in the extensions directory the previous version
  * of the extension is build to compare it with the new configuration coming
  * from the extension builder input
  *
  * @param \EBT\ExtensionBuilder\Domain\Model\Extension $extension
  */
 public function initialize(Model\Extension $extension)
 {
     $this->extension = $extension;
     $this->extensionDirectory = $this->extension->getExtensionDir();
     if (!$this->parserService instanceof \EBT\ExtensionBuilder\Service\Parser) {
         $this->injectParserService(GeneralUtility::makeInstance('EBT\\ExtensionBuilder\\Service\\Parser'));
     }
     $this->settings = $this->configurationManager->getExtensionBuilderSettings();
     // defaults
     $this->previousExtensionDirectory = $this->extensionDirectory;
     $this->previousExtensionKey = $this->extension->getExtensionKey();
     if ($extension->isRenamed()) {
         $this->previousExtensionDirectory = $extension->getPreviousExtensionDirectory();
         $this->previousExtensionKey = $extension->getOriginalExtensionKey();
         $this->extensionRenamed = true;
         GeneralUtility::devlog('Extension renamed: ' . $this->previousExtensionKey . ' => ' . $this->extension->getExtensionKey(), 'extension_builder', 1, array('$previousExtensionDirectory ' => $this->previousExtensionDirectory));
     }
     // Rename the old kickstarter.json file to ExtensionBuilder.json
     if (file_exists($this->previousExtensionDirectory . 'kickstarter.json')) {
         rename($this->previousExtensionDirectory . 'kickstarter.json', $this->previousExtensionDirectory . ConfigurationManager::EXTENSION_BUILDER_SETTINGS_FILE);
     }
     if (file_exists($this->previousExtensionDirectory . ConfigurationManager::EXTENSION_BUILDER_SETTINGS_FILE)) {
         $extensionSchemaBuilder = GeneralUtility::makeInstance('EBT\\ExtensionBuilder\\Service\\ExtensionSchemaBuilder');
         $jsonConfig = $this->configurationManager->getExtensionBuilderConfiguration($this->previousExtensionKey, false);
         GeneralUtility::devlog('old JSON:' . $this->previousExtensionDirectory . 'ExtensionBuilder.json', 'extension_builder', 0, $jsonConfig);
         $this->previousExtension = $extensionSchemaBuilder->build($jsonConfig);
         $previousDomainObjects = $this->previousExtension->getDomainObjects();
         /** @var $previousDomainObjects \EBT\ExtensionBuilder\Domain\Model\DomainObject[] */
         foreach ($previousDomainObjects as $oldDomainObject) {
             $this->previousDomainObjects[$oldDomainObject->getUniqueIdentifier()] = $oldDomainObject;
             $this->log('Old domain object: ' . $oldDomainObject->getName() . ' - ' . $oldDomainObject->getUniqueIdentifier(), 0, $jsonConfig);
         }
         /**
          * now we store all renamed domainObjects in an array to enable
          * detection of renaming in relationProperties (property->getForeignModel)
          * we also build an array with the new unique identifiers to detect
          * deleting of domainObjects
          */
         $currentDomainsObjects = array();
         foreach ($this->extension->getDomainObjects() as $domainObject) {
             /** @var \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject */
             if (isset($this->previousDomainObjects[$domainObject->getUniqueIdentifier()])) {
                 if ($this->previousDomainObjects[$domainObject->getUniqueIdentifier()]->getName() != $domainObject->getName()) {
                     $renamedDomainObjects[$domainObject->getUniqueIdentifier()] = $domainObject;
                 }
             }
             $currentDomainsObjects[$domainObject->getUniqueIdentifier()] = $domainObject;
         }
         // remove deleted objects
         foreach ($previousDomainObjects as $oldDomainObject) {
             if (!isset($currentDomainsObjects[$oldDomainObject->getUniqueIdentifier()])) {
                 $this->removeDomainObjectFiles($oldDomainObject);
             }
         }
     }
 }