From 949113b0bd969d4465a6af9a2115f69d7cdf7c76 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Wed, 3 Aug 2022 21:11:24 +0200 Subject: [PATCH 1/9] fix: fix setup and dummy in case meilisearch not activated --- app/Console/Commands/SetupApplication.php | 38 ++++++++++++---------- app/Console/Commands/SetupDummyAccount.php | 11 ++++--- app/Helpers/ScoutHelper.php | 16 +++++++++ app/Models/Contact.php | 11 +++++++ app/Models/Group.php | 11 +++++++ app/Models/Loan.php | 11 +++++++ app/Models/Note.php | 11 +++++++ 7 files changed, 87 insertions(+), 22 deletions(-) create mode 100644 app/Helpers/ScoutHelper.php diff --git a/app/Console/Commands/SetupApplication.php b/app/Console/Commands/SetupApplication.php index bd2c70ce4..dbd46ed0c 100644 --- a/app/Console/Commands/SetupApplication.php +++ b/app/Console/Commands/SetupApplication.php @@ -47,24 +47,26 @@ public function handle(): void $this->line('-> Creating indexes on Meilisearch. Make sure Meilisearch is running.'); - $client = new Client(config('scout.meilisearch.host'), config('scout.meilisearch.key')); - $index = $client->index('contacts'); - $index->updateFilterableAttributes([ - 'id', - 'vault_id', - ]); - $index = $client->index('notes'); - $index->updateFilterableAttributes([ - 'id', - 'vault_id', - 'contact_id', - ]); - $index = $client->index('groups'); - $index->updateFilterableAttributes([ - 'id', - 'vault_id', - ]); + if (config('scout.driver') === 'meilisearch' && ($host = config('scout.meilisearch.host')) !== '') { + $client = new Client($host, config('scout.meilisearch.key')); + $index = $client->index('contacts'); + $index->updateFilterableAttributes([ + 'id', + 'vault_id', + ]); + $index = $client->index('notes'); + $index->updateFilterableAttributes([ + 'id', + 'vault_id', + 'contact_id', + ]); + $index = $client->index('groups'); + $index->updateFilterableAttributes([ + 'id', + 'vault_id', + ]); - $this->line('✓ Indexes created'); + $this->line('✓ Indexes created'); + } } } diff --git a/app/Console/Commands/SetupDummyAccount.php b/app/Console/Commands/SetupDummyAccount.php index 662082cc8..afa932288 100644 --- a/app/Console/Commands/SetupDummyAccount.php +++ b/app/Console/Commands/SetupDummyAccount.php @@ -18,6 +18,7 @@ use Carbon\Carbon; use Faker\Factory as Faker; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Http; class SetupDummyAccount extends Command { @@ -81,9 +82,11 @@ private function start(): void private function wipeAndMigrateDB(): void { - shell_exec('curl -X DELETE "'.config('scout.meilisearch.host').'/indexes/notes"'); - shell_exec('curl -X DELETE "'.config('scout.meilisearch.host').'/indexes/contacts"'); - shell_exec('curl -X DELETE "'.config('scout.meilisearch.host').'/indexes/groups"'); + if (config('scout.driver') === 'meilisearch' && ($host = config('scout.meilisearch.host')) !== '') { + Http::delete("$host/indexes/notes"); + Http::delete("$host/indexes/contacts"); + Http::delete("$host/indexes/groups"); + } $this->artisan('☐ Reset search engine', 'monica:setup'); $this->artisan('☐ Migration of the database', 'migrate:fresh'); $this->artisan('☐ Symlink the storage folder', 'storage:link'); @@ -124,7 +127,7 @@ private function createFirstUsers(): void ]); $this->firstUser->email_verified_at = Carbon::now(); $this->firstUser->save(); - sleep(5); + // sleep(5); } private function createVaults(): void diff --git a/app/Helpers/ScoutHelper.php b/app/Helpers/ScoutHelper.php new file mode 100644 index 000000000..987ecd010 --- /dev/null +++ b/app/Helpers/ScoutHelper.php @@ -0,0 +1,16 @@ + 'boolean', ]; + /** + * When updating a model, this method determines if we should update the search index. + * + * @return bool + */ + public function searchIndexShouldBeUpdated() + { + return ScoutHelper::searchIndexShouldBeUpdated(); + } + /** * Get the vault associated with the loan. * diff --git a/app/Models/Note.php b/app/Models/Note.php index e23ae8d34..fccfbaa34 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Helpers\ScoutHelper; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -44,6 +45,16 @@ public function toSearchableArray(): array return $array; } + /** + * When updating a model, this method determines if we should update the search index. + * + * @return bool + */ + public function searchIndexShouldBeUpdated() + { + return ScoutHelper::searchIndexShouldBeUpdated(); + } + /** * Get the contact associated with the note. * From 43d4c538b33dcdf63b7e59e5c9683c3dc81082af Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 5 Aug 2022 09:04:50 +0200 Subject: [PATCH 2/9] fix --- app/Console/Commands/SetupDummyAccount.php | 1 - app/Helpers/ScoutHelper.php | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/SetupDummyAccount.php b/app/Console/Commands/SetupDummyAccount.php index afa932288..e989ebcec 100644 --- a/app/Console/Commands/SetupDummyAccount.php +++ b/app/Console/Commands/SetupDummyAccount.php @@ -127,7 +127,6 @@ private function createFirstUsers(): void ]); $this->firstUser->email_verified_at = Carbon::now(); $this->firstUser->save(); - // sleep(5); } private function createVaults(): void diff --git a/app/Helpers/ScoutHelper.php b/app/Helpers/ScoutHelper.php index 987ecd010..e08366e9c 100644 --- a/app/Helpers/ScoutHelper.php +++ b/app/Helpers/ScoutHelper.php @@ -8,6 +8,7 @@ class ScoutHelper * When updating a model, this method determines if we should update the search index. * * @return bool + * @codeCoverageIgnore */ public static function searchIndexShouldBeUpdated() { From 2137536fe77f0b62763b692cef5e6e31122b28c7 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 5 Aug 2022 10:21:10 +0200 Subject: [PATCH 3/9] make scout work with a database engine --- .env.example | 4 ++-- app/Console/Commands/SetupApplication.php | 2 +- app/Console/Commands/SetupDummyAccount.php | 12 ++++++------ app/Helpers/ScoutHelper.php | 12 +++++++++++- app/Models/Contact.php | 6 ++---- app/Models/Group.php | 2 ++ app/Models/Note.php | 11 ++++++----- .../2020_04_25_133132_create_contacts_table.php | 8 ++++++++ .../2021_10_09_204235_create_group_table.php | 5 +++++ .../2021_10_21_013005_create_notes_table.php | 8 ++++++++ domains/Contact/ManageNotes/Services/CreateNote.php | 1 + .../Web/ViewHelpers/VaultSearchIndexViewHelper.php | 1 + 12 files changed, 53 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index 61119763c..781dc6b24 100644 --- a/.env.example +++ b/.env.example @@ -25,7 +25,7 @@ LOG_CHANNEL=stack # Drivers BROADCAST_DRIVER=log CACHE_DRIVER=file -QUEUE_CONNECTION=database +QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 @@ -51,7 +51,7 @@ MAIL_REPLY_TO_NAME="${APP_NAME}" # Read config/scout.php for more information. # Note that you have to use either Meilisearch or Algolia to enable search in # Monica. Searching requires a queue to be configured. -SCOUT_DRIVER=meilisearch +SCOUT_DRIVER=database SCOUT_QUEUE=true MEILISEARCH_HOST= MEILISEARCH_KEY= diff --git a/app/Console/Commands/SetupApplication.php b/app/Console/Commands/SetupApplication.php index dbd46ed0c..a471850ff 100644 --- a/app/Console/Commands/SetupApplication.php +++ b/app/Console/Commands/SetupApplication.php @@ -47,7 +47,7 @@ public function handle(): void $this->line('-> Creating indexes on Meilisearch. Make sure Meilisearch is running.'); - if (config('scout.driver') === 'meilisearch' && ($host = config('scout.meilisearch.host')) !== '') { + if (config('scout.driver') === 'meilisearch' && ($host = (string) config('scout.meilisearch.host')) !== '') { $client = new Client($host, config('scout.meilisearch.key')); $index = $client->index('contacts'); $index->updateFilterableAttributes([ diff --git a/app/Console/Commands/SetupDummyAccount.php b/app/Console/Commands/SetupDummyAccount.php index e989ebcec..1436f7bf7 100644 --- a/app/Console/Commands/SetupDummyAccount.php +++ b/app/Console/Commands/SetupDummyAccount.php @@ -11,6 +11,8 @@ use App\Exceptions\EntryAlreadyExistException; use App\Models\Contact; use App\Models\ContactImportantDate; +use App\Models\Group; +use App\Models\Note; use App\Models\User; use App\Models\Vault; use App\Settings\CreateAccount\Services\CreateAccount; @@ -18,7 +20,6 @@ use Carbon\Carbon; use Faker\Factory as Faker; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Http; class SetupDummyAccount extends Command { @@ -82,11 +83,10 @@ private function start(): void private function wipeAndMigrateDB(): void { - if (config('scout.driver') === 'meilisearch' && ($host = config('scout.meilisearch.host')) !== '') { - Http::delete("$host/indexes/notes"); - Http::delete("$host/indexes/contacts"); - Http::delete("$host/indexes/groups"); - } + $this->artisan('☐ Flush search engine', 'scout:flush', ['model' => Note::class]); + $this->artisan('☐ Flush search engine', 'scout:flush', ['model' => Contact::class]); + $this->artisan('☐ Flush search engine', 'scout:flush', ['model' => Group::class]); + $this->artisan('☐ Reset search engine', 'monica:setup'); $this->artisan('☐ Migration of the database', 'migrate:fresh'); $this->artisan('☐ Symlink the storage folder', 'storage:link'); diff --git a/app/Helpers/ScoutHelper.php b/app/Helpers/ScoutHelper.php index e08366e9c..35c673a4b 100644 --- a/app/Helpers/ScoutHelper.php +++ b/app/Helpers/ScoutHelper.php @@ -12,6 +12,16 @@ class ScoutHelper */ public static function searchIndexShouldBeUpdated() { - return (config('scout.driver') === 'algolia' && config('scout.algolia.id') !== '') || (config('scout.driver') === 'meilisearch' && config('scout.meilisearch.host') !== ''); + switch (config('scout.driver')) { + case 'algolia': + return config('scout.algolia.id') !== ''; + case 'meilisearch': + return config('scout.meilisearch.host') !== ''; + case 'database': + case 'collection': + return true; + default: + return false; + } } } diff --git a/app/Models/Contact.php b/app/Models/Contact.php index dc4005cde..d4cb1866c 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -66,6 +66,8 @@ class Contact extends Model * * @return array */ + #[SearchUsingPrefix(['id', 'vault_id'])] + #[SearchUsingFullText(['first_name', 'last_name', 'middle_name', 'nickname', 'maiden_name'])] public function toSearchableArray(): array { return [ @@ -76,10 +78,6 @@ public function toSearchableArray(): array 'middle_name' => $this->middle_name, 'nickname' => $this->nickname, 'maiden_name' => $this->maiden_name, - 'url' => route('contact.show', [ - 'vault' => $this->vault_id, - 'contact' => $this->id, - ]), ]; } diff --git a/app/Models/Group.php b/app/Models/Group.php index d2ac6bcdd..49a573658 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -33,6 +33,8 @@ class Group extends Model * * @return array */ + #[SearchUsingPrefix(['id', 'vault_id'])] + #[SearchUsingFullText(['name'])] public function toSearchableArray(): array { return [ diff --git a/app/Models/Note.php b/app/Models/Note.php index fccfbaa34..9d8b0dc85 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -21,6 +21,7 @@ class Note extends Model */ protected $fillable = [ 'contact_id', + 'vault_id', 'author_id', 'emotion_id', 'title', @@ -32,17 +33,17 @@ class Note extends Model * * @return array */ + #[SearchUsingPrefix(['id', 'vault_id'])] + #[SearchUsingFullText(['title', 'body'])] public function toSearchableArray(): array { - $array = [ + return [ 'id' => $this->id, - 'vault_id' => $this->contact->vault_id, - 'contact_id' => $this->contact->id, + 'vault_id' => $this->vault_id, + 'contact_id' => $this->contact_id, 'title' => $this->title, 'body' => $this->body, ]; - - return $array; } /** diff --git a/database/migrations/2020_04_25_133132_create_contacts_table.php b/database/migrations/2020_04_25_133132_create_contacts_table.php index b0e419537..e2fa78dea 100644 --- a/database/migrations/2020_04_25_133132_create_contacts_table.php +++ b/database/migrations/2020_04_25_133132_create_contacts_table.php @@ -28,11 +28,19 @@ public function up() $table->boolean('listed')->default(true); $table->datetime('last_updated_at')->nullable(); $table->timestamps(); + $table->foreign('vault_id')->references('id')->on('vaults')->onDelete('cascade'); $table->foreign('gender_id')->references('id')->on('genders')->onDelete('set null'); $table->foreign('pronoun_id')->references('id')->on('pronouns')->onDelete('set null'); $table->foreign('template_id')->references('id')->on('templates')->onDelete('set null'); $table->foreign('company_id')->references('id')->on('companies')->onDelete('set null'); + + if (config('scout.driver') === 'database' && in_array(DB::connection()->getDriverName(), ['mysql', 'pgsql'])) { + $table->fullText('first_name'); + $table->fullText('middle_name'); + $table->fullText('nickname'); + $table->fullText('maiden_name'); + } }); Schema::create('user_vault', function (Blueprint $table) { diff --git a/database/migrations/2021_10_09_204235_create_group_table.php b/database/migrations/2021_10_09_204235_create_group_table.php index b91078aaa..e1ba552d3 100644 --- a/database/migrations/2021_10_09_204235_create_group_table.php +++ b/database/migrations/2021_10_09_204235_create_group_table.php @@ -37,8 +37,13 @@ public function up() $table->unsignedBigInteger('group_type_id'); $table->string('name'); $table->timestamps(); + $table->foreign('vault_id')->references('id')->on('vaults')->onDelete('cascade'); $table->foreign('group_type_id')->references('id')->on('group_types')->onDelete('cascade'); + + if (config('scout.driver') === 'database' && in_array(DB::connection()->getDriverName(), ['mysql', 'pgsql'])) { + $table->fullText('name'); + } }); Schema::create('contact_group', function (Blueprint $table) { diff --git a/database/migrations/2021_10_21_013005_create_notes_table.php b/database/migrations/2021_10_21_013005_create_notes_table.php index da5caa413..bdc51e262 100644 --- a/database/migrations/2021_10_21_013005_create_notes_table.php +++ b/database/migrations/2021_10_21_013005_create_notes_table.php @@ -14,14 +14,22 @@ public function up() Schema::create('notes', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('contact_id'); + $table->unsignedBigInteger('vault_id'); $table->unsignedBigInteger('author_id')->nullable(); $table->unsignedBigInteger('emotion_id')->nullable(); $table->string('title')->nullable(); $table->text('body'); $table->timestamps(); + $table->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade'); + $table->foreign('vault_id')->references('id')->on('vaults')->onDelete('cascade'); $table->foreign('author_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('emotion_id')->references('id')->on('emotions')->onDelete('set null'); + + if (config('scout.driver') === 'database' && in_array(DB::connection()->getDriverName(), ['mysql', 'pgsql'])) { + $table->fullText('title'); + $table->fullText('body'); + } }); } diff --git a/domains/Contact/ManageNotes/Services/CreateNote.php b/domains/Contact/ManageNotes/Services/CreateNote.php index 19fff1679..3e0f63341 100644 --- a/domains/Contact/ManageNotes/Services/CreateNote.php +++ b/domains/Contact/ManageNotes/Services/CreateNote.php @@ -67,6 +67,7 @@ public function execute(array $data): Note $this->note = Note::create([ 'contact_id' => $this->contact->id, + 'vault_id' => $data['vault_id'], 'author_id' => $this->author->id, 'title' => $this->valueOrNull($data, 'title'), 'body' => $data['body'], diff --git a/domains/Vault/Search/Web/ViewHelpers/VaultSearchIndexViewHelper.php b/domains/Vault/Search/Web/ViewHelpers/VaultSearchIndexViewHelper.php index 414ac052e..c5b96d401 100644 --- a/domains/Vault/Search/Web/ViewHelpers/VaultSearchIndexViewHelper.php +++ b/domains/Vault/Search/Web/ViewHelpers/VaultSearchIndexViewHelper.php @@ -40,6 +40,7 @@ private static function contacts(Vault $vault, string $term): Collection 'vault' => $contact->vault_id, 'contact' => $contact->id, ]), + ]; }); From a6f2959ffa88e69c02d23b512695b19b0e83d72d Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 5 Aug 2022 13:23:27 +0200 Subject: [PATCH 4/9] fix --- app/Console/Commands/SetupApplication.php | 2 +- app/Listeners/LocaleUpdatedListener.php | 19 ------------------- app/Models/Contact.php | 2 ++ app/Models/Group.php | 2 ++ app/Models/Note.php | 2 ++ app/Providers/EventServiceProvider.php | 6 ------ database/factories/NoteFactory.php | 2 ++ 7 files changed, 9 insertions(+), 26 deletions(-) delete mode 100644 app/Listeners/LocaleUpdatedListener.php diff --git a/app/Console/Commands/SetupApplication.php b/app/Console/Commands/SetupApplication.php index a471850ff..dbd46ed0c 100644 --- a/app/Console/Commands/SetupApplication.php +++ b/app/Console/Commands/SetupApplication.php @@ -47,7 +47,7 @@ public function handle(): void $this->line('-> Creating indexes on Meilisearch. Make sure Meilisearch is running.'); - if (config('scout.driver') === 'meilisearch' && ($host = (string) config('scout.meilisearch.host')) !== '') { + if (config('scout.driver') === 'meilisearch' && ($host = config('scout.meilisearch.host')) !== '') { $client = new Client($host, config('scout.meilisearch.key')); $index = $client->index('contacts'); $index->updateFilterableAttributes([ diff --git a/app/Listeners/LocaleUpdatedListener.php b/app/Listeners/LocaleUpdatedListener.php deleted file mode 100644 index c0f2f49fe..000000000 --- a/app/Listeners/LocaleUpdatedListener.php +++ /dev/null @@ -1,19 +0,0 @@ -set('cashier.currency_locale', $event->locale); - } -} diff --git a/app/Models/Contact.php b/app/Models/Contact.php index d4cb1866c..86192d4c3 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -13,6 +13,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Facades\Auth; +use Laravel\Scout\Attributes\SearchUsingFullText; +use Laravel\Scout\Attributes\SearchUsingPrefix; use Laravel\Scout\Searchable; class Contact extends Model diff --git a/app/Models/Group.php b/app/Models/Group.php index 49a573658..a9073c58c 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -8,6 +8,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\MorphOne; +use Laravel\Scout\Attributes\SearchUsingFullText; +use Laravel\Scout\Attributes\SearchUsingPrefix; use Laravel\Scout\Searchable; class Group extends Model diff --git a/app/Models/Note.php b/app/Models/Note.php index 9d8b0dc85..45eaf030b 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphOne; +use Laravel\Scout\Attributes\SearchUsingFullText; +use Laravel\Scout\Attributes\SearchUsingPrefix; use Laravel\Scout\Searchable; class Note extends Model diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 3695decac..9d2f333ea 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -4,12 +4,9 @@ use App\Contact\ManageDocuments\Events\FileDeleted; use App\Contact\ManageDocuments\Listeners\DeleteFileInStorage; -use App\Listeners\LocaleUpdatedListener; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; -use Illuminate\Foundation\Events\LocaleUpdated; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -use Illuminate\Support\Facades\Event; class EventServiceProvider extends ServiceProvider { @@ -22,9 +19,6 @@ class EventServiceProvider extends ServiceProvider Registered::class => [ SendEmailVerificationNotification::class, ], - LocaleUpdated::class => [ - LocaleUpdatedListener::class, - ], FileDeleted::class => [ DeleteFileInStorage::class, ], diff --git a/database/factories/NoteFactory.php b/database/factories/NoteFactory.php index 4a04bf02c..6766b1483 100644 --- a/database/factories/NoteFactory.php +++ b/database/factories/NoteFactory.php @@ -5,6 +5,7 @@ use App\Models\Contact; use App\Models\Note; use App\Models\User; +use App\Models\Vault; use Illuminate\Database\Eloquent\Factories\Factory; class NoteFactory extends Factory @@ -25,6 +26,7 @@ public function definition() { return [ 'contact_id' => Contact::factory(), + 'vault_id' => Vault::factory(), 'author_id' => User::factory(), 'title' => $this->faker->title(), 'body' => $this->faker->sentence(), From 3b25dd40e86552cd2ea7363f0b94b4da0703f472 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 5 Aug 2022 13:48:16 +0200 Subject: [PATCH 5/9] use scout database driver --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 7c21a572f..18de7cfda 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -22,6 +22,6 @@ - + From 40dae153aae12f354ee032521b35a0dbcba77ae6 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 5 Aug 2022 14:00:19 +0200 Subject: [PATCH 6/9] ignore coverage --- app/Models/Contact.php | 1 + app/Models/Group.php | 1 + app/Models/Note.php | 1 + phpunit.xml | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Models/Contact.php b/app/Models/Contact.php index 86192d4c3..d2234ac93 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -67,6 +67,7 @@ class Contact extends Model * Get the indexable data array for the model. * * @return array + * @codeCoverageIgnore */ #[SearchUsingPrefix(['id', 'vault_id'])] #[SearchUsingFullText(['first_name', 'last_name', 'middle_name', 'nickname', 'maiden_name'])] diff --git a/app/Models/Group.php b/app/Models/Group.php index a9073c58c..f7045a499 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -34,6 +34,7 @@ class Group extends Model * Get the indexable data array for the model. * * @return array + * @codeCoverageIgnore */ #[SearchUsingPrefix(['id', 'vault_id'])] #[SearchUsingFullText(['name'])] diff --git a/app/Models/Note.php b/app/Models/Note.php index 45eaf030b..bff4e80cb 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -34,6 +34,7 @@ class Note extends Model * Get the indexable data array for the model. * * @return array + * @codeCoverageIgnore */ #[SearchUsingPrefix(['id', 'vault_id'])] #[SearchUsingFullText(['title', 'body'])] diff --git a/phpunit.xml b/phpunit.xml index 18de7cfda..7c21a572f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -22,6 +22,6 @@ - + From 7994fe88237efc0d783777287b3ccaf804079ab8 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 5 Aug 2022 14:14:58 +0200 Subject: [PATCH 7/9] rename method --- app/Helpers/ScoutHelper.php | 2 +- app/Models/Contact.php | 2 +- app/Models/Group.php | 2 +- app/Models/Loan.php | 2 +- app/Models/Note.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Helpers/ScoutHelper.php b/app/Helpers/ScoutHelper.php index 35c673a4b..552eda13d 100644 --- a/app/Helpers/ScoutHelper.php +++ b/app/Helpers/ScoutHelper.php @@ -10,7 +10,7 @@ class ScoutHelper * @return bool * @codeCoverageIgnore */ - public static function searchIndexShouldBeUpdated() + public static function activated() { switch (config('scout.driver')) { case 'algolia': diff --git a/app/Models/Contact.php b/app/Models/Contact.php index d2234ac93..39089f923 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -115,7 +115,7 @@ protected static function boot(): void */ public function searchIndexShouldBeUpdated() { - return ScoutHelper::searchIndexShouldBeUpdated(); + return ScoutHelper::activated(); } /** diff --git a/app/Models/Group.php b/app/Models/Group.php index f7045a499..88ef63c6b 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -54,7 +54,7 @@ public function toSearchableArray(): array */ public function searchIndexShouldBeUpdated() { - return ScoutHelper::searchIndexShouldBeUpdated(); + return ScoutHelper::activated(); } /** diff --git a/app/Models/Loan.php b/app/Models/Loan.php index 4b6746937..cd07fd0e4 100644 --- a/app/Models/Loan.php +++ b/app/Models/Loan.php @@ -65,7 +65,7 @@ class Loan extends Model */ public function searchIndexShouldBeUpdated() { - return ScoutHelper::searchIndexShouldBeUpdated(); + return ScoutHelper::activated(); } /** diff --git a/app/Models/Note.php b/app/Models/Note.php index bff4e80cb..55d50eaaa 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -56,7 +56,7 @@ public function toSearchableArray(): array */ public function searchIndexShouldBeUpdated() { - return ScoutHelper::searchIndexShouldBeUpdated(); + return ScoutHelper::activated(); } /** From 879f263d4da63610792678ee937c8802958e74a8 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 5 Aug 2022 14:16:24 +0200 Subject: [PATCH 8/9] consistency --- .../Vault/Search/Web/ViewHelpers/VaultSearchIndexViewHelper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/domains/Vault/Search/Web/ViewHelpers/VaultSearchIndexViewHelper.php b/domains/Vault/Search/Web/ViewHelpers/VaultSearchIndexViewHelper.php index c5b96d401..414ac052e 100644 --- a/domains/Vault/Search/Web/ViewHelpers/VaultSearchIndexViewHelper.php +++ b/domains/Vault/Search/Web/ViewHelpers/VaultSearchIndexViewHelper.php @@ -40,7 +40,6 @@ private static function contacts(Vault $vault, string $term): Collection 'vault' => $contact->vault_id, 'contact' => $contact->id, ]), - ]; }); From b51ba77ea11eb74c1b0c3adab53446fddd1fdf18 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 5 Aug 2022 14:23:19 +0200 Subject: [PATCH 9/9] fix coverage --- app/Console/Commands/SetupApplication.php | 15 +++------------ app/Console/Commands/SetupDummyAccount.php | 10 ---------- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/app/Console/Commands/SetupApplication.php b/app/Console/Commands/SetupApplication.php index dbd46ed0c..2d6569d05 100644 --- a/app/Console/Commands/SetupApplication.php +++ b/app/Console/Commands/SetupApplication.php @@ -21,20 +21,11 @@ class SetupApplication extends Command */ protected $description = 'Setup everything that is needed for Monica to work'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * * @return void + * @codeCoverageIgnore */ public function handle(): void { @@ -45,9 +36,9 @@ public function handle(): void $this->line('|'); $this->line('-----------------------------'); - $this->line('-> Creating indexes on Meilisearch. Make sure Meilisearch is running.'); - if (config('scout.driver') === 'meilisearch' && ($host = config('scout.meilisearch.host')) !== '') { + $this->line('-> Creating indexes on Meilisearch. Make sure Meilisearch is running.'); + $client = new Client($host, config('scout.meilisearch.key')); $index = $client->index('contacts'); $index->updateFilterableAttributes([ diff --git a/app/Console/Commands/SetupDummyAccount.php b/app/Console/Commands/SetupDummyAccount.php index 1436f7bf7..b67d16e69 100644 --- a/app/Console/Commands/SetupDummyAccount.php +++ b/app/Console/Commands/SetupDummyAccount.php @@ -43,16 +43,6 @@ class SetupDummyAccount extends Command */ protected $description = 'Prepare an account with fake data so users can play with it'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. *