Skip to content

Commit a54d0df

Browse files
authored
Merge branch 'laravel:9.x' into 9.x
2 parents c72d8d4 + 0f1eb9e commit a54d0df

Some content is hidden

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

42 files changed

+748
-154
lines changed

.github/workflows/databases.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ jobs:
213213
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
214214

215215
- name: Execute tests
216-
run: vendor/bin/phpunit tests/Integration/Database --verbose --exclude-group SkipMSSQL
216+
run: vendor/bin/phpunit tests/Integration/Database --verbose
217217
env:
218218
DB_CONNECTION: sqlsrv
219219
DB_DATABASE: master

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
uses: shivammathur/setup-php@v2
5050
with:
5151
php-version: ${{ matrix.php }}
52-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis-phpredis/[email protected], igbinary, msgpack, lzf, zstd, lz4, memcached
52+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis-phpredis/[email protected], igbinary, msgpack, lzf, zstd, lz4, memcached, gmp
5353
ini-values: error_reporting=E_ALL
5454
tools: composer:v2
5555
coverage: none
@@ -122,7 +122,7 @@ jobs:
122122
uses: shivammathur/setup-php@v2
123123
with:
124124
php-version: ${{ matrix.php }}
125-
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, pdo_mysql, fileinfo, ftp, redis, memcached
125+
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, pdo_mysql, fileinfo, ftp, redis, memcached, gmp
126126
tools: composer:v2
127127
coverage: none
128128

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
# Release Notes for 9.x
22

