BxDataMigrationGroups.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. require_once 'BxDataMigrationOrcaForum.php';
  3. class BxDataMigrationGroups extends BxDataMigrationOrcaForum
  4. {
  5. /**
  6. * Class constructor;
  7. *
  8. * @param : $oMigrationModule (object) - object instance of migration class;
  9. * @param : $rOldDb (resourse) - connect to old dolphin's database;
  10. * @param : $oDolModule (object);
  11. * @return : void;
  12. */
  13. function BxDataMigrationGroups(&$oMigrationModule, &$rOldDb, $oDolModule = '')
  14. {
  15. parent::BxDataMigrationOrcaForum($oMigrationModule, $rOldDb, $oDolModule, true);
  16. }
  17. /**
  18. * Function migrate groups and groups forum data;
  19. *
  20. * @return : (integer) operation result;
  21. */
  22. function getMigration()
  23. {
  24. mysql_query('SET NAMES utf8', $this->rOldDb);
  25. // transfer categories;
  26. $this -> setResultStatus('transfer forum categories');
  27. $sError = $this -> _transferCategories();
  28. if($sError) {
  29. $this -> setResultStatus($sError);
  30. return MIGRATION_FAILED;
  31. }
  32. //transfer forums;
  33. $this -> setResultStatus('transfer forums');
  34. $sError = $this -> _transferForums();
  35. if($sError) {
  36. $this -> setResultStatus($sError);
  37. return MIGRATION_FAILED;
  38. }
  39. //transfer flags;
  40. $this -> setResultStatus('transfer forum\'s flags');
  41. $sError = $this -> _transferFlags();
  42. if($sError) {
  43. $this -> setResultStatus($sError);
  44. return MIGRATION_FAILED;
  45. }
  46. //transfer forum's posts;
  47. $this -> setResultStatus('transfer forum\'s posts');
  48. $sError = $this -> _transferPosts();
  49. if($sError) {
  50. $this -> setResultStatus($sError);
  51. return MIGRATION_FAILED;
  52. }
  53. //transfer forum's topics;
  54. $this -> setResultStatus('transfer forum\'s topics');
  55. $sError = $this -> _transferTopics();
  56. if($sError) {
  57. $this -> setResultStatus($sError);
  58. return MIGRATION_FAILED;
  59. }
  60. //transfer forum's users;
  61. $this -> setResultStatus('transfer forum\'s users');
  62. $sError = $this -> _transferUsers();
  63. if($sError) {
  64. $this -> setResultStatus($sError);
  65. return MIGRATION_FAILED;
  66. }
  67. //transfer forum's users activity;
  68. $this -> setResultStatus('transfer forum\'s users activity');
  69. $sError = $this -> _transferUsersActivity();
  70. if($sError) {
  71. $this -> setResultStatus($sError);
  72. return MIGRATION_FAILED;
  73. }
  74. //transfer forum's users stat;
  75. $this -> setResultStatus('transfer forum\'s users stat');
  76. $sError = $this -> _transferUsersStat();
  77. if($sError) {
  78. $this -> setResultStatus($sError);
  79. return MIGRATION_FAILED;
  80. }
  81. //transfer forum's users vote;
  82. $this -> setResultStatus('transfer forum\'s users vote');
  83. $sError = $this -> _transferUsersVote();
  84. if($sError) {
  85. $this -> setResultStatus($sError);
  86. return MIGRATION_FAILED;
  87. }
  88. // set as finished;
  89. $this -> setResultStatus('Forums were transferred');
  90. $sError = $this->_transferGroups();
  91. if($sError) {
  92. $this -> setResultStatus($sError);
  93. return MIGRATION_FAILED;
  94. }
  95. // set as finished;
  96. $this -> setResultStatus('Groups were transferred');
  97. return MIGRATION_SUCCESSFUL;
  98. }
  99. function _transferGroups() {
  100. // transfer categories
  101. $rCategs = mysql_query("select * from `GroupsCateg`", $this->rOldDb);
  102. while ($aCateg = mysql_fetch_assoc($rCategs)) {
  103. $sCategNameDB = $this->escape($aCateg['Name']);
  104. $sCategName = $this->getOne("select `Category` from `sys_categories` where `Type` = 'bx_groups' and `Category` = '$sCategNameDB'");
  105. if ($sCategName) {
  106. // if category already exists
  107. // TODO: ...do nothing
  108. } else {
  109. // if category doesn't exist, create it
  110. $this->query("
  111. insert into `sys_categories`
  112. (`Category`, `Type`)
  113. values
  114. ('$sCategNameDB', 'bx_groups')
  115. ");
  116. }
  117. // transfer groups
  118. $rGroups = mysql_query("select * from `Groups` where `categID` = {$aCateg['ID']}", $this->rOldDb);
  119. while ($aGroup = mysql_fetch_assoc($rGroups)) {
  120. $sGroupNameDB = $this->escape($aGroup['Name']);
  121. $iGroupID = (int)$this->getOne("select `id` from `bx_groups_main` where `title` = '$sGroupNameDB'");
  122. if ($iGroupID) {
  123. // if group already exists
  124. // TODO: ...do nothing
  125. } else {
  126. // if group doesn't exist, create it
  127. $g = $this->escapeData($aGroup);
  128. $g['status'] = ($aGroup['status'] == 'Active') ? 'approved' : 'pending';
  129. $g['created'] = $this->getTSFromDate($aGroup['created']);
  130. $iFansCount = 0;
  131. $rFans = mysql_query("select count(*) as `count` from `GroupsMembers` where `groupID` = {$aGroup['ID']}", $this->rOldDb);
  132. if ($rFans && ($aFans = mysql_fetch_assoc($rFans))) {
  133. $iFansCount = $aFans['count'];
  134. mysql_free_result($rFans);
  135. }
  136. $this->query("
  137. insert into `bx_groups_main`
  138. ( `id`, `title`, `uri`, `desc`, `country`, `city`, `status`, `created`, `author_id`, `categories`, `fans_count`, `allow_view_group_to`, `allow_view_fans_to`, `allow_comment_to`, `allow_rate_to`, `allow_post_in_forum_to`, `allow_join_to`, `join_confirmation`, `allow_upload_photos_to`, `allow_upload_videos_to`, `allow_upload_sounds_to`, `allow_upload_files_to`) values
  139. ('{$g['ID']}', '{$g['Name']}', '{$g['Uri']}', '{$g['Desc']}', '{$g['Country']}', '{$g['City']}', '{$g['status']}', '{$g['created']}', '{$g['creatorID']}', '$sCategNameDB', '$iFansCount', '3', '3', 'f', 'f', 'f', '3', '0', 'a', 'a', 'a', 'a')
  140. ");
  141. $iGroupID = $this->lastId();
  142. }
  143. // transfer profiles
  144. $rProfiles = mysql_query("select * from `GroupsMembers` where `groupID` = {$aGroup['ID']}", $this->rOldDb);
  145. while ($p = mysql_fetch_assoc($rProfiles)) {
  146. $p['Date'] = $this->getTSFromDate($p['Date']);
  147. $p['confirmed'] = ($p['status'] == 'Active') ? 1 : 0;
  148. $this->query("
  149. insert into `bx_groups_fans`
  150. ( `id_entry`, `id_profile`, `when`, `confirmed`) values
  151. ({$p['groupID']}, {$p['memberID']}, {$p['Date']}, {$p['confirmed']})
  152. ");
  153. }
  154. // transfer gallery
  155. $rImages = mysql_query("select * from `GroupsGallery` where `groupID` = {$aGroup['ID']}", $this->rOldDb);
  156. while ($i = mysql_fetch_assoc($rImages)) {
  157. $aFileInfo = array(
  158. 'medTitle' => $aGroup['Name'],
  159. 'medDesc' => $aGroup['Name'],
  160. 'medTags' => 'groups',
  161. 'Categories' => array('Groups'),
  162. );
  163. $sOrigFile = $this->oMigrationModule->_oDb->getExtraParam('config_root') . 'groups/gallery/' . "{$aGroup['ID']}_{$i['ID']}_{$i['seed']}.{$i['ext']}";
  164. $aPathInfo = pathinfo ($sOrigFile);
  165. $sTmpFile = BX_DIRECTORY_PATH_ROOT . 'tmp/bx_migration_groups_image.' . $aPathInfo['extension'];
  166. @copy ($sOrigFile, $sTmpFile);
  167. $iPhotoId = BxDolService::call('photos', 'perform_photo_upload', array($sTmpFile, $aFileInfo, false, $i['by']), 'Uploader');
  168. @unlink($sTmpFile);
  169. if ($iPhotoId) {
  170. if ($this->query("INSERT INTO `bx_groups_images` VALUES ($iGroupID, $iPhotoId)")) {
  171. $this->query("UPDATE `bx_groups_main` SET `thumb` = '$iPhotoId' WHERE `id` = '$iGroupID' AND `thumb` = 0");
  172. }
  173. }
  174. }
  175. // transfer forum
  176. //TODO: ...
  177. }
  178. }
  179. }
  180. function getTSFromDate($sDateTime) {
  181. list($sDate, $sTime) = explode(' ', $sDateTime);
  182. $sTime = strlen($sTime) ? $sTime : '0:0:0';
  183. $aDate = explode('-', $sDate);
  184. $aTime = explode(':', $sTime);
  185. return mktime((int)$aTime[0], (int)$aTime[1], (int)$aTime[2], (int)$aDate[1], (int)$aDate[2], (int)$aDate[0]);
  186. }
  187. }