Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 1 | <?php |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | bf6b11d | 2015-01-12 17:27:12 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 6 | * |
Andrey Andreev | 46f2f26 | 2014-11-11 14:37:51 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 8 | * |
Andrey Andreev | bf6b11d | 2015-01-12 17:27:12 +0200 | [diff] [blame] | 9 | * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 10 | * |
Andrey Andreev | 46f2f26 | 2014-11-11 14:37:51 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 17 | * |
Andrey Andreev | 46f2f26 | 2014-11-11 14:37:51 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
Andrey Andreev | bf6b11d | 2015-01-12 17:27:12 +0200 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | 46f2f26 | 2014-11-11 14:37:51 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
| 34 | * @link http://codeigniter.com |
| 35 | * @since Version 3.0.0 |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
| 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
| 39 | |
| 40 | /** |
| 41 | * CodeIgniter Session Database Driver |
| 42 | * |
Andrey Andreev | 46f2f26 | 2014-11-11 14:37:51 +0200 | [diff] [blame] | 43 | * @package CodeIgniter |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 44 | * @subpackage Libraries |
| 45 | * @category Sessions |
Andrey Andreev | 46f2f26 | 2014-11-11 14:37:51 +0200 | [diff] [blame] | 46 | * @author Andrey Andreev |
| 47 | * @link http://codeigniter.com/user_guide/libraries/sessions.html |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 48 | */ |
| 49 | class CI_Session_database_driver extends CI_Session_driver implements SessionHandlerInterface { |
| 50 | |
| 51 | /** |
| 52 | * DB object |
| 53 | * |
| 54 | * @var object |
| 55 | */ |
| 56 | protected $_db; |
| 57 | |
| 58 | /** |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 59 | * Row exists flag |
| 60 | * |
| 61 | * @var bool |
| 62 | */ |
| 63 | protected $_row_exists = FALSE; |
| 64 | |
| 65 | /** |
| 66 | * Lock "driver" flag |
| 67 | * |
| 68 | * @var string |
| 69 | */ |
Andrey Andreev | e9ca012 | 2015-01-15 17:42:17 +0200 | [diff] [blame] | 70 | protected $_platform; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 71 | |
| 72 | // ------------------------------------------------------------------------ |
| 73 | |
| 74 | /** |
| 75 | * Class constructor |
| 76 | * |
| 77 | * @param array $params Configuration parameters |
| 78 | * @return void |
| 79 | */ |
| 80 | public function __construct(&$params) |
| 81 | { |
| 82 | parent::__construct($params); |
| 83 | |
| 84 | $CI =& get_instance(); |
| 85 | isset($CI->db) OR $CI->load->database(); |
Andrey Andreev | 00c222d | 2015-01-29 18:14:31 +0200 | [diff] [blame] | 86 | $this->_db = $CI->db; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 87 | |
| 88 | if ( ! $this->_db instanceof CI_DB_query_builder) |
| 89 | { |
| 90 | throw new Exception('Query Builder not enabled for the configured database. Aborting.'); |
| 91 | } |
| 92 | elseif ($this->_db->pconnect) |
| 93 | { |
| 94 | throw new Exception('Configured database connection is persistent. Aborting.'); |
| 95 | } |
| 96 | |
| 97 | $db_driver = $this->_db->dbdriver.(empty($this->_db->subdriver) ? '' : '_'.$this->_db->subdriver); |
| 98 | if (strpos($db_driver, 'mysql') !== FALSE) |
| 99 | { |
Andrey Andreev | e9ca012 | 2015-01-15 17:42:17 +0200 | [diff] [blame] | 100 | $this->_platform = 'mysql'; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 101 | } |
| 102 | elseif (in_array($db_driver, array('postgre', 'pdo_pgsql'), TRUE)) |
| 103 | { |
Andrey Andreev | e9ca012 | 2015-01-15 17:42:17 +0200 | [diff] [blame] | 104 | $this->_platform = 'postgre'; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 105 | } |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 106 | |
Andrey Andreev | 7f8eb36 | 2015-01-15 18:01:41 +0200 | [diff] [blame] | 107 | // Note: BC work-around for the old 'sess_table_name' setting, should be removed in the future. |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 108 | isset($this->_config['save_path']) OR $this->_config['save_path'] = config_item('sess_table_name'); |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | // ------------------------------------------------------------------------ |
| 112 | |
Andrey Andreev | 10411fc | 2015-01-19 13:54:53 +0200 | [diff] [blame] | 113 | /** |
| 114 | * Open |
| 115 | * |
| 116 | * Initializes the database connection |
| 117 | * |
| 118 | * @param string $save_path Table name |
| 119 | * @param string $name Session cookie name, unused |
| 120 | * @return bool |
| 121 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 122 | public function open($save_path, $name) |
| 123 | { |
| 124 | return empty($this->_db->conn_id) |
| 125 | ? ( ! $this->_db->autoinit && $this->_db->db_connect()) |
| 126 | : TRUE; |
| 127 | } |
| 128 | |
| 129 | // ------------------------------------------------------------------------ |
| 130 | |
Andrey Andreev | 10411fc | 2015-01-19 13:54:53 +0200 | [diff] [blame] | 131 | /** |
| 132 | * Read |
| 133 | * |
| 134 | * Reads session data and acquires a lock |
| 135 | * |
| 136 | * @param string $session_id Session ID |
| 137 | * @return string Serialized session data |
| 138 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 139 | public function read($session_id) |
| 140 | { |
Andrey Andreev | d069b9b | 2014-09-16 10:18:16 +0300 | [diff] [blame] | 141 | if ($this->_get_lock($session_id) !== FALSE) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 142 | { |
Andrey Andreev | 7474a67 | 2014-10-31 23:35:32 +0200 | [diff] [blame] | 143 | // Needed by write() to detect session_regenerate_id() calls |
| 144 | $this->_session_id = $session_id; |
| 145 | |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 146 | $this->_db |
| 147 | ->select('data') |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 148 | ->from($this->_config['save_path']) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 149 | ->where('id', $session_id); |
| 150 | |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 151 | if ($this->_config['match_ip']) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 152 | { |
| 153 | $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']); |
| 154 | } |
| 155 | |
| 156 | if (($result = $this->_db->get()->row()) === NULL) |
| 157 | { |
| 158 | $this->_fingerprint = md5(''); |
| 159 | return ''; |
| 160 | } |
| 161 | |
Andrey Andreev | e9ca012 | 2015-01-15 17:42:17 +0200 | [diff] [blame] | 162 | // PostgreSQL's variant of a BLOB datatype is Bytea, which is a |
| 163 | // PITA to work with, so we use base64-encoded data in a TEXT |
| 164 | // field instead. |
Andrey Andreev | d012255 | 2015-01-15 21:25:58 +0200 | [diff] [blame] | 165 | $result = ($this->_platform === 'postgre') |
| 166 | ? base64_decode(rtrim($result->data)) |
| 167 | : $result->data; |
Andrey Andreev | e9ca012 | 2015-01-15 17:42:17 +0200 | [diff] [blame] | 168 | |
Andrey Andreev | d012255 | 2015-01-15 21:25:58 +0200 | [diff] [blame] | 169 | $this->_fingerprint = md5($result); |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 170 | $this->_row_exists = TRUE; |
Andrey Andreev | 7400975 | 2015-01-15 21:36:25 +0200 | [diff] [blame] | 171 | return $result; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | $this->_fingerprint = md5(''); |
| 175 | return ''; |
| 176 | } |
| 177 | |
Andrey Andreev | 10411fc | 2015-01-19 13:54:53 +0200 | [diff] [blame] | 178 | // ------------------------------------------------------------------------ |
| 179 | |
| 180 | /** |
| 181 | * Write |
| 182 | * |
| 183 | * Writes (create / update) session data |
| 184 | * |
| 185 | * @param string $session_id Session ID |
| 186 | * @param string $session_data Serialized session data |
| 187 | * @return bool |
| 188 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 189 | public function write($session_id, $session_data) |
| 190 | { |
Andrey Andreev | 7474a67 | 2014-10-31 23:35:32 +0200 | [diff] [blame] | 191 | // Was the ID regenerated? |
Shakespeare2000 | 305186d | 2014-11-02 11:28:47 +0100 | [diff] [blame] | 192 | if ($session_id !== $this->_session_id) |
Andrey Andreev | 7474a67 | 2014-10-31 23:35:32 +0200 | [diff] [blame] | 193 | { |
| 194 | if ( ! $this->_release_lock() OR ! $this->_get_lock($session_id)) |
| 195 | { |
| 196 | return FALSE; |
| 197 | } |
| 198 | |
| 199 | $this->_row_exists = FALSE; |
| 200 | $this->_session_id = $session_id; |
| 201 | } |
Shakespeare2000 | 305186d | 2014-11-02 11:28:47 +0100 | [diff] [blame] | 202 | elseif ($this->_lock === FALSE) |
| 203 | { |
| 204 | return FALSE; |
| 205 | } |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 206 | |
| 207 | if ($this->_row_exists === FALSE) |
| 208 | { |
Andrey Andreev | 5231d32 | 2015-01-19 02:29:49 +0200 | [diff] [blame] | 209 | $insert_data = array( |
| 210 | 'id' => $session_id, |
| 211 | 'ip_address' => $_SERVER['REMOTE_ADDR'], |
| 212 | 'timestamp' => time(), |
| 213 | 'data' => ($this->_platform === 'postgre' ? base64_encode($session_data) : $session_data) |
| 214 | ); |
| 215 | |
| 216 | if ($this->_db->insert($this->_config['save_path'], $insert_data)) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 217 | { |
| 218 | $this->_fingerprint = md5($session_data); |
| 219 | return $this->_row_exists = TRUE; |
| 220 | } |
| 221 | |
| 222 | return FALSE; |
| 223 | } |
| 224 | |
| 225 | $this->_db->where('id', $session_id); |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 226 | if ($this->_config['match_ip']) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 227 | { |
| 228 | $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']); |
| 229 | } |
| 230 | |
Andrey Andreev | c33c3ad | 2015-01-19 10:54:21 +0200 | [diff] [blame] | 231 | $update_data = array('timestamp' => time()); |
Andrey Andreev | 5231d32 | 2015-01-19 02:29:49 +0200 | [diff] [blame] | 232 | if ($this->_fingerprint !== md5($session_data)) |
| 233 | { |
| 234 | $update_data['data'] = ($this->_platform === 'postgre') |
| 235 | ? base64_encode($session_data) |
| 236 | : $session_data; |
| 237 | } |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 238 | |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 239 | if ($this->_db->update($this->_config['save_path'], $update_data)) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 240 | { |
| 241 | $this->_fingerprint = md5($session_data); |
| 242 | return TRUE; |
| 243 | } |
| 244 | |
| 245 | return FALSE; |
| 246 | } |
| 247 | |
| 248 | // ------------------------------------------------------------------------ |
| 249 | |
Andrey Andreev | 10411fc | 2015-01-19 13:54:53 +0200 | [diff] [blame] | 250 | /** |
| 251 | * Close |
| 252 | * |
| 253 | * Releases locks |
| 254 | * |
Gabriel Potkány | 1fb5000 | 2015-02-04 01:45:59 +0100 | [diff] [blame^] | 255 | * @return bool |
Andrey Andreev | 10411fc | 2015-01-19 13:54:53 +0200 | [diff] [blame] | 256 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 257 | public function close() |
| 258 | { |
| 259 | return ($this->_lock) |
| 260 | ? $this->_release_lock() |
| 261 | : TRUE; |
| 262 | } |
| 263 | |
| 264 | // ------------------------------------------------------------------------ |
| 265 | |
Andrey Andreev | 10411fc | 2015-01-19 13:54:53 +0200 | [diff] [blame] | 266 | /** |
| 267 | * Destroy |
| 268 | * |
| 269 | * Destroys the current session. |
| 270 | * |
| 271 | * @param string $session_id Session ID |
| 272 | * @return bool |
| 273 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 274 | public function destroy($session_id) |
| 275 | { |
| 276 | if ($this->_lock) |
| 277 | { |
| 278 | $this->_db->where('id', $session_id); |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 279 | if ($this->_config['match_ip']) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 280 | { |
| 281 | $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']); |
| 282 | } |
| 283 | |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 284 | return $this->_db->delete($this->_config['save_path']) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 285 | ? ($this->close() && $this->_cookie_destroy()) |
| 286 | : FALSE; |
| 287 | } |
| 288 | |
| 289 | return ($this->close() && $this->_cookie_destroy()); |
| 290 | } |
| 291 | |
| 292 | // ------------------------------------------------------------------------ |
| 293 | |
Andrey Andreev | 10411fc | 2015-01-19 13:54:53 +0200 | [diff] [blame] | 294 | /** |
| 295 | * Garbage Collector |
| 296 | * |
| 297 | * Deletes expired sessions |
| 298 | * |
| 299 | * @param int $maxlifetime Maximum lifetime of sessions |
| 300 | * @return bool |
| 301 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 302 | public function gc($maxlifetime) |
| 303 | { |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 304 | return $this->_db->delete($this->_config['save_path'], 'timestamp < '.(time() - $maxlifetime)); |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | // ------------------------------------------------------------------------ |
| 308 | |
Andrey Andreev | 10411fc | 2015-01-19 13:54:53 +0200 | [diff] [blame] | 309 | /** |
| 310 | * Get lock |
| 311 | * |
| 312 | * Acquires a lock, depending on the underlying platform. |
| 313 | * |
| 314 | * @param string $session_id Session ID |
| 315 | * @return bool |
| 316 | */ |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 317 | protected function _get_lock($session_id) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 318 | { |
Andrey Andreev | e9ca012 | 2015-01-15 17:42:17 +0200 | [diff] [blame] | 319 | if ($this->_platform === 'mysql') |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 320 | { |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 321 | $arg = $session_id.($this->_config['match_ip'] ? '_'.$_SERVER['REMOTE_ADDR'] : ''); |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 322 | if ($this->_db->query("SELECT GET_LOCK('".$arg."', 10) AS ci_session_lock")->row()->ci_session_lock) |
| 323 | { |
| 324 | $this->_lock = $arg; |
| 325 | return TRUE; |
| 326 | } |
| 327 | |
| 328 | return FALSE; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 329 | } |
Andrey Andreev | e9ca012 | 2015-01-15 17:42:17 +0200 | [diff] [blame] | 330 | elseif ($this->_platform === 'postgre') |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 331 | { |
Andrey Andreev | dfb39be | 2014-10-06 01:50:14 +0300 | [diff] [blame] | 332 | $arg = "hashtext('".$session_id."')".($this->_config['match_ip'] ? ", hashtext('".$_SERVER['REMOTE_ADDR']."')" : ''); |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 333 | if ($this->_db->simple_query('SELECT pg_advisory_lock('.$arg.')')) |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 334 | { |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 335 | $this->_lock = $arg; |
| 336 | return TRUE; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 337 | } |
| 338 | |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 339 | return FALSE; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 340 | } |
| 341 | |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 342 | return parent::_get_lock($session_id); |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | // ------------------------------------------------------------------------ |
| 346 | |
Andrey Andreev | 10411fc | 2015-01-19 13:54:53 +0200 | [diff] [blame] | 347 | /** |
| 348 | * Release lock |
| 349 | * |
| 350 | * Releases a previously acquired lock |
| 351 | * |
| 352 | * @return bool |
| 353 | */ |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 354 | protected function _release_lock() |
| 355 | { |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 356 | if ( ! $this->_lock) |
| 357 | { |
| 358 | return TRUE; |
| 359 | } |
| 360 | |
Andrey Andreev | e9ca012 | 2015-01-15 17:42:17 +0200 | [diff] [blame] | 361 | if ($this->_platform === 'mysql') |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 362 | { |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 363 | if ($this->_db->query("SELECT RELEASE_LOCK('".$this->_lock."') AS ci_session_lock")->row()->ci_session_lock) |
| 364 | { |
| 365 | $this->_lock = FALSE; |
| 366 | return TRUE; |
| 367 | } |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 368 | |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 369 | return FALSE; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 370 | } |
Andrey Andreev | e9ca012 | 2015-01-15 17:42:17 +0200 | [diff] [blame] | 371 | elseif ($this->_platform === 'postgre') |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 372 | { |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 373 | if ($this->_db->simple_query('SELECT pg_advisory_unlock('.$this->_lock.')')) |
| 374 | { |
| 375 | $this->_lock = FALSE; |
| 376 | return TRUE; |
| 377 | } |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 378 | |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 379 | return FALSE; |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 380 | } |
| 381 | |
Andrey Andreev | 93d9fa7 | 2014-08-27 22:14:36 +0300 | [diff] [blame] | 382 | return parent::_release_lock(); |
Andrey Andreev | 47a47fb | 2014-05-31 16:08:30 +0300 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | } |