AlexeyUna 5 лет назад
Родитель
Сommit
23c2fe822b

+ 32 - 4
modules/boonex/dolphin_migration/classes/BxDolMConfig.php

@@ -20,7 +20,8 @@ class BxDolMConfig extends BxBaseModGeneralConfig
 		'bx_poll' => 'polls',
 		'bx_events' => 'events',
 		'bx_groups' => 'groups',		
-		'bx_blogs' => 'blogs'
+		'bx_blogs' => 'blogs',
+		'bx_photos' => 'photos',
 	);
 
     /**
@@ -115,7 +116,7 @@ class BxDolMConfig extends BxBaseModGeneralConfig
 						'bx_events'	=> 'Events'					
 			        ),
                 ),
-				'photos' => array(
+				'photos_albums' => array(
                     'table_name'	=> 'bx_photos_main',	
 					'table_name_albums' => 'sys_albums',
 					'type'				=> 'bx_photos',
@@ -129,7 +130,21 @@ class BxDolMConfig extends BxBaseModGeneralConfig
 						'bx_albums'		=> 'Albums'	
 			        ),
                 ),
-				'videos' => array(
+                'photos' => array(
+                    'table_name'	=> 'bx_photos_main',
+                    'table_name_photos' => 'sys_albums',
+                    'type'				=> 'bx_photos',
+                    'keywords'			=> 'bx_photos_meta_keywords',
+                    'migration_class' => 'BxDolMPhotos',
+                    'dependencies' => array(
+                        'profiles',
+                    ),
+                    'plugins' => array(
+                        'bx_persons'	=> 'Persons',
+                        'bx_photos'		=> 'Photos'
+                    ),
+                ),
+				'videos_albums' => array(
                     'table_name'	=> 'RayVideoFiles',
 					'table_name_albums' => 'sys_albums',
 					'type'				=> 'bx_videos',
@@ -142,7 +157,20 @@ class BxDolMConfig extends BxBaseModGeneralConfig
 						'bx_persons'	=> 'Persons',
 						'bx_albums'		=> 'Albums'	
 			        ),
-                ),				
+                ),
+                'videos' => array(
+                    'table_name'	=> 'RayVideoFiles',
+                    'table_name_videos' => 'sys_albums',
+                    'type'				=> 'bx_videos',
+                    'keywords'			=> 'bx_videos_meta_keywords_media',
+                    'migration_class'   => 'BxDolMVideos',
+                    'dependencies' => array(
+                        'profiles',
+                    ),
+                    'plugins' => array(
+                        'bx_persons'	=> 'Persons'
+                    ),
+                ),
 				'conversations' => array(
 					'table_name'		=> 'sys_messages',					
                     'migration_class'	=> 'BxDolMConv',

+ 9 - 1
modules/boonex/dolphin_migration/classes/BxDolMData.php

@@ -400,7 +400,11 @@ class BxDolMData
 		
 		switch($sType)
 		{
-			case 'photos': 
+            case 'photos':
+                            $sCmtsTable = 'bx_photos_cmts';
+                            $sTable = 'bx_photos_cmts';
+                            break;
+		    case 'album_photo':
 							$sCmtsTable = 'bx_photos_cmts';
 							$sTable = 'bx_albums_cmts_media';
 							break;
@@ -615,6 +619,10 @@ class BxDolMData
 
         return $this -> getValidPrivacy($iPrivacy);
     }
+
+    function getFieldType($sFieldName){
+        return $this->_mDb->getOne("SELECT `Type` FROM `sys_profile_fields` WHERE `Name`=:name LIMIT 1", array('name' => $sFieldName));
+    }
 }
    
 /** @} */

+ 6 - 5
modules/boonex/dolphin_migration/classes/BxDolMPhotoAlbums.php

