Skip to content

Commit 906679d

Browse files
author
Till Brehm
committed
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
2 parents c7e58bf + b886fe2 commit 906679d

38 files changed

+185
-341
lines changed

interface/web/admin/directive_snippets_del.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,31 @@
4545
//* Check permissions for module
4646
$app->auth->check_module_permissions('admin');
4747

48-
$app->uses("tform_actions");
49-
$app->tform_actions->onDelete();
48+
$app->load("tform_actions");
49+
50+
class page_action extends tform_actions {
51+
function onBeforeDelete() {
52+
global $app, $conf;
53+
54+
if($this->dataRecord['type'] === 'php') {
55+
$rlike = $this->dataRecord['directive_snippets_id'].'|,'.$this->dataRecord['directive_snippets_id'].'|'.$this->dataRecord['directive_snippets_id'].',';
56+
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets REGEXP ? AND type = ?', $rlike, 'apache');
57+
if(is_array($affected_snippets) && !empty($affected_snippets)) {
58+
foreach($affected_snippets as $snippet) {
59+
$sql_in[] = $snippet['directive_snippets_id'];
60+
}
61+
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN ?', $conf['server_id'], $sql_in);
62+
}
63+
} elseif($this->dataRecord['type'] === 'apache' || $this->dataRecord['type'] === 'nginx') {
64+
$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']);
65+
}
66+
67+
if(!empty($affected_sites)) {
68+
$app->error($app->tform->lng('error_delete_snippet_active_sites'));
69+
}
70+
}
71+
}
72+
73+
$page = new page_action();
74+
$page->onDelete();
5075

51-
?>

interface/web/admin/directive_snippets_edit.php

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -49,81 +49,58 @@
4949

5050
class page_action extends tform_actions {
5151

52-
function onShow() {
52+
private function getAffectedSites() {
5353
global $app, $conf;
54-
55-
if($this->id > 0){
56-
$record = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ?", $this->id);
57-
if($record['master_directive_snippets_id'] > 0){
58-
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']);
54+
55+
if($this->dataRecord['type'] === 'php') {
56+
$rlike = $this->dataRecord['id'].'|,'.$this->dataRecord['id'].'|'.$this->dataRecord['id'].',';
57+
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets REGEXP ? AND type = ?', $rlike, 'apache');
58+
if(is_array($affected_snippets) && !empty($affected_snippets)) {
59+
foreach($affected_snippets as $snippet) {
60+
$sql_in[] = $snippet['directive_snippets_id'];
61+
}
62+
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN ?', $conf['server_id'], $sql_in);
5963
}
60-
unset($record);
64+
} elseif($this->dataRecord['type'] === 'apache' || $this->dataRecord['type'] === 'nginx') {
65+
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id = ?', $conf['server_id'], $this->dataRecord['id']);
6166
}
62-
63-
parent::onShow();
67+
68+
return $affected_sites;
6469
}
65-
66-
function onShowEnd() {
67-
global $app, $conf;
68-
69-
$is_master = false;
70-
if($this->id > 0){
71-
if($this->dataRecord['master_directive_snippets_id'] > 0){
72-
$is_master = true;
73-
$app->tpl->setVar("name", $this->dataRecord['name'], true);
74-
$app->tpl->setVar("type", $this->dataRecord['type'], true);
75-
$app->tpl->setVar("snippet", $this->dataRecord['snippet'], true);
70+
71+
public function onBeforeUpdate() {
72+
global $app;
73+
74+
$oldRecord = $app->tform->getDataRecord($this->id);
75+
76+
if($this->dataRecord['active'] !== 'y' && $oldRecord['active'] === 'y') {
77+
$affected_sites = $this->getAffectedSites();
78+
if(!empty($affected_sites)) {
79+
$app->tform->errorMessage .= $app->tform->lng('error_disable_snippet_active_sites');
80+
}
81+
} elseif($this->dataRecord['customer_viewable'] !== 'y' && $oldRecord['customer_viewable'] === 'y') {
82+
$affected_sites = $this->getAffectedSites();
83+
if(!empty($affected_sites)) {
84+
$app->tform->errorMessage .= $app->tform->lng('error_hide_snippet_active_sites');
7685
}
7786
}
78-
79-
$app->tpl->setVar("is_master", $is_master);
80-
81-
parent::onShowEnd();
8287
}
83-
84-
function onSubmit() {
85-
global $app, $conf;
8688

87-
if($this->id > 0){
88-
$record = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ?", $this->id);
89-
if($record['master_directive_snippets_id'] > 0){
90-
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']);
91-
}
92-
93-
if(isset($this->dataRecord['update_sites'])) {
94-
parent::onSubmit();
95-
} else {
96-
$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);
97-
98-
if($_REQUEST["next_tab"] == '') {
99-
$list_name = $_SESSION["s"]["form"]["return_to"];
100-
if($list_name != '' && $_SESSION["s"]["list"][$list_name]["parent_name"] != $app->tform->formDef["name"]) {
101-
$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"];
102-
$_SESSION["s"]["form"]["return_to"] = '';
103-
session_write_close();
104-
header($redirect);
105-
} elseif (isset($_SESSION["s"]["form"]["return_to_url"]) && $_SESSION["s"]["form"]["return_to_url"] != '') {
106-
$redirect = $_SESSION["s"]["form"]["return_to_url"];
107-
$_SESSION["s"]["form"]["return_to_url"] = '';
108-
session_write_close();
109-
header("Location: ".$redirect);
110-
exit;
111-
} else {
112-
header("Location: ".$app->tform->formDef['list_default']);
113-
}
114-
exit;
89+
public function onAfterUpdate() {
90+
global $app;
91+
92+
if(isset($this->dataRecord['update_sites']) && $this->dataRecord['update_sites'] === 'y' && $this->dataRecord['active'] === 'y') {
93+
$affected_sites = $this->getAffectedSites();
94+
95+
if(is_array($affected_sites) && !empty($affected_sites)) {
96+
foreach($affected_sites as $site) {
97+
$website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $site['domain_id']);
98+
$app->db->datalogUpdate('web_domain', $website, 'domain_id', $site['domain_id'], true);
11599
}
116100
}
117-
118-
unset($record);
119101
}
120-
121-
parent::onSubmit();
122102
}
123-
124103
}
125104

126105
$page = new page_action;
127-
$page->onLoad();
128-
129-
?>
106+
$page->onLoad();

interface/web/admin/directive_snippets_list.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public function prepareDataRow($rec)
5757
//* Alternating datarow colors
5858
$this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
5959
$rec['bgcolor'] = $this->DataRowColor;
60-
61-
$rec['is_master'] = $rec['master_directive_snippets_id'];
6260

6361
//* substitute value for select fields
6462
if(is_array($app->listform->listDef['item']) && count($app->listform->listDef['item']) > 0) {
@@ -79,15 +77,8 @@ public function prepareDataRow($rec)
7977
$rec['id'] = $rec[$this->idx_key];
8078
return $rec;
8179
}
82-
80+
8381
}
8482
$list = new list_action;
8583
$list->SQLOrderBy = 'ORDER BY directive_snippets.name';
8684
$list->onLoad();
87-
88-
//$app->listform_actions->SQLExtWhere = 'master_directive_snippets_id = 0';
89-
/*
90-
$app->listform_actions->SQLOrderBy = 'ORDER BY directive_snippets.name';
91-
$app->listform_actions->onLoad();
92-
*/
93-
?>

interface/web/admin/form/directive_snippets.tform.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
'name' => array (
6767
'datatype' => 'VARCHAR',
6868
'formtype' => 'TEXT',
69-
'validators' => array (
69+
'validators' => array (
7070
0 => array ( 'type' => 'NOTEMPTY', 'errmsg'=> 'directive_snippets_name_empty'),
7171
1 => array ( 'type' => 'CUSTOM', 'class' => 'validate_server_directive_snippets', 'function' => 'validate_snippet'),
7272
),
@@ -121,7 +121,7 @@
121121
'formtype' => 'CHECKBOXARRAY',
122122
'default' => '',
123123
'datasource' => array ( 'type' => 'SQL',
124-
'querystring' => "SELECT directive_snippets_id,name FROM directive_snippets WHERE type = 'php' AND active = 'y' AND master_directive_snippets_id = 0 ORDER BY name",
124+
'querystring' => "SELECT directive_snippets_id,name FROM directive_snippets WHERE type = 'php' AND active = 'y' ORDER BY name",
125125
'keyfield' => 'directive_snippets_id',
126126
'valuefield' => 'name'
127127
),

interface/web/admin/lib/lang/ar_directive_snippets.lng

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
1010
$wb['customer_viewable_txt'] = 'Customer viewable';
1111
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
1212
$wb['update_sites_txt'] = 'Update sites using this snippet';
13-
?>
13+
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';

interface/web/admin/lib/lang/bg_directive_snippets.lng

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
1010
$wb['customer_viewable_txt'] = 'Customer viewable';
1111
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
1212
$wb['update_sites_txt'] = 'Update sites using this snippet';
13-
?>
13+
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';

interface/web/admin/lib/lang/br_directive_snippets.lng

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variáveis';
1010
$wb['customer_viewable_txt'] = 'Visualização personalizada';
1111
$wb['required_php_snippets_txt'] = 'Trecho de código exige php';
1212
$wb['update_sites_txt'] = 'Update sites using this snippet';
13-
?>
13+
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';

interface/web/admin/lib/lang/ca_directive_snippets.lng

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variables';
1010
$wb['customer_viewable_txt'] = 'Customer viewable';
1111
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
1212
$wb['update_sites_txt'] = 'Update sites using this snippet';
13-
?>
13+
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';

interface/web/admin/lib/lang/cz_directive_snippets.lng

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Proměnné';
1010
$wb['customer_viewable_txt'] = 'Dostupná volba pro klienta';
1111
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
1212
$wb['update_sites_txt'] = 'Update sites using this snippet';
13-
?>
13+
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';

interface/web/admin/lib/lang/de_directive_snippets.lng

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variablen';
1010
$wb['customer_viewable_txt'] = 'Sichtbar für Kunden';
1111
$wb['required_php_snippets_txt'] = 'Required PHP Snippet';
1212
$wb['update_sites_txt'] = 'Update sites using this snippet';
13-
?>
13+
$wb['error_hide_snippet_active_sites'] = 'You cannot hide this snippet from customers as it is currently used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currently used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currently used by existing websites.';

0 commit comments

Comments
 (0)