BxDolStudioInstallerUtils.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. $aFailed = array();
  208. $aUpdates = $this->checkUpdates();
  209. if(empty($aUpdates) || !is_array($aUpdates))
  210. return true;
  211. foreach($aUpdates as $aUpdate) {
  212. $mixedResult = $this->downloadUpdatePublic($aUpdate['name']);
  213. if($mixedResult !== true) {
  214. $aFailed[$aUpdate['name']] = $mixedResult;
  215. continue;
  216. }
  217. }
  218. $aSuccess = array();
  219. $aUpdates = $this->getUpdates();
  220. if(empty($aUpdates) || !is_array($aUpdates))
  221. return true;
  222. foreach($aUpdates as $aUpdate) {
  223. $aResult = $this->perform($aUpdate['dir'], 'update');
  224. if((int)$aResult['code'] != 0) {
  225. $aFailed[$aUpdate['module_name']] = $aResult['message'];
  226. continue;
  227. }
  228. $aSuccess[$aUpdate['module_name']] = $aUpdate['version_to'];
  229. }
  230. if($bEmailNotify && !empty($aSuccess))
  231. $this->emailNotifyModulesUpgrade('success', $aSuccess);
  232. if($bEmailNotify && !empty($aFailed))
  233. $this->emailNotifyModulesUpgrade('failed', $aFailed);
  234. return empty($aFailed);
  235. }
  236. public function checkModules($bAuthorizedAccess = false)
  237. {
  238. $iPerPage = 9999; //--- Note. It's essential to load all purchased products at the same time.
  239. if($bAuthorizedAccess)
  240. $aProducts = $this->getAccessObject(true)->loadItems(array(
  241. 'method' => 'browse_purchased',
  242. 'domain' => BX_DOL_URL_ROOT,
  243. 'products' => $this->getInstalledInfoShort(),
  244. 'per_page' => $iPerPage
  245. ));
  246. else
  247. $aProducts = $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_browse_purchased', array('key' => getParam('sys_oauth_key'), 'per_page' => $iPerPage));
  248. if(empty($aProducts) || !is_array($aProducts))
  249. return $aProducts;
  250. $oModuleDb = BxDolModuleQuery::getInstance();
  251. $oModuleDb->updateModule(array('hash' => ''));
  252. if(!empty($aProducts) && is_array($aProducts))
  253. foreach ($aProducts as $aProduct)
  254. if(!empty($aProduct['hash']))
  255. $oModuleDb->updateModule(array('hash' => $aProduct['hash']), array('name' => $aProduct['name']));
  256. return $aProducts;
  257. }
  258. public function checkUpdates($bAuthorizedAccess = false)
  259. {
  260. $sProducts = $this->getInstalledInfoShort();
  261. if($bAuthorizedAccess)
  262. return $this->getAccessObject(true)->loadItems(array(
  263. 'method' => 'browse_updates',
  264. 'products' => $sProducts
  265. ));
  266. return $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_browse_updates', array(
  267. 'key' => getParam('sys_oauth_key'),
  268. 'products' => $sProducts
  269. ));
  270. }
  271. public function downloadFileAuthorized($iFileId)
  272. {
  273. $aItem = $this->getAccessObject(true)->loadItems(array(
  274. 'method' => 'download_file',
  275. 'file_id' => $iFileId
  276. ));
  277. if(empty($aItem) || !is_array($aItem))
  278. return $aItem;
  279. return $this->downloadFileInit($aItem, array('module_name' => $aItem['module_name']));
  280. }
  281. public function downloadUpdatePublic($sModuleName, $bAutoUpdate = false)
  282. {
  283. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModuleName);
  284. $aItem = $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_download_update', array(
  285. 'key' => getParam('sys_oauth_key'),
  286. 'product' => base64_encode(serialize(array(
  287. 'name' => $aModule['name'],
  288. 'version' => $aModule['version'],
  289. 'hash' => $aModule['hash'],
  290. ))),
  291. ));
  292. return $this->downloadFileInit($aItem, array('module_name' => $sModuleName, 'auto_action' => $bAutoUpdate ? 'update' : ''));
  293. }
  294. protected function downloadFileInit($aItem, $aParams = array())
  295. {
  296. if(empty($aItem) || !is_array($aItem))
  297. return $aItem;
  298. //--- write ZIP archive.
  299. $sFilePath = '';
  300. $mixedResult = $this->performWrite($aItem, $sFilePath);
  301. if($mixedResult !== true)
  302. return $mixedResult;
  303. return $this->downloadFileComplete($sFilePath, $aParams);
  304. }
  305. protected function downloadFileComplete($sFilePath, $aParams = array())
  306. {
  307. $bTransient = false;
  308. if(isset($aParams['transient']) && $aParams['transient'] === true) {
  309. $bTransient = true;
  310. unset($aParams['transient']);
  311. }
  312. $sAutoAction = isset($aParams['auto_action']) ? $aParams['auto_action'] : '';
  313. $bAutoAction = !empty($sAutoAction);
  314. if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner()) {
  315. if(!$this->addTransientJob(self::getNameDownloadFile($aParams['module_name']), 'download_file_complete', array($sFilePath, $aParams)))
  316. return _t('_adm_str_err_download_failed');
  317. return array('code' => BX_DOL_STUDIO_IU_RC_SCHEDULED, 'message' => _t('_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled'));
  318. }
  319. //--- Unarchive package.
  320. $sPackagePath = '';
  321. $mixedResult = $this->performUnarchive($sFilePath, $sPackagePath);
  322. @unlink($sFilePath);
  323. if($mixedResult !== true) {
  324. if($bTransient)
  325. $this->emailNotify($mixedResult);
  326. return $mixedResult;
  327. }
  328. //--- Copy unarchived package.
  329. $sHomePath = '';
  330. $mixedResult = $this->performCopy($sPackagePath, $sHomePath);
  331. @bx_rrmdir($sPackagePath);
  332. if($mixedResult !== true) {
  333. if($bTransient)
  334. $this->emailNotify($mixedResult);
  335. return $mixedResult;
  336. }
  337. if(!$bAutoAction)
  338. return true;
  339. //--- Autoinstall the downloaded package if it's needed.
  340. $aResult = $this->perform($sHomePath, $sAutoAction, $aParams);
  341. if((int)$aResult['code'] != 0) {
  342. if($bTransient)
  343. $this->emailNotify($aResult['message']);
  344. return $aResult['message'];
  345. }
  346. return true;
  347. }
  348. protected function performWrite($aItem, &$sFilePath)
  349. {
  350. $sFilePath = BX_DIRECTORY_PATH_TMP . $aItem['name'];
  351. if(file_exists($sFilePath))
  352. @unlink($sFilePath);
  353. $iUmaskSave = umask(0);
  354. if(!$rHandler = fopen($sFilePath, 'w')) {
  355. umask($iUmaskSave);
  356. return _t('_adm_str_err_cannot_write');
  357. }
  358. $sContent = urldecode($aItem['content']);
  359. if(!fwrite($rHandler, $sContent, strlen($sContent))) {
  360. umask($iUmaskSave);
  361. return _t('_adm_str_err_cannot_write');
  362. }
  363. fclose($rHandler);
  364. umask($iUmaskSave);
  365. return true;
  366. }
  367. protected function performUnarchive($sFilePath, &$sPackagePath)
  368. {
  369. if(!class_exists('ZipArchive'))
  370. return _t('_adm_str_err_zip_not_available');
  371. $iUmaskSave = umask(0);
  372. $oZip = new ZipArchive();
  373. if($oZip->open($sFilePath) !== true) {
  374. umask($iUmaskSave);
  375. return _t('_adm_str_err_cannot_unzip_package');
  376. }
  377. $sPackageFolder = '';
  378. if($oZip->numFiles > 0)
  379. $sPackageFolder = $oZip->getNameIndex(0);
  380. if(empty($sPackageFolder)) {
  381. umask($iUmaskSave);
  382. return _t('_adm_str_err_cannot_unzip_package');
  383. }
  384. $sPackagePath = BX_DIRECTORY_PATH_TMP . $sPackageFolder;
  385. if(file_exists($sPackagePath)) // remove existing tmp folder with the same name
  386. @bx_rrmdir($sPackagePath);
  387. if(!$oZip->extractTo(BX_DIRECTORY_PATH_TMP)) {
  388. umask($iUmaskSave);
  389. return _t('_adm_str_err_cannot_unzip_package');
  390. }
  391. $oZip->close();
  392. umask($iUmaskSave);
  393. return true;
  394. }
  395. protected function performCopy($sPackagePath, &$sHomePath)
  396. {
  397. if($this->bUseFtp) {
  398. $sLogin = getParam('sys_ftp_login');
  399. $sPassword = getParam('sys_ftp_password');
  400. $sPath = getParam('sys_ftp_dir');
  401. if(empty($sLogin) || empty($sPassword) || empty($sPath))
  402. return _t('_adm_str_err_no_ftp_info');
  403. $oFile = new BxDolFtp($_SERVER['HTTP_HOST'], $sLogin, $sPassword, $sPath);
  404. if(!$oFile->connect())
  405. return _t('_adm_str_err_cannot_connect_to_ftp');
  406. if(!$oFile->isUna())
  407. return _t('_adm_str_err_destination_not_valid');
  408. }
  409. else
  410. $oFile = BxDolFile::getInstance();
  411. $aConfig = self::getModuleConfig($sPackagePath . 'install/config.php');
  412. if(empty($aConfig) || !is_array($aConfig) || empty($aConfig['home_dir']))
  413. return _t('_adm_str_err_wrong_package_format');
  414. $sHomePath = $aConfig['home_dir'];
  415. if(!$oFile->copy($sPackagePath, 'modules/' . $sHomePath))
  416. return _t('_adm_str_err_files_copy_failed');
  417. return true;
  418. }
  419. protected function getConfigModule($sConfigPath, $aInstalled = array())
  420. {
  421. $aConfig = self::getModuleConfig($sConfigPath);
  422. if(empty($aConfig) || !is_array($aConfig))
  423. return array();
  424. $bInstalled = !empty($aInstalled);
  425. $bEnabled = $bInstalled && (int)$aInstalled['enabled'] == 1;
  426. $sVersion = $bInstalled ? $aInstalled['version'] : $aConfig['version'];
  427. return array(
  428. 'type' => $aConfig['type'],
  429. 'name' => isset($aConfig['name']) ? $aConfig['name'] : $aConfig['home_uri'],
  430. 'title' => bx_process_output($aConfig['title']),
  431. 'vendor' => $aConfig['vendor'],
  432. 'version' => $sVersion,
  433. 'uri' => $aConfig['home_uri'],
  434. 'dir' => $aConfig['home_dir'],
  435. 'note' => isset($aConfig['note']) ? bx_process_output($aConfig['note']) : '',
  436. 'installed' => $bInstalled,
  437. 'enabled' => $bEnabled
  438. );
  439. }
  440. protected function getConfigUpdate($sConfigPathModule, $sConfigPathUpdate, $aInstalledModule = array())
  441. {
  442. $aModule = $this->getConfigModule($sConfigPathModule, $aInstalledModule);
  443. if(empty($aModule) || !$aModule['installed'])
  444. return array();
  445. $aConfig = self::getModuleConfig($sConfigPathUpdate);
  446. if(empty($aConfig) || !is_array($aConfig))
  447. return array();
  448. return array(
  449. 'title' => bx_process_output($aConfig['title']),
  450. 'vendor' => $aConfig['vendor'],
  451. 'version_from' => $aConfig['version_from'],
  452. 'version_to' => $aConfig['version_to'],
  453. 'dir' => $aConfig['home_dir'],
  454. 'module_type' => $aModule['type'],
  455. 'module_name' => $aModule['name'],
  456. 'module_dir' => $aModule['dir'],
  457. 'module_version' => $aModule['version']
  458. );
  459. }
  460. private function getInstalledInfo()
  461. {
  462. $aModules = BxDolModuleQuery::getInstance()->getModules();
  463. $aInstalledInfo = array();
  464. foreach($aModules as $aModule)
  465. $aInstalledInfo[$aModule['path']] = $aModule;
  466. return $aInstalledInfo;
  467. }
  468. private function getInstalledInfoShort()
  469. {
  470. $aModules = BxDolModuleQuery::getInstance()->getModules();
  471. $aProducts = array();
  472. foreach($aModules as $aModule) {
  473. if(empty($aModule['name']))
  474. continue;
  475. $aProducts[$aModule['name']] = array(
  476. 'name' => $aModule['name'],
  477. 'version' => $aModule['version'],
  478. 'hash' => $aModule['hash'],
  479. );
  480. }
  481. return base64_encode(serialize($aProducts));
  482. }
  483. private function addTransientJob($sName, $sAction, $aParams)
  484. {
  485. if(BxDolCronQuery::getInstance()->addTransientJobService($sName, array('system', $sAction, $aParams, 'DolStudioInstallerUtils')))
  486. return true;
  487. return false;
  488. }
  489. private function emailNotify($sMessage)
  490. {
  491. sendMailTemplateSystem('t_BgOperationFailed', array (
  492. 'conclusion' => strip_tags($sMessage),
  493. ));
  494. }
  495. private function emailNotifyModulesUpgrade($sResult, $aData)
  496. {
  497. $oModuleQuery = BxDolModuleQuery::getInstance();
  498. $sConclusion = '';
  499. if(!empty($aData))
  500. foreach($aData as $sModule => $sMessage) {
  501. $aModule = $oModuleQuery->getModuleByName($sModule);
  502. $sConclusion .= _t('_sys_et_txt_body_modules_upgrade_' . $sResult, $aModule['title'], $sMessage);
  503. }
  504. sendMailTemplateSystem('t_UpgradeModules' . ucfirst($sResult), array (
  505. 'conclusion' => $sConclusion,
  506. ));
  507. }
  508. }
  509. /** @} */