BxDolMQuotes.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. require_once('BxDolMData.php');
  12. bx_import('BxDolStorage');
  13. class BxDolMQuotes extends BxDolMData
  14. {
  15. public function __construct(&$oMigrationModule, &$oDb)
  16. {
  17. parent::__construct($oMigrationModule, $oDb);
  18. $this -> _sModuleName = 'quotes';
  19. $this -> _sTableWithTransKey = 'bx_quoteofday_internal';
  20. }
  21. public function getTotalRecords()
  22. {
  23. return $this -> _mDb -> getOne("SELECT COUNT(*) FROM `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name'] . "`");
  24. }
  25. public function runMigration()
  26. {
  27. if (!$this -> getTotalRecords())
  28. {
  29. $this -> setResultStatus(_t('_bx_dolphin_migration_no_data_to_transfer'));
  30. return BX_MIG_SUCCESSFUL;
  31. }
  32. $this -> setResultStatus(_t('_bx_dolphin_migration_started_migration_quotes'));
  33. $this -> createMIdField();
  34. $aQuotes = $this -> _mDb -> getAll("SELECT * FROM `" . $this -> _oConfig -> _aMigrationModules[$this -> _sModuleName]['table_name'] . "` ORDER BY `ID`");
  35. $aParticipantsList = array();
  36. foreach($aQuotes as $iMes => $aQuote)
  37. {
  38. $iQuoteId = $this -> isItemExisted($aQuote['ID']);
  39. if (!$iQuoteId)
  40. {
  41. $sQuery = $this -> _oDb -> prepare(
  42. "
  43. INSERT INTO
  44. `{$this -> _sTableWithTransKey}`
  45. SET
  46. `text` = ?,
  47. `added` = UNIX_TIMESTAMP()
  48. ",
  49. $aQuote['Text']
  50. );
  51. $this -> _oDb -> query($sQuery);
  52. $iQuoteId = $this -> _oDb -> lastId();
  53. if (!$iQuoteId)
  54. {
  55. $this -> setResultStatus(_t('_bx_dolphin_migration_started_migration_quotes_error', (int)$aQuote['ID']));
  56. return BX_MIG_FAILED;
  57. }
  58. $this -> setMID($iQuoteId, $aQuote['ID']);
  59. $this -> _iTransferred++;
  60. }
  61. }
  62. // set as finished;
  63. $this -> setResultStatus(_t('_bx_dolphin_migration_started_migration_quotes_finished', $this -> _iTransferred));
  64. return BX_MIG_SUCCESSFUL;
  65. }
  66. public function removeContent()
  67. {
  68. if (!$this -> _oDb -> isTableExists($this -> _sTableWithTransKey) || !$this -> _oDb -> isFieldExists($this -> _sTableWithTransKey, $this -> _sTransferFieldIdent))
  69. return false;
  70. $aRecords = $this -> _oDb -> getAll("SELECT * FROM `{$this -> _sTableWithTransKey}` WHERE `{$this -> _sTransferFieldIdent}` !=0 ");
  71. $iNumber = 0;
  72. if (!empty($aRecords)) {
  73. foreach ($aRecords as $iKey => $aValue) {
  74. $this->_oDb->query("DELETE FROM `{$this -> _sTableWithTransKey}` WHERE `id`=:id", array('id' => $aValue['id']));
  75. $iNumber++;
  76. }
  77. }
  78. parent::removeContent();
  79. return $iNumber;
  80. }
  81. }
  82. /** @} */