Skip to content

NOW MANAGED ON CODEBERG

Refactored search-based code to its own folder

Dan Brown837fd74bf691
diff --git a/app/Auth/Permissions/PermissionApplicator.php b/app/Auth/Permissions/PermissionApplicator.php
index 9a39f3e90..d840ccd16 100644
--- a/app/Auth/Permissions/PermissionApplicator.php
+++ b/app/Auth/Permissions/PermissionApplicator.php
@@ -74,9 +74,8 @@ class PermissionApplicator
}
foreach ($chain as $currentEntity) {
-
if (is_null($currentEntity->restricted)) {
- throw new InvalidArgumentException("Entity restricted field used but has not been loaded");
+ throw new InvalidArgumentException('Entity restricted field used but has not been loaded');
}
if ($currentEntity->restricted) {
diff --git a/app/Auth/User.php b/app/Auth/User.php
index 393965e0d..6e66bc808 100644
--- a/app/Auth/User.php
+++ b/app/Auth/User.php
@@ -249,6 +249,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
}
$this->avatarUrl = $avatar;
+
return $avatar;
}
diff --git a/app/Console/Commands/RegenerateSearch.php b/app/Console/Commands/RegenerateSearch.php
index 20e3fc798..ff584da56 100644
--- a/app/Console/Commands/RegenerateSearch.php
+++ b/app/Console/Commands/RegenerateSearch.php
@@ -3,7 +3,7 @@
namespace BookStack\Console\Commands;
use BookStack\Entities\Models\Entity;
-use BookStack\Entities\Tools\SearchIndex;
+use BookStack\Search\SearchIndex;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
diff --git a/app/Entities/Models/Entity.php b/app/Entities/Models/Entity.php
index 17f018a56..ffb9b9c7d 100644
--- a/app/Entities/Models/Entity.php
+++ b/app/Entities/Models/Entity.php
@@ -11,7 +11,6 @@ use BookStack\Auth\Permissions\EntityPermission;
use BookStack\Auth\Permissions\JointPermission;
use BookStack\Auth\Permissions\JointPermissionBuilder;
use BookStack\Auth\Permissions\PermissionApplicator;
-use BookStack\Entities\Tools\SearchIndex;
use BookStack\Entities\Tools\SlugGenerator;
use BookStack\Interfaces\Deletable;
use BookStack\Interfaces\Favouritable;
@@ -19,6 +18,8 @@ use BookStack\Interfaces\Loggable;
use BookStack\Interfaces\Sluggable;
use BookStack\Interfaces\Viewable;
use BookStack\Model;
+use BookStack\Search\SearchIndex;
+use BookStack\Search\SearchTerm;
use BookStack\Traits\HasCreatorAndUpdater;
use BookStack\Traits\HasOwner;
use Carbon\Carbon;
diff --git a/app/Http/Controllers/Api/SearchApiController.php b/app/Http/Controllers/Api/SearchApiController.php
index 5c4112f74..7ef714390 100644
--- a/app/Http/Controllers/Api/SearchApiController.php
+++ b/app/Http/Controllers/Api/SearchApiController.php
@@ -3,9 +3,9 @@
namespace BookStack\Http\Controllers\Api;
use BookStack\Entities\Models\Entity;
-use BookStack\Entities\Tools\SearchOptions;
-use BookStack\Entities\Tools\SearchResultsFormatter;
-use BookStack\Entities\Tools\SearchRunner;
+use BookStack\Search\SearchOptions;
+use BookStack\Search\SearchResultsFormatter;
+use BookStack\Search\SearchRunner;
use Illuminate\Http\Request;
class SearchApiController extends ApiController
diff --git a/app/Http/Controllers/PageRevisionController.php b/app/Http/Controllers/PageRevisionController.php
index ea80e13cd..c4d5fbc7b 100644
--- a/app/Http/Controllers/PageRevisionController.php
+++ b/app/Http/Controllers/PageRevisionController.php
@@ -27,9 +27,9 @@ class PageRevisionController extends Controller
{
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$revisions = $page->revisions()->select([
- 'id', 'page_id', 'name', 'created_at', 'created_by', 'updated_at',
- 'type', 'revision_number', 'summary',
- ])
+ 'id', 'page_id', 'name', 'created_at', 'created_by', 'updated_at',
+ 'type', 'revision_number', 'summary',
+ ])
->selectRaw("IF(markdown = '', false, true) as is_markdown")
->with(['page.book', 'createdBy'])
->get();
@@ -38,7 +38,7 @@ class PageRevisionController extends Controller
return view('pages.revisions', [
'revisions' => $revisions,
- 'page' => $page,
+ 'page' => $page,
]);
}
diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php
index 4a002298c..699733e37 100644
--- a/app/Http/Controllers/SearchController.php
+++ b/app/Http/Controllers/SearchController.php
@@ -3,10 +3,10 @@
namespace BookStack\Http\Controllers;
use BookStack\Entities\Queries\Popular;
-use BookStack\Entities\Tools\SearchOptions;
-use BookStack\Entities\Tools\SearchResultsFormatter;
-use BookStack\Entities\Tools\SearchRunner;
use BookStack\Entities\Tools\SiblingFetcher;
+use BookStack\Search\SearchOptions;
+use BookStack\Search\SearchResultsFormatter;
+use BookStack\Search\SearchRunner;
use Illuminate\Http\Request;
class SearchController extends Controller
diff --git a/app/Entities/Tools/SearchIndex.php b/app/Search/SearchIndex.php
similarity index 99%
rename from app/Entities/Tools/SearchIndex.php
rename to app/Search/SearchIndex.php
index db44daadf..8c793a109 100644
--- a/app/Entities/Tools/SearchIndex.php
+++ b/app/Search/SearchIndex.php
@@ -1,12 +1,11 @@
<?php
-namespace BookStack\Entities\Tools;
+namespace BookStack\Search;
use BookStack\Actions\Tag;
use BookStack\Entities\EntityProvider;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Models\Page;
-use BookStack\Entities\Models\SearchTerm;
use DOMDocument;
use DOMNode;
use Illuminate\Database\Eloquent\Builder;
diff --git a/app/Entities/Tools/SearchOptions.php b/app/Search/SearchOptions.php
similarity index 94%
rename from app/Entities/Tools/SearchOptions.php
rename to app/Search/SearchOptions.php
index 99271058e..0bf9c3116 100644
--- a/app/Entities/Tools/SearchOptions.php
+++ b/app/Search/SearchOptions.php
@@ -1,30 +1,15 @@
<?php
-namespace BookStack\Entities\Tools;
+namespace BookStack\Search;
use Illuminate\Http\Request;
class SearchOptions
{
- /**
- * @var array
- */
- public $searches = [];
-
- /**
- * @var array
- */
- public $exacts = [];
-
- /**
- * @var array
- */
- public $tags = [];
-
- /**
- * @var array
- */
- public $filters = [];
+ public array $searches = [];
+ public array $exacts = [];
+ public array $tags = [];
+ public array $filters = [];
/**
* Create a new instance from a search string.
diff --git a/app/Entities/Tools/SearchResultsFormatter.php b/app/Search/SearchResultsFormatter.php
similarity index 99%
rename from app/Entities/Tools/SearchResultsFormatter.php
rename to app/Search/SearchResultsFormatter.php
index 00b9c0b26..9cbc5ee68 100644
--- a/app/Entities/Tools/SearchResultsFormatter.php
+++ b/app/Search/SearchResultsFormatter.php
@@ -1,6 +1,6 @@
<?php
-namespace BookStack\Entities\Tools;
+namespace BookStack\Search;
use BookStack\Actions\Tag;
use BookStack\Entities\Models\Entity;
diff --git a/app/Entities/Tools/SearchRunner.php b/app/Search/SearchRunner.php
similarity index 99%
rename from app/Entities/Tools/SearchRunner.php
rename to app/Search/SearchRunner.php
index 22f0f66c7..e36edb06c 100644
--- a/app/Entities/Tools/SearchRunner.php
+++ b/app/Search/SearchRunner.php
@@ -1,6 +1,6 @@
<?php
-namespace BookStack\Entities\Tools;
+namespace BookStack\Search;
use BookStack\Auth\Permissions\PermissionApplicator;
use BookStack\Auth\User;
@@ -8,7 +8,6 @@ use BookStack\Entities\EntityProvider;
use BookStack\Entities\Models\BookChild;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Models\Page;
-use BookStack\Entities\Models\SearchTerm;
use Illuminate\Database\Connection;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
@@ -29,7 +28,7 @@ class SearchRunner
*
* @var string[]
*/
- protected $queryOperators = ['<=', '>=', '=', '<', '>', 'like', '!='];
+ protected array $queryOperators = ['<=', '>=', '=', '<', '>', 'like', '!='];
/**
* Retain a cache of score adjusted terms for specific search options.
diff --git a/app/Entities/Models/SearchTerm.php b/app/Search/SearchTerm.php
similarity index 91%
rename from app/Entities/Models/SearchTerm.php
rename to app/Search/SearchTerm.php
index 4ec8d6c45..d416b0059 100644
--- a/app/Entities/Models/SearchTerm.php
+++ b/app/Search/SearchTerm.php
@@ -1,6 +1,6 @@
<?php
-namespace BookStack\Entities\Models;
+namespace BookStack\Search;
use BookStack\Model;
diff --git a/database/seeders/DummyContentSeeder.php b/database/seeders/DummyContentSeeder.php
index e97069e7f..f61e4e13d 100644
--- a/database/seeders/DummyContentSeeder.php
+++ b/database/seeders/DummyContentSeeder.php
@@ -10,7 +10,7 @@ use BookStack\Auth\User;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
-use BookStack\Entities\Tools\SearchIndex;
+use BookStack\Search\SearchIndex;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
diff --git a/database/seeders/LargeContentSeeder.php b/database/seeders/LargeContentSeeder.php
index b2d8a4d1b..d0e65f974 100644
--- a/database/seeders/LargeContentSeeder.php
+++ b/database/seeders/LargeContentSeeder.php
@@ -8,7 +8,7 @@ use BookStack\Auth\User;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Page;
-use BookStack\Entities\Tools\SearchIndex;
+use BookStack\Search\SearchIndex;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
diff --git a/tests/Entity/SearchOptionsTest.php b/tests/Entity/SearchOptionsTest.php
index 25a0ae720..cac9c67f1 100644
--- a/tests/Entity/SearchOptionsTest.php
+++ b/tests/Entity/SearchOptionsTest.php
@@ -2,7 +2,7 @@
namespace Tests\Entity;
-use BookStack\Entities\Tools\SearchOptions;
+use BookStack\Search\SearchOptions;
use Tests\TestCase;
class SearchOptionsTest extends TestCase
diff --git a/tests/FavouriteTest.php b/tests/FavouriteTest.php
index 032e46d0c..de36c77e1 100644
--- a/tests/FavouriteTest.php
+++ b/tests/FavouriteTest.php
@@ -1,4 +1,6 @@
-<?php namespace Tests;
+<?php
+
+namespace Tests;
use BookStack\Actions\Favourite;
use BookStack\Auth\User;