3-
## [Unreleased](https://github.com/laravel/framework/compare/v9.26.1...9.x)
3+
## [Unreleased](https://github.com/laravel/framework/compare/v9.27.0...9.x)
4+
5+
6+
## [v9.27.0](https://github.com/laravel/framework/compare/v9.26.1...v9.27.0) - 2022-08-30
7+
8+
### Added
9+
- Add getter and setter for connection in the DatabaseBatchRepository class ([#43869](https://github.com/laravel/framework/pull/43869))
10+
11+
### Fixed
12+
- Fix for potential bug with non-backed enums ([#43842](https://github.com/laravel/framework/pull/43842))
13+
- Patch nested array validation rule regression bug ([#43897](https://github.com/laravel/framework/pull/43897))
14+
- Fix registering event listeners with array callback ([#43890](https://github.com/laravel/framework/pull/43890))
15+
16+
### Changed
17+
- Explicitly add column name to SQLite query in `Illuminate/Database/Console/DatabaseInspectionCommand::getSqliteTableSize()` ([#43832](https://github.com/laravel/framework/pull/43832))
18+
- Allow broadcast on demand notifications ([d2b1446](https://github.com/laravel/framework/commit/d2b14466c27a3d62219256cea27088e6ecd9d32f))
19+
- Make Vite::hotFile() public ([#43875](https://github.com/laravel/framework/pull/43875))
20+
- Prompt to create sqlite db when migrating ([#43867](https://github.com/laravel/framework/pull/43867))
21+
- Call prepare() on HttpException responses ([#43895](https://github.com/laravel/framework/pull/43895))
22+
- Make the model:prune command easier to extend ([#43919](https://github.com/laravel/framework/pull/43919))
423

524

625
## [v9.26.1](https://github.com/laravel/framework/compare/v9.26.0...v9.26.1) - 2022-08-23

src/Illuminate/Bus/DatabaseBatchRepository.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,25 @@ protected function toBatch($batch)
341341
$batch->finished_at ? CarbonImmutable::createFromTimestamp($batch->finished_at) : $batch->finished_at
342342
);
343343
}
344+
345+
/**
346+
* Get the underlying database connection.
347+
*
348+
* @return \Illuminate\Database\Connection
349+
*/
350+
public function getConnection()
351+
{
352+
return $this->connection;
353+
}
354+
355+
/**
356+
* Set the underlying database connection.
357+
*
358+
* @param \Illuminate\Database\Connection $connection
359+
* @return void
360+
*/
361+
public function setConnection(Connection $connection)
362+
{
363+
$this->connection = $connection;
364+
}
344365
}

src/Illuminate/Database/Connectors/SQLiteConnector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Illuminate\Database\Connectors;
44

5-
use InvalidArgumentException;
5+
use Illuminate\Database\SQLiteDatabaseDoesNotExistException;
66

77
class SQLiteConnector extends Connector implements ConnectorInterface
88
{
@@ -12,7 +12,7 @@ class SQLiteConnector extends Connector implements ConnectorInterface
1212
* @param array $config
1313
* @return \PDO
1414
*
15-
* @throws \InvalidArgumentException
15+
* @throws \Illuminate\Database\SQLiteDatabaseDoesNotExistException
1616
*/
1717
public function connect(array $config)
1818
{
@@ -31,7 +31,7 @@ public function connect(array $config)
3131
// as the developer probably wants to know if the database exists and this
3232
// SQLite driver will not throw any exception if it does not by default.
3333
if ($path === false) {
34-
throw new InvalidArgumentException("Database ({$config['database']}) does not exist.");
34+
throw new SQLiteDatabaseDoesNotExistException($config['database']);
3535
}
3636

3737
return $this->createConnection("sqlite:{$path}", $config, $options);

src/Illuminate/Database/Console/Migrations/MigrateCommand.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Contracts\Events\Dispatcher;
88
use Illuminate\Database\Events\SchemaLoaded;
99
use Illuminate\Database\Migrations\Migrator;
10+
use Illuminate\Database\SQLiteDatabaseDoesNotExistException;
1011
use Illuminate\Database\SqlServerConnection;
1112

1213
class MigrateCommand extends BaseCommand
@@ -108,7 +109,7 @@ public function handle()
108109
*/
109110
protected function prepareDatabase()
110111
{
111-
if (! $this->migrator->repositoryExists()) {
112+
if (! $this->repositoryExists()) {
112113
$this->components->info('Preparing database.');
113114

114115
$this->components->task('Creating migration table', function () {
@@ -125,6 +126,36 @@ protected function prepareDatabase()
125126
}
126127
}
127128

129+
/**
130+
* Determine if the migrator repository exists.
131+
*
132+
* @return bool
133+
*/
134+
protected function repositoryExists()
135+
{
136+
return retry(2, fn () => $this->migrator->repositoryExists(), 0, function ($e) {
137+
if (! $e->getPrevious() instanceof SQLiteDatabaseDoesNotExistException) {
138+
return false;
139+
}
140+
141+
if ($this->option('force')) {
142+
return touch($e->getPrevious()->path);
143+
}
144+
145+
if ($this->option('no-interaction')) {
146+
return false;
147+
}
148+
149+
$this->components->warn('The SQLite database does not exist: '.$e->getPrevious()->path);
150+
151+
if (! $this->components->confirm('Would you like to create it?')) {
152+
return false;
153+
}
154+
155+
return touch($e->getPrevious()->path);
156+
});
157+
}
158+
128159
/**
129160
* Load the schema state to seed the initial database schema structure.
130161
*

src/Illuminate/Database/Console/PruneCommand.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,33 @@ public function handle(Dispatcher $events)
7171
});
7272

7373
$models->each(function ($model) {
74-
$instance = new $model;
74+
$this->pruneModel($model);
75+
});
76+
77+
$events->forget(ModelsPruned::class);
78+
}
7579

76-
$chunkSize = property_exists($instance, 'prunableChunkSize')
77-
? $instance->prunableChunkSize
78-
: $this->option('chunk');
80+
/**
81+
* Prune the given model.
82+
*
83+
* @param string $model
84+
* @return void
85+
*/
86+
protected function pruneModel(string $model)
87+
{
88+
$instance = new $model;
7989

80-
$total = $this->isPrunable($model)
81-
? $instance->pruneAll($chunkSize)
82-
: 0;
90+
$chunkSize = property_exists($instance, 'prunableChunkSize')
91+
? $instance->prunableChunkSize
92+
: $this->option('chunk');
8393

84-
if ($total == 0) {
85-
$this->components->info("No prunable [$model] records found.");
86-
}
87-
});
94+
$total = $this->isPrunable($model)
95+
? $instance->pruneAll($chunkSize)
96+
: 0;
8897

89-
$events->forget(ModelsPruned::class);
98+
if ($total == 0) {
99+
$this->components->info("No prunable [$model] records found.");
100+
}
90101
}
91102

92103
/**
@@ -131,7 +142,7 @@ protected function models()
131142
/**
132143
* Get the default path where models are located.
133144
*
134-
* @return string
145+
* @return string|string[]
135146
*/
136147
protected function getDefaultPath()
137148
{

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,11 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
289289
// If the attribute cast was a date or a datetime, we will serialize the date as
290290
// a string. This allows the developers to customize how dates are serialized
291291
// into an array without affecting how they are persisted into the storage.
292-
if ($attributes[$key] && in_array($value, ['date', 'datetime', 'immutable_date', 'immutable_datetime'])) {
292+
if (isset($attributes[$key]) && in_array($value, ['date', 'datetime', 'immutable_date', 'immutable_datetime'])) {
293293
$attributes[$key] = $this->serializeDate($attributes[$key]);
294294
}
295295

296-
if ($attributes[$key] && ($this->isCustomDateTimeCast($value) ||
296+
if (isset($attributes[$key]) && ($this->isCustomDateTimeCast($value) ||
297297
$this->isImmutableCustomDateTimeCast($value))) {
298298
$attributes[$key] = $attributes[$key]->format(explode(':', $value, 2)[1]);
299299
}
@@ -303,7 +303,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
303303
$attributes[$key] = $this->serializeDate($attributes[$key]);
304304
}
305305

306-
if ($attributes[$key] && $this->isClassSerializable($key)) {
306+
if (isset($attributes[$key]) && $this->isClassSerializable($key)) {
307307
$attributes[$key] = $this->serializeClassCastableAttribute($key, $attributes[$key]);
308308
}
309309

@@ -930,7 +930,7 @@ public function setAttribute($key, $value)
930930
// If an attribute is listed as a "date", we'll convert it from a DateTime
931931
// instance into a form proper for storage on the database tables using
932932
// the connection grammar's date format. We will auto set the values.
933-
elseif ($value && $this->isDateAttribute($key)) {
933+
elseif (! is_null($value) && $this->isDateAttribute($key)) {
934934
$value = $this->fromDateTime($value);
935935
}
936936

src/Illuminate/Database/Eloquent/Factories/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ protected function expandAttributes(array $definition)
478478
/**
479479
* Add a new state transformation to the model definition.
480480
*
481-
* @param (callable(array<string, mixed>, \Illuminate\Database\Eloquent\Model|null=): array<string, mixed>)|array<string, mixed> $state
481+
* @param (callable(array<string, mixed>, \Illuminate\Database\Eloquent\Model|null): array<string, mixed>)|array<string, mixed> $state
482482
* @return static
483483
*/
484484
public function state($state)

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ abstract class Model implements Arrayable, ArrayAccess, CanBeEscapedWhenCastToSt
174174
*/
175175
protected static $lazyLoadingViolationCallback;
176176

177+
/**
178+
* Indicates if an exception should be thrown instead of silently discarding non-fillable attributes.
179+
*
180+
* @var bool
181+
*/
182+
protected static $modelsShouldPreventSilentlyDiscardingAttributes = false;
183+
177184
/**
178185
* Indicates if broadcasting is currently enabled.
179186
*
@@ -392,6 +399,17 @@ public static function handleLazyLoadingViolationUsing(?callable $callback)
392399
static::$lazyLoadingViolationCallback = $callback;
393400
}
394401

402+
/**
403+
* Prevent non-fillable attributes from being silently discarded.
404+
*
405+
* @param bool $value
406+
* @return void
407+
*/
408+
public static function preventSilentlyDiscardingAttributes($value = true)
409+
{
410+
static::$modelsShouldPreventSilentlyDiscardingAttributes = $value;
411+
}
412+
395413
/**
396414
* Execute a callback without broadcasting any model events for all model types.
397415
*
@@ -429,7 +447,7 @@ public function fill(array $attributes)
429447
// the model, and all others will just get ignored for security reasons.
430448
if ($this->isFillable($key)) {
431449
$this->setAttribute($key, $value);
432-
} elseif ($totallyGuarded) {
450+
} elseif ($totallyGuarded || static::preventsSilentlyDiscardingAttributes()) {
433451
throw new MassAssignmentException(sprintf(
434452
'Add [%s] to fillable property to allow mass assignment on [%s].',
435453
$key, get_class($this)
@@ -2061,6 +2079,16 @@ public static function preventsLazyLoading()
20612079
return static::$modelsShouldPreventLazyLoading;
20622080
}
20632081

2082+
/**
2083+
* Determine if discarding guarded attribute fills is disabled.
2084+
*
2085+
* @return bool
2086+
*/
2087+
public static function preventsSilentlyDiscardingAttributes()
2088+
{
2089+
return static::$modelsShouldPreventSilentlyDiscardingAttributes;
2090+
}
2091+
20642092
/**
20652093
* Get the broadcast channel route definition that is associated with the given entity.
20662094
*

0 commit comments

Comments
 (0)