BxDolStudioInstaller.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. <?php
  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. defined('BX_DOL') or die('hack attempt');
  10. bx_import('BxDolInstallerUtils');
  11. bx_import('BxDolStudioInstallerQuery');
  12. define("BX_DOL_STUDIO_INSTALLER_SUCCESS", 0);
  13. define("BX_DOL_STUDIO_INSTALLER_FAILED", 1);
  14. /**
  15. * Base class for Installer classes in modules engine.
  16. *
  17. * The class contains different check functions which are used during the installation process.
  18. * An object of the class is created automatically with Dolphin's modules installer.
  19. * Installation/Uninstallation process can be controlled with config.php file located in [module]/install/ folder.
  20. *
  21. *
  22. * Example of usage:
  23. * @see any module included in the default Dolphin's package.
  24. *
  25. *
  26. * Memberships/ACL:
  27. * Doesn't depend on user's membership.
  28. *
  29. *
  30. * Alerts:
  31. * no alerts available
  32. *
  33. */
  34. class BxDolStudioInstaller extends BxDolInstallerUtils {
  35. var $oDb;
  36. var $_aConfig;
  37. var $_sBasePath;
  38. var $_sHomePath;
  39. var $_sModulePath;
  40. var $_aActions;
  41. var $_aNonHashable;
  42. var $_bShowOnSuccess = false;
  43. function BxDolStudioInstaller($aConfig) {
  44. parent::BxDolInstallerUtils();
  45. $this->oDb = new 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->_aActions = array(
  51. 'perform_install' => array(
  52. 'title' => '',
  53. 'success' => _t('_adm_msg_modules_success_install'),
  54. 'failed' => ''
  55. ),
  56. 'perform_uninstall' => array(
  57. 'title' => '',
  58. 'success' => _t('_adm_msg_modules_success_uninstall'),
  59. 'failed' => ''
  60. ),
  61. 'perform_enable' => array(
  62. 'title' => '',
  63. 'success' => _t('_adm_msg_modules_success_enable'),
  64. 'failed' => ''
  65. ),
  66. 'perform_disable' => array(
  67. 'title' => '',
  68. 'success' => _t('_adm_msg_modules_success_disable'),
  69. 'failed' => ''
  70. ),
  71. 'check_script_version' => array(
  72. 'title' => _t('_adm_txt_modules_check_script_version'),
  73. ),
  74. 'check_dependencies' => array(
  75. 'title' => _t('_adm_txt_modules_check_dependencies'),
  76. ),
  77. 'show_introduction' => array(
  78. 'title' => _t('_adm_txt_modules_show_introduction'),
  79. ),
  80. 'change_permissions' => array(
  81. 'title' => _t('_adm_txt_modules_change_permissions'),
  82. ),
  83. 'move_sources' => array(
  84. 'title' => _t('_adm_txt_modules_move_sources'),
  85. ),
  86. 'execute_sql' => array(
  87. 'title' => _t('_adm_txt_modules_execute_sql'),
  88. ),
  89. 'install_language' => array(
  90. 'title' => _t('_adm_txt_modules_install_language'),
  91. ),
  92. 'update_languages' => array(
  93. 'title' => _t('_adm_txt_modules_update_languages'),
  94. ),
  95. 'recompile_global_paramaters' => array(
  96. 'title' => _t('_adm_txt_modules_recompile_global_paramaters'),
  97. ),
  98. 'recompile_main_menu' => array(
  99. 'title' => _t('_adm_txt_modules_recompile_main_menu'),
  100. ),
  101. 'recompile_member_menu' => array(
  102. 'title' => _t('_adm_txt_modules_recompile_member_menu'),
  103. ),
  104. 'recompile_site_stats' => array(
  105. 'title' => _t('_adm_txt_modules_recompile_site_stats'),
  106. ),
  107. 'recompile_page_builder' => array(
  108. 'title' => _t('_adm_txt_modules_recompile_page_builder'),
  109. ),
  110. 'recompile_profile_fields' => array(
  111. 'title' => _t('_adm_txt_modules_recompile_profile_fields'),
  112. ),
  113. 'recompile_comments' => array(
  114. 'title' => _t('_adm_txt_modules_recompile_comments'),
  115. ),
  116. 'recompile_member_actions' => array(
  117. 'title' => _t('_adm_txt_modules_recompile_member_actions'),
  118. ),
  119. 'recompile_tags' => array(
  120. 'title' => _t('_adm_txt_modules_recompile_tags'),
  121. ),
  122. 'recompile_votes' => array(
  123. 'title' => _t('_adm_txt_modules_recompile_votes'),
  124. ),
  125. 'recompile_categories' => array(
  126. 'title' => _t('_adm_txt_modules_recompile_categories'),
  127. ),
  128. 'recompile_search' => array(
  129. 'title' => _t('_adm_txt_modules_recompile_search'),
  130. ),
  131. 'recompile_injections' => array(
  132. 'title' => _t('_adm_txt_modules_recompile_injections'),
  133. ),
  134. 'recompile_permalinks' => array(
  135. 'title' => _t('_adm_txt_modules_recompile_permalinks'),
  136. ),
  137. 'recompile_alerts' => array(
  138. 'title' => _t('_adm_txt_modules_recompile_alerts'),
  139. ),
  140. 'clear_db_cache' => array(
  141. 'title' => _t('_adm_txt_modules_clear_db_cache'),
  142. ),
  143. 'show_conclusion' => array(
  144. 'title' => _t('_adm_txt_modules_show_conclusion'),
  145. ),
  146. );
  147. $this->_aNonHashable = array(
  148. 'install',
  149. 'updates'
  150. );
  151. }
  152. public function install($aParams, $bEnable = false) {
  153. //--- Check whether the module was already installed ---//
  154. if($this->oDb->isModule($this->_aConfig['home_uri']))
  155. return array(
  156. 'message' => _t('_adm_err_modules_already_installed'),
  157. 'result' => false
  158. );
  159. //--- Check mandatory settings ---//
  160. if($this->oDb->isModuleParamsUsed($this->_aConfig['home_uri'], $this->_aConfig['home_dir'], $this->_aConfig['db_prefix'], $this->_aConfig['class_prefix']))
  161. return array(
  162. 'message' => _t('_adm_txt_modules_params_used'),
  163. 'result' => false
  164. );
  165. //--- Check version compatibility ---//
  166. $bCompatible = false;
  167. if(isset($this->_aConfig['compatible_with']) && is_array($this->_aConfig['compatible_with']))
  168. foreach($this->_aConfig['compatible_with'] as $iKey => $sVersion) {
  169. $sVersion = '/^' . str_replace(array('.', 'x'), array('\.', '[0-9]+'), $sVersion) . '$/is';
  170. $bCompatible = $bCompatible || (preg_match($sVersion, BX_DOL_VERSION . '.' . BX_DOL_BUILD) > 0);
  171. }
  172. if(!$bCompatible)
  173. return array(
  174. 'message' => $this->_displayResult('check_script_version', false, '_adm_err_modules_wrong_version_script'),
  175. 'result' => false
  176. );
  177. //--- Check for available translations ---//
  178. $oFile = $this->_getFileManager();
  179. $sModuleUri = $this->_aConfig['home_uri'];
  180. $aLanguages = $this->oDb->getModulesBy(array('type' => 'languages'));
  181. foreach($aLanguages as $aLanguage) {
  182. if($aLanguage['uri'] == 'en')
  183. continue;
  184. $sLanguageConfig = BX_DIRECTORY_PATH_MODULES . $aLanguage['path'] . '/install/config.php';
  185. if(!file_exists($sLanguageConfig))
  186. continue;
  187. include_once($sLanguageConfig);
  188. $aLanguageConfig = &$aConfig;
  189. if(!isset($aLanguageConfig['includes'][$sModuleUri]) || empty($aLanguageConfig['includes'][$sModuleUri]))
  190. continue;
  191. $sSrcPath = 'modules/' . $aLanguage['path'] . 'install/data/' . $aLanguageConfig['includes'][$sModuleUri];
  192. $sDstPath = $aLanguageConfig['includes'][$sModuleUri];
  193. $oFile->copy($sSrcPath, $sDstPath);
  194. }
  195. //--- Check actions ---//
  196. $aResult = $this->_perform('install');
  197. if($aResult['result']) {
  198. $sDependencies = "";
  199. if(isset($this->_aConfig['install']['check_dependencies']) && (int)$this->_aConfig['install']['check_dependencies'] == 1 && isset($this->_aConfig['dependencies']) && is_array($this->_aConfig['dependencies']))
  200. $this->_aConfig['dependencies'] = array_keys($this->_aConfig['dependencies']);
  201. $iModuleId = $this->oDb->insertModule($this->_aConfig);
  202. bx_import('BxDolModule');
  203. $sTitleKey = BxDolModule::getTitleKey($this->_aConfig['home_uri']);
  204. bx_import('BxDolStudioLanguagesUtils');
  205. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  206. $oLanguages->addLanguageString($sTitleKey, $this->_aConfig['title']);
  207. $oLanguages->compileLanguage();
  208. $aFiles = array();
  209. $this->_hash($this->_sModulePath, $aFiles);
  210. foreach($aFiles as $aFile)
  211. $this->oDb->insertModuleTrack($iModuleId, $aFile);
  212. $this->oDb->cleanMemory('sys_modules_' . $this->_aConfig['home_uri']);
  213. $this->oDb->cleanMemory('sys_modules_' . $iModuleId);
  214. $this->oDb->cleanMemory('sys_modules');
  215. }
  216. if($bEnable) {
  217. $aResultEnable = $this->enable($aParams);
  218. $aResult['result'] = $aResult['result'] & $aResultEnable['result'];
  219. $aResult['message'] = $aResult['message'] . $aResultEnable['message'];
  220. }
  221. return $aResult;
  222. }
  223. public function uninstall($aParams, $bDisable = false) {
  224. //--- Check whether the module was already uninstalled ---//
  225. if(!$this->oDb->isModule($this->_aConfig['home_uri']))
  226. return array(
  227. 'message' => _t('_adm_err_modules_already_uninstalled'),
  228. 'result' => false
  229. );
  230. //--- Check for dependent modules ---//
  231. $bDependent = false;
  232. $aDependents = $this->oDb->getDependent($this->_aConfig['home_uri']);
  233. if(is_array($aDependents) && !empty($aDependents)) {
  234. $bDependent = true;
  235. $sMessage = '<br />-- -- ' . _t('_adm_err_modules_wrong_dependency_uninstall') . '<br />';
  236. foreach($aDependents as $aDependent)
  237. $sMessage .= '-- -- ' . $aDependent['title'] . '<br />';
  238. }
  239. if($bDependent)
  240. return array(
  241. 'message' => $this->_displayResult('check_dependencies', false, $sMessage),
  242. 'result' => false
  243. );
  244. $aResult = $this->_perform('uninstall');
  245. if($aResult['result']) {
  246. $iModuleId = $this->oDb->deleteModule($this->_aConfig);
  247. bx_import('BxDolModule');
  248. $sTitleKey = BxDolModule::getTitleKey($this->_aConfig['home_uri']);
  249. bx_import('BxDolStudioLanguagesUtils');
  250. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  251. $oLanguages->deleteLanguageString($sTitleKey);
  252. $oLanguages->compileLanguage();
  253. $this->oDb->cleanMemory ('sys_modules_' . $this->_aConfig['home_uri']);
  254. $this->oDb->cleanMemory ('sys_modules_' . $iModuleId);
  255. $this->oDb->cleanMemory ('sys_modules');
  256. }
  257. if($bDisable) {
  258. $aResultEnable = $this->disable($aParams);
  259. $aResult['result'] = $aResult['result'] & $aResultEnable['result'];
  260. $aResult['message'] = $aResult['message'] . $aResultEnable['message'];
  261. }
  262. return $aResult;
  263. }
  264. public function delete() {
  265. bx_import('BxDolFtp');
  266. $oFtp = new BxDolFtp($_SERVER['HTTP_HOST'], getParam('sys_ftp_login'), getParam('sys_ftp_password'), getParam('sys_ftp_dir'));
  267. if(!$oFtp->connect())
  268. return array(
  269. 'message' => _t('_adm_err_modules_cannot_connect_to_ftp'),
  270. 'result' => false
  271. );
  272. if(!$oFtp->delete('modules/' . $this->_aConfig['home_dir']))
  273. return array(
  274. 'message' => _t('_adm_err_modules_cannot_remove_package'),
  275. 'result' => false
  276. );
  277. return array(
  278. 'message' => '', //_t('_adm_msg_modules_success_delete'),
  279. 'result' => true
  280. );
  281. }
  282. public function recompile($aParams) {
  283. bx_import('BxDolStudioLanguagesUtils');
  284. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  285. $aResult = array('message' => '', 'result' => false);
  286. $aLanguages = $this->oDb->getLanguages();
  287. if (isAdmin() && !empty($aLanguages)) {
  288. $this->_updateLanguage(false, current($aLanguages));
  289. $bResult = false;
  290. foreach($aLanguages as $aLanguage) {
  291. $bResult = $this->_updateLanguage(true, $aLanguage) && $oLanguages->compileLanguage($aLanguage['id']);
  292. $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 />';
  293. $aResult['result'] |= $bResult;
  294. }
  295. }
  296. return $aResult;
  297. }
  298. public function enable($aParams) {
  299. $aModule = $this->oDb->getModuleByUri($this->_aConfig['home_uri']);
  300. //--- Check whether the module is installed ---//
  301. if(empty($aModule) || !is_array($aModule))
  302. return array(
  303. 'message' => _t('_adm_err_modules_module_not_installed'),
  304. 'result' => false
  305. );
  306. //--- Check whether the module is already enabled ---//
  307. if((int)$aModule['enabled'] != 0)
  308. return array(
  309. 'message' => _t('_adm_err_modules_already_enabled'),
  310. 'result' => false
  311. );
  312. $aResult = $this->_perform('enable');
  313. if($aResult['result']) {
  314. $this->oDb->enableModuleByUri($aModule['uri']);
  315. $this->oDb->cleanMemory('sys_modules_' . $aModule['uri']);
  316. $this->oDb->cleanMemory('sys_modules_' . $aModule['id']);
  317. $this->oDb->cleanMemory('sys_modules');
  318. }
  319. return $aResult;
  320. }
  321. public function disable($aParams) {
  322. $aModule = $this->oDb->getModuleByUri($this->_aConfig['home_uri']);
  323. //--- Check whether the module is installed ---//
  324. if(empty($aModule) || !is_array($aModule))
  325. return array(
  326. 'message' => _t('_adm_err_modules_module_not_installed'),
  327. 'result' => false
  328. );
  329. //--- Check whether the module is already disabled ---//
  330. if((int)$aModule['enabled'] == 0)
  331. return array(
  332. 'message' => _t('_adm_err_modules_already_disabled'),
  333. 'result' => false
  334. );
  335. //--- Check for dependent modules ---//
  336. $bDependent = false;
  337. $aDependents = $this->oDb->getDependent($this->_aConfig['home_uri']);
  338. if(is_array($aDependents) && !empty($aDependents)) {
  339. $bDependent = true;
  340. $sMessage = '<br />-- -- ' . _t('_adm_err_modules_wrong_dependency_disable') . '<br />';
  341. foreach($aDependents as $aDependent)
  342. $sMessage .= '-- -- ' . $aDependent['title'] . '<br />';
  343. }
  344. if($bDependent)
  345. return array(
  346. 'message' => $this->_displayResult('check_dependencies', false, $sMessage),
  347. 'result' => false
  348. );
  349. $aResult = $this->_perform('disable');
  350. if($aResult['result']) {
  351. $this->oDb->disableModuleByUri($aModule['uri']);
  352. $this->oDb->cleanMemory('sys_modules_' . $aModule['uri']);
  353. $this->oDb->cleanMemory('sys_modules_' . $aModule['id']);
  354. $this->oDb->cleanMemory('sys_modules');
  355. }
  356. return $aResult;
  357. }
  358. function _hash($sPath, &$aFiles) {
  359. if(file_exists($sPath) && is_dir($sPath) && ($rSource = opendir($sPath))) {
  360. while(($sFile = readdir($rSource)) !== false) {
  361. if($sFile == '.' || $sFile =='..' || $sFile[0] == '.' || in_array($sFile, $this->_aNonHashable))
  362. continue;
  363. if(is_dir($sPath . $sFile))
  364. $this->_hash($sPath . $sFile . '/', $aFiles);
  365. else
  366. $aFiles[] = $this->_info($sPath . $sFile);
  367. }
  368. closedir($rSource);
  369. }
  370. else
  371. $aFiles[] = $this->_info($sPath, $sFile);
  372. }
  373. function _info($sPath) {
  374. return array(
  375. 'file' => str_replace($this->_sModulePath, '', $sPath),
  376. 'hash' => md5(file_get_contents($sPath))
  377. );
  378. }
  379. function _perform($sOperationName) {
  380. if(!defined('BX_SKIP_INSTALL_CHECK') && !$GLOBALS['logged']['admin'])
  381. return array('message' => '', 'result' => false);
  382. $sMessage = '';
  383. foreach($this->_aConfig[$sOperationName] as $sAction => $iEnabled) {
  384. $sMethod = 'action' . str_replace (' ', '', ucwords(str_replace ('_', ' ', $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'] : '');
  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)), '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 = '') {
  402. $sMessage = '-- ' . $this->_aActions[$sAction]['title'] . ' ';
  403. if(!empty($sResult) && substr($sResult, 0, 1) == '_')
  404. $sResult = _t($sResult) . '<br />';
  405. if(!$bResult)
  406. return $sMessage . '<span style="color:red; font-weight:bold;">' . $sResult . '</span>';
  407. if($bResult && !in_array($sAction, array('show_introduction', 'show_conclusion')) && !$this->_bShowOnSuccess)
  408. return;
  409. return $sMessage . '<span style="color:green; font-weight:bold;">' . (!empty($sResult) ? $sResult : _t('_adm_txt_modules_process_action_success') . '<br />') . '</span>';
  410. }
  411. //--- Action Methods ---//
  412. function actionOperationFailed($mixedResult) {
  413. return _t('_adm_err_modules_process_action_failed');
  414. }
  415. function actionCheckDependencies($sOperation) {
  416. $sContent = '';
  417. if(in_array($sOperation, array('install', 'enable', 'update'))) {
  418. if(!isset($this->_aConfig['dependencies']) || !is_array($this->_aConfig['dependencies']))
  419. return BX_DOL_STUDIO_INSTALLER_SUCCESS;
  420. foreach($this->_aConfig['dependencies'] as $sModuleUri => $sModuleTitle)
  421. if(!$this->oDb->isModule($sModuleUri))
  422. $sContent .= '-- -- ' . $sModuleTitle . '<br />';
  423. if(!empty($sContent))
  424. $sContent = '<br />-- -- ' . _t('_adm_err_modules_wrong_dependency_install') . '<br />' . $sContent;
  425. }
  426. return empty($sContent) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : array('code' => BX_DOL_STUDIO_INSTALLER_FAILED, 'content' => $sContent);
  427. }
  428. function actionCheckDependenciesFailed($mixedResult) {
  429. return $mixedResult['content'];
  430. }
  431. function actionShowIntroduction($sOperation) {
  432. if(!isset($this->_aConfig[$sOperation . '_info']['introduction']))
  433. return BX_DOL_STUDIO_INSTALLER_FAILED;
  434. $sPath = $this->_sHomePath . 'install/info/' . $this->_aConfig[$sOperation . '_info']['introduction'];
  435. return file_exists($sPath) ? array("code" => BX_DOL_STUDIO_INSTALLER_SUCCESS, "content" => "<pre>" . file_get_contents($sPath) . "</pre>") : BX_DOL_STUDIO_INSTALLER_FAILED;
  436. }
  437. function actionShowConclusion($sOperation) {
  438. if(!isset($this->_aConfig[$sOperation . '_info']['conclusion']))
  439. return BX_DOL_STUDIO_INSTALLER_FAILED;
  440. $sPath = $this->_sHomePath . 'install/info/' . $this->_aConfig[$sOperation . '_info']['conclusion'];
  441. return file_exists($sPath) ? array("code" => BX_DOL_STUDIO_INSTALLER_SUCCESS, "content" => "<pre>" . file_get_contents($sPath) . "</pre>") : BX_DOL_STUDIO_INSTALLER_FAILED;
  442. }
  443. function actionChangePermissions($sOperation) {
  444. if(!isset($this->_aConfig[$sOperation . '_permissions']) || !is_array($this->_aConfig[$sOperation . '_permissions']))
  445. return BX_DOL_STUDIO_INSTALLER_FAILED;
  446. $aResult = array();
  447. $aPermissions = $this->_aConfig[$sOperation . '_permissions'];
  448. foreach($aPermissions as $sPermissions => $aFiles) {
  449. $sCheckFunction = 'is' . ucfirst($sPermissions);
  450. $sCptPermissions = _t('_adm_txt_modules_' . $sPermissions);
  451. foreach($aFiles as $sFile)
  452. if(!BxDolInstallerUtils::$sCheckFunction(str_replace(BX_DIRECTORY_PATH_ROOT, '', $this->_sModulePath . $sFile)))
  453. $aResult[] = array('path' => $this->_sModulePath . $sFile, 'permissions' => $sCptPermissions);
  454. }
  455. return empty($aResult) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : array('code' => BX_DOL_STUDIO_INSTALLER_FAILED, 'content' => $aResult);
  456. }
  457. function actionChangePermissionsFailed($mixedResult) {
  458. $sResult = '<br />-- -- ' . _t('_adm_err_modules_wrong_permissions') . '<br />';
  459. foreach($mixedResult['content'] as $aFile)
  460. $sResult .= '-- -- ' . _t('_adm_err_modules_wrong_permissions_msg', $aFile['path'], $aFile['permissions']) . '<br />';
  461. return $sResult;
  462. }
  463. function actionMoveSources($sOperation) {
  464. $oFile = $this->_getFileManager();
  465. $aInstalled = array_merge(array('system'), $this->oDb->getModulesUri());
  466. $bResult = true;
  467. foreach($this->_aConfig['includes'] as $sUri => $sPath) {
  468. if(!in_array($sUri, $aInstalled) || empty($sPath))
  469. continue;
  470. if($sOperation == 'install') {
  471. $sSrcPath = 'modules/' . $this->_aConfig['home_dir'] . 'install/data/' . $sPath;
  472. $sDstPath = $sPath;
  473. $bResult &= $oFile->copy($sSrcPath, $sDstPath);
  474. }
  475. else if($sOperation == 'uninstall')
  476. $bResult &= $oFile->delete($sPath);
  477. }
  478. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  479. }
  480. function actionExecuteSql($sOperation) {
  481. switch($sOperation) {
  482. case 'install':
  483. $this->actionExecuteSql('disable');
  484. $this->actionExecuteSql('uninstall');
  485. break;
  486. case 'enable':
  487. $this->actionExecuteSql('disable');
  488. break;
  489. }
  490. $sPath = $this->_sHomePath . 'install/sql/' . $sOperation . '.sql';
  491. if(!file_exists($sPath) || !($rHandler = fopen($sPath, "r")))
  492. return BX_DOL_STUDIO_INSTALLER_FAILED;
  493. $sQuery = "";
  494. $sDelimiter = ';';
  495. $aResult = array();
  496. while(!feof($rHandler)) {
  497. $sStr = trim(fgets($rHandler));
  498. if(empty($sStr) || $sStr[0] == "" || $sStr[0] == "#" || ($sStr[0] == "-" && $sStr[1] == "-"))
  499. continue;
  500. //--- Change delimiter ---//
  501. if(strpos($sStr, "DELIMITER //") !== false || strpos($sStr, "DELIMITER ;") !== false) {
  502. $sDelimiter = trim(str_replace('DELIMITER', '', $sStr));
  503. continue;
  504. }
  505. $sQuery .= $sStr;
  506. //--- Check for multiline query ---//
  507. if(substr($sStr, -strlen($sDelimiter)) != $sDelimiter)
  508. continue;
  509. //--- Execute query ---//
  510. if($sDelimiter != ';')
  511. $sQuery = str_replace($sDelimiter, "", $sQuery);
  512. $rResult = db_res(trim($sQuery), false);
  513. if(!$rResult)
  514. $aResult[] = array('query' => $sQuery, 'error' => BxDolDb::getInstance()->getErrorMessage());
  515. $sQuery = "";
  516. }
  517. fclose($rHandler);
  518. return empty($aResult) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : array('code' => BX_DOL_STUDIO_INSTALLER_FAILED, 'content' => $aResult);
  519. }
  520. function actionExecuteSqlFailed($mixedResult) {
  521. $sResult = '<br />-- -- ' . _t('_adm_err_modules_wrong_mysql_query') . '<br />';
  522. foreach($mixedResult['content'] as $aQuery) {
  523. $sResult .= '-- -- ' . _t('_adm_err_modules_wrong_mysql_query_msg', $aQuery['error']) . '<br />';
  524. $sResult .= '<pre>' . $aQuery['query'] . '</pre>';
  525. }
  526. return $sResult;
  527. }
  528. function actionInstallLanguage($sOperation) {
  529. bx_import('BxDolStudioLanguagesUtils');
  530. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  531. $sLanguage = isset($this->_aConfig['home_uri']) ? $this->_aConfig['home_uri'] : '';
  532. $bResult = true;
  533. if($sOperation == 'install')
  534. $bResult = $oLanguages->installLanguage(array('path' => $this->_aConfig['home_dir'], 'uri' => $this->_aConfig['home_uri'], 'lang_category' => $this->_aConfig['language_category']),false);
  535. return $bResult && $oLanguages->compileLanguage(0, true) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  536. }
  537. function actionUpdateLanguages($sOperation) {
  538. if(!isset($this->_aConfig['language_category']) || empty($this->_aConfig['language_category']))
  539. return BX_DOL_STUDIO_INSTALLER_FAILED;
  540. bx_import('BxDolStudioLanguagesUtils');
  541. $oLanguages = BxDolStudioLanguagesUtils::getInstance();
  542. $bResult = true;
  543. $aResult = array();
  544. //--- Process Language Category ---//
  545. if($sOperation == 'install')
  546. $iCategoryId = $oLanguages->addLanguageCategory($this->_aConfig['language_category']);
  547. //--- Process languages' key=>value pears ---//
  548. $aModule = array(
  549. 'path' => $this->_aConfig['home_dir'],
  550. 'uri' => $this->_aConfig['home_uri'],
  551. 'lang_category' => $this->_aConfig['language_category']
  552. );
  553. if($sOperation == 'install')
  554. $bResult = $oLanguages->restoreLanguage(0, $aModule, false);
  555. else if($sOperation == 'uninstall')
  556. $bResult = $oLanguages->removeLanguageByModule($aModule, false);
  557. if($sOperation == 'uninstall' && $bResult)
  558. $oLanguages->deleteLanguageCategory($this->_aConfig['language_category']);
  559. return $bResult && $oLanguages->compileLanguage(0, true) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  560. }
  561. function actionRecompileGlobalParamaters($sOperation) {
  562. $bResult = $this->oDb->oParams->cache();
  563. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  564. }
  565. function actionRecompileMainMenu($sOperation) {
  566. /*
  567. TODO: Update the code when menu engine is rewrited.
  568. bx_import('BxDolMenu');
  569. $bResult = BxDolMenu::getInstance()->_compile();
  570. */
  571. $bResult = true;
  572. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  573. }
  574. function actionRecompileMemberMenu($sOperation) {
  575. /*
  576. //TODO: Recreate if the feature will be available.
  577. bx_import('BxDolMemberMenu');
  578. $oMemberMenu = new BxDolMemberMenu();
  579. $bResult = $oMemberMenu->deleteMemberMenuCaches();
  580. */
  581. $bResult = true;
  582. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  583. }
  584. function actionRecompileSiteStats($sOperation) {
  585. $bResult = $this->oDb->cleanCache('sys_stat_site');
  586. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  587. }
  588. function actionRecompilePageBuilder($sOperation) {
  589. /*
  590. //TODO: Recreate when cache engine is available.
  591. bx_import('BxDolPageViewCacher');
  592. ob_start();
  593. $oPVCacher = new BxDolPageViewCacher('sys_page_compose', 'sys_page_compose.inc');
  594. $bResult = $oPVCacher->createCache();
  595. ob_get_clean();
  596. */
  597. $bResult = true;
  598. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  599. }
  600. function actionRecompileProfileFields($sOperation) {
  601. /*
  602. //TODO: Recreate when cache engine is available.
  603. bx_import('BxDolPFMCacher');
  604. ob_start();
  605. $oBxDolPFMCacher = new BxDolPFMCacher();
  606. $bResult = $oBxDolPFMCacher -> createCache();
  607. ob_get_clean();
  608. */
  609. $bResult = true;
  610. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  611. }
  612. function actionRecompileComments($sOperation) {
  613. $bResult = $this->oDb->cleanCache('sys_objects_cmts');
  614. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  615. }
  616. function actionRecompileMemberActions($sOperation) {
  617. $bResult = $this->oDb->cleanCache('sys_objects_actions');
  618. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  619. }
  620. function actionRecompileTags($sOperation) {
  621. $bResult = $this->oDb->cleanCache('sys_objects_tag');
  622. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  623. }
  624. function actionRecompileVotes($sOperation) {
  625. $bResult = $this->oDb->cleanCache('sys_objects_vote');
  626. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  627. }
  628. function actionRecompileCategories($sOperation) {
  629. $bResult = $this->oDb->cleanCache('sys_objects_categories');
  630. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  631. }
  632. function actionRecompileInjections($sOperation) {
  633. $bResult = $this->oDb->cleanCache('sys_injections.inc');
  634. $bResult = $bResult && $this->oDb->cleanCache('sys_injections_admin.inc');
  635. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  636. }
  637. function actionRecompilePermalinks($sOperation) {
  638. $bResult = true;
  639. ob_start();
  640. bx_import('BxDolPermalinks');
  641. $bResult = $bResult && BxDolPermalinks::getInstance()->cache();
  642. /*
  643. TODO: Update the code when menu engine is rewrited.
  644. bx_import('BxDolMenu');
  645. $bResult = $bResult && BxDolMenu::getInstance()->_compile();
  646. */
  647. $bResult = $bResult && $this->oDb->cleanCache('sys_menu_member');
  648. ob_get_clean();
  649. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  650. }
  651. function actionRecompileAlerts($sOperation) {
  652. $bResult = $this->oDb->cleanCache('sys_alerts');
  653. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  654. }
  655. function actionClearDbCache($sOperation) {
  656. $oCache = $this->oDb->getDbCacheObject();
  657. $bResult = $oCache->removeAllByPrefix('db_');
  658. return $bResult ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
  659. }
  660. //--- Get/Set Methods ---//
  661. function getVendor() {
  662. return $this->_aConfig['vendor'];
  663. }
  664. function getName() {
  665. return $this->_aConfig['name'];
  666. }
  667. function getTitle() {
  668. return $this->_aConfig['title'];
  669. }
  670. function getHomeDir() {
  671. return $this->_aConfig['home_dir'];
  672. }
  673. //--- Protected methods ---//
  674. protected function _getPermissions($sFilePath) {
  675. clearstatcache();
  676. $hPerms = @fileperms($sFilePath);
  677. if($hPerms == false)
  678. return false;
  679. return substr( decoct( $hPerms ), -3 );
  680. }
  681. protected function _getFileManager($bUseFtp = false) {
  682. $oFile = null;
  683. if($bUseFtp) {
  684. bx_import('BxDolFtp');
  685. $oFile = new BxDolFtp(BX_DOL_URL_ROOT, $this->oDb->getParam('sys_ftp_login'), $this->oDb->getParam('sys_ftp_password'), $this->oDb->getParam('sys_ftp_dir'));
  686. }
  687. else {
  688. bx_import('BxDolFile');
  689. $oFile = BxDolFile::getInstance();
  690. }
  691. return $oFile;
  692. }
  693. }
  694. /** @} */