File indexing completed on 2025-02-09 07:14:33
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class Default_Model_DbTable_MemberExternalId extends Local_Model_Table 0024 { 0025 0026 protected $_name = "member_external_id"; 0027 protected $_keyColumnsForRow = array('external_id'); 0028 0029 protected $_key = 'external_id'; 0030 0031 protected $_defaultValues = array( 0032 'external_id' => 0, 0033 'member_id' => 0, 0034 'created_at' => null, 0035 'is_deleted' => null 0036 ); 0037 0038 /** 0039 * @param int $identifier 0040 * 0041 * @return int 0042 * @throws Zend_Db_Statement_Exception 0043 */ 0044 public function setDelete($identifier) 0045 { 0046 $sql = "UPDATE `{$this->_name}` SET `is_deleted` = 1 WHERE `{$this->_key}` = :id"; 0047 $stmnt = $this->_db->query($sql, array('id' => $identifier)); 0048 0049 return $stmnt->rowCount(); 0050 } 0051 0052 /** 0053 * @param array|string $member_id 0054 * 0055 * @return int|void 0056 * @throws Exception 0057 */ 0058 public function delete($member_id) 0059 { 0060 throw new Exception('Deleting of users is not allowed.'); 0061 } 0062 0063 public function createExternalId($member_id) 0064 { 0065 $sql = "INSERT INTO `{$this->_name}` (external_id, member_id) VALUES (SUBSTR(SHA(:memberId), 1, 20), :memberId)"; 0066 $stmnt = $this->_db->query($sql, array('memberId' => $member_id)); 0067 $sql = "SELECT external_id FROM `{$this->_name}` WHERE member_id = :memberId ORDER BY created_at DESC"; 0068 $result = $this->_db->query($sql, array('memberId' => $member_id))->fetchAll(); 0069 $id = $result[0]['external_id']; 0070 return $id; 0071 } 0072 0073 public function updateGitlabUserId($member_id, $gitlab_user_id) 0074 { 0075 $sql = " 0076 update member_external_id set gitlab_user_id = :gitlab_user_id where member_id = :member_id 0077 "; 0078 $this->getAdapter()->query($sql, array('gitlab_user_id'=>$gitlab_user_id,'member_id'=>$member_id)); 0079 } 0080 0081 }