Skip to content

Commit 3234a8d

Browse files
committed
Merge branch '8.x'
2 parents 4e6e235 + 7d3151c commit 3234a8d

File tree

12 files changed

+191
-39
lines changed

12 files changed

+191
-39
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
"symfony/cache": "^6.0"
9595
},
9696
"provide": {
97-
"psr/container-implementation": "1.0"
97+
"psr/container-implementation": "1.0",
98+
"psr/simple-cache-implementation": "1.0"
9899
},
99100
"conflict": {
100101
"tightenco/collect": "<5.5.33"

src/Illuminate/Cache/composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"illuminate/macroable": "^9.0",
2121
"illuminate/support": "^9.0"
2222
},
23+
"provide": {
24+
"psr/simple-cache-implementation": "1.0"
25+
},
2326
"autoload": {
2427
"psr-4": {
2528
"Illuminate\\Cache\\": ""

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,24 @@ public function delete()
12611261
return true;
12621262
}
12631263

1264+
/**
1265+
* Delete the model from the database within a transaction.
1266+
*
1267+
* @return bool|null
1268+
*
1269+
* @throws \Throwable
1270+
*/
1271+
public function deleteOrFail()
1272+
{
1273+
if (! $this->exists) {
1274+
return false;
1275+
}
1276+
1277+
return $this->getConnection()->transaction(function () {
1278+
return $this->delete();
1279+
});
1280+
}
1281+
12641282
/**
12651283
* Force a hard delete on a soft deleted model.
12661284
*

src/Illuminate/Foundation/Console/ModelMakeCommand.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function handle()
5454
$this->input->setOption('seed', true);
5555
$this->input->setOption('migration', true);
5656
$this->input->setOption('controller', true);
57+
$this->input->setOption('policy', true);
5758
$this->input->setOption('resource', true);
5859
}
5960

@@ -72,6 +73,10 @@ public function handle()
7273
if ($this->option('controller') || $this->option('resource') || $this->option('api')) {
7374
$this->createController();
7475
}
76+
77+
if ($this->option('policy')) {
78+
$this->createPolicy();
79+
}
7580
}
7681

7782
/**
@@ -140,6 +145,21 @@ protected function createController()
140145
]));
141146
}
142147

148+
/**
149+
* Create a policy file for the model.
150+
*
151+
* @return void
152+
*/
153+
protected function createPolicy()
154+
{
155+
$policy = Str::studly(class_basename($this->argument('name')));
156+
157+
$this->call('make:policy', [
158+
'name' => "{$policy}Policy",
159+
'--model' => $this->qualifyClass($this->getNameInput()),
160+
]);
161+
}
162+
143163
/**
144164
* Get the stub file for the generator.
145165
*
@@ -184,12 +204,13 @@ protected function getDefaultNamespace($rootNamespace)
184204
protected function getOptions()
185205
{
186206
return [
187-
['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, and resource controller for the model'],
207+
['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, and resource controller for the model'],
188208
['controller', 'c', InputOption::VALUE_NONE, 'Create a new controller for the model'],
189209
['factory', 'f', InputOption::VALUE_NONE, 'Create a new factory for the model'],
190210
['force', null, InputOption::VALUE_NONE, 'Create the class even if the model already exists'],
191211
['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model'],
192-
['seed', 's', InputOption::VALUE_NONE, 'Create a new seeder file for the model'],
212+
['policy', null, InputOption::VALUE_NONE, 'Create a new policy for the model'],
213+
['seed', 's', InputOption::VALUE_NONE, 'Create a new seeder for the model'],
193214
['pivot', 'p', InputOption::VALUE_NONE, 'Indicates if the generated model should be a custom intermediate table model'],
194215
['resource', 'r', InputOption::VALUE_NONE, 'Indicates if the generated controller should be a resource controller'],
195216
['api', null, InputOption::VALUE_NONE, 'Indicates if the generated controller should be an API controller'],

src/Illuminate/Foundation/Console/stubs/maintenance-mode.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if (isset($_COOKIE['laravel_maintenance']) && isset($data['secret'])) {
4848
if (is_array($payload) &&
4949
is_numeric($payload['expires_at'] ?? null) &&
5050
isset($payload['mac']) &&
51-
hash_equals(hash_hmac('SHA256', $payload['expires_at'], $data['secret']), $payload['mac']) &&
51+
hash_equals(hash_hmac('sha256', $payload['expires_at'], $data['secret']), $payload['mac']) &&
5252
(int) $payload['expires_at'] >= time()) {
5353
return;
5454
}

src/Illuminate/Foundation/Http/MaintenanceModeBypassCookie.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function create(string $key)
1919

2020
return new Cookie('laravel_maintenance', base64_encode(json_encode([
2121
'expires_at' => $expiresAt->getTimestamp(),
22-
'mac' => hash_hmac('SHA256', $expiresAt->getTimestamp(), $key),
22+
'mac' => hash_hmac('sha256', $expiresAt->getTimestamp(), $key),
2323
])), $expiresAt);
2424
}
2525

@@ -37,7 +37,7 @@ public static function isValid(string $cookie, string $key)
3737
return is_array($payload) &&
3838
is_numeric($payload['expires_at'] ?? null) &&
3939
isset($payload['mac']) &&
40-
hash_equals(hash_hmac('SHA256', $payload['expires_at'], $key), $payload['mac']) &&
40+
hash_equals(hash_hmac('sha256', $payload['expires_at'], $key), $payload['mac']) &&
4141
(int) $payload['expires_at'] >= Carbon::now()->getTimestamp();
4242
}
4343
}

src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,36 @@ protected function assertSoftDeleted($table, array $data = [], $connection = nul
108108
return $this;
109109
}
110110

111+
/**
112+
* Assert the given model exists in the database.
113+
*
114+
* @param \Illuminate\Database\Eloquent\Model $model
115+
* @return $this
116+
*/
117+
protected function assertModelExists($model)
118+
{
119+
return $this->assertDatabaseHas(
120+
$model->getTable(),
121+
[$model->getKeyName() => $model->getKey()],
122+
$model->getConnectionName()
123+
);
124+
}
125+
126+
/**
127+
* Assert the given model does not exist in the database.
128+
*
129+
* @param \Illuminate\Database\Eloquent\Model $model
130+
* @return $this
131+
*/
132+
protected function assertModelMissing($model)
133+
{
134+
return $this->assertDatabaseMissing(
135+
$model->getTable(),
136+
[$model->getKeyName() => $model->getKey()],
137+
$model->getConnectionName()
138+
);
139+
}
140+
111141
/**
112142
* Determine if the argument is a soft deletable model.
113143
*

src/Illuminate/Log/LogManager.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function channel($channel = null)
9595
*/
9696
public function driver($driver = null)
9797
{
98-
return $this->get($driver ?? $this->getDefaultDriver());
98+
return $this->get($this->parseDriver($driver));
9999
}
100100

101101
/**
@@ -450,7 +450,7 @@ protected function configurationFor($name)
450450
/**
451451
* Get the default log driver name.
452452
*
453-
* @return string
453+
* @return string|null
454454
*/
455455
public function getDefaultDriver()
456456
{
@@ -490,13 +490,30 @@ public function extend($driver, Closure $callback)
490490
*/
491491
public function forgetChannel($driver = null)
492492
{
493-
$driver = $driver ?? $this->getDefaultDriver();
493+
$driver = $this->parseDriver($driver);
494494

495495
if (isset($this->channels[$driver])) {
496496
unset($this->channels[$driver]);
497497
}
498498
}
499499

500+
/**
501+
* Parse the driver name.
502+
*
503+
* @param string|null $driver
504+
* @return string|null
505+
*/
506+
protected function parseDriver($driver)
507+
{
508+
$driver = $driver ?? $this->getDefaultDriver();
509+
510+
if ($this->app->runningUnitTests()) {
511+
$driver = $driver ?? 'null';
512+
}
513+
514+
return $driver;
515+
}
516+
500517
/**
501518
* System is unusable.
502519
*

src/Illuminate/Queue/Queue.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ public function getJobBackoff($job)
189189
return;
190190
}
191191

192-
return collect(Arr::wrap($job->backoff ?? $job->backoff()))
192+
if (is_null($backoff = $job->backoff ?? $job->backoff())) {
193+
return;
194+
}
195+
196+
return collect(Arr::wrap($backoff))
193197
->map(function ($backoff) {
194198
return $backoff instanceof DateTimeInterface
195199
? $this->secondsUntil($backoff) : $backoff;

tests/Database/DatabaseSchemaBlueprintIntegrationTest.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,35 @@ protected function tearDown(): void
4343
Facade::setFacadeApplication(null);
4444
}
4545

46-
public function testRenamingAndChangingColumnsWork()
47-
{
48-
$this->db->connection()->getSchemaBuilder()->create('users', function ($table) {
49-
$table->string('name');
50-
$table->string('age');
51-
});
52-
53-
$blueprint = new Blueprint('users', function ($table) {
54-
$table->renameColumn('name', 'first_name');
55-
$table->integer('age')->change();
56-
});
57-
58-
$queries = $blueprint->toSql($this->db->connection(), new SQLiteGrammar);
59-
60-
$expected = [
61-
'CREATE TEMPORARY TABLE __temp__users AS SELECT name, age FROM users',
62-
'DROP TABLE users',
63-
'CREATE TABLE users (name VARCHAR(255) NOT NULL COLLATE BINARY, age INTEGER NOT NULL)',
64-
'INSERT INTO users (name, age) SELECT name, age FROM __temp__users',
65-
'DROP TABLE __temp__users',
66-
'CREATE TEMPORARY TABLE __temp__users AS SELECT name, age FROM users',
67-
'DROP TABLE users',
68-
'CREATE TABLE users (age VARCHAR(255) NOT NULL COLLATE BINARY, first_name VARCHAR(255) NOT NULL)',
69-
'INSERT INTO users (first_name, age) SELECT name, age FROM __temp__users',
70-
'DROP TABLE __temp__users',
71-
];
72-
73-
$this->assertEquals($expected, $queries);
74-
}
46+
// public function testRenamingAndChangingColumnsWork()
47+
// {
48+
// $this->db->connection()->getSchemaBuilder()->create('users', function ($table) {
49+
// $table->string('name');
50+
// $table->string('age');
51+
// });
52+
53+
// $blueprint = new Blueprint('users', function ($table) {
54+
// $table->renameColumn('name', 'first_name');
55+
// $table->integer('age')->change();
56+
// });
57+
58+
// $queries = $blueprint->toSql($this->db->connection(), new SQLiteGrammar);
59+
60+
// $expected = [
61+
// 'CREATE TEMPORARY TABLE __temp__users AS SELECT name, age FROM users',
62+
// 'DROP TABLE users',
63+
// 'CREATE TABLE users (name VARCHAR(255) NOT NULL COLLATE BINARY, age INTEGER NOT NULL)',
64+
// 'INSERT INTO users (name, age) SELECT name, age FROM __temp__users',
65+
// 'DROP TABLE __temp__users',
66+
// 'CREATE TEMPORARY TABLE __temp__users AS SELECT name, age FROM users',
67+
// 'DROP TABLE users',
68+
// 'CREATE TABLE users (age VARCHAR(255) NOT NULL COLLATE BINARY, first_name VARCHAR(255) NOT NULL)',
69+
// 'INSERT INTO users (first_name, age) SELECT name, age FROM __temp__users',
70+
// 'DROP TABLE __temp__users',
71+
// ];
72+
73+
// $this->assertEquals($expected, $queries);
74+
// }
7575

7676
public function testChangingColumnWithCollationWorks()
7777
{

0 commit comments

Comments
 (0)