Skip to content

Commit 160b172

Browse files
jaapmarcusV4M0N0S
andauthored
Allow PHP template selection of apps (hestiacp#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 hestiacp#2711 Check if database was created successfully Co-authored-by: V4M0N0S <65557634+V4M0N0S@users.noreply.github.com>
1 parent a8a5294 commit 160b172

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

web/src/app/System/HestiaApp.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,15 @@ public function databaseAdd(string $dbname, string $dbuser, string $dbpass, stri
188188
unlink($v_password);
189189
return $status;
190190
}
191-
191+
192+
public function getCurrentBackendTemplate(string $domain){
193+
$status = $this->runUser('v-list-web-domain', [$domain, 'json'],$return_message);
194+
$version = $return_message -> json[$domain]['BACKEND'];
195+
$test= preg_match('/^.*PHP-([0-9])\_([0-9])/',$version, $match);
196+
return $match[1].'.'.$match[2];
197+
198+
}
199+
192200
public function changeWebTemplate(string $domain, string $template)
193201
{
194202
$status = $this->runUser('v-change-web-domain-tpl', [$domain, $template]);
@@ -226,9 +234,9 @@ public function getSupportedPHP($support)
226234
$supported_versions[] = $version;
227235
}
228236
}
229-
if ($supported) {
230-
return $supported_versions[count($supported_versions) - 1];
231-
} else {
237+
if($supported){
238+
return $supported_versions;
239+
}else{
232240
return false;
233241
}
234242
}

web/src/app/WebApp/AppWizard.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function formNs()
6464
public function getOptions()
6565
{
6666
$options = $this->appsetup->getOptions();
67+
68+
$config = $this->appsetup -> getConfig();
69+
$options = array_merge($options, array('php_version' => ['type' => 'select', 'value' => $this->appcontext->getCurrentBackendTemplate($this -> domain), 'options' => $this->appcontext->getSupportedPHP($config['server']['php']['supported'])]));
70+
6771
if ($this->appsetup->withDatabase()) {
6872
$options = array_merge($options, $this->database_config);
6973
}

web/src/app/WebApp/Installers/BaseSetup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function setup(array $options=null)
123123
throw new \Exception('Required PHP version is not supported');
124124
}
125125
//convert from x.x to PHP-x_x to accepted..
126-
$this -> appcontext -> changeBackendTemplate($this -> domain, 'PHP-'.str_replace('.', '_', $php_version));
126+
$this -> appcontext -> changeBackendTemplate($this -> domain, 'PHP-'.str_replace('.', '_', $options['php_version']));
127127
}
128128
}
129129
}

web/src/app/WebApp/Installers/Wordpress/WordpressSetup.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ public function install(array $options = null)
118118
. "&admin_password2=". rawurlencode($options['wordpress_account_password'])
119119
. "&admin_email=" . rawurlencode($options['wordpress_account_email'])
120120
), $output, $return_var);
121-
121+
122+
if ( strpos(implode(PHP_EOL,$output),'Error establishing a database connection' !== false)){
123+
throw new \Exception('Error establishing a database connection');
124+
}
122125

123126
if ($return_var > 0) {
124127
throw new \Exception(implode(PHP_EOL, $output));

web/templates/pages/setup_webapp.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
<?php if( !$WebappInstaller->isDomainRootClean()): ?>
3434
<span class="alert alert-info alert-with-icon">
3535
<i class="fas fa-info"></i>
36-
<?=_('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');?>
36+
<?=_('Data loss warning!');?><br /><br />
37+
<?=_('Your web folder already has files uploaded to it. The installer will overwrite your files and / or the installation might fail.');?><br /><br />
38+
<?php echo sprintf(_('Please make sure ~/web/%s/public_html is empty!'),$v_domain);?>
3739
</span>
3840
<br />
3941
<?php endif; ?>

0 commit comments

Comments
 (0)