From b9390747b3cc8dd286dc53a1b1ae23feb7f700aa Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 25 Nov 2015 12:54:00 +0100 Subject: [PATCH] SyncRule: add getPriorityForNextProperty() method --- library/Director/Objects/SyncRule.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/Director/Objects/SyncRule.php b/library/Director/Objects/SyncRule.php index e3083bb9..c384072d 100644 --- a/library/Director/Objects/SyncRule.php +++ b/library/Director/Objects/SyncRule.php @@ -21,6 +21,22 @@ class SyncRule extends DbObject 'filter_expression' => null, ); + public function getPriorityForNextProperty() + { + if (! $this->hasBeenLoadedFromDb()) { + return 1; + } + + $db = $this->getDb(); + return $db->fetchOne( + $db->select() + ->from( + 'sync_property', + '(CASE WHEN MAX(priority) IS NULL THEN 1 ELSE MAX(priority) + 1 END)' + )->where('rule_id = ?', $this->id) + ); + } + public function fetchSyncProperties() { $db = $this->getDb();