File tree Expand file tree Collapse file tree 2 files changed +25
-20
lines changed
app/code/Magento/Integration/Model Expand file tree Collapse file tree 2 files changed +25
-20
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,11 @@ class Consumer extends \Magento\Framework\Model\AbstractModel implements Consume
43
43
*/
44
44
protected $ dataHelper ;
45
45
46
+ /**
47
+ * @var \Magento\Framework\Stdlib\DateTime\DateTime
48
+ */
49
+ private $ _dateHelper ;
50
+
46
51
/**
47
52
* @param \Magento\Framework\Model\Context $context
48
53
* @param \Magento\Framework\Registry $registry
@@ -80,6 +85,22 @@ protected function _construct()
80
85
$ this ->_init ('Magento\Integration\Model\ResourceModel\Oauth\Consumer ' );
81
86
}
82
87
88
+ /**
89
+ * The getter function to get the new DateTime dependency
90
+ *
91
+ * @return \Magento\Framework\Stdlib\DateTime\DateTime
92
+ *
93
+ * @deprecated
94
+ */
95
+ private function getDateHelper ()
96
+ {
97
+ if ($ this ->_dateHelper === null ) {
98
+ $ this ->_dateHelper = \Magento \Framework \App \ObjectManager::getInstance ()
99
+ ->get (\Magento \Framework \Stdlib \DateTime \DateTime::class);
100
+ }
101
+ return $ this ->_dateHelper ;
102
+ }
103
+
83
104
/**
84
105
* BeforeSave actions
85
106
*
@@ -176,6 +197,8 @@ public function getCreatedAt()
176
197
public function isValidForTokenExchange ()
177
198
{
178
199
$ expiry = $ this ->dataHelper ->getConsumerExpirationPeriod ();
179
- return $ expiry > $ this ->getResource ()->getTimeInSecondsSinceTokenExchangeStarted ($ this ->getId ());
200
+ $ currentTimestamp = $ this ->getDateHelper ()->gmtTimestamp ();
201
+ $ updatedTimestamp = $ this ->getDateHelper ()->gmtTimestamp ($ this ->getUpdatedAt ());
202
+ return $ expiry > ($ currentTimestamp - $ updatedTimestamp );
180
203
}
181
204
}
Original file line number Diff line number Diff line change @@ -56,25 +56,7 @@ public function getTimeInSecondsSinceCreation($consumerId)
56
56
$ select = $ connection ->select ()
57
57
->from ($ this ->getMainTable ())
58
58
->reset (\Magento \Framework \DB \Select::COLUMNS )
59
- ->columns (new \Zend_Db_Expr ('UTC_TIMESTAMP() - created_at ' ))
60
- ->where ('entity_id = ? ' , $ consumerId );
61
-
62
- return $ connection ->fetchOne ($ select );
63
- }
64
-
65
- /**
66
- * Compute time in seconds since token exchange started.
67
- *
68
- * @param int $consumerId - The consumer id
69
- * @return int - time lapsed in seconds
70
- */
71
- public function getTimeInSecondsSinceTokenExchangeStarted ($ consumerId )
72
- {
73
- $ connection = $ this ->getConnection ();
74
- $ select = $ connection ->select ()
75
- ->from ($ this ->getMainTable ())
76
- ->reset (\Magento \Framework \DB \Select::COLUMNS )
77
- ->columns (new \Zend_Db_Expr ('UTC_TIMESTAMP() - updated_at ' ))
59
+ ->columns (new \Zend_Db_Expr ('CURRENT_TIMESTAMP() - created_at ' ))
78
60
->where ('entity_id = ? ' , $ consumerId );
79
61
80
62
return $ connection ->fetchOne ($ select );
You can’t perform that action at this time.
0 commit comments