Commit 175d3690 authored by Marius Burkard's avatar Marius Burkard
Browse files

- prevent snippets from being hidden, disabled or deleted if used by at least one website

parent 0ae4c0ac
Pipeline #5529 passed with stage
in 7 minutes and 21 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->lng('error_delete_snippet_active_sites'));
}
}
}
$page = new page_action();
$page->onDelete();
?>
......@@ -49,23 +49,48 @@ $app->uses('tpl,tform,tform_actions');
class page_action extends tform_actions {
public function onAfterUpdate() {
private function getAffectedSites() {
global $app, $conf;
if(isset($this->dataRecord['update_sites']) && $this->dataRecord['update_sites'] === 'y' && $this->dataRecord['active'] === 'y') {
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);
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'];
}
} 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']);
$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['id']);
}
return $affected_sites;
}
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->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->lng('error_hide_snippet_active_sites');
}
}
}
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) {
......
......@@ -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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly used by existing websites.';
\ No newline at end of file
......@@ -10,4 +10,6 @@ $wb['variables_txt'] = 'Variabelen';
$wb['customer_viewable_txt'] = 'Zichtbaar voor klanten';
$wb['required_php_snippets_txt'] = 'Vereiste 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 currencly used by existing websites.';
$wb['error_disable_snippet_active_sites'] = 'You cannot disable this snippet as it is currencly used by existing websites.';
$wb['error_delete_snippet_active_sites'] = 'You cannot delete this snippet as it is currencly 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