/** * Read configuration by code * * @param string $code * @return array */ public function read($code = null) { if ($this->_appState->isInstalled()) { if (empty($code)) { $store = $this->_storeManager->getStore(); } elseif ($code == \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT) { $store = $this->_storeManager->getDefaultStoreView(); } else { $store = $this->_storeFactory->create(); $store->load($code); } if (!$store->getCode()) { throw NoSuchEntityException::singleField('storeCode', $code); } $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $store->getWebsite()->getCode())->getSource(); $config = array_replace_recursive($websiteConfig, $this->_initialConfig->getData("stores|{$code}")); $collection = $this->_collectionFactory->create(array('scope' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scopeId' => $store->getId())); $dbStoreConfig = array(); foreach ($collection as $item) { $dbStoreConfig[$item->getPath()] = $item->getValue(); } $config = $this->_converter->convert($dbStoreConfig, $config); } else { $websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)->getSource(); $config = $this->_converter->convert($websiteConfig, $this->_initialConfig->getData("stores|{$code}")); } return $config; }
/** * Perform required checks before cron run * * @param \Magento\Framework\App\Cron $subject * * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @throws \Magento\Framework\Exception */ public function beforeLaunch(\Magento\Framework\App\Cron $subject) { $this->_sidResolver->setUseSessionInUrl(false); if (false == $this->_appState->isInstalled()) { throw new \Magento\Framework\Exception('Application is not installed yet, please complete the installation first.'); } }
/** * Get config value by key * * @param null|string $path * @param null|mixed $default * @return null|mixed */ public function get($path = null, $default = null) { if (!$this->_appState->isInstalled() && !in_array($this->_configScope->getCurrentScope(), array('global', 'install'))) { return $default; } return parent::get($path, $default); }
/** * Perform url rewites * * @param \Magento\Framework\App\FrontController $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if (!$this->_state->isInstalled()) { return $proceed($request); } $this->_rewriteService->applyRewrites($request); return $proceed($request); }
/** * Dispatch request * * @param \Magento\Framework\App\Action\Action $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if (!$this->_appState->isInstalled()) { $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $this->_response->setRedirect($this->_url->getUrl('install')); return $this->_response; } return $proceed($request); }
/** * Get theme model by theme path and area code * * @param string $themePath * @param string $areaCode * @return \Magento\Framework\View\Design\ThemeInterface */ public function getThemeModel($themePath, $areaCode) { if ($this->appState->isInstalled()) { $themeModel = $this->flyweightFactory->create($themePath, $areaCode); } else { $themeModel = $this->themeList->getThemeByFullPath($areaCode . '/' . $themePath); } return $themeModel; }
/** * @param \Magento\Framework\App\Action\Action $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @throws \Magento\Store\Model\Exception */ public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if ($this->_appState->isInstalled()) { if (!$this->_storeManager->getStore()->getIsActive()) { throw new \Magento\Store\Model\Exception('Current store is not active.'); } } return $proceed($request); }
/** * @param \Magento\Framework\App\FrontController $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if ($this->_appState->isInstalled() && !$this->_cache->load('data_upgrade')) { $this->_dbUpdater->updateScheme(); $this->_dbUpdater->updateData(); $this->_cache->save('true', 'data_upgrade'); } return $proceed($request); }
/** * {@inheritdoc} */ public function read($scope = null) { $activeModules = $this->_filterActiveModules(parent::read($scope)); if ($this->appState->isInstalled()) { foreach ($activeModules as $moduleConfig) { $this->dependencyManager->checkModuleDependencies($moduleConfig, $activeModules); } } return $this->_sortModules($activeModules); }
/** * Read configuration data * * @return array */ public function read() { $config = $this->_initialConfig->getData(\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT); if ($this->_appState->isInstalled()) { $collection = $this->_collectionFactory->create(array('scope' => \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)); $dbDefaultConfig = array(); foreach ($collection as $item) { $dbDefaultConfig[$item->getPath()] = $item->getValue(); } $dbDefaultConfig = $this->_converter->convert($dbDefaultConfig); $config = array_replace_recursive($config, $dbDefaultConfig); } return $config; }
/** * Clear temporary directories * * @param \Magento\Install\Controller\Index\Index $subject * @param \Magento\Framework\App\RequestInterface $request * * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch(\Magento\Install\Controller\Index\Index $subject, \Magento\Framework\App\RequestInterface $request) { if (!$this->appState->isInstalled()) { foreach ($this->varDirectory->read() as $dir) { if ($this->varDirectory->isDirectory($dir)) { try { $this->varDirectory->delete($dir); } catch (FilesystemException $exception) { $this->logger->log($exception->getMessage()); } } } } }
/** * Handle REST request * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $path = $this->_pathProcessor->process($request->getPathInfo()); $this->_request->setPathInfo($path); $this->areaList->getArea($this->_appState->getAreaCode())->load(\Magento\Framework\App\Area::PART_TRANSLATE); try { if (!$this->_appState->isInstalled()) { throw new \Magento\Webapi\Exception(__('Magento is not yet installed')); } $this->_checkPermissions(); $route = $this->_getCurrentRoute(); if ($route->isSecure() && !$this->_request->isSecure()) { throw new \Magento\Webapi\Exception(__('Operation allowed only in HTTPS')); } /** @var array $inputData */ $inputData = $this->_request->getRequestData(); $serviceMethodName = $route->getServiceMethod(); $serviceClassName = $route->getServiceClass(); $inputData = $this->_overrideParams($inputData, $route->getParameters()); $inputParams = $this->_serializer->getInputData($serviceClassName, $serviceMethodName, $inputData); $service = $this->_objectManager->get($serviceClassName); /** @var \Magento\Framework\Service\Data\AbstractObject $outputData */ $outputData = call_user_func_array([$service, $serviceMethodName], $inputParams); $outputData = $this->_processServiceOutput($outputData); if ($this->_request->getParam(PartialResponseProcessor::FILTER_PARAMETER) && is_array($outputData)) { $outputData = $this->partialResponseProcessor->filter($outputData); } $this->_response->prepareResponse($outputData); } catch (\Exception $e) { $maskedException = $this->_errorProcessor->maskException($e); $this->_response->setException($maskedException); } return $this->_response; }
/** * Check whether modules updates processing should be skipped * * @return bool */ protected function _shouldSkipProcessModulesUpdates() { if (!$this->_appState->isInstalled()) { return false; } return $this->_skipModuleUpdate; }
/** * Get storage instance * * @param array $arguments * @return \Magento\Store\Model\StoreManagerInterface * @throws \InvalidArgumentException */ public function get(array $arguments = array()) { $className = $this->_appState->isInstalled() ? $this->_installedStorageClassName : $this->_defaultStorageClassName; if (false == isset($this->_cache[$className])) { /** @var $storage \Magento\Store\Model\StoreManagerInterface */ $storage = $this->_objectManager->create($className, $arguments); if (false === $storage instanceof \Magento\Store\Model\StoreManagerInterface) { throw new \InvalidArgumentException($className . ' doesn\'t implement \\Magento\\Store\\Model\\StoreManagerInterface'); } $this->_cache[$className] = $storage; if ($className === $this->_installedStorageClassName) { $this->_reinitStores($storage, $arguments); $useSid = $this->_scopeConfig->isSetFlag(\Magento\Framework\Session\SidResolver::XML_PATH_USE_FRONTEND_SID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storage->getStore()); $this->_sidResolver->setUseSessionInUrl($useSid); $this->_eventManager->dispatch('core_app_init_current_store_after'); $store = $storage->getStore(true); $logActive = $this->_scopeConfig->isSetFlag('dev/log/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); if ($logActive || $this->_appState->getMode() === \Magento\Framework\App\State::MODE_DEVELOPER) { $logFile = $this->_scopeConfig->getValue('dev/log/file', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); $logExceptionFile = $this->_scopeConfig->getValue('dev/log/exception_file', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); $this->_log->unsetLoggers(); $this->_log->addStreamLog(\Magento\Framework\Logger::LOGGER_SYSTEM, $logFile, $this->_writerModel); $this->_log->addStreamLog(\Magento\Framework\Logger::LOGGER_EXCEPTION, $logExceptionFile, $this->_writerModel); } } } return $this->_cache[$className]; }
/** * Validate and Match Cms Page and modify request * * @param \Magento\Framework\App\RequestInterface $request * @return bool * * @SuppressWarnings(PHPMD.ExitExpression) */ public function match(\Magento\Framework\App\RequestInterface $request) { if (!$this->_appState->isInstalled()) { $this->_response->setRedirect($this->_url->getUrl('install'))->sendResponse(); exit; } $identifier = trim($request->getPathInfo(), '/'); $condition = new \Magento\Framework\Object(array('identifier' => $identifier, 'continue' => true)); $this->_eventManager->dispatch('cms_controller_router_match_before', array('router' => $this, 'condition' => $condition)); $identifier = $condition->getIdentifier(); if ($condition->getRedirectUrl()) { $this->_response->setRedirect($condition->getRedirectUrl()); $request->setDispatched(true); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request)); } if (!$condition->getContinue()) { return null; } /** @var \Magento\Cms\Model\Page $page */ $page = $this->_pageFactory->create(); $pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId()); if (!$pageId) { return null; } $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId); $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier); return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', array('request' => $request)); }
/** * Perform necessary checks for all actions * * Redirect out if system is already installed * Throw a bootstrap exception if page cannot be displayed due to mis-configured base directories * * @param RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(RequestInterface $request) { if ($this->_appState->isInstalled()) { $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true); $this->_redirect('/'); } return parent::dispatch($request); }
/** * @param State\OptionsInterface $options * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool * @param \Magento\Framework\App\State $appState * @param bool $banAll Whether all cache types are forced to be disabled */ public function __construct(State\OptionsInterface $options, \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool, \Magento\Framework\App\State $appState, $banAll = false) { $this->_options = $options; $this->_cacheFrontend = $cacheFrontendPool->get(\Magento\Framework\App\Cache\Frontend\Pool::DEFAULT_FRONTEND_ID); if ($appState->isInstalled()) { $this->_loadTypeStatuses($banAll); } }
/** * Auto-redirect to base url (without SID) if the requested url doesn't match it. * By default this feature is enabled in configuration. * * @param \Magento\Framework\App\FrontController $subject * @param callable $proceed * @param \Magento\Framework\App\RequestInterface $request * * @return \Magento\Framework\App\ResponseInterface * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request) { if ($this->_appState->isInstalled() && !$request->isPost() && $this->_isBaseUrlCheckEnabled()) { $baseUrl = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, $this->_storeManager->getStore()->isCurrentlySecure()); if ($baseUrl) { $uri = parse_url($baseUrl); if (!$this->_isBaseUrlCorrect($uri, $request)) { $redirectUrl = $this->_url->getRedirectUrl($this->_url->getUrl(ltrim($request->getPathInfo(), '/'), array('_nosid' => true))); $redirectCode = (int) $this->_scopeConfig->getValue('web/url/redirect_to_base', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) !== 301 ? 302 : 301; $response = $this->_responseFactory->create(); $response->setRedirect($redirectUrl, $redirectCode); return $response; } } } $request->setDispatched(false); return $proceed($request); }
/** * Retrieve array of allowed currencies * * @return array */ protected function _getAllowedCurrencies() { if ($this->_appState->isInstalled()) { $allowed = $this->_scopeResolver->getScope()->getAllowedCurrencies(); } else { $allowed = $this->_config->getAllowedCurrencies(); } return $allowed; }
/** * Read configuration by code * * @param string $code * @return array */ public function read($code = null) { $config = array_replace_recursive($this->_scopePool->getScope(\Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)->getSource(), $this->_initialConfig->getData("websites|{$code}")); if ($this->_appState->isInstalled()) { $website = $this->_websiteFactory->create(); $website->load($code); $collection = $this->_collectionFactory->create(array('scope' => \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES, 'scopeId' => $website->getId())); $dbWebsiteConfig = array(); foreach ($collection as $configValue) { $dbWebsiteConfig[$configValue->getPath()] = $configValue->getValue(); } $dbWebsiteConfig = $this->_converter->convert($dbWebsiteConfig); if (count($dbWebsiteConfig)) { $config = array_replace_recursive($config, $dbWebsiteConfig); } } return $config; }
/** * Validate and Match Cms Page and modify request * * @param \Magento\Framework\App\RequestInterface $request * @return mixed */ public function match(\Magento\Framework\App\RequestInterface $request) { if (!$this->appState->isInstalled()) { $this->response->setRedirect($this->url->getUrl('install'))->sendResponse(); return null; } $identifier = trim($request->getPathInfo(), '/'); $urlRewrite = $this->urlMatcher->match($identifier, $this->storeManager->getStore()->getId()); if ($urlRewrite === null) { return null; } $redirectType = $urlRewrite->getRedirectType(); if ($redirectType) { $redirectCode = $redirectType == \Magento\UrlRedirect\Model\OptionProvider::PERMANENT ? 301 : 302; $this->response->setRedirect($urlRewrite->getTargetPath(), $redirectCode); $request->setDispatched(true); return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request)); } $request->setPathInfo('/' . $urlRewrite->getTargetPath()); return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Forward', array('request' => $request)); }
/** * Check that request uses https protocol if it should. * Function redirects user to correct URL if needed. * * @param \Magento\Framework\App\RequestInterface $request * @param string $path * @return void */ protected function _checkShouldBeSecure(\Magento\Framework\App\RequestInterface $request, $path = '') { if (!$this->_appState->isInstalled() || $request->getPost()) { return; } if ($this->_shouldBeSecure($path) && !$request->isSecure()) { $url = $this->_getCurrentSecureUrl($request); if ($this->_shouldRedirectToSecure()) { $url = $this->_url->getRedirectUrl($url); } $this->_responseFactory->create()->setRedirect($url)->sendResponse(); exit; } }
/** * Retrieve translations array by strings * * @param array $strings * @param int|null $storeId * @return array */ public function getTranslationArrayByStrings(array $strings, $storeId = null) { if (!$this->_appState->isInstalled()) { return array(); } if (is_null($storeId)) { $storeId = $this->getStoreId(); } $adapter = $this->_getReadAdapter(); if (!$adapter) { return array(); } if (empty($strings)) { return array(); } $bind = array(':store_id' => $storeId); $select = $adapter->select()->from($this->getMainTable(), array('string', 'translate'))->where('string IN (?)', $strings)->where('store_id = :store_id'); return $adapter->fetchPairs($select, $bind); }
/** * Dispatch request * * @param RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(RequestInterface $request) { if (!$this->appState->isInstalled()) { parent::dispatch($request); } if (!$this->getRequest()->isDispatched()) { parent::dispatch($request); } $action = strtolower($this->getRequest()->getActionName()); $pattern = '/^(' . implode('|', $this->_getAllowedActions()) . ')$/i'; if (!preg_match($pattern, $action)) { if (!$this->_getSession()->authenticate($this)) { $this->_actionFlag->set('', 'no-dispatch', true); } } else { $this->_getSession()->setNoReferer(true); } $result = parent::dispatch($request); $this->_getSession()->unsNoReferer(false); return $result; }
/** * Dispatch SOAP request. * * @param \Magento\Framework\App\RequestInterface $request * @return \Magento\Framework\App\ResponseInterface */ public function dispatch(\Magento\Framework\App\RequestInterface $request) { $path = $this->_pathProcessor->process($request->getPathInfo()); $this->_request->setPathInfo($path); $this->areaList->getArea($this->_appState->getAreaCode())->load(\Magento\Framework\App\Area::PART_TRANSLATE); try { if (!$this->_appState->isInstalled()) { throw new WebapiException(__('Magento is not yet installed')); } if ($this->_isWsdlRequest()) { $responseBody = $this->_wsdlGenerator->generate($this->_request->getRequestedServices(), $this->_soapServer->generateUri()); $this->_setResponseContentType(self::CONTENT_TYPE_WSDL_REQUEST); $this->_setResponseBody($responseBody); } else { $this->_soapServer->handle(); } } catch (\Exception $e) { $this->_prepareErrorResponse($e); } return $this->_response; }
/** * Run application * * @return \Magento\Framework\App\ResponseInterface */ public function launch() { try { if (!$this->_applicationState->isInstalled()) { $this->_response->setHttpResponseCode(404); return $this->_response; } if (!$this->_mediaDirectory) { $config = $this->_objectManager->create('Magento\\Core\\Model\\File\\Storage\\Config', array('cacheFile' => $this->_configCacheFile)); $config->save(); $this->_mediaDirectory = str_replace($this->_workingDirectory, '', $config->getMediaDirectory()); $allowedResources = $config->getAllowedResources(); $this->_relativeFileName = str_replace($this->_mediaDirectory . '/', '', $this->_request->getPathInfo()); $isAllowed = $this->_isAllowed; if (!$isAllowed($this->_relativeFileName, $allowedResources)) { $this->_response->setHttpResponseCode(404); return $this->_response; } } if (0 !== stripos($this->_request->getPathInfo(), $this->_mediaDirectory . '/')) { $this->_response->setHttpResponseCode(404); return $this->_response; } $sync = $this->_objectManager->get('Magento\\Core\\Model\\File\\Storage\\Synchronization'); $sync->synchronize($this->_relativeFileName, $this->_request->getFilePath()); if ($this->directory->isReadable($this->directory->getRelativePath($this->_request->getFilePath()))) { $this->_response->setFilePath($this->_request->getFilePath()); } else { $this->_response->setHttpResponseCode(404); } return $this->_response; } catch (\Exception $e) { $this->_response->setHttpResponseCode(404); return $this->_response; } }
/** * Checking install status of application * * @return bool */ public function isApplicationInstalled() { return $this->_appState->isInstalled(); }
public function testIsInstalled() { $this->assertFalse($this->model->isInstalled()); $this->model->setInstallDate(strtotime('now')); $this->assertTrue($this->model->isInstalled()); }
/** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\String $stringHelper * @param \Magento\Framework\App\RequestInterface $request * @param \Magento\Framework\App\State $appState * @param \Magento\Framework\App\Filesystem $filesystem * @param string $scopeType * @param string $saveMethod * @param null|string $savePath * @param null|string $cacheLimiter * @param string $lifetimePath */ public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\String $stringHelper, \Magento\Framework\App\RequestInterface $request, \Magento\Framework\App\State $appState, \Magento\Framework\App\Filesystem $filesystem, $scopeType, $saveMethod = \Magento\Framework\Session\SaveHandlerInterface::DEFAULT_HANDLER, $savePath = null, $cacheLimiter = null, $lifetimePath = self::XML_PATH_COOKIE_LIFETIME) { $this->_scopeConfig = $scopeConfig; $this->_stringHelper = $stringHelper; $this->_httpRequest = $request; $this->_appState = $appState; $this->_filesystem = $filesystem; $this->_scopeType = $scopeType; $this->setSaveHandler($saveMethod === 'db' ? 'user' : $saveMethod); if (!$this->_appState->isInstalled() || !$savePath) { $savePath = $this->_filesystem->getPath('session'); } $this->setSavePath($savePath); if ($cacheLimiter) { $this->setOption('session.cache_limiter', $cacheLimiter); } $lifetime = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_LIFETIME, $this->_scopeType); $lifetime = is_numeric($lifetime) ? $lifetime : self::COOKIE_LIFETIME_DEFAULT; $this->setCookieLifetime($lifetime); $path = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_PATH, $this->_scopeType); if (empty($path)) { $path = $this->_httpRequest->getBasePath(); } $this->setCookiePath($path); $domain = $this->_scopeConfig->getValue(self::XML_PATH_COOKIE_DOMAIN, $this->_scopeType); $domain = empty($domain) ? $this->_httpRequest->getHttpHost() : $domain; $this->setCookieDomain((string) $domain); $this->setCookieHttpOnly($this->_scopeConfig->getValue(self::XML_PATH_COOKIE_HTTPONLY, $this->_scopeType)); }
/** * Merge layout update by handle * * @param string $handle * @return $this */ protected function _merge($handle) { $this->_fetchPackageLayoutUpdates($handle); if ($this->_appState->isInstalled()) { $this->_fetchDbLayoutUpdates($handle); } return $this; }