Skip to content

Commit

Permalink
Fixed collecting of database queries in Laravel 5.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsgoingd committed Jan 7, 2016
1 parent b3f0cd7 commit f14f8e9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.10.1
- fixed collecting of database queries in Laravel 5.2 (thanks sebastiandedeyne)

1.10
- added Laravel 5.2 support (thanks jonphipps)
- improved file storage to allow configuring directory permissions (thanks patrick-radius)
Expand Down
34 changes: 26 additions & 8 deletions Clockwork/DataSource/EloquentDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,41 @@ public function __construct(DatabaseManager $databaseManager, EventDispatcher $e
*/
public function listenToEvents()
{
$this->eventDispatcher->listen('illuminate.query', array($this, 'registerQuery'));
if (class_exists('Illuminate\Database\Events\QueryExecuted')) {
// Laravel 5.2
$this->eventDispatcher->listen('Illuminate\Database\Events\QueryExecuted', array($this, 'registerQuery'));
} else {
// Laravel 4.0 to 5.1
$this->eventDispatcher->listen('illuminate.query', array($this, 'registerLegacyQuery'));
}
}

/**
* Log the query into the internal store
* @return array
*/
public function registerQuery($query, $bindings, $time, $connection)
public function registerQuery($event)
{
$this->queries[] = array(
'query' => $query,
'bindings' => $bindings,
'time' => $time,
'connection' => $connection
'query' => $event->sql,
'bindings' => $event->bindings,
'time' => $event->time,
'connection' => $event->connectionName
);
}

/**
* Log a legacy (pre Laravel 5.2) query into the internal store
*/
public function registerLegacyQuery($sql, $bindings, $time, $connection)
{
return $this->registerQuery((object) array(
'sql' => $sql,
'bindings' => $bindings,
'time' => $time,
'connectionName' => $connection
));
}

/**
* Adds ran database queries to the request
*/
Expand Down Expand Up @@ -104,4 +122,4 @@ protected function getDatabaseQueries()

return $queries;
}
}
}

0 comments on commit f14f8e9

Please sign in to comment.