New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Fix regression in save(touch) option #15264

Merged
merged 1 commit into from Sep 5, 2016
Jump to file or symbol
Failed to load files and symbols.
+21 −3
Diff settings

Always

Just for now

@@ -1462,7 +1462,7 @@ public function save(array $options = [])
// clause to only update this model. Otherwise, we'll just insert them.
if ($this->exists) {
$saved = $this->isDirty() ?
$this->performUpdate($query) : true;
$this->performUpdate($query, $options) : true;
}
// If the model is brand new, we'll insert it into our database and set the
@@ -1515,9 +1515,10 @@ protected function finishSave(array $options)
* Perform a model update operation.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $options
* @return bool
*/
protected function performUpdate(Builder $query)
protected function performUpdate(Builder $query, array $options = [])
{
// If the updating event returns false, we will cancel the update operation so
// developers can hook Validation systems into their models and cancel this
@@ -1529,7 +1530,7 @@ protected function performUpdate(Builder $query)
// First we need to create a fresh query instance and touch the creation and
// update timestamp on the model which are maintained by us for developer
// convenience. Then we will just continue saving the model instances.
if ($this->timestamps) {
if ($this->timestamps && Arr::get($options, 'touch', true)) {
$this->updateTimestamps();
}
@@ -195,6 +195,23 @@ public function testUpdateProcessDoesntOverrideTimestamps()
$this->assertTrue($model->save());
}
public function testSaveDoesntUpateTimestampsIfTouchOptionDisabled()
{
$model = $this->getMockBuilder('EloquentModelStub')->setMethods(['newQueryWithoutScopes', 'updateTimestamps', 'fireModelEvent'])->getMock();
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('where')->once()->with('id', '=', 1);
$query->shouldReceive('update')->once()->with(['name' => 'taylor'])->andReturn(1);
$model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));
$model->expects($this->never())->method('updateTimestamps');
$model->expects($this->any())->method('fireModelEvent')->will($this->returnValue(true));
$model->id = 1;
$model->syncOriginal();
$model->name = 'taylor';
$model->exists = true;
$this->assertTrue($model->save(['touch' => false]));
}
public function testSaveIsCancelledIfSavingEventReturnsFalse()
{
$model = $this->getMockBuilder('EloquentModelStub')->setMethods(['newQueryWithoutScopes'])->getMock();
ProTip! Use n and p to navigate between commits in a pull request.