File indexing completed on 2025-01-26 05:29:12
0001 <?php 0002 /** 0003 * ocs-webserver 0004 * 0005 * Copyright 2016 by pling GmbH. 0006 * 0007 * This file is part of ocs-webserver. 0008 * 0009 * This program is free software: you can redistribute it and/or modify 0010 * it under the terms of the GNU Affero General Public License as 0011 * published by the Free Software Foundation, either version 3 of the 0012 * License, or (at your option) any later version. 0013 * 0014 * This program is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 * GNU Affero General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Affero General Public License 0020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 **/ 0022 0023 class Local_Tools_UUID 0024 { 0025 0026 public static function migrateMembers() 0027 { 0028 $memberTable = new Default_Model_Member(); 0029 0030 /** @var $rowSet Zend_Db_Table_Rowset */ 0031 $rowSet = $memberTable->fetchAll('uuid is null'); 0032 0033 /** @var $row Zend_Db_Table_Row */ 0034 foreach ($rowSet as $row) { 0035 $row->uuid = Local_Tools_UUID::generateUUID(); 0036 $row->save(); 0037 } 0038 0039 } 0040 0041 /** 0042 * @return string 0043 */ 0044 public static function generateUUID() 0045 { 0046 $randomString = openssl_random_pseudo_bytes(16); 0047 $time_low = bin2hex(substr($randomString, 0, 4)); 0048 $time_mid = bin2hex(substr($randomString, 4, 2)); 0049 $time_hi_and_version = bin2hex(substr($randomString, 6, 2)); 0050 $clock_seq_hi_and_reserved = bin2hex(substr($randomString, 8, 2)); 0051 $node = bin2hex(substr($randomString, 10, 6)); 0052 0053 /** 0054 * Set the four most significant bits (bits 12 through 15) of the 0055 * time_hi_and_version field to the 4-bit version number from 0056 * Section 4.1.3. 0057 * @see http://tools.ietf.org/html/rfc4122#section-4.1.3 0058 */ 0059 $time_hi_and_version = hexdec($time_hi_and_version); 0060 $time_hi_and_version = $time_hi_and_version >> 4; 0061 $time_hi_and_version = $time_hi_and_version | 0x4000; 0062 0063 /** 0064 * Set the two most significant bits (bits 6 and 7) of the 0065 * clock_seq_hi_and_reserved to zero and one, respectively. 0066 */ 0067 $clock_seq_hi_and_reserved = hexdec($clock_seq_hi_and_reserved); 0068 $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved >> 2; 0069 $clock_seq_hi_and_reserved = $clock_seq_hi_and_reserved | 0x8000; 0070 0071 return sprintf('%08s%04s%04x%04x%012s', $time_low, $time_mid, $time_hi_and_version, $clock_seq_hi_and_reserved, $node); 0072 } 0073 0074 public static function migrateProjects() 0075 { 0076 $projectTable = new Default_Model_Project(); 0077 0078 /** @var $rowSet Zend_Db_Table_Rowset */ 0079 $rowSet = $projectTable->fetchAll('uuid is null'); 0080 0081 /** @var $row Zend_Db_Table_Row */ 0082 foreach ($rowSet as $row) { 0083 $row->uuid = Local_Tools_UUID::generateUUID(); 0084 $row->save(); 0085 } 0086 0087 } 0088 0089 }