/** * Execute the console command. * * @param Search $search * @param IndexManager $manager * @param StreamRepositoryInterface $streams */ public function fire(Search $search, IndexManager $manager, StreamRepositoryInterface $streams, EntryRepositoryInterface $repository) { $stream = $this->argument('stream'); list($namespace, $slug) = explode('.', $stream); if (!($stream = $streams->findBySlugAndNamespace($slug, $namespace))) { $this->error('Stream [' . $this->argument('stream') . '] could not be found.'); return; } /* @var EntryModel $model */ $repository->setModel($model = $stream->getEntryModel()); /** * If the stream is empty we can't * really index it. */ if (!($entry = $repository->first())) { $this->error('Stream [' . $this->argument('stream') . '] is empty.'); } /** * If the stream does not have a valid * search configuration then we don't * know how to insert it's entries. */ if (!($config = $this->dispatch(new GetConfig($entry)))) { $this->error('Stream [' . $this->argument('stream') . '] does not have a search configuration.'); } $this->info('Deleting ' . $this->argument('stream')); $search->search('stream', $stream)->delete(); $this->info('Rebuilding ' . $this->argument('stream')); $this->output->progressStart($repository->count()); foreach ($repository->all() as $entry) { $manager->insert($entry, $config); $this->output->progressAdvance(); } $this->output->progressFinish(); }
/** * Execute the console command. * * @param ModuleCollection $modules * @param Repository $config * @param Search $search * @param Kernel $console */ public function fire(ModuleCollection $modules, Repository $config, Search $search, Kernel $console) { $stream = $this->argument('stream'); if (!$stream) { $this->info('Destroying index'); $console->call('search:destroy'); } else { $this->info('Deleting ' . $stream); $search->search('stream', $stream)->delete(); } /* @var Module $module */ foreach ($modules->withConfig('search') as $module) { foreach ($config->get($module->getNamespace('search')) as $model => $search) { /* @var EntryModel $model */ $model = new $model(); if (!$stream || $stream == $model->getStreamNamespace() . '.' . $model->getStreamSlug()) { $this->info('Rebuilding ' . $stream); $this->output->progressStart($model->count()); foreach ($model->all() as $entry) { $entry->save(); $this->output->progressAdvance(); } $this->output->progressFinish(); } } } }