-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[9.x] Fix removing queued models with custom Scout keys (#480)
* Re-push remove from Scout queue fix #479 * Fix test * StyleCI fixes * Update src/Jobs/RemoveFromSearch.php Co-authored-by: Dries Vints <[email protected]> * Update RemoveFromSearch.php Co-authored-by: Dries Vints <[email protected]>
- Loading branch information
1 parent
ce621be
commit c1e1e92
Showing
4 changed files
with
113 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Laravel\Scout\Jobs; | ||
|
||
use Illuminate\Database\Eloquent\Collection; | ||
use Laravel\Scout\Searchable; | ||
|
||
class RemoveableScoutCollection extends Collection | ||
{ | ||
/** | ||
* Get the Scout identifiers for all of the entities. | ||
* | ||
* @return array | ||
*/ | ||
public function getQueueableIds() | ||
{ | ||
if ($this->isEmpty()) { | ||
return []; | ||
} | ||
|
||
return in_array(Searchable::class, class_uses_recursive($this->first())) | ||
? $this->map->getScoutKey()->all() | ||
: parent::getQueueableIds(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Laravel\Scout\Tests\Fixtures; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Laravel\Scout\Searchable; | ||
|
||
class SearchableModelWithCustomKey extends Model | ||
{ | ||
use Searchable; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = ['other_id']; | ||
|
||
public function getScoutKey() | ||
{ | ||
return $this->other_id; | ||
} | ||
|
||
public function getScoutKeyName() | ||
{ | ||
return $this->qualifyColumn('other_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters