diff --git a/src/Controller/InfoProviderController.php b/src/Controller/InfoProviderController.php index deec8a57..cd076d67 100644 --- a/src/Controller/InfoProviderController.php +++ b/src/Controller/InfoProviderController.php @@ -31,6 +31,7 @@ use App\Services\InfoProviderSystem\ExistingPartFinder; use App\Services\InfoProviderSystem\PartInfoRetriever; use App\Services\InfoProviderSystem\ProviderRegistry; use App\Services\InfoProviderSystem\Providers\GenericWebProvider; +use App\Services\InfoProviderSystem\Providers\InfoProviderInterface; use App\Settings\AppSettings; use App\Settings\InfoProviderSystem\InfoProviderGeneralSettings; use Doctrine\ORM\EntityManagerInterface; @@ -172,10 +173,15 @@ class InfoProviderController extends AbstractController $keyword = $form->get('keyword')->getData(); $providers = $form->get('providers')->getData(); + $no_cache_search = $form->get('no_cache_search')->getData(); + $no_cache_details = $form->get('no_cache_details')->getData(); + $dtos = []; try { - $dtos = $this->infoRetriever->searchByKeyword(keyword: $keyword, providers: $providers); + $dtos = $this->infoRetriever->searchByKeyword(keyword: $keyword, providers: $providers, options: [ + InfoProviderInterface::OPTION_NO_CACHE => $no_cache_search + ]); } catch (ClientException $e) { $this->addFlash('error', t('info_providers.search.error.client_exception')); $this->addFlash('error',$e->getMessage()); @@ -207,7 +213,8 @@ class InfoProviderController extends AbstractController return $this->render('info_providers/search/part_search.html.twig', [ 'form' => $form, 'results' => $results, - 'update_target' => $update_target + 'update_target' => $update_target, + 'no_cache_details' => $no_cache_details ?? false, ]); } diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 4c7ec37f..c80afdb7 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -346,10 +346,13 @@ final class PartController extends AbstractController $this->denyAccessUnlessGranted('edit', $part); $this->denyAccessUnlessGranted('@info_providers.create_parts'); + //Force info providers to not use cache, when retrieving part details for creating a new part, because otherwise we might end up with outdated information + $no_cache = $request->query->getBoolean('no_cache', false); + //Save the old name of the target part for the template $old_name = $part->getName(); - $dto = $infoRetriever->getDetails($providerKey, $providerId); + $dto = $infoRetriever->getDetails($providerKey, $providerId, [InfoProviderInterface::OPTION_NO_CACHE => $no_cache]); $provider_part = $infoRetriever->dtoToPart($dto); $part = $partMerger->merge($part, $provider_part); diff --git a/src/Form/InfoProviderSystem/PartSearchType.php b/src/Form/InfoProviderSystem/PartSearchType.php index 9d582ca4..154c1aa3 100644 --- a/src/Form/InfoProviderSystem/PartSearchType.php +++ b/src/Form/InfoProviderSystem/PartSearchType.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace App\Form\InfoProviderSystem; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\SearchType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\FormBuilderInterface; @@ -40,8 +41,17 @@ class PartSearchType extends AbstractType 'help' => 'info_providers.search.providers.help', ]); + $builder->add('no_cache_search', CheckboxType::class, [ + 'label' => 'info_providers.no_cache_search', + 'required' => false, + ]); + $builder->add('no_cache_details', CheckboxType::class, [ + 'label' => 'info_providers.no_cache_details', + 'required' => false, + ]); + $builder->add('submit', SubmitType::class, [ 'label' => 'info_providers.search.submit' ]); } -} \ No newline at end of file +} diff --git a/src/Services/InfoProviderSystem/PartInfoRetriever.php b/src/Services/InfoProviderSystem/PartInfoRetriever.php index 53206a75..6c10f10e 100644 --- a/src/Services/InfoProviderSystem/PartInfoRetriever.php +++ b/src/Services/InfoProviderSystem/PartInfoRetriever.php @@ -80,7 +80,7 @@ final class PartInfoRetriever } /** @noinspection SlowArrayOperationsInLoopInspection */ - $results = array_merge($results, $this->searchInProvider($provider, $keyword)); + $results = array_merge($results, $this->searchInProvider($provider, $keyword, $options)); } return $results; diff --git a/templates/info_providers/search/part_search.html.twig b/templates/info_providers/search/part_search.html.twig index eac3507d..9e1f0834 100644 --- a/templates/info_providers/search/part_search.html.twig +++ b/templates/info_providers/search/part_search.html.twig @@ -33,6 +33,19 @@ +
+ +