option('misc')) { $countQuery->whereIn('categories_id', Category::OTHERS_GROUP); } elseif ($this->option('all')) { if ($this->confirm('This will reset categorization on all releases and re-categorize them all from scratch. Are you sure? (y/n)', false)) { Release::query()->where('iscategorized', 1)->update([ 'iscategorized' => 0, ]); $countQuery->where('iscategorized', 0); } else { $this->info('Reset script stopped.'); exit(); } } elseif ($this->option('group')) { $countQuery->where('groups_id', $this->option('group')); } elseif ($this->option('groups')) { $countQuery->whereIn('groups_id', explode(',', $this->option('groups'))); } elseif ($this->option('category')) { $countQuery->where('categories_id', $this->option('category')); } elseif ($this->option('categories')) { $countQuery->whereIn('categories_id', explode(',', $this->option('categories'))); } elseif ($this->option('test')) { $countQuery->where('iscategorized', 0); } else { $this->error('You must specify at least one option. See: --help'); exit(); } $count = $countQuery->count(); $cat = new CategorizationService; $results = $countQuery->select(['id', 'searchname', 'fromname', 'groups_id', 'categories_id'])->get(); $bar = $this->output->createProgressBar($count); $bar->start(); foreach ($results as $result) { $bar->advance(); $catId = $cat->determineCategory($result->groups_id, $result->searchname, $result->fromname); if ((int) $result->categories_id !== (int) $catId['categories_id']) { if ($this->option('test')) { $this->info('Would have changed '.$result->searchname.' from '.$result->categories_id.' to '.$catId['categories_id']); } else { Release::query()->where('id', $result->id)->update([ 'iscategorized' => 1, 'videos_id' => 0, 'tv_episodes_id' => 0, 'imdbid' => null, 'musicinfo_id' => null, 'consoleinfo_id' => null, 'gamesinfo_id' => 0, 'bookinfo_id' => 0, 'anidbid' => null, 'xxxinfo_id' => 0, 'categories_id' => $catId['categories_id'], ]); /** @var Category|null $newCatName */ $newCatName = Category::query()->where('id', $catId['categories_id'])->first(); $this->line(''); $this->output->writeln('ID : '.$result->id); $this->output->writeln('Release : '.$result->searchname); $this->output->writeln('Group : '.$result->group->name); // @phpstan-ignore property.notFound $oldCategoryTitle = $result->category?->parent ? ($result->category->parent->title.' -> '.$result->category->title) : ($result->category?->title ?? 'N/A'); // @phpstan-ignore property.notFound, property.notFound, property.notFound, nullsafe.neverNull $newCategoryTitle = $newCatName?->parent ? ($newCatName->parent->title.' -> '.$newCatName->title) : ($newCatName?->title ?? 'N/A'); // @phpstan-ignore nullsafe.neverNull $this->output->writeln('Category : '.$oldCategoryTitle.' '.$newCategoryTitle.''); $this->line(''); } } } $bar->finish(); } }