プロジェクト

全般

プロフィール

Enhancement(機能追加・改善) #3836 » 0001-refs-3836-Alter-session-table-colmuns.patch

Shinichi Urabe, 2015-09-05 03:50

差分を表示:

config/doctrine/schema.yml
Session:
actAs: []
columns:
id: { type: string(128), primary: true }
session_data: { type: string, comment: "Session information" }
time: { type: string, comment: "Timestamp of generated time" }
id: { type: varbinary(128), notnull: true, primary: true }
session_data: { type: blob(65532), notnull: true, comment: "Session information" }
time: { type: integer(4), unsigned: true, notnull: true, comment: "Timestamp" }
session_lifetime: { type: integer(3), notnull: true, comment: "Lifetime" }
options:
type: INNODB
collate: utf8_unicode_ci
collate: utf8_bin
charset: utf8
comment: "Saves session data"
data/fixtures/000_revision.yml
SnsConfig:
current_revision:
name: "OpenPNE_revision"
value: 47
value: 48
data/migrations/048_alter_table_session.php
<?php
/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/
class alterTableSession048 extends opMigration
{
public function up()
{
$conn = Doctrine_Manager::connection();
$conn->execute('ALTER TABLE session CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin');
$conn->execute('ALTER TABLE session MODIFY COLUMN `id` varbinary(128) NOT NULL DEFAULT \'\'');
$conn->execute('ALTER TABLE session MODIFY COLUMN `session_data` blob NOT NULL COMMENT \'Session information\'');
$conn->execute('ALTER TABLE session MODIFY COLUMN `time` int(10) unsigned NOT NULL COMMENT \'Timestamp\'');
$columns = $conn->import->listTableColumns('session');
if (isset($columns['session_lifetime']))
{
return;
}
$conn->execute('ALTER TABLE session ADD COLUMN `session_lifetime` mediumint(9) NOT NULL COMMENT \'Lifetime\'');
}
public function postUp()
{
$time = (int) time();
$lifetime = (int) ini_get('session.gc_maxlifetime');
$count = Doctrine::getTable('Session')->createQuery()
->delete()
->where('time < ? - ?', array($time, $lifetime))
->execute();
$this->log(sprintf('DELETED %d sessions', $count));
$count = Doctrine::getTable('Session')->createQuery()
->update()
->set('session_lifetime', 'time + ? - ?', array($lifetime, $time))
->set('time', '?', $time)
->execute();
$this->log(sprintf('UPDATED %d sessions', $count));
}
public function log($str)
{
printf('[%s] %s%s', date('Y-m-d H:i:s'), $str, PHP_EOL);
}
}
(1-1/2)