Skip to content

Commit fb3fba6

Browse files
committed
Prevent duplicate assignment of libraries and custom script
1 parent 3cf4587 commit fb3fba6

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/Mvc/Controller/KyteLibraryAssignmentController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ public function hook_response_data($method, $o, &$r = null, &$d = null) {
99
throw new \Exception("Cannot delete assignment for globally included libraries. This library is set to include on all pages. To remove it, either disable global inclusion in Site → Libraries or delete the library entirely.");
1010
}
1111
} else {
12+
if ($method == 'new') {
13+
$assignments = new \Kyte\Core\Model($this->model);
14+
$assignments->retrieve('library', $d['library'], false, [['field' => 'page', 'value' => $d['page']], ['field' => 'site', 'value' => $d['site']], ['field' => 'kyte_account', 'value' => $this->account]]);
15+
if ($assignments->count > 0) {
16+
throw new \Exception("This library is already assigned to the specified page or site.");
17+
}
18+
}
1219
if (isset($r['page'], $r['page']['header'], $r['page']['footer'])) {
1320
$r['page']['header'] = null;
1421
$r['page']['footer'] = null;

src/Mvc/Controller/KyteScriptAssignmentController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ public function hook_response_data($method, $o, &$r = null, &$d = null) {
99
throw new \Exception("Cannot delete assignment for globally included script. This script is set to include on all pages. To remove it, either disable global inclusion in Site → Custom Scripts or delete the script entirely.");
1010
}
1111
} else {
12+
if ($method == 'new') {
13+
$assignments = new \Kyte\Core\Model($this->model);
14+
$assignments->retrieve('script', $d['library'], false, [['field' => 'page', 'value' => $d['page']], ['field' => 'site', 'value' => $d['site']], ['field' => 'kyte_account', 'value' => $this->account]]);
15+
if ($assignments->count > 0) {
16+
throw new \Exception("This custom script is already assigned to the specified page or site.");
17+
}
18+
}
1219
if (isset($r['script'])) {
1320
$r['script']['content'] = '';
1421
$r['script']['content_js_obfuscated'] = '';

0 commit comments

Comments
 (0)