Răsfoiți Sursa

Migration Tools Upgrade (Dolphin Migration Tool and Social Engine tool)

AlexeyUna 8 ani în urmă
părinte
comite
754ce5a406

+ 34 - 10
modules/boonex/dolphin_migration/classes/BxDolMConfig.php

@@ -22,16 +22,36 @@ class BxDolMConfig extends BxBaseModGeneralConfig
 		'bx_groups' => 'groups',		
 		'bx_blogs' => 'blogs'
 	);
-	
+
+    /**
+     * @var bool allows to overwrite existed members profile data
+     */
+	public $_bIsOverwrite = false;
+
 	/**
-	 *  @var array modules for transfer from Dolphin to una with parameters
-	 *  	[table_name] -  (string) table from which to get data
-	 *  	[migration_class] - (string) class name/file name for data migration
-	 *  	[dependencies] -  (array) list of the modules which should be migrated before transferring selected module 
-	 *  	[plugins] - (array) list of the modules which should be installed on UNA before transferring selected module
-	 */
-	 
-	public $_aMigrationModules = array(
+     * @var bool allows to transfer photo albums even if they are empty
+     */
+    public $_bTransferEmpty = true;
+
+    /**
+     * @var bool allows to use members NickName instead of FullName
+     */
+    public $_bUseNickName = false;
+
+    /**
+     * @var int interval in milliseconds for checking if the data already transferred but script still works.
+     */
+    public $_iCheckInterval = 60000;
+
+    /**
+     *  @var array modules for transfer from Dolphin to UNA with parameters
+     *  	[table_name] -  (string) table from which to get data
+     *  	[migration_class] - (string) class name/file name for data migration
+     *  	[dependencies] -  (array) list of the modules which should be migrated before transferring selected module
+     *  	[plugins] - (array) list of the modules which should be installed on UNA before transferring selected module
+     */
+
+    public $_aMigrationModules = array(
 				'profiles' => array(
                     'table_name'     => 'Profiles', 
                     'migration_class' => 'BxDolMProfiles',
@@ -237,7 +257,11 @@ class BxDolMConfig extends BxBaseModGeneralConfig
 			 
 	public function __construct($aModule)
 	{
-		parent::__construct($aModule);		
+        $this -> _bIsOverwrite = getParam('bx_dolphin_migration_overwrite');
+        $this -> _bTransferEmpty = getParam('bx_dolphin_migration_empty_albums');
+        $this -> _bUseNickName = getParam('bx_dolphin_migration_use_nickname');
+
+        parent::__construct($aModule);
 	}
 
 }

+ 29 - 36
modules/boonex/dolphin_migration/classes/BxDolMConv.php

@@ -23,7 +23,7 @@ class BxDolMConv extends BxDolMData
 	
 	public function getTotalRecords()
 	{
-		return (int)$this -> _mDb -> getOne("SELECT COUNT(*) FROM  `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name'] . "` WHERE `Type` = 'letter' ORDER BY `ID`");			
+		return (int)$this -> _mDb -> getOne("SELECT COUNT(*) FROM  `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name'] . "` WHERE `Type` = 'letter' AND `Sender` <> `Recipient` ORDER BY `ID`");
 	}
 	
 	public function runMigration()
@@ -44,10 +44,10 @@ class BxDolMConv extends BxDolMData
 			$iSenderId = $this -> getProfileId((int)$aValue['Sender']);
 			$iRecipientId = $this -> getProfileId((int)$aValue['Recipient']);			
 			$iDate = isset($aValue['Date']) ? strtotime($aValue['Date']) : time();				
-			if (!$iSenderId || !$iRecipientId)
+			if (!$iSenderId || !$iRecipientId || ($iSenderId == $iRecipientId))
 				continue;
 			
-			$iConvId = $this -> isConvExisted($aValue['Subject'], $iSenderId, $iRecipientId);		
+			$iConvId = $this -> isConvExisted($aValue['Subject'], $iSenderId, $iRecipientId);
 			if (!$iConvId)
 			{
 				$sQuery = $this -> _oDb -> prepare( 
@@ -72,42 +72,14 @@ class BxDolMConv extends BxDolMData
 		
 				$this -> _oDb -> query($sQuery);
 				
-				$iConvId = $this -> _oDb -> lastId();			
+				$iConvId = $this -> _oDb -> lastId();
 				if (!$iConvId){
 					$this -> setResultStatus(_t('_bx_dolphin_migration_started_migration_conv_error', (int)$aValue['ID']));
 					return BX_MIG_FAILED;
-				}	
-								
+				}
 
-				$sQuery = $this -> _oDb -> prepare( 
-						"
-							INSERT INTO
-								`bx_convos_conv2folder`
-							SET
-								`conv_id`      		= ?,
-								`folder_id`   		= ?,
-								`collaborator`		= ?
-						", 
-						$iConvId,
-						stripos($aValue['Trash'], 'sender') !== FALSE ? 4 : 1,
-						$iSenderId
-						);
-				$this -> _oDb -> query($sQuery);
-				
-				$sQuery = $this -> _oDb -> prepare( 
-						"
-							INSERT INTO
-								`bx_convos_conv2folder`
-							SET
-								`conv_id`      		= ?,
-								`folder_id`   		= ?,
-								`collaborator`		= ?
-						", 
-						$iConvId,
-						stripos($aValue['Trash'], 'recipient') !== FALSE ? 4 : 1,
-						$iRecipientId
-						);
-				$this -> _oDb -> query($sQuery);
+                $this -> updateConvFolder($iSenderId, stripos($aValue['Trash'], 'sender') !== FALSE ? 4 : 1, $iConvId);
+                $this -> updateConvFolder($iRecipientId, stripos($aValue['Trash'], 'recipient') !== FALSE ? 4 : 1, $iConvId);
 			}
 			
 			$this -> createMIdField();
@@ -150,7 +122,28 @@ class BxDolMConv extends BxDolMData
         $this -> setResultStatus(_t('_bx_dolphin_migration_started_migration_conv_finished', $this -> _iTransferred));
         return BX_MIG_SUCCESSFUL;
     }
-	
+	private function updateConvFolder($iCollaborator, $iFolder, $iConvId){
+	    $iId = $this -> _oDb -> getOne("SELECT `id` FROM `bx_convos_conv2folder` WHERE `collaborator` = :coll AND `folder_id` = :folder AND `conv_id` = :id",
+            array('coll' => $iCollaborator, 'folder' => $iFolder, 'id' => $iConvId));
+	    if($iId)
+	        return $iId;
+
+	    $sQuery = $this -> _oDb -> prepare(
+                        "
+							INSERT INTO
+								`bx_convos_conv2folder`
+							SET
+								`conv_id`      		= ?,
+								`folder_id`   		= ?,
+								`collaborator`		= ?
+						",
+                $iConvId,
+                $iFolder,
+                $iCollaborator
+            );
+
+	    return $this -> _oDb -> query($sQuery);
+    }
 	protected function isConvExisted($sSubject, $iSenderId, $iRecipientId)
 	{
 		$sSubject = preg_replace('/^Re.*:\s+(.*)$/i', '\\1', $sSubject);

+ 20 - 12
modules/boonex/dolphin_migration/classes/BxDolMData.php

@@ -265,7 +265,7 @@ class BxDolMData
 						`Key`	= ?, 
 						`Value`	= ?,
 						`Order`	= ?,
-						`LKey`	= ?", $sName, 0, 0, '_sys_please_select');
+						`LKey`	= ?", $sName, '', 0, '_sys_please_select');
 				$this -> _oDb -> query($sQuery);
 			}
 			else
@@ -381,7 +381,14 @@ class BxDolMData
 		foreach($aTags as $aTag)
 			$this -> _oDb -> query("INSERT IGNORE INTO `{$sTableKeywords}` SET `keyword`=:keyword, `object_id`=:id", array('keyword' => $aTag['Tag'], 'id' => $iNewObjectId));
 	}
-	
+	private function addCmtsIds($sCmtsTable, $iId, $iRate){
+        $iSystem = $this -> _oDb -> getOne("SELECT `ID` FROM `sys_objects_cmts` WHERE `Table`=:table LIMIT 1", array('table' => $sCmtsTable));
+        if (!$iSystem)
+            return false;
+
+        return $this -> _oDb -> query("INSERT INTO `sys_cmts_ids` SET `system_id` = :id, `rate`=:rate, `cmt_id`=:cmt_id",
+                                       array('id' => $iSystem, 'rate' => $iRate, 'cmt_id' => $iId));
+    }
 	/**
 	 *  Transfer comments for module's items
 	 *  
@@ -443,7 +450,7 @@ class BxDolMData
 		
 		$aComments = $this -> _mDb -> getAll("SELECT * FROM `{$sCmtsTable}` WHERE `cmt_object_id` = :id ORDER BY `cmt_id` ASC", array('id' => $iEntryId));
 		
-		$iCommnets = 0;
+		$iComments = 0;
 		$aCommentsArray = array();
 		foreach($aComments as $iKey => $aValue)
 		{
@@ -451,8 +458,8 @@ class BxDolMData
 			if ($iProfileId)
 			{
 				$bIscmtsArray = $aValue['cmt_parent_id'] && isset($aCommentsArray[$aValue['cmt_parent_id']]);
-				$this -> _oDb -> query("INSERT INTO `{$sTable}` (`cmt_id`, `cmt_parent_id`, `cmt_vparent_id`, `cmt_object_id`, `cmt_author_id`, `cmt_level`, `cmt_text`, `cmt_time`, `cmt_replies`, `cmt_rate`, `cmt_rate_count`)
-									VALUES	(NULL, :parent_id, :vparent_id, :object, :user, :level, :message, :time, :replies, :rate, :rate_count)", 
+				$this -> _oDb -> query("INSERT INTO `{$sTable}` (`cmt_id`, `cmt_parent_id`, `cmt_vparent_id`, `cmt_object_id`, `cmt_author_id`, `cmt_level`, `cmt_text`, `cmt_time`, `cmt_replies`)
+									VALUES	(NULL, :parent_id, :vparent_id, :object, :user, :level, :message, :time, :replies)",
 									array(
 											'parent_id'	=> $bIscmtsArray ? $aCommentsArray[$aValue['cmt_parent_id']]['id'] : 0,
 											'vparent_id' => $bIscmtsArray ? ($aCommentsArray[$aValue['cmt_parent_id']]['vparent'] ? $aCommentsArray[$aValue['cmt_parent_id']]['vparent'] : $aCommentsArray[$aValue['cmt_parent_id']]['id']) : 0,
@@ -461,13 +468,14 @@ class BxDolMData
 											'message' => $aValue['cmt_text'], 
 											'time' => strtotime($aValue['cmt_time']),
 											'replies' => $aValue['cmt_replies'],
-											'rate' => $aValue['cmt_rate'],
-											'rate_count' => $aValue['cmt_rate_count'],
 											'level' => isset($aCommentsArray[$aValue['cmt_parent_id']]) && $aCommentsArray[$aValue['cmt_parent_id']] ? $aCommentsArray[$aValue['cmt_parent_id']]['level'] + 1 : 0
 										));
-				
+
+				$iLastInsertId = $this -> _oDb -> lastId();
+
+				$this -> addCmtsIds($sTable, $iLastInsertId, $aValue['cmt_rate'], $aValue['cmt_rate_count']);
 				$aCommentsArray[$aValue['cmt_id']] = array(
-																'id' => $this -> _oDb -> lastId(),
+																'id' => $iLastInsertId,
 																'level' => $bIscmtsArray ? (int)$aCommentsArray[$aValue['cmt_parent_id']]['level'] + 1 : 0,
 																'vparent' => 
 																			$bIscmtsArray ? 
@@ -475,11 +483,11 @@ class BxDolMData
 																				$aCommentsArray[$aValue['cmt_parent_id']]['vparent'] ? $aCommentsArray[$aValue['cmt_parent_id']]['vparent'] :  $aCommentsArray[$aValue['cmt_parent_id']]['id']
 																			) : 0 
 															);
-				$iCommnets++;				
+				$iComments++;
 			}
 		}
 		
-		return $iCommnets;
+		return $iComments;
 	}
 
 	
@@ -509,7 +517,7 @@ class BxDolMData
 		if (!$this -> _sTableWithTransKey)
 			return false;
 
-		return (int)$this -> _oDb -> getOne("SELECT `{$this -> _sTransferFieldIdent}` FROM `{$this -> _sTableWithTransKey}` WHERE `{$this -> _sTransferFieldIdent}` <> 0 ORDER BY `ID` DESC LIMIT 1");
+		return (int)$this -> _oDb -> getOne("SELECT `{$this -> _sTransferFieldIdent}` FROM `{$this -> _sTableWithTransKey}` WHERE `{$this -> _sTransferFieldIdent}` <> 0 ORDER BY `{$this -> _sTransferFieldIdent}` DESC LIMIT 1");
 	}
 
 	/**

+ 24 - 5
modules/boonex/dolphin_migration/classes/BxDolMDb.php

@@ -21,6 +21,7 @@ class BxDolMDb extends BxBaseModGeneralDb
 	/** 
 	* Save Dolphin configuration 
 	* @param array $aConfig parameters
+    * @return boolean if requests are successful
 	*/ 
 	public function saveConfig($aConfig)
 	{
@@ -39,9 +40,19 @@ class BxDolMDb extends BxBaseModGeneralDb
 		}
 		
 		return $bRecords;
-	} 
-	
-	/** 
+	}
+
+	/**
+     * Removes Dolphin's transfer settings
+     * @return boolean if requests are successful
+     */
+    public function removeConfig()
+    {
+        $this -> query("TRUNCATE TABLE `bx_dolphin_config`");
+        $this -> query("TRUNCATE TABLE `bx_dolphin_transfers`");
+    }
+
+    /**
 	* Get config parameter value
 	* @param string $sConfigName param's name 
 	* @return string 
@@ -111,7 +122,7 @@ class BxDolMDb extends BxBaseModGeneralDb
 	*/
 	 public function isConfigInstalled()
 	 {
-		return $this -> getExtraParam('dbname') && $this -> getExtraParam('username');
+		return $this -> getOne('SELECT COUNT(*) FROM `bx_dolphin_config`');
 	 }
 	
 	/** 
@@ -139,10 +150,18 @@ class BxDolMDb extends BxBaseModGeneralDb
 		return (int)$this -> getOne($sQuery) == 1;
 	}
 	
-	public function cleanTrasnfersTable()
+	public function cleanTransfersTable()
 	{
 		return $this -> query("TRUNCATE TABLE `{$this -> _sPrefix}transfers`");
 	}
+
+	public function isFinished($aElements){
+	    if (empty($aElements))
+	        return false;
+
+	    $sList = implode("','", $aElements);
+	    return $this -> getOne("SELECT COUNT(*) FROM `{$this -> _sPrefix}transfers` WHERE `module` IN (:list) AND `status` != 'finished'", array('list' => $sList)) == 0;
+    }
 }
 
 /** @} */

