]> BookStack Code Mirror - bookstack/commitdiff
Refactored search-based code to its own folder
authorDan Brown <redacted>
Tue, 16 Aug 2022 10:27:22 +0000 (11:27 +0100)
committerDan Brown <redacted>
Tue, 16 Aug 2022 10:28:05 +0000 (11:28 +0100)
Also applied StyleCI changes

16 files changed:
app/Auth/Permissions/PermissionApplicator.php
app/Auth/User.php
app/Console/Commands/RegenerateSearch.php
app/Entities/Models/Entity.php
app/Http/Controllers/Api/SearchApiController.php
app/Http/Controllers/PageRevisionController.php
app/Http/Controllers/SearchController.php
app/Search/SearchIndex.php [moved from app/Entities/Tools/SearchIndex.php with 99% similarity]
app/Search/SearchOptions.php [moved from app/Entities/Tools/SearchOptions.php with 94% similarity]
app/Search/SearchResultsFormatter.php [moved from app/Entities/Tools/SearchResultsFormatter.php with 99% similarity]
app/Search/SearchRunner.php [moved from app/Entities/Tools/SearchRunner.php with 99% similarity]
app/Search/SearchTerm.php [moved from app/Entities/Models/SearchTerm.php with 91% similarity]
database/seeders/DummyContentSeeder.php
database/seeders/LargeContentSeeder.php
tests/Entity/SearchOptionsTest.php
tests/FavouriteTest.php

index 9a39f3e901a4520a9bf9b3dd6d03f0b0497c589d..d840ccd16b89d3ac1021154fa4996c0e2576dcf4 100644 (file)
@@ -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) {
index 393965e0d8608950520418f0dfd39727ea0f2e97..6e66bc808296c4c531568ac516c93412000a07c9 100644 (file)
@@ -249,6 +249,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
         }
 
         $this->avatarUrl = $avatar;
+
         return $avatar;
     }
 
index 20e3fc7983f8bd7ff472758d20f3693841864ec5..ff584da56452561fab14ab1b63f0e72bb97a073b 100644 (file)
@@ -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;
 
index 17f018a566a01f76db1e39d64557b71cf2671c1e..ffb9b9c7d6d91674c8d3d0d7ad9f391cfe3f0ba0 100644 (file)
@@ -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;
index 5c4112f743fe76bce24fbb4bfa61110f3445e14a..7ef714390903033d4ab0d43016518214db887be9 100644 (file)
@@ -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
index ea80e13cd67ceff1daed211861de9ab3bff97d9c..c4d5fbc7b37fc59ab6e946e37acb60e51bfb169c 100644 (file)
@@ -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,
         ]);
     }
 
index 4a002298cebb617de9eb0c34dd23cde56f920d44..699733e377008f508634d9dbbda6755e103c6394 100644 (file)
@@ -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
similarity index 99%
rename from app/Entities/Tools/SearchIndex.php
rename to app/Search/SearchIndex.php
index db44daadfb931122e2a449c9ab3078bf1974877d..8c793a109ffb905c2d75904d17a24b34f802e770 100644 (file)
@@ -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;
similarity index 94%
rename from app/Entities/Tools/SearchOptions.php
rename to app/Search/SearchOptions.php
index 99271058e2306412d10d14b76a888c8ecd70d371..0bf9c3116b67d91e092ee3fa82abda3e01441fa0 100644 (file)
@@ -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.
similarity index 99%
rename from app/Entities/Tools/SearchResultsFormatter.php
rename to app/Search/SearchResultsFormatter.php
index 00b9c0b26369d234e9944c31d5d85697c4faef7b..9cbc5ee6862d708457be7ba9b0efe4ef0d0ce335 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace BookStack\Entities\Tools;
+namespace BookStack\Search;
 
 use BookStack\Actions\Tag;
 use BookStack\Entities\Models\Entity;
similarity index 99%
rename from app/Entities/Tools/SearchRunner.php
rename to app/Search/SearchRunner.php
index 22f0f66c7d43217a2c7f2811cb9ba3b210264e01..e36edb06c2ca10f3bb7499e7b3e928323894609b 100644 (file)
@@ -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.
similarity index 91%
rename from app/Entities/Models/SearchTerm.php
rename to app/Search/SearchTerm.php
index 4ec8d6c45ac1ad027322d0ccbb26fec418e9e468..d416b0059e6bdc0267037eb5784d89a5fc010b98 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace BookStack\Entities\Models;
+namespace BookStack\Search;
 
 use BookStack\Model;
 
index e97069e7f5999afaee29e75817e9ebd7f476787a..f61e4e13df394e20adc51170110cf97feec37890 100644 (file)
@@ -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;
index b2d8a4d1b369eae0b19509cdb9cd1f2da624530e..d0e65f9749024030436f1907671d0ab3a50df6f9 100644 (file)
@@ -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;
 
index 25a0ae7209572b18145e1cf9411c8fff4b2edd93..cac9c67f145f5780c6be173849162693bf295120 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace Tests\Entity;
 
-use BookStack\Entities\Tools\SearchOptions;
+use BookStack\Search\SearchOptions;
 use Tests\TestCase;
 
 class SearchOptionsTest extends TestCase
index 032e46d0c043580838e4fb822fe230c5cd4bf75a..de36c77e1e0117b6f0691ab44abcc0069380963e 100644 (file)
@@ -1,4 +1,6 @@
-<?php namespace Tests;
+<?php
+
+namespace Tests;
 
 use BookStack\Actions\Favourite;
 use BookStack\Auth\User;
Morty Proxy This is a proxified and sanitized view of the page, visit original site.