drop support for php 7.4 (#5740)
[openemr.git] / interface / modules / zend_modules / module / Installer / src / Installer / Controller / InstallerController.php
blob8392a2456bca009516cdc08040a57b24d06befe7
1 <?php
3 /**
4 * interface/modules/zend_modules/module/Installer/src/Installer/Controller/InstallerController.php
6 * @package OpenEMR
7 * @link https://www.open-emr.org
8 * @author Jacob T.Paul <jacob@zhservices.com>
9 * @author Vipin Kumar <vipink@zhservices.com>
10 * @author Remesh Babu S <remesh@zhservices.com>
11 * @author Jerry Padgett <sjpadgett@gmail.com>
12 * @copyright Copyright (c) 2020 Jerry Padgett <sjpadgett@gmail.com>
13 * @copyright Copyright (c) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 namespace Installer\Controller;
19 use Laminas\Mvc\Controller\AbstractActionController;
20 use Laminas\View\Model\ViewModel;
21 use Laminas\View\Model\JsonModel;
22 use Laminas\Json\Json;
23 use Installer\Model\InstModule;
24 use Application\Listener\Listener;
25 use Installer\Model\InstModuleTable;
26 use Laminas\Db\Adapter\Adapter;
27 use OpenEMR\Common\Acl\AclMain;
28 use OpenEMR\Common\Utils\RandomGenUtils;
29 use OpenEMR\Services\Utils\SQLUpgradeService;
31 class InstallerController extends AbstractActionController
33 /**
34 * @var InstModuleTable
36 protected $InstallerTable;
37 protected $listenerObject;
39 /**
40 * @var Laminas\Db\Adapter\Adapter
42 private $dbAdapter;
44 public function __construct(InstModuleTable $installerTable)
46 $this->listenerObject = new Listener();
47 $this->InstallerTable = $installerTable;
48 $this->dbAdapter = $adapter ?? null;
51 public function nolayout()
53 // Turn off the layout, i.e. only render the view script.
54 $viewModel = new ViewModel();
55 $viewModel->setTerminal(true);
56 return $viewModel;
59 public function indexAction()
61 //get the list of installed and new modules
62 $result = $this->getInstallerTable()->allModules();
64 $allModules = array();
65 foreach ($result as $dataArray) {
66 $mod = new InstModule();
67 $mod->exchangeArray($dataArray);
68 $mod = $this->makeButtonForSqlAction($mod);
69 $mod = $this->makeButtonForAClAction($mod);
70 array_push($allModules, $mod);
73 return new ViewModel(array(
74 'InstallersExisting' => $allModules,
75 'InstallersAll' => $allModules,
76 'listenerObject' => $this->listenerObject,
77 'dependencyObject' => $this->getInstallerTable(),
78 // TODO: @adunsulag there should be a way to pull this from application.config.php but so far the answer eludes me.
79 'coreModules' => ['Application', 'Acl', 'Installer', 'FHIR', 'PatientFlowBoard']
80 ));
83 /**
84 * @return Installer\Model\InstModuleTable
86 public function getInstallerTable(): InstModuleTable
88 return $this->InstallerTable;
91 public function registerAction()
93 if (!AclMain::aclCheckCore('admin', 'manage_modules')) {
94 echo xlt('Not Authorized');
95 exit;
98 $status = false;
99 $request = $this->getRequest();
100 if (method_exists($request, 'isPost')) {
101 if ($request->getPost('mtype') == 'zend') {
102 // TODO: We want to be able to load the modules
103 // from the database.. however, this can be fairly slow so we might want to do some kind of APC caching of the module
104 // list that is loaded using the OpenEMR db connector and not the zend db connector, cache the modules, and then
105 // we can filter / update that list. We'll have to inject the unloaded module list into the installer but that is fine.
106 $rel_path = "public/" . $request->getPost('mod_name') . "/";
108 // registering the table inserts the module record into the database.
109 // it's always loaded regardless, but it inserts it in the database as not activated
110 if ($this->getInstallerTable()->register($request->getPost('mod_name'), $rel_path, 0, $GLOBALS['zendModDir'])) {
111 $status = true;
113 } else {
114 // TODO: there doesn't appear to be any methodology in how to load these custom registered modules... which seems pretty odd.
115 // there aren't any in the system... but why have this then?
116 $rel_path = $request->getPost('mod_name') . "/index.php";
117 if ($this->getInstallerTable()->register($request->getPost('mod_name'), $rel_path)) {
118 $status = true;
121 die($status ? $this->listenerObject->z_xlt("Success") : $this->listenerObject->z_xlt("Failure"));
122 } else {
123 die("Something went very wrong, so exiting");
127 public function manageAction()
129 if (!AclMain::aclCheckCore('admin', 'manage_modules')) {
130 echo json_encode(["status" => xlt('Not Authorized')]);
131 exit;
134 $outputToBrowser = '';
135 $request = $this->getRequest();
136 $status = $this->listenerObject->z_xlt("Failure");
137 if ($request->isPost()) {
138 if ($request->getPost('modAction') == "enable") {
139 $status = $this->EnableModule($request->getPost('modId'));
140 } elseif ($request->getPost('modAction') == "disable") {
141 $status = $this->DisableModule($request->getPost('modId'));
142 } elseif ($request->getPost('modAction') == "install") {
143 $modId = $request->getPost('modId');
144 $mod_enc_menu = $request->getPost('mod_enc_menu');
145 $mod_nick_name = $request->getPost('mod_nick_name');
146 $status = $this->InstallModule($modId, $mod_enc_menu, $mod_nick_name);
147 } elseif ($request->getPost('modAction') == 'install_sql') {
148 if ($this->InstallModuleSQL($request->getPost('modId'))) {
149 $status = $this->listenerObject->z_xlt("Success");
150 } else {
151 $status = $this->listenerObject->z_xlt("ERROR") . ':' . $this->listenerObject->z_xlt("could not open table") . '.' . $this->listenerObject->z_xlt("sql") . ', ' . $this->listenerObject->z_xlt("broken form") . "?";
153 } elseif ($request->getPost('modAction') == 'upgrade_sql') {
154 $div = $this->UpgradeModuleSQL($request->getPost('modId'));
155 $status = $this->listenerObject->z_xlt("Success");
156 } elseif ($request->getPost('modAction') == 'install_acl') {
157 if ($div = $this->InstallModuleACL($request->getPost('modId'))) {
158 $status = $this->listenerObject->z_xlt("Success");
159 } else {
160 $status = $this->listenerObject->z_xlt("ERROR") . ':' . $this->listenerObject->z_xlt("could not install ACL");
162 } elseif ($request->getPost('modAction') == 'upgrade_acl') {
163 if ($div = $this->UpgradeModuleACL($request->getPost('modId'))) {
164 $status = $this->listenerObject->z_xlt("Success");
165 } else {
166 $status = $this->listenerObject->z_xlt("ERROR") . ':' . $this->listenerObject->z_xlt("could not install ACL");
168 } elseif ($request->getPost('modAction') == "unregister") {
169 $status = $this->UnregisterModule($request->getPost('modId'));
172 $output = "";
173 if (!empty($div) && is_array($div)) {
174 $output = implode("<br />\n", $div);
176 echo json_encode(["status" => $status, "output" => $output]);
177 exit(0);
181 * @param $version
182 * @return int|string
184 function upgradeAclFromVersion($ACL_UPGRADE, $version)
186 $toVersion = '';
187 foreach ($ACL_UPGRADE as $toVersion => $function) {
188 if (version_compare($version, $toVersion) < 0) {
189 $function();
192 return $toVersion;
196 * Function to install ACL for the installed modules
198 * @param string $dir Location of the php file which calling functions to add sections,aco etc.
199 * @return boolean
201 private function installACL($dir)
203 $aclfile = $dir . "/moduleACL.php";
204 if (file_exists($aclfile)) {
205 include_once($aclfile);
210 * Used to recreate the application config file
212 * @param unknown_type $data
213 * @return string
215 private function getContent($data)
217 $string = "";
218 foreach ($data as $key => $value) {
219 $string .= " '$key' => ";
220 if (is_array($value)) {
221 $string .= " array(";
222 $string .= $this->getContent($value);
223 $string .= " )";
224 } else {
225 $string .= "'$value'";
228 $string .= ",";
231 return $string;
234 public function SaveHooksAction()
236 $request = $this->getRequest();
237 $postArr = $request->getPost();
238 //DELETE OLD HOOKS OF A MODULE
239 $this->getInstallerTable()->deleteModuleHooks($postArr['mod_id']);
240 if (!empty($postArr['hook_hanger']) && count($postArr['hook_hanger']) > 0) {
241 foreach ($postArr['hook_hanger'] as $hookId => $hooks) {
242 foreach ($hooks as $hangerId => $hookHanger) {
243 $this->getInstallerTable()->saveHooks($postArr['mod_id'], $hookId, $hangerId);
247 $return[0] = array('return' => 1, 'msg' => $this->listenerObject->z_xlt("Saved Successfully"));
248 } else {
249 $return[0] = array('return' => 1, 'msg' => $this->listenerObject->z_xlt("No Hooks enabled for this Module"));
252 $arr = new JsonModel($return);
253 return $arr;
256 public function configureAction()
258 $request = $this->getRequest();
259 $modId = $request->getPost('mod_id');
261 /** Configuration Details */
262 $result = $this->getInstallerTable()->getConfigSettings($modId);
263 $configuration = array();
264 foreach ($result as $tmp) {
265 $configuration[$tmp['field_name']] = $tmp;
268 //INSERT MODULE HOOKS IF NOT EXISTS
269 $moduleDirectory = $this->getInstallerTable()->getModuleDirectory($modId);
270 //GET MODULE HOOKS FROM A FUNCTION IN CONFIGURATION MODEL CLASS
271 $hooksArr = $this->getInstallerTable()->getModuleHooks($moduleDirectory);
273 if (count($hooksArr) > 0) {
274 foreach ($hooksArr as $hook) {
275 if (count($hook) > 0) {
276 if ($this->getInstallerTable()->checkModuleHookExists($modId, $hook['name']) == "0") {
277 $this->getInstallerTable()->saveModuleHooks($modId, $hook['name'], $hook['title'], $hook['path']);
281 } else {
282 //DELETE ADDED HOOKS TO HANGERS OF THIS MODULE, IF NO HOOKS EXIST IN THIS MODULE
283 $this->getInstallerTable()->deleteModuleHooks($modId);
284 //DELETE MODULE HOOKS
285 $this->getInstallerTable()->deleteModuleHookSettings($modId);
288 //GET MODULE ACL SECTION FROM A FUNCTION IN CONFIGURATION MODEL CLASS
289 $aclArray = $this->getInstallerTable()->getModuleAclSections($moduleDirectory);
290 if (sizeof($aclArray) > 0) {
291 $this->getInstallerTable()->insertAclSections($aclArray, $moduleDirectory, $modId);
292 } else {
293 $this->getInstallerTable()->deleteACLSections($modId);
296 $obj = $this->getInstallerTable()->getObject($moduleDirectory, 'Controller');
297 $aclArray = array();
298 if ($obj) {
299 $aclArray = $obj->getAclConfig();
302 /** Configuration Form and Configuration Form Class */
303 $configForm = $this->getInstallerTable()->getFormObject($moduleDirectory);
305 /** Setup Config Details */
306 $setup = $this->getInstallerTable()->getSetupObject($moduleDirectory);
308 return new ViewModel(array(
309 'mod_id' => $modId,
310 'TabSettings' => $this->getInstallerTable()->getTabSettings($modId),
311 'ACL' => $this->getInstallerTable()->getSettings('ACL', $modId),
312 'OemrUserGroup' => $this->getInstallerTable()->getOemrUserGroup(),
313 'OemrUserGroupAroMap' => $this->getInstallerTable()->getOemrUserGroupAroMap(),
314 'ListActiveUsers' => $this->getInstallerTable()->getActiveUsers(),
315 'ListActiveACL' => $this->getInstallerTable()->getActiveACL($modId),
316 'ListActiveHooks' => $this->getInstallerTable()->getActiveHooks($modId),
317 'helperObject' => $this->helperObject,
318 'configuration' => $configuration,
319 'hangers' => $this->getInstallerTable()->getHangers(),
320 'Hooks' => $hooksArr,
321 'hookObject' => $this->getInstallerTable(),
322 'settings' => $configForm,
323 'listenerObject' => $this->listenerObject,
324 'setup' => $setup,
328 public function saveConfigAction()
330 $request = $this->getRequest();
331 $moduleId = $request->getPost()->module_id;
333 foreach ($request->getPost() as $key => $value) {
334 $fieldName = $key;
335 $fieldValue = $value;
336 if ($fieldName != 'module_id') {
337 $result = $this->getInstallerTable()->saveSettings($fieldName, $fieldValue, $moduleId);
341 $data = array();
342 $returnArr = array('modeId' => $moduleId);
343 $return = new JsonModel($returnArr);
344 return $return;
347 public function DeleteAclAction()
349 $request = $this->getRequest();
350 $this->getInstallerTable()->DeleteAcl($request->getPost());
351 $return[0] = array('return' => 1, 'msg' => $this->listenerObject->z_xlt("Deleted Successfully"));
352 $arr = new JsonModel($return);
353 return $arr;
356 public function DeleteHooksAction()
358 $request = $this->getRequest();
359 $this->getInstallerTable()->DeleteHooks($request->getPost());
360 $return[0] = array('return' => 1, 'msg' => $this->listenerObject->z_xlt("Deleted Successfully"));
361 $arr = new JsonModel($return);
362 return $arr;
365 public function nickNameAction()
367 $request = $this->getRequest();
368 $nickname = $request->getPost()->nickname;
369 echo $this->getInstallerTable()->validateNickName(trim($nickname));
370 exit(0);
373 function getModuleVersionFromFile($modId)
375 //SQL version of Module
376 $dirModule = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory");
377 $ModulePath = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $dirModule->modDirectory;
379 $version_of_module = $ModulePath . "/version.php";
380 $table_sql = $ModulePath . "/table.sql";
381 $install_sql = $ModulePath . "/sql/install.sql";
382 $install_acl = $ModulePath . "/acl/acl_setup.php";
383 if (file_exists($version_of_module) && (file_exists($table_sql) || file_exists($install_sql) || file_exists($install_acl))) {
384 include_once($version_of_module);
385 $version = $v_major . "." . $v_minor . "." . $v_patch;
386 return $version;
388 return false;
391 public function getFilesForUpgrade($modDirectory, $sqldir)
393 $ModulePath = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $modDirectory;
394 $versions = [];
395 $dh = opendir($sqldir);
396 if (!$dh) {
397 return false;
400 while (false !== ($sfname = readdir($dh))) {
401 if (substr($sfname, 0, 1) == '.') {
402 continue;
405 if (preg_match('/^(\d+)_(\d+)_(\d+)-to-\d+_\d+_\d+_upgrade.sql$/', $sfname, $matches)) {
406 $version = $matches[1] . '.' . $matches[2] . '.' . $matches[3];
407 $versions[$version] = $sfname;
410 $arrayKeys = array_keys($versions);
411 usort($arrayKeys, 'version_compare');
412 $sortVersions = array();
413 foreach ($arrayKeys as $key) {
414 $sortVersions[$key] = $versions[$key];
416 return $sortVersions;
419 public function makeButtonForSqlAction(InstModule $mod)
421 $dirModule = $this->getInstallerTable()->getRegistryEntry($mod->modId, "mod_directory");
422 $ModulePath = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $dirModule->modDirectory;
423 $sqldir = $ModulePath . "/sql";
424 if (!is_dir($sqldir)) {
425 $sqldir = $ModulePath;
427 $mod->sql_action = "";
429 if (file_exists($sqldir . "/install.sql") && file_exists($ModulePath . "/version.php") && empty($mod->sql_version)) {
430 $mod->sql_action = "install";
433 if (!empty($mod->sql_version) && $mod->sqlRun == 1) {
434 $versions = $this->getFilesForUpgrade($mod->modDirectory, $sqldir);
436 if (count($versions) > 0) {
437 foreach ($versions as $version => $sfname) {
438 if (version_compare($version, $mod->sql_version) < 0) {
439 continue;
441 $mod->sql_action = "upgrade";
445 return $mod;
448 public function makeButtonForACLAction(InstModule $mod)
450 $dirModule = $this->getInstallerTable()->getRegistryEntry($mod->modId, "mod_directory");
451 $ModulePath = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $dirModule->modDirectory;
452 $sqldir = $ModulePath . "/acl";
453 $mod->acl_action = "";
455 if (file_exists($sqldir . "/acl_setup.php") && file_exists($ModulePath . "/version.php") && empty($mod->acl_version)) {
456 $mod->acl_action = "install";
458 if (file_exists($sqldir . "/acl_upgrade.php") && file_exists($ModulePath . "/version.php") && !empty($mod->acl_version)) {
459 global $ACL_UPGRADE;
460 // Pass a variable, so below scripts can not be run on their own
461 $aclSetupFlag = true;
462 include_once($sqldir . "/acl_upgrade.php");
464 foreach ($ACL_UPGRADE as $toVersion => $function) {
465 if (version_compare($mod->acl_version, $toVersion) > 0) {
466 continue;
468 $mod->acl_action = "upgrade";
471 return $mod;
475 * @param $moduleName
476 * @return bool
478 public function getModuleId($moduleName)
480 if (empty($moduleName)) {
481 return false;
483 $allModules = $this->getInstallerTable()->allModules();
484 foreach ($allModules as $module) {
485 if ($module["mod_directory"] === $moduleName) {
486 return $module["mod_id"];
492 * @param string $modId
493 * @return bool
495 public function InstallModuleSQL($modId = '')
497 $registryEntry = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory");
498 $dirModule = $registryEntry->modDirectory;
499 $modType = $registryEntry->type;
500 if ($this->getInstallerTable()->installSQL($modId, $modType, $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $dirModule)) {
501 $values = array($registryEntry->mod_nick_name,$registryEntry->mod_enc_menu);
502 $values[2] = $this->getModuleVersionFromFile($modId);
503 $values[3] = $registryEntry->acl_version;
504 $this->getInstallerTable()->updateRegistered($modId, '', $values);
505 return true;
506 } else {
507 return false;
512 * @param string $modId
513 * @return array
515 public function UpgradeModuleSQL($modId = '')
517 $Module = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory");
518 $modDir = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $Module->modDirectory;
519 $sqlInstallLocation = $modDir . '/sql';
520 // if this is a custom module that for some reason doesn't have the SQL in a sql folder...
521 if (!file_exists($sqlInstallLocation)) {
522 $sqlInstallLocation = $modDir;
525 $versions = $this->getFilesForUpgrade($Module->modDirectory, $sqlInstallLocation);
527 $values = array($Module->mod_nick_name,$Module->mod_enc_menu);
528 $div = [];
529 $outputToBrowser = '';
530 foreach ($versions as $version => $filename) {
531 if (version_compare($version, $Module->sql_version) < 0) {
532 continue;
534 ob_start();
535 $sqlUpgradeService = new SQLUpgradeService();
536 $sqlUpgradeService->setRenderOutputToScreen(true);
537 $sqlUpgradeService->upgradeFromSqlFile($filename, $sqlInstallLocation);
538 $outputToBrowser .= ob_get_contents();
539 ob_end_clean();
542 if (preg_match_all("/(.*)\<br \/\>\n/i", $outputToBrowser, $matches)) {
543 $add_query_string = 0;
544 $add_ended_divs = 0;
545 $k = 0;
546 foreach ($matches[1] as $string) {
547 $prev_html_tag = false;
548 if (preg_match("/<([a-z]+).*?>([^<]+)<\/([a-z]+)>/i", $string, $mm)) {
549 if ($add_query_string > 0) {
550 $div[] = "</div>";
551 $add_ended_divs++;
553 $div[] = $string;
554 $prev_html_tag = true;
555 $curr_html_tag = true;
557 if (!$prev_html_tag && $curr_html_tag) {
558 $div[] = "<div class='show_hide_log'>" . xlt("show/hide executed query log") . "</div><div class='spoiler' style='margin-left: 10px' >" . $string;
559 $curr_html_tag = false;
560 } elseif (!$prev_html_tag && !$curr_html_tag) {
561 $div[] = $string;
562 $add_query_string++;
564 if (count($matches[1]) == (count($div) - $add_ended_divs) && (!$prev_html_tag && !$curr_html_tag)) {
565 $div[] = "</div>";
567 $k++;
570 $values[2] = $this->getModuleVersionFromFile($modId);
571 $values[3] = $Module->acl_version;
572 $this->getInstallerTable()->updateRegistered($modId, '', $values);
573 return $div;
577 * @param string $modId
578 * @return bool
580 public function InstallModuleACL($modId = '')
582 $Module = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory");
583 $modDir = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $Module->modDirectory;
584 $div = [];
585 if (file_exists($modDir . "/acl/acl_setup.php") && empty($modDir->acl_version)) {
586 // Pass a variable, so below scripts can not be run on their own
587 $aclSetupFlag = true;
588 ob_start();
589 include_once($modDir . "/acl/acl_setup.php");
590 $div[] = ob_get_contents();
591 ob_end_clean();
592 $values = array($Module->mod_nick_name,$Module->mod_enc_menu);
593 $values[2] = $Module->sql_version;
594 $values[3] = $this->getModuleVersionFromFile($modId);
595 $this->getInstallerTable()->updateRegistered($modId, '', $values);
596 return $div;
598 return false;
602 * Function to Enable Module
604 * @param string $dir Location of the php file which calling functions to add sections,aco etc.
605 * @return boolean
607 public function EnableModule($modId = '')
609 $resp = $this->getInstallerTable()->updateRegistered($modId, "mod_active=0");
610 if ($resp['status'] == 'failure' && $resp['code'] == '200') {
611 $status = $resp['value'];
612 } else {
613 $status = $this->listenerObject->z_xlt("Success");
615 return $status;
619 * Function to Disable Module
621 * @param string $dir Location of the php file which calling functions to add sections,aco etc.
622 * @return boolean
624 public function DisableModule($modId = '')
626 $resp = $this->getInstallerTable()->updateRegistered($modId, "mod_active=1");
627 if ($resp['status'] == 'failure' && $resp['code'] == '200') {
628 $plural = "Module";
629 if (count($resp['value']) > 1) {
630 $plural = "Modules";
633 $status = $this->listenerObject->z_xlt("Dependency Problem") . ':' . implode(", ", $resp['value']) . " " . $this->listenerObject->z_xlt($plural) . " " . $this->listenerObject->z_xlt("Should be Enabled");
634 } elseif ($resp['status'] == 'failure' && ($resp['code'] == '300' || $resp['code'] == '400')) {
635 $status = $resp['value'];
636 } else {
637 $status = $this->listenerObject->z_xlt("Success");
639 return $status;
643 * Function to Install Module
645 * @param string $dir Location of the php file which calling functions to add sections,aco etc.
646 * @return boolean
648 public function InstallModule($modId = '', $mod_enc_menu = '', $mod_nick_name = '')
650 $registryEntry = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory");
651 $modType = $registryEntry->type;
652 $dirModule = $registryEntry->modDirectory;
653 $sqlInstalled = false;
654 if ($modType == InstModuleTable::MODULE_TYPE_CUSTOM) {
655 $fullDirectory = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . $GLOBALS['customModDir'] . "/" . $dirModule;
656 if ($this->getInstallerTable()->installSQL($modId, $modType, $fullDirectory)) {
657 $sqlInstalled = true;
658 } else {
659 // TODO: This is a wierd error... why is it written like this?
660 $status = $this->listenerObject->z_xlt("ERROR") . ':' . $this->listenerObject->z_xlt("could not open table") . '.' . $this->listenerObject->z_xlt("sql") . ', ' . $this->listenerObject->z_xlt("broken form") . "?";
662 } elseif ($modType == InstModuleTable::MODULE_TYPE_ZEND) {
663 $fullDirectory = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $dirModule;
664 if ($this->getInstallerTable()->installSQL($modId, $modType, $fullDirectory)) {
665 $sqlInstalled = true;
666 } else {
667 $status = $this->listenerObject->z_xlt("ERROR") . ':' . $this->listenerObject->z_xlt("could not run sql query");
671 if ($sqlInstalled) {
672 $values = array($mod_nick_name, $mod_enc_menu);
673 $values[2] = $this->getModuleVersionFromFile($modId);
674 $this->getInstallerTable()->updateRegistered($modId, '', $values);
675 $status = $this->listenerObject->z_xlt("Success");
678 return $status;
682 * Function to Unregister Module
684 * @param string $dir Location of the php file which calling functions to add sections,aco etc.
685 * @return boolean
687 public function UnregisterModule($modId = '')
689 $resp = $this->getInstallerTable()->unRegister($modId);
690 if ($resp == 'failure') {
691 $status = $this->listenerObject->z_xlt("ERROR") . ':' . $this->listenerObject->z_xlt("Failed to unregister module.");
692 } else {
693 $status = $this->listenerObject->z_xlt("Success");
696 return $status;
705 * @param string $modId
706 * @return array|bool
708 public function UpgradeModuleACL($modId = '')
710 $Module = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory");
711 $modDir = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $Module->modDirectory;
712 $div = [];
713 if (file_exists($modDir . "/acl/acl_upgrade.php") && !empty($Module->acl_version)) {
714 // Pass a variable, so below scripts can not be run on their own
715 $aclSetupFlag = true;
716 ob_start();
717 $ACL_UPGRADE = include_once($modDir . "/acl/acl_upgrade.php");
718 $version = $this->upgradeAclFromVersion($ACL_UPGRADE, $Module->acl_version);
719 $div[] = ob_get_contents();
720 ob_end_clean();
722 if (strlen($version) > 0) {
723 $values = array($Module->mod_nick_name,$Module->mod_enc_menu);
724 $values[2] = $Module->sql_version;
725 $values[3] = $this->getModuleVersionFromFile($modId);
726 $this->getInstallerTable()->updateRegistered($modId, '', $values);
728 return $div;
730 return false;
736 public function commandInstallModuleAction($moduleName, $moduleAction)
738 if (php_sapi_name() !== 'cli') {
739 throw new RuntimeException('You can only use this action from a console!');
742 $moduleId = null;
743 $div = [];
745 echo PHP_EOL . '--- Run command [' . $moduleAction . '] in module: ' . $moduleName . '---' . PHP_EOL;
746 echo 'start process - ' . date('Y-m-d H:i:s') . PHP_EOL;
748 if (!empty($moduleAction) && !empty($moduleName) && $moduleName != "all") {
749 $moduleId = $this->getModuleId($moduleName);
752 if ($moduleId !== null) {
753 echo 'module [' . $moduleName . '] was found' . PHP_EOL;
755 $msg = "command completed successfully";
757 if ($moduleAction === "install_sql") {
758 $this->InstallModuleSQL($moduleId);
759 } elseif ($moduleAction === "upgrade_sql") {
760 $div = $this->UpgradeModuleSQL($moduleId);
761 } elseif ($moduleAction === "install_acl") {
762 $div = $this->InstallModuleACL($moduleId);
763 } elseif ($moduleAction === "upgrade_acl") {
764 $div = $this->UpgradeModuleACL($moduleId);
765 } elseif ($moduleAction === "enable") {
766 $div = $this->DisableModule($moduleId);
767 } elseif ($moduleAction === "disable") {
768 $div = $this->EnableModule($moduleId);
769 } elseif ($moduleAction === "install") {
770 $div = $this->InstallModule($moduleId);
771 } elseif ($moduleAction === "unregister") {
772 $div = $this->UnregisterModule($moduleId);
773 } else {
774 $msg = 'Unsupported command';
776 } else {
777 $msg = "module Id is null";
781 $output = "";
783 if (is_array($div)) {
784 $output = implode("<br />\n", $div) . PHP_EOL;
786 echo $output;
788 exit($msg . PHP_EOL);