Esempio n. 1
0
 /**
  * Rewrite Magento entity. Helpers have specific behavior - no alias in core configs.
  *
  * @param string $originNamespace
  * @param string $originPath
  * @param string $path
  * @param Mtool_Codegen_Entity_Module $module
  */
 public function rewrite($originNamespace, $originPath, $path, Mtool_Codegen_Entity_Module $module)
 {
     // Create own class
     $originPathSteps = $this->_ucPath(explode('_', $originPath));
     $originModuleName = ucfirst($originNamespace);
     $originClassName = implode('_', $originPathSteps);
     $params = array('original_class_name' => "Mage_{$originModuleName}_{$this->_entityName}_{$originClassName}");
     $className = $this->createClass($path, $this->_rewriteTemplate, $module, $params);
     // Register rewrite in config
     $config = new Mtool_Codegen_Config($module->getConfigPath('config.xml'));
     $config->set("global/{$this->_configNamespace}/{$originNamespace}/rewrite/{$originPath}", $className);
 }
Esempio n. 2
0
 /**
  * Rewrite resource model
  *
  * @param string $originNamespace
  * @param string $originPath
  * @param string $path
  * @param Mtool_Codegen_Entity_Module $module
  */
 public function rewrite($originNamespace, $originPath, $path, Mtool_Codegen_Entity_Module $module)
 {
     // Find origin class prefix
     $resourceModel = $this->lookupOriginEntityClass($originNamespace, $module->findThroughModules('config.xml'), 'resourceModel');
     $classPrefix = $this->lookupOriginEntityClass($resourceModel, $module->findThroughModules('config.xml'));
     // Create own class
     $originPathSteps = $this->_ucPath(explode('_', $originPath));
     $originClassName = implode('_', $originPathSteps);
     $params = array('original_class_name' => "{$classPrefix}_{$originClassName}");
     $className = $this->createClass($path, $this->_rewriteTemplate, $module, $params);
     //Register rewrite in config
     $config = new Mtool_Codegen_Config($module->getConfigPath('config.xml'));
     $config->set("global/{$this->_configNamespace}/{$resourceModel}/rewrite/{$originPath}", $className);
 }
Esempio n. 3
0
 /**
  * Upgrade magento module
  *
  * @param string $mode - see mode constants
  * @param string $versionRequest - exact version or a mask depending on mode
  */
 public function upgrade($mode, $versionRequest)
 {
     if (!$this->exists()) {
         throw new Mtool_Codegen_Exception_Module("Seems like this module does not exist. Aborting.");
     }
     $config = new Mtool_Codegen_Config($this->getConfigPath('config.xml'));
     // Define version value
     $currentVersion = $config->get("modules/{$this->getName()}/version");
     switch ($mode) {
         case self::UPGRADE_MODE_EXACT:
             $version = $versionRequest;
             break;
         case self::UPGRADE_MODE_INCREMENT:
             $version = $this->_forceVersion($currentVersion, $versionRequest);
             break;
         default:
             throw new Mtool_Codegen_Exception_Module("Undefined version upgrade type: {$mode}");
     }
     $config->set("modules/{$this->getName()}/version", $version);
     // Create upgrade file
     $setupNamspace = strtolower($this->getName()) . '_setup';
     $modulesTemplate = new Mtool_Codegen_Template('module_upgrader');
     $params = array('module_name' => $this->getName(), 'module' => $this->_moduleName, 'company_name' => $this->getCompanyName(), 'year' => date('Y'), 'class' => $config->get("global/resources/{$setupNamspace}/setup/class") ?: 'Mage_Core_Model_Resource_Setup');
     $modulesTemplate->setParams(array_merge($params, $this->_templateParams))->move($this->_moduleSqlDir . DIRECTORY_SEPARATOR . $setupNamspace, "mysql4-upgrade-{$currentVersion}-{$version}.php");
 }
Esempio n. 4
0
 /**
  * Lookup the class definition among the project
  * modules
  *
  * @param string $namespace
  * @param RegexIterator $configs
  * @param string $field
  * @return string (like Mage_Catalog_Model)
  */
 public function lookupOriginEntityClass($namespace, $configs, $field = 'class')
 {
     foreach ($configs as $_config) {
         try {
             $config = new Mtool_Codegen_Config(@$_config[0]);
             if ($prefix = $config->get("global/{$this->_configNamespace}/{$namespace}/{$field}")) {
                 return $prefix;
             }
         } catch (Exception $e) {
         }
     }
     throw new Mtool_Codegen_Exception_Entity("Module with namespace {$namespace} not found");
 }