/**
  * Handle dispatch exceptions
  *
  * @param \Magento\Framework\App\FrontController $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  *
  * @return mixed
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDispatch(\Magento\Framework\App\FrontController $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     try {
         return $proceed($request);
     } catch (\Magento\Framework\Session\Exception $e) {
         header('Location: ' . $this->_storeManager->getStore()->getBaseUrl());
         exit;
     } catch (\Magento\Store\Model\Exception $e) {
         require $this->filesystem->getPath(Filesystem::PUB_DIR) . '/errors/404.php';
         exit;
     }
 }
Beispiel #2
0
 /**
  * Checks whether the provided file can be rendered.
  *
  * Available directories which are allowed to be rendered
  * (the template file should be located under these directories):
  *  - app
  *  - design
  *
  * @param string $fileName
  * @return bool
  */
 protected function isTemplateFileValid($fileName)
 {
     $fileName = str_replace('\\', '/', $fileName);
     $themesDir = str_replace('\\', '/', $this->_filesystem->getPath(Filesystem::THEMES_DIR));
     $appDir = str_replace('\\', '/', $this->_filesystem->getPath(Filesystem::APP_DIR));
     return ($this->isPathInDirectory($fileName, $appDir) || $this->isPathInDirectory($fileName, $themesDir) || $this->isAllowSymlinks()) && $this->getRootDirectory()->isFile($this->getRootDirectory()->getRelativePath($fileName));
 }
Beispiel #3
0
 /**
  * Return newly created cache frontend instance
  *
  * @param array $options
  * @return \Magento\Framework\Cache\FrontendInterface
  */
 public function create(array $options)
 {
     $options = $this->_getExpandedOptions($options);
     foreach (array('backend_options', 'slow_backend_options') as $section) {
         if (!empty($options[$section]['cache_dir'])) {
             $directory = $this->_filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
             $directory->create($options[$section]['cache_dir']);
             $options[$section]['cache_dir'] = $directory->getAbsolutePath($options[$section]['cache_dir']);
         }
     }
     $this->_backendOptions['cache_dir'] = $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::CACHE_DIR);
     $idPrefix = isset($options['id_prefix']) ? $options['id_prefix'] : '';
     if (!$idPrefix && isset($options['prefix'])) {
         $idPrefix = $options['prefix'];
     }
     if (empty($idPrefix)) {
         $idPrefix = substr(md5($this->_filesystem->getPath(\Magento\Framework\App\Filesystem::CONFIG_DIR)), 0, 3) . '_';
     }
     $options['frontend_options']['cache_id_prefix'] = $idPrefix;
     $backend = $this->_getBackendOptions($options);
     $frontend = $this->_getFrontendOptions($options);
     // Start profiling
     $profilerTags = array('group' => 'cache', 'operation' => 'cache:create', 'frontend_type' => $frontend['type'], 'backend_type' => $backend['type']);
     \Magento\Framework\Profiler::start('cache_frontend_create', $profilerTags);
     /** @var $result \Magento\Framework\Cache\Frontend\Adapter\Zend */
     $result = $this->_objectManager->create('Magento\\Framework\\Cache\\Frontend\\Adapter\\Zend', array('frontend' => \Zend_Cache::factory($frontend['type'], $backend['type'], $frontend, $backend['options'], true, true, true)));
     $result = $this->_applyDecorators($result);
     // stop profiling
     \Magento\Framework\Profiler::stop('cache_frontend_create');
     return $result;
 }
