Fixed several bugs
This commit is contained in:
41
app/Console/Commands/MigrateDownloadsCount.php
Normal file
41
app/Console/Commands/MigrateDownloadsCount.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
#[Signature('migrate:downloads-count')]
|
||||
#[Description('Command description')]
|
||||
class MigrateDownloadsCount extends Command
|
||||
{
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$rows = DB::table('migrations_logs')
|
||||
->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) .')');
|
||||
}
|
||||
}
|
||||
@@ -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 )
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user