+ 5 - 8
modules/boonex/dolphin_migration/classes/BxDolMModule.php

@@ -43,8 +43,8 @@ class BxDolMModule extends BxBaseModGeneralModule
 			echo json_encode(array('code' => 1, 'message' => _t('_bx_dolphin_migration_successfully_finished')));
 			exit;
 		}
-		
-		$this -> initDb();		
+
+		$this -> initDb();
 		header('Content-Type:text/javascript');			
 		
 		foreach($aModules as $iKey => $sModule){
@@ -86,11 +86,9 @@ class BxDolMModule extends BxBaseModGeneralModule
                 $oModule = new $this -> _oConfig -> _aMigrationModules[$sModule]['migration_class']($this, $this -> _oMDb);
                 if($oModule -> runMigration()) 
 	                $this -> _oDb -> updateTransferStatus($sModule, 'finished');                
-                else {                    
+                else
                     $this -> _oDb -> updateTransferStatus($sModule, 'error');
-					return _t('_bx_dolphin_migration_successfully_failed');					
-                }
-            }		
+            }
 	     }
 		
 		return _t('_bx_dolphin_migration_successfully_finished');	
@@ -98,14 +96,13 @@ class BxDolMModule extends BxBaseModGeneralModule
 	
 	/** 
 	* Creates date for migration
-	* @param ref $oMDb Dolphin database connect
 	*/
 	public function createMigration()
 	{
 		if (is_null($this -> _oMDb)) 
 			$this -> initDb();
 
-		$this -> _oDb -> cleanTrasnfersTable();
+		$this -> _oDb -> cleanTransfersTable();
 		foreach ($this -> _oConfig -> _aMigrationModules as $sName => $aModule)
 		{			
 			if ($this -> _oMDb -> isTableExists($aModule['table_name']))

+ 13 - 2
modules/boonex/dolphin_migration/classes/BxDolMPhotoAlbums.php

@@ -39,11 +39,16 @@ class BxDolMPhotoAlbums extends BxDolMData
 			  $this -> setResultStatus(_t('_bx_dolphin_migration_no_data_to_transfer'));
 	          return BX_MIG_SUCCESSFUL;
 		}
-		
+
+		$sWhereCount = '';
+		if ($this -> _oConfig -> _bTransferEmpty)
+            $sWhereCount = " AND `ObjCount` <> 0";
+
 		$this -> setResultStatus(_t('_bx_dolphin_migration_started_migration_photos'));
 		
 		$this -> createMIdField();
-		$aResult = $this -> _mDb -> getAll("SELECT * FROM `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name_albums'] ."` WHERE `Type` = 'bx_photos' AND `Uri` <> 'Hidden' ORDER BY `ID` ASC");
+		$aResult = $this -> _mDb -> getAll("SELECT * FROM `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name_albums'] ."` 
+		                                    WHERE `Type` = 'bx_photos' AND `Uri` <> 'Hidden' {$sWhereCount} ORDER BY `ID` ASC");
 		foreach($aResult as $iKey => $aValue)
 		{ 			
 			$iProfileId = $this -> getProfileId((int)$aValue['Owner']);
@@ -129,6 +134,7 @@ class BxDolMPhotoAlbums extends BxDolMData
 					if ($iId)
 					{ 
 						$oStorage -> afterUploadCleanup($iId, $iProfileId);
+                        $this -> updateFilesDate($iId, $aValue['Date']);
 						
 						$sQuery = $this -> _oDb -> prepare("INSERT INTO `bx_albums_files2albums` SET `content_id` = ?, `file_id` = ?, `data` = ?, `title` = ?", $iNewAlbumID, $iId, $aValue['Size'], $aValue['Title']);
 						$this -> _oDb -> query($sQuery);
@@ -152,6 +158,11 @@ class BxDolMPhotoAlbums extends BxDolMData
     	$sQuery  = $this -> _oDb ->  prepare("SELECT COUNT(*) FROM `bx_albums_files` WHERE `profile_id` = ? AND `file_name` = ? AND `added` = ? LIMIT 1", $iAuthor, $sTitle, $iDate);
         return (bool)$this -> _oDb -> getOne($sQuery);
     }
+
+    private function updateFilesDate($iId, $iDate){
+        $sQuery  = $this -> _oDb ->  prepare("UPDATE `bx_albums_files` SET `added`=? WHERE `id` = ?", $iDate, $iId);
+        return $this -> _oDb -> query($sQuery);
+    }
 	
 	public function removeContent()
 	{

+ 1 - 2
modules/boonex/dolphin_migration/classes/BxDolMPolls.php

@@ -103,8 +103,7 @@ class BxDolMPolls extends BxDolMData
 			
 			$this -> trasnferTags($aValue['id_poll'], $iPollId, $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['type'], $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['keywords']);
         }      	
-        
-		//$this -> dropMID();
+
 
         // set as finished;
         $this -> setResultStatus(_t('_bx_dolphin_migration_started_migration_polls_finished', $this -> _iTransferred));

+ 51 - 34
modules/boonex/dolphin_migration/classes/BxDolMProfiles.php

@@ -31,14 +31,14 @@ class BxDolMProfiles extends BxDolMData
 	
 	public function runMigration()
 	{
-		if (!$this -> getTotalRecords())
+	    if (!$this -> getTotalRecords())
 		{
 			  $this -> setResultStatus(_t('_bx_dolphin_migration_no_data_to_transfer'));
 	          return BX_MIG_SUCCESSFUL;
 		}	
 		
 		$this -> setResultStatus(_t('_bx_dolphin_migration_started_migration_profiles'));
-        $sError = $this -> profilesMigrtion();
+        $sError = $this -> profilesMigration();
         if($sError) {
               $this -> setResultStatus($sError);
               return BX_MIG_FAILED;
@@ -51,40 +51,49 @@ class BxDolMProfiles extends BxDolMData
 	/**
 	* Check if profile with the same nickname already exists
 	* @param string $sNickName name of the user
-	* @return string
-         */ 	 
-	private function isProfileExisted($sNickName, $sEmail)
-	{
-         $sQuery  = $this -> _oDb -> prepare("SELECT COUNT(*) FROM `sys_accounts` WHERE `name` = ? OR `email` = ?", $sNickName, $sEmail);
-         return $this -> _oDb -> getOne($sQuery) ? true : false;
-	} 
-	
-	function profilesMigrtion()
+	* @return integer account id
+     */
+	private function isProfileExisted($sNickName, $sEmail){
+        $sQuery  = $this -> _oDb -> prepare("SELECT `id` FROM `sys_accounts` WHERE `name` = ? OR `email` = ?", $sNickName, $sEmail);
+        return $this -> _oDb -> getOne($sQuery);
+	}
+
+	function profilesMigration()
     {
 			$this -> createMIdField();
-		
-			// get ID of the latest transferred profile from Dolphin
+
+			// get IDs of the latest transferred profile for UNA Accounts and Dolphin Profiles
 			$iProfileID = $this -> getLastMIDField();
 			$sStart = '';
-			if ($iProfileID) 				
+			if ($iProfileID[$this -> _sTransferFieldIdent])
 				$sStart = "WHERE `ID` > {$iProfileID}";
 			else 
 				$this -> addPreValues('Sex', true, 2); // transfer all sex values more then 2 value
 
 			$aResult = $this -> _mDb -> getAll("SELECT * FROM `"  . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name'] . "` {$sStart} ORDER BY `ID` ASC");			
-
-			$aAdditionalProfileFields = $this -> getAssocFields();
 			$aSex = $this -> getPreValuesBy('Sex', 'Value', 'Order');
-				
-			$oLanguage = BxDolLanguages::getInstance();
+
 			foreach($aResult as $iKey => $aValue)
-			{                  
+			{
 
-				if($aValue['NickName'] && !$this -> isProfileExisted($aValue['NickName'], $aValue['Email'])) 
-				  {					
-					$sQuery = $this -> _oDb -> prepare( 
+				if($aValue['NickName'])
+				{
+                     $sAction = "INSERT INTO";
+                     $sWhere  = "";
+                     $iAccountId = $this -> isProfileExisted($aValue['NickName'], $aValue['Email']);
+                     if ($iAccountId)
+                     {
+                         if ($this -> _oConfig -> _bIsOverwrite) {
+                             $sAction = "UPDATE";
+                             $sWhere = "WHERE `id` = '{$iAccountId}'";
+                         }
+                         else
+                             continue;
+				     }
+
+                      $sQuery = $this -> _oDb -> prepare(
                      "
-                     	INSERT INTO
+                     	{$sAction}
                      		`sys_accounts`
                      	SET
                      		`name`   			= ?,
@@ -99,7 +108,7 @@ class BxDolMProfiles extends BxDolMData
 							`email_confirmed`	= ?,
 							`receive_updates`	= ?,	
 							`receive_news`		= ?
-							
+						{$sWhere}	
                      ", 
 						$aValue['NickName'], 
 						$aValue['Email'], 
@@ -116,17 +125,23 @@ class BxDolMProfiles extends BxDolMData
 						);
 						
 					$this -> _oDb -> query($sQuery);										
-					$iAccountId = $this -> _oDb -> lastId();
+
+					$iAccountId = $iAccountId ? $iAccountId : $this -> _oDb -> lastId();
 					if (!$iAccountId) 
 						continue;
 					
 					$this -> setMID($iAccountId, $aValue['ID']);
-					
-					$sFullName = isset($aValue['FullName']) ? $aValue['FullName'] : "{$aValue['FirstName']} {$aValue['LastName']}";
+
+                    if ($this -> _oConfig -> _bUseNickName)
+                        $sFullName = $aValue['NickName'];
+					else
+					    {
+                        $sFullName = isset($aValue['FullName']) ? $aValue['FullName'] : "{$aValue['FirstName']} {$aValue['LastName']}";
+                        $sFullName = $sFullName ? $sFullName : $aValue['NickName'];
+                    }
 					
 					$sQuery = $this -> _oDb -> prepare( 
-	                     "
-	                     	INSERT INTO
+	                     "INSERT INTO
 	                     		`bx_persons_data`
 	                     	SET
 	                     		`author`   			= 0,
@@ -137,17 +152,17 @@ class BxDolMProfiles extends BxDolMData
 								`fullname`			= ?,
 								`birthday`			= ?,
 								`gender`			= ?,
-								`allow_view_to`		= ?,
+								`allow_view_to`		= 3,
 								`featured`			= ?,
 								`views`				= ?,
 								`description`		= ?
-	                     ", 						
+	                     ",
 							strtotime($aValue['DateReg']),
 							strtotime($aValue['DateLastEdit']),
 							$sFullName,
 							isset($aValue['DateOfBirth']) ? $aValue['DateOfBirth'] : 'NULL',
 							isset($aValue['Sex']) && $aValue['Sex'] ? $aSex[$aValue['Sex']] : 1,
-							isset($aValue['allow_view_to']) ? $aValue['allow_view_to'] : 3,
+							//isset($aValue['allow_view_to']) ? $aValue['allow_view_to'] : 3,
 							isset($aValue['Featured']) ? (int)$aValue['Featured'] : 0,
 							isset($aValue['Views']) ? (int)$aValue['Views'] : 0,
 							isset($aValue['DescriptionMe']) ? $aValue['DescriptionMe'] : ''
@@ -201,7 +216,9 @@ class BxDolMProfiles extends BxDolMData
 			$aInfo = $this -> _mDb -> getRow("SELECT `bx_photos_main`.*  FROM `bx_photos_main`
 					LEFT JOIN `sys_albums_objects` ON `sys_albums_objects`.`id_object`=`bx_photos_main`.`ID` 
 					LEFT JOIN `sys_albums` ON `sys_albums`.`ID`=`sys_albums_objects`.`id_album` 
-					WHERE `bx_photos_main`.`Status` ='approved' AND `bx_photos_main`.`Owner` =:id AND `sys_albums`.`Status` ='active' AND `sys_albums`.`Type` ='bx_photos' AND `sys_albums`.`Uri` = :uri LIMIT 1", array('uri' => $sAlbumName, 'id' => $aProfileInfo['ID']));
+					WHERE `bx_photos_main`.`Status` ='approved' AND `bx_photos_main`.`Owner` =:id AND `sys_albums`.`Status` ='active' AND `sys_albums`.`Type` ='bx_photos' AND `sys_albums`.`Uri` = :uri 
+					ORDER BY `obj_order` ASC, `id_object`
+					LIMIT 1", array('uri' => $sAlbumName, 'id' => $aProfileInfo['ID']));
 			
 			if (!empty($aInfo) && isset($aInfo['ID']))
 				$sImagePath = $sImagePath . "photos" . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR ."{$aInfo['ID']}.{$aInfo['Ext']}";
@@ -240,7 +257,7 @@ class BxDolMProfiles extends BxDolMData
 						   `content`    = ?,
 						   `mutual`     = ?,
 						   `added`     	= UNIX_TIMESTAMP()
-				   ", $iUserId, $iFriendId, (int)($aValue['status'] == 'active'));
+				   ", $iUserId, $iFriendId, (int)($aValue['Check']));
 
 				   $iResult = (int) $this -> _oDb -> query($sQuery);
 				   if($iResult <= 0) {

+ 53 - 21
modules/boonex/dolphin_migration/classes/BxDolMStudioPage.php

@@ -27,10 +27,10 @@ class BxDolMStudioPage extends BxTemplStudioModule
 		
 		$this->aMenuItems = array(
             array('name' => 'settings', 'icon' => 'cogs', 'title' => '_bx_dolphin_migration_cpt_settings'),
-            array('name' => 'config', 'icon' => 'exchange-alt', 'title' => '_bx_dolphin_migration_cpt_transfer_data'),
+		    array('name' => 'config', 'icon' => 'exchange-alt', 'title' => '_bx_dolphin_migration_cpt_transfer_data')
         );	
 		
-		$this -> _oModule -> _oTemplate -> addStudioJs(array('transfer.js', 'BxDolGrid.js'));
+		$this -> _oModule -> _oTemplate -> addStudioJs(array('jquery-ui/jquery-ui.custom.min.js', 'transfer.js', 'BxDolGrid.js'));
 		$this -> _oModule -> _oTemplate -> addStudioCss(array('main.css'));	
      } 
 	
@@ -70,8 +70,16 @@ class BxDolMStudioPage extends BxTemplStudioModule
 		return MsgBox( _t('_bx_dolphin_migration_data_was_set'), 2);			
 	}
 	
-	 protected function getSettings()
+	 private function getPathSettings()
     {
+        $sMessage = '';
+
+        if (isset($_POST['save']))
+            $sMessage = $this -> saveData(bx_get('path'));
+
+        if (isset($_POST['clean']))
+            $this -> _oModule -> _oDb -> removeConfig();
+
         $aForm = array(
 			'params' => array(
 				'db' => array(
@@ -83,36 +91,60 @@ class BxDolMStudioPage extends BxTemplStudioModule
                     'type' => 'text',
                     'name' => 'path',
                     'caption' => $this -> _oModule -> _oDb -> isConfigInstalled() ? _t('_bx_dolphin_migration_defined_path') : _t('_bx_dolphin_migration_cpt_put_path'),
-                    'value' => $this -> _oModule -> _oDb -> getExtraParam('root'),
-					'attrs_wrap'
-                ),   
-				
-				'save' => array (
-                    'type' => 'submit',
-                    'name' => 'save',
-                    'value' => _t('_bx_dolphin_migration_cpt_' . ($this -> _oModule -> _oDb -> getExtraParam('root') ? 'update' : 'save'))					
+                    'value' => $this -> _oModule -> _oDb -> getExtraParam('root')
+                ),
+				'buttons' => array (
+                    'name' => 'buttons',
+                    'type' => 'input_set',
+				    array(
+				        'type' => 'submit',
+                        'name' => 'save',
+                        'value' => _t('_bx_dolphin_migration_cpt_' . ($this -> _oModule -> _oDb -> getExtraParam('root') ? 'update' : 'save'))
+                    ),
+                    array(
+                        'type' => 'submit',
+                        'name' => 'clean',
+                        'value' => _t('_bx_dolphin_migration_cpt_clean'),
+                        'attrs' => array('onclick' => "javascript:return confirm('" . bx_js_string(_t('_bx_dolphin_migration_cpt_clean_warning')) . "');")
+                    ),
                 )
             )
         );
-        
-		
+
+
 		if ($this -> _oModule -> _oDb -> isConfigInstalled())
-				$aForm['inputs']['save']['attrs'] = array('onclick' => "javascript:return confirm('" . bx_js_string(_t('_bx_dolphin_migration_reupload_data')) . "');");
+				$aForm['inputs']['buttons'][0]['attrs'] = array('onclick' => "javascript:return confirm('" . bx_js_string(_t('_bx_dolphin_migration_reupload_data')) . "');");
 		
 		$oForm = new BxTemplStudioFormView($aForm);	
-		
-		$sMessage = '';
-		if ($oForm -> isSubmitted()) 
-			$sMessage = $this -> saveData($oForm -> getCleanValue('path'));		
-		
+
         return $sMessage . $oForm -> getCode();
     }
 	
 	protected function getConfig()
 	{		
-		$oGrid = BxDolMTransfers::getObjectInstance('bx_dolphin_migration_transfers'); 
+		$oGrid = BxDolMTransfers::getObjectInstance('bx_dolphin_migration_transfers');
+
+		$JsCode =<<<EOF
+		<script>
+        const check = () => {
+              let oModules = $("[name=bx_dolphin_migration_transfers_check]:checked");
+                  if (oModules.length && typeof glGrids.bx_dolphin_migration_transfers != undefined) 
+                  {
+                      let aModules = []; 
+                      oModules.each(function(){
+                          aModules.push($(this).val());
+                      });
+                      glGrids.bx_dolphin_migration_transfers.iMigInterval = setInterval(function(){
+                          glGrids.bx_dolphin_migration_transfers.action(`finished`,{},`modules=` + aModules.join(','), true);
+                      }, {$this -> _oModule -> _oConfig -> _iCheckInterval})
+                  }
+              };
+        $("button[bx_grid_action_bulk='run']").bind('click', check);
+        </script>
+EOF;
+
 		if ($oGrid)	
-			return $oGrid -> getCode(); // print grid object 		
+			return $this -> getPathSettings() . $oGrid -> getCode() . $JsCode; // print grid object
         
 		return MsgBox(_t('_bx_dolphin_migration_installation_problem'));
 	}

+ 6 - 6
modules/boonex/dolphin_migration/classes/BxDolMTimeline.php

@@ -29,7 +29,7 @@ class BxDolMTimeline extends BxDolMData
 	
 	public function getTotalRecords()
 	{
-		return (int)$this -> _mDb -> getOne("SELECT COUNT(*) FROM `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name'] . "` ORDER BY `id`");
+	    return (int)$this -> _mDb -> getOne("SELECT COUNT(*) FROM `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name'] . "` ORDER BY `id`");
 	}
 	/**
 	 *  Returns data from the module into which data was added
@@ -40,7 +40,8 @@ class BxDolMTimeline extends BxDolMData
 	 */
 	private function getModuleItemInfo($iModuleItemId, $sModule = 'forum')
 	{
-		switch($sModule)
+        $sTable = '';
+	    switch($sModule)
 		{
 			case 'events':
 					$sTable = 'bx_events_data';
@@ -85,9 +86,6 @@ class BxDolMTimeline extends BxDolMData
 		$iObjectId = $this -> getProfileId($aInfo['object_id']);
 		$iTime	= time();
 		$sTitle = '';
-		$sUrl = '';
-		$iMediaId = 0;
-		$sMediaType = 0;
 		$aData = array();
 		
 		$mixedTransferred = $this -> isModuleContentTransferred($aInfo['type']);
@@ -114,6 +112,7 @@ class BxDolMTimeline extends BxDolMData
 				$sType = $aInfo['type'];
 				$iObjectId = $aItemInfo['id'];
 				$iTime = $aInfo['date'];
+
 				switch($sModule)
 				{
 					case 'events':
@@ -186,11 +185,12 @@ class BxDolMTimeline extends BxDolMData
 				if (isset($aInfo['content']))
 					$aItemInfo = @unserialize($aInfo['content']);
 				
-				if (!isset($aItemInfo['action']) || !($aItemInfo['action'] == 'add' || $aItemInfo['action'] == 'create'))
+				if (!isset($aItemInfo['action']) || !($aItemInfo['action'] == 'add' || $aItemInfo['action'] == 'create')  || !isset($this -> _oConfig -> _aModulesAliases[$aItemInfo['type']]))
 					break;
 				else
 					$sSubAction = 'added';
 
+
 				$aSubInfo = $this -> getModuleItemInfo($aItemInfo['object_id'], $this -> _oConfig -> _aModulesAliases[$aItemInfo['type']]);
 				if (empty($aSubInfo))
 					break;

+ 14 - 3
modules/boonex/dolphin_migration/classes/BxDolMTransfers.php

@@ -50,11 +50,22 @@ class BxDolMTransfers extends BxTemplGrid
 	{
 		$aElements = bx_get('ids');
 		echoJson(array(
-			'msg' => $this-> _oModule -> actionStartTransfer($aElements), 
-			'grid' => $this -> getCode(false),
-			'blink' => $aElements,
+            'msg' => $this-> _oModule -> actionStartTransfer($aElements),
+		    'grid' => $this -> getCode(false),
+			'blink' => $aElements
 		));		   
 	}
+
+    public function performActionFinished()
+    {
+        $aElements = explode(',', bx_get('modules'));
+        if (!empty($aElements) && $this-> _oModule -> _oDb -> isFinished($aElements))
+          echoJson(array(
+            'grid' => $this -> getCode(false),
+            'blink' => $aElements,
+            'eval' => 'clearInterval(glGrids.bx_dolphin_migration_transfers.iMigInterval);'
+        ));
+    }
 	
 	protected function _getFilterControls ()
     {

+ 1 - 1
modules/boonex/dolphin_migration/install/config.php

@@ -17,7 +17,7 @@ $aConfig = array(
     'name' => 'bx_dolphin_migration',
     'title' => 'Dolphin Migration',
     'note' => 'Migration Tool',
-    'version' => '9.0.3.DEV',
+    'version' => '9.0.4.DEV',
     'vendor' => 'Boonex',
 	'help_url' => 'http://feed.una.io/?section={module_name}',
 

+ 8 - 2
modules/boonex/dolphin_migration/install/langs/en.xml

@@ -18,7 +18,7 @@
 	<string name="_bx_dolphin_migration_defined_path"><![CDATA[Path to Dolphin script]]></string>
 	<string name="_bx_dolphin_migration_start_transfer"><![CDATA[Start transfer]]></string>
 	<string name="_bx_dolphin_migration_start_transfer_confirmation"><![CDATA[Please don't reload or close the page during data transferring]]></string>  
-	<string name="_bx_dolphin_migration_reupload_data"><![CDATA[If you update path to config file, all information from table below will be lost, but all transferred data will be saved.]]></string>  
+	<string name="_bx_dolphin_migration_reupload_data"><![CDATA[If you update path, all information from table below will be lost, but it will not influence on already transferred data.]]></string>
 	<string name="_bx_dolphin_migration_already_transfer"><![CDATA[Module {0} already transferred]]></string>
 	<string name="_bx_dolphin_migration_install_before"><![CDATA[Please transfer {0} first!]]></string>
 	<string name="_bx_dolphin_migration_install_plugin"><![CDATA[You need to install {0} plugin(s), before {1} transfer]]></string>
@@ -93,7 +93,7 @@
 	<string name="_bx_dolphin_migration_started_migration_forum_finished"><![CDATA[{0} topics with posts and comments were transferred]]></string>
 	<string name="_bx_dolphin_migration_started_migration_forum_error"><![CDATA[Error occurred. Record Id is {0}]]></string>
 	<string name="_bx_dolphin_migration_started_migration_polls"><![CDATA[Polls migration was started]]></string>
-	<string name="_bx_dolphin_migration_started_migration_polls_finished"><![CDATA[Polls were transferred]]></string>
+	<string name="_bx_dolphin_migration_started_migration_polls_finished"><![CDATA[{0} Polls were transferred]]></string>
 	<string name="_bx_dolphin_migration_started_migration_polls_error"><![CDATA[Error occurred. Record Id is {0}]]></string>
 	<string name="_bx_dolphin_migration_started_migration_timeline"><![CDATA[Wall Migration was started]]></string>
 	<string name="_bx_dolphin_migration_started_migration_timeline_finished"><![CDATA[{0} wall posts with comments were transferred]]></string>
@@ -112,4 +112,10 @@
 	<string name="_bx_dolphin_migration_successfully_removed"><![CDATA[{0} records were successfully removed!]]></string>
 	<string name="_bx_dolphin_migration_nothing_removed"><![CDATA[Nothing was removed!]]></string>
 	<string name="_bx_dolphin_migration_remove_profile_content_confirmation"><![CDATA[If you remove profiles, it will remove all transferred profiles' content also. Continue?]]></string>
+	<string name="_bx_dolphin_migration_cpt_overwrite"><![CDATA[If account with the same NickName already exists, overwrite its info.
+	<br/><b>This option is useful if you already have account on current version with the same Nickname as in Dolphin. If you enable this option all existed on UNA accounts will be updated using profiles' info from Dolphin and don't forget that info of your current logged member may be also updated and you can be logged out.</b>]]></string>
+	<string name="_bx_dolphin_migration_cpt_clean"><![CDATA[Clean]]></string>
+	<string name="_bx_dolphin_migration_cpt_use_nickname"><![CDATA[Use NickName instead of Profile's FullName]]></string>
+	<string name="_bx_dolphin_migration_cpt_empty_albums"><![CDATA[Transfer photo albums even if they are empty]]></string>
+	<string name="_bx_dolphin_migration_cpt_clean_warning"><![CDATA[Path to the Dolphin root and information from table below will be lost, Continue?]]></string>
 </resources>

+ 4 - 1
modules/boonex/dolphin_migration/install/sql/enable.sql

@@ -11,7 +11,10 @@ VALUES (@iTypeId,  @sName, '_bx_dolphin_migration_wgt_cpt', 1);
 SET @iCategId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_error`, `extra`, `order`) VALUES
-('bx_dolphin_migration_salt', '', 0, '_bx_dolphin_migration_salt', 'digit', '', '', '', 0);
+('bx_dolphin_migration_salt', '', 0, '_bx_dolphin_migration_salt', 'digit', '', '', '', 0),
+('bx_dolphin_migration_overwrite', '', @iCategId, '_bx_dolphin_migration_cpt_overwrite', 'checkbox', '', '', '', 0),
+('bx_dolphin_migration_use_nickname', '', @iCategId, '_bx_dolphin_migration_cpt_use_nickname', 'checkbox', '', '', '', 0),
+('bx_dolphin_migration_empty_albums', 'on', @iCategId, '_bx_dolphin_migration_cpt_empty_albums', 'checkbox', '', '', '', 0);
 
 -- GRIDS:
 INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `field_active`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_fields_translatable`, `filter_mode`, `sorting_fields`, `sorting_fields_translatable`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES

+ 4 - 1
modules/boonex/dolphin_migration/template/css/main.css

@@ -7,10 +7,13 @@
 	font-weight:bold;
 	color:red;
 }
-table.bx-grid-table td{
+table#bx-grid-table-bx_dolphin_migration_transfers td{
 	text-align:center;
 }
 
 .bx-grid-header-cnt > div{
 	width:50%;	
+}
+.bx-form-input-wrapper-input_set > button{
+	margin-right:2rem;
 }

+ 1 - 13
modules/boonex/se_migration/classes/BxSEMigConfig.php

@@ -58,19 +58,7 @@ class BxSEMigConfig extends BxBaseModGeneralConfig {
 						'bx_persons'	=> 'Persons',
 						'bx_albums'		=> 'Albums'	
 			        ),
-                ),
-                
-                /*'videos' => array(
-                    'table_name'     => 'video_videos',
-                    'migration_class' => 'BxSEMigVideos',
-			        'dependencies' => array(
-                		'profiles',
-                     ),
-					 'plugins' => array(
-						'bx_persons'	=> 'Persons',
-						'bx_albums'		=> 'Albums'	
-			        ),
-                ),*/                
+                )               
              );
 			 
    public function __construct($aModule){

+ 1 - 2
modules/boonex/se_migration/classes/BxSEMigStudioPage.php

@@ -27,13 +27,12 @@ class BxSEMigStudioPage extends BxTemplStudioModule
             array('name' => 'config', 'icon' => 'exchange-alt', 'title' => '_bx_se_migration_cpt_transfer_data'),
         );	
 		
-		$this -> _oModule -> _oTemplate -> addStudioJs(array('transfer.js', 'BxDolGrid.js'));
+		$this -> _oModule -> _oTemplate -> addStudioJs(array('jquery-ui/jquery-ui.custom.min.js', 'transfer.js', 'BxDolGrid.js'));
 		$this -> _oModule -> _oTemplate -> addStudioCss(array('main.css'));	
      } 
 	
 	public function saveData($sPath){
 		$isDbDefined = false;
-        $isDirDefined = false;
 
 		if ( substr($sPath, strlen($sPath) - 1 ) != DIRECTORY_SEPARATOR ) {
                 $sPath .= DIRECTORY_SEPARATOR;

+ 1 - 1
modules/boonex/se_migration/template/css/main.css

@@ -7,7 +7,7 @@
 	font-weight:bold;
 	color:red;
 }
-table.bx-grid-table td{
+table#bx-grid-table-bx_se_migration_transfers td{
 	text-align:center;
 }