Skip to content

Commit

Permalink
Merge branch '11.x' into on-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmastech authored Jan 18, 2025
2 parents fb9012f + ad20dd5 commit 6b22499
Show file tree
Hide file tree
Showing 24 changed files with 1,028 additions and 130 deletions.
3 changes: 3 additions & 0 deletions config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
'report' => false,
],

'public' => [
Expand All @@ -42,6 +43,7 @@
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
'report' => false,
],

's3' => [
Expand All @@ -54,6 +56,7 @@
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'report' => false,
],

],
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Bus/DatabaseBatchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function transaction(Closure $callback)
*/
public function rollBack()
{
$this->connection->rollBack();
$this->connection->rollBack(toLevel: 0);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Bus/UniqueLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function release($job)
* @param mixed $job
* @return string
*/
protected function getKey($job)
public static function getKey($job)
{
$uniqueId = method_exists($job, 'uniqueId')
? $job->uniqueId()
Expand Down
16 changes: 16 additions & 0 deletions src/Illuminate/Cache/LuaScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

class LuaScripts
{
/**
* Get the Lua script that sets a key only when it does not yet exist.
*
* KEYS[1] - The name of the key
* ARGV[1] - The value of the key
* ARGV[2] - The number of seconds the key should be valid
*
* @return string
*/
public static function add()
{
return <<<'LUA'
return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])
LUA;
}

/**
* Get the Lua script to atomically release a lock.
*
Expand Down
82 changes: 72 additions & 10 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ public function __construct(Redis $redis, $prefix = '', $connection = 'default')
*/
public function get($key)
{
$value = $this->connection()->get($this->prefix.$key);
$connection = $this->connection();

$value = $connection->get($this->prefix.$key);

return ! is_null($value) ? $this->unserialize($value) : null;
return ! is_null($value) ? $this->connectionAwareUnserialize($value, $connection) : null;
}

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

$results = [];

$values = $this->connection()->mget(array_map(function ($key) {
$connection = $this->connection();

$values = $connection->mget(array_map(function ($key) {
return $this->prefix.$key;
}, $keys));

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

return $results;
Expand All @@ -110,8 +114,10 @@ public function many(array $keys)
*/
public function put($key, $value, $seconds)
{
return (bool) $this->connection()->setex(
$this->prefix.$key, (int) max(1, $seconds), $this->serialize($value)
$connection = $this->connection();

return (bool) $connection->setex(
$this->prefix.$key, (int) max(1, $seconds), $this->connectionAwareSerialize($value, $connection)
);
}

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

return (bool) $this->connection()->eval(
$lua, 1, $this->prefix.$key, $this->serialize($value), (int) max(1, $seconds)
return (bool) $connection->eval(
LuaScripts::add(), 1, $this->prefix.$key, $this->pack($value, $connection), (int) max(1, $seconds)
);
}

Expand Down Expand Up @@ -205,7 +211,9 @@ public function decrement($key, $value = 1)
*/
public function forever($key, $value)
{
return (bool) $this->connection()->set($this->prefix.$key, $this->serialize($value));
$connection = $this->connection();

return (bool) $connection->set($this->prefix.$key, $this->connectionAwareSerialize($value, $connection));
}

/**
Expand Down Expand Up @@ -414,6 +422,28 @@ public function setPrefix($prefix)
$this->prefix = $prefix;
}

/**
* Prepare a value to be used with the Redis cache store when used by eval scripts.
*
* @param mixed $value
* @param \Illuminate\Redis\Connections\Connection $connection
* @return mixed
*/
protected function pack($value, $connection)
{
if ($connection instanceof PhpRedisConnection) {
if ($connection->serialized()) {
return $connection->pack([$value])[0];
}

if ($connection->compressed()) {
return $connection->pack([$this->serialize($value)])[0];
}
}

return $this->serialize($value);
}

/**
* Serialize the value.
*
Expand All @@ -435,4 +465,36 @@ protected function unserialize($value)
{
return is_numeric($value) ? $value : unserialize($value);
}

/**
* Handle connection specific considerations when a value needs to be serialized.
*
* @param mixed $value
* @param \Illuminate\Redis\Connections\Connection $connection
* @return mixed
*/
protected function connectionAwareSerialize($value, $connection)
{
if ($connection instanceof PhpRedisConnection && $connection->serialized()) {
return $value;
}

return $this->serialize($value);
}

/**
* Handle connection specific considerations when a value needs to be unserialized.
*
* @param mixed $value
* @param \Illuminate\Redis\Connections\Connection $connection
* @return mixed
*/
protected function connectionAwareUnserialize($value, $connection)
{
if ($connection instanceof PhpRedisConnection && $connection->serialized()) {
return $value;
}

return $this->unserialize($value);
}
}
50 changes: 50 additions & 0 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Illuminate\Filesystem;

use Closure;
use Illuminate\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystemContract;
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract;
use Illuminate\Http\File;
Expand Down Expand Up @@ -35,6 +37,7 @@
use Psr\Http\Message\StreamInterface;
use RuntimeException;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Throwable;

/**
* @mixin \League\Flysystem\FilesystemOperator
Expand Down Expand Up @@ -288,6 +291,8 @@ public function get($path)
return $this->driver->read($path);
} catch (UnableToReadFile $e) {
throw_if($this->throwsExceptions(), $e);

$this->report($e);
}
}

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

$this->report($e);

return false;
}

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

$this->report($e);

return false;
}

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

$this->report($e);

$success = false;
}
}
Expand All @@ -581,6 +592,8 @@ public function copy($from, $to)
} catch (UnableToCopyFile $e) {
throw_if($this->throwsExceptions(), $e);

$this->report($e);

return false;
}

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

$this->report($e);

return false;
}

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

$this->report($e);

return false;
}
}
Expand All @@ -648,6 +665,8 @@ public function mimeType($path)
return $this->driver->mimeType($path);
} catch (UnableToRetrieveMetadata $e) {
throw_if($this->throwsExceptions(), $e);

$this->report($e);
}

return false;
Expand All @@ -673,6 +692,8 @@ public function readStream($path)
return $this->driver->readStream($path);
} catch (UnableToReadFile $e) {
throw_if($this->throwsExceptions(), $e);

$this->report($e);
}
}

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

$this->report($e);

return false;
}

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

$this->report($e);

return false;
}

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

$this->report($e);

return false;
}

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

/**
* @param Throwable $exception
* @return void
*
* @throws Throwable
*/
protected function report($exception)
{
if ($this->shouldReport() && Container::getInstance()->bound(ExceptionHandler::class)) {
Container::getInstance()->make(ExceptionHandler::class)->report($exception);
}
}

/**
* Determine if Flysystem exceptions should be reported.
*
* @return bool
*/
protected function shouldReport(): bool
{
return (bool) ($this->config['report'] ?? false);
}

/**
* Pass dynamic methods call onto Flysystem.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Illuminate/Foundation/Bus/PendingDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Foundation\Bus\Attributes\OnConnection;
use Illuminate\Foundation\Bus\Attributes\OnQueue;
use Illuminate\Foundation\Queue\InteractsWithUniqueJobs;

class PendingDispatch
{
use InteractsWithUniqueJobs;

/**
* The job.
*
Expand Down Expand Up @@ -242,12 +245,18 @@ public function __call($method, $parameters)
*/
public function __destruct()
{
$this->addUniqueJobInformationToContext($this->job);

if (! $this->shouldDispatch()) {
$this->removeUniqueJobInformationFromContext($this->job);

return;
} elseif ($this->afterResponse) {
app(Dispatcher::class)->dispatchAfterResponse($this->job);
} else {
app(Dispatcher::class)->dispatch($this->job);
}

$this->removeUniqueJobInformationFromContext($this->job);
}
}
Loading

0 comments on commit 6b22499

Please sign in to comment.