Example #1
0
 /**
  * @return array
  */
 protected function cleanCache()
 {
     $result = true;
     $message = '';
     try {
         if ($this->isInstalled()) {
             if (!empty($_REQUEST['clean_sessions'])) {
                 \Mage::app()->cleanAllSessions();
                 $message .= 'Session cleaned successfully. ';
             }
             \Mage::app()->cleanCache();
             // reinit config and apply all updates
             \Mage::app()->getConfig()->reinit();
             /** @var $updater \Magento\Framework\Module\UpdaterInterface*/
             $updater = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\\Framework\\Module\\UpdaterInterface');
             $updater->updateScheme();
             $updater->updateData();
             $message .= 'Cache cleaned successfully';
         } else {
             $result = true;
         }
     } catch (\Exception $e) {
         $result = false;
         $message = "Exception during cache and session cleaning: " . $e->getMessage();
         $this->session()->addMessage('error', $message);
     }
     if ($result && $this->_getMaintenanceFlag()) {
         $maintenance_filename = 'var/maintenance.flag';
         $config = $this->config();
         if (!$this->isWritable() && strlen($config->__get('remote_config')) > 0) {
             $ftpObj = new \Magento\Framework\Connect\Ftp();
             $ftpObj->connect($config->__get('remote_config'));
             $ftpObj->delete($maintenance_filename);
             $ftpObj->close();
         } else {
             @unlink($this->_getMaintenanceFilePath());
         }
     }
     return array('result' => $result, 'message' => $message);
 }
Example #2
0
 /**
  * Validate settings post data.
  *
  * @param array $p
  * @return string[]
  */
 public function validateConfigPost($p)
 {
     $errors = array();
     $configTestFile = 'connect.cfgt';
     $configObj = $this->connect()->getConfig();
     if ('ftp' == $p['deployment_type'] || '1' == $p['inst_protocol']) {
         /*check ftp*/
         $confFile = $configObj->downloader_path . '/' . $configTestFile;
         try {
             $ftpObj = new \Magento\Framework\Connect\Ftp();
             $ftpObj->connect($p['ftp']);
             $tempFile = tempnam(sys_get_temp_dir(), 'config');
             $serial = md5('config test file');
             $f = @fopen($tempFile, "w+");
             @fwrite($f, $serial);
             @fclose($f);
             $ret = $ftpObj->upload($confFile, $tempFile);
             //read file
             if (!$errors && is_file($configTestFile)) {
                 $size = filesize($configTestFile);
                 if (!$size) {
                     $errors[] = 'Unable to read saved settings. Please check Installation Path of FTP Connection.';
                 }
                 if (!$errors) {
                     $f = @fopen($configTestFile, "r");
                     @fseek($f, 0, SEEK_SET);
                     $contents = @fread($f, strlen($serial));
                     if ($serial != $contents) {
                         $errors[] = 'Wrong Installation Path of FTP Connection.';
                     }
                     fclose($f);
                 }
             } else {
                 $errors[] = 'Unable to read saved settings. Please check Installation Path of FTP Connection.';
             }
             $ftpObj->delete($confFile);
             $ftpObj->close();
         } catch (\Exception $e) {
             $errors[] = 'Deployment FTP Error. ' . $e->getMessage();
         }
     } else {
         $p['ftp'] = '';
     }
     if ('1' == $p['use_custom_permissions_mode']) {
         /*check permissions*/
         if (octdec(intval($p['mkdir_mode'])) < 73 || octdec(intval($p['mkdir_mode'])) > 511) {
             $errors[] = 'Folders permissions not valid. ';
         }
         if (octdec(intval($p['chmod_file_mode'])) < 73 || octdec(intval($p['chmod_file_mode'])) > 511) {
             $errors[] = 'Files permissions not valid. ';
         }
     }
     //$this->controller()->session()->addMessage('success', 'Settings has been successfully saved');
     return $errors;
 }