BxDolStudioInstallerUtils.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaStudio UNA Studio
  7. * @{
  8. */
  9. bx_import('BxDolLanguages');
  10. define('BX_DOL_MARKET_URL_ROOT', 'https://una.io/');
  11. define('BX_DOL_MARKET_URL_INTEGRATION', BX_DOL_MARKET_URL_ROOT . 'm/market_api/');
  12. define('BX_DOL_STUDIO_IU_RC_SUCCESS', 0);
  13. define('BX_DOL_STUDIO_IU_RC_FAILED', 1);
  14. define('BX_DOL_STUDIO_IU_RC_SCHEDULED', 2);
  15. class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSingleton
  16. {
  17. protected $bUseFtp;
  18. protected $sAuthorizedAccessClass;
  19. protected $sStoreDataUrlPublic;
  20. public function __construct()
  21. {
  22. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  23. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  24. parent::__construct();
  25. $this->bUseFtp = BX_FORCE_USE_FTP_FILE_TRANSFER;
  26. $this->sAuthorizedAccessClass = 'BxDolStudioOAuthOAuth2';
  27. $this->sStoreDataUrlPublic = BX_DOL_MARKET_URL_INTEGRATION;
  28. }
  29. /**
  30. * Prevent cloning the instance
  31. */
  32. public function __clone()
  33. {
  34. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  35. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  36. }
  37. /**
  38. * Get singleton instance of the class
  39. */
  40. public static function getInstance()
  41. {
  42. if (!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  43. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolStudioInstallerUtils();
  44. return $GLOBALS['bxDolClasses'][__CLASS__];
  45. }
  46. public static function getNamePerformAction($sParam)
  47. {
  48. return 'sys_perform_action_' . md5($sParam);
  49. }
  50. public static function getNameDownloadFile($sParam)
  51. {
  52. return 'sys_download_file_complete_' . $sParam;
  53. }
  54. public static function getNamePerformModulesUpgrade()
  55. {
  56. return 'sys_upgrade_modules_transient';
  57. }
  58. /*
  59. * Is used to complete Downloading inside Transient Cron Job.
  60. */
  61. public function serviceDownloadFileComplete($sFilePath, $aParams = array())
  62. {
  63. return $this->downloadFileComplete($sFilePath, array_merge($aParams, array('transient' => true)));
  64. }
  65. /*
  66. * Is used to perform action inside Transient Cron Job.
  67. */
  68. public function servicePerformAction($sDirectory, $sOperation, $aParams)
  69. {
  70. return $this->perform($sDirectory, $sOperation, array_merge($aParams, array('transient' => true)));
  71. }
  72. /*
  73. * Is used to perform modules upgrade inside Transient Cron Job.
  74. */
  75. public function servicePerformModulesUpgrade($bEmailNotify)
  76. {
  77. return $this->performModulesUpgrade(true, $bEmailNotify);
  78. }
  79. public function getStoreDataUrl($sType = 'public')
  80. {
  81. return $sType == 'public' ? $this->sStoreDataUrlPublic : '';
  82. }
  83. public function getAccessObject($bAuthorizedAccess)
  84. {
  85. $sClass = $bAuthorizedAccess ? $this->sAuthorizedAccessClass : 'BxDolStudioJson';
  86. bx_import($sClass);
  87. return $sClass::getInstance();
  88. }
  89. public function getModules($bTitleAsKey = true)
  90. {
  91. $aModules = array();
  92. $oTemplate = BxDolStudioTemplate::getInstance();
  93. $aInstalledInfo = $this->getInstalledInfo();
  94. $sPath = BX_DIRECTORY_PATH_MODULES;
  95. if(($rHandleVendor = opendir($sPath)) !== false) {
  96. while(($sVendor = readdir($rHandleVendor)) !== false) {
  97. if(substr($sVendor, 0, 1) == '.' || !is_dir($sPath . $sVendor))
  98. continue;
  99. if(($rHandleModule = opendir($sPath . $sVendor)) !== false) {
  100. while(($sModule = readdir($rHandleModule)) !== false) {
  101. if(!is_dir($sPath . $sVendor . '/' . $sModule) || substr($sModule, 0, 1) == '.')
  102. continue;
  103. $sModulePath = $sVendor . '/' . $sModule . '/';
  104. $aModule = $this->getConfigModule($sPath . $sModulePath . 'install/config.php', !empty($aInstalledInfo[$sModulePath]) ? $aInstalledInfo[$sModulePath] : array());
  105. if(empty($aModule))
  106. continue;
  107. $aModules[$bTitleAsKey ? $aModule['title'] : $aModule['name']] = $aModule;
  108. }
  109. closedir($rHandleModule);
  110. }
  111. }
  112. closedir($rHandleVendor);
  113. }
  114. ksort($aModules);
  115. return $aModules;
  116. }
  117. public function getUpdates()
  118. {
  119. $aUpdates = array();
  120. $oTemplate = BxDolStudioTemplate::getInstance();
  121. $aInstalledInfo = $this->getInstalledInfo();
  122. $sPath = BX_DIRECTORY_PATH_MODULES;
  123. if(($rHandleVendor = opendir($sPath)) !== false) {
  124. while(($sVendor = readdir($rHandleVendor)) !== false) {
  125. if(substr($sVendor, 0, 1) == '.' || !is_dir($sPath . $sVendor))
  126. continue;
  127. if(($rHandleModule = opendir($sPath . $sVendor . '/')) !== false) {
  128. while(($sModule = readdir($rHandleModule)) !== false) {
  129. if(!is_dir($sPath . $sVendor . '/' . $sModule) || substr($sModule, 0, 1) == '.')
  130. continue;
  131. $sModulePath = $sVendor . '/' . $sModule . '/';
  132. if(empty($aInstalledInfo[$sModulePath]))
  133. continue;
  134. $aUpdate = $this->getUpdate($aInstalledInfo[$sModulePath]);
  135. if(!empty($aUpdate))
  136. $aUpdates[$aUpdate['title']] = $aUpdate;
  137. }
  138. closedir($rHandleModule);
  139. }
  140. }
  141. closedir($rHandleVendor);
  142. }
  143. ksort($aUpdates);
  144. return $aUpdates;
  145. }
  146. public function getUpdate($mixedModule)
  147. {
  148. $aResult = array();
  149. if(!is_array($mixedModule))
  150. $mixedModule = BxDolModuleQuery::getInstance()->{is_numeric($mixedModule) ? 'getModuleById' : 'getModuleByName'}($mixedModule);
  151. if(empty($mixedModule) || !is_array($mixedModule))
  152. return $aResult;
  153. $sPathModule = BX_DIRECTORY_PATH_MODULES . $mixedModule['path'];
  154. $sPathUpdates = $sPathModule . 'updates/';
  155. $rHandleUpdate = @opendir($sPathUpdates);
  156. if($rHandleUpdate === false)
  157. return $aResult;
  158. while(($sUpdate = readdir($rHandleUpdate)) !== false) {
  159. $sPathUpdate = $sPathUpdates . $sUpdate . '/';
  160. if(substr($sUpdate, 0, 1) == '.' || !is_dir($sPathUpdate))
  161. continue;
  162. $aUpdate = $this->getConfigUpdate($sPathModule . 'install/config.php', $sPathUpdate . 'install/config.php', $mixedModule);
  163. if(empty($aUpdate) || !is_array($aUpdate) || version_compare($aUpdate['module_version'], $aUpdate['version_from']) != 0)
  164. continue;
  165. $aResult = $aUpdate;
  166. break;
  167. }
  168. closedir($rHandleUpdate);
  169. return $aResult;
  170. }
  171. public function perform($sDirectory, $sOperation, $aParams = array())
  172. {
  173. $bTransient = false;
  174. if(isset($aParams['transient']) && $aParams['transient'] === true) {
  175. $bTransient = true;
  176. unset($aParams['transient']);
  177. }
  178. if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner() && !in_array($sOperation, array('install', 'uninstall', 'enable', 'disable'))) {
  179. if($this->addTransientJob(self::getNamePerformAction($sDirectory), 'perform_action', array($sDirectory, $sOperation, $aParams)))
  180. return array('code' => BX_DOL_STUDIO_IU_RC_SCHEDULED, 'message' => _t('_adm_mod_msg_process_operation_scheduled'));
  181. else
  182. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory));
  183. }
  184. $sConfigFile = 'install/config.php';
  185. $sInstallerFile = 'install/installer.php';
  186. $sInstallerClass = $sOperation == 'update' ? 'Updater' : 'Installer';
  187. $aConfig = self::getModuleConfig(BX_DIRECTORY_PATH_MODULES . $sDirectory . $sConfigFile);
  188. $sPathInstaller = BX_DIRECTORY_PATH_MODULES . $sDirectory . $sInstallerFile;
  189. if(empty($aConfig) || !file_exists($sPathInstaller)) {
  190. $sMessage = _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory);
  191. if($bTransient)
  192. $this->emailNotify($sMessage);
  193. return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => $sMessage);
  194. }
  195. require_once($sPathInstaller);
  196. $sClassName = $aConfig['class_prefix'] . $sInstallerClass;
  197. $oInstaller = new $sClassName($aConfig);
  198. $aResult = $oInstaller->$sOperation($aParams);
  199. if(!$aResult['result'] && $bTransient)
  200. $this->emailNotify($aResult['message']);
  201. return array('code' => $aResult['result'] ? BX_DOL_STUDIO_IU_RC_SUCCESS : BX_DOL_STUDIO_IU_RC_FAILED, 'message' => $aResult['message']);
  202. }
  203. public function performModulesUpgrade($bDirectly = true, $bEmailNotify = true)
  204. {
  205. if(!defined('BX_DOL_CRON_EXECUTE') && !$bDirectly)
  206. return $this->addTransientJob(self::getNamePerformModulesUpgrade(), 'perform_modules_upgrade', array($bEmailNotify));
  207. $oLog = BxDolLog::getInstance();
  208. $oLog->setName('upgrade_modules');
  209. $aFailed = array();
  210. $aUpdates = $this->checkUpdates();
  211. if(empty($aUpdates) || !is_array($aUpdates)) {
  212. $oLog->write('Cannot get a list of modules which require to be updated.');
  213. return true;
  214. }
  215. foreach($aUpdates as $aUpdate) {
  216. $mixedResult = $this->downloadUpdatePublic($aUpdate['name']);
  217. if($mixedResult !== true) {
  218. $aFailed[$aUpdate['name']] = $mixedResult;
  219. continue;
  220. }
  221. }
  222. $aSuccess = array();
  223. $aUpdates = $this->getUpdates();
  224. if(empty($aUpdates) || !is_array($aUpdates)) {
  225. $oLog->write('Cannot find update scripts for modules. They are damaged or were not downloaded.');
  226. return true;
  227. }
  228. foreach($aUpdates as $aUpdate) {
  229. $aResult = $this->perform($aUpdate['dir'], 'update');
  230. if((int)$aResult['code'] != 0) {
  231. $aFailed[$aUpdate['module_name']] = $aResult['message'];
  232. continue;
  233. }
  234. $aSuccess[$aUpdate['module_name']] = $aUpdate['version_to'];
  235. }
  236. if(!empty($aFailed)) {
  237. $oLog->write('Failed to update modules:', $aFailed);
  238. if($bEmailNotify)
  239. $this->emailNotifyModulesUpgrade('failed', $aFailed);
  240. }
  241. if(!empty($aSuccess)) {
  242. $oLog->write('Successfully updated modules:', $aSuccess);
  243. if($bEmailNotify)
  244. $this->emailNotifyModulesUpgrade('success', $aSuccess);
  245. }
  246. return empty($aFailed);
  247. }
  248. public function checkModules($bAuthorizedAccess = false)
  249. {
  250. $iPerPage = 9999; //--- Note. It's essential to load all purchased products at the same time.
  251. if($bAuthorizedAccess)
  252. $aProducts = $this->getAccessObject(true)->loadItems(array(
  253. 'method' => 'browse_purchased',
  254. 'domain' => BX_DOL_URL_ROOT,
  255. 'products' => $this->getInstalledInfoShort(),
  256. 'per_page' => $iPerPage
  257. ));
  258. else
  259. $aProducts = $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_browse_purchased', array('key' => getParam('sys_oauth_key'), 'per_page' => $iPerPage));
  260. if(empty($aProducts) || !is_array($aProducts))
  261. return $aProducts;
  262. $oModuleDb = BxDolModuleQuery::getInstance();
  263. $oModuleDb->updateModule(array('hash' => ''));
  264. if(!empty($aProducts) && is_array($aProducts))
  265. foreach ($aProducts as $aProduct)
  266. if(!empty($aProduct['hash']))
  267. $oModuleDb->updateModule(array('hash' => $aProduct['hash']), array('name' => $aProduct['name']));
  268. return $aProducts;
  269. }
  270. public function checkUpdates($bAuthorizedAccess = false)
  271. {
  272. $sProducts = $this->getInstalledInfoShort();
  273. if($bAuthorizedAccess)
  274. return $this->getAccessObject(true)->loadItems(array(
  275. 'method' => 'browse_updates',
  276. 'products' => $sProducts
  277. ));
  278. return $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_browse_updates', array(
  279. 'key' => getParam('sys_oauth_key'),
  280. 'products' => $sProducts
  281. ));
  282. }
  283. public function downloadFileAuthorized($iFileId)
  284. {
  285. $aItem = $this->getAccessObject(true)->loadItems(array(
  286. 'method' => 'download_file',
  287. 'file_id' => $iFileId
  288. ));
  289. if(empty($aItem) || !is_array($aItem))
  290. return $aItem;
  291. return $this->downloadFileInit($aItem, array('module_name' => $aItem['module_name']));
  292. }
  293. public function downloadUpdatePublic($sModuleName, $bAutoUpdate = false)
  294. {
  295. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModuleName);
  296. $aItem = $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_download_update', array(
  297. 'key' => getParam('sys_oauth_key'),
  298. 'product' => base64_encode(serialize(array(
  299. 'name' => $aModule['name'],
  300. 'version' => $aModule['version'],
  301. 'hash' => $aModule['hash'],
  302. ))),
  303. ));
  304. return $this->downloadFileInit($aItem, array('module_name' => $sModuleName, 'auto_action' => $bAutoUpdate ? 'update' : ''));
  305. }
  306. protected function downloadFileInit($aItem, $aParams = array())
  307. {
  308. if(empty($aItem) || !is_array($aItem))
  309. return $aItem;
  310. //--- write ZIP archive.
  311. $sFilePath = '';
  312. $mixedResult = $this->performWrite($aItem, $sFilePath);
  313. if($mixedResult !== true)
  314. return $mixedResult;
  315. return $this->downloadFileComplete($sFilePath, $aParams);
  316. }
  317. protected function downloadFileComplete($sFilePath, $aParams = array())
  318. {
  319. $bTransient = false;
  320. if(isset($aParams['transient']) && $aParams['transient'] === true) {
  321. $bTransient = true;
  322. unset($aParams['transient']);
  323. }
  324. $sAutoAction = isset($aParams['auto_action']) ? $aParams['auto_action'] : '';
  325. $bAutoAction = !empty($sAutoAction);
  326. if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner()) {
  327. if(!$this->addTransientJob(self::getNameDownloadFile($aParams['module_name']), 'download_file_complete', array($sFilePath, $aParams)))
  328. return _t('_adm_str_err_download_failed');
  329. return array('code' => BX_DOL_STUDIO_IU_RC_SCHEDULED, 'message' => _t('_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled'));
  330. }
  331. //--- Unarchive package.
  332. $sPackagePath = '';
  333. $mixedResult = $this->performUnarchive($sFilePath, $sPackagePath);
  334. @unlink($sFilePath);
  335. if($mixedResult !== true) {
  336. if($bTransient)
  337. $this->emailNotify($mixedResult);
  338. return $mixedResult;
  339. }
  340. //--- Copy unarchived package.
  341. $sHomePath = '';
  342. $mixedResult = $this->performCopy($sPackagePath, $sHomePath);
  343. @bx_rrmdir($sPackagePath);
  344. if($mixedResult !== true) {
  345. if($bTransient)
  346. $this->emailNotify($mixedResult);
  347. return $mixedResult;
  348. }
  349. if(!$bAutoAction)
  350. return true;
  351. //--- Autoinstall the downloaded package if it's needed.
  352. $aResult = $this->perform($sHomePath, $sAutoAction, $aParams);
  353. if((int)$aResult['code'] != 0) {
  354. if($bTransient)
  355. $this->emailNotify($aResult['message']);
  356. return $aResult['message'];
  357. }
  358. return true;
  359. }
  360. protected function performWrite($aItem, &$sFilePath)
  361. {
  362. $sFilePath = BX_DIRECTORY_PATH_TMP . $aItem['name'];
  363. if(file_exists($sFilePath))
  364. @unlink($sFilePath);
  365. $iUmaskSave = umask(0);
  366. if(!$rHandler = fopen($sFilePath, 'w')) {
  367. umask($iUmaskSave);
  368. return _t('_adm_str_err_cannot_write');
  369. }
  370. $sContent = urldecode($aItem['content']);
  371. if(!fwrite($rHandler, $sContent, strlen($sContent))) {
  372. umask($iUmaskSave);
  373. return _t('_adm_str_err_cannot_write');
  374. }
  375. fclose($rHandler);
  376. umask($iUmaskSave);
  377. return true;
  378. }
  379. protected function performUnarchive($sFilePath, &$sPackagePath)
  380. {
  381. if(!class_exists('ZipArchive'))
  382. return _t('_adm_str_err_zip_not_available');
  383. $iUmaskSave = umask(0);
  384. $oZip = new ZipArchive();
  385. if($oZip->open($sFilePath) !== true) {
  386. umask($iUmaskSave);
  387. return _t('_adm_str_err_cannot_unzip_package');
  388. }
  389. $sPackageFolder = '';
  390. if($oZip->numFiles > 0)
  391. $sPackageFolder = $oZip->getNameIndex(0);
  392. if(empty($sPackageFolder)) {
  393. umask($iUmaskSave);
  394. return _t('_adm_str_err_cannot_unzip_package');
  395. }
  396. $sPackagePath = BX_DIRECTORY_PATH_TMP . $sPackageFolder;
  397. if(file_exists($sPackagePath)) // remove existing tmp folder with the same name
  398. @bx_rrmdir($sPackagePath);
  399. if(!$oZip->extractTo(BX_DIRECTORY_PATH_TMP)) {
  400. umask($iUmaskSave);
  401. return _t('_adm_str_err_cannot_unzip_package');
  402. }
  403. $oZip->close();
  404. umask($iUmaskSave);
  405. return true;
  406. }
  407. protected function performCopy($sPackagePath, &$sHomePath)
  408. {
  409. if($this->bUseFtp) {
  410. $sLogin = getParam('sys_ftp_login');
  411. $sPassword = getParam('sys_ftp_password');
  412. $sPath = getParam('sys_ftp_dir');
  413. if(empty($sLogin) || empty($sPassword) || empty($sPath))
  414. return _t('_adm_str_err_no_ftp_info');
  415. $oFile = new BxDolFtp($_SERVER['HTTP_HOST'], $sLogin, $sPassword, $sPath);
  416. if(!$oFile->connect())
  417. return _t('_adm_str_err_cannot_connect_to_ftp');
  418. if(!$oFile->isUna())
  419. return _t('_adm_str_err_destination_not_valid');
  420. }
  421. else
  422. $oFile = BxDolFile::getInstance();
  423. $aConfig = self::getModuleConfig($sPackagePath . 'install/config.php');
  424. if(empty($aConfig) || !is_array($aConfig) || empty($aConfig['home_dir']))
  425. return _t('_adm_str_err_wrong_package_format');
  426. $sHomePath = $aConfig['home_dir'];
  427. if(!$oFile->copy($sPackagePath, 'modules/' . $sHomePath))
  428. return _t('_adm_str_err_files_copy_failed');
  429. return true;
  430. }
  431. protected function getConfigModule($sConfigPath, $aInstalled = array())
  432. {
  433. $aConfig = self::getModuleConfig($sConfigPath);
  434. if(empty($aConfig) || !is_array($aConfig))
  435. return array();
  436. $bInstalled = !empty($aInstalled);
  437. $bEnabled = $bInstalled && (int)$aInstalled['enabled'] == 1;
  438. $sVersion = $bInstalled ? $aInstalled['version'] : $aConfig['version'];
  439. return array(
  440. 'type' => $aConfig['type'],
  441. 'name' => isset($aConfig['name']) ? $aConfig['name'] : $aConfig['home_uri'],
  442. 'title' => bx_process_output($aConfig['title']),
  443. 'vendor' => $aConfig['vendor'],
  444. 'version' => $sVersion,
  445. 'uri' => $aConfig['home_uri'],
  446. 'dir' => $aConfig['home_dir'],
  447. 'note' => isset($aConfig['note']) ? bx_process_output($aConfig['note']) : '',
  448. 'installed' => $bInstalled,
  449. 'enabled' => $bEnabled
  450. );
  451. }
  452. protected function getConfigUpdate($sConfigPathModule, $sConfigPathUpdate, $aInstalledModule = array())
  453. {
  454. $aModule = $this->getConfigModule($sConfigPathModule, $aInstalledModule);
  455. if(empty($aModule) || !$aModule['installed'])
  456. return array();
  457. $aConfig = self::getModuleConfig($sConfigPathUpdate);
  458. if(empty($aConfig) || !is_array($aConfig))
  459. return array();
  460. return array(
  461. 'title' => bx_process_output($aConfig['title']),
  462. 'vendor' => $aConfig['vendor'],
  463. 'version_from' => $aConfig['version_from'],
  464. 'version_to' => $aConfig['version_to'],
  465. 'dir' => $aConfig['home_dir'],
  466. 'module_type' => $aModule['type'],
  467. 'module_name' => $aModule['name'],
  468. 'module_dir' => $aModule['dir'],
  469. 'module_version' => $aModule['version']
  470. );
  471. }
  472. private function getInstalledInfo()
  473. {
  474. $aModules = BxDolModuleQuery::getInstance()->getModules();
  475. $aInstalledInfo = array();
  476. foreach($aModules as $aModule)
  477. $aInstalledInfo[$aModule['path']] = $aModule;
  478. return $aInstalledInfo;
  479. }
  480. private function getInstalledInfoShort()
  481. {
  482. $aModules = BxDolModuleQuery::getInstance()->getModules();
  483. $aProducts = array();
  484. foreach($aModules as $aModule) {
  485. if(empty($aModule['name']))
  486. continue;
  487. $aProducts[$aModule['name']] = array(
  488. 'name' => $aModule['name'],
  489. 'version' => $aModule['version'],
  490. 'hash' => $aModule['hash'],
  491. );
  492. }
  493. return base64_encode(serialize($aProducts));
  494. }
  495. private function addTransientJob($sName, $sAction, $aParams)
  496. {
  497. if(BxDolCronQuery::getInstance()->addTransientJobService($sName, array('system', $sAction, $aParams, 'DolStudioInstallerUtils')))
  498. return true;
  499. return false;
  500. }
  501. private function emailNotify($sMessage)
  502. {
  503. sendMailTemplateSystem('t_BgOperationFailed', array (
  504. 'conclusion' => strip_tags($sMessage),
  505. ));
  506. }
  507. private function emailNotifyModulesUpgrade($sResult, $aData)
  508. {
  509. $oModuleQuery = BxDolModuleQuery::getInstance();
  510. $sConclusion = '';
  511. if(!empty($aData))
  512. foreach($aData as $sModule => $sMessage) {
  513. $aModule = $oModuleQuery->getModuleByName($sModule);
  514. $sConclusion .= _t('_sys_et_txt_body_modules_upgrade_' . $sResult, $aModule['title'], $sMessage);
  515. }
  516. sendMailTemplateSystem('t_UpgradeModules' . ucfirst($sResult), array (
  517. 'conclusion' => $sConclusion,
  518. ));
  519. }
  520. }
  521. /** @} */