| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- <?php
- require_once 'BxDataMigrationData.php';
- //-- this is abstract class, need to inherit --//
- class BxDataMigrationOrcaForum extends BxDataMigrationData
- {
- var $isGroupForum;
- var $sOldTablePrefix;
- var $sNewTablePrefix;
- /**
- * Class constructor;
- *
- * @param : $oMigrationModule (object) - object instance of migration class;
- * @param : $rOldDb (resourse) - connect to old dolphin's database;
- * @param : $oDolModule (object);
- * @return : void;
- */
- function BxDataMigrationOrcaForum(&$oMigrationModule, &$rOldDb, $oDolModule = '', $isGroupForum = false)
- {
- parent::BxDataMigrationData($oMigrationModule, $rOldDb, $oDolModule);
- $this -> isGroupForum = $isGroupForum;
- $this -> sOldTablePrefix = !$this -> isGroupForum ? 'pre_' : 'grp_' ;
- $this -> sNewTablePrefix = !$this -> isGroupForum ? 'bx_' : 'bx_groups_' ;
- }
- //-- private methods --//
- /**
- * Transfer all forum's categories;
- *
- * @return : (string) - error message or empty;
- */
- function _transferCategories()
- {
- if($this -> isGroupForum) {
- // clear all data;
- $sQuery = "TRUNCATE TABLE `{$this -> sNewTablePrefix}forum_cat`";
- $this -> oMigrationModule -> _oDb -> query($sQuery);
- }
- // get all categories;
- $sQuery = "SELECT * FROM `{$this -> sOldTablePrefix}forum_cat`";
- $rResult = mysql_query($sQuery, $this -> rOldDb);
- while( $aRow = mysql_fetch_assoc($rResult) )
- {
- if( !$this -> isCategoryExisting($aRow['cat_id']) ) {
- // escape all data;
- $aRow = $this -> escapeData($aRow);
- // insert new;
- $sQuery =
- "
- INSERT INTO
- `{$this -> sNewTablePrefix}forum_cat`
- SET
- `cat_id` = '{$aRow['cat_id']}',
- `cat_uri` = '{$aRow['cat_uri']}',
- `cat_name` = '{$aRow['cat_name']}',
- `cat_icon` = '{$aRow['cat_icon']}',
- `cat_order` = '{$aRow['cat_order']}'
- ";
- $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery);
- if($iResult <= 0) {
- return 'Database error. Cannot insert new forum\'s category in the database.';
- }
- }
- else {
- return 'Duplicate data (in forum categories).
- Remove all data from forum and start again';
- }
- }
- }
- /**
- * Transfer all forums;
- *
- * @return : (string) - error message or empty;
- */
- function _transferForums()
- {
- // get all forums;
- $sQuery = "SELECT * FROM `{$this -> sOldTablePrefix}forum`";
- $rResult = mysql_query($sQuery, $this -> rOldDb);
- $sExtraSql = '';
- while( $aRow = mysql_fetch_assoc($rResult) )
- {
- if( !$this -> isForumExisting($aRow['forum_id']) ) {
- // escape all data;
- $aRow = $this -> escapeData($aRow);
- if ($this -> isGroupForum) {
- $sExtraSql = ", `entry_id` = '{$aRow['forum_id']}'";
- }
- // insert new;
- $sQuery =
- "
- INSERT INTO
- `{$this -> sNewTablePrefix}forum`
- SET
- `forum_id` = '{$aRow['forum_id']}',
- `forum_uri` = '{$aRow['forum_uri']}',
- `cat_id` = '{$aRow['cat_id']}',
- `forum_title` = '{$aRow['forum_title']}',
- `forum_desc` = '{$aRow['forum_desc']}',
- `forum_posts` = '{$aRow['forum_posts']}',
- `forum_topics` = '{$aRow['forum_topics']}',
- `forum_last` = '{$aRow['forum_last']}',
- `forum_type` = '{$aRow['forum_type']}'
- {$sExtraSql}
- ";
- $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery);
- if($iResult <= 0) {
- return 'Database error. Cannot insert new forum in the database.';
- }
- }
- else {
- return 'Duplicate data (in forum).
- Remove all data from forum and start again';
- }
- }
- }
- /**
- * Transfer all forum's flags;
- *
- * @return : (string) - error message or empty;
- */
- function _transferFlags()
- {
- // get all flags;
- $sQuery = "SELECT * FROM `{$this -> sOldTablePrefix}forum_flag`";
- $rResult = mysql_query($sQuery, $this -> rOldDb);
- while( $aRow = mysql_fetch_assoc($rResult) )
- {
- if( !$this -> isFlagExisting($aRow['user'], $aRow['topic_id']) ) {
- // escape all data;
- $aRow = $this -> escapeData($aRow);
- // insert new;
- $sQuery =
- "
- INSERT INTO
- `{$this -> sNewTablePrefix}forum_flag`
- SET
- `user` = '{$aRow['user']}',
- `topic_id` = '{$aRow['topic_id']}',
- `when` = '{$aRow['when']}'
- ";
- $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery);
- if($iResult <= 0) {
- return 'Database error. Cannot insert new forum\'s flag in the database.';
- }
- }
- else {
- return 'Duplicate data (in forum flags).
- Remove all data from forum and start again';
- }
- }
- }
- /**
- * Transfer all forum's posts;
- *
- * @return : (string) - error message or empty;
- */
- function _transferPosts()
- {
- // get all posts;
- $sQuery = "SELECT * FROM `{$this -> sOldTablePrefix}forum_post`";
- $rResult = mysql_query($sQuery, $this -> rOldDb);
- while( $aRow = mysql_fetch_assoc($rResult) )
- {
- if( !$this -> isPostExisting($aRow['post_id']) ) {
- // escape all data;
- $aRow = $this -> escapeData($aRow);
- // insert new;
- $sQuery =
- "
- INSERT INTO
- `{$this -> sNewTablePrefix}forum_post`
- SET
- `post_id` = '{$aRow['post_id']}',
- `topic_id` = '{$aRow['topic_id']}',
- `forum_id` = '{$aRow['forum_id']}',
- `user` = '{$aRow['user']}',
- `post_text` = '{$aRow['post_text']}',
- `when` = '{$aRow['when']}',
- `votes` = '{$aRow['votes']}',
- `reports` = '{$aRow['reports']}'
- ";
- $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery);
- if($iResult <= 0) {
- return 'Database error. Cannot insert new forum\'s post in the database.';
- }
- }
- else {
- return 'Duplicate data (in forum posts).
- Remove all data from forum and start again';
- }
- }
- }
- /**
- * Transfer all forum's topics;
- *
- * @return : (string) - error message or empty;
- */
- function _transferTopics()
- {
- // get all topics;
- $sQuery = "SELECT * FROM `{$this -> sOldTablePrefix}forum_topic`";
- $rResult = mysql_query($sQuery, $this -> rOldDb);
- while( $aRow = mysql_fetch_assoc($rResult) )
- {
- if( !$this -> isTopicExisting($aRow['topic_id']) ) {
- // escape all data;
- $aRow = $this -> escapeData($aRow);
- // insert new;
- $sQuery =
- "
- INSERT INTO
- `{$this -> sNewTablePrefix}forum_topic`
- SET
- `topic_id` = '{$aRow['topic_id']}',
- `topic_uri` = '{$aRow['topic_uri']}',
- `forum_id` = '{$aRow['forum_id']}',
- `topic_title` = '{$aRow['topic_title']}',
- `when` = '{$aRow['when']}',
- `topic_posts` = '{$aRow['topic_posts']}',
- `first_post_user` = '{$aRow['first_post_user']}',
- `first_post_when` = '{$aRow['first_post_when']}',
- `last_post_user` = '{$aRow['last_post_user']}',
- `last_post_when` = '{$aRow['last_post_when']}',
- `topic_sticky` = '{$aRow['topic_sticky']}',
- `topic_locked` = '{$aRow['topic_locked']}'
- ";
- $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery);
- if($iResult <= 0) {
- return 'Database error. Cannot insert new forum\'s topic in the database.';
- }
- }
- else {
- return 'Duplicate data (in forum topics).
- Remove all data from forum and start again';
- }
- }
- }
- /**
- * Transfer all forum's users;
- *
- * @return : (string) - error message or empty;
- */
- function _transferUsers()
- {
- // get all users;
- $sQuery = "SELECT * FROM `{$this -> sOldTablePrefix}forum_user`";
- $rResult = mysql_query($sQuery, $this -> rOldDb);
- while( $aRow = mysql_fetch_assoc($rResult) )
- {
- if( !$this -> isUserExisting($aRow['user_name']) ) {
- // escape all data;
- $aRow = $this -> escapeData($aRow);
- // insert new;
- $sQuery =
- "
- INSERT INTO
- `{$this -> sNewTablePrefix}forum_user`
- SET
- `user_name` = '{$aRow['user_name']}',
- `user_pwd` = '{$aRow['user_pwd']}',
- `user_email` = '{$aRow['user_email']}',
- `user_join_date` = '{$aRow['user_join_date']}'
- ";
- $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery);
- if($iResult <= 0) {
- return 'Database error. Cannot insert new user in the database.';
- }
- }
- else {
- return 'Duplicate data (in forum users).
- Remove all data from forum and start again';
- }
- }
- }
- /**
- * Transfer all forum's users activity;
- *
- * @return : (string) - error message or empty;
- */
- function _transferUsersActivity()
- {
- // clear all data;
- $sQuery = "TRUNCATE TABLE `{$this -> sNewTablePrefix}forum_user_activity`";
- $this -> oMigrationModule -> _oDb -> query($sQuery);
- // get all users activity;
- $sQuery = "SELECT * FROM `{$this -> sOldTablePrefix}forum_user_activity`";
- $rResult = mysql_query($sQuery, $this -> rOldDb);
- while( $aRow = mysql_fetch_assoc($rResult) )
- {
- // escape all data;
- $aRow = $this -> escapeData($aRow);
- // insert new;
- $sQuery =
- "
- INSERT INTO
- `{$this -> sNewTablePrefix}forum_user_activity`
- SET
- `user` = '{$aRow['user']}',
- `act_current` = '{$aRow['act_current']}',
- `act_last` = '{$aRow['act_last']}'
- ";
- $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery);
- if($iResult <= 0) {
- return 'Database error. Cannot insert new user activity in the database.';
- }
- }
- }
- /**
- * Transfer all forum's users stat;
- *
- * @return : (string) - error message or empty;
- */
- function _transferUsersStat()
- {
- // clear all data;
- $sQuery = "TRUNCATE TABLE `{$this -> sNewTablePrefix}forum_user_stat`";
- $this -> oMigrationModule -> _oDb -> query($sQuery);
- // get all users stat;
- $sQuery = "SELECT * FROM `{$this -> sOldTablePrefix}forum_user_stat`";
- $rResult = mysql_query($sQuery, $this -> rOldDb);
- while( $aRow = mysql_fetch_assoc($rResult) )
- {
- // escape all data;
- $aRow = $this -> escapeData($aRow);
- // insert new;
- $sQuery =
- "
- INSERT INTO
- `{$this -> sNewTablePrefix}forum_user_stat`
- SET
- `user` = '{$aRow['user']}',
- `posts` = '{$aRow['posts']}',
- `user_last_post` = '{$aRow['user_last_post']}'
- ";
- $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery);
- if($iResult <= 0) {
- return 'Database error. Cannot insert new user stat in the database.';
- }
- }
- }
- /**
- * Transfer all forum's users vote;
- *
- * @return : (string) - error message or empty;
- */
- function _transferUsersVote()
- {
- // get all users vote;
- $sQuery = "SELECT * FROM `{$this -> sOldTablePrefix}forum_vote`";
- $rResult = mysql_query($sQuery, $this -> rOldDb);
- while( $aRow = mysql_fetch_assoc($rResult) )
- {
- if( !$this -> isUserVoteExisting($aRow['user']) ) {
- // escape all data;
- $aRow = $this -> escapeData($aRow);
- // insert new;
- $sQuery =
- "
- INSERT INTO
- `{$this -> sNewTablePrefix}forum_vote`
- SET
- `user_name` = '{$aRow['user_name']}',
- `post_id` = '{$aRow['post_id']}',
- `vote_when` = '{$aRow['vote_when']}',
- `vote_point` = '{$aRow['vote_point']}'
- ";
- $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery);
- if($iResult <= 0) {
- return 'Database error. Cannot insert new user vote in the database.';
- }
- }
- else {
- return 'Duplicate data (in forum users vote).
- Remove all data from forum and start again';
- }
- }
- }
- //-- public methods --//
- /**
- * Check category existing;
- *
- * @param : $iCatId integer - category id;
- * @return : boolean true if exist;
- */
- function isCategoryExisting($iCatId)
- {
- $iCatId = (int) $iCatId;
- $sQuery = "SELECT COUNT(*) FROM `{$this -> sNewTablePrefix}forum_cat` WHERE `cat_id` = {$iCatId}";
- return $this -> oMigrationModule -> _oDb -> getOne($sQuery) ? true : false;
- }
- /**
- * Check forum existing;
- *
- * @param : $iForumId integer - forum id;
- * @return : boolean true if exist;
- */
- function isForumExisting($iForumId)
- {
- $iForumId = (int) $iForumId;
- $sQuery = "SELECT COUNT(*) FROM `{$this -> sNewTablePrefix}forum` WHERE `forum_id` = {$iForumId}";
- return $this -> oMigrationModule -> _oDb -> getOne($sQuery) ? true : false;
- }
- /**
- * Check flags existing;
- *
- * @param : $iUserId string - user nickname;
- * @param : $iTopicId integer - topic id;
- * @return : boolean true if exist;
- */
- function isFlagExisting($sUserName, $iTopicId)
- {
- $sUserName = $this -> oMigrationModule -> _oDb -> escape($sUserName);
- $iTopicId = (int) $iTopicId;
- $sQuery = "SELECT COUNT(*) FROM `{$this -> sNewTablePrefix}forum_flag` WHERE `user` = '{$sUserName}' AND `topic_id` = {$iTopicId}";
- return $this -> oMigrationModule -> _oDb -> getOne($sQuery) ? true : false;
- }
- /**
- * Check post existing;
- *
- * @param : $iPostId integer - post id;
- * @return : boolean true if exist;
- */
- function isPostExisting($iPostId)
- {
- $iPostId = (int) $iPostId;
- $sQuery = "SELECT COUNT(*) FROM `{$this -> sNewTablePrefix}forum_post` WHERE `post_id` = {$iPostId}";
- return $this -> oMigrationModule -> _oDb -> getOne($sQuery) ? true : false;
- }
- /**
- * Check topic existing;
- *
- * @param : $iTopicId integer - topic id;
- * @return : boolean true if exist;
- */
- function isTopicExisting($iTopicId)
- {
- $iTopicId = (int) $iTopicId;
- $sQuery = "SELECT COUNT(*) FROM `{$this -> sNewTablePrefix}forum_topic` WHERE `topic_id` = {$iTopicId}";
- return $this -> oMigrationModule -> _oDb -> getOne($sQuery) ? true : false;
- }
- /**
- * Check user existing;
- *
- * @param : $sUserName string;
- * @return : boolean true if exist;
- */
- function isUserExisting($sUserName)
- {
- $sUserName = $this -> oMigrationModule -> _oDb -> escape($sUserName);
- $sQuery = "SELECT COUNT(*) FROM `{$this -> sNewTablePrefix}forum_user` WHERE `user_name` = '{$sUserName}'";
- return $this -> oMigrationModule -> _oDb -> getOne($sQuery) ? true : false;
- }
- /**
- * Check user vote;
- *
- * @param : $sUserName string;
- * @return : boolean true if exist;
- */
- function isUserVoteExisting($sUserName)
- {
- $sUserName = $this -> oMigrationModule -> _oDb -> escape($sUserName);
- $sQuery = "SELECT COUNT(*) FROM `{$this -> sNewTablePrefix}forum_vote` WHERE `user_name` = '{$sUserName}'";
- return $this -> oMigrationModule -> _oDb -> getOne($sQuery) ? true : false;
- }
- }
|