BxDevModule.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Developer Developer
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. require_once('BxDevFunctions.php');
  12. define('BX_DEV_TOOLS_SETTINGS', 'settings');
  13. define('BX_DEV_TOOLS_FORMS', 'forms');
  14. define('BX_DEV_TOOLS_PAGES', 'pages');
  15. define('BX_DEV_TOOLS_NAVIGATION', 'navigation');
  16. define('BX_DEV_TOOLS_POLYGLOT', 'polyglot');
  17. define('BX_DEV_TOOLS_PERMISSIONS', 'permissions');
  18. class BxDevModule extends BxDolModule
  19. {
  20. public $aTools;
  21. function __construct($aModule)
  22. {
  23. parent::__construct($aModule);
  24. $this->aTools = array(
  25. array('name' => BX_DEV_TOOLS_SETTINGS, 'title' => '_adm_page_cpt_settings', 'icon' => 'bx-dev-mi-settings.svg'),
  26. array('name' => BX_DEV_TOOLS_POLYGLOT, 'title' => '_adm_page_cpt_polyglot', 'icon' => 'bx-dev-mi-polyglot.svg'),
  27. array('name' => BX_DEV_TOOLS_FORMS, 'title' => '_adm_page_cpt_builder_forms', 'icon' => 'bx-dev-mi-forms.svg'),
  28. array('name' => BX_DEV_TOOLS_NAVIGATION, 'title' => '_adm_page_cpt_builder_menus', 'icon' => 'bx-dev-mi-navigation.svg'),
  29. array('name' => BX_DEV_TOOLS_PAGES, 'title' => '_adm_page_cpt_builder_pages', 'icon' => 'bx-dev-mi-pages.svg'),
  30. //array('name' => BX_DEV_TOOLS_PERMISSIONS, 'title' => '_adm_page_cpt_builder_permissions', 'icon' => 'bx-dev-mi-permissions.png'),
  31. );
  32. }
  33. function getToolsList()
  34. {
  35. return $this->aTools;
  36. }
  37. public function actionResetHash($sType, $sModule = '') {
  38. $oDb = bx_instance('BxDolStudioInstallerQuery');
  39. $sResult = '';
  40. switch ($sType) {
  41. case 'system':
  42. $oHasher = bx_instance('BxDolInstallerHasher');
  43. $oDb->deleteModuleTrackFiles(BX_SYSTEM_MODULE_ID);
  44. $sResult = _t('_bx_dev_hash_' . ($oHasher->hashSystemFiles() ? 'msg' : 'err') . '_reset_hash_system');
  45. break;
  46. case 'modules':
  47. $oModuleQuery = BxDolModuleQuery::getInstance();
  48. if(!empty($sModule)) {
  49. $aNames = strpos($sModule, ',') !== false ? explode(',', $sModule) : array($sModule);
  50. $aModule = array();
  51. foreach($aNames as $aName)
  52. $aModules[] = $oModuleQuery->getModuleByName($aName);
  53. }
  54. else
  55. $aModules = $oModuleQuery->getModules();
  56. $aTmplVarsModules = array();
  57. if(!empty($aModules) && is_array($aModules))
  58. foreach($aModules as $aModule) {
  59. if($aModule['name'] == 'system')
  60. continue;
  61. $aConfig = BxDolInstallerUtils::getModuleConfig($aModule);
  62. $sPathInstaller = BX_DIRECTORY_PATH_MODULES . $aModule['path'] . 'install/installer.php';
  63. if(empty($aConfig) || !file_exists($sPathInstaller))
  64. continue;
  65. require_once($sPathInstaller);
  66. $sClassName = $aConfig['class_prefix'] . 'Installer';
  67. $oInstaller = new $sClassName($aConfig);
  68. $oDb->deleteModuleTrackFiles($aModule['id']);
  69. $aFiles = array();
  70. $oInstaller->hashFiles(BX_DIRECTORY_PATH_ROOT . 'modules/' . $aModule['path'], $aFiles);
  71. foreach($aFiles as $aFile)
  72. $oDb->insertModuleTrack($aModule['id'], $aFile);
  73. $aTmplVarsModules[] = array(
  74. 'module' => $aModule['title'],
  75. 'files' => count($aFiles)
  76. );
  77. }
  78. $sResult = $this->_oTemplate->parseHtmlByName('hash_modules.html', array(
  79. 'bx_repeat:modules' => $aTmplVarsModules
  80. ));
  81. break;
  82. }
  83. echo $sResult;
  84. exit;
  85. }
  86. }
  87. /** @} */