Skip to content

Commit

Permalink
formatting and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jul 7, 2021
1 parent 2dca8bf commit 1dfde65
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
52 changes: 30 additions & 22 deletions src/ModelObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Scout;

use Closure;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Config;

Expand All @@ -22,19 +23,18 @@ class ModelObserver
protected $usingSoftDeletes;

/**
* The class names that syncing is disabled for.
* Indicates if the model is currently force saving.
*
* @var array
* @var bool
*/
protected static $syncingDisabledFor = [];
protected $forceSaving = false;

/**
* Indicates if the model is currently force saving.
* When force saving we dismiss the sensitive attributes check.
* The class names that syncing is disabled for.
*
* @var bool
* @var array
*/
protected $forceSaving = false;
protected static $syncingDisabledFor = [];

/**
* Create a new observer instance.
Expand Down Expand Up @@ -109,19 +109,6 @@ public function saved($model)
$model->searchable();
}

/**
* Handle the saved event for the model without checking for sensitive attributes.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
protected function forceSaved($model)
{
$this->forceSaving = true;
$this->saved($model);
$this->forceSaving = false;
}

/**
* Handle the deleted event for the model.
*
Expand All @@ -139,7 +126,9 @@ public function deleted($model)
}

if ($this->usingSoftDeletes && $this->usesSoftDelete($model)) {
$this->forceSaved($model);
$this->whileForcingUpdate(function () use ($model) {
$this->saved($model);
});
} else {
$model->unsearchable();
}
Expand Down Expand Up @@ -168,7 +157,26 @@ public function forceDeleted($model)
*/
public function restored($model)
{
$this->forceSaved($model);
$this->whileForcingUpdate(function () use ($model) {
$this->saved($model);
});
}

/**
* Execute the given callback while forcing updates.
*
* @param \Closure $callback
* @return mixed
*/
protected function whileForcingUpdate(Closure $callback)
{
$this->forceSaving = true;

$result = $callback();

$this->forceSaving = false;

return $result;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ public function shouldBeSearchable()
}

/**
* When updating a model, this method determines if we
* should perform a search engine update or not.
* When updating a model, this method determines if we should update the search index.
*
* @return bool
*/
public function searchShouldUpdate(): bool
public function searchIndexShouldBeUpdated()
{
return true;
}
Expand Down

0 comments on commit 1dfde65

Please sign in to comment.