BxDolStudioInstaller.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. bx_import('BxDolInstallerUtils');
  10. define("BX_DOL_STUDIO_INSTALLER_SUCCESS", 0);
  11. define("BX_DOL_STUDIO_INSTALLER_FAILED", 1);
  12. /**
  13. * Base class for Installer classes in modules engine.
  14. *
  15. * The class contains different check functions which are used during the installation process.
  16. * An object of the class is created automatically with Dolphin's modules installer.
  17. * Installation/Uninstallation process can be controlled with config.php file located in [module]/install/ folder.
  18. *
  19. *
  20. * Example of usage:
  21. * @see any module included in the default Dolphin's package.
  22. *
  23. *
  24. * Memberships/ACL:
  25. * Doesn't depend on user's membership.
  26. *
  27. *
  28. * Alerts:
  29. * no alerts available
  30. *
  31. */
  32. class BxDolStudioInstaller extends BxDolInstallerUtils
  33. {
  34. protected $oDb;
  35. protected $_aConfig;
  36. protected $_sBasePath;
  37. protected $_sHomePath;
  38. protected $_sModulePath;
  39. protected $_bUseFtp;
  40. protected $_aActions;
  41. protected $_bShowOnSuccess = false;
  42. function __construct($aConfig)
  43. {
  44. parent::__construct();
  45. $this->oDb = bx_instance('BxDolStudioInstallerQuery');
  46. $this->_aConfig = $aConfig;
  47. $this->_sBasePath = BX_DIRECTORY_PATH_MODULES;
  48. $this->_sHomePath = $this->_sBasePath . $aConfig['home_dir'];
  49. $this->_sModulePath = $this->_sBasePath . $aConfig['home_dir'];
  50. $this->_bUseFtp = BX_FORCE_USE_FTP_FILE_TRANSFER;
  51. $this->_aActions = array(
  52. 'perform_install' => array(
  53. 'title' => '',
  54. 'success' => _t('_adm_msg_modules_success_install'),
  55. 'failed' => ''
  56. ),
  57. 'perform_uninstall' => array(
  58. 'title' => '',
  59. 'success' => _t('_adm_msg_modules_success_uninstall'),
  60. 'failed' => ''
  61. ),
  62. 'perform_enable' => array(
  63. 'title' => '',
  64. 'success' => _t('_adm_msg_modules_success_enable'),
  65. 'failed' => ''
  66. ),
  67. 'perform_disable' => array(
  68. 'title' => '',
  69. 'success' => _t('_adm_msg_modules_success_disable'),
  70. 'failed' => ''
  71. ),
  72. 'check_script_version' => array(
  73. 'title' => _t('_adm_txt_modules_check_script_version'),
  74. ),
  75. 'check_dependencies' => array(
  76. 'title' => _t('_adm_txt_modules_check_dependencies'),
  77. ),
  78. 'show_introduction' => array(
  79. 'title' => _t('_adm_txt_modules_show_introduction'),
  80. ),
  81. 'move_sources' => array(
  82. 'title' => _t('_adm_txt_modules_move_sources'),
  83. ),
  84. 'execute_sql' => array(
  85. 'title' => _t('_adm_txt_modules_execute_sql'),
  86. ),
  87. 'install_language' => array(
  88. 'title' => _t('_adm_txt_modules_install_language'),
  89. ),
  90. 'update_languages' => array(
  91. 'title' => _t('_adm_txt_modules_update_languages'),
  92. ),
  93. 'update_relations' => array(
  94. 'title' => _t('_adm_txt_modules_update_relations'),
  95. ),
  96. 'process_deleted_profiles' => array(
  97. 'title' => _t('_adm_txt_modules_process_deleted_profiles'),
  98. ),
  99. 'recompile_global_paramaters' => array(
  100. 'title' => _t('_adm_txt_modules_recompile_global_paramaters'),
  101. ),
  102. 'recompile_menus' => array(
  103. 'title' => _t('_adm_txt_modules_recompile_menus'),
  104. ),
  105. 'recompile_site_stats' => array(
  106. 'title' => _t('_adm_txt_modules_recompile_site_stats'),
  107. ),
  108. 'recompile_comments' => array(
  109. 'title' => _t('_adm_txt_modules_recompile_comments'),
  110. ),
  111. 'recompile_member_actions' => array(
  112. 'title' => _t('_adm_txt_modules_recompile_member_actions'),
  113. ),
  114. 'recompile_votes' => array(
  115. 'title' => _t('_adm_txt_modules_recompile_votes'),
  116. ),
  117. 'recompile_search' => array(
  118. 'title' => _t('_adm_txt_modules_recompile_search'),
  119. ),
  120. 'recompile_injections' => array(
  121. 'title' => _t('_adm_txt_modules_recompile_injections'),
  122. ),
  123. 'recompile_permalinks' => array(
  124. 'title' => _t('_adm_txt_modules_recompile_permalinks'),
  125. ),
  126. 'recompile_alerts' => array(
  127. 'title' => _t('_adm_txt_modules_recompile_alerts'),
  128. ),
  129. 'clear_db_cache' => array(
  130. 'title' => _t('_adm_txt_modules_clear_db_cache'),
  131. ),
  132. 'show_conclusion' => array(
  133. 'title' => _t('_adm_txt_modules_show_conclusion'),
  134. ),
  135. );
  136. $this->_aNonHashableFiles = array(
  137. 'install',
  138. 'updates'
  139. );
  140. }
  141. public function install($aParams, $bAutoEnable = false)
  142. {
  143. $bAutoEnable = $bAutoEnable || (isset($aParams['auto_enable']) && (bool)$aParams['auto_enable']);
  144. $bHtmlResponce = isset($aParams['html_response']) && (bool)$aParams['html_response'];
  145. //--- Check whether the module was already installed ---//
  146. if($this->oDb->isModule($this->_aConfig['home_uri']))
  147. return array(
  148. 'message' => _t('_adm_err_modules_already_installed'),
  149. 'result' => false
  150. );
  151. $aResult = array();
  152. bx_alert('system', 'before_install', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
  153. if ($aResult && !$aResult['result'])
  154. return $aResult;
  155. //--- Check mandatory settings ---//
  156. if($this->oDb->isModuleParamsUsed($this->_aConfig['home_uri'], $this->_aConfig['home_dir'], $this->_aConfig['db_prefix'], $this->_aConfig['class_prefix']))
  157. return array(
  158. 'message' => _t('_adm_txt_modules_params_used'),
  159. 'result' => false
  160. );
  161. //--- Check version compatibility ---//
  162. if(!$this->_isCompatibleWith())
  163. return array(
  164. 'message' => $this->_displayResult('check_script_version', false, '_adm_err_modules_wrong_version_script', $bHtmlResponce),
  165. 'result' => false
  166. );
  167. //--- Check for available translations ---//
  168. $oFile = $this->_getFileManager();
  169. $sModuleUri = $this->_aConfig['home_uri'];
  170. $aLanguages = $this->oDb->getModulesBy(array('type' => 'languages'));
  171. foreach($aLanguages as $aLanguage) {
  172. if($aLanguage['uri'] == 'en')
  173. continue;
  174. $aLanguageConfig = self::getModuleConfig(BX_DIRECTORY_PATH_MODULES . $aLanguage['path'] . '/install/config.php');
  175. if(empty($aLanguageConfig))
  176. continue;
  177. if(!isset($aLanguageConfig['includes'][$sModuleUri]) || empty($aLanguageConfig['includes'][$sModuleUri]))
  178. continue;
  179. $sSrcPath = 'modules/' . $aLanguage['path'] . 'install/data/' . $aLanguageConfig['includes'][$sModuleUri];
  180. $sDstPath = $aLanguageConfig['includes'][$sModuleUri];
  181. $oFile->copy($sSrcPath, $sDstPath);
  182. }
  183. //--- Check actions ---//
  184. $aResult = $this->_perform('install', $aParams);
  185. if($aResult['result']) {
  186. $sDependencies = "";
  187. if(isset($this->_aConfig['install']['check_dependencies']) && (int)$this->_aConfig['install']['check_dependencies'] == 1 && isset($this->_aConfig['dependencies']) && is_array($this->_aConfig['dependencies']))
  188. $this->_aConfig['dependencies'] = array_keys($this->_aConfig['dependencies']);
  189. $iModuleId = $this->oDb->insertModule($this->_aConfig);
  190. bx_import('BxDolModule');
  191. $sTitleKey = BxDolModule::getTitleKey($this->_aConfig['home_uri']);
  192. bx_import('BxDolStudioLanguagesUtils');
  193. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  194. $oLanguages->addLanguageString($sTitleKey, $this->_aConfig['title']);
  195. $oLanguages->compileLanguage();
  196. bx_import('BxDolStudioInstallerUtils');
  197. BxDolStudioInstallerUtils::getInstance()->checkModules();
  198. $aFiles = array();
  199. $this->hashFiles($this->_sModulePath, $aFiles);
  200. foreach($aFiles as $aFile)
  201. $this->oDb->insertModuleTrack($iModuleId, $aFile);
  202. $this->oDb->cleanMemory('sys_modules_' . $this->_aConfig['home_uri']);
  203. $this->oDb->cleanMemory('sys_modules_' . $iModuleId);
  204. $this->oDb->cleanMemory('sys_modules');
  205. }
  206. bx_alert('system', 'install', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
  207. if($aResult['result'] && $bAutoEnable) {
  208. $aResultEnable = $this->enable($aParams);
  209. $aResult['result'] = $aResult['result'] & $aResultEnable['result'];
  210. $aResult['message'] = $aResult['message'] . $aResultEnable['message'];
  211. }
  212. return $aResult;
  213. }
  214. public function uninstall($aParams, $bAutoDisable = false)
  215. {
  216. $bAutoDisable = $bAutoDisable || (isset($aParams['auto_disable']) && (bool)$aParams['auto_disable']);
  217. $bHtmlResponce = isset($aParams['html_response']) && (bool)$aParams['html_response'];
  218. //--- Check whether the module was already uninstalled ---//
  219. if(!$this->oDb->isModule($this->_aConfig['home_uri']))
  220. return array(
  221. 'message' => _t('_adm_err_modules_already_uninstalled'),
  222. 'result' => false
  223. );
  224. if($bAutoDisable) {
  225. $aResultDisable = $this->disable($aParams);
  226. if(!$aResultDisable['result'])
  227. return $aResultDisable;
  228. }
  229. $aResult = array();
  230. bx_alert('system', 'before_uninstall', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
  231. if ($aResult && !$aResult['result'])
  232. return $aResult;
  233. //--- Check for dependent modules ---//
  234. $bDependent = false;
  235. $aDependents = $this->oDb->getDependent($this->_aConfig['home_uri']);
  236. if(is_array($aDependents) && !empty($aDependents)) {
  237. $bDependent = true;
  238. $sMessage = '<br />' . _t('_adm_err_modules_wrong_dependency_uninstall') . '<br />';
  239. foreach($aDependents as $aDependent)
  240. $sMessage .= $aDependent['title'] . '<br />';
  241. }
  242. if($bDependent)
  243. return array(
  244. 'message' => $this->_displayResult('check_dependencies', false, $sMessage, $bHtmlResponce),
  245. 'result' => false
  246. );
  247. $aResult = $this->_perform('uninstall', $aParams);
  248. if($aResult['result']) {
  249. $iModuleId = $this->oDb->deleteModule($this->_aConfig);
  250. bx_import('BxDolModule');
  251. $sTitleKey = BxDolModule::getTitleKey($this->_aConfig['home_uri']);
  252. bx_import('BxDolStudioLanguagesUtils');
  253. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  254. $oLanguages->deleteLanguageString($sTitleKey);
  255. $oLanguages->compileLanguage();
  256. $this->oDb->cleanMemory ('sys_modules_' . $this->_aConfig['home_uri']);
  257. $this->oDb->cleanMemory ('sys_modules_' . $iModuleId);
  258. $this->oDb->cleanMemory ('sys_modules');
  259. }
  260. if($bAutoDisable) {
  261. $aResult['result'] = $aResultDisable['result'] & $aResult['result'];
  262. $aResult['message'] = $aResultDisable['message'] . $aResult['message'];
  263. }
  264. bx_alert('system', 'uninstall', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
  265. return $aResult;
  266. }
  267. public function delete($aParams)
  268. {
  269. $aError = array(
  270. 'message' => _t('_adm_err_modules_cannot_remove_package'),
  271. 'result' => false
  272. );
  273. $oFile = $this->_getFileManager();
  274. if(empty($oFile))
  275. return $aError;
  276. if(!$oFile->delete('modules/' . $this->_aConfig['home_dir']))
  277. return $aError;
  278. return array(
  279. 'message' => '', //_t('_adm_msg_modules_success_delete'),
  280. 'result' => true
  281. );
  282. }
  283. public function recompile($aParams)
  284. {
  285. bx_import('BxDolStudioLanguagesUtils');
  286. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  287. $aResult = array('message' => '', 'result' => false);
  288. $aLanguages = $this->oDb->getLanguages();
  289. if (isAdmin() && !empty($aLanguages)) {
  290. $this->_updateLanguage(false, current($aLanguages));
  291. $bResult = false;
  292. foreach($aLanguages as $aLanguage) {
  293. $bResult = $this->_updateLanguage(true, $aLanguage) && $oLanguages->compileLanguage($aLanguage['id']);
  294. $aResult['message'] .= $aLanguage['title'] . ': <span style="color:' . ($bResult ? 'green' : 'red') . '">' . _t($bResult ? '_adm_txt_modules_process_action_success' : '_adm_txt_modules_process_action_failed') . '</span><br />';
  295. $aResult['result'] |= $bResult;
  296. }
  297. }
  298. return $aResult;
  299. }
  300. public function enable($aParams)
  301. {
  302. $aModule = $this->oDb->getModuleByUri($this->_aConfig['home_uri']);
  303. //--- Check whether the module is installed ---//
  304. if(empty($aModule) || !is_array($aModule))
  305. return array(
  306. 'message' => _t('_adm_err_modules_module_not_installed'),
  307. 'result' => false
  308. );
  309. //--- Check whether the module is already enabled ---//
  310. if((int)$aModule['enabled'] != 0)
  311. return array(
  312. 'message' => _t('_adm_err_modules_already_enabled'),
  313. 'result' => false
  314. );
  315. $aResult = array();
  316. bx_alert('system', 'before_enable', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
  317. if ($aResult && !$aResult['result'])
  318. return $aResult;
  319. $aResult = $this->_perform('enable', $aParams);
  320. if($aResult['result']) {
  321. $this->oDb->enableModuleByUri($aModule['uri']);
  322. $this->oDb->cleanMemory('sys_modules_' . $aModule['uri']);
  323. $this->oDb->cleanMemory('sys_modules_' . $aModule['id']);
  324. $this->oDb->cleanMemory('sys_modules');
  325. }
  326. bx_alert('system', 'enable', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
  327. return $aResult;
  328. }
  329. public function disable($aParams)
  330. {
  331. $bHtmlResponce = isset($aParams['html_response']) && (bool)$aParams['html_response'];
  332. $aModule = $this->oDb->getModuleByUri($this->_aConfig['home_uri']);
  333. //--- Check whether the module is installed ---//
  334. if(empty($aModule) || !is_array($aModule))
  335. return array(
  336. 'message' => _t('_adm_err_modules_module_not_installed'),
  337. 'result' => false
  338. );
  339. //--- Check whether the module is already disabled ---//
  340. if((int)$aModule['enabled'] == 0)
  341. return array(
  342. 'message' => _t('_adm_err_modules_already_disabled'),
  343. 'result' => false
  344. );
  345. $aResult = array();
  346. bx_alert('system', 'before_disable', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
  347. if ($aResult && !$aResult['result'])
  348. return $aResult;
  349. //--- Check for dependent modules ---//
  350. $bDependent = false;
  351. $aDependents = $this->oDb->getDependent($this->_aConfig['home_uri']);
  352. if(is_array($aDependents) && !empty($aDependents)) {
  353. $bDependent = true;
  354. $sMessage = '<br />' . _t('_adm_err_modules_wrong_dependency_disable') . '<br />';
  355. foreach($aDependents as $aDependent)
  356. $sMessage .= $aDependent['title'] . '<br />';
  357. }
  358. if($bDependent)
  359. return array(
  360. 'message' => $this->_displayResult('check_dependencies', false, $sMessage, $bHtmlResponce),
  361. 'result' => false
  362. );
  363. $aResult = $this->_perform('disable', $aParams);
  364. if($aResult['result']) {
  365. $this->oDb->disableModuleByUri($aModule['uri']);
  366. $this->oDb->cleanMemory('sys_modules_' . $aModule['uri']);
  367. $this->oDb->cleanMemory('sys_modules_' . $aModule['id']);
  368. $this->oDb->cleanMemory('sys_modules');
  369. }
  370. bx_alert('system', 'disable', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
  371. return $aResult;
  372. }
  373. protected function filePathWithoutBase($sPath)
  374. {
  375. return bx_ltrim_str($sPath, $this->_sModulePath);
  376. }
  377. function _perform($sOperationName, $aParams = array())
  378. {
  379. $bHtmlResponce = isset($aParams['html_response']) && (bool)$aParams['html_response'];
  380. if(!defined('BX_SKIP_INSTALL_CHECK') && !defined('BX_DOL_CRON_EXECUTE') && !$GLOBALS['logged']['admin'])
  381. return array('message' => '_adm_mod_err_only_admin_can_perform_operations_with_modules', 'result' => false);
  382. $sMessage = '';
  383. foreach($this->_aConfig[$sOperationName] as $sAction => $iEnabled) {
  384. $sMethod = 'action' . bx_gen_method_name($sAction);
  385. if($iEnabled == 0 || !method_exists($this, $sMethod))
  386. continue;
  387. $mixedResult = $this->$sMethod($sOperationName);
  388. //--- On Success ---//
  389. if((is_int($mixedResult) && (int)$mixedResult == BX_DOL_STUDIO_INSTALLER_SUCCESS) || (isset($mixedResult['code']) && (int)$mixedResult['code'] == BX_DOL_STUDIO_INSTALLER_SUCCESS)) {
  390. $sMessage .= $this->_displayResult($sAction, true, isset($mixedResult['content']) ? $mixedResult['content'] : '', $bHtmlResponce);
  391. continue;
  392. }
  393. //--- On Failed ---//
  394. $sMethodFailed = $sMethod . 'Failed';
  395. return array('message' => $this->_displayResult($sAction, false, method_exists($this, $sMethodFailed) ? $this->$sMethodFailed($mixedResult) : $this->actionOperationFailed($mixedResult), $bHtmlResponce), 'result' => false);
  396. }
  397. if($this->_bShowOnSuccess)
  398. $sMessage = $this->_aActions['perform_' . $sOperationName]['success'] . $sMessage;
  399. return array('message' => $sMessage, 'result' => true);
  400. }
  401. function _displayResult($sAction, $bResult, $sResult = '', $bHtmlResponse = true)
  402. {
  403. if($bResult && !in_array($sAction, array('show_introduction', 'show_conclusion')) && !$this->_bShowOnSuccess)
  404. return '';
  405. $sTitle = $this->_aActions[$sAction]['title'] . ' ';
  406. if(!empty($sResult))
  407. $sResult = (substr($sResult, 0, 1) == '_' ? _t($sResult) : $sResult);
  408. $sContent = !empty($sResult) ? $sResult : _t($bResult ? '_adm_txt_modules_process_action_success' : '_adm_err_modules_process_action_failed');
  409. if(!$bHtmlResponse)
  410. return $sTitle . $sContent;
  411. bx_import('BxDolStudioTemplate');
  412. return BxDolStudioTemplate::getInstance()->parseHtmlByName('mod_action_result_step.html', array(
  413. 'color' => $bResult ? 'green' : 'red',
  414. 'title' => $sTitle,
  415. 'content' => $sContent
  416. ));
  417. }
  418. //--- Action Methods ---//
  419. function actionOperationFailed($mixedResult)
  420. {
  421. return _t('_adm_err_modules_process_action_failed');
  422. }
  423. function actionCheckDependencies($sOperation)
  424. {
  425. $sContent = '';
  426. if(in_array($sOperation, array('install', 'enable', 'update'))) {
  427. if(!isset($this->_aConfig['dependencies']) || !is_array($this->_aConfig['dependencies']))
  428. return BX_DOL_STUDIO_INSTALLER_SUCCESS;
  429. foreach($this->_aConfig['dependencies'] as $sModuleUri => $sModuleTitle)
  430. if(!$this->oDb->isModule($sModuleUri))
  431. $sContent .= $sModuleTitle . '<br />';
  432. if(!empty($sContent))
  433. $sContent = '<br />' . _t('_adm_err_modules_wrong_dependency_install') . '<br />' . $sContent;
  434. }
  435. return empty($sContent) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : array('code' => BX_DOL_STUDIO_INSTALLER_FAILED, 'content' => $sContent);
  436. }
  437. function actionCheckDependenciesFailed($mixedResult)
  438. {
  439. return $mixedResult['content'];
  440. }
  441. function actionShowIntroduction($sOperation)
  442. {
  443. if(!isset($this->_aConfig[$sOperation . '_info']['introduction']))
  444. return BX_DOL_STUDIO_INSTALLER_FAILED;
  445. $sPath = $this->_sHomePath . 'install/info/' . $this->_aConfig[$sOperation . '_info']['introduction'];
  446. return file_exists($sPath) ? array("code" => BX_DOL_STUDIO_INSTALLER_SUCCESS, "content" => file_get_contents($sPath)) : BX_DOL_STUDIO_INSTALLER_FAILED;
  447. }
  448. function actionShowConclusion($sOperation)
  449. {
  450. if(!isset($this->_aConfig[$sOperation . '_info']['conclusion']))
  451. return BX_DOL_STUDIO_INSTALLER_FAILED;
  452. $sPath = $this->_sHomePath . 'install/info/' . $this->_aConfig[$sOperation . '_info']['conclusion'];
  453. return file_exists($sPath) ? array("code" => BX_DOL_STUDIO_INSTALLER_SUCCESS, "content" => file_get_contents($sPath)) : BX_DOL_STUDIO_INSTALLER_FAILED;
  454. }
  455. function actionMoveSources($sOperation)
  456. {
  457. $oFile = $this->_getFileManager();
  458. $aInstalled = array_merge(array('system'), $this->oDb->getModulesUri());
  459. $bResult = true;
  460. foreach($this->_aConfig['includes'] as $sUri => $sPath) {
  461. if(!in_array($sUri, $aInstalled) || empty($sPath))
  462. continue;
  463. if($sOperation == 'install') {
  464. $sSrcPath = 'modules/' . $this->_aConfig['home_dir'] . 'install/data/' . $sPath;
  465. $sDstPath = $sPath;
  466. $bResult &= $oFile->copy($sSrcPath, $sDstPath);
  467. } else if($sOperation == 'uninstall')
  468. $bResult &= $oFile->delete($sPath);
  469. }
  470. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  471. }
  472. function actionExecuteSql($sOperation)
  473. {
  474. switch($sOperation) {
  475. case 'install':
  476. $this->actionExecuteSql('disable');
  477. $this->actionExecuteSql('uninstall');
  478. break;
  479. case 'enable':
  480. $this->actionExecuteSql('disable');
  481. break;
  482. }
  483. $mixedResult = $this->oDb->executeSQL($this->_sHomePath . 'install/sql/' . $sOperation . '.sql', $this->getMarkersForDb());
  484. return $mixedResult === true ? BX_DOL_STUDIO_INSTALLER_SUCCESS : array('code' => BX_DOL_STUDIO_INSTALLER_FAILED, 'content' => $mixedResult);
  485. }
  486. function actionExecuteSqlFailed($mixedResult)
  487. {
  488. if(is_int($mixedResult))
  489. return $this->actionOperationFailed($mixedResult);
  490. $sResult = '<br />' . _t('_adm_err_modules_wrong_mysql_query') . '<br />';
  491. foreach($mixedResult['content'] as $aQuery) {
  492. $sResult .= _t('_adm_err_modules_wrong_mysql_query_msg', $aQuery['error']) . '<br />';
  493. $sResult .= '<pre>' . $aQuery['query'] . '</pre>';
  494. }
  495. return $sResult;
  496. }
  497. function actionInstallLanguage($sOperation)
  498. {
  499. bx_import('BxDolStudioLanguagesUtils');
  500. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  501. $sLanguage = isset($this->_aConfig['home_uri']) ? $this->_aConfig['home_uri'] : '';
  502. $bResult = true;
  503. if($sOperation == 'install')
  504. $bResult = $oLanguages->installLanguage(array('path' => $this->_aConfig['home_dir'], 'uri' => $this->_aConfig['home_uri'], 'lang_category' => $this->_aConfig['language_category']),false);
  505. return $bResult && $oLanguages->compileLanguage(0, true) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  506. }
  507. function actionUpdateLanguages($sOperation)
  508. {
  509. if(!isset($this->_aConfig['language_category']) || empty($this->_aConfig['language_category']))
  510. return BX_DOL_STUDIO_INSTALLER_FAILED;
  511. bx_import('BxDolStudioLanguagesUtils');
  512. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  513. $bResult = true;
  514. $aResult = array();
  515. //--- Process Language Category ---//
  516. if($sOperation == 'install')
  517. $iCategoryId = $oLanguages->addLanguageCategory($this->_aConfig['language_category']);
  518. //--- Process languages' key=>value pears ---//
  519. $aModule = array(
  520. 'path' => $this->_aConfig['home_dir'],
  521. 'uri' => $this->_aConfig['home_uri'],
  522. 'lang_category' => $this->_aConfig['language_category']
  523. );
  524. if($sOperation == 'install')
  525. $bResult = $oLanguages->restoreLanguage(0, $aModule, false);
  526. else if($sOperation == 'uninstall')
  527. $bResult = $oLanguages->removeLanguageByModule($aModule, false);
  528. if($sOperation == 'uninstall' && $bResult)
  529. $oLanguages->deleteLanguageCategory($this->_aConfig['language_category']);
  530. return $bResult && $oLanguages->compileLanguage(0, true) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  531. }
  532. function actionUpdateRelations($sOperation)
  533. {
  534. if(!in_array($sOperation, array('install', 'uninstall', 'enable', 'disable')))
  535. return BX_DOL_STUDIO_INSTALLER_FAILED;
  536. if(empty($this->_aConfig['relations']) || !is_array($this->_aConfig['relations']))
  537. return BX_DOL_STUDIO_INSTALLER_SUCCESS;
  538. foreach($this->_aConfig['relations'] as $sModule) {
  539. if(!$this->oDb->isModuleByName($sModule))
  540. continue;
  541. $aRelation = $this->oDb->getRelationsBy(array('type' => 'module', 'value' => $sModule));
  542. if(empty($aRelation) || empty($aRelation['on_' . $sOperation]) || !BxDolRequest::serviceExists($aRelation['module'], $aRelation['on_' . $sOperation]))
  543. continue;
  544. BxDolService::call($aRelation['module'], $aRelation['on_' . $sOperation], array($this->_aConfig['home_uri']));
  545. }
  546. return BX_DOL_STUDIO_INSTALLER_SUCCESS;
  547. }
  548. function actionProcessDeletedProfiles($sOperation)
  549. {
  550. if(!in_array($sOperation, array('install', 'uninstall', 'enable', 'disable')))
  551. return BX_DOL_STUDIO_INSTALLER_FAILED;
  552. bx_import('BxDolProfileQuery');
  553. $o = BxDolProfileQuery::getInstance();
  554. $o->processDeletedProfiles();
  555. return BX_DOL_STUDIO_INSTALLER_SUCCESS;
  556. }
  557. function actionRecompileGlobalParamaters($sOperation)
  558. {
  559. $bResult = $this->oDb->cacheParamsClear();
  560. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  561. }
  562. function actionRecompileMenus($sOperation)
  563. {
  564. $bResult = $this->oDb->cleanCache('sys_objects_menu');
  565. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  566. }
  567. function actionRecompileSiteStats($sOperation)
  568. {
  569. $bResult = $this->oDb->cleanCache('sys_stat_site');
  570. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  571. }
  572. function actionRecompileComments($sOperation)
  573. {
  574. $bResult = $this->oDb->cleanCache('sys_objects_cmts');
  575. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  576. }
  577. function actionRecompileMemberActions($sOperation)
  578. {
  579. $bResult = $this->oDb->cleanCache('sys_objects_actions');
  580. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  581. }
  582. function actionRecompileVotes($sOperation)
  583. {
  584. $bResult = $this->oDb->cleanCache('sys_objects_vote');
  585. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  586. }
  587. function actionRecompileInjections($sOperation)
  588. {
  589. $bResult = $this->oDb->cleanCache('sys_injections.inc');
  590. $bResult = $bResult && $this->oDb->cleanCache('sys_injections_admin.inc');
  591. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  592. }
  593. function actionRecompilePermalinks($sOperation)
  594. {
  595. $bResult = true;
  596. bx_import('BxDolPermalinks');
  597. $bResult = $bResult && BxDolPermalinks::getInstance()->cacheInvalidate();
  598. $bResult = $bResult && ($this->actionRecompileMenus($sOperation) == BX_DOL_STUDIO_INSTALLER_SUCCESS);
  599. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  600. }
  601. function actionRecompileAlerts($sOperation)
  602. {
  603. $bResult = $this->oDb->cleanCache('sys_alerts');
  604. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  605. }
  606. function actionClearDbCache($sOperation)
  607. {
  608. $oCache = $this->oDb->getDbCacheObject();
  609. $bResult = $oCache->removeAllByPrefix('db_');
  610. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  611. }
  612. //--- Get/Set Methods ---//
  613. function getVendor()
  614. {
  615. return $this->_aConfig['vendor'];
  616. }
  617. function getName()
  618. {
  619. return $this->_aConfig['name'];
  620. }
  621. function getTitle()
  622. {
  623. return $this->_aConfig['title'];
  624. }
  625. function getHomeDir()
  626. {
  627. return $this->_aConfig['home_dir'];
  628. }
  629. //--- Protected methods ---//
  630. protected function _getFileManager()
  631. {
  632. $oFile = null;
  633. if($this->_bUseFtp) {
  634. bx_import('BxDolFtp');
  635. $oFile = new BxDolFtp(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost', getParam('sys_ftp_login'), getParam('sys_ftp_password'), getParam('sys_ftp_dir'));
  636. if(!$oFile->connect())
  637. return null;
  638. if(!$oFile->isDolphin())
  639. return null;
  640. }
  641. else {
  642. bx_import('BxDolFile');
  643. $oFile = BxDolFile::getInstance();
  644. }
  645. return $oFile;
  646. }
  647. protected function _isCompatibleWith()
  648. {
  649. $sVersionCur = bx_get_ver();
  650. $bCompatible = false;
  651. if(isset($this->_aConfig['compatible_with']) && is_array($this->_aConfig['compatible_with']))
  652. foreach($this->_aConfig['compatible_with'] as $iKey => $sVersionReq)
  653. $bCompatible = $bCompatible || (version_compare($sVersionCur, $sVersionReq, '>=') == 1);
  654. return $bCompatible;
  655. }
  656. protected function getMarkersForDb()
  657. {
  658. return array(
  659. 'from' => array('{db_name}'),
  660. 'to' => array(defined('BX_DATABASE_NAME') ? BX_DATABASE_NAME : ''),
  661. );
  662. }
  663. }
  664. /** @} */