Skip to content

Commit 5da0367

Browse files
committed
Merge branch 'master' into v4
2 parents 049a7da + 1817eab commit 5da0367

File tree

5 files changed

+57
-32
lines changed

5 files changed

+57
-32
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
4.1.4
2+
3+
- added support for a time property to the Request:add* apis, defaults to "current time - duration"
4+
- fixed crash when collecting console commands with array arguments or options in the Laravel integration (implemented by mortenscheel, thanks!)
5+
- fixed default storage directory being one level too deep in vanilla integration
6+
17
4.1.3
28

39
- fixed file storage not unlocking index when cleanup has nothing to clean (implemented by Nacoma, thanks!)

Clockwork/Clockwork.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Clockwork implements LoggerInterface
2121
/**
2222
* Clockwork version
2323
*/
24-
const VERSION = '4.1.3';
24+
const VERSION = '4.1.4';
2525

2626
/**
2727
* Array of data sources, these objects provide data to be stored in a request object
@@ -344,15 +344,17 @@ public function endEvent($name)
344344

345345
// Shortcut methods for the Request object
346346

347-
// Add database query, takes query, bindings, duration and additional data - connection (connection name), file
348-
// (caller file name), line (caller line number), trace (serialized trace), model (associated ORM model)
347+
// Add database query, takes query, bindings, duration (in ms) and additional data - connection (connection name),
348+
// time (when was the query executed), file (caller file name), line (caller line number), trace (serialized trace),
349+
// model (associated ORM model)
349350
public function addDatabaseQuery($query, $bindings = [], $duration = null, $data = [])
350351
{
351352
return $this->getRequest()->addDatabaseQuery($query, $bindings, $duration, $data);
352353
}
353354

354-
// Add cache query, takes type, key, value and additional data - connection (connection name), file
355-
// (caller file name), line (caller line number), trace (serialized trace), expiration
355+
// Add cache query, takes type, key, value, duration (in ms) and additional data - connection (connection name),
356+
// time (when was the query executed), file (caller file name), line (caller line number), trace (serialized trace),
357+
// expiration
356358
public function addCacheQuery($type, $key, $value = null, $duration = null, $data = [])
357359
{
358360
return $this->getRequest()->addCacheQuery($type, $key, $value, $duration, $data);
@@ -372,17 +374,18 @@ public function addRoute($method, $uri, $action, $data = [])
372374
return $this->getRequest()->addRoute($method, $uri, $action, $data);
373375
}
374376

375-
// Add route, takes method, uri, action and additional data - name, middleware, before (before filters), after
376-
// (after filters)
377-
public function addEmail($subject, $to, $from = null, $headers = [])
377+
// Add sent email, takes subject, recipient address, sender address, array of headers, and additional data - time
378+
// (when was the email sent), duration (sending time in ms)
379+
public function addEmail($subject, $to, $from = null, $headers = [], $data = [])
378380
{
379-
return $this->getRequest()->addEmail($subject, $to, $from, $headers);
381+
return $this->getRequest()->addEmail($subject, $to, $from, $headers, $data);
380382
}
381383

382-
// Add view, takes view name and data
383-
public function addView($name, $data = [])
384+
// Add view, takes view name, view data and additional data - time (when was the view rendered), duration (sending
385+
// time in ms)
386+
public function addView($name, $viewData = [], $data = [])
384387
{
385-
return $this->getRequest()->addView($name, $data);
388+
return $this->getRequest()->addView($name, $viewData, $data);
386389
}
387390

388391
// Add executed subrequest, takes the requested url, suvrequest Clockwork ID and additional data - path if non-default,

Clockwork/Request/Request.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,17 @@ public function toJson()
361361
return json_encode($this->toArray(), \JSON_PARTIAL_OUTPUT_ON_ERROR);
362362
}
363363

364-
// Add database query, takes query, bindings, duration and additional data - connection (connection name), file
365-
// (caller file name), line (caller line number), trace (serialized trace), model (associated ORM model)
364+
// Add database query, takes query, bindings, duration (in ms) and additional data - connection (connection name),
365+
// time (when was the query executed), file (caller file name), line (caller line number), trace (serialized trace),
366+
// model (associated ORM model)
366367
public function addDatabaseQuery($query, $bindings = [], $duration = null, $data = [])
367368
{
368369
$this->databaseQueries[] = [
369370
'query' => $query,
370371
'bindings' => (new Serializer)->normalize($bindings),
371372
'duration' => $duration,
372373
'connection' => isset($data['connection']) ? $data['connection'] : null,
374+
'time' => isset($data['time']) ? $data['time'] : microtime(true) - $duration / 1000,
373375
'file' => isset($data['file']) ? $data['file'] : null,
374376
'line' => isset($data['line']) ? $data['line'] : null,
375377
'trace' => isset($data['trace']) ? $data['trace'] : null,
@@ -380,8 +382,9 @@ public function addDatabaseQuery($query, $bindings = [], $duration = null, $data
380382
];
381383
}
382384

383-
// Add cache query, takes type, key, value and additional data - connection (connection name), file
384-
// (caller file name), line (caller line number), trace (serialized trace), expiration
385+
// Add cache query, takes type, key, value, duration (in ms) and additional data - connection (connection name),
386+
// time (when was the query executed), file (caller file name), line (caller line number), trace (serialized trace),
387+
// expiration
385388
public function addCacheQuery($type, $key, $value = null, $duration = null, $data = [])
386389
{
387390
$this->cacheQueries[] = [
@@ -390,6 +393,7 @@ public function addCacheQuery($type, $key, $value = null, $duration = null, $dat
390393
'value' => (new Serializer)->normalize($value),
391394
'duration' => $duration,
392395
'connection' => isset($data['connection']) ? $data['connection'] : null,
396+
'time' => isset($data['time']) ? $data['time'] : microtime(true) - $duration / 1000,
393397
'file' => isset($data['file']) ? $data['file'] : null,
394398
'line' => isset($data['line']) ? $data['line'] : null,
395399
'trace' => isset($data['trace']) ? $data['trace'] : null,
@@ -404,7 +408,7 @@ public function addEvent($event, $eventData = null, $time = null, $data = [])
404408
$this->events[] = [
405409
'event' => $event,
406410
'data' => (new Serializer)->normalize($eventData),
407-
'time' => $time,
411+
'time' => $time ?: microtime(true),
408412
'listeners' => isset($data['listeners']) ? $data['listeners'] : null,
409413
'file' => isset($data['file']) ? $data['file'] : null,
410414
'line' => isset($data['line']) ? $data['line'] : null,
@@ -427,12 +431,16 @@ public function addRoute($method, $uri, $action, $data = [])
427431
];
428432
}
429433

430-
// Add route, takes method, uri, action and additional data - name, middleware, before (before filters), after
431-
// (after filters)
432-
public function addEmail($subject, $to, $from = null, $headers = [])
434+
// Add sent email, takes subject, recipient address, sender address, array of headers, and additional data - time
435+
// (when was the email sent), duration (sending time in ms)
436+
public function addEmail($subject, $to, $from = null, $headers = [], $data = [])
433437
{
434438
$this->emailsData[] = [
435-
'data' => [
439+
'start' => isset($data['time']) ? $data['time'] : null,
440+
'end' => isset($data['time'], $data['duration']) ? $data['time'] + $data['duration'] / 1000 : null,
441+
'duration' => isset($data['duration']) ? $data['duration'] : null,
442+
'description' => 'Sending an email message',
443+
'data' => [
436444
'subject' => $subject,
437445
'to' => $to,
438446
'from' => $from,
@@ -441,13 +449,18 @@ public function addEmail($subject, $to, $from = null, $headers = [])
441449
];
442450
}
443451

444-
// Add view, takes view name and data
445-
public function addView($name, $data = [])
452+
// Add view, takes view name, view data and additional data - time (when was the view rendered), duration (sending
453+
// time in ms)
454+
public function addView($name, $viewData = [], $data = [])
446455
{
447456
$this->viewsData[] = [
448-
'data' => [
457+
'start' => isset($data['time']) ? $data['time'] : null,
458+
'end' => isset($data['time'], $data['duration']) ? $data['time'] + $data['duration'] / 1000 : null,
459+
'duration' => isset($data['duration']) ? $data['duration'] : null,
460+
'description' => 'Rendering a view',
461+
'data' => [
449462
'name' => $name,
450-
'data' => (new Serializer)->normalize($data)
463+
'data' => (new Serializer)->normalize($viewData)
451464
]
452465
];
453466
}

Clockwork/Support/Laravel/ClockworkSupport.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,20 @@ public function collectCommands()
142142

143143
$command = $this->app->make(ConsoleKernel::class)->all()[$event->command];
144144

145-
$argumentsDefaults = $command->getDefinition()->getArgumentDefaults();
146-
$optionsDefaults = $command->getDefinition()->getOptionDefaults();
145+
$allArguments = $event->input->getArguments();
146+
$allOptions = $event->input->getOptions();
147+
148+
$defaultArguments = $command->getDefinition()->getArgumentDefaults();
149+
$defaultOptions = $command->getDefinition()->getOptionDefaults();
147150

148151
$this->app->make('clockwork')
149152
->resolveAsCommand(
150153
$event->command,
151154
$event->exitCode,
152-
array_diff($event->input->getArguments(), $argumentsDefaults),
153-
array_diff($event->input->getOptions(), $optionsDefaults),
154-
$argumentsDefaults,
155-
$optionsDefaults,
155+
array_udiff_assoc($allArguments, $defaultArguments, function ($a, $b) { return $a == $b ? 0 : 1; }),
156+
array_udiff_assoc($allOptions, $defaultOptions, function ($a, $b) { return $a == $b ? 0 : 1; }),
157+
$defaultArguments,
158+
$defaultOptions,
156159
$this->getConfig('artisan.collect_output') ? $event->output->getFormatter()->capturedOutput() : null
157160
)
158161
->storeRequest();

Clockwork/Support/Vanilla/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
'storage' => isset($_ENV['CLOCKWORK_STORAGE']) ? $_ENV['CLOCKWORK_STORAGE'] : 'files',
6161

62-
'storage_files_path' => isset($_ENV['CLOCKWORK_STORAGE_FILES_PATH']) ? $_ENV['CLOCKWORK_STORAGE_FILES_PATH'] : __DIR__ . '/../../../../../clockwork',
62+
'storage_files_path' => isset($_ENV['CLOCKWORK_STORAGE_FILES_PATH']) ? $_ENV['CLOCKWORK_STORAGE_FILES_PATH'] : __DIR__ . '/../../../../../../clockwork',
6363

6464
// Compress the metadata files using gzip, trading a little bit of performance for lower disk usage
6565
'storage_files_compress' => isset($_ENV['CLOCKWORK_STORAGE_FILES_COMPRESS']) ? $_ENV['CLOCKWORK_STORAGE_FILES_COMPRESS'] : false,

0 commit comments

Comments
 (0)