Ejemplo n.º 1
0
 /**
  * execute command
  * 
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $options['unlimited'] = true;
     $options['list_for'] = 'admin';
     $ModulesDb = new \System\Core\Models\ModulesDb($this->Db);
     $module_list = $ModulesDb->listModulesQb($options);
     unset($ModulesDb, $options);
     if (is_array($module_list) && array_key_exists('total', $module_list) && $module_list['total'] > '0' && array_key_exists('items', $module_list)) {
         $output->writeln('There are total ' . $module_list['total'] . ' modules in db.');
         $output->writeln('------------------------------');
         foreach ($module_list['items'] as $row) {
             $output->write('ID: "' . $row->module_id . '"');
             $output->write(' Module: "' . $row->module_system_name . '"');
             $output->writeln(' Version: "' . $row->module_version . '"');
             // module in each sites.
             if (property_exists($row, 'module_sites')) {
                 $Table = new \Symfony\Component\Console\Helper\Table($output);
                 $Table->setHeaders(['Site ID', 'Enabled']);
                 foreach ($row->module_sites as $msrow) {
                     $Table->addRows([[$msrow->site_id, $msrow->module_enable == '1' ? 'Yes' : 'No']]);
                 }
                 // endforeach;
                 unset($msrow);
                 $Table->render();
                 unset($Table);
                 $output->writeln('------------------------------');
             }
         }
         // endforeach;
         unset($row);
     } else {
         $output->writeln('<error>Unable to list module or there is no module.</error>');
     }
     unset($module_list);
 }
Ejemplo n.º 2
0
 /**
  * load functions file.
  * 
  * @param mixed $file path to file name start from inside module. this can be file name (string) or multiple file names (array).
  * @param string $module module name.
  * @param boolean $load_again set to false to require_once, set to true to require. use false to prevent function/class exists.
  * @return boolean return true on success loading, return false on failed loading.
  */
 public function loadFunctions($file, $module = '', $load_again = false)
 {
     if (is_array($file)) {
         $last = false;
         foreach ($file as $a_file) {
             $last = $this->loadFunctions($a_file, $module, $load_again);
         }
         return $last;
     }
     $this->Db = $this->Silexapp['Db'];
     if ($module != null) {
         // load function on specified module. check that module is enabled.
         $cache = new \System\Libraries\Cache();
         $cache->setSubFolder('system/Libraries/Modules.php');
         if ($cache->contains('Modules-registerAutoload-' . $this->Db->getCurrentSiteId())) {
             $modules_list = $cache->fetch('Modules-registerAutoload-' . $this->Db->getCurrentSiteId());
         } else {
             $moduledb = new \System\Core\Models\ModulesDb($this->Db);
             $options['module_enable'] = 1;
             $options['site_id'] = intval($this->Db->getCurrentSiteId());
             $options['unlimited'] = true;
             $modules_list = $moduledb->listModulesQb($options);
             $cache->save('Modules-registerAutoload-' . $this->Db->getCurrentSiteId(), $modules_list, 60 * 60 * 24 * 30);
             unset($moduledb, $options);
         }
         if (is_array($modules_list) && array_key_exists('items', $modules_list) && is_array($modules_list['items'])) {
             foreach ($modules_list['items'] as $row) {
                 if ($module == $row->module_system_name) {
                     // found in module enabled.
                     $module_found = true;
                     break;
                 }
             }
             // endforeach;
             unset($row);
         }
         unset($cache, $modules_list);
         if (!isset($module_found) || isset($module_found) && $module_found == false) {
             return false;
         }
     }
     if ($module == null) {
         $file = SYSTEM_PATH . DS . 'Functions' . DS . $file;
     } else {
         $file = MODULE_PATH . DS . $module . DS . 'Functions' . DS . $file;
     }
     return $this->loadFile($file, $load_again);
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * get all available modules.
  * 
  * @return array return array with total and items in key. items key contain list of all modules available.
  */
 public function getAllAvailableModules()
 {
     $this->Db = $this->Silexapp['Db'];
     $cache = new \System\Libraries\Cache();
     $cache->setSubFolder('system/Libraries/Modules.php');
     if ($cache->contains('Modules-registerAutoload-' . $this->Db->getCurrentSiteId())) {
         $modules_list = $cache->fetch('Modules-registerAutoload-' . $this->Db->getCurrentSiteId());
     } else {
         $moduledb = new \System\Core\Models\ModulesDb($this->Db);
         $options['module_enable'] = 1;
         $options['site_id'] = intval($this->Db->getCurrentSiteId());
         $options['unlimited'] = true;
         $modules_list = $moduledb->listModulesQb($options);
         $cache->save('Modules-registerAutoload-' . $this->Db->getCurrentSiteId(), $modules_list, 60 * 60 * 24 * 30);
         unset($moduledb, $options);
     }
     unset($cache, $this->Db);
     return $modules_list;
 }