Просмотр исходного кода

Allow PHP template selection of apps (#2713)

* Update setup_webapp.html

a clearer description of the process / error

* Allow users to select php version

* Update setup_webapp.html

* Update dataloss warning

* Fix #2711 Check if database was created successfully

Co-authored-by: V4M0N0S <65557634+V4M0N0S@users.noreply.github.com>
Jaap Marcus 3 лет назад
Родитель
Сommit
160b172872

+ 12 - 4
web/src/app/System/HestiaApp.php

@@ -188,7 +188,15 @@ class HestiaApp
         unlink($v_password);
         return $status;
     }
-
+    
+    public function getCurrentBackendTemplate(string $domain){
+        $status = $this->runUser('v-list-web-domain', [$domain, 'json'],$return_message);
+        $version = $return_message -> json[$domain]['BACKEND'];
+        $test= preg_match('/^.*PHP-([0-9])\_([0-9])/',$version, $match);
+        return $match[1].'.'.$match[2];
+                
+    }
+    
     public function changeWebTemplate(string $domain, string $template)
     {
         $status = $this->runUser('v-change-web-domain-tpl', [$domain, $template]);
@@ -226,9 +234,9 @@ class HestiaApp
                 $supported_versions[] = $version;
             }
         }
-        if ($supported) {
-            return $supported_versions[count($supported_versions) - 1];
-        } else {
+        if($supported){
+            return $supported_versions;
+        }else{
             return false;
         }
     }

+ 4 - 0
web/src/app/WebApp/AppWizard.php

@@ -64,6 +64,10 @@ class AppWizard {
     public function getOptions()
     {
         $options = $this->appsetup->getOptions();
+        
+        $config = $this->appsetup -> getConfig();
+        $options = array_merge($options, array('php_version' => ['type' => 'select', 'value' => $this->appcontext->getCurrentBackendTemplate($this -> domain), 'options' => $this->appcontext->getSupportedPHP($config['server']['php']['supported'])]));
+        
         if ($this->appsetup->withDatabase()) {
             $options = array_merge($options, $this->database_config);
         }

+ 1 - 1
web/src/app/WebApp/Installers/BaseSetup.php

@@ -123,7 +123,7 @@ abstract class BaseSetup implements InstallerInterface
                     throw new \Exception('Required PHP version is not supported');
                 }
                 //convert from x.x to PHP-x_x  to accepted..
-                $this -> appcontext -> changeBackendTemplate($this -> domain, 'PHP-'.str_replace('.', '_', $php_version));
+                $this -> appcontext -> changeBackendTemplate($this -> domain, 'PHP-'.str_replace('.', '_', $options['php_version']));
             }
         }
     }

+ 4 - 1
web/src/app/WebApp/Installers/Wordpress/WordpressSetup.php

@@ -118,7 +118,10 @@ class WordpressSetup extends BaseSetup
             . "&admin_password2=". rawurlencode($options['wordpress_account_password'])
             . "&admin_email="    . rawurlencode($options['wordpress_account_email'])
             ), $output, $return_var);
-
+        
+        if ( strpos(implode(PHP_EOL,$output),'Error establishing a database connection' !== false)){
+           throw new \Exception('Error establishing a database connection'); 
+        }
 
         if ($return_var > 0) {
             throw new \Exception(implode(PHP_EOL, $output));

+ 3 - 1
web/templates/pages/setup_webapp.html

@@ -33,7 +33,9 @@
 				<?php if( !$WebappInstaller->isDomainRootClean()): ?>
 					<span class="alert alert-info alert-with-icon">
 						<i class="fas fa-info"></i>
-						<?=_('Data loss warning!<br>Your web domain already has files uploaded, the installer will overwrite your files and/or the installation might fail.<br/><br/> Please use the installer only for empty web domains');?>
+						<?=_('Data loss warning!');?><br /><br />
+						<?=_('Your web folder already has files uploaded to it. The installer will overwrite your files and / or the installation might fail.');?><br /><br />
+						<?php echo sprintf(_('Please make sure ~/web/%s/public_html is empty!'),$v_domain);?>
 					</span>
 					<br />
 				<?php endif; ?>