diff --git a/app/Http/Controllers/FrontIndexController.php b/app/Http/Controllers/FrontIndexController.php index 9154475..0a94782 100644 --- a/app/Http/Controllers/FrontIndexController.php +++ b/app/Http/Controllers/FrontIndexController.php @@ -26,11 +26,17 @@ class FrontIndexController extends Controller public function start() { + //for fresh installs that dont have any source data yet + $latest_update = 'Never Run'; + if(count($this->location->getRecent()) != 0) + { + $latest_update = $this->location->getRecent()[0]->updated_at->format('Y M d'); + } return view('front.index', [ 'count' => count($this->location->getActiveLocations()), 'sources' => count($this->source->getActive()), 'recent' => $this->location->getRecent(), - 'latest_date' => $this->location->getRecent()[0]->updated_at->format('Y M d'), + 'latest_date' => $latest_update, 'title' => "The Bad Space" ]); } diff --git a/app/Models/Location.php b/app/Models/Location.php index a13d6d7..da215d0 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -38,4 +38,13 @@ class Location extends Model "archive_links", "notes", ]; + + public function scopeSearch($query, $search) + { + if (!$search) { + return $query; + } + return $query->whereRaw('searchtext @@ to_tsquery(\'english\', ?)', [$search]) + ->orderByRaw('ts_rank(searchtext, to_tsquery(\'english\', ?)) DESC', [$search]); + } } diff --git a/app/Repositories/LocationRepository.php b/app/Repositories/LocationRepository.php index f654b44..f335223 100644 --- a/app/Repositories/LocationRepository.php +++ b/app/Repositories/LocationRepository.php @@ -23,7 +23,8 @@ class LocationRepository $rawSearch = $terms; $terms = str_replace(",", "", $terms); $terms = str_replace(" ", "|", $terms); - $raw = DB::select("SELECT * FROM searchlocations(?)", [$terms]); + //$raw = DB::select("SELECT * FROM searchlocations(?)", [$terms]); + $raw = Location::search($terms)->get(); $results = []; foreach ($raw as $item) { if (($item->block_count + $item->silence_count) >= 2) { diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php deleted file mode 100644 index 444fafb..0000000 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ /dev/null @@ -1,32 +0,0 @@ -id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('users'); - } -}; diff --git a/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php b/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php deleted file mode 100644 index 81a7229..0000000 --- a/database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php +++ /dev/null @@ -1,28 +0,0 @@ -string('email')->primary(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('password_reset_tokens'); - } -}; diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php deleted file mode 100644 index 249da81..0000000 --- a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php +++ /dev/null @@ -1,32 +0,0 @@ -id(); - $table->string('uuid')->unique(); - $table->text('connection'); - $table->text('queue'); - $table->longText('payload'); - $table->longText('exception'); - $table->timestamp('failed_at')->useCurrent(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('failed_jobs'); - } -}; diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php deleted file mode 100644 index e828ad8..0000000 --- a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ /dev/null @@ -1,33 +0,0 @@ -id(); - $table->morphs('tokenable'); - $table->string('name'); - $table->string('token', 64)->unique(); - $table->text('abilities')->nullable(); - $table->timestamp('last_used_at')->nullable(); - $table->timestamp('expires_at')->nullable(); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('personal_access_tokens'); - } -}; diff --git a/database/migrations/2025_04_15_180833_create_location_table.php b/database/migrations/2025_04_15_180833_create_location_table.php new file mode 100644 index 0000000..3ade50f --- /dev/null +++ b/database/migrations/2025_04_15_180833_create_location_table.php @@ -0,0 +1,57 @@ +bigIncrements('id'); + $table->uuid('uuid'); + $table->string('name', length: 255); + $table->string('url', length: 255); + $table->text('public_comments'); + $table->json('images')->nullable(); + $table->boolean('active'); + $table->string('rating', length: 255); + $table->integer('added_by'); + $table->timestamps(precision: 0); + $table->timestamp('deleted_at', precision: 0)->nullable(); + $table->string('tags', length: 255); + $table->integer('block_count')->nullable(); + $table->integer('silence_count')->nullable(); + $table->integer('actions_count')->nullable(); + $table->text('archive_links')->nullable(); + $table->json('block_vote')->nullable(); + $table->json('silence_vote')->nullable(); + $table->text('notes')->nullable(); + }); + + DB::statement("ALTER TABLE location ADD COLUMN searchtext TSVECTOR"); + DB::statement("UPDATE location SET searchtext = to_tsvector('english', name)"); + DB::statement("UPDATE location SET searchtext = to_tsvector('english', url)"); + DB::statement("UPDATE location SET searchtext = to_tsvector('english', public_comments)"); + DB::statement("UPDATE location SET searchtext = to_tsvector('english', tags)"); + DB::statement("CREATE INDEX searchtext_gin ON location USING GIN(searchtext)"); + DB::statement("CREATE TRIGGER ts_searchtext BEFORE INSERT OR UPDATE ON location FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('searchtext', 'pg_catalog.english', 'name', 'url', 'public_comments', 'tags')"); + } + + //'name', 'url', 'public_comments', 'tags' + + /** + * Reverse the migrations. + */ + public function down(): void + { + DB::statement("DROP TRIGGER IF EXISTS tsvector_update_trigger ON location"); + DB::statement("DROP INDEX IF EXISTS searchtext_gin"); + DB::statement("ALTER TABLE location DROP COLUMN searchtext"); + Schema::dropIfExists('location'); + } +}; diff --git a/database/migrations/2025_04_15_183002_create_member_table.php b/database/migrations/2025_04_15_183002_create_member_table.php new file mode 100644 index 0000000..fad14e6 --- /dev/null +++ b/database/migrations/2025_04_15_183002_create_member_table.php @@ -0,0 +1,37 @@ +bigIncrements('id'); + $table->uuid('uuid'); + $table->string('handle', length: 255); + $table->string('email', length: 255); + $table->string('password', length: 255); + $table->string('avatar', length: 255)->nullable(); + $table->string('pronoun', length: 255); + $table->string('gender', length: 255)->nullable(); + $table->boolean('active'); + $table->integer('role')->nullable(); + $table->timestamp('created_at', precision: 0); + $table->timestamp('last_login', precision: 0); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('member'); + } +}; diff --git a/database/migrations/2025_04_15_183923_create_source_table.php b/database/migrations/2025_04_15_183923_create_source_table.php new file mode 100644 index 0000000..019fe45 --- /dev/null +++ b/database/migrations/2025_04_15_183923_create_source_table.php @@ -0,0 +1,34 @@ +bigIncrements('id'); + $table->string('url', length: 255); + $table->string('type', length: 255); + $table->boolean('active'); + $table->integer('admin_id')->nullable(); + $table->string('format', length: 255); + $table->string('token', length: 255)->nullable(); + $table->timestamp('last_updated', precision: 0)->nullable(); + $table->json('list_data')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('source'); + } +}; diff --git a/database/migrations/2025_04_15_184832_create_appeal_table.php b/database/migrations/2025_04_15_184832_create_appeal_table.php new file mode 100644 index 0000000..4eeb4d8 --- /dev/null +++ b/database/migrations/2025_04_15_184832_create_appeal_table.php @@ -0,0 +1,35 @@ +bigIncrements('id'); + $table->uuid('uuid'); + $table->string('location', length: 255); + $table->string('location_admin', length: 255); + $table->string('sponsor', length: 255); + $table->text('description'); + $table->boolean('reviewed')->default(false); + $table->boolean('approved')->default(false); + $table->timestamps(precision: 0); + $table->timestamp('deleted_at', precision: 0)->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('appeal'); + } +};