Пример #1
0
 /**
  * @param Server $server
  *
  * @return array|Module[]
  */
 protected function defaultModules(Server $server)
 {
     $serverModules = [];
     /** @var Module[] $modules */
     $modules = $this->getRepository('App:Module')->findBy(['defaultEnabled' => true]);
     foreach ($modules as $module) {
         $serverModule = new ServerModule();
         $serverModule->setModule($module);
         $serverModule->setServer($server);
         $serverModule->setEnabled($module->getDefaultEnabled());
         $this->getManager()->persist($serverModule);
         $serverModules[] = $serverModule;
     }
     return $serverModules;
 }
Пример #2
0
 private function updateModules()
 {
     $this->output->text('Attempting to updating modules');
     /** @var EntityManager|DocumentManager $manager */
     $manager = $this->getContainer()->get('default_manager');
     $repo = $manager->getRepository('App:Module');
     foreach ($this->getContainer()->getParameter('kernel.modules') as $module) {
         if (empty($repo->findOneBy(['name' => $module::getModuleName()]))) {
             $this->output->text('New module discovered. Adding to database.');
             $this->addModule($module);
         }
     }
     /** @var Module[] $modules */
     $modules = $manager->getRepository('App:Module')->findAll();
     /** @var Server[] $servers */
     $servers = $manager->getRepository($this->getContainer()->getParameter('server_class'))->findAll();
     foreach ($servers as $server) {
         foreach ($modules as $module) {
             if (!$server->hasModule($module)) {
                 $serverModule = new ServerModule();
                 $serverModule->setModule($module);
                 $serverModule->setServer($server);
                 $serverModule->setEnabled($module->getDefaultEnabled());
                 $manager->persist($serverModule);
                 $server->addModule($serverModule);
                 $manager->persist($server);
             }
         }
     }
     $manager->flush();
 }