Passed
Push — master ( d021a5...a13070 )
by Sam
03:47 queued 12s
created

DbLogRoute::createLogTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
/**
4
 * Database log route. We override parent in order to change the "logtime" 
5
 * column to a DATETIME which makes filtering feasible.
6
 *
7
 * @author Sam Stenvall <[email protected]>
8
 * @copyright Copyright &copy; Sam Stenvall 2013-
9
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
10
 */
11
class DbLogRoute extends CDbLogRoute
12
{
13
14
	protected function createLogTable($db, $tableName)
15
	{
16
		$db->createCommand()->createTable($tableName, array(
17
			'id'=>'pk',
18
			'level'=>'varchar(128)',
19
			'category'=>'varchar(128)',
20
			'logtime'=>'datetime',
21
			'message'=>'text',
22
			'source_address'=>'varchar(45)',
23
		));
24
	}
25
26
	protected function processLogs($logs)
27
	{
28
		$command = $this->getDbConnection()->createCommand();
29
		foreach ($logs as $log)
30
		{
31
			$command->insert($this->logTableName, array(
32
				'level'=>$log[1],
33
				'category'=>$log[2],
34
				'logtime'=>date('Y-m-d H:i:s', (int)$log[3]),
35
				'message'=>$log[0],
36
				'source_address'=>$_SERVER['REMOTE_ADDR'],
37
			));
38
		}
39
	}
40
41
}