Example #1
0
 /**
  * execute command
  * 
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $options['unlimited'] = true;
     $options['list_for'] = 'admin';
     $SitesDb = new \System\Core\Models\SitesDb($this->Db);
     $site_list = $SitesDb->listSites($options);
     unset($SitesDb, $options);
     if (is_array($site_list) && array_key_exists('total', $site_list) && $site_list['total'] > '0' && array_key_exists('items', $site_list)) {
         $output->writeln('There are total ' . $site_list['total'] . ' sites in db.');
         $output->writeln('------------------------------');
         $Table = new \Symfony\Component\Console\Helper\Table($output);
         $list_site_rows = [];
         foreach ($site_list['items'] as $row) {
             if ($row->site_status == '2') {
                 $site_status = 'Maintenance';
             } elseif ($row->site_status == '1') {
                 $site_status = 'Enabled';
             } else {
                 $site_status = 'Disabled';
             }
             $list_site_rows[] = [$row->site_id, $row->site_name, $row->site_domain, $site_status];
             unset($site_status);
         }
         // endforeach;
         $Table->setHeaders(['Site ID', 'Site name', 'Domain', 'Status'])->setRows($list_site_rows);
         $Table->render();
         unset($list_site_rows, $row, $Table);
     } else {
         $output->writeln('<error>Unable to list site or there is no site.</error>');
     }
     unset($site_list);
 }
 /**
  * disable module on multiple sites.
  * 
  * @param OutputInterface $output
  * @param string $module_system_name module system name same as module folder name.
  * @param array $site_ids array of site ids.
  * @return int return number of updated count.
  */
 private function disableModuleSites(OutputInterface $output, $module_system_name, array $site_ids = [])
 {
     $output_count = 0;
     // get all site ids for checking. ------------------------------------------
     $options['list_for'] = 'admin';
     $options['unlimited'] = true;
     $SitesDb = new \System\Core\Models\SitesDb($this->Db);
     $list_sites = $SitesDb->listSites($options);
     unset($options);
     $sites = [];
     if (is_array($list_sites) && array_key_exists('items', $list_sites)) {
         foreach ($list_sites['items'] as $row) {
             $sites = array_merge($sites, [$row->site_id]);
         }
         unset($row);
     }
     unset($list_sites, $SitesDb);
     // get selected module where site_ids are in ---------------------------
     if (!empty($site_ids)) {
         $options['module_system_name'] = $module_system_name;
         $options['list_for'] = 'admin';
         $options['site_ids'] = $site_ids;
         $options['unlimited'] = true;
         $ModulesDb = new \System\Core\Models\ModulesDb($this->Db);
         $list_modules = $ModulesDb->listModulesQb($options);
         unset($options);
         $module_site_ids = [];
         if (is_array($list_modules) && array_key_exists('items', $list_modules)) {
             foreach ($list_modules['items'] as $row) {
                 $module_id = $row->module_id;
                 $module_site_ids = array_merge($module_site_ids, [$row->site_id]);
             }
             unset($row);
         }
     }
     unset($list_modules, $ModulesDb);
     // check the sites, site_ids values before change status. --------------
     if (!empty($site_ids)) {
         // there are site ids specified. check that site_id is really in the `sites` table.
         foreach ($site_ids as $site_id) {
             if ($site_id != null && in_array($site_id, $sites)) {
                 // selected site id is exists in sites table. it is real site which means ok to update.
                 if (isset($module_id) && intval($module_id) != '0') {
                     if (in_array($site_id, $module_site_ids)) {
                         // this module and site id is already exists in db. yeah you are able to disable it.
                         $result = $this->disableModuleSite($output, intval($module_id), intval($site_id));
                         $sites = array_diff($sites, [$site_id]);
                         if ($result === true) {
                             $output_count++;
                         }
                     } elseif (!in_array($site_id, $module_site_ids)) {
                         // this module had never added to this site, use add and then disable.
                         $result = $this->addDisableModuleSite($output, intval($module_id), intval($site_id));
                         $sites = array_diff($sites, [$site_id]);
                         if ($result === true) {
                             $output_count++;
                         }
                     }
                 }
             }
         }
         // endforeach;
         unset($site_id);
     }
     unset($module_site_ids, $result, $sites);
     return $output_count;
 }
