From 4b51b585c08ee3c0b2eff547f07547357ec0657d Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Sun, 23 Jan 2011 22:21:04 -0500 Subject: [PATCH] Remove logging to a SQL backend - not usually a good use of a relational database, and could cause circular dependency problems. --- framework/Log/lib/Horde/Log/Handler/Db.php | 83 ------------------------ framework/Log/package.xml | 2 - framework/Log/test/Horde/Log/Handler/DbTest.php | 84 ------------------------- 3 files changed, 169 deletions(-) delete mode 100644 framework/Log/lib/Horde/Log/Handler/Db.php delete mode 100644 framework/Log/test/Horde/Log/Handler/DbTest.php diff --git a/framework/Log/lib/Horde/Log/Handler/Db.php b/framework/Log/lib/Horde/Log/Handler/Db.php deleted file mode 100644 index c3cff3d7a..000000000 --- a/framework/Log/lib/Horde/Log/Handler/Db.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://opensource.org/licenses/bsd-license.php BSD - * @package Log - * @subpackage Handlers - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://opensource.org/licenses/bsd-license.php BSD - * @package Log - * @subpackage Handlers - */ -class Horde_Log_Handler_Db extends Horde_Log_Handler_Base -{ - /** - * Database adapter instance. - * - * @var Horde_Db_Adapter - */ - private $_db; - - /** - * Name of the log table in the database. - * - * @var string - */ - private $_table; - - /** - * Options to be set by setOption(). - * Sets the field names in the database table. - * - * @var array - */ - protected $_options = array( - 'fieldMessage' => 'message', - 'fieldLevel' => 'level' - ); - - /** - * Constructor. - * - * @param Horde_Db_Adapter $db Database adapter instance. - * @param string $table Log table in database. - */ - public function __construct($db, $table) - { - $this->_db = $db; - $this->_table = $table; - } - - /** - * Write a message to the log. - * - * @param array $event Log event. - * - * @return bool True. - */ - public function write($event) - { - $fields = array( - $this->_options['fieldMessage'] => $event['message'], - $this->_options['fieldLevel'] => $event['level'], - ); - - $this->_db->insert($this->_table, $fields); - - return true; - } - -} diff --git a/framework/Log/package.xml b/framework/Log/package.xml index 3c807f909..160a5483d 100644 --- a/framework/Log/package.xml +++ b/framework/Log/package.xml @@ -50,7 +50,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -100,7 +99,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - diff --git a/framework/Log/test/Horde/Log/Handler/DbTest.php b/framework/Log/test/Horde/Log/Handler/DbTest.php deleted file mode 100644 index 61e7c2eba..000000000 --- a/framework/Log/test/Horde/Log/Handler/DbTest.php +++ /dev/null @@ -1,84 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://opensource.org/licenses/bsd-license.php BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://opensource.org/licenses/bsd-license.php BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Handler_DbTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->tableName = 'db-table-name'; - - $this->db = new Horde_Log_Handler_DbTest_MockDbAdapter(); - $this->handler = new Horde_Log_Handler_Db($this->db, $this->tableName); - } - - public function testWriteWithDefaults() - { - // log to the mock db adapter - $message = 'message-to-log'; - $level = 2; - $this->handler->write(array('message' => $message, 'level' => $level)); - - // insert should be called once... - $this->assertContains('insert', array_keys($this->db->calls)); - $this->assertEquals(1, count($this->db->calls['insert'])); - - // ...with the correct table and binds for the database - $binds = array('message' => $message, - 'level' => $level); - $this->assertEquals(array($this->tableName, $binds), - $this->db->calls['insert'][0]); - } - - public function testWriteUsesOptionalCustomColumns() - { - $this->handler->setOption('fieldMessage', $messageField = 'new-message-field'); - $this->handler->setOption('fieldLevel', $levelField = 'new-level-field'); - - // log to the mock db adapter - $message = 'message-to-log'; - $level = 2; - $this->handler->write(array('message' => $message, 'level' => $level)); - - // insert should be called once... - $this->assertContains('insert', array_keys($this->db->calls)); - $this->assertEquals(1, count($this->db->calls['insert'])); - - // ...with the correct table and binds for the database - $binds = array($messageField => $message, - $levelField => $level); - $this->assertEquals(array($this->tableName, $binds), - $this->db->calls['insert'][0]); - } -} - - -class Horde_Log_Handler_DbTest_MockDbAdapter -{ - public $calls = array(); - - public function __call($method, $params) - { - $this->calls[$method][] = $params; - } -} -- 2.11.0