Issues

ZF2-484: Log\Writer\Db not able to handle timestamp colum as datetime can't be converted to string

Description

The doWrite method of Log\Writer\Db currently doesn't handle the datetime object, so when the query is set to be manually built (something which should perhaps use the Sql insert class?) the datetime object cannot be converted to a string, and it errors out. Tested with sqlite, though perhaps not for mysql?

This poses an urgent problem of how the datetime is to be formatted for the user, should it be something like simply getTimestamp() on the datetime object, or formatted with date("r", ...) for example. The user should be able to choose.

See the two commented out lines below.


    protected function doWrite(array $event)
    {
        if (null === $this->db) {
            throw new Exception\RuntimeException('Database adapter is null');
        }

        // manually format timestamp
//        $event['timestamp'] = $event['timestamp']->getTimestamp();
//        $event['timestamp'] = date("r", $event['timestamp']->getTimestamp());

        // Transform the event array into fields
        if (null === $this->columnMap) {
            $dataToInsert = $this->eventIntoColumn($event);
        } else {
            $dataToInsert = $this->mapEventIntoColumn($event, $this->columnMap);
        }

        $statement = $this->db->query($this->prepareInsert($this->db, $this->tableName, $dataToInsert));
        $statement->execute($dataToInsert);

    }

Comments

Fixed on master