Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Session.php
Go to the documentation of this file.
1 <?php
7 
12 {
18  protected $_useIsObjectNew = true;
19 
25  protected $_sessionFactory;
26 
34  public function __construct(
35  \Magento\Framework\Model\ResourceModel\Db\Context $context,
36  \Magento\Persistent\Model\SessionFactory $sessionFactory,
37  $connectionName = null
38  ) {
39  $this->_sessionFactory = $sessionFactory;
40  parent::__construct($context, $connectionName);
41  }
42 
48  protected function _construct()
49  {
50  $this->_init('persistent_session', 'persistent_id');
51  }
52 
61  protected function _getLoadSelect($field, $value, $object)
62  {
63  $select = parent::_getLoadSelect($field, $value, $object);
64  if (!$object->getLoadExpired()) {
65  $tableName = $this->getMainTable();
66  $select->join(
67  ['customer' => $this->getTable('customer_entity')],
68  'customer.entity_id = ' . $tableName . '.customer_id'
69  )->where(
70  $tableName . '.updated_at >= ?',
71  $object->getExpiredBefore()
72  );
73  }
74 
75  return $select;
76  }
77 
85  {
86  $this->getConnection()->delete($this->getMainTable(), ['customer_id = ?' => $customerId]);
87  return $this;
88  }
89 
96  public function isKeyAllowed($key)
97  {
98  $sameSession = $this->_sessionFactory->create()->setLoadExpired();
99  $sameSession->loadByCookieKey($key);
100  return !$sameSession->getId();
101  }
102 
110  public function deleteExpired($websiteId, $expiredBefore)
111  {
112  $this->getConnection()->delete(
113  $this->getMainTable(),
114  ['website_id = ?' => $websiteId, 'updated_at < ?' => $expiredBefore]
115  );
116  return $this;
117  }
118 }
$tableName
Definition: trigger.php:13
deleteExpired($websiteId, $expiredBefore)
Definition: Session.php:110
_getLoadSelect($field, $value, $object)
Definition: Session.php:61
$value
Definition: gender.phtml:16
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Persistent\Model\SessionFactory $sessionFactory, $connectionName=null)
Definition: Session.php:34