BxDolMStudioPage.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 DolphinMigration Dolphin Migration
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. require_once('BxDolMTransfers.php');
  12. class BxDolMStudioPage extends BxTemplStudioModule
  13. {
  14. /**
  15. * @var ref $_oModule main module reference
  16. */
  17. protected $_oModule;
  18. function __construct($sModule, $mixedPageName, $sPage = "")
  19. {
  20. $this -> MODULE = 'bx_dolphin_migration';
  21. parent::__construct($sModule, $mixedPageName, $sPage);
  22. $this -> _oModule = BxDolModule::getInstance($sModule);
  23. $this->aMenuItems = array(
  24. 'settings' => array('name' => 'settings', 'icon' => 'cogs', 'title' => '_bx_dolphin_migration_cpt_settings'),
  25. 'config' => array('name' => 'config', 'icon' => 'exchange-alt', 'title' => '_bx_dolphin_migration_cpt_transfer_data')
  26. );
  27. $this -> _oModule -> _oTemplate -> addStudioJs(array('jquery-ui/jquery-ui.custom.min.js', 'transfer.js', 'BxDolGrid.js'));
  28. $this -> _oModule -> _oTemplate -> addStudioCss(array('main.css'));
  29. }
  30. public function saveData($sPath)
  31. {
  32. $aConfig = array();
  33. if (substr($sPath, strlen($sPath) - 1 ) != DIRECTORY_SEPARATOR)
  34. $sPath .= DIRECTORY_SEPARATOR;
  35. // get settings from Dolphin's header file info;
  36. $sConfigFile = "{$sPath}inc" . DIRECTORY_SEPARATOR . "header.inc.php";
  37. if (file_exists($sConfigFile))
  38. {
  39. $sFile = @file_get_contents($sConfigFile);
  40. preg_match_all('/\s*\$(db|dir)\[[\'"](.*)[\'"]\]\s*=\s*[\'"](.*)[\'"];/im', $sFile, $aData);
  41. for($i=0; $i < sizeof($aData[1]); $i++)
  42. if (($aData[1][$i] == 'dir' && $aData[2][$i] == 'root') || $aData[1][$i] == 'db')
  43. $aConfig[$aData[2][$i]] = trim($aData[3][$i], "'");
  44. }
  45. if (empty($aConfig))
  46. return MsgBox( _t('_bx_dolphin_migration_error_config_file_was_not_found'));
  47. if(!empty($aConfig)) {
  48. $this -> _oModule -> _oDb -> saveConfig($aConfig);
  49. $this -> _oModule -> createMigration();
  50. if ($this -> _oModule -> initDb())
  51. $this -> _oModule -> createMigration();
  52. else
  53. return MsgBox( _t('_bx_dolphin_migration_error_data_was_not_set'), 2);
  54. }
  55. else
  56. return MsgBox( _t('_bx_dolphin_migration_error_data_was_not_set'), 2);
  57. return MsgBox( _t('_bx_dolphin_migration_data_was_set'), 2);
  58. }
  59. private function getPathSettings()
  60. {
  61. $sMessage = '';
  62. if (isset($_POST['save']))
  63. $sMessage = $this -> saveData(bx_get('path'));
  64. if (isset($_POST['clean']))
  65. $this -> _oModule -> _oDb -> removeConfig();
  66. $aForm = array(
  67. 'params' => array(
  68. 'db' => array(
  69. 'submit_name' => 'save'
  70. )
  71. ),
  72. 'inputs' => array (
  73. 'path' => array(
  74. 'type' => 'text',
  75. 'name' => 'path',
  76. 'caption' => $this -> _oModule -> _oDb -> isConfigInstalled() ? _t('_bx_dolphin_migration_defined_path') : _t('_bx_dolphin_migration_cpt_put_path'),
  77. 'value' => $this -> _oModule -> _oDb -> getExtraParam('root')
  78. ),
  79. 'buttons' => array (
  80. 'name' => 'buttons',
  81. 'type' => 'input_set',
  82. array(
  83. 'type' => 'submit',
  84. 'name' => 'save',
  85. 'value' => _t('_bx_dolphin_migration_cpt_' . ($this -> _oModule -> _oDb -> getExtraParam('root') ? 'update' : 'save'))
  86. ),
  87. array(
  88. 'type' => 'submit',
  89. 'name' => 'clean',
  90. 'value' => _t('_bx_dolphin_migration_cpt_clean'),
  91. 'attrs' => array('onclick' => "javascript:return confirm('" . bx_js_string(_t('_bx_dolphin_migration_cpt_clean_warning')) . "');")
  92. ),
  93. )
  94. )
  95. );
  96. if ($this -> _oModule -> _oDb -> isConfigInstalled())
  97. $aForm['inputs']['buttons'][0]['attrs'] = array('onclick' => "javascript:return confirm('" . bx_js_string(_t('_bx_dolphin_migration_reupload_data')) . "');");
  98. $oForm = new BxTemplStudioFormView($aForm);
  99. return $sMessage . $oForm -> getCode();
  100. }
  101. protected function getConfig()
  102. {
  103. $oGrid = BxDolMTransfers::getObjectInstance('bx_dolphin_migration_transfers');
  104. $JsCode =<<<EOF
  105. <script>
  106. const check = () => {
  107. let oModules = $("[name=bx_dolphin_migration_transfers_check]:checked");
  108. if (oModules.length && typeof glGrids.bx_dolphin_migration_transfers != undefined)
  109. {
  110. let aModules = [];
  111. oModules.each(function(){
  112. aModules.push($(this).val());
  113. });
  114. glGrids.bx_dolphin_migration_transfers.iMigInterval = setInterval(function(){
  115. glGrids.bx_dolphin_migration_transfers.action(`finished`,{},`modules=` + aModules.join(','), true);
  116. }, {$this -> _oModule -> _oConfig -> _iCheckInterval})
  117. }
  118. };
  119. $("button[bx_grid_action_bulk='run']").bind('click', check);
  120. </script>
  121. EOF;
  122. if ($oGrid)
  123. return $this -> getPathSettings() . $oGrid -> getCode() . $JsCode; // print grid object
  124. return MsgBox(_t('_bx_dolphin_migration_installation_problem'));
  125. }
  126. }
  127. /** @} */