BxDataMigrationFeedback.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /***************************************************************************
  3. * Dolphin Smart Community Builder
  4. * -------------------
  5. * begin : Mon Mar 23 2006
  6. * copyright : (C) 2007 BoonEx Group
  7. * website : http://www.boonex.com
  8. * This file is part of Dolphin - Smart Community Builder
  9. *
  10. * Dolphin is free software; you can redistribute it and/or modify it under
  11. * the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the
  13. * License, or any later version.
  14. *
  15. * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  16. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. * See the GNU General Public License for more details.
  18. * You should have received a copy of the GNU General Public License along with Dolphin,
  19. * see license.txt file; if not, write to marketing@boonex.com
  20. ***************************************************************************/
  21. require_once 'BxDataMigrationData.php';
  22. class BxDataMigrationFeedback extends BxDataMigrationData {
  23. function BxDataMigrationFeedback(&$oMigrationModule, &$rOldDb, $oDolModule = '') {
  24. parent::BxDataMigrationData($oMigrationModule, $rOldDb, $oDolModule);
  25. }
  26. function getMigration() {
  27. $this->setResultStatus('The transfer was started.');
  28. mysql_query('SET NAMES utf8', $this->rOldDb);
  29. $sSql = "SELECT
  30. `ID` AS `id`,
  31. `Sender` AS `author_id`,
  32. `Header` AS `caption`,
  33. `Text` AS `content`,
  34. '' AS `uri`,
  35. '' AS `tags`,
  36. '3' AS `allow_comment_to`,
  37. '3' AS `allow_vote_to`,
  38. `Date` AS `date`,
  39. `Active` AS `status`,
  40. '0' AS `rate`,
  41. '0' AS `rate_count`,
  42. '0' AS `cmts_count`
  43. FROM `Stories`";
  44. $rResult = mysql_query($sSql, $this -> rOldDb);
  45. $iCount = mysql_num_rows($rResult);
  46. while($aFeedback = mysql_fetch_assoc($rResult)) {
  47. $aFeedback['uri'] = uriGenerate ($aFeedback['caption']
  48. , $this->oDolModule->_oDb->getPrefix() . 'entries', 'uri');
  49. $aFeedback['status'] = $aFeedback['status'] == 'on' ? 0 : 1;
  50. if($this->exists($aFeedback['id'], $aFeedback['uri'])) {
  51. $this->setResultStatus('Duplicate data. Feedback with similar info already exists.');
  52. return MIGRATION_FAILED;
  53. }
  54. $sSql = "INSERT INTO `" . $this->oDolModule->_oDb->getPrefix() . "entries` SET";
  55. foreach($aFeedback as $sKey => $sValue)
  56. $sSql .= " `" . $sKey . "`='" . $this -> oMigrationModule -> _oDb -> escape($sValue) . "',";
  57. $iResult = (int)$this->oDolModule->_oDb->query(substr($sSql, 0, -1));
  58. if($iResult <= 0) {
  59. $this->setResultStatus('Database error. Cannot insert data in the database.');
  60. return MIGRATION_FAILED;
  61. }
  62. }
  63. $this->setResultStatus('The transfer was successfully completed. (' . $iCount . ' items)');
  64. return MIGRATION_SUCCESSFUL;
  65. }
  66. function exists($iId, $sUri) {
  67. $iId = (int) $iId;
  68. $sUri = $this -> oMigrationModule -> _oDb -> escape($sUri);
  69. $sSql = "SELECT `id` FROM `" . $this->oDolModule->_oDb->getPrefix() . "entries` WHERE `id`='" . $iId . "' OR `uri`='" . $sUri . "' LIMIT 1";
  70. return (int)$this->oDolModule->_oDb->getOne($sSql) != 0;
  71. }
  72. }