@@ -15,14 +15,14 @@ bx_import('BxDolStorage');
 class BxDolMPhotoAlbums extends BxDolMData
 {
 	/**
-	*  @var $_iTransferredAlbums transferred alums number 
+	*  @var $_iTransferredAlbums transferred albums number
 	*/
 	private $_iTransferredAlbums;
     
 	public function __construct(&$oMigrationModule, &$oDb)
 	{
         parent::__construct($oMigrationModule, $oDb);
-		$this -> _sModuleName = 'photos';
+		$this -> _sModuleName = 'photo_albums';
 		$this -> _sTableWithTransKey = 'bx_albums_albums';
     }
 	
@@ -123,10 +123,11 @@ class BxDolMPhotoAlbums extends BxDolMData
 			$iTransferred  = 0;
 			foreach($aResult as $iKey => $aValue)
 			{ 
-				if ($this -> isFileExisted($iProfileId, $aValue['Title'], $aValue['Date'])) 
+				$sFileName = "{$aValue['ID']}.{$aValue['Ext']}";
+			    if ($this -> isFileExisted($iProfileId, $sFileName, $aValue['Date']))
 					continue;
 				
-				$sImagePath = $this -> _sImagePhotoFiles . "{$aValue['ID']}.{$aValue['Ext']}";				
+				$sImagePath = $this -> _sImagePhotoFiles . $sFileName;
 				if (file_exists($sImagePath))
 				{
 					$oStorage = BxDolStorage::getObjectInstance('bx_albums_files');
@@ -138,7 +139,7 @@ class BxDolMPhotoAlbums extends BxDolMData
 						$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);
 						
-						$iCmts = $this -> transferComments($iItemId = $this -> _oDb -> lastId(), $aValue['ID']);
+						$iCmts = $this -> transferComments($iItemId = $this -> _oDb -> lastId(), $aValue['ID'], 'album_photo');
 						if ($iCmts)
 							$this -> _oDb -> query("UPDATE `bx_albums_files2albums` SET `comments` = :comments WHERE `id` = :id", array('id' => $iItemId, 'comments' => $iCmts));
 						

+ 202 - 0
modules/boonex/dolphin_migration/classes/BxDolMPhotos.php

@@ -0,0 +1,202 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    DolphinMigration  Dolphin Migration
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+require_once('BxDolMData.php');
+bx_import('BxDolStorage');
+	
+class BxDolMPhotos extends BxDolMData
+{
+	public function __construct(&$oMigrationModule, &$oDb)
+	{
+        parent::__construct($oMigrationModule, $oDb);
+		$this -> _sModuleName = 'photos';
+		$this -> _sTableWithTransKey = 'bx_photos_entries';
+    }
+	
+	public function getTotalRecords()
+	{
+		$aResult = $this -> _mDb -> getRow("SELECT COUNT(*) as `count`, SUM(`ObjCount`) as `obj` 
+                                            FROM `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name_photos'] ."` 
+                                            WHERE `Type` = 'bx_photos' AND `Uri` <> 'Hidden'");
+
+		return !(int)$aResult['count'] && !(int)$aResult['obj'] ? 0 : $aResult;
+	}
+    
+	public function runMigration()
+	{
+		if (!$this -> getTotalRecords())
+		{
+			  $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_photos'] ."` 
+		                                    WHERE `Type` = 'bx_photos' AND `Uri` <> 'Hidden' {$sWhereCount} ORDER BY `ID` ASC");
+
+		foreach($aResult as $iKey => $aValue)
+		{ 			
+			$iProfileId = $this -> getProfileId((int)$aValue['Owner']);
+			if (!$iProfileId) 
+				continue;
+
+			$this -> migratePhoto($aValue['ID'], $iProfileId);
+			$this -> _iTransferredPhotos++;
+       }        
+
+        // set as finished;
+        $this -> setResultStatus(_t('_bx_dolphin_migration_started_migration_photos_finished', 0, $this -> _iTransferred));
+        return BX_MIG_SUCCESSFUL;
+    }
+   	
+   /**
+	* Migrates all photo albums and users photos
+	* @param int $iAlbumId original albums id
+	* @param int $iProfileId una profile ID
+	* @param int $iNewPhotoId created una Album
+	* @return Integer
+         */  
+   private function migratePhoto($iAlbumId, $iProfileId){
+          $aResult = $this -> _mDb -> getAll("SELECT  `m`.*, `a`.`AllowAlbumView`, `a`.`Status` as `admin_status`, `m`.`Status` as `status`
+													FROM  `sys_albums_objects` as `o`
+													LEFT JOIN `sys_albums` as `a` ON `o`.`id_album` = `a`.`ID`
+													LEFT JOIN `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name'] ."` as `m` ON `o`.`id_object` = `m`.`ID`
+													WHERE  `o`.`id_album` = :album ORDER BY `o`.`id_object` ASC", array('album' => $iAlbumId));
+
+		  $iTransferred  = 0;
+          foreach($aResult as $iKey => $aValue)
+		  {
+                $iPhotoId = $this -> isItemExisted($aValue['ID']);
+                if ($iPhotoId)
+                    continue;
+
+                $sPhotoTitle = $aValue['Title'];
+                $sQuery = $this -> _oDb -> prepare(
+                        "
+								INSERT INTO
+									`bx_photos_entries`
+								SET
+									`author`   			= ?,
+									`added`      		= ?,
+									`changed`   		= ?,
+									`thumb`				= 0,
+									`title`				= ?,
+									`allow_view_to` 	= ?,
+									`text`				= ?,
+									`status_admin`		= ?,
+                                    `status`            = ?,
+                                    `cat`               = ?
+							 ",
+                        $iProfileId,
+                        $aValue['Date'] ? $aValue['Date'] : time(),
+                        $aValue['Date'] ? $aValue['Date'] : time(),
+                        $sPhotoTitle,
+                        $this -> getPrivacy($aValue['Owner'], (int)$aValue['AllowAlbumView'], 'photos', 'album_view'),
+                        $aValue['Desc'],
+                        $aValue['admin_status'] == 'active' ? 'active' : 'hidden',
+                        $aValue['status'] == 'approved' ? 'active' : 'hidden',
+                        $this -> transferCategory($aValue['Categories'], 'bx_photos', 'bx_photos_cats')
+                    );
+
+                    $this -> _oDb -> query($sQuery);
+                    if ($iPhotoId = $this -> _oDb -> lastId())
+                        $this -> setMID($iPhotoId, $aValue['ID']);
+                    else
+                        continue;
+
+			    $sFileName = "{$aValue['ID']}.{$aValue['Ext']}";
+				$sImagePath = $this -> _sImagePhotoFiles . $sFileName;
+				if (file_exists($sImagePath))
+				{
+					$oStorage = BxDolStorage::getObjectInstance('bx_photos_photos');
+					$iId = $oStorage -> storeFileFromPath($sImagePath, false, $iProfileId, $iPhotoId);
+					if ($iId)
+					{ 
+                        $this -> _iTransferred++;
+						$iTransferred++;
+
+                        $this->_oDb->query("UPDATE `bx_photos_entries` SET `thumb`=:thumb WHERE `id`=:id", array('thumb' => $iId, 'id' => $iPhotoId));
+
+                        $this->updateExif($iPhotoId, array('thumb' => $iId, 'id' => $iPhotoId));
+						$this->transferTags((int)$aValue['ID'], $iId, $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['type'], $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['keywords']);
+						$this->transferFavorites((int)$aValue['ID'], $iId);
+
+                        $this->_oDb->query("UPDATE `bx_photos_entries` SET `comments` = :comments WHERE `id` = :id", array('id' => $iPhotoId, 'comments' => $this->transferComments($iPhotoId, $aValue['ID'])));
+
+                    }
+				}
+			}	
+				  
+	  return $iTransferred;
+   }
+
+    private function transferFavorites($iPhotoId, $iNewID){
+        $aData = $this->_mDb->getRow("SELECT * FROM `bx_photos_favorites` WHERE `ID`=:id LIMIT 1", array('id' => $iPhotoId));
+        if (empty($aData))
+            return false;
+
+        $iProfileId = $this -> getProfileId((int)$aData['Profile']);
+        if (!$iProfileId)
+            return false;
+
+        $sQuery = $this -> _oDb -> prepare("INSERT INTO `bx_photos_favorites_track` SET `object_id` = ?, `author_id` = ?, `date` = ?", $iNewID, $iProfileId, ($aData['Date'] ? $aData['Date'] : time()));
+        return $this -> _oDb -> query($sQuery);
+    }
+
+	public function removeContent()
+	{
+		if (!$this -> _oDb -> isTableExists($this -> _sTableWithTransKey) || !$this -> _oDb -> isFieldExists($this -> _sTableWithTransKey, $this -> _sTransferFieldIdent))
+			return false;
+		
+		$aRecords = $this -> _oDb -> getAll("SELECT * FROM `{$this -> _sTableWithTransKey}` WHERE `{$this -> _sTransferFieldIdent}` !=0");
+		$iNumber = 0;		
+		if (!empty($aRecords))
+		{		
+			foreach($aRecords as $iKey => $aValue)
+			{
+				BxDolService::call('bx_photos', 'delete_entity', array($aValue['id']));
+				$iNumber++;
+			}
+		}
+
+		parent::removeContent();
+		return $iNumber;
+	}
+
+    function updateExif($iPhotoId, $aContentInfo)
+    {
+        $CNF = &$this->_oConfig->CNF;
+        $oStorage = BxDolStorage::getObjectInstance('bx_photos_photos');
+        $oTranscoder = BxDolTranscoderImage::getObjectInstance('bx_photos_preview');
+
+        if (!$oStorage || !$oTranscoder)
+            return false;
+
+        $aInfo = bx_get_image_exif_and_size($oStorage, $oTranscoder, $aContentInfo['thumb']);
+        $this->_oDb->query("UPDATE `bx_photos_entries` SET `exif`=:exif WHERE `id`=:id", array('exif' => $aInfo['exif'], 'id' => $iPhotoId));
+
+        $aExif = unserialize($aInfo['exif']);
+        if ($aContentInfo && isset($aExif['Make']) && !empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
+            $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
+            if ($oMetatags->keywordsIsEnabled()){
+                $oMetatags->keywordsAddOne($aContentInfo['id'], $oMetatags->keywordsCameraModel($aExif));
+            }
+        }
+    }
+}
+
+/** @} */

+ 7 - 7
modules/boonex/dolphin_migration/install/langs/en.xml

@@ -6,19 +6,18 @@
 	<string name="_bx_dolphin_migration_cpt_transfer_data"><![CDATA[Data Transfer]]></string>
 	<string name="_bx_dolphin_migration_cpt_put_path"><![CDATA[Define path to the root Dolphin's folder]]></string>  
 	<string name="_bx_dolphin_migration_cpt_save"><![CDATA[Save]]></string>
-	<string name="_bx_dolphin_migration_cpt_update"><![CDATA[Update]]></string>
+	<string name="_bx_dolphin_migration_cpt_update"><![CDATA[Set the path]]></string>
 	<string name="_bx_dolphin_migration_error_data_was_not_set"><![CDATA[Configuration was not defined]]></string>
 	<string name="_bx_dolphin_migration_error_config_file_was_not_found"><![CDATA[Sorry configuration file was not found, please check path to the Dolphin Script!]]></string>
 	<string name="_bx_dolphin_migration_data_was_set"><![CDATA[Dolphin Configuration was successfully set. Go to Data Transfer area to continue!]]></string>
-	<string name="_bx_dolphin_migration_avaialble_modules_to_transfer"><![CDATA[Available content for transfer]]></string>
 	<string name="_bx_dolphin_migration_no_data_to_transfer"><![CDATA[No data to transfer]]></string>  
 	<string name="_bx_dolphin_migration_modules_name"><![CDATA[Data]]></string>  
 	<string name="_bx_dolphin_migration_modules_records_number"><![CDATA[Records number]]></string>  
 	<string name="_bx_dolphin_migration_modules_status"><![CDATA[Status]]></string>
-	<string name="_bx_dolphin_migration_defined_path"><![CDATA[Path to Dolphin script]]></string>
+	<string name="_bx_dolphin_migration_defined_path"><![CDATA[Path to the 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, all information from table below will be lost, but it will not influence on already transferred data.]]></string>
+	<string name="_bx_dolphin_migration_reupload_data"><![CDATA[If you update the path, all the 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>
@@ -56,7 +55,7 @@
 	<string name="_bx_dolphin_migration_data_shoutbox"><![CDATA[Shoutbox]]></string>
 	<string name="_bx_dolphin_migration_data_simple_messenger"><![CDATA[Simple messenger]]></string>
 	<string name="_bx_dolphin_migration_data_chat"><![CDATA[Flash Chat]]></string>
-	<string name="_bx_dolphin_migration_data_forum"><![CDATA[Topics, Posts]]></string>
+	<string name="_bx_dolphin_migration_data_forum"><![CDATA[Topicts, Posts]]></string>
 	<string name="_bx_dolphin_migration_data_conversations"><![CDATA[Conversations]]></string>
 	<string name="_bx_dolphin_migration_data_timeline"><![CDATA[Timeline]]></string>
 	<string name="_bx_dolphin_migration_started_migration_blogs"><![CDATA[Blogs Migration was started]]></string>
@@ -118,9 +117,10 @@
 	<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 or Email already exists, then to 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_clean"><![CDATA[Clear]]></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_default_privacy"><![CDATA[This privacy group will be set in case if you have not standard privacy groups in Dolphin and transferring item's privacy doesn't exist in UNA]]></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>
+	<string name="_bx_dolphin_migration_cpt_clean_warning"><![CDATA[The all data from the table below will be removed. Continue?]]></string>
+	<string name="_bx_dolphin_migration_started_migration_conversations"><![CDATA[Migration has been started]]></string>
 </resources>

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

@@ -16,4 +16,8 @@ table#bx-grid-table-bx_dolphin_migration_transfers td{
 }
 .bx-form-input-wrapper-input_set > button{
 	margin-right:2rem;
+}
+
+#bx-grid-wrap-bx_dolphin_migration_transfers {
+	margin-top: 1rem;
 }