|
1 |
<?php
|
|
2 |
|
|
3 |
/**
|
|
4 |
* This file is part of the OpenPNE package.
|
|
5 |
* (c) OpenPNE Project (http://www.openpne.jp/)
|
|
6 |
*
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
8 |
* file and the NOTICE file that were distributed with this source code.
|
|
9 |
*/
|
|
10 |
|
|
11 |
class alterTableSession048 extends opMigration
|
|
12 |
{
|
|
13 |
public function up()
|
|
14 |
{
|
|
15 |
$conn = Doctrine_Manager::connection();
|
|
16 |
|
|
17 |
$conn->execute('ALTER TABLE session CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin');
|
|
18 |
$conn->execute('ALTER TABLE session MODIFY COLUMN `id` varbinary(128) NOT NULL DEFAULT \'\'');
|
|
19 |
$conn->execute('ALTER TABLE session MODIFY COLUMN `session_data` blob NOT NULL COMMENT \'Session information\'');
|
|
20 |
$conn->execute('ALTER TABLE session MODIFY COLUMN `time` int(10) unsigned NOT NULL COMMENT \'Timestamp\'');
|
|
21 |
$columns = $conn->import->listTableColumns('session');
|
|
22 |
if (isset($columns['session_lifetime']))
|
|
23 |
{
|
|
24 |
return;
|
|
25 |
}
|
|
26 |
|
|
27 |
$conn->execute('ALTER TABLE session ADD COLUMN `session_lifetime` mediumint(9) NOT NULL COMMENT \'Lifetime\'');
|
|
28 |
}
|
|
29 |
|
|
30 |
public function postUp()
|
|
31 |
{
|
|
32 |
$time = (int) time();
|
|
33 |
$lifetime = (int) ini_get('session.gc_maxlifetime');
|
|
34 |
$count = Doctrine::getTable('Session')->createQuery()
|
|
35 |
->delete()
|
|
36 |
->where('time < ? - ?', array($time, $lifetime))
|
|
37 |
->execute();
|
|
38 |
$this->log(sprintf('DELETED %d sessions', $count));
|
|
39 |
|
|
40 |
$count = Doctrine::getTable('Session')->createQuery()
|
|
41 |
->update()
|
|
42 |
->set('session_lifetime', 'time + ? - ?', array($lifetime, $time))
|
|
43 |
->set('time', '?', $time)
|
|
44 |
->execute();
|
|
45 |
$this->log(sprintf('UPDATED %d sessions', $count));
|
|
46 |
}
|
|
47 |
|
|
48 |
public function log($str)
|
|
49 |
{
|
|
50 |
printf('[%s] %s%s', date('Y-m-d H:i:s'), $str, PHP_EOL);
|
|
51 |
}
|
|
52 |
}
|
0 |
|
-
|