Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: laravel/framework
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.23.2
Choose a base ref
...
head repository: laravel/framework
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.24.0
Choose a head ref
  • 7 commits
  • 7 files changed
  • 4 contributors

Commits on Aug 7, 2020

  1. Copy the full SHA
    bdf7699 View commit details
  2. formatting

    taylorotwell committed Aug 7, 2020
    Copy the full SHA
    c6a3174 View commit details
  3. [7.x] Add plain text only notifications (#33781)

    * Add test for html only notifications
    
    * Add ability to send plain text only notifications
    
    * Improve class name
    pawelmysior authored Aug 7, 2020
    Copy the full SHA
    7a7582f View commit details
  4. [6.x] Verify column names are actual columns when using guarded (#33777)

    * verify column names are actual columns when using guarded
    
    * Apply fixes from StyleCI (#33778)
    
    * remove json check
    taylorotwell authored Aug 7, 2020
    Copy the full SHA
    897d107 View commit details
  5. patch

    taylorotwell committed Aug 7, 2020
    Copy the full SHA
    baec6c2 View commit details
  6. version

    taylorotwell committed Aug 7, 2020
    Copy the full SHA
    e351423 View commit details
  7. minor

    taylorotwell committed Aug 7, 2020
    Copy the full SHA
    71bfb1f View commit details
22 changes: 21 additions & 1 deletion src/Illuminate/Database/Connectors/MySqlConnector.php
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@ public function connect(array $config)
$connection->exec("use `{$config['database']}`;");
}

$this->configureIsolationLevel($connection, $config);

$this->configureEncoding($connection, $config);

// Next, we will check to see if a timezone has been specified in this config
@@ -40,12 +42,30 @@ public function connect(array $config)
}

/**
* Set the connection character set and collation.
* Set the connection transaction isolation level.
*
* @param \PDO $connection
* @param array $config
* @return void
*/
protected function configureIsolationLevel($connection, array $config)
{
if (! isset($config['isolation_level'])) {
return;
}

$connection->prepare(
"SET SESSION TRANSACTION ISOLATION LEVEL '{$config['isolation_level']}'"
)->execute();
}

/**
* Set the connection character set and collation.
*
* @param \PDO $connection
* @param array $config
* @return void|\PDO
*/
protected function configureEncoding($connection, array $config)
{
if (! isset($config['charset'])) {
31 changes: 28 additions & 3 deletions src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php
Original file line number Diff line number Diff line change
@@ -27,6 +27,13 @@ trait GuardsAttributes
*/
protected static $unguarded = false;

/**
* The actual columns that exist on the database and can be guarded.
*
* @var array
*/
protected static $guardableColumns = [];

/**
* Get the fillable attributes for the model.
*
@@ -190,12 +197,30 @@ public function isFillable($key)
*/
public function isGuarded($key)
{
if (strpos($key, '->') !== false) {
$key = Str::before($key, '->');
if (empty($this->getGuarded())) {
return false;
}

return $this->getGuarded() == ['*'] ||
! empty(preg_grep('/^'.preg_quote($key).'$/i', $this->getGuarded()));
! empty(preg_grep('/^'.preg_quote($key).'$/i', $this->getGuarded())) ||
! $this->isGuardableColumn($key);
}

/**
* Determine if the given column is a valid, guardable column.
*
* @param string $key
* @return bool
*/
protected function isGuardableColumn($key)
{
if (! isset(static::$guardableColumns[get_class($this)])) {
static::$guardableColumns[get_class($this)] = $this->getConnection()
->getSchemaBuilder()
->getColumnListing($this->getTable());
}

return in_array($key, static::$guardableColumns[get_class($this)]);
}

/**
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
*
* @var string
*/
const VERSION = '7.23.2';
const VERSION = '7.24.0';

/**
* The base path for the Laravel installation.
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/Channels/MailChannel.php
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ protected function messageBuilder($notifiable, $notification, $message)
*/
protected function buildView($message)
{
if ($message->view) {
if ($message->view || $message->textView) {
return [
'html' => $message->view,
'text' => $message->textView,
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/Messages/MailMessage.php
Original file line number Diff line number Diff line change
@@ -331,7 +331,7 @@ protected function arrayOfAddresses($address)
*/
public function render()
{
if (isset($this->view)) {
if (isset($this->view) || isset($this->textView)) {
return Container::getInstance()->make('mailer')->render(
[$this->view, $this->textView],
$this->data()
13 changes: 12 additions & 1 deletion tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Connection;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\ConnectionResolverInterface as Resolver;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\JsonEncodingException;
@@ -1096,11 +1097,21 @@ public function testUnderscorePropertiesAreNotFilled()
public function testGuarded()
{
$model = new EloquentModelStub;

EloquentModelStub::setConnectionResolver($resolver = m::mock(Resolver::class));
$resolver->shouldReceive('connection')->andReturn($connection = m::mock(stdClass::class));
$connection->shouldReceive('getSchemaBuilder->getColumnListing')->andReturn(['name', 'age', 'foo']);

$model->guard(['name', 'age']);
$model->fill(['name' => 'foo', 'age' => 'bar', 'foo' => 'bar']);
$this->assertFalse(isset($model->name));
$this->assertFalse(isset($model->age));
$this->assertSame('bar', $model->foo);

$model = new EloquentModelStub;
$model->guard(['name', 'age']);
$model->fill(['Foo' => 'bar']);
$this->assertFalse(isset($model->Foo));
}

public function testFillableOverridesGuarded()
@@ -2314,7 +2325,7 @@ public function getDates()
class EloquentModelSaveStub extends Model
{
protected $table = 'save_stub';
protected $guarded = ['id'];
protected $guarded = [];

public function save(array $options = [])
{
102 changes: 98 additions & 4 deletions tests/Integration/Notifications/SendingMailNotificationsTest.php
Original file line number Diff line number Diff line change
@@ -249,9 +249,9 @@ public function testMailIsSentUsingMailable()
$user->notify($notification);
}

public function testMailIsSentUsingMailMessageWithPlain()
public function testMailIsSentUsingMailMessageWithHtmlAndPlain()
{
$notification = new TestMailNotificationWithPlain;
$notification = new TestMailNotificationWithHtmlAndPlain;
$notification->id = Str::uuid()->toString();

$user = NotifiableUser::forceCreate([
@@ -270,7 +270,71 @@ public function testMailIsSentUsingMailMessageWithPlain()

$message->shouldReceive('to')->once()->with(['taylor@laravel.com']);

$message->shouldReceive('subject')->once()->with('Test Mail Notification With Plain');
$message->shouldReceive('subject')->once()->with('Test Mail Notification With Html And Plain');

$closure($message);

return true;
})
);

$user->notify($notification);
}

public function testMailIsSentUsingMailMessageWithHtmlOnly()
{
$notification = new TestMailNotificationWithHtmlOnly;
$notification->id = Str::uuid()->toString();

$user = NotifiableUser::forceCreate([
'email' => 'taylor@laravel.com',
]);

$this->mailer->shouldReceive('send')->once()->with(
['html' => 'html', 'text' => null],
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
'__laravel_notification_queued' => false,
]),
m::on(function ($closure) {
$message = m::mock(Message::class);

$message->shouldReceive('to')->once()->with(['taylor@laravel.com']);

$message->shouldReceive('subject')->once()->with('Test Mail Notification With Html Only');

$closure($message);

return true;
})
);

$user->notify($notification);
}

public function testMailIsSentUsingMailMessageWithPlainOnly()
{
$notification = new TestMailNotificationWithPlainOnly;
$notification->id = Str::uuid()->toString();

$user = NotifiableUser::forceCreate([
'email' => 'taylor@laravel.com',
]);

$this->mailer->shouldReceive('send')->once()->with(
['html' => null, 'text' => 'plain'],
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
'__laravel_notification_queued' => false,
]),
m::on(function ($closure) {
$message = m::mock(Message::class);

$message->shouldReceive('to')->once()->with(['taylor@laravel.com']);

$message->shouldReceive('subject')->once()->with('Test Mail Notification With Plain Only');

$closure($message);

@@ -364,7 +428,7 @@ public function toMail($notifiable)
}
}

class TestMailNotificationWithPlain extends Notification
class TestMailNotificationWithHtmlAndPlain extends Notification
{
public function via($notifiable)
{
@@ -378,3 +442,33 @@ public function toMail($notifiable)
->text('plain');
}
}

class TestMailNotificationWithHtmlOnly extends Notification
{
public function via($notifiable)
{
return [MailChannel::class];
}

public function toMail($notifiable)
{
return (new MailMessage)
->view('html')
->text(null);
}
}

class TestMailNotificationWithPlainOnly extends Notification
{
public function via($notifiable)
{
return [MailChannel::class];
}

public function toMail($notifiable)
{
return (new MailMessage)
->view(null)
->text('plain');
}
}