Beispiel #4
0
 /**
  * Create Backup
  *
  * @return $this
  */
 public function scheduledBackup()
 {
     if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) {
         return $this;
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->set(true);
     }
     $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE);
     $this->_errors = array();
     try {
         $backupManager = $this->_backupFactory->create($type)->setBackupExtension($this->_backupData->getExtensionByType($type))->setTime(time())->setBackupsDir($this->_backupData->getBackupsDir());
         $this->_coreRegistry->register('backup_manager', $backupManager);
         if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) {
             $backupManager->setRootDir($this->_filesystem->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR))->addIgnorePaths($this->_backupData->getBackupIgnorePaths());
         }
         $backupManager->create();
         $message = $this->_backupData->getCreateSuccessMessageByType($type);
         $this->_logger->log($message);
     } catch (\Exception $e) {
         $this->_errors[] = $e->getMessage();
         $this->_errors[] = $e->getTrace();
         $this->_logger->log($e->getMessage(), \Zend_Log::ERR);
         $this->_logger->logException($e);
     }
     if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
         $this->maintenanceMode->set(false);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * Retrieve newly created fallback rule for static view files, such as CSS, JavaScript, images, etc.
  *
  * @return RuleInterface
  */
 protected function createViewFileRule()
 {
     $themesDir = $this->filesystem->getPath(Filesystem::THEMES_DIR);
     $modulesDir = $this->filesystem->getPath(Filesystem::MODULES_DIR);
     $libDir = $this->filesystem->getPath(Filesystem::LIB_WEB);
     return new ModularSwitch(new Composite(array(new Theme(new Composite(array(new Simple("{$themesDir}/<area>/<theme_path>/web/i18n/<locale>", array('locale')), new Simple("{$themesDir}/<area>/<theme_path>/web")))), new Simple($libDir))), new Composite(array(new Theme(new Composite(array(new Simple("{$themesDir}/<area>/<theme_path>/<namespace>_<module>/web/i18n/<locale>", array('locale')), new Simple("{$themesDir}/<area>/<theme_path>/<namespace>_<module>/web")))), new Simple("{$modulesDir}/<namespace>/<module>/view/<area>/web/i18n/<locale>", array('locale')), new Simple("{$modulesDir}/<namespace>/<module>/view/base/web/i18n/<locale>", array('locale')), new Simple("{$modulesDir}/<namespace>/<module>/view/<area>/web"), new Simple("{$modulesDir}/<namespace>/<module>/view/base/web"))));
 }
Beispiel #6
0
 /**
  * Return Media base dir
  *
  * @return string
  */
 public function getMediaBaseDir()
 {
     if (null === $this->_mediaBaseDirectory) {
         $mediaDir = $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::MEDIA_DIR);
         $this->_mediaBaseDirectory = rtrim($mediaDir, '\\/');
     }
     return $this->_mediaBaseDirectory;
 }
Beispiel #7
0
 /**
  * Process exception
  *
  * @param \Exception $exception
  * @param array $params
  * @return void
  */
 public function processException(\Exception $exception, array $params = array())
 {
     if ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
         parent::processException($exception, $params);
     } else {
         $reportData = array($exception->getMessage(), $exception->getTraceAsString()) + $params;
         // retrieve server data
         if (isset($_SERVER)) {
             if (isset($_SERVER['REQUEST_URI'])) {
                 $reportData['url'] = $_SERVER['REQUEST_URI'];
             }
             if (isset($_SERVER['SCRIPT_NAME'])) {
                 $reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
             }
         }
         require_once $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::PUB_DIR) . '/errors/report.php';
     }
 }
Beispiel #8
0
 /**
  * Get list of available fonts.
  *
  * Return format:
  * [['arial'] => ['label' => 'Arial', 'path' => '/www/magento/fonts/arial.ttf']]
  *
  * @return array
  */
 public function getFonts()
 {
     $fontsConfig = $this->_config->getValue(\Magento\Captcha\Helper\Data::XML_PATH_CAPTCHA_FONTS, 'default');
     $fonts = array();
     if ($fontsConfig) {
         $libDir = $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::LIB_INTERNAL);
         foreach ($fontsConfig as $fontName => $fontConfig) {
             $fonts[$fontName] = array('label' => $fontConfig['label'], 'path' => $libDir . '/' . $fontConfig['path']);
         }
     }
     return $fonts;
 }
Beispiel #9
0
 /**
  * Retrieve writable full paths for checking
  *
  * @return array
  */
 public function getWritableFullPathsForCheck()
 {
     $data = $this->_dataStorage->get();
     $paths = array();
     $items = isset($data['filesystem_prerequisites']) && isset($data['filesystem_prerequisites']['writables']) ? $data['filesystem_prerequisites']['writables'] : array();
     foreach ($items as $nodeKey => $item) {
         $value = $item;
         $value['path'] = $this->filesystem->getPath($nodeKey);
         $paths[$nodeKey] = $value;
     }
     return $paths;
 }
Beispiel #10
0
 /**
  * Handle for any other errors
  *
  * @param Bootstrap $bootstrap
  * @param \Exception $exception
  * @return bool
  */
 private function handleGenericReport(Bootstrap $bootstrap, \Exception $exception)
 {
     $reportData = array($exception->getMessage(), $exception->getTraceAsString());
     $params = $bootstrap->getParams();
     if (isset($params['REQUEST_URI'])) {
         $reportData['url'] = $params['REQUEST_URI'];
     }
     if (isset($params['SCRIPT_NAME'])) {
         $reportData['script_name'] = $params['SCRIPT_NAME'];
     }
     require $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php';
     return true;
 }
Beispiel #11
0
 /**
  * {@inheritdoc}
  *
  * @return $this|string
  */
 public function compactValue($value)
 {
     if ($this->getIsAjaxRequest()) {
         return $this;
     }
     $attribute = $this->getAttribute();
     $original = $this->_value;
     $toDelete = false;
     if ($original) {
         if (!$attribute->isRequired() && !empty($value['delete'])) {
             $toDelete = true;
         }
         if (!empty($value['tmp_name'])) {
             $toDelete = true;
         }
     }
     $path = $this->_fileSystem->getPath(\Magento\Framework\App\Filesystem::MEDIA_DIR) . '/' . $this->_entityTypeCode;
     $result = $original;
     // unlink entity file
     if ($toDelete) {
         $result = '';
         $file = $path . $original;
         $ioFile = new \Magento\Framework\Io\File();
         if ($ioFile->fileExists($file)) {
             $ioFile->rm($file);
         }
     }
     if (!empty($value['tmp_name'])) {
         try {
             $uploader = new \Magento\Framework\File\Uploader($value);
             $uploader->setFilesDispersion(true);
             $uploader->setFilenamesCaseSensitivity(false);
             $uploader->setAllowRenameFiles(true);
             $uploader->save($path, $value['name']);
             $fileName = $uploader->getUploadedFileName();
             $result = $fileName;
         } catch (\Exception $e) {
             $this->_logger->logException($e);
         }
     }
     return $result;
 }
Beispiel #12
0
 /**
  * Run application
  *
  * @return ResponseInterface
  */
 public function launch()
 {
     try {
         $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
         $this->_state->setAreaCode($areaCode);
         $this->_objectManager->configure($this->_configLoader->load($areaCode));
         $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
         // This event gives possibility to launch something before sending output (allow cookie setting)
         $eventParams = array('request' => $this->_request, 'response' => $this->_response);
         $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
     } catch (\Exception $exception) {
         $message = $exception->getMessage() . "\n";
         try {
             if ($this->_state->getMode() == State::MODE_DEVELOPER) {
                 $message .= '<pre>';
                 $message .= $exception->getMessage() . "\n\n";
                 $message .= $exception->getTraceAsString();
                 $message .= '</pre>';
             } else {
                 $reportData = array($exception->getMessage(), $exception->getTraceAsString());
                 // retrieve server data
                 if (isset($_SERVER)) {
                     if (isset($_SERVER['REQUEST_URI'])) {
                         $reportData['url'] = $_SERVER['REQUEST_URI'];
                     }
                     if (isset($_SERVER['SCRIPT_NAME'])) {
                         $reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
                     }
                 }
                 require_once $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php';
                 $processor = new \Magento\Framework\Error\Processor($this->_response);
                 $processor->saveReport($reportData);
                 $this->_response = $processor->processReport();
             }
         } catch (\Exception $exception) {
             $message .= "Unknown error happened.";
         }
         $this->_response->setHttpResponseCode(500);
         $this->_response->setBody($message);
     }
     return $this->_response;
 }
Beispiel #13
0
 /**
  * Generate installation data and record them into local.xml using local.xml.template
  *
  * @return void
  */
 public function install()
 {
     $data = $this->getConfigData();
     $defaults = array('root_dir' => $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR), 'app_dir' => $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::APP_DIR), 'var_dir' => $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::VAR_DIR), 'base_url' => $this->_request->getDistroBaseUrl());
     foreach ($defaults as $index => $value) {
         if (!isset($data[$index])) {
             $data[$index] = $value;
         }
     }
     if (isset($data['unsecure_base_url'])) {
         $data['unsecure_base_url'] .= substr($data['unsecure_base_url'], -1) != '/' ? '/' : '';
         if (strpos($data['unsecure_base_url'], 'http') !== 0) {
             $data['unsecure_base_url'] = 'http://' . $data['unsecure_base_url'];
         }
         if (!$this->_getInstaller()->getDataModel()->getSkipBaseUrlValidation()) {
             $this->_checkUrl($data['unsecure_base_url']);
         }
     }
     if (isset($data['secure_base_url'])) {
         $data['secure_base_url'] .= substr($data['secure_base_url'], -1) != '/' ? '/' : '';
         if (strpos($data['secure_base_url'], 'http') !== 0) {
             $data['secure_base_url'] = 'https://' . $data['secure_base_url'];
         }
         if (!empty($data['use_secure']) && !$this->_getInstaller()->getDataModel()->getSkipUrlValidation()) {
             $this->_checkUrl($data['secure_base_url']);
         }
     }
     $data['date'] = self::TMP_INSTALL_DATE_VALUE;
     $data['key'] = self::TMP_ENCRYPT_KEY_VALUE;
     $data['var_dir'] = $data['root_dir'] . '/var';
     $data['use_script_name'] = isset($data['use_script_name']) ? 'true' : 'false';
     $this->_getInstaller()->getDataModel()->setConfigData($data);
     $contents = $this->_configDirectory->readFile('local.xml.template');
     foreach ($data as $index => $value) {
         $contents = str_replace('{{' . $index . '}}', '<![CDATA[' . $value . ']]>', $contents);
     }
     $this->_configDirectory->writeFile($this->_localConfigFile, $contents);
     $this->_configDirectory->changePermissions($this->_localConfigFile, 0777);
 }
Beispiel #14
0
 /**
  * @param \Magento\Framework\App\Filesystem $filesystem
  * @param string $schema
  * @param string $perFileSchema
  */
 public function __construct(\Magento\Framework\App\Filesystem $filesystem, $schema, $perFileSchema)
 {
     $this->_schema = $filesystem->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR) . '/' . $schema;
     $this->_perFileSchema = $filesystem->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR) . '/' . $perFileSchema;
 }
Beispiel #15
0
 /**
  * Return current media directory, allowed resources for get.php script, etc.
  *
  * @return array
  */
 public function getScriptConfig()
 {
     $config = array();
     $config['media_directory'] = $this->filesystem->getPath(Filesystem::MEDIA_DIR);
     $allowedResources = $this->_coreConfig->getValue(self::XML_PATH_MEDIA_RESOURCE_WHITELIST, 'default');
     foreach ($allowedResources as $allowedResource) {
         $config['allowed_resources'][] = $allowedResource;
     }
     $config['update_time'] = $this->_scopeConfig->getValue(self::XML_PATH_MEDIA_UPDATE_TIME, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     return $config;
 }
Beispiel #16
0
 /**
  * @param \Magento\Framework\App\Filesystem $appFilesystem
  */
 public function __construct(Filesystem $appFilesystem)
 {
     $this->_schema = $appFilesystem->getPath(Filesystem::LIB_INTERNAL) . '/Magento/Framework/View/PageLayout/etc/layouts.xsd';
 }
Beispiel #17
0
 /**
  * Create Db Instance
  *
  * @return \Magento\Framework\Backup\BackupInterface
  */
 protected function _createDbBackupInstance()
 {
     return $this->_backupFactory->create(\Magento\Framework\Backup\Factory::TYPE_DB)->setBackupExtension('gz')->setTime($this->getTime())->setBackupsDir($this->_filesystem->getPath(\Magento\Framework\App\Filesystem::VAR_DIR))->setResourceModel($this->getResourceModel());
 }
Beispiel #18
0
 /**
  * Test getPath returns right path
  */
 public function testGetPath()
 {
     $this->assertContains('design', $this->filesystem->getPath(\Magento\Framework\App\Filesystem::THEMES_DIR));
 }
Beispiel #19
0
 /**
  * Get paths that should be ignored when rolling back system snapshots
  *
  * @return string[]
  */
 public function getRollbackIgnorePaths()
 {
     return array('.svn', '.git', $this->_filesystem->getPath(MaintenanceMode::FLAG_DIR) . '/' . MaintenanceMode::FLAG_FILENAME, $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::SESSION_DIR), $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::LOG_DIR), $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::VAR_DIR) . '/locks', $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::VAR_DIR) . '/report', $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR) . '/errors', $this->_filesystem->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR) . '/index.php');
 }
Beispiel #20
0
 /**
  * Test getUri returns right uri
  */
 public function testGetUri()
 {
     $this->assertContains('media', $this->filesystem->getPath(\Magento\Framework\App\Filesystem::MEDIA_DIR));
 }
Beispiel #21
0
 /**
  * @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));
 }