Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a fix for JobWatchers when the job payload is encrypted #1089

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/Watchers/JobWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
namespace Laravel\Telescope\Watchers;

use Illuminate\Bus\BatchRepository;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Queue;
use Illuminate\Support\Str;
use Laravel\Telescope\EntryType;
use Laravel\Telescope\EntryUpdate;
use Laravel\Telescope\ExceptionContext;
use Laravel\Telescope\ExtractProperties;
use Laravel\Telescope\ExtractTags;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use RuntimeException;

class JobWatcher extends Watcher
{
Expand Down Expand Up @@ -180,8 +183,10 @@ protected function tags(array $payload)
*/
protected function updateBatch($payload)
{
$command = $this->getCommand($payload['data']);

$properties = ExtractProperties::from(
unserialize($payload['data']['command'])
$command
);

if (isset($properties['batchId'])) {
Expand All @@ -196,4 +201,25 @@ protected function updateBatch($payload)
));
}
}

/**
* Get the command from the given payload.
*
* @param array $data
* @return mixed
*
* @throws \RuntimeException
*/
protected function getCommand(array $data)
{
if (Str::startsWith($data['command'], 'O:')) {
return unserialize($data['command']);
}

if (app()->bound(Encrypter::class)) {
return unserialize(app(Encrypter::class)->decrypt($data['command']));
}

throw new RuntimeException('Unable to extract job payload.');
}
}