BxSEMigModule.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 SocialEngineMigration SocialEngine Migration
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. require_once('BxSEDb.php');
  12. if ( function_exists('ini_set')) {
  13. ini_set('max_execution_time', 0);
  14. }
  15. define('_ENGINE', 1); //defined to allow including Social Engine config file
  16. class BxSEMigModule extends BxBaseModGeneralModule
  17. {
  18. protected $_oSEDb = null;
  19. public function __construct(&$aModule){
  20. parent::__construct($aModule);
  21. }
  22. public function actionStartTransfer($aModules){
  23. if (empty($aModules)){
  24. echo json_encode(array('code' => 1, 'message' => _t('_bx_se_migration_successfully_finished')));
  25. exit;
  26. }
  27. $this -> initSEDb();
  28. header('Content-Type:text/javascript');
  29. foreach($aModules as $iKey => $sModule){
  30. if( $sModule && !empty(($this -> _oConfig -> _aMigrationModules[$sModule]))) {
  31. $sTransferred = $this -> _oDb -> getTransferStatus($sModule);
  32. if ($sTransferred == 'finished') continue;
  33. if(is_array($this -> _oConfig -> _aMigrationModules[$sModule]['dependencies'])) {
  34. foreach($this -> _oConfig -> _aMigrationModules[$sModule]['dependencies'] as $iKey => $sDependenciesModule)
  35. {
  36. $sTransferred = $this -> _oDb -> getTransferStatus($sDependenciesModule);
  37. if( $sTransferred != 'finished')
  38. return _t('_bx_se_migration_install_before', _t("_bx_se_migration_data_{$sDependenciesModule}"));
  39. }
  40. }
  41. if(is_array($this -> _oConfig -> _aMigrationModules[$sModule]['plugins'])) {
  42. $sPlugins = '';
  43. foreach($this -> _oConfig -> _aMigrationModules[$sModule]['plugins'] as $sKey => $sTitle){
  44. if (!$this -> _oDb -> isPluginInstalled($sKey))
  45. $sPlugins .= $sTitle . ', ';
  46. }
  47. if ($sPlugins)
  48. return _t('_bx_se_migration_install_plugin', trim($sPlugins, ', '), $sModule);
  49. }
  50. // create new module's instance;
  51. require_once($this -> _oConfig -> _aMigrationModules[$sModule]['migration_class'] . '.php');
  52. $this -> sProcessedModule = $sModule;
  53. // set as started;
  54. $this -> _oDb -> updateTransferStatus($sModule, 'started');
  55. // create new migration instance;
  56. $oModule = new $this -> _oConfig -> _aMigrationModules[$sModule]['migration_class']($this, $this -> _oSEDb);
  57. if($oModule -> runMigration())
  58. $this -> _oDb -> updateTransferStatus($sModule, 'finished');
  59. else {
  60. $this -> _oDb -> updateTransferStatus($sModule, 'error');
  61. return _t('_bx_se_migration_successfully_failed');
  62. }
  63. }
  64. }
  65. return _t('_bx_se_migration_successfully_finished');
  66. }
  67. /**
  68. * Creates Migration Info before to start with number of records
  69. * @param ref $oSEDb social engine database connect
  70. */
  71. public function createMigration(){
  72. if (is_null($this -> _oSEDb)) $this -> initSEDb();
  73. foreach ($this -> _oConfig -> _aMigrationModules as $sName => $aModule){
  74. if ($this -> _oSEDb -> isTableExists($this -> _oConfig -> getEngineVersionPrefix() . $aModule['table_name'])){
  75. //Create transferring class object
  76. require_once($aModule['migration_class'] . '.php');
  77. $oObject = new $aModule['migration_class']($this, $this -> _oSEDb);
  78. if ($iNumber = $oObject -> getTotalRecords())
  79. $this -> _oDb -> addToTransferList($sName, $iNumber);
  80. }
  81. }
  82. //Get Social Engine Secret Salt
  83. $sSecret = $this -> _oSEDb -> getSEParam( $this -> _oConfig -> getEngineVersionPrefix() . "core_settings", 'core.secret');
  84. if ($sSecret) $this -> _oDb -> setParam('se_migration_salt', $sSecret);
  85. }
  86. /**
  87. * Inits connect with Social Engine database
  88. * @return Boolean
  89. */
  90. public function initSEDb(){
  91. $aConfig = array(
  92. 'host' => $this -> _oDb -> getExtraParam('host'),
  93. 'user' => $this -> _oDb -> getExtraParam('username'),
  94. 'pwd' => $this -> _oDb -> getExtraParam('password'),
  95. 'name' => $this -> _oDb -> getExtraParam('dbname'),
  96. 'charset' => $this -> _oDb -> getExtraParam('charset'),
  97. 'port' => '',
  98. 'sock' => ''
  99. );
  100. $this -> _oSEDb = new BxSEDb($aConfig);
  101. return $this -> _oSEDb -> connect();
  102. }
  103. public function serviceGetSafeServices()
  104. {
  105. return array ();
  106. }
  107. /**
  108. * Returns Password Ecnrypted by Seocial Engine Rules
  109. * @param object
  110. */
  111. public function serviceSocialEngineResponse($oAlert){
  112. // if imported member tries to login set new hash for password
  113. if ($oAlert -> sAction == 'encrypt_password_after' && isset($oAlert -> aExtras['info']['se_id']) && (int)$oAlert -> aExtras['info']['se_id']){
  114. $oAlert -> aExtras['password'] = $this -> _oDb -> encryptPassword($oAlert -> aExtras['pwd'], $oAlert -> aExtras['info']['salt']);
  115. }
  116. else if (isset($oAlert -> aExtras['action']) && $oAlert -> aExtras['action'] == 'forgot_password'){
  117. // set 0 for se_id - it means now member's password is encrypted using standard algorithm
  118. $this -> _oDb -> updateSEId($oAlert -> iObject);
  119. }
  120. }
  121. }
  122. /** @} */