public function getKeys(\common_ext_Extension $ext)
 {
     $data = array();
     $path = CONFIG_PATH . $ext->getId();
     if (file_exists($path)) {
         foreach (new \DirectoryIterator($path) as $fileinfo) {
             if (!$fileinfo->isDot() && substr($fileinfo->getFilename(), -strlen('.conf.php')) == '.conf.php') {
                 $key = substr($fileinfo->getFilename(), 0, -strlen('.conf.php'));
                 $data[] = array('data' => $key, 'attributes' => array('id' => $key, 'class' => 'node-instance'));
             }
         }
     }
     return $data;
 }
Exemplo n.º 2
0
 /**
  * Check if extension requirements are met
  * Always returns true, but throws exception on error
  *
  * @param common_ext_Extension $extension
  * @throws common_ext_MissingExtensionException
  * @throws common_ext_OutdatedVersionException
  * @throws common_exception_Error
  * @return boolean
  */
 public static function checkRequiredExtensions(common_ext_Extension $extension)
 {
     $extensionManager = common_ext_ExtensionsManager::singleton();
     foreach ($extension->getDependencies() as $requiredExt => $requiredVersion) {
         $installedVersion = $extensionManager->getInstalledVersion($requiredExt);
         if (is_null($installedVersion)) {
             throw new common_ext_MissingExtensionException('Extension ' . $requiredExt . ' is needed by the extension to be installed but is missing.', 'GENERIS');
         }
         if ($requiredVersion != '*') {
             $matches = array();
             preg_match('/[0-9\\.]+/', $requiredVersion, $matches, PREG_OFFSET_CAPTURE);
             if (count($matches) == 1) {
                 $match = current($matches);
                 $nr = $match[0];
                 $operator = $match[1] > 0 ? substr($requiredVersion, 0, $match[1]) : '=';
                 if (!version_compare($installedVersion, $nr, $operator)) {
                     throw new common_ext_OutdatedVersionException('Installed version of ' . $requiredExt . ' ' . $installedVersion . ' does not satisfy required ' . $requiredVersion . ' for ' . $extension->getId());
                 }
             } else {
                 throw new common_exception_Error('Unsupported version requirement: "' . $requiredVersion . '"');
             }
         }
     }
     // always return true, or throws an exception
     return true;
 }
Exemplo n.º 3
0
 /**
  * Helper to find all controllers
  * 
  * @param \common_ext_Extension $extension
  * @return array
  * @ignore
  */
 private function getControllerClasses(\common_ext_Extension $extension)
 {
     $returnValue = array();
     // routes
     $namespaces = array();
     foreach ($extension->getManifest()->getRoutes() as $mapedPath => $ns) {
         $namespaces[] = trim($ns, '\\');
     }
     if (!empty($namespaces)) {
         common_Logger::t('Namespace found in routes for extension ' . $extension->getId());
         $classes = array();
         $recDir = new RecursiveDirectoryIterator($extension->getDir());
         $recIt = new RecursiveIteratorIterator($recDir);
         $regexIt = new RegexIterator($recIt, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH);
         foreach ($regexIt as $entry) {
             $info = helpers_PhpTools::getClassInfo($entry[0]);
             if (!empty($info['ns'])) {
                 $ns = trim($info['ns'], '\\');
                 if (!empty($info['ns']) && in_array($ns, $namespaces)) {
                     $returnValue[$info['class']] = $ns . '\\' . $info['class'];
                 }
             }
         }
     }
     // legacy
     if ($extension->hasConstant('DIR_ACTIONS') && file_exists($extension->getConstant('DIR_ACTIONS'))) {
         $dir = new DirectoryIterator($extension->getConstant('DIR_ACTIONS'));
         foreach ($dir as $fileinfo) {
             if (preg_match('/^class\\.[^.]*\\.php$/', $fileinfo->getFilename())) {
                 $module = substr($fileinfo->getFilename(), 6, -4);
                 $returnValue[$module] = $extension->getId() . '_actions_' . $module;
             }
         }
     }
     // validate the classes
     foreach (array_keys($returnValue) as $key) {
         $class = $returnValue[$key];
         if (!class_exists($class)) {
             common_Logger::w($class . ' not found');
             unset($returnValue[$key]);
         } elseif (!is_subclass_of($class, 'Module')) {
             common_Logger::w($class . ' does not inherit Module');
             unset($returnValue[$key]);
         } else {
             // abstract so just move along
             $reflection = new \ReflectionClass($class);
             if ($reflection->isAbstract()) {
                 unset($returnValue[$key]);
             }
         }
     }
     return (array) $returnValue;
 }
