Skip to content

Commit 175d369

Browse files
author
Marius Burkard
committed
- prevent snippets from being hidden, disabled or deleted if used by at least one website
1 parent 0ae4c0a commit 175d369

27 files changed

+140
-41
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->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: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,48 @@
4949

5050
class page_action extends tform_actions {
5151

52-
53-
public function onAfterUpdate() {
52+
private function getAffectedSites() {
5453
global $app, $conf;
5554

56-
if(isset($this->dataRecord['update_sites']) && $this->dataRecord['update_sites'] === 'y' && $this->dataRecord['active'] === 'y') {
57-
if($this->dataRecord['type'] === 'php') {
58-
$rlike = $this->dataRecord['id'].'|,'.$this->dataRecord['id'].'|'.$this->dataRecord['id'].',';
59-
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets REGEXP ? AND type = ?', $rlike, 'apache');
60-
if(is_array($affected_snippets) && !empty($affected_snippets)) {
61-
foreach($affected_snippets as $snippet) {
62-
$sql_in[] = $snippet['directive_snippets_id'];
63-
}
64-
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN ?', $conf['server_id'], $sql_in);
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'];
6561
}
66-
} elseif($this->dataRecord['type'] === 'apache' || $this->dataRecord['type'] === 'nginx') {
67-
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id = ?', $conf['server_id'], $this->dataRecord['id']);
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);
6863
}
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']);
66+
}
67+
68+
return $affected_sites;
69+
}
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->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->lng('error_hide_snippet_active_sites');
85+
}
86+
}
87+
}
88+
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();
6994

7095
if(is_array($affected_sites) && !empty($affected_sites)) {
7196
foreach($affected_sites as $site) {

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 currencly used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly used by existing websites.';

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variabler';
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 currencly used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly used by existing websites.';

interface/web/admin/lib/lang/el_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 currencly used by existing websites.';
14+
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
15+
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly used by existing websites.';

0 commit comments

Comments
 (0)