Consumer.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. class Consumer extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  8. {
  9. /**
  10. * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
  11. * @param string $connectionName
  12. */
  13. public function __construct(
  14. \Magento\Framework\Model\ResourceModel\Db\Context $context,
  15. $connectionName = null
  16. ) {
  17. parent::__construct($context, $connectionName);
  18. }
  19. /**
  20. * Initialize resource model
  21. *
  22. * @return void
  23. */
  24. protected function _construct()
  25. {
  26. $this->_init('oauth_consumer', 'entity_id');
  27. }
  28. /**
  29. * Delete all Nonce entries associated with the consumer
  30. *
  31. * @param \Magento\Framework\Model\AbstractModel $object
  32. * @return $this
  33. */
  34. public function _afterDelete(\Magento\Framework\Model\AbstractModel $object)
  35. {
  36. $connection = $this->getConnection();
  37. $connection->delete($this->getTable('oauth_nonce'), ['consumer_id = ?' => (int)$object->getId()]);
  38. $connection->delete($this->getTable('oauth_token'), ['consumer_id = ?' => (int)$object->getId()]);
  39. return parent::_afterDelete($object);
  40. }
  41. /**
  42. * Compute time in seconds since consumer was created.
  43. *
  44. * @deprecated 100.0.6
  45. *
  46. * @param int $consumerId - The consumer id
  47. * @return int - time lapsed in seconds
  48. */
  49. public function getTimeInSecondsSinceCreation($consumerId)
  50. {
  51. $connection = $this->getConnection();
  52. $select = $connection->select()
  53. ->from($this->getMainTable())
  54. ->reset(\Magento\Framework\DB\Select::COLUMNS)
  55. ->columns(new \Zend_Db_Expr('CURRENT_TIMESTAMP() - created_at'))
  56. ->where('entity_id = ?', $consumerId);
  57. return $connection->fetchOne($select);
  58. }
  59. }