BxDolMData.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup DolphinMigration Dolphin Migration
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_MIG_SUCCESSFUL', 1);
  12. define('BX_MIG_FAILED', 0);
  13. /**
  14. * Base class for all migration classes
  15. * contains general variables and function for modules' migration classes
  16. */
  17. class BxDolMData
  18. {
  19. /**
  20. * @var ref $_oMainModule the reference to the main module object
  21. */
  22. protected $_oMainModule;
  23. /**
  24. * @var ref $_mDb the reference to Dolphin's database connect
  25. */
  26. protected $_mDb;
  27. /**
  28. * @var string $_sPrefix migration module database prefix
  29. */
  30. protected $_sPrefix;
  31. /**
  32. * @var ref $_oDb connect to UNA database
  33. */
  34. protected $_oDb;
  35. /**
  36. * @var string $_sModuleName module name, it is set by inherited object and equal to value from {@link $_aMigrationModules}
  37. *@uses BxDolMConfig::_aMigrationModules modules array
  38. */
  39. protected $_sModuleName = '';
  40. /**
  41. * @var string $_sTableWithTransKey the main a module's table name into which transferring data from Dolphin's module
  42. * it is individual for each module and set in constructor of each class
  43. */
  44. protected $_sTableWithTransKey;
  45. /**
  46. * @var int $_iTransferred number of transferred records
  47. */
  48. protected $_iTransferred = 0;
  49. /**
  50. * @var ref $_oLanguage reference on @uses BxDolStudioLanguagesUtils::getInstance()
  51. */
  52. protected $_oLanguage = null;
  53. /**
  54. * @var array $_aLanguages list of the installed languages in appropriate format
  55. */
  56. protected $_aLanguages = array();
  57. /**
  58. * @var string $_sImagePhotoFiles path to the photo module's data files in Dolphin
  59. */
  60. protected $_sImagePhotoFiles = '';
  61. /**
  62. * @var string $_sTransferFieldIdent field name which is created in table into which records are added, it allows to set connect between ids from Dolphin and UNA's tables
  63. */
  64. protected $_sTransferFieldIdent = 'mig_id';
  65. /**
  66. * Base class constructor
  67. *
  68. * @param ref $oMainModule main module
  69. * @param ref $oDb connect with Dolphin database
  70. * @return void
  71. */
  72. public function __construct(&$oMainModule, &$oDb)
  73. {
  74. $this -> _sPrefix = $oMainModule -> _aModule['db_prefix'];
  75. $this -> _oMainModule = $oMainModule;
  76. $this -> _oConfig = $oMainModule -> _oConfig;
  77. $this -> _mDb = $oDb;
  78. $this -> _oDb = $this -> _oMainModule -> _oDb;
  79. $this -> _sTableWithTransKey = '';
  80. $this -> _oLanguage = BxDolStudioLanguagesUtils::getInstance();
  81. $this -> _aLanguages = $this -> _oDb -> getPairs("SELECT * FROM `sys_localization_languages` WHERE `Enabled`='1'", 'Name', 'ID');
  82. $this -> _sImagePhotoFiles = $this -> _oDb -> getExtraParam('root') . 'modules' . DIRECTORY_SEPARATOR . 'boonex' . DIRECTORY_SEPARATOR . "photos" . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR;
  83. }
  84. /**
  85. * Main migration function, executes required operations for transfer
  86. * @return boolean
  87. */
  88. public function runMigration()
  89. {
  90. $this -> setResultStatus(_t('_bx_dolphin_migration_define_migration_method'));
  91. return BX_MIG_FAILED;
  92. }
  93. /**
  94. * Gets total records for transferring
  95. * @return boolean
  96. */
  97. public function getTotalRecords()
  98. {
  99. $this -> setResultStatus(_t('_bx_dolphin_migration_define_total_method'));
  100. return BX_MIG_FAILED;
  101. }
  102. /**
  103. * Set Migration Status
  104. * @param string $sStatus message
  105. */
  106. protected function setResultStatus($sStatus, $sModule = '')
  107. {
  108. $sQuery = $this -> _oDb -> prepare("UPDATE `{$this -> _sPrefix}transfers` SET `status_text` = ? WHERE `module` = ? ", $sStatus, $this -> _sModuleName);
  109. $this -> _oDb -> query($sQuery);
  110. }
  111. /**
  112. * Returns content id of transferred member from Dolphin
  113. * @param int $iId Dolphin's profile ID
  114. * @return int
  115. */
  116. protected function getContentId($iId){
  117. $sQuery = $this -> _oDb -> prepare("SELECT `p`.`content_id` FROM `sys_accounts` AS `a`
  118. LEFT JOIN `sys_profiles` AS `p` ON `a`.`id` = `p`.`account_id`
  119. WHERE `mig_id` = ? AND `p`.`type` = 'bx_persons' LIMIT 1", $iId);
  120. return $this -> _oDb -> getOne($sQuery);
  121. }
  122. /**
  123. * Returns person id of transferred member from Dolphin
  124. * @param int $iId Dolphin's profile ID
  125. * @return int
  126. */
  127. protected function getProfileId($iId)
  128. {
  129. $sQuery = $this -> _oDb -> prepare("SELECT `p`.`id` FROM `sys_accounts` AS `a`
  130. LEFT JOIN `sys_profiles` AS `p` ON `a`.`id` = `p`.`account_id`
  131. WHERE `mig_id` = ? AND `p`.`type` = 'bx_persons' LIMIT 1", $iId);
  132. return $this -> _oDb -> getOne($sQuery);
  133. }
  134. /**
  135. * Check if the module was transfered
  136. * @param string $sModule name from the list @uses BxDolMConfig::_aMigrationModules
  137. * @return int
  138. */
  139. protected function isModuleContentTransferred($sModule)
  140. {
  141. return isset($this -> _oConfig -> _aModulesAliases[$sModule])
  142. ? (int)$this -> _oDb -> getOne("SELECT `number` FROM `{$this -> _sPrefix}transfers` WHERE `status` != 'not_started' AND `module`=:module", array('module' => $this -> _oConfig -> _aModulesAliases[$sModule]))
  143. : false;
  144. }
  145. /**
  146. * Returns list of the fields which should be transferred to Persons module
  147. * @return array list of the fields names
  148. */
  149. protected function getAssocFields()
  150. {
  151. $aFields = array();
  152. $aExclude = array('Status', 'Couple', 'Captcha', 'aff_num', 'TermsOfUse', 'UserStatus', 'UserStatusMessage', 'UserStatusMessageWhen', 'Agree', 'Tags', 'Age', 'Featured', 'Keyword', 'Location', 'ProfilePhoto');
  153. $sWhere = "";
  154. if (!empty($aExclude))
  155. $sWhere = " AND `Name` NOT IN ('" . implode("','" , $aExclude) . "')";
  156. $aItems = $this -> _mDb -> getAll("SELECT * FROM `sys_profile_fields` WHERE `Type` != 'block' {$sWhere}");
  157. foreach($aItems as $iKey => $aValue)
  158. {
  159. $aFields[$aValue['Name']] = array(
  160. 'name' => $aValue['Name'],
  161. 'type' => $aValue['Type'],
  162. 'required' => $aValue['Mandatory'],
  163. 'title' => "_FieldCaption_{$aValue['Name']}_Edit",
  164. 'add' => (int)$aValue['JoinBlock'] !=0,
  165. 'edit' => (int)$aValue['EditOwnBlock'] !=0,
  166. 'view' => $aValue['ViewVisBlock'] !=0,
  167. 'values' => $aValue['Values']
  168. );
  169. }
  170. return $aFields;
  171. }
  172. /**
  173. * Check if the list already exists in una pre values list
  174. *
  175. * @param string $sName list name
  176. * @return Boolean
  177. */
  178. protected function isKeyPreKeyExits($sName)
  179. {
  180. return $this -> _oDb -> getOne("SELECT COUNT(*) FROM `sys_form_pre_lists` WHERE `key` = :key", array('key' => $sName)) == 1;
  181. }
  182. /**
  183. * Adds category to existed list
  184. *
  185. * @param string $sName category title
  186. * @param string $sPrefix prefix for the module which should be used for new category (depends on module)
  187. * @param int $sCategory module's category's pre values Name
  188. * @return string value of the added category
  189. */
  190. protected function transferCategory($sName, $sPrefix, $sCategory)
  191. {
  192. if (strpos($sName, ';') !== false)
  193. $sName = substr($sName, 0, strpos($sName, ';'));
  194. $sTitle = str_replace(' ', '_', $sName);
  195. $aValues = $this -> _oDb -> getRow("SELECT * FROM `sys_form_pre_values` WHERE `Key` = :cat AND `LKey` LIKE CONCAT('%', :value, '%') LIMIT 1", array('cat' => $sCategory, 'value' => $sTitle));
  196. if (!empty($aValues))
  197. return $aValues['Value'];
  198. $aValues = $this -> _oDb -> getRow("SELECT MAX(`Value`) + 1 as `Value`, MAX(`Order`) + 1 as `Order` FROM `sys_form_pre_values` WHERE `Key` = :cat", array('cat' => $sCategory));
  199. $sQuery = $this -> _oDb -> prepare("
  200. INSERT INTO `sys_form_pre_values` SET
  201. `Key` = ?,
  202. `Value` = ?,
  203. `Order` = ?,
  204. `LKey` = ?", $sCategory, $aValues['Value'], $aValues['Order'], "_{$sPrefix}_cat_{$sTitle}");
  205. $this -> _oDb -> query($sQuery);
  206. BxDolStudioLanguagesUtils::getInstance() -> addLanguageString("_{$sPrefix}_cat_{$sTitle}", $sName);
  207. return $aValues['Value'];
  208. }
  209. /**
  210. * Transfer fields lists with translations
  211. *
  212. * @param string $sName field name
  213. * @param string $sTitle translation
  214. * @param mixed $mixedValues contains name of the list which already exists or array values for transfer
  215. * @param bool $bAdd don't add value to already exited fields list
  216. * @return string list name for db insert with #!
  217. */
  218. protected function transferPreValues($sName, $sTitle, $mixedValues, $bAdd = false)
  219. {
  220. if (empty($mixedValues))
  221. return '';
  222. if (is_string($mixedValues) && substr($mixedValues, 0, 2) == '#!')
  223. return $mixedValues;
  224. $i = 1;
  225. if (!$this -> isKeyPreKeyExits($sName))
  226. {
  227. $sQuery = $this -> _oDb -> prepare("INSERT INTO `sys_form_pre_lists` (`id`, `module`, `key`, `title`, `use_for_sets`, `extendable`) VALUES
  228. (NULL, 'bx_persons', ?, ?, 0, 1)", $sName, '_bx_' . $sName . '_pre_lists_cats');
  229. $this -> _oLanguage -> addLanguageString('_bx_' . $sName . '_pre_lists_cats', $sTitle);
  230. $this -> _oDb -> query($sQuery);
  231. $sQuery = $this -> _oDb -> prepare("
  232. INSERT INTO `sys_form_pre_values` SET
  233. `Key` = ?,
  234. `Value` = ?,
  235. `Order` = ?,
  236. `LKey` = ?", $sName, '', 0, '_sys_please_select');
  237. $this -> _oDb -> query($sQuery);
  238. }
  239. else
  240. {
  241. if (!$bAdd)
  242. return '';
  243. $i = $this -> _oDb -> getOne("SELECT MAX(`Order`) FROM `sys_form_pre_values` WHERE `Key` =:key", array('key' => $sName)) + 1;
  244. }
  245. foreach($mixedValues as $mixedKey => $mixedValue)
  246. {
  247. $sLangKey = "_bx_fields_cat_{$sName}_value_{$mixedKey}";
  248. if (is_array($mixedValue))
  249. {
  250. foreach($mixedValue as $sLang => $sValue)
  251. {
  252. if (isset($this -> _aLanguages[$sLang]))
  253. $this -> _oLanguage -> addLanguageString($sLangKey, $sValue, $this -> _aLanguages[$sLang]);
  254. }
  255. }
  256. else
  257. $this -> _oLanguage -> addLanguageString($sLangKey, $mixedValue);
  258. $sQuery = $this -> _oDb -> prepare("
  259. INSERT INTO `sys_form_pre_values` SET
  260. `Key` = ?,
  261. `Value` = ?,
  262. `Order` = ?,
  263. `LKey` = ?", $sName, $mixedKey, $i++, $sLangKey);
  264. $this -> _oDb -> query($sQuery);
  265. }
  266. return "#!{$sName}";
  267. }
  268. /**
  269. * Returns pre values array by list name in pairs format
  270. *
  271. * @param string $sName name of the list
  272. * @param string $sField array's index field name
  273. * @param string $sValue array's value field name
  274. * @param int $iStart - allows to set start value and get values above it only
  275. * @return array
  276. */
  277. protected function getPreValuesBy($sName, $sField = 'Order', $sValue = 'LKey', $iStart = 0)
  278. {
  279. $sStart = '';
  280. if ($iStart)
  281. $sStart = "AND `$sField` > $iStart";
  282. $sQuery = $this -> _mDb -> prepare("SELECT * FROM `sys_pre_values` WHERE `Key` = ? {$sStart} ORDER BY `Order`", $sName);
  283. return $this -> _mDb -> getPairs($sQuery, $sField, $sValue);
  284. }
  285. /**
  286. * Returns default language name/id
  287. *
  288. * @param boolean $bName return language name, otherwise id
  289. * @return mixed default language
  290. */
  291. protected function getDefaultLang($bName = true)
  292. {
  293. $aLang = $this -> _mDb -> getPairs("SELECT * FROM `sys_localization_languages` ORDER BY `id`", 'Name', 'ID');
  294. $sDefultLang = $this -> _mDb -> getParam('lang_default');
  295. return $bName ? $sDefultLang : $aLang[$sDefultLang];
  296. }
  297. /**
  298. * Returns translations for all existed languages on Dolphin by language key
  299. *
  300. * @param string $LKey language key
  301. * @return array
  302. */
  303. protected function getLKeyTranslations($LKey)
  304. {
  305. return $this -> _mDb -> getPairs("SELECT `l`.`Name`, `s`.`String`, `l`.`ID`
  306. FROM `sys_localization_keys` as `k`
  307. LEFT JOIN `sys_localization_strings` as `s` ON `k`.`ID` = `s`.`IDKey`
  308. LEFT JOIN `sys_localization_languages` as `l` ON `s`.`IDLanguage` = `l`.`ID`
  309. WHERE `k`.`Key` = :key", 'Name', 'String', array('key' => $LKey));
  310. }
  311. /**
  312. * Returns pre values field value of defined field, by Key and Value
  313. *
  314. * @param string $sKey Key name
  315. * @param mixed $mixedValue Value
  316. * @param string $sField field name
  317. * @return mixed value
  318. */
  319. public function getPreValuesFieldBy($sKey, $mixedValue, $sField = 'Order')
  320. {
  321. return $this -> _mDb -> getOne("SELECT `{$sField}` FROM `sys_pre_values` WHERE `Key` = ? AND `Value` = ? LIMIT 1", $sName, $mixedValue);
  322. }
  323. /**
  324. * Transfer Tags from the module, to meta
  325. *
  326. * @param int $iObjectId module's item ID in Dolphin
  327. * @param int $iNewObjectId module's item ID in UNA
  328. * @param int $sType module's prefix in Dolphin
  329. * @param int $sTableKeywords table name in UNA for tags migration
  330. * @return void
  331. */
  332. protected function trasnferTags($iObjectId, $iNewObjectId, $sType, $sTableKeywords)
  333. {
  334. $aTags = $this -> _mDb -> getAll("SELECT `Tag` FROM `sys_tags` WHERE `ObjID`=:id AND `Type`=:type", array('id' => $iObjectId, 'type' => $sType));
  335. if (empty($aTags))
  336. return false;
  337. foreach($aTags as $aTag)
  338. $this -> _oDb -> query("INSERT IGNORE INTO `{$sTableKeywords}` SET `keyword`=:keyword, `object_id`=:id", array('keyword' => $aTag['Tag'], 'id' => $iNewObjectId));
  339. }
  340. private function addCmtsIds($sCmtsTable, $iId, $iRate){
  341. $iSystem = $this -> _oDb -> getOne("SELECT `ID` FROM `sys_objects_cmts` WHERE `Table`=:table LIMIT 1", array('table' => $sCmtsTable));
  342. if (!$iSystem)
  343. return false;
  344. return $this -> _oDb -> query("INSERT INTO `sys_cmts_ids` SET `system_id` = :id, `rate`=:rate, `cmt_id`=:cmt_id",
  345. array('id' => $iSystem, 'rate' => $iRate, 'cmt_id' => $iId));
  346. }
  347. /**
  348. * Transfer comments for module's items
  349. *
  350. * @param int $iObject object ID in UNA
  351. * @param int $iEntryId object ID in Dolphin
  352. * @param string $sType module name for transfer @uses BxDolMConfig::_aMigrationModules
  353. * @return int transferred comments number
  354. */
  355. protected function transferComments($iObject, $iEntryId, $sType = 'photos')
  356. {
  357. switch($sType)
  358. {
  359. case 'photos':
  360. $sCmtsTable = 'bx_photos_cmts';
  361. $sTable = 'bx_albums_cmts_media';
  362. break;
  363. case 'photo_albums':
  364. $sCmtsTable = 'bx_photos_cmts_albums';
  365. $sTable = 'bx_albums_cmts';
  366. break;
  367. case 'videos':
  368. $sCmtsTable = 'bx_videos_cmts';
  369. $sTable = 'bx_albums_cmts_media';
  370. break;
  371. case 'video_albums':
  372. $sCmtsTable = 'bx_videos_cmts_albums';
  373. $sTable = 'bx_albums_cmts';
  374. break;
  375. case 'blogs':
  376. $sCmtsTable = 'bx_blogs_cmts';
  377. $sTable = 'bx_posts_cmts';
  378. break;
  379. case 'groups':
  380. $sCmtsTable = 'bx_groups_cmts';
  381. $sTable = 'bx_groups_cmts';
  382. break;
  383. case 'events':
  384. $sCmtsTable = 'bx_events_cmts';
  385. $sTable = 'bx_events_cmts';
  386. break;
  387. case 'polls':
  388. $sCmtsTable = 'bx_poll_cmts';
  389. $sTable = 'bx_polls_cmts';
  390. break;
  391. case 'files':
  392. $sCmtsTable = 'bx_files_cmts';
  393. $sTable = 'bx_files_cmts';
  394. break;
  395. case 'market':
  396. $sCmtsTable = 'bx_store_cmts';
  397. $sTable = 'bx_market_cmts';
  398. break;
  399. case 'timeline':
  400. $sCmtsTable = 'bx_wall_comments';
  401. $sTable = 'bx_timeline_comments';
  402. break;
  403. }
  404. $aComments = $this -> _mDb -> getAll("SELECT * FROM `{$sCmtsTable}` WHERE `cmt_object_id` = :id ORDER BY `cmt_id` ASC", array('id' => $iEntryId));
  405. $iComments = 0;
  406. $aCommentsArray = array();
  407. foreach($aComments as $iKey => $aValue)
  408. {
  409. $iProfileId = $this -> getProfileId($aValue['cmt_author_id']);
  410. if ($iProfileId)
  411. {
  412. $bIscmtsArray = $aValue['cmt_parent_id'] && isset($aCommentsArray[$aValue['cmt_parent_id']]);
  413. $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`)
  414. VALUES (NULL, :parent_id, :vparent_id, :object, :user, :level, :message, :time, :replies)",
  415. array(
  416. 'parent_id' => $bIscmtsArray ? $aCommentsArray[$aValue['cmt_parent_id']]['id'] : 0,
  417. 'vparent_id' => $bIscmtsArray ? ($aCommentsArray[$aValue['cmt_parent_id']]['vparent'] ? $aCommentsArray[$aValue['cmt_parent_id']]['vparent'] : $aCommentsArray[$aValue['cmt_parent_id']]['id']) : 0,
  418. 'object' => $iObject,
  419. 'user' => $iProfileId,
  420. 'message' => $aValue['cmt_text'],
  421. 'time' => strtotime($aValue['cmt_time']),
  422. 'replies' => $aValue['cmt_replies'],
  423. 'level' => isset($aCommentsArray[$aValue['cmt_parent_id']]) && $aCommentsArray[$aValue['cmt_parent_id']] ? $aCommentsArray[$aValue['cmt_parent_id']]['level'] + 1 : 0
  424. ));
  425. $iLastInsertId = $this -> _oDb -> lastId();
  426. $this -> addCmtsIds($sTable, $iLastInsertId, $aValue['cmt_rate'], $aValue['cmt_rate_count']);
  427. $aCommentsArray[$aValue['cmt_id']] = array(
  428. 'id' => $iLastInsertId,
  429. 'level' => $bIscmtsArray ? (int)$aCommentsArray[$aValue['cmt_parent_id']]['level'] + 1 : 0,
  430. 'vparent' =>
  431. $bIscmtsArray ?
  432. (
  433. $aCommentsArray[$aValue['cmt_parent_id']]['vparent'] ? $aCommentsArray[$aValue['cmt_parent_id']]['vparent'] : $aCommentsArray[$aValue['cmt_parent_id']]['id']
  434. ) : 0
  435. );
  436. $iComments++;
  437. }
  438. }
  439. return $iComments;
  440. }
  441. /**
  442. * Create migration field in main table for transferring content from Dolphin to UNA and contains id of the object in Dolphin
  443. * @return mixed
  444. */
  445. protected function createMIDField()
  446. {
  447. if (!$this -> _sTableWithTransKey)
  448. return false;
  449. if ($this -> _oDb -> isFieldExists($this -> _sTableWithTransKey, $this -> _sTransferFieldIdent))
  450. return true;
  451. return $this -> _oDb -> query("ALTER TABLE `{$this -> _sTableWithTransKey}` ADD `{$this -> _sTransferFieldIdent}` int(11) unsigned NOT NULL default '0'");
  452. }
  453. /**
  454. * Returns last migration field value
  455. *
  456. * @return int
  457. */
  458. protected function getLastMIDField()
  459. {
  460. if (!$this -> _sTableWithTransKey)
  461. return false;
  462. return (int)$this -> _oDb -> getOne("SELECT `{$this -> _sTransferFieldIdent}` FROM `{$this -> _sTableWithTransKey}` WHERE `{$this -> _sTransferFieldIdent}` <> 0 ORDER BY `{$this -> _sTransferFieldIdent}` DESC LIMIT 1");
  463. }
  464. /**
  465. * Check if this record was already transferred
  466. *
  467. * @param int $iItemId object id in Dolphin
  468. * @param string $sField field name with id values in Dolphin
  469. * @return int
  470. */
  471. protected function isItemExisted($iItemId, $sField = 'id')
  472. {
  473. if (!$this -> _sTableWithTransKey)
  474. return false;
  475. return (int)$this -> _oDb -> getOne("SELECT `{$sField}` FROM `{$this -> _sTableWithTransKey}` WHERE `{$this -> _sTransferFieldIdent}` = :item LIMIT 1", array('item' => $iItemId));
  476. }
  477. /**
  478. * Set value for migrated record to migration field
  479. *
  480. * @param int $iId object id in UNA
  481. * @param int $iItemId object id in Dolphin
  482. * @param string $sField id field name
  483. * @return int affected rows
  484. */
  485. protected function setMID($iId, $iItemId, $sField ='id')
  486. {
  487. if (!$this -> _sTableWithTransKey)
  488. return false;
  489. return (int)$this -> _oDb -> query("UPDATE `{$this -> _sTableWithTransKey}` SET `{$this -> _sTransferFieldIdent}` = :item WHERE `{$sField}` = :id", array('id' => $iId, 'item' => $iItemId));
  490. }
  491. /**
  492. * Drop migration field from the table
  493. *
  494. * @return int affected rows
  495. */
  496. public function dropMID()
  497. {
  498. if (!$this -> _sTableWithTransKey || !$this -> _oDb -> isFieldExists($this -> _sTableWithTransKey, $this -> _sTransferFieldIdent))
  499. return false;
  500. return (int)$this -> _oDb -> query("ALTER TABLE `{$this -> _sTableWithTransKey}` DROP `{$this -> _sTransferFieldIdent}`");
  501. }
  502. /**
  503. * Removes all transferred content from UNA
  504. *
  505. * @return void
  506. */
  507. public function removeContent()
  508. {
  509. $this -> dropMID();
  510. $this -> _oDb -> updateTransferStatus($this -> _sModuleName, 'not_started');
  511. $this -> setResultStatus('');
  512. }
  513. }
  514. /** @} */