From 7b100cc57b58a1ef5c2c6cef28904e1ba79f0c49 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 20 Jul 2016 21:40:27 -0400 Subject: Move logic of PR #2496 to GroupModel --- app/Model/GroupModel.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'app/Model/GroupModel.php') diff --git a/app/Model/GroupModel.php b/app/Model/GroupModel.php index 0a975570..b43423b3 100644 --- a/app/Model/GroupModel.php +++ b/app/Model/GroupModel.php @@ -116,4 +116,23 @@ class GroupModel extends Base { return $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values); } + + /** + * Get groupId from externalGroupId and create the group if not found + * + * @access public + * @param string $name + * @param string $external_id + * @return bool|integer + */ + public function getOrCreateExternalGroupId($name, $external_id) + { + $group_id = $this->db->table(self::TABLE)->eq('external_id', $external_id)->findOneColumn('id'); + + if (empty($group_id)) { + $group_id = $this->create($name, $external_id); + } + + return $group_id; + } } -- cgit v1.2.3