Skip to content

Commit 6b22499

Browse files
authored
Merge branch '11.x' into on-queue
2 parents fb9012f + ad20dd5 commit 6b22499

24 files changed

+1028
-130
lines changed

config/filesystems.php

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'driver' => 'local',
3535
'root' => storage_path('app'),
3636
'throw' => false,
37+
'report' => false,
3738
],
3839

3940
'public' => [
@@ -42,6 +43,7 @@
4243
'url' => env('APP_URL').'/storage',
4344
'visibility' => 'public',
4445
'throw' => false,
46+
'report' => false,
4547
],
4648

4749
's3' => [
@@ -54,6 +56,7 @@
5456
'endpoint' => env('AWS_ENDPOINT'),
5557
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
5658
'throw' => false,
59+
'report' => false,
5760
],
5861

5962
],

src/Illuminate/Bus/DatabaseBatchRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public function transaction(Closure $callback)
319319
*/
320320
public function rollBack()
321321
{
322-
$this->connection->rollBack();
322+
$this->connection->rollBack(toLevel: 0);
323323
}
324324

325325
/**

src/Illuminate/Bus/UniqueLock.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function release($job)
6464
* @param mixed $job
6565
* @return string
6666
*/
67-
protected function getKey($job)
67+
public static function getKey($job)
6868
{
6969
$uniqueId = method_exists($job, 'uniqueId')
7070
? $job->uniqueId()

src/Illuminate/Cache/LuaScripts.php

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44

55
class LuaScripts
66
{
7+
/**
8+
* Get the Lua script that sets a key only when it does not yet exist.
9+
*
10+
* KEYS[1] - The name of the key
11+
* ARGV[1] - The value of the key
12+
* ARGV[2] - The number of seconds the key should be valid
13+
*
14+
* @return string
15+
*/
16+
public static function add()
17+
{
18+
return <<<'LUA'
19+
return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])
20+
LUA;
21+
}
22+
723
/**
824
* Get the Lua script to atomically release a lock.
925
*

src/Illuminate/Cache/RedisStore.php

+72-10
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ public function __construct(Redis $redis, $prefix = '', $connection = 'default')
6868
*/
6969
public function get($key)
7070
{
71-
$value = $this->connection()->get($this->prefix.$key);
71+
$connection = $this->connection();
72+
73+
$value = $connection->get($this->prefix.$key);
7274

73-
return ! is_null($value) ? $this->unserialize($value) : null;
75+
return ! is_null($value) ? $this->connectionAwareUnserialize($value, $connection) : null;
7476
}
7577

