Skip to content
Snippets Groups Projects
Commit 5e3bdb07 authored by Jared Hancock's avatar Jared Hancock Committed by Peter Rotich
Browse files

queue: Refuse to set queue a descendent of itself

Also, fix queue paths created at installation time.
parent ace9b520
Branches
Tags
No related merge requests found
...@@ -749,8 +749,8 @@ class CustomQueue extends VerySimpleModel { ...@@ -749,8 +749,8 @@ class CustomQueue extends VerySimpleModel {
if (!$this->id) if (!$this->id)
return; return;
$path = $this->parent ? $this->parent->getPath() : ''; $path = $this->parent ? $this->parent->buildPath() : '';
return $path . "/{$this->id}"; return rtrim($path, "/") . "/{$this->id}/";
} }
function getFullName() { function getFullName() {
...@@ -800,6 +800,14 @@ class CustomQueue extends VerySimpleModel { ...@@ -800,6 +800,14 @@ class CustomQueue extends VerySimpleModel {
if ($this->parent_id && !$this->parent) if ($this->parent_id && !$this->parent)
$errors['parent_id'] = __('Select a valid queue'); $errors['parent_id'] = __('Select a valid queue');
// Try to avoid infinite recursion determining ancestry
if ($this->parent_id && isset($this->id)) {
$P = $this;
while ($P = $P->parent)
if ($P->parent_id == $this->id)
$errors['parent_id'] = __('Cannot be a descendent of itself');
}
// Configure quick filter options // Configure quick filter options
$this->filter = $vars['filter']; $this->filter = $vars['filter'];
if ($vars['sort_id']) { if ($vars['sort_id']) {
...@@ -925,17 +933,29 @@ class CustomQueue extends VerySimpleModel { ...@@ -925,17 +933,29 @@ class CustomQueue extends VerySimpleModel {
} }
function save($refetch=false) { function save($refetch=false) {
$wasnew = !isset($this->id); $nopath = !isset($this->path);
$path_changed = isset($this->dirty['parent_id']);
if ($this->dirty) if ($this->dirty)
$this->updated = SqlFunction::NOW(); $this->updated = SqlFunction::NOW();
if (!($rv = parent::save($refetch || $this->dirty))) if (!($rv = parent::save($refetch || $this->dirty)))
return $rv; return $rv;
if ($wasnew) { if ($nopath) {
$this->path = $this->buildPath(); $this->path = $this->buildPath();
$this->save(); $this->save();
} }
if ($path_changed) {
$this->children->reset();
$move_children = function($q) use (&$move_children) {
foreach ($q->children as $qq) {
$qq->path = $qq->buildPath();
$qq->save();
$move_children($qq);
}
};
$move_children($this);
}
return $this->columns->saveAll() return $this->columns->saveAll()
&& $this->sorts->saveAll(); && $this->sorts->saveAll();
} }
......
...@@ -89,8 +89,11 @@ else { ...@@ -89,8 +89,11 @@ else {
== <?php echo $queue->parent_id ?: 0; ?>);"> == <?php echo $queue->parent_id ?: 0; ?>);">
<option value="0"><?php echo __('Top-Level Queue'); ?></option> <option value="0"><?php echo __('Top-Level Queue'); ?></option>
<?php foreach (CustomQueue::queues() as $cq) { <?php foreach (CustomQueue::queues() as $cq) {
if ($cq->getId() == $queue->getId()) // Queue cannot be a descendent of itself
continue; if ($cq->id == $queue->id)
continue;
if (strpos($cq->path, "/{$queue->id}/") !== false)
continue;
?> ?>
<option value="<?php echo $cq->id; ?>" <option value="<?php echo $cq->id; ?>"
<?php if ($cq->getId() == $queue->parent_id) echo 'selected="selected"'; ?> <?php if ($cq->getId() == $queue->parent_id) echo 'selected="selected"'; ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment