Commit 906679dd authored by Till Brehm's avatar Till Brehm
Browse files

Merge branch '5785-directive-snippets-not-saved-and-not-applied' into 'develop'

Resolve "Directive snippets not saved and not applied"

Closes #5785

See merge request ispconfig/ispconfig3!1230
parents c7e58bf9 b886fe24
Pipeline #5535 passed with stage
in 9 seconds
......@@ -45,7 +45,31 @@ require_once '../../lib/app.inc.php';
//* Check permissions for module
$app->auth->check_module_permissions('admin');
$app->uses("tform_actions");
$app->tform_actions->onDelete();
$app->load("tform_actions");
class page_action extends tform_actions {
function onBeforeDelete() {
global $app, $conf;
if($this->dataRecord['type'] === 'php') {
$rlike = $this->dataRecord['directive_snippets_id'].'|,'.$this->dataRecord['directive_snippets_id'].'|'.$this->dataRecord['directive_snippets_id'].',';
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets REGEXP ? AND type = ?', $rlike, 'apache');
if(is_array($affected_snippets) && !empty($affected_snippets)) {
foreach($affected_snippets as $snippet) {
$sql_in[] = $snippet['directive_snippets_id'];
}
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN ?', $conf['server_id'], $sql_in);
}
} elseif($this->dataRecord['type'] === 'apache' || $this->dataRecord['type'] === 'nginx') {
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id = ?', $conf['server_id'], $this->dataRecord['directive_snippets_id']);
}
if(!empty($affected_sites)) {
$app->error($app->tform->lng('error_delete_snippet_active_sites'));
}
}
}
$page = new page_action();
$page->onDelete();
?>
......@@ -49,81 +49,58 @@ $app->uses('tpl,tform,tform_actions');
class page_action extends tform_actions {
function onShow() {
private function getAffectedSites() {
global $app, $conf;
if($this->id > 0){
$record = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ?", $this->id);
if($record['master_directive_snippets_id'] > 0){
unset($app->tform->formDef["tabs"]['directive_snippets']['fields']['name'], $app->tform->formDef["tabs"]['directive_snippets']['fields']['type'], $app->tform->formDef["tabs"]['directive_snippets']['fields']['snippet'], $app->tform->formDef["tabs"]['directive_snippets']['fields']['required_php_snippets']);
if($this->dataRecord['type'] === 'php') {
$rlike = $this->dataRecord['id'].'|,'.$this->dataRecord['id'].'|'.$this->dataRecord['id'].',';
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets REGEXP ? AND type = ?', $rlike, 'apache');
if(is_array($affected_snippets) && !empty($affected_snippets)) {
foreach($affected_snippets as $snippet) {
$sql_in[] = $snippet['directive_snippets_id'];
}
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN ?', $conf['server_id'], $sql_in);
}
unset($record);
} elseif($this->dataRecord['type'] === 'apache' || $this->dataRecord['type'] === 'nginx') {
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id = ?', $conf['server_id'], $this->dataRecord['id']);
}
parent::onShow();
return $affected_sites;
}
function onShowEnd() {
global $app, $conf;
$is_master = false;
if($this->id > 0){
if($this->dataRecord['master_directive_snippets_id'] > 0){
$is_master = true;
$app->tpl->setVar("name", $this->dataRecord['name'], true);
$app->tpl->setVar("type", $this->dataRecord['type'], true);
$app->tpl->setVar("snippet", $this->dataRecord['snippet'], true);
public function onBeforeUpdate() {
global $app;
$oldRecord = $app->tform->getDataRecord($this->id);
if($this->dataRecord['active'] !== 'y' && $oldRecord['active'] === 'y') {
$affected_sites = $this->getAffectedSites();
if(!empty($affected_sites)) {
$app->tform->errorMessage .= $app->tform->lng('error_disable_snippet_active_sites');
}
} elseif($this->dataRecord['customer_viewable'] !== 'y' && $oldRecord['customer_viewable'] === 'y') {
$affected_sites = $this->getAffectedSites();
if(!empty($affected_sites)) {
$app->tform->errorMessage .= $app->tform->lng('error_hide_snippet_active_sites');
}
}
$app->tpl->setVar("is_master", $is_master);
parent::onShowEnd();
}
function onSubmit() {
global $app, $conf;
if($this->id > 0){
$record = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ?", $this->id);
if($record['master_directive_snippets_id'] > 0){
unset($app->tform->formDef["tabs"]['directive_snippets']['fields']['name'], $app->tform->formDef["tabs"]['directive_snippets']['fields']['type'], $app->tform->formDef["tabs"]['directive_snippets']['fields']['snippet'], $app->tform->formDef["tabs"]['directive_snippets']['fields']['required_php_snippets']);
}
if(isset($this->dataRecord['update_sites'])) {
parent::onSubmit();
} else {
$app->db->query('UPDATE directive_snippets SET name = ?, type = ?, snippet = ?, customer_viewable = ?, required_php_snippets = ?, active = ? WHERE directive_snippets_id = ?', $this->dataRecord['name'], $this->dataRecord['type'], $this->dataRecord['snippet'], $this->dataRecord['customer_viewable'], implode(',', $this->dataRecord['required_php_snippets']), $this->dataRecord['active'], $this->id);
if($_REQUEST["next_tab"] == '') {
$list_name = $_SESSION["s"]["form"]["return_to"];
if($list_name != '' && $_SESSION["s"]["list"][$list_name]["parent_name"] != $app->tform->formDef["name"]) {
$redirect = "Location: ".$_SESSION["s"]["list"][$list_name]["parent_script"]."?id=".$_SESSION["s"]["list"][$list_name]["parent_id"]."&next_tab=".$_SESSION["s"]["list"][$list_name]["parent_tab"];
$_SESSION["s"]["form"]["return_to"] = '';
session_write_close();
header($redirect);
} elseif (isset($_SESSION["s"]["form"]["return_to_url"]) && $_SESSION["s"]["form"]["return_to_url"] != '') {
$redirect = $_SESSION["s"]["form"]["return_to_url"];
$_SESSION["s"]["form"]["return_to_url"] = '';
session_write_close();
header("Location: ".$redirect);
exit;
} else {
header("Location: ".$app->tform->formDef['list_default']);
}
exit;
public function onAfterUpdate() {
global $app;
if(isset($this->dataRecord['update_sites']) && $this->dataRecord['update_sites'] === 'y' && $this->dataRecord['active'] === 'y') {
$affected_sites = $this->getAffectedSites();
if(is_array($affected_sites) && !empty($affected_sites)) {
foreach($affected_sites as $site) {
$website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $site['domain_id']);
$app->db->datalogUpdate('web_domain', $website, 'domain_id', $site['domain_id'], true);
}
}
unset($record);
}
parent::onSubmit();
}
}
$page = new page_action;
$page->onLoad();
?>
$page->onLoad();
\ No newline at end of file
......@@ -57,8 +57,6 @@ class list_action extends listform_actions {
//* Alternating datarow colors
$this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
$rec['bgcolor'] = $this->DataRowColor;
$rec['is_master'] = $rec['master_directive_snippets_id'];
//* substitute value for select fields
if(is_array($app->listform->listDef['item']) && count($app->listform->listDef['item']) > 0) {
......@@ -79,15 +77,8 @@ class list_action extends listform_actions {
$rec['id'] = $rec[$this->idx_key];
return $rec;
}
}
$list = new list_action;
$list->SQLOrderBy = 'ORDER BY directive_snippets.name';
$list->onLoad();
//$app->listform_actions->SQLExtWhere = 'master_directive_snippets_id = 0';
/*
$app->listform_actions->SQLOrderBy = 'ORDER BY directive_snippets.name';
$app->listform_actions->onLoad();
*/
?>
......@@ -66,7 +66,7 @@ $form["tabs"]['directive_snippets'] = array (
'name' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'validators' => array (
'validators' => array (
0 => array ( 'type' => 'NOTEMPTY', 'errmsg'=> 'directive_snippets_name_empty'),
1 => array ( 'type' => 'CUSTOM', 'class' => 'validate_server_directive_snippets', 'function' => 'validate_snippet'),
),
......@@ -121,7 +121,7 @@ $form["tabs"]['directive_snippets'] = array (
'formtype' => 'CHECKBOXARRAY',
'default' => '',
'datasource' => array ( 'type' => 'SQL',
'querystring' => "SELECT directive_snippets_id,name FROM directive_snippets WHERE type = 'php' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name",
'querystring' => "SELECT directive_snippets_id,name FROM directive_snippets WHERE type = 'php' AND active = 'y' ORDER BY name",
'keyfield' => 'directive_snippets_id',
'valuefield' => 'name'
),
......
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variáveis';
$wb['customer_viewable_txt'] = 'Visualização personalizada';
$wb['required_php_snippets_txt'] = 'Trecho de código exige php';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Proměnné';
$wb['customer_viewable_txt'] = 'Dostupná volba pro klienta';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variablen';
$wb['customer_viewable_txt'] = 'Sichtbar für Kunden';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variabler';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
\ No newline at end of file
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['type_txt'] = 'Tipo';
$wb['variables_txt'] = 'Variables';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Varijable';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variabili';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment