dateTime = $dateTime; $this->requestLogConfig = $requestLogConfig; } /** * {@inheritdoc} */ protected function _construct() { $this->_init('oauth_token_request_log', 'entity_id'); } /** * {@inheritdoc} */ public function getFailuresCount($userName, $userType) { $select = $this->getConnection()->select(); $select->from($this->getMainTable(), 'failures_count') ->where('user_name = :user_name AND user_type = :user_type'); return (int)$this->getConnection()->fetchOne($select, ['user_name' => $userName, 'user_type' => $userType]); } /** * {@inheritdoc} */ public function resetFailuresCount($userName, $userType) { $this->getConnection()->delete( $this->getMainTable(), ['user_name = ?' => $userName, 'user_type = ?' => $userType] ); } /** * {@inheritdoc} */ public function incrementFailuresCount($userName, $userType) { $date = (new \DateTime())->setTimestamp($this->dateTime->gmtTimestamp()); $date->add(new \DateInterval('PT' . $this->requestLogConfig->getLockTimeout() . 'S')); $dateTime = $date->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); $this->getConnection()->insertOnDuplicate( $this->getMainTable(), [ 'user_name' => $userName, 'user_type' => $userType, 'failures_count' => 1, 'lock_expires_at' => $dateTime ], [ 'failures_count' => new \Zend_Db_Expr('failures_count+1'), 'lock_expires_at' => new \Zend_Db_Expr("'" . $dateTime . "'") ] ); } /** * {@inheritdoc} */ public function clearExpiredFailures() { $date = (new \DateTime())->setTimestamp($this->dateTime->gmtTimestamp()); $dateTime = $date->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); $this->getConnection()->delete($this->getMainTable(), ['lock_expires_at <= ?' => $dateTime]); } }