Exemplo n.º 4
0
 public function updateVersion(common_ext_Extension $extension, $version)
 {
     $extensions = $this->getExtensionById('generis')->getConfig(self::EXTENSIONS_CONFIG_KEY);
     $extensions[$extension->getId()]['installed'] = $version;
     $this->getExtensionById('generis')->setConfig(self::EXTENSIONS_CONFIG_KEY, $extensions);
 }
Exemplo n.º 5
0
 /**
  * 
  * @param common_ext_Extension $extension
  * @return common_persistence_KeyValuePersistence
  */
 public static function getPersistence(common_ext_Extension $extension)
 {
     $driver = new self($extension);
     return $driver->connect('config_' . $extension->getId(), array('dir' => CONFIG_PATH . $extension->getId(), 'humanReadable' => true));
 }
Exemplo n.º 6
0
 /**
  * Whenever or not the extension is required to be enabled
  * by other enabled extensions
  * 
  * @param common_ext_Extension $extension
  * @return boolean
  */
 public static function mustBeEnabled(common_ext_Extension $extension)
 {
     foreach (common_ext_ExtensionsManager::singleton()->getEnabledExtensions() as $ext) {
         foreach ($ext->getDependencies() as $extId => $version) {
             if ($extId == $extension->getId()) {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 7
0
 protected function buildExtensionData(common_ext_Extension $extension, $roleUri, $includedRoleUris)
 {
     $extAccess = funcAcl_helpers_Cache::getExtensionAccess($extension->getId());
     $extAclUri = funcAcl_models_classes_AccessService::singleton()->makeEMAUri($extension->getId());
     $atLeastOneAccess = false;
     $allAccess = in_array($roleUri, $extAccess);
     $inherited = count(array_intersect($includedRoleUris, $extAccess)) > 0;
     $controllers = array();
     foreach (ControllerHelper::getControllers($extension->getId()) as $controllerClassName) {
         $controllerData = $this->buildControllerData($controllerClassName, $roleUri, $includedRoleUris);
         $atLeastOneAccess = $atLeastOneAccess || $controllerData['access'] != self::ACCESS_NONE;
         $controllers[] = $controllerData;
     }
     usort($controllers, function ($a, $b) {
         return strcmp($a['label'], $b['label']);
     });
     $access = $inherited ? 'inherited' : ($allAccess ? 'full' : ($atLeastOneAccess ? 'partial' : 'none'));
     return array('uri' => $extAclUri, 'label' => $extension->getName(), 'access' => $access, 'modules' => $controllers);
 }
Exemplo n.º 8
0
 /**
  * Add the end of an uninstallation unregister the extension
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param common_ext_Extension $extension
  * @return boolean
  */
 public function unregisterExtension(common_ext_Extension $extension)
 {
     $extensions = $this->getExtensionById('generis')->getConfig(self::EXTENSIONS_CONFIG_KEY);
     unset($extensions[$extension->getId()]);
     $this->getExtensionById('generis')->setConfig(self::EXTENSIONS_CONFIG_KEY, $extensions);
 }
Exemplo n.º 9
0
 /**
  * Helper to find all controllers
  * 
  * @param \common_ext_Extension $extension
  * @return array
  * @ignore
  */
 private function getControllerClasses(\common_ext_Extension $extension)
 {
     $returnValue = array();
     // routes
     $namespaces = array();
     foreach ($extension->getManifest()->getRoutes() as $mapedPath => $ns) {
         if (is_string($ns)) {
             $namespaces[] = trim($ns, '\\');
         }
     }
     if (!empty($namespaces)) {
         common_Logger::t('Namespace found in routes for extension ' . $extension->getId());
         $classes = array();
         $recDir = new RecursiveDirectoryIterator($extension->getDir());
         $recIt = new RecursiveIteratorIterator($recDir);
         $regexIt = new RegexIterator($recIt, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH);
         foreach ($regexIt as $entry) {
             $info = helpers_PhpTools::getClassInfo($entry[0]);
             if (!empty($info['ns'])) {
                 $ns = trim($info['ns'], '\\');
                 if (!empty($info['ns']) && in_array($ns, $namespaces)) {
                     $returnValue[$info['class']] = $ns . '\\' . $info['class'];
                 }
             }
         }
     }
     // legacy
     if ($extension->hasConstant('DIR_ACTIONS') && file_exists($extension->getConstant('DIR_ACTIONS'))) {
         $dir = new DirectoryIterator($extension->getConstant('DIR_ACTIONS'));
         foreach ($dir as $fileinfo) {
             if (preg_match('/^class\\.[^.]*\\.php$/', $fileinfo->getFilename())) {
                 $module = substr($fileinfo->getFilename(), 6, -4);
                 $returnValue[$module] = $extension->getId() . '_actions_' . $module;
             }
         }
     }
     $returnValue = array_filter($returnValue, array($this, 'isControllerClassNameValid'));
     return (array) $returnValue;
 }