Skip to content

Commit 1baab99

Browse files
committed
Add runtime fallback for Tools Time->duration() method
The duration() method is specific to the Tools TimeHelper. Applications not using the Tools plugin would get a fatal error. This adds a method_exists check with a fallback to PHP's DateInterval::format(). Port of #462 to master.
1 parent 32de0da commit 1baab99

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

templates/Admin/QueuedJobs/index.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@
101101
<?php if ($queuedJob->completed) { ?>
102102
<div>
103103
<small><?php
104-
echo '<span title="Duration">' . $this->Time->duration($queuedJob->completed->diff($queuedJob->fetched)) . '</span>';
104+
$interval = $queuedJob->completed->diff($queuedJob->fetched);
105+
$duration = method_exists($this->Time, 'duration')
106+
? $this->Time->duration($interval)
107+
: ltrim($interval->format('%H:%I:%S'), '0:');
108+
echo '<span title="Duration">' . $duration . '</span>';
105109
?></small>
106110
</div>
107111
<?php } ?>

templates/Admin/QueuedJobs/view.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@
6161
<td>
6262
<?= $this->Time->nice($queuedJob->fetched) ?>
6363
<?php if ($queuedJob->fetched) {
64+
$interval = $queuedJob->fetched->diff($queuedJob->created);
65+
$duration = method_exists($this->Time, 'duration')
66+
? $this->Time->duration($interval)
67+
: ltrim($interval->format('%H:%I:%S'), '0:');
6468
echo '<div><small>';
65-
echo __d('queue', 'Delay') . ': ' . $this->Time->duration($queuedJob->fetched->diff($queuedJob->created));
69+
echo __d('queue', 'Delay') . ': ' . $duration;
6670
echo '</small></div>';
6771
} ?>
6872
</td>
@@ -72,8 +76,12 @@
7276
<td>
7377
<?= $this->element('Queue.ok', ['value' => $this->Time->nice($queuedJob->completed), 'ok' => (bool)$queuedJob->completed]) ?>
7478
<?php if ($queuedJob->completed) {
79+
$interval = $queuedJob->completed->diff($queuedJob->fetched);
80+
$duration = method_exists($this->Time, 'duration')
81+
? $this->Time->duration($interval)
82+
: ltrim($interval->format('%H:%I:%S'), '0:');
7583
echo '<div><small>';
76-
echo __d('queue', 'Duration') . ': ' . $this->Time->duration($queuedJob->completed->diff($queuedJob->fetched));
84+
echo __d('queue', 'Duration') . ': ' . $duration;
7785
echo '</small></div>';
7886
} ?>
7987
</td>

0 commit comments

Comments
 (0)