Visit BoonEx Page at Facebook

Facebook

Join BoonEx group at LinkedIn

LinkedIn

Follow BoonEx on Twitter

Twitter

Subscribe to BoonEx Blog RSS feed

RSS

Changeset 13145

Show
Ignore:
Timestamp:
11/05/09 10:48:23 (2 weeks ago)
Author:
Alexander Ermashev
Message:

- ticket #1416;

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/modules/boonex/data_migration/classes/BxDataMigrationProfiles.php

    r13104 r13145  
    110110                     createUserDataFile($iProfileId); 
    111111 
    112                      $this -> iTransffered++; 
    113  
    114112                     // migrate profile's picture; 
    115113                     if($aRow['Picture'] && $this -> bAvatarInstalled) { 
    116114                         $this -> _exportAvatar($aRow['ID'], $iProfileId, $aRow['PrimPhoto']); 
    117115                     } 
     116 
     117                     // migrate friends; 
     118                     $sResult = $this -> _exportFriends($aRow['ID']); 
     119                     if($sResult) { 
     120                         return $sResult; 
     121                     } 
     122 
     123                     $this -> iTransffered++; 
    118124                  } 
    119125             } 
     
    164170                } 
    165171            } 
     172        } 
     173 
     174        /** 
     175         * Export all profile's friends; 
     176         *  
     177         * @param $iProfileId integer; 
     178         * @return string - error message if needed; 
     179         */ 
     180        function _exportFriends($iProfileId) 
     181        { 
     182            $iProfileId = (int) $iProfileId; 
     183 
     184            $sQuery = "SELECT * FROM `FriendList` WHERE `ID` = {$iProfileId} OR `Profile` = {$iProfileId}"; 
     185            $rResult = mysql_query($sQuery, $this -> rOldDb); 
     186 
     187                    while( $aRow = mysql_fetch_assoc($rResult) ) 
     188                    { 
     189                        if( !$this -> isFriendExisting($aRow['ID'], $aRow['Profile'])) { 
     190                               // build query;  
     191                               $sQuery = 
     192                        " 
     193                                INSERT INTO 
     194                                `sys_friend_list` 
     195                            SET 
     196                               `ID`             = '{$aRow['ID']}', 
     197                               `Profile`    = '{$aRow['Profile']}', 
     198                               `Check`      = '{$aRow['Check']}', 
     199                               `When`           = NOW() 
     200                               "; 
     201         
     202                               $iResult = (int) $this -> oMigrationModule -> _oDb -> query($sQuery); 
     203                               if($iResult <= 0) { 
     204                                   return 'Database error. Cannot insert friend list in the database.'; 
     205                               } 
     206                        } 
     207                    } 
    166208        } 
    167209 
     
    215257            return $this -> oMigrationModule -> _oDb -> getOne($sQuery) ? true : false; 
    216258        }  
     259 
     260        /** 
     261         * Check friends pair; 
     262         *  
     263         * @param $iProfileId integer 
     264         * @param $iFriendId integer 
     265         * @return boolean - true if already existing 
     266         */ 
     267        function isFriendExisting($iProfileId, $iFriendId) 
     268        { 
     269            $iProfileId = (int) $iProfileId; 
     270            $iFriendId  = (int) $iFriendId; 
     271 
     272            $sQuery =  
     273            " 
     274                SELECT  
     275                        COUNT(*)  
     276                FROM  
     277                        `sys_friend_list`  
     278                WHERE 
     279                        ( 
     280                                (`ID` = {$iProfileId} AND `Profile` = {$iFriendId}) 
     281                                        OR 
     282                                (`ID` = {$iFriendId} AND `Profile` = {$iProfileId})      
     283                        ) 
     284                                AND 
     285                        `Check` = 1      
     286            "; 
     287 
     288            return $this -> oMigrationModule -> _oDb -> getOne($sQuery) ? true : false; 
     289        } 
    217290    }