load(); } elseif (file_exists($parentEnv . '/.env')) { $dotenv = Dotenv\Dotenv::createImmutable($parentEnv); $dotenv->load(); } require_once __DIR__ . '/database/seeds/DatabaseSeeder.php'; use App\Core\Container; use App\Services\Database\Connection; use App\Services\Database\MigrationRunner; use App\Services\Crawler\RssParser; use App\Services\Crawler\AiAnalyzer; use App\Services\Crawler\Collector; use Database\Seeds\DatabaseSeeder; use Database\Seeds\SourceSeeder; $container = new Container(); // Singletons configurations $container->singleton(Connection::class, Connection::class); $container->singleton(MigrationRunner::class, MigrationRunner::class); $container->singleton(DatabaseSeeder::class, DatabaseSeeder::class); $container->singleton(SourceSeeder::class, SourceSeeder::class); // Crawler service (needed for CLI collect command) $container->singleton(RssParser::class, RssParser::class); $container->singleton(AiAnalyzer::class, AiAnalyzer::class); $container->singleton(Collector::class, Collector::class); $args = $argv; $command = $args[1] ?? 'help'; switch ($command) { case 'migrate': echo "=== Running Migrations ===\n"; try { $runner = $container->get(MigrationRunner::class); $runner->migrate(); } catch (\Throwable $e) { echo "Migration failed: " . $e->getMessage() . "\n"; exit(1); } break; case 'seed-sources': echo "=== Seeding 100+ Data Sources ===\n"; try { $seeder = $container->get(SourceSeeder::class); $seeder->seed(); } catch (\Throwable $e) { echo "Seeding sources failed: " . $e->getMessage() . "\n"; exit(1); } break; case 'seed': echo "=== Running Database Seeder ===\n"; try { $seeder = $container->get(DatabaseSeeder::class); $seeder->seed(); } catch (\Throwable $e) { echo "Seeding failed: " . $e->getMessage() . "\n"; exit(1); } break; case 'collect': echo "=== Running Data Collector ===\n"; try { $collector = $container->get(Collector::class); $results = $collector->collectAll(); echo "\n--- Results ---\n"; echo "Sources processed: {$results['processed']}/{$results['total_sources']}\n"; echo "Errors: {$results['errors']}\n"; echo "New opportunities: {$results['new_opportunities']}\n"; echo "New organizations: {$results['new_organizations']}\n\n"; foreach ($results['details'] as $detail) { echo "[{$detail['status']}] {$detail['source']} ({$detail['type']}): "; if ($detail['status'] === 'success') { echo "{$detail['entries_found']} entries, {$detail['new_opportunities']} opps, {$detail['new_organizations']} orgs\n"; } else { echo "ERROR: {$detail['error']}\n"; } } } catch (\Throwable $e) { echo "Collection failed: " . $e->getMessage() . "\n"; exit(1); } break; case 'help': default: echo "ScoutIQ CLI Utility\n"; echo "Usage: php cli.php [command]\n\n"; echo "Commands:\n"; echo " migrate Run SQL database migrations\n"; echo " seed Seed the database with default data\n"; echo " seed-sources Seed 100+ data sources (RSS feeds)\n"; echo " collect Run data collector (RSS feeds)\n"; echo " help Show this help menu\n"; break; }