7678
/**
@@ -89,12 +91,14 @@ public function many(array $keys)
8991

9092
$results = [];
9193

92-
$values = $this->connection()->mget(array_map(function ($key) {
94+
$connection = $this->connection();
95+
96+
$values = $connection->mget(array_map(function ($key) {
9397
return $this->prefix.$key;
9498
}, $keys));
9599

96100
foreach ($values as $index => $value) {
97-
$results[$keys[$index]] = ! is_null($value) ? $this->unserialize($value) : null;
101+
$results[$keys[$index]] = ! is_null($value) ? $this->connectionAwareUnserialize($value, $connection) : null;
98102
}
99103

100104
return $results;
@@ -110,8 +114,10 @@ public function many(array $keys)
110114
*/
111115
public function put($key, $value, $seconds)
112116
{
113-
return (bool) $this->connection()->setex(
114-
$this->prefix.$key, (int) max(1, $seconds), $this->serialize($value)
117+
$connection = $this->connection();
118+
119+
return (bool) $connection->setex(
120+
$this->prefix.$key, (int) max(1, $seconds), $this->connectionAwareSerialize($value, $connection)
115121
);
116122
}
117123

@@ -165,10 +171,10 @@ public function putMany(array $values, $seconds)
165171
*/
166172
public function add($key, $value, $seconds)
167173
{
168-
$lua = "return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])";
174+
$connection = $this->connection();
169175

170-
return (bool) $this->connection()->eval(
171-
$lua, 1, $this->prefix.$key, $this->serialize($value), (int) max(1, $seconds)
176+
return (bool) $connection->eval(
177+
LuaScripts::add(), 1, $this->prefix.$key, $this->pack($value, $connection), (int) max(1, $seconds)
172178
);
173179
}
174180

@@ -205,7 +211,9 @@ public function decrement($key, $value = 1)
205211
*/
206212
public function forever($key, $value)
207213
{
208-
return (bool) $this->connection()->set($this->prefix.$key, $this->serialize($value));
214+
$connection = $this->connection();
215+
216+
return (bool) $connection->set($this->prefix.$key, $this->connectionAwareSerialize($value, $connection));
209217
}
210218

211219
/**
@@ -414,6 +422,28 @@ public function setPrefix($prefix)
414422
$this->prefix = $prefix;
415423
}
416424

425+
/**
426+
* Prepare a value to be used with the Redis cache store when used by eval scripts.
427+
*
428+
* @param mixed $value
429+
* @param \Illuminate\Redis\Connections\Connection $connection
430+
* @return mixed
431+
*/
432+
protected function pack($value, $connection)
433+
{
434+
if ($connection instanceof PhpRedisConnection) {
435+
if ($connection->serialized()) {
436+
return $connection->pack([$value])[0];
437+
}
438+
439+
if ($connection->compressed()) {
440+
return $connection->pack([$this->serialize($value)])[0];
441+
}
442+
}
443+
444+
return $this->serialize($value);
445+
}
446+
417447
/**
418448
* Serialize the value.
419449
*
@@ -435,4 +465,36 @@ protected function unserialize($value)
435465
{
436466
return is_numeric($value) ? $value : unserialize($value);
437467
}
468+
469+
/**
470+
* Handle connection specific considerations when a value needs to be serialized.
471+
*
472+
* @param mixed $value
473+
* @param \Illuminate\Redis\Connections\Connection $connection
474+
* @return mixed
475+
*/
476+
protected function connectionAwareSerialize($value, $connection)
477+
{
478+
if ($connection instanceof PhpRedisConnection && $connection->serialized()) {
479+
return $value;
480+
}
481+
482+
return $this->serialize($value);
483+
}
484+
485+
/**
486+
* Handle connection specific considerations when a value needs to be unserialized.
487+
*
488+
* @param mixed $value
489+
* @param \Illuminate\Redis\Connections\Connection $connection
490+
* @return mixed
491+
*/
492+
protected function connectionAwareUnserialize($value, $connection)
493+
{
494+
if ($connection instanceof PhpRedisConnection && $connection->serialized()) {
495+
return $value;
496+
}
497+
498+
return $this->unserialize($value);
499+
}
438500
}

src/Illuminate/Filesystem/FilesystemAdapter.php

+50
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Illuminate\Filesystem;
44

55
use Closure;
6+
use Illuminate\Container\Container;
7+
use Illuminate\Contracts\Debug\ExceptionHandler;
68
use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystemContract;
79
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract;
810
use Illuminate\Http\File;
@@ -35,6 +37,7 @@
3537
use Psr\Http\Message\StreamInterface;
3638
use RuntimeException;
3739
use Symfony\Component\HttpFoundation\StreamedResponse;
40+
use Throwable;
3841

3942
/**
4043
* @mixin \League\Flysystem\FilesystemOperator
@@ -288,6 +291,8 @@ public function get($path)
288291
return $this->driver->read($path);
289292
} catch (UnableToReadFile $e) {
290293
throw_if($this->throwsExceptions(), $e);
294+
295+
$this->report($e);
291296
}
292297
}
293298

@@ -417,6 +422,8 @@ public function put($path, $contents, $options = [])
417422
} catch (UnableToWriteFile|UnableToSetVisibility $e) {
418423
throw_if($this->throwsExceptions(), $e);
419424

425+
$this->report($e);
426+
420427
return false;
421428
}
422429

@@ -502,6 +509,8 @@ public function setVisibility($path, $visibility)
502509
} catch (UnableToSetVisibility $e) {
503510
throw_if($this->throwsExceptions(), $e);
504511

512+
$this->report($e);
513+
505514
return false;
506515
}
507516

@@ -560,6 +569,8 @@ public function delete($paths)
560569
} catch (UnableToDeleteFile $e) {
561570
throw_if($this->throwsExceptions(), $e);
562571

572+
$this->report($e);
573+
563574
$success = false;
564575
}
565576
}
@@ -581,6 +592,8 @@ public function copy($from, $to)
581592
} catch (UnableToCopyFile $e) {
582593
throw_if($this->throwsExceptions(), $e);
583594

595+
$this->report($e);
596+
584597
return false;
585598
}
586599

@@ -601,6 +614,8 @@ public function move($from, $to)
601614
} catch (UnableToMoveFile $e) {
602615
throw_if($this->throwsExceptions(), $e);
603616

617+
$this->report($e);
618+
604619
return false;
605620
}
606621

@@ -632,6 +647,8 @@ public function checksum(string $path, array $options = [])
632647
} catch (UnableToProvideChecksum $e) {
633648
throw_if($this->throwsExceptions(), $e);
634649

650+
$this->report($e);
651+
635652
return false;
636653
}
637654
}
@@ -648,6 +665,8 @@ public function mimeType($path)
648665
return $this->driver->mimeType($path);
649666
} catch (UnableToRetrieveMetadata $e) {
650667
throw_if($this->throwsExceptions(), $e);
668+
669+
$this->report($e);
651670
}
652671

653672
return false;
@@ -673,6 +692,8 @@ public function readStream($path)
673692
return $this->driver->readStream($path);
674693
} catch (UnableToReadFile $e) {
675694
throw_if($this->throwsExceptions(), $e);
695+
696+
$this->report($e);
676697
}
677698
}
678699

@@ -686,6 +707,8 @@ public function writeStream($path, $resource, array $options = [])
686707
} catch (UnableToWriteFile|UnableToSetVisibility $e) {
687708
throw_if($this->throwsExceptions(), $e);
688709

710+
$this->report($e);
711+
689712
return false;
690713
}
691714

@@ -918,6 +941,8 @@ public function makeDirectory($path)
918941
} catch (UnableToCreateDirectory|UnableToSetVisibility $e) {
919942
throw_if($this->throwsExceptions(), $e);
920943

944+
$this->report($e);
945+
921946
return false;
922947
}
923948

@@ -937,6 +962,8 @@ public function deleteDirectory($directory)
937962
} catch (UnableToDeleteDirectory $e) {
938963
throw_if($this->throwsExceptions(), $e);
939964

965+
$this->report($e);
966+
940967
return false;
941968
}
942969

@@ -1026,6 +1053,29 @@ protected function throwsExceptions(): bool
10261053
return (bool) ($this->config['throw'] ?? false);
10271054
}
10281055

1056+
/**
1057+
* @param Throwable $exception
1058+
* @return void
1059+
*
1060+
* @throws Throwable
1061+
*/
1062+
protected function report($exception)
1063+
{
1064+
if ($this->shouldReport() && Container::getInstance()->bound(ExceptionHandler::class)) {
1065+
Container::getInstance()->make(ExceptionHandler::class)->report($exception);
1066+
}
1067+
}
1068+
1069+
/**
1070+
* Determine if Flysystem exceptions should be reported.
1071+
*
1072+
* @return bool
1073+
*/
1074+
protected function shouldReport(): bool
1075+
{
1076+
return (bool) ($this->config['report'] ?? false);
1077+
}
1078+
10291079
/**
10301080
* Pass dynamic methods call onto Flysystem.
10311081
*

src/Illuminate/Foundation/Bus/PendingDispatch.php

+9
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
use Illuminate\Contracts\Queue\ShouldBeUnique;
1010
use Illuminate\Foundation\Bus\Attributes\OnConnection;
1111
use Illuminate\Foundation\Bus\Attributes\OnQueue;
12+
use Illuminate\Foundation\Queue\InteractsWithUniqueJobs;
1213

1314
class PendingDispatch
1415
{
16+
use InteractsWithUniqueJobs;
17+
1518
/**
1619
* The job.
1720
*
@@ -242,12 +245,18 @@ public function __call($method, $parameters)
242245
*/
243246
public function __destruct()
244247
{
248+
$this->addUniqueJobInformationToContext($this->job);
249+
245250
if (! $this->shouldDispatch()) {
251+
$this->removeUniqueJobInformationFromContext($this->job);
252+
246253
return;
247254
} elseif ($this->afterResponse) {
248255
app(Dispatcher::class)->dispatchAfterResponse($this->job);
249256
} else {
250257
app(Dispatcher::class)->dispatch($this->job);
251258
}
259+
260+
$this->removeUniqueJobInformationFromContext($this->job);
252261
}
253262
}

0 commit comments

Comments
 (0)