Example #3
0
 /**
  * get the routes from db. the routes in db will be generate to file automatically for future use.
  */
 protected function getRoutes()
 {
     // setup international uri and language.
     $this->i18nUri();
     if ($this->Profiler != null) {
         $this->Profiler->Console->timeload('Initialize the routes.', __FILE__, __LINE__);
         $this->Profiler->Console->memoryUsage('Initialize the routes.', __FILE__, __LINE__ - 1);
     }
     // register autoload for enabled modules.
     $module = new \System\Libraries\Modules($this->Silexapp);
     $module->registerAutoload();
     unset($module);
     $Silexapp = $this->Silexapp;
     $this->Silexapp->register(new \Silex\Provider\ServiceControllerServiceProvider());
     // built-in routes. ---------------------------------------------
     $Silexapp['SystemCoreControllersErrorE403.Controller'] = function () use($Silexapp) {
         $controller = new \System\Core\Controllers\Error\E403($Silexapp);
         return $controller;
     };
     $Silexapp->match('/Error/E403', 'SystemCoreControllersErrorE403.Controller:indexAction')->bind('error_403');
     $Silexapp->match('/Error/E403/siteDisabled', 'SystemCoreControllersErrorE403.Controller:siteDisabledAction')->bind('error_403_sitedisabled');
     $Silexapp['SystemCoreControllersErrorE404.Controller'] = function () use($Silexapp) {
         $controller = new \System\Core\Controllers\Error\E404($Silexapp);
         return $controller;
     };
     $Silexapp->match('/Error/E404', 'SystemCoreControllersErrorE404.Controller:indexAction')->bind('error_404');
     // end built-in routes. -----------------------------------------
     // check current site enabled.
     $SitesDb = new \System\Core\Models\SitesDb($this->Silexapp['Db']);
     if (!$SitesDb->isSiteEnabled(true)) {
         $request = new \Symfony\Component\HttpFoundation\Request();
         $subrequest = $request->create('/Error/E403/siteDisabled');
         $response = $Silexapp->handle($subrequest, \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, false);
         $response->send();
         unset($request, $response, $Silexapp, $subrequest);
         exit;
     }
     unset($SitesDb);
     // routes in db.
     $routedb = new \System\Core\Models\RoutesDb($this->Silexapp['Db']);
     $route_file = $routedb->getRoutesFile();
     if ($route_file != null) {
         include $route_file;
     }
     unset($route_file, $routedb, $Silexapp);
     // handle errors
     $this->handleErrors();
     if ($this->Profiler != null) {
         $this->Profiler->Console->timeload('Finished the routes.', __FILE__, __LINE__);
         $this->Profiler->Console->memoryUsage('Finished the routes.', __FILE__, __LINE__ - 1);
     }
 }
Example #4
0
 /**
  * prepare to add module for multiple sites.
  * 
  * @param \Symfony\Component\Console\Output\OutputInterface $output symfony output interface.
  * @param string $module_system_name module systen name.
  * @param array $module_metadata module metadata.
  * @param array $site_ids array of site id that will be enabled.
  * @return integer return number of sites per module that were added.
  */
 private function prepareAddModuleSites(OutputInterface $output, $module_system_name, array $module_metadata, array $site_ids = [])
 {
     $output_count = 0;
     $output_subtracted = 0;
     // get all site ids for checking and adding. ----------------
     $options['list_for'] = 'admin';
     $options['unlimited'] = true;
     $SitesDb = new \System\Core\Models\SitesDb($this->Db);
     $list_sites = $SitesDb->listSites($options);
     unset($options);
     $sites = [];
     if (is_array($list_sites) && array_key_exists('items', $list_sites)) {
         foreach ($list_sites['items'] as $row) {
             $sites = array_merge($sites, [$row->site_id]);
         }
         unset($row);
     }
     unset($list_sites, $SitesDb);
     // check module exists or not -------------------------------
     $options['module_system_name'] = $module_system_name;
     $ModulesDb = new \System\Core\Models\ModulesDb($this->Db);
     $module = $ModulesDb->getModule($options);
     unset($ModulesDb, $options);
     $module_id = null;
     $module_site_ids = [];
     if ($module == null || empty($module)) {
         // module not exists.
         $module_id = null;
         $module_site_ids = $site_ids;
     } else {
         // module exists.
         $module_id = $module->module_id;
         $module_site_ids = $site_ids;
         if (is_array($module) || is_object($module) && property_exists($module, 'module_sites') && is_array($module->module_sites)) {
             foreach ($module->module_sites as $row) {
                 if (in_array($row->site_id, $site_ids)) {
                     // current site_id in module_sites table is in add list.
                     $module_site_ids = array_diff($module_site_ids, [$row->site_id]);
                     $output_subtracted++;
                 }
             }
             // endforeach;
             unset($row);
         }
     }
     unset($module);
     // end check module exists or not --------------------------
     // check for site id is in real sites table. --------------------
     if (!empty($site_ids)) {
         // now, loop to check again that site_id add list that is really exists in sites table.
         foreach ($module_site_ids as $site_id) {
             if (!in_array($site_id, $sites)) {
                 // site_id in add list is not really exists in sites table, remove it.
                 $module_site_ids = array_diff($module_site_ids, [$site_id]);
             }
         }
         // endforeach;
         unset($site_id);
     } else {
         $module_site_ids = $sites;
     }
     // really add module to sites. --------------------------------
     $result = $this->addModuleSites($output, $module_system_name, $module_metadata, $module_id, $module_site_ids);
     if ($result === true) {
         $output_count = count($module_site_ids);
     }
     unset($module_id, $module_site_ids, $result, $sites);
     return $output_count + $output_subtracted;
 }