make(Illuminate\Contracts\Console\Kernel::class); $kernel->bootstrap(); use Illuminate\Support\Facades\DB; function out($s) { echo $s . PHP_EOL; } try { $default = DB::table('forum_posts')->where('topic_id', 309)->count(); out('default: ' . $default); } catch (Throwable $e) { out('default: ERROR - ' . $e->getMessage()); } try { $legacy = DB::connection('legacy')->table('forum_posts')->where('topic_id', 309)->count(); out('legacy: ' . $legacy); } catch (Throwable $e) { out('legacy: ERROR - ' . $e->getMessage()); } // Also check new forum_posts table (if different name) try { $new = DB::table('forum_posts')->where('thread_id', 309)->count(); out('default(thread_id=): ' . $new); } catch (Throwable $e) {} // check forum_threads existence try { $threads = DB::table('forum_threads')->where('id', 309)->exists(); out('forum_threads has 309: ' . ($threads ? 'yes' : 'no')); } catch (Throwable $e) {} try { $threadRow = DB::table('forum_threads')->where('id', 309)->first(); out('thread row: ' . json_encode($threadRow)); } catch (Throwable $e) { out('thread row: ERROR - ' . $e->getMessage()); } try { $totalPosts = DB::table('forum_posts')->count(); out('forum_posts total: ' . $totalPosts); } catch (Throwable $e) { out('forum_posts total: ERROR - ' . $e->getMessage()); } try { $top = DB::table('forum_posts') ->select('thread_id', DB::raw('count(*) as cnt')) ->groupBy('thread_id') ->orderByDesc('cnt') ->limit(10) ->get(); out('top thread_id counts: ' . json_encode($top)); } catch (Throwable $e) { out('top thread_id counts: ERROR - ' . $e->getMessage()); } try { foreach ($top as $row) { $t = DB::table('forum_threads')->where('id', $row->thread_id)->first(); out('thread ' . $row->thread_id . ' -> ' . ($t ? ($t->title ?? $t->topic ?? 'no-title') : 'missing')); } } catch (Throwable $e) { out('thread title lookup: ERROR - ' . $e->getMessage()); } try { $matches = DB::table('forum_threads')->where('title', 'like', '%General Art%')->orWhere('slug', 'like', '%general-art%')->limit(10)->get(); out('threads matching General Art: ' . json_encode($matches)); } catch (Throwable $e) { out('threads matching: ERROR - ' . $e->getMessage()); } exit(0);