BxDolUpgraderModules.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php use system\L;
  2. defined('BX_DOL') or die('hack attempt');
  3. /**
  4. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  6. *
  7. * @defgroup DolphinCore Dolphin Core
  8. * @{
  9. */
  10. bx_import('BxDolUpgrader');
  11. class BxDolUpgraderModules extends BxDolUpgrader
  12. {
  13. public function prepare()
  14. {
  15. $iUmaskSave = umask(0);
  16. bx_import('BxDolStudioInstallerUtils');
  17. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  18. $aUpdated = array();
  19. while(true) {
  20. $aUpdates = $oInstallerUtils->checkUpdates();
  21. foreach($aUpdates as $aUpdate) {
  22. $mixedResult = $oInstallerUtils->downloadUpdatePublic($aUpdate['name']);
  23. if($mixedResult !== true) {
  24. $this->setError($mixedResult);
  25. break;
  26. }
  27. }
  28. if($this->getError())
  29. break;
  30. $aUpdates = $oInstallerUtils->getUpdates();
  31. foreach($aUpdates as $aUpdate) {
  32. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aUpdate['dir'], 'update');
  33. if((int)$aResult['code'] != 0) {
  34. $this->setError($aResult['message']);
  35. break;
  36. }
  37. else
  38. $aUpdated[$aUpdate['module_name']] = $aUpdate['version_to'];
  39. }
  40. break;
  41. }
  42. umask($iUmaskSave);
  43. if(!empty($aUpdated)) {
  44. bx_import('BxDolModuleQuery');
  45. $oModuleQuery = BxDolModuleQuery::getInstance();
  46. $sUpdated = '';
  47. foreach($aUpdated as $sModule => $sVersion) {
  48. $aModule = $oModuleQuery->getModuleByName($sModule);
  49. $sUpdated .= _t('_sys_et_txt_body_upgraded_module', $aModule['title'], $sVersion);
  50. }
  51. sendMailTemplateSystem('t_UpgradeModulesSuccess', array (
  52. 'conclusion' => $sUpdated,
  53. ));
  54. }
  55. return $this->getError() ? false : true;
  56. }
  57. }
  58. /** @} */