/** * {@inheritdoc} */ public function read() { if ($token = $this->getToken() and $data = $this->connection->executeQuery("SELECT user_id, status, access FROM {$this->config['table']} WHERE id = :id AND status > :status", ['id' => sha1($token), 'status' => self::STATUS_INACTIVE])->fetch(\PDO::FETCH_ASSOC)) { if (strtotime($data['access']) + $this->config['timeout'] < time()) { if ($data['status'] == self::STATUS_REMEMBERED) { $this->write($data['user_id'], self::STATUS_REMEMBERED); } else { return null; } } $this->connection->update($this->config['table'], ['access' => date('Y-m-d H:i:s')], ['id' => sha1($token)]); return $data['user_id']; } return null; }
/** * Migrates the database. * * @return Schema */ public function migrate() { $diff = Comparator::compareSchemas($this->manager->createSchema(), $this->schema); foreach ($diff->toSaveSql($this->connection->getDatabasePlatform()) as $query) { $this->connection->executeQuery($query); } }
/** * Execute the query as select, update or delete. * * @param string $type * @return mixed */ protected function executeQuery($type = 'select') { switch ($type) { case 'update': $sql = $this->getSQLForUpdate(); break; case 'delete': $sql = $this->getSQLForDelete(); break; default: $sql = $this->getSQLForSelect(); } if ($type == 'select') { return $this->connection->executeQuery($sql, $this->params, $this->guessParamTypes($this->params)); } else { return $this->connection->executeUpdate($sql, $this->params, $this->guessParamTypes($this->params)); } }
/** * {@inheritdoc} */ public function write($id, $data) { try { $params = ['id' => $id, 'data' => base64_encode($data), 'time' => date('Y-m-d H:i:s')]; if (null !== ($sql = $this->getMergeSql())) { $this->connection->executeQuery($sql, $params); return true; } $this->connection->beginTransaction(); try { $this->connection->delete($this->table, ['id' => $id]); $this->connection->insert($this->table, $params); $this->connection->commit(); } catch (ConnectionException $e) { $this->connection->rollback(); throw $e; } } catch (\PDOException $e) { throw new \RuntimeException(sprintf('PDOException was thrown when trying to write the session data: %s', $e->getMessage()), 0, $e); } return true; }