BxSEMigDb.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. bx_import('BxDolDb');
  12. class BxSEMigDb extends BxBaseModGeneralDb
  13. {
  14. public function __construct(&$oConfig)
  15. {
  16. parent::__construct($oConfig);
  17. }
  18. /**
  19. * Saving Social Engine config info
  20. * @param array $aConfig parameters
  21. */
  22. public function saveConfig($aConfig){
  23. if( is_array($aConfig) ) {
  24. $bRecords = false;
  25. foreach($aConfig as $sName => $mValue)
  26. {
  27. $mValue = bx_process_input($mValue);
  28. $sName = bx_process_input($sName);
  29. $sQuery = $this -> prepare("REPLACE INTO `{$this -> _sPrefix}config` SET `name` = ?, `value` = ?", $sName, $mValue);
  30. if ($this -> res($sQuery)) $bRecords = true;
  31. }
  32. }
  33. }
  34. /**
  35. * Get Social Engine config parameter
  36. * @param string $sConfigName param's name
  37. * @return string
  38. */
  39. public function getExtraParam($sConfigName){
  40. $sQuery = $this -> prepare("SELECT `value` FROM `{$this -> _sPrefix}config` WHERE `name` = ?", $sConfigName);
  41. return $this -> getOne($sQuery);
  42. }
  43. /**
  44. * Create migration list
  45. * @param array $aConfig social engine config info
  46. */
  47. public function createConfig($aConfig){
  48. if( is_array($aConfig) ) {
  49. foreach($aConfig as $sName => $mValue)
  50. {
  51. $mValue = $this -> escape($mValue);
  52. $sName = $this -> escape($sName);
  53. // create new;
  54. if( !$this -> getExtraParam($sName) ) {
  55. $sQuery = $this -> prepare("INSERT INTO `{$this -> _sPrefix}config` SET `name` = ?, `value` = ?", $sName, $mValue);
  56. $this -> query($sQuery);
  57. }
  58. else {
  59. // update exsisting;
  60. $sQuery = $this -> prepare("UPDATE `{$this -> _sPrefix}config` SET `value` = ? WHERE `name` = ?", $mValue, $sName);
  61. $this -> query($sQuery);
  62. }
  63. }
  64. }
  65. }
  66. /**
  67. * Returns Migration Result information
  68. * @param string $sModule name
  69. * @return string
  70. */
  71. public function getTransferStatusText($sModule)
  72. {
  73. $sQuery = $this -> prepare("SELECT `status_text` FROM `{$this -> _sPrefix}transfers` WHERE `module` = ? LIMIT 1", $sModule);
  74. return $this -> getOne($sQuery);
  75. }
  76. /**
  77. * Returns current migration status
  78. * @param string $sModule name
  79. * @return string
  80. */
  81. public function getTransferStatus($sModule)
  82. {
  83. $sQuery = $this -> prepare("SELECT `status` FROM `{$this -> _sPrefix}transfers` WHERE `module` = ? LIMIT 1", $sModule);
  84. return $this -> getOne($sQuery);
  85. }
  86. public function updateTransferStatus($sModule, $sStatus){
  87. $this -> query("UPDATE `{$this -> _sPrefix}transfers` SET `status` = :status WHERE `module` = :module", array('module' => $sModule, 'status' => $sStatus));
  88. }
  89. /**
  90. * Check if social engine configuration exists
  91. * @return Boolean
  92. */
  93. public function isConfigInstalled(){
  94. return $this -> getExtraParam('dbname') && $this -> getExtraParam('username');
  95. }
  96. /**
  97. * Adds module for migration to migration list
  98. * @param string $sName modules name
  99. * @param int $iNumber records number
  100. * @return mixed
  101. */
  102. public function addToTransferList($sName, $iNumber){
  103. return $this -> query("REPLACE INTO `{$this -> _sPrefix}transfers` SET `module` = :module, `status` = 'not_started', `number` = :number", array('module' => $sName, 'number' => $iNumber));
  104. }
  105. public function getTransfers(){
  106. return $this -> getAll("SELECT * FROM `{$this -> _sPrefix}transfers` ORDER BY `id`");
  107. }
  108. /**
  109. * Check whether requiered Una plugin installed for transferring
  110. * @param string $sName pugin name
  111. * @return Boolean
  112. */
  113. public function isPluginInstalled($sName){
  114. $sQuery = $this -> prepare("SELECT COUNT(*) FROM `sys_modules` WHERE `type` = 'module' AND `name` = ? LIMIT 1" , $sName);
  115. return (int)$this -> getOne($sQuery) == 1;
  116. }
  117. public function encryptPassword($sPwd, $sSalt){
  118. return md5($this -> getParam('se_migration_salt') . $sPwd. $sSalt);
  119. }
  120. public function updateSEId($iAccountId, $iVal = 0){
  121. $sQuery = $this -> prepare("UPDATE `sys_accounts` SET `se_id` = ? WHERE `id` = ?", (int)$iVal, (int)$iAccountId);
  122. return $this -> query($sQuery);
  123. }
  124. }
  125. /** @} */