backendAuthSession = $backendAuthSession; $this->productMetadata = $productMetadata; $this->config = $config; $this->extensionInformationList = $extensionInformationList; $this->getTrueCustomerKey = $getTrueCustomerKey; $this->authorizationKey = $authorizationKey; $this->moduleList = $moduleList; } /** * Retrieve feed url * * @return string */ public function getFeedUrl(): string { if ($this->_feedUrl === null) { $this->_feedUrl = 'https://' . Urls::NOTIFICATIONS_URL . '/'; } // phpcs:ignore Magento2.Functions.DiscouragedFunction $domain = parse_url($this->urlBuilder->getBaseUrl(), PHP_URL_HOST) ?: ''; $url = $this->_feedUrl . 'domain/' . urlencode($domain); $modulesParams = []; foreach ($this->extensionInformationList->getList()->getItems() as $extensionInformation) { $modulesParams[] = implode(',', [ $extensionInformation->getModuleName(), $extensionInformation->getInstalledVersion(), $this->getNotificationKey($extensionInformation->getModuleName()) ]); } if (count($modulesParams)) { $url .= '/modules/' . base64_encode(implode(';', $modulesParams)); } if ($this->config->isEnabledNotifications() && $this->config->getEnabledNotificationLists()) { $url .= '/lists/' . implode('|', $this->config->getEnabledNotificationLists()); } else { $url .= '/lists/none'; } if ($this->config->isEnabledStatistic()) { $ed = $this->productMetadata->getEdition(); $url .= '/platform/' . ($ed === 'Community' ? 'm2ce' : 'm2ee'); $url .= '/edition/' . $ed; $url .= '/magento_version/' . $this->productMetadata->getVersion(); } return $url; } /** * Check feed for modification * * @return $this */ public function checkUpdate() { if (! $this->moduleList->has('Magento_AdminNotification')) { return $this; } $session = $this->backendAuthSession; $time = time(); $frequency = $this->getFrequency(); if (($frequency + $session->getMfBaseNoticeLastUpdate() > $time) || ($frequency + $this->getLastUpdate() > $time) ) { return $this; } $session->setPANLastUpdate($time); parent::checkUpdate(); return $this; } /** * Retrieve update frequency * * @return int */ public function getFrequency(): int { return 86400; } /** * Retrieve last update time * * @return int */ public function getLastUpdate(): int { return (int) $this->_cacheManager->load('plumrocket_admin_notifications_lastcheck'); } /** * Set last update time (now) * * @return $this */ public function setLastUpdate() { $this->_cacheManager->save(time(), 'plumrocket_admin_notifications_lastcheck'); return $this; } /** * Receive key * * @param string $moduleName * @return string */ public function getNotificationKey($moduleName): string { return implode(',', [ $this->getTrueCustomerKey->execute($moduleName), $this->authorizationKey->get($moduleName) ]); } }