Skip to content

Commit 32b1336

Browse files
Merge branch '9.x'
2 parents c3744b2 + 93ed7f4 commit 32b1336

File tree

135 files changed

+4721
-524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+4721
-524
lines changed

.github/workflows/databases.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]
44

55
jobs:
66
mysql_57:
7-
runs-on: ubuntu-20.04
7+
runs-on: ubuntu-22.04
88

99
services:
1010
mysql:
@@ -47,7 +47,7 @@ jobs:
4747
DB_USERNAME: root
4848

4949
mysql_8:
50-
runs-on: ubuntu-20.04
50+
runs-on: ubuntu-22.04
5151

5252
services:
5353
mysql:
@@ -90,7 +90,7 @@ jobs:
9090
DB_USERNAME: root
9191

9292
mariadb:
93-
runs-on: ubuntu-20.04
93+
runs-on: ubuntu-22.04
9494

9595
services:
9696
mysql:
@@ -133,7 +133,7 @@ jobs:
133133
DB_USERNAME: root
134134

135135
pgsql:
136-
runs-on: ubuntu-20.04
136+
runs-on: ubuntu-22.04
137137

138138
services:
139139
postgresql:
@@ -201,7 +201,7 @@ jobs:
201201
uses: shivammathur/setup-php@v2
202202
with:
203203
php-version: 8.1
204-
extensions: dom, curl, libxml, mbstring, zip, pcntl, sqlsrv, pdo, pdo_sqlsrv
204+
extensions: dom, curl, libxml, mbstring, zip, pcntl, sqlsrv, pdo, pdo_sqlsrv, odbc, pdo_odbc
205205
tools: composer:v2
206206
coverage: none
207207

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
src:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-22.04
1212

1313
strategy:
1414
fail-fast: true

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
linux_tests:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-22.04
1212

1313
services:
1414
memcached:

.styleci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
php:
22
preset: laravel
33
version: 8.1
4+
finder:
5+
not-name:
6+
- bad-syntax-strategy.php
47
js:
58
finder:
69
not-name:

src/Illuminate/Broadcasting/BroadcastManager.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
use Illuminate\Broadcasting\Broadcasters\NullBroadcaster;
1111
use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster;
1212
use Illuminate\Broadcasting\Broadcasters\RedisBroadcaster;
13+
use Illuminate\Bus\UniqueLock;
1314
use Illuminate\Contracts\Broadcasting\Factory as FactoryContract;
15+
use Illuminate\Contracts\Broadcasting\ShouldBeUnique;
1416
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
1517
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcherContract;
18+
use Illuminate\Contracts\Cache\Repository as Cache;
1619
use Illuminate\Contracts\Foundation\CachesRoutes;
1720
use InvalidArgumentException;
1821
use Psr\Log\LoggerInterface;
@@ -165,9 +168,34 @@ public function queue($event)
165168
$queue = $event->queue;
166169
}
167170

168-
$this->app->make('queue')->connection($event->connection ?? null)->pushOn(
169-
$queue, new BroadcastEvent(clone $event)
170-
);
171+
$broadcastEvent = new BroadcastEvent(clone $event);
172+
173+
if ($event instanceof ShouldBeUnique) {
174+
$broadcastEvent = new UniqueBroadcastEvent(clone $event);
175+
176+
if ($this->mustBeUniqueAndCannotAcquireLock($broadcastEvent)) {
177+
return;
178+
}
179+
}
180+
181+
$this->app->make('queue')
182+
->connection($event->connection ?? null)
183+
->pushOn($queue, $broadcastEvent);
184+
}
185+
186+
/**
187+
* Determine if the broadcastable event must be unique and determine if we can acquire the necessary lock.
188+
*
189+
* @param mixed $event
190+
* @return bool
191+
*/
192+
protected function mustBeUniqueAndCannotAcquireLock($event)
193+
{
194+
return ! (new UniqueLock(
195+
method_exists($event, 'uniqueVia')
196+
? $event->uniqueVia()
197+
: $this->app->make(Cache::class)
198+
))->acquire($event);
171199
}
172200

173201
/**
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Illuminate\Broadcasting;
4+
5+
use Illuminate\Container\Container;
6+
use Illuminate\Contracts\Cache\Repository;
7+
use Illuminate\Contracts\Queue\ShouldBeUnique;
8+
9+
class UniqueBroadcastEvent extends BroadcastEvent implements ShouldBeUnique
10+
{
11+
/**
12+
* The unique lock identifier.
13+
*
14+
* @var mixed
15+
*/
16+
public $uniqueId;
17+
18+
/**
19+
* The number of seconds the unique lock should be maintained.
20+
*
21+
* @var int
22+
*/
23+
public $uniqueFor;
24+
25+
/**
26+
* Create a new event instance.
27+
*
28+
* @param mixed $event
29+
* @return void
30+
*/
31+
public function __construct($event)
32+
{
33+
$this->uniqueId = get_class($event);
34+
35+
if (method_exists($event, 'uniqueId')) {
36+
$this->uniqueId .= $event->uniqueId();
37+
} elseif (property_exists($event, 'uniqueId')) {
38+
$this->uniqueId .= $event->uniqueId;
39+
}
40+
41+
if (method_exists($event, 'uniqueFor')) {
42+
$this->uniqueFor = $event->uniqueFor();
43+
} elseif (property_exists($event, 'uniqueFor')) {
44+
$this->uniqueFor = $event->uniqueFor;
45+
}
46+
47+
parent::__construct($event);
48+
}
49+
50+
/**
51+
* Resolve the cache implementation that should manage the event's uniqueness.
52+
*
53+
* @return \Illuminate\Contracts\Cache\Repository
54+
*/
55+
public function uniqueVia()
56+
{
57+
return method_exists($this->event, 'uniqueVia')
58+
? $this->event->uniqueVia()
59+
: Container::getInstance()->make(Repository::class);
60+
}
61+
}

src/Illuminate/Broadcasting/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"psr/log": "^1.0|^2.0|^3.0",
2020
"illuminate/bus": "^10.0",
2121
"illuminate/collections": "^10.0",
22+
"illuminate/container": "^10.0",
2223
"illuminate/contracts": "^10.0",
2324
"illuminate/queue": "^10.0",
2425
"illuminate/support": "^10.0"

src/Illuminate/Bus/DatabaseBatchRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function get($limit = 50, $before = null)
7676
public function find(string $batchId)
7777
{
7878
$batch = $this->connection->table($this->table)
79+
->useWritePdo()
7980
->where('id', $batchId)
8081
->first();
8182

src/Illuminate/Bus/UniqueLock.php

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public function __construct(Cache $cache)
3232
*/
3333
public function acquire($job)
3434
{
35-
$uniqueId = method_exists($job, 'uniqueId')
36-
? $job->uniqueId()
37-
: ($job->uniqueId ?? '');
38-
3935
$uniqueFor = method_exists($job, 'uniqueFor')
4036
? $job->uniqueFor()
4137
: ($job->uniqueFor ?? 0);
@@ -44,9 +40,36 @@ public function acquire($job)
4440
? $job->uniqueVia()
4541
: $this->cache;
4642

47-
return (bool) $cache->lock(
48-
$key = 'laravel_unique_job:'.get_class($job).$uniqueId,
49-
$uniqueFor
50-
)->get();
43+
return (bool) $cache->lock($this->getKey($job), $uniqueFor)->get();
44+
}
45+
46+
/**
47+
* Release the lock for the given job.
48+
*
49+
* @param mixed $job
50+
* @return void
51+
*/
52+
public function release($job)
53+
{
54+
$cache = method_exists($job, 'uniqueVia')
55+
? $job->uniqueVia()
56+
: $this->cache;
57+
58+
$cache->lock($this->getKey($job))->forceRelease();
59+
}
60+
61+
/**
62+
* Generate the lock key for the given job.
63+
*
64+
* @param mixed $job
65+
* @return string
66+
*/
67+
protected function getKey($job)
68+
{
69+
$uniqueId = method_exists($job, 'uniqueId')
70+
? $job->uniqueId()
71+
: ($job->uniqueId ?? '');
72+
73+
return 'laravel_unique_job:'.get_class($job).$uniqueId;
5174
}
5275
}

src/Illuminate/Collections/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ protected function sortByMany(array $comparisons = [])
13671367
{
13681368
$items = $this->items;
13691369

1370-
usort($items, function ($a, $b) use ($comparisons) {
1370+
uasort($items, function ($a, $b) use ($comparisons) {
13711371
foreach ($comparisons as $comparison) {
13721372
$comparison = Arr::wrap($comparison);
13731373

0 commit comments

Comments
 (0)