-
Notifications
You must be signed in to change notification settings - Fork 330
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
[6.0] Use engine to flush records of model #310
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Release Notes | ||
|
||
## [v6.0.0 (unreleased)](https://github.com/laravel/framework/compare/v5.0.3...v6.0.0) | ||
|
||
### Changed | ||
- Flush records of a model using the engine ([#310](https://github.com/laravel/scout/pull/310)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,6 @@ public function handle(Dispatcher $events) | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @driesvints This class no longer needs the line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
$model = new $class; | ||
|
||
$events->listen(ModelsFlushed::class, function ($event) use ($class) { | ||
$key = $event->models->last()->getScoutKey(); | ||
|
||
$this->line('<comment>Flushed ['.$class.'] models up to ID:</comment> '.$key); | ||
}); | ||
|
||
$model::removeAllFromSearch(); | ||
|
||
$events->forget(ModelsFlushed::class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also don't need this line. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,19 @@ public function getTotalCount($results) | |
return $results['nbHits']; | ||
} | ||
|
||
/** | ||
* Flush all of the model's records from the engine. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $model | ||
* @return void | ||
*/ | ||
public function flush($model) | ||
{ | ||
$index = $this->algolia->initIndex($model->searchableAs()); | ||
|
||
$index->clearIndex(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirm. This is good. 👍 |
||
} | ||
|
||
/** | ||
* Determine if the given model uses soft deletes. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be:
## [v6.0.0 (unreleased)](https://github.com/laravel/scout/compare/v5.0.3...v6.0.0)