backendAuthSession = $backendAuthSession; $this->config = $config; $this->cache = $cache; $this->productMetadata = $productMetadata; $this->getEnabledStoresUrls = $getEnabledStoresUrls; $this->extensionInformationList = $extensionInformationList; $this->extensionAuthorizationRepository = $extensionAuthorizationRepository; $this->isEnabledOnAnyStoreView = $isEnabledOnAnyStoreView; $this->getTrueCustomerKey = $getTrueCustomerKey; $this->authorizationKey = $authorizationKey; $this->externalConnector = $externalConnector; $this->calculateStatus = $calculateStatus; $this->extensionAuthorizationFactory = $extensionAuthorizationFactory; $this->updateStatus = $updateStatus; $this->disableExtension = $disableExtension; $this->getInstallType = $getInstallType; $this->magentoUtil = $magentoUtil; } /** * Reindex installed extensions. * * @return void * @throws \Magento\Framework\Exception\LocalizedException */ public function execute(): void { $time = time(); $session = $this->backendAuthSession; $cacheKey = 'Plumrocket_base_reindex'; if (! $session->isLoggedIn() || (86400 + $session->getPBProductReindex() > $time) || (86400 + ((int) $this->cache->load($cacheKey)) > $time) ) { if (! $this->config->isDebugMode()) { return; } } $data = [ 'edition' => $this->productMetadata->getEdition(), 'products' => [], 'base_urls' => $this->getEnabledStoresUrls->execute(), 'platform' => 'm2', 'magento_version' => $this->productMetadata->getVersion(), 'php_version' => $this->magentoUtil->getTrimmedPhpVersion(), ]; $activeModules = []; foreach ($this->extensionInformationList->getList()->getItems() as $extensionInformation) { $moduleName = $extensionInformation->getModuleName(); try { $isCached = $this->extensionAuthorizationRepository->get($moduleName)->isCached(); } catch (NoSuchEntityException $e) { $isCached = false; } if ($isCached || ! $this->isEnabledOnAnyStoreView->execute($moduleName)) { continue; } $activeModules[$moduleName] = $moduleName; $data['products'][$moduleName] = [ $moduleName, $extensionInformation->getInstalledVersion(), $this->getTrueCustomerKey->execute($moduleName) ?: 0, $this->authorizationKey->get($moduleName) ?: 0, $extensionInformation->getTitle(), $this->getInstallType->execute($moduleName), ]; } if (count($activeModules)) { try { $xml = $this->externalConnector->connect('https://' . Urls::PINGBACK_URL . '/extensions/', $data); if (! isset($xml['statuses'])) { throw new LocalizedException(__('Statuses are missing.'), null, 1); } $statuses = $xml['statuses']; } catch (Exception $e) { if ($this->config->isDebugMode()) { throw new LocalizedException(__($e->getMessage()), null, 1); } $statuses = []; foreach ($activeModules as $moduleName) { $statuses[$moduleName] = $this->calculateStatus->execute($moduleName); } } foreach ($activeModules as $moduleName) { try { $authorization = $this->extensionAuthorizationRepository->get($moduleName); } catch (NoSuchEntityException $e) { $authorization = $this->extensionAuthorizationFactory->create($moduleName); } $status = $statuses[$moduleName] ?? 301; $authorization = $this->updateStatus->execute($authorization, $status); if (! $authorization->isAuthorized()) { $this->disableExtension->execute($authorization->getModuleName()); } } } $this->cache->save($time, $cacheKey); $session->setPBProductReindex($time); } }