示例#1
0
 /**
  * Clean up old authorized tokens for specified consumer-user pairs
  *
  * @param \Magento\Integration\Model\Oauth\Token $exceptToken Token just created to exclude from delete
  * @throws \Magento\Framework\Model\Exception
  * @return int The number of affected rows
  */
 public function cleanOldAuthorizedTokensExcept(\Magento\Integration\Model\Oauth\Token $exceptToken)
 {
     if (!$exceptToken->getId() || !$exceptToken->getAuthorized()) {
         throw new \Magento\Framework\Model\Exception('Invalid token to except');
     }
     $adapter = $this->_getWriteAdapter();
     $where = $adapter->quoteInto('authorized = 1 AND consumer_id = ?', $exceptToken->getConsumerId(), \Zend_Db::INT_TYPE);
     $where .= $adapter->quoteInto(' AND entity_id <> ?', $exceptToken->getId(), \Zend_Db::INT_TYPE);
     if ($exceptToken->getCustomerId()) {
         $where .= $adapter->quoteInto(' AND customer_id = ?', $exceptToken->getCustomerId(), \Zend_Db::INT_TYPE);
     } elseif ($exceptToken->getAdminId()) {
         $where .= $adapter->quoteInto(' AND admin_id = ?', $exceptToken->getAdminId(), \Zend_Db::INT_TYPE);
     } else {
         throw new \Magento\Framework\Model\Exception('Invalid token to except');
     }
     return $adapter->delete($this->getMainTable(), $where);
 }