diff --git a/app/Console/Commands/MigrateDownloadsCount.php b/app/Console/Commands/MigrateDownloadsCount.php new file mode 100644 index 0000000..0c0ded2 --- /dev/null +++ b/app/Console/Commands/MigrateDownloadsCount.php @@ -0,0 +1,41 @@ +where('source_system', 'wp') + ->where('source_table', 'wp_posts') + ->where('target_table', 'entries' ) + ->get(['source_id', 'target_id']) + ; + + $updated = 0; + + foreach ($rows as $row) { + $downloadCount = DB::connection('old_wp') + ->table('postmeta') + ->where('post_id', $row->source_id) + ->where('meta_key', 'download_counter' ) + ->value('meta_value'); + + if( $downloadCount ) { + DB::table('entries')->where('id', $row->target_id)->update(['old_download_count' => intval($downloadCount)]); + $updated++; + } + } + + $this->info('All done (' . $updated . '/' . count($rows) .')'); + } +} diff --git a/app/Livewire/Database.php b/app/Livewire/Database.php index 4f44940..dc07142 100644 --- a/app/Livewire/Database.php +++ b/app/Livewire/Database.php @@ -175,6 +175,7 @@ class Database extends Component public const array SORT_OPTIONS = [ 'created_at' => 'Date added', 'release_date' => 'Release date', + 'total_downloads' => 'Total downloads', 'title' => 'Title' ]; @@ -236,7 +237,7 @@ class Database extends Component { $query = Entry::query()->published()->with([ 'game.platform', 'game.genre', 'status', 'authors', 'languages', 'level', 'systems', 'categories', 'modifications' - ]); + ])->withSum('files', 'download_count'); if( $this->search ) { $query->where(function($q) { @@ -328,7 +329,13 @@ class Database extends Component $query->where('user_id', $this->userId); } - return $query->orderBy($this->sortBy, $this->sortDir); + $sortColumn = $this->sortBy; + + if ($sortColumn === 'total_downloads') { + $sortColumn = 'files_sum_download_count'; + } + + return $query->orderBy($sortColumn, $this->sortDir); } private function searchFilter( string $modelClass, string $search ) diff --git a/app/Livewire/EntrySelector.php b/app/Livewire/EntrySelector.php index e78b74c..c3d6bfd 100644 --- a/app/Livewire/EntrySelector.php +++ b/app/Livewire/EntrySelector.php @@ -21,6 +21,7 @@ class EntrySelector extends Component if( $entry ) { $this->selectedEntryId = $oldEntryId; $this->entryName = $entry->complete_title ?? $entry->title; + $this->search = $entry->complete_title ?? $entry->title; } } } diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 65f917b..4ee1732 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -255,7 +255,7 @@ class Entry extends Model public function getTotalDownloadsAttribute(): int { - return $this->files->sum('download_count'); + return $this->files->sum('download_count') + $this->old_download_count; } public function parseStaffCredits(): ?array { diff --git a/app/Services/ActivityService.php b/app/Services/ActivityService.php index eb8396c..332e94d 100644 --- a/app/Services/ActivityService.php +++ b/app/Services/ActivityService.php @@ -213,6 +213,7 @@ class ActivityService ->join('post', 'thread.first_post_id', '=', 'post.post_id') ->where('thread.discussion_state', 'visible') ->where('thread.discussion_type', '!=', 'redirect' ) + ->where('thread.node_id', '!=', config('xenforo.comments_node_id') ) ->orderByDesc('thread.post_date') ->limit(self::ITEMS_PER_TYPE) ->select([ diff --git a/database/migrations/2026_06_29_171149_create_old_download_count_column_to_entries.php b/database/migrations/2026_06_29_171149_create_old_download_count_column_to_entries.php new file mode 100644 index 0000000..bbd97e3 --- /dev/null +++ b/database/migrations/2026_06_29_171149_create_old_download_count_column_to_entries.php @@ -0,0 +1,28 @@ +unsignedBigInteger('old_download_count')->default(0); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('entries', function (Blueprint $table) { + $table->dropColumn('old_download_count'); + }); + } +}; diff --git a/resources/views/components/gallery-field.blade.php b/resources/views/components/gallery-field.blade.php index a8f85a8..dcf22f8 100644 --- a/resources/views/components/gallery-field.blade.php +++ b/resources/views/components/gallery-field.blade.php @@ -2,7 +2,7 @@
- +
diff --git a/resources/views/components/main-image-field.blade.php b/resources/views/components/main-image-field.blade.php index 1e0dcd3..7f6f8ea 100644 --- a/resources/views/components/main-image-field.blade.php +++ b/resources/views/components/main-image-field.blade.php @@ -3,7 +3,7 @@
- +