From 73f689d9f4a600d47d7c041adee36c5838fcb072 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Wed, 21 Mar 2018 20:22:49 +0000 Subject: [PATCH] Saved Searches : Save old records Commit 5be0de0d introduced the idea of moving up old saved searches to make room for custom queues - but failed to account for cases where the system has more than 30 saved searches. This commit addresses the issue by just re-inserting the old records after queues are imported. --- include/mysqli.php | 2 +- .../streams/core/934b8db8-ad9d0a5f.task.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/mysqli.php b/include/mysqli.php index 998d28659..efb459f33 100644 --- a/include/mysqli.php +++ b/include/mysqli.php @@ -234,7 +234,7 @@ function db_fetch_field($res) { return ($res) ? $res->fetch_field() : NULL; } -function db_assoc_array($res, $mode=false) { +function db_assoc_array($res, $mode=MYSQLI_ASSOC) { $result = array(); if($res && db_num_rows($res)) { while ($row=db_fetch_array($res, $mode)) diff --git a/include/upgrader/streams/core/934b8db8-ad9d0a5f.task.php b/include/upgrader/streams/core/934b8db8-ad9d0a5f.task.php index 29a3a4b8c..b34f4690a 100644 --- a/include/upgrader/streams/core/934b8db8-ad9d0a5f.task.php +++ b/include/upgrader/streams/core/934b8db8-ad9d0a5f.task.php @@ -9,14 +9,24 @@ class QueueSortCreator extends MigrationTask { foreach ($columns as $C) { QueueColumn::__create($C); } - // Make room for the new queues starting at ID 1 - $id = new SqlField('id'); - CustomQueue::objects()->update(['id' => $id->plus(30)]); + + // Save old records + $old = db_assoc_array(db_query('SELECT * FROM '.QUEUE_TABLE)); + // Truncate Queue table - make room for the new queues starting at ID 1 + db_query('TRUNCATE TABLE '.QUEUE_TABLE); $queues = $i18n->getTemplate('queue.yaml')->getData(); foreach ($queues as $C) { CustomQueue::__create($C); } + // Re-insert old saved searches + foreach ($old ?: array() as $row) { + $row['root'] = 'T'; + CustomQueue::__create(array_intersect_key($row, array_flip( + array('staff_id', 'title', 'config', 'flags', + 'root', 'created', 'updated')))); + } + $columns = $i18n->getTemplate('queue_sort.yaml')->getData(); foreach ($columns as $C) { QueueSort::__create($C); -- GitLab