BxDataMigrationDb.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /***************************************************************************
  3. * Dolphin Smart Community Builder
  4. * -------------------
  5. * begin : Mon Mar 23 2006
  6. * copyright : (C) 2007 BoonEx Group
  7. * website : http://www.boonex.com
  8. * This file is part of Dolphin - Smart Community Builder
  9. *
  10. * Dolphin is free software; you can redistribute it and/or modify it under
  11. * the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the
  13. * License, or any later version.
  14. *
  15. * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  16. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. * See the GNU General Public License for more details.
  18. * You should have received a copy of the GNU General Public License along with Dolphin,
  19. * see license.txt file; if not, write to marketing@boonex.com
  20. ***************************************************************************/
  21. require_once( BX_DIRECTORY_PATH_CLASSES . 'BxDolModuleDb.php' );
  22. class BxDataMigrationDb extends BxDolModuleDb
  23. {
  24. var $_oConfig;
  25. var $sTablePrefix;
  26. /**
  27. * Constructor.
  28. */
  29. function BxDataMigrationDb(&$oConfig)
  30. {
  31. parent::BxDolModuleDb();
  32. $this -> _oConfig = $oConfig;
  33. $this -> sTablePrefix = $oConfig -> getDbPrefix();
  34. }
  35. /**
  36. * Function will create some config;
  37. *
  38. * @param : $aConfig (array) - array with some of settings;
  39. * @return : void;
  40. */
  41. function createConfig($aConfig)
  42. {
  43. if( is_array($aConfig) ) {
  44. foreach($aConfig as $sName => $mValue)
  45. {
  46. $mValue = $this -> escape($mValue);
  47. $sName = $this -> escape($sName);
  48. // create new;
  49. if( !$this -> getExtraParam($sName) ) {
  50. $sQuery = "INSERT INTO `{$this -> sTablePrefix}config` SET `name` = '{$sName}', `value` = '{$mValue}'";
  51. $this -> query($sQuery);
  52. }
  53. else {
  54. // update exsisting;
  55. $sQuery = "UPDATE `{$this -> sTablePrefix}config` SET `value` = '{$mValue}' WHERE `name` = '{$sName}'";
  56. $this -> query($sQuery);
  57. }
  58. }
  59. }
  60. }
  61. /**
  62. * Function get transfer's status text;
  63. *
  64. * @param : $sModule (string) - module's name;
  65. * @param : $sStatus (string) - transfer's status;
  66. * @return : void;
  67. */
  68. function getTransferStatusText($sModule)
  69. {
  70. $sModule = $this -> escape($sModule);
  71. $sQuery = "SELECT `status_text` FROM `{$this->sTablePrefix}transfers` WHERE `module` = '{$sModule}' LIMIT 1";
  72. return $this -> getOne($sQuery);
  73. }
  74. /**
  75. * Function get transfer's status;
  76. *
  77. * @param : $sModule (string) - module's name;
  78. * @param : $sStatus (string) - transfer's status;
  79. * @return : void;
  80. */
  81. function getTransferStatus($sModule)
  82. {
  83. $sModule = $this -> escape($sModule);
  84. $sQuery = "SELECT `status` FROM `{$this->sTablePrefix}transfers` WHERE `module` = '{$sModule}' LIMIT 1";
  85. return $this -> getOne($sQuery);
  86. }
  87. /**
  88. * Function update transfer's status;
  89. *
  90. * @param : $sModule (string) - module's name;
  91. * @param : $sStatus (string) - transfer's status;
  92. * @return : void;
  93. */
  94. function updateTransferStatus($sModule, $sStatus)
  95. {
  96. $sModule = $this -> escape($sModule);
  97. $sStatus = $this -> escape($sStatus);
  98. $sQuery = "UPDATE `{$this->sTablePrefix}transfers` SET `status` = '{$sStatus}' WHERE `module` = '{$sModule}'";
  99. $this -> query($sQuery);
  100. }
  101. /**
  102. * Function will crete new transfer;
  103. *
  104. * @param : $sModule (string) - module's name;
  105. * @return : void;
  106. */
  107. function createTransfer($sModule)
  108. {
  109. $sModule = $this -> escape($sModule);
  110. $sQuery = "INSERT INTO `{$this->sTablePrefix}transfers` SET `module` = '{$sModule}', `status` = 'not_started'";
  111. $this -> query($sQuery);
  112. }
  113. /**
  114. * Function will get the first transfer;
  115. *
  116. * @return : (string) - module's name;
  117. */
  118. function getFirstTransfer()
  119. {
  120. $sQuery = "SELECT `module` FROM `{$this->sTablePrefix}transfers` WHERE `status` = 'not_started' ORDER BY `id` LIMIT 1";
  121. return $this -> getOne($sQuery);
  122. }
  123. /**
  124. * Function will delete transfer from queue;
  125. *
  126. * @param : $sModule (string) - module name;
  127. * @return : void;
  128. */
  129. function deleteTransfer($sModule)
  130. {
  131. $sModule = $this -> escape($sModule);
  132. $sQuery = "DELETE FROM `{$this->sTablePrefix}transfers` WHERE `module` = '{$sModule}'";
  133. $this -> query($sQuery);
  134. }
  135. /**
  136. * Function will check transfer exsiting;
  137. *
  138. * @param : $sModule (string) - module's name;
  139. * @return : (boolean) true if isset;
  140. */
  141. function checkTransfer($sModule)
  142. {
  143. $sModule = $this -> escape($sModule);
  144. $sQuery = "SELECT COUNT(*) FROM `{$this->sTablePrefix}transfers` WHERE `module` = '{$sModule}'";
  145. return $this -> getOne($sQuery) ? true : false;
  146. }
  147. /**
  148. * Function will get some config value;
  149. *
  150. * @param : $sConfigName (sting) - config name;
  151. * @return : (mixed) - config value;
  152. */
  153. function getExtraParam($sConfigName)
  154. {
  155. $sConfigName = $this -> escape($sConfigName);
  156. return $this -> getOne("SELECT `value` FROM `{$this->sTablePrefix}config` WHERE `name` = '{$sConfigName}'");
  157. }
  158. /**
  159. * Function will set some config value;
  160. *
  161. * @param : $sConfigName (sting) - config name;
  162. * @param : $mConfigValue (mixed) - config value;
  163. * @return : void;
  164. */
  165. function setExtraParam($sConfigName, $sConfigValue)
  166. {
  167. $sConfigName = $this -> escape($sConfigName);
  168. $sConfigValue = $this -> escape($sConfigValue);
  169. if( !$this -> getOne("SELECT `value` FROM `{$this->sTablePrefix}config` WHERE `name` = '{$sConfigName}'") ) {
  170. // create new;
  171. $sQuery = "INSERT INTO `{$this->sTablePrefix}config` SET `name` = '{$sConfigName}', `value` = '{$sConfigValue}'";
  172. }
  173. else {
  174. // update;
  175. $sQuery = "UPDATE `{$this->sTablePrefix}config` SET `value` = '{$sConfigValue}' WHERE `name` = '{$sConfigName}'";
  176. }
  177. $this -> query($sQuery);
  178. }
  179. /**
  180. * Function will connect to old dolphin Db base;
  181. *
  182. * @return : void;
  183. */
  184. function oldDbConnect()
  185. {
  186. $aConfig = array(
  187. 'host' => $this -> getExtraParam('config_host'),
  188. 'user' => $this -> getExtraParam('config_user'),
  189. 'pass' => $this -> getExtraParam('config_passwd'),
  190. 'db_name' => $this -> getExtraParam('config_db'),
  191. );
  192. $rLink = mysql_connect($aConfig['host'], $aConfig['user'], $aConfig['pass'], true);
  193. mysql_select_db ($aConfig['db_name'], $rLink);
  194. return $rLink;
  195. }
  196. /**
  197. * Function will get nickname from old Db;
  198. *
  199. * @param : $iProfileid (integer);
  200. * @return : (strng) - profile's nickname;
  201. */
  202. function getOldNickName($iProfileId)
  203. {
  204. $sQuery = "SELECT `NickName` FROM `Profiles` WHERE `ID` = $iProfileId";
  205. $rResult = mysql_query( $sQuery, $this -> oldDbConnect() );
  206. while( $aRow = mysql_fetch_assoc($rResult) )
  207. {
  208. return $aRow['NickName'];
  209. }
  210. }
  211. }