Skip to content

Commit

Permalink
Now withoutSyncingToSearch() returns result of closure.
Browse files Browse the repository at this point in the history
(cherry picked from commit 9dfb3f0)
  • Loading branch information
nqxcode committed Sep 6, 2017
1 parent 19d5b10 commit 434f60d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Nqxcode/LuceneSearch/Model/SearchTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public static function bootSearchTrait()
public static function withoutSyncingToSearch(\Closure $closure)
{
SearchObserver::setEnabled(false);
$closure();
$result = $closure();
SearchObserver::setEnabled(true);

return $result;
}

public static function search($value, $field = '*', array $options = [])
Expand Down
5 changes: 4 additions & 1 deletion tests/functional/EventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ public function testWithoutSyncingToSearch()
{
$this->assertEquals(0, Search::query('observer')->count());

Product::withoutSyncingToSearch(function () {
$result = Product::withoutSyncingToSearch(function () {
$p = Product::first();
$p->name = 'observer';
$p->save();

return 'result of closure';
});

$this->assertEquals(0, Search::query('observer')->count());
$this->assertEquals('result of closure', $result);
}

public function testSearch()
Expand Down

0 comments on commit 434f60d

Please sign in to comment.