コード例 #1
0
ファイル: CmsInstaller.php プロジェクト: svobodni/web
 /**
  * @param IModule $module
  */
 public function uninstall(IModule $module)
 {
     if (!$this->context->hasService('doctrine') || !$this->context->doctrine->createCheckConnection()) {
         throw new \Exception('Database connection not found!');
     }
     $layouts = $this->templateManager->getLayoutsByModule($module->getName());
     $repository = $this->getTemplateRepository();
     foreach ($layouts as $path => $name) {
         foreach ($repository->findBy(array('file' => $path)) as $entity) {
             $repository->delete($entity);
         }
     }
 }
コード例 #2
0
ファイル: Solver.php プロジェクト: svobodni/web
 /**
  * @param IModule $module
  * @param Problem $problem
  * @throws InvalidArgumentException
  */
 public function testUpgrade(IModule $module, Problem $problem = NULL)
 {
     $installedModules =& $this->installedModules;
     $modules =& $this->modules;
     foreach ($module->getRequire() as $name => $require) {
         $requires = VersionHelpers::normalizeRequire($require);
         if (!isset($installedModules[$name])) {
             if ($problem && isset($modules[$name])) {
                 try {
                     $solver = $this->createSolver();
                     $solver->testInstall($modules[$name], $problem);
                 } catch (InvalidArgumentException $e) {
                     throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' which is not installed.");
                 }
                 $job = new Job(Job::ACTION_INSTALL, $modules[$name]);
                 if (!$problem->hasSolution($job)) {
                     $problem->addSolution($job);
                 }
                 $installedModules[$name] = $modules[$name];
                 $tr = array($this->libsDir => '%libsDir%', $this->modulesDir => '%modulesDir%');
                 $this->modulesConfig[$name] = array(ModuleManager::MODULE_STATUS => ModuleManager::STATUS_INSTALLED, ModuleManager::MODULE_ACTION => ModuleManager::ACTION_NONE, ModuleManager::MODULE_CLASS => $module->getClassName(), ModuleManager::MODULE_VERSION => $module->getVersion(), ModuleManager::MODULE_PATH => str_replace(array_keys($tr), array_merge($tr), $module->getPath()), ModuleManager::MODULE_AUTOLOAD => str_replace(array_keys($tr), array_merge($tr), $module->getAutoload()), ModuleManager::MODULE_REQUIRE => $module->getRequire());
             } else {
                 throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' which is not installed.");
             }
         }
         foreach ($requires as $items) {
             foreach ($items as $operator => $version) {
                 $dVersion = $this->modulesConfig[$name][ModuleManager::MODULE_VERSION];
                 if (!version_compare($dVersion, $version, $operator)) {
                     if (!version_compare($installedModules[$name]->getVersion(), $version, $operator)) {
                         throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' with version '{$require}'. Current version is '{$dVersion}'.");
                     }
                     // dependency must be upgraded
                     if ($problem && isset($modules[$name])) {
                         try {
                             $solver = $this->createSolver();
                             $solver->testUpgrade($modules[$name], $problem);
                         } catch (InvalidArgumentException $e) {
                             throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' with version '{$require}'. Current version is '{$dVersion}'.");
                         }
                         $job = new Job(Job::ACTION_UPGRADE, $modules[$name]);
                         if (!$problem->hasSolution($job)) {
                             $problem->addSolution($job);
                         }
                         $this->modulesConfig[$name][ModuleManager::MODULE_VERSION] = $modules[$name]->getVersion();
                     } else {
                         throw new InvalidArgumentException("Module '{$module->getName()}' depend on '{$name}' with version '{$require}'. Current version is '{$dVersion}'.");
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: DoctrineInstaller.php プロジェクト: svobodni/web
 /**
  * @param \Venne\Module\IModule $module
  * @return array
  * @throws \Exception
  */
 protected function getClasses(IModule $module)
 {
     // find files
     $robotLoader = new \Nette\Loaders\RobotLoader();
     $robotLoader->setCacheStorage(new \Nette\Caching\Storages\MemoryStorage());
     $robotLoader->addDirectory($module->getPath());
     $robotLoader->register();
     $entities = $robotLoader->getIndexedClasses();
     // paths
     $paths = array();
     foreach (\Nette\Utils\Finder::findFiles('*Entity.php')->from($module->getPath())->exclude('vendor/*')->exclude('tests/*') as $file) {
         $paths[] = $file->getPath();
     }
     $this->entityManager->getConfiguration()->getMetadataDriverImpl()->addPaths($paths);
     // classes
     $classes = array();
     foreach ($entities as $class => $item) {
         if (\Nette\Reflection\ClassType::from($class)->hasAnnotation('ORM\\Entity')) {
             $classes[] = $class;
         }
     }
     $robotLoader->unregister();
     return $classes;
 }
コード例 #4
0
ファイル: ModuleManager.php プロジェクト: svobodni/web
 /**
  * @param IModules[] $modules
  * @param IModule $module
  * @throws InvalidArgumentException
  */
 public function matchModulesWithModule($modules, IModule $module)
 {
     foreach ($modules as $sourceModule) {
         foreach ($sourceModule->getRequire() as $name => $require) {
             if ($name !== $module->getName()) {
                 continue;
             }
             $requires = VersionHelpers::normalizeRequire($require);
             foreach ($requires as $items) {
                 foreach ($items as $operator => $version) {
                     if (!version_compare($module->getVersion(), $version, $operator)) {
                         throw new InvalidArgumentException("Module '{$sourceModule->getName()}' depend on '{$module->getName()}' with version '{$require}'. Current version is '{$module->getVersion()}'.");
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
ファイル: BaseInstaller.php プロジェクト: svobodni/web
 /**
  * @param \Venne\Module\IModule $module
  */
 public function uninstall(IModule $module)
 {
     $name = $module->getName();
     $configuration = $module->getConfiguration();
     // update main config.neon
     if (count($configuration) > 0) {
         $orig = $data = $this->loadConfig();
         $data = $this->getRecursiveDiff($data, $configuration);
         // remove extension parameters
         $configuration = $module->getConfiguration();
         if (isset($configuration['extensions'])) {
             foreach ($configuration['extensions'] as $key => $values) {
                 if (isset($data[$key])) {
                     unset($data[$key]);
                 }
             }
         }
         $this->saveConfig($data);
         $this->actions[] = function ($self) use($orig) {
             $self->saveConfig($orig);
         };
     }
     // remove resources dir
     $resourcesDir = $this->resourcesDir . "/{$name}Module";
     if (file_exists($resourcesDir)) {
         if (is_link($resourcesDir)) {
             unlink($resourcesDir);
         } else {
             File::rmdir($resourcesDir, TRUE);
         }
     }
 }