/** * Get component controller object by given component name and type * Calls before the method preInit() and postInit() hooks are called * * @param string $componentName component name * @param string $componentType component type * * @return \Cx\Core\Core\Controller\SystemComponentController */ protected function getComponentControllerByNameAndType($componentName, $componentType) { $component = new \Cx\Core\Core\Model\Entity\SystemComponent(); $component->setName($componentName); $component->setType($componentType); // Initialize ComponentController of component if available, // otherwise initialize the SystemComponentController // Implementation taken from method Cx\Core\Core\Model\Repository\SystemComponentRepository::getComponentControllerClassFor() // as that method shall not be used at this point to prevent the // system (i.e. the Class Loader) from loading the doctine PHP classes. if ($this->cl->getFilePath($component->getDirectory(false) . '/Controller/ComponentController.class.php')) { $componentControllerClass = $component->getNamespace() . '\\Controller\\ComponentController'; } else { $componentControllerClass = '\\Cx\\Core\\Core\\Model\\Entity\\SystemComponentController'; } return new $componentControllerClass($component, $this); }
/** * This adds all necessary DB entries in order to activate this component (if they do not exist) * @todo Backend navigation entry (from meta.yml) (rxqcmv1) * @todo Pages (from meta.yml) (rxqcmv1) */ public function activate() { if (!$this->exists()) { throw new \Cx\Core\Core\Controller\ComponentException('No such component: "' . $this->componentName . '" of type "' . $this->componentType . '"'); } $cx = \Env::get('cx'); $em = $cx->getDb()->getEntityManager(); // component if (!$this->isLegacy()) { $componentRepo = $em->getRepository('Cx\\Core\\Core\\Model\\Entity\\SystemComponent'); if (!$componentRepo->findOneBy(array('name' => $this->componentName, 'type' => $this->componentType))) { $component = new \Cx\Core\Core\Model\Entity\SystemComponent(); $component->setName($this->componentName); $component->setType($this->componentType); $em->persist($component); $em->flush(); } } // modules $distributor = 'Cloudrexx AG'; $workbenchComponent = new self('Workbench', 'core_module'); if ($workbenchComponent->exists()) { $workbench = new \Cx\Core_Modules\Workbench\Controller\Workbench(); $distributor = $workbench->getConfigEntry('distributor'); } $query = ' SELECT `id` FROM `' . DBPREFIX . 'modules` WHERE `name` = \'' . $this->componentName . '\' '; $result = $cx->getDb()->getAdoDb()->query($query); if (!$result->EOF) { $id = $result->fields['id']; $query = ' UPDATE `' . DBPREFIX . 'modules` SET `status` = \'y\', `is_required` = ' . (int) ($this->componentType == 'core') . ', `is_core` = ' . (int) ($this->componentType == 'core' || $this->componentType == 'core_module') . ', `is_active` = 1, `is_licensed` = 1 WHERE `id` = ' . $id . ' '; } else { $query = ' SELECT `id` FROM `' . DBPREFIX . 'modules` WHERE `id` >= 900 ORDER BY `id` DESC LIMIT 1 '; $id = 900; $result = $cx->getDb()->getAdoDb()->query($query); if (!$result->EOF) { $id = $result->fields['id'] + 1; } $query = ' INSERT INTO `' . DBPREFIX . 'modules` ( `id`, `name`, `distributor`, `description_variable`, `status`, `is_required`, `is_core`, `is_active`, `is_licensed` ) VALUES ( ' . $id . ', \'' . $this->componentName . '\', \'' . $distributor . '\', \'TXT_' . strtoupper($this->componentType) . '_' . strtoupper($this->componentName) . '_DESCRIPTION\', \'y\', ' . (int) ($this->componentType == 'core') . ', ' . (int) ($this->componentType == 'core' || $this->componentType == 'core_module') . ', 1, 1 ) '; } $cx->getDb()->getAdoDb()->query($query); // backend_areas $query = ' SELECT `area_id` FROM `' . DBPREFIX . 'backend_areas` WHERE `uri` LIKE \'%cmd=' . contrexx_raw2db($this->componentName) . '&%\' OR `uri` LIKE \'%cmd=' . contrexx_raw2db($this->componentName) . '\' '; $result = $cx->getDb()->getAdoDb()->query($query); if (!$result->EOF) { $query = ' UPDATE `' . DBPREFIX . 'backend_areas` SET `module_id` = ' . $id . ' WHERE `area_id` = ' . $result->fields['area_id'] . ' '; } else { $parent = 0; if ($this->componentType == 'module') { $parent = 2; } $order_id = 0; $query = ' SELECT `order_id` FROM `' . DBPREFIX . 'backend_areas` WHERE `parent_area_id` = ' . $parent . ' ORDER BY `order_id` DESC LIMIT 1 '; $result = $cx->getDb()->getAdoDb()->query($query); if (!$result->EOF) { $order_id = $result->fields['order_id'] + 1; } $access_id = 900; $query = ' SELECT `access_id` FROM `' . DBPREFIX . 'backend_areas` WHERE `access_id` >= 900 ORDER BY `access_id` DESC LIMIT 1 '; $result = $cx->getDb()->getAdoDb()->query($query); if (!$result->EOF) { $access_id = $result->fields['access_id'] + 1; } $query = ' INSERT INTO `' . DBPREFIX . 'backend_areas` ( `parent_area_id`, `type`, `scope`, `area_name`, `is_active`, `uri`, `target`, `module_id`, `order_id`, `access_id` ) VALUES ( ' . $parent . ', \'navigation\', \'backend\', \'TXT_' . strtoupper($this->componentType) . '_' . strtoupper($this->componentName) . '\', ' . (int) ($parent == 2) . ', \'index.php?cmd=' . $this->componentName . '\', \'_self\', ' . $id . ', ' . $order_id . ', ' . $access_id . ' ) '; } $cx->getDb()->getAdoDb()->query($query); // pages (if necessary) from repo (if has existing entry/ies) or empty one if ($this->componentType != 'module') { // only modules need a frontend page to be active return; } // we will not use modulemanager here in order to be able to replace // modulemanager by this in a later release $pageRepo = $em->getRepository('\\Cx\\Core\\ContentManager\\Model\\Entity\\Page'); $pages = $pageRepo->findBy(array('module' => $this->componentName, 'type' => \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION)); //Pages already exists so no need of adding pages again if (!empty($pages)) { return; } // does the module repository have something for us? if (!$this->loadPagesFromModuleRepository($id)) { $nodeRepo = $em->getRepository('\\Cx\\Core\\ContentManager\\Model\\Entity\\Node'); // if not: create an empty page $parcat = $nodeRepo->getRoot(); $newnode = new \Cx\Core\ContentManager\Model\Entity\Node(); $newnode->setParent($parcat); // replace root node by parent! $em->persist($newnode); $em->flush(); $nodeRepo->moveDown($newnode, true); // move to the end of this level foreach (\FWLanguage::getActiveFrontendLanguages() as $lang) { if ($lang['is_default'] === 'true' || $lang['fallback'] == null) { $type = \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION; } else { $type = \Cx\Core\ContentManager\Model\Entity\Page::TYPE_FALLBACK; } $page = $pageRepo->createPage($newnode, $lang['id'], $this->componentName, $type, $this->componentName, '', false, ''); $em->persist($page); } $em->flush(); } }