Nonce.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Model\ResourceModel\Oauth;
  7. /**
  8. * oAuth nonce resource model
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Nonce extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  13. {
  14. /**
  15. * Initialize resource model
  16. *
  17. * @return void
  18. */
  19. protected function _construct()
  20. {
  21. $this->_init('oauth_nonce', null);
  22. }
  23. /**
  24. * Delete old entries
  25. *
  26. * @param int $minutes Delete entries older than
  27. * @return int
  28. */
  29. public function deleteOldEntries($minutes)
  30. {
  31. if ($minutes > 0) {
  32. $connection = $this->getConnection();
  33. return $connection->delete(
  34. $this->getMainTable(),
  35. $connection->quoteInto('timestamp <= ?', time() - $minutes * 60, \Zend_Db::INT_TYPE)
  36. );
  37. } else {
  38. return 0;
  39. }
  40. }
  41. /**
  42. * Select a unique nonce row using a composite primary key (i.e. $nonce and $consumerId)
  43. *
  44. * @param string $nonce - The nonce string
  45. * @param int $consumerId - The consumer id
  46. * @return array - Array of data
  47. */
  48. public function selectByCompositeKey($nonce, $consumerId)
  49. {
  50. $connection = $this->getConnection();
  51. $select = $connection->select()->from(
  52. $this->getMainTable()
  53. )->where(
  54. 'nonce = ?',
  55. $nonce
  56. )->where(
  57. 'consumer_id = ?',
  58. $consumerId
  59. );
  60. $row = $connection->fetchRow($select);
  61. return $row ? $row : [];
  62. }
  63. }