| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Module\UrsPromotion\Commands;
- use App\Module\UrsPromotion\Test\TestRelationCacheScript;
- use Illuminate\Console\Command;
- /**
- * URS关系缓存测试命令
- */
- class UrsTestRelationCacheCommand extends Command
- {
- protected $signature = 'urs:test-relation-cache
- {action : 测试动作 (generate|check|batch|clear|stats)}
- {--user-id= : 指定URS用户ID}
- {--users= : 指定多个URS用户ID,用逗号分隔}';
- protected $description = 'URS关系缓存测试命令';
- public function handle()
- {
- $script = new TestRelationCacheScript();
- $action = $this->argument('action');
- switch ($action) {
- case 'generate':
- $userId = $this->option('user-id');
- if (!$userId) {
- $this->error('请使用 --user-id 指定URS用户ID');
- return 1;
- }
- $result = $script->testGenerateCacheForUser((int)$userId);
- $this->info('测试完成');
- break;
- case 'check':
- $result = $script->testCheckIntegrity();
- $this->info('检查完成');
- break;
- case 'batch':
- $users = $this->option('users');
- if (!$users) {
- $this->error('请使用 --users 指定URS用户ID列表,用逗号分隔');
- return 1;
- }
- $userIds = array_map('intval', explode(',', $users));
- $result = $script->testBatchGenerate($userIds);
- $this->info('批量测试完成');
- break;
- case 'clear':
- if ($this->confirm('确定要清理所有缓存数据吗?')) {
- $script->clearAllCache();
- $this->info('清理完成');
- } else {
- $this->info('操作已取消');
- }
- break;
- case 'stats':
- $stats = $script->showCacheStats();
- $this->info('统计完成');
- break;
- default:
- $this->error('无效的动作,支持的动作: generate, check, batch, clear, stats');
- return 1;
- }
- return 0;
- }
- }
|