1
0

BxDataMigrationEvents.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. require_once 'BxDataMigrationData.php';
  3. class BxDataMigrationEvents extends BxDataMigrationData
  4. {
  5. var $sTablePrefix = 'bx_events_';
  6. var $iTransffered = 0;
  7. // default values for the fields which are not match with old ones
  8. var $aDefValues = array (
  9. 'EventMembershipFilter' => '',
  10. 'allow_view_event_to' => '3', // 3 - public (all)
  11. 'allow_view_participants_to' => '3', // 3 - public (all)
  12. 'allow_comment_to' => '3', // 3 - public (all)
  13. 'allow_rate_to' => '3', // 3 - public (all)
  14. 'allow_join_to' => '3', // 3 - public (all)
  15. 'allow_post_in_forum_to' => 'p', // p - event participants only
  16. 'JoinConfirmation' => '0', // 0 - disabled
  17. 'allow_upload_photos_to' => 'a', // a - event admin anly
  18. 'allow_upload_videos_to' => 'a', // a - event admin anly
  19. 'allow_upload_sounds_to' => 'a', // a - event admin anly
  20. 'allow_upload_files_to' => 'a', // a - event admin anly
  21. );
  22. /**
  23. * Class constructor;
  24. *
  25. * @param : $oMigrationModule (object) - object instance of migration class;
  26. * @param : $rOldDb (resourse) - connect to old dolphin's database;
  27. * @param : $oDolModule (object);
  28. * @return : void;
  29. */
  30. function BxDataMigrationEvents(&$oMigrationModule, &$rOldDb, $oDolModule = '')
  31. {
  32. parent::BxDataMigrationData($oMigrationModule, $rOldDb, $oDolModule);
  33. }
  34. /**
  35. * Function migrate all events;
  36. *
  37. * @return : (integer) operation result;
  38. */
  39. function getMigration()
  40. {
  41. if(!$this -> oDolModule) {
  42. $this -> setResultStatus('System error: object instance is not received');
  43. return MIGRATION_FAILED;
  44. }
  45. // set new status;
  46. $this -> setResultStatus('Events are transfering now');
  47. mysql_query('SET NAMES utf8', $this->rOldDb);
  48. // transfer all profiles polls;
  49. $sError = $this -> process();
  50. if($sError) {
  51. $this -> setResultStatus($sError);
  52. return MIGRATION_FAILED;
  53. }
  54. // set as finished;
  55. $this -> setResultStatus('Events were successfully transferred (' . $this -> iTransffered . ' items)');
  56. return MIGRATION_SUCCESSFUL;
  57. }
  58. /**
  59. * Function will transfer all profile's polls;
  60. *
  61. * @return : (string) - error message or empty;
  62. */
  63. function process()
  64. {
  65. $sTableMainNew = $this -> sTablePrefix . $this->oDolModule->_oDb->_sTableMain;
  66. if ($this->oMigrationModule->_oDb->getOne("SELECT COUNT(*) FROM `{$sTableMainNew}`") > 0)
  67. return 'Error: it is possible to transfaer data to clean install only, in your case some existing data was found.';
  68. $sQuery = "SELECT * FROM `SDatingEvents`";
  69. $rResult = mysql_query($sQuery, $this -> rOldDb);
  70. while($r = mysql_fetch_assoc($rResult))
  71. {
  72. $r = $this -> escapeData($r);
  73. //count participants
  74. $iParticipants = $this -> getParticipantsCount($r['ID']);
  75. $sStatus = $r['Status'] == 'Active' ? 'approved' : 'pending';
  76. // execute query;
  77. $sQuery =
  78. "
  79. INSERT INTO
  80. `$sTableMainNew`
  81. SET
  82. `ID` = {$r['ID']},
  83. `Title` = '{$r['Title']}',
  84. `EntryUri` = '{$r['EntryUri']}',
  85. `Description` = '{$r['Description']}',
  86. `Status` = '{$sStatus}',
  87. `Country` = '{$r['Country']}',
  88. `City` = '{$r['City']}',
  89. `Place` = '{$r['Place']}',
  90. `PrimPhoto` = '',
  91. `Date` = UNIX_TIMESTAMP('{$r['EventStart']}'),
  92. `EventStart` = UNIX_TIMESTAMP('{$r['EventStart']}'),
  93. `EventEnd` = UNIX_TIMESTAMP('{$r['EventStart']}'),
  94. `ResponsibleID` = '{$r['ResponsibleID']}',
  95. `EventMembershipFilter` = '{$this->aDefValues['EventMembershipFilter']}',
  96. `Tags` = '{$r['Tags']}',
  97. `Categories` = '',
  98. `Views` = '0',
  99. `Rate` = '0',
  100. `RateCount` = '0',
  101. `CommentsCount` = '0',
  102. `FansCount` = '{$iParticipants}',
  103. `Featured` = '0',
  104. `allow_view_event_to` = '{$this->aDefValues['allow_view_event_to']}',
  105. `allow_view_participants_to` = '{$this->aDefValues['allow_view_participants_to']}',
  106. `allow_comment_to` = '{$this->aDefValues['allow_comment_to']}',
  107. `allow_rate_to` = '{$this->aDefValues['allow_rate_to']}',
  108. `allow_join_to` = '{$this->aDefValues['allow_join_to']}',
  109. `allow_post_in_forum_to` = '{$this->aDefValues['allow_post_in_forum_to']}',
  110. `JoinConfirmation` = '{$this->aDefValues['JoinConfirmation']}',
  111. `allow_upload_photos_to` = '{$this->aDefValues['allow_upload_photos_to']}',
  112. `allow_upload_videos_to` = '{$this->aDefValues['allow_upload_videos_to']}',
  113. `allow_upload_sounds_to` = '{$this->aDefValues['allow_upload_sounds_to']}',
  114. `allow_upload_files_to` = '{$this->aDefValues['allow_upload_files_to']}'
  115. ";
  116. $iResult = (int) $this->oMigrationModule->_oDb->query($sQuery);
  117. if($iResult <= 0) {
  118. return 'Database error: can not insert new event into the table.';
  119. }
  120. //reparse tags
  121. $oTag = new BxDolTags();
  122. $oTag->reparseObjTags('bx_events', $r['ID']);
  123. // transfer partocipants
  124. $this -> _transferParticipants($r['ID']);
  125. // transfer photo;
  126. $this -> _transferEventPhoto($r);
  127. $this -> iTransffered++;
  128. }
  129. }
  130. /**
  131. * Transfer event's video;
  132. *
  133. * @param $aEventInfo array- event's info;
  134. * @return void;
  135. */
  136. function _transferEventPhoto($aEventInfo)
  137. {
  138. $sOldFilePath = $this -> oMigrationModule -> _oDb -> getExtraParam('config_sdatingImage') . $aEventInfo['PhotoFilename'];
  139. if( file_exists($sOldFilePath) ) {
  140. $aFileInfo = array (
  141. 'medTitle' => stripslashes($aEventInfo['Title']),
  142. 'medDesc' => stripslashes($aEventInfo['Title']),
  143. 'medTags' => 'events',
  144. 'Categories' => array('Events'),
  145. );
  146. $aPathInfo = pathinfo ($sOldFilePath);
  147. $sTmpFile = BX_DIRECTORY_PATH_ROOT . 'tmp/bx_migration_events_image.' . $aPathInfo['extension'];
  148. @copy ($sOldFilePath, $sTmpFile);
  149. $iImgId = BxDolService::call('photos', 'perform_photo_upload', array($sTmpFile, $aFileInfo, false, $aEventInfo['ResponsibleID']), 'Uploader');
  150. @unlink ($sTmpFile);
  151. if($iImgId) {
  152. // update event's table;
  153. $sQuery = "INSERT `{$this -> sTablePrefix}images` SET `entry_id` = '{$aEventInfo['ID']}', `media_id` = '{$iImgId}'";
  154. $this -> oMigrationModule -> _oDb -> query($sQuery);
  155. $sQuery = "UPDATE `{$this -> sTablePrefix}main` SET `PrimPhoto` = '{$iImgId}' WHERE `ID` = '{$aEventInfo['ID']}'";
  156. $this -> oMigrationModule -> _oDb -> query($sQuery);
  157. }
  158. }
  159. }
  160. /**
  161. * Transfer Participants;
  162. *
  163. * @param $iIventId integer;
  164. * @return void;
  165. */
  166. function _transferParticipants($iIventId)
  167. {
  168. $iIventId = (int) $iIventId;
  169. $sQuery = "SELECT * FROM `SDatingParticipants` WHERE `IDEvent` = {$iIventId}";
  170. $rResult = mysql_query($sQuery, $this -> rOldDb);
  171. while( $aRow = mysql_fetch_assoc($rResult) )
  172. {
  173. $sQuery =
  174. "
  175. INSERT INTO
  176. `{$this -> sTablePrefix}participants`
  177. SET
  178. `id_entry` = {$iIventId},
  179. `id_profile` = {$aRow['IDMember']},
  180. `confirmed` = 1,
  181. `when` = UNIX_TIMESTAMP()
  182. ";
  183. $iResult = (int) $this -> oMigrationModule -> _oDb->query($sQuery);
  184. if($iResult <= 0) {
  185. return 'Database error: can not insert new participant into the table.';
  186. }
  187. }
  188. }
  189. /**
  190. * Get count of event's Participants;
  191. *
  192. * @param $iIventId integer;
  193. * @return integer;
  194. */
  195. function getParticipantsCount($iIventId)
  196. {
  197. $iIventId = (int) $iIventId;
  198. $sQuery = "SELECT COUNT(*) as `iCount` FROM `SDatingParticipants` WHERE `IDEvent` = {$iIventId}";
  199. $rResult = mysql_query($sQuery, $this -> rOldDb);
  200. $aRow = mysql_fetch_assoc($rResult);
  201. return (int) $aRow['iCount'];
  202. }
  203. }
  204. ?>