BxSEMigModule.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 Social Engine 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', $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. }
  83. /**
  84. * Inits connect with Social Engine database
  85. * @return Boolean
  86. */
  87. public function initSEDb(){
  88. $aConfig = array(
  89. 'host' => $this -> _oDb -> getExtraParam('host'),
  90. 'user' => $this -> _oDb -> getExtraParam('username'),
  91. 'pwd' => $this -> _oDb -> getExtraParam('password'),
  92. 'name' => $this -> _oDb -> getExtraParam('dbname'),
  93. 'charset' => $this -> _oDb -> getExtraParam('charset'),
  94. 'port' => '',
  95. 'sock' => ''
  96. );
  97. $this -> _oSEDb = new SEDB($aConfig);
  98. return $this -> _oSEDb -> connect();
  99. }
  100. /**
  101. * Returns Password Ecnrypted by Seocial Engine Rules
  102. * @param object
  103. */
  104. public function serviceEncryptPassword($oAlert){
  105. // if imported member tries to login set new hash for password
  106. if (isset($oAlert -> aExtras['info']['se_id']) && (int)$oAlert -> aExtras['info']['se_id']){
  107. $oAlert -> aExtras['password'] = $this -> _oDb -> encryptPassword($oAlert -> aExtras['pwd'], $oAlert -> aExtras['info']['salt']);
  108. }
  109. }
  110. }
  111. /** @} */