FOSSology  4.4.0
Open Source License Compliance by Open Source Software
instance_uuid.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2020 Orange
4 
5  SPDX-License-Identifier: GPL-2.0-only
6  Author: Drozdz Bartlomiej <bartlomiej.drozdz@orange.com>
7 */
8 
15  function CreateInstanceUUIDTable($dbManager)
16  {
17  if($dbManager == NULL){
18  echo "Missing dbManager object. Can't create instance_uuid table.\n";
19  return false;
20  }
21 
22  $dbManager->queryOnce("
23 BEGIN;
24 CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";
25 CREATE TABLE IF NOT EXISTS instance (
26  id bool PRIMARY KEY DEFAULT TRUE,
27  instance_uuid UUID NOT NULL DEFAULT uuid_generate_v4(),
28 CONSTRAINT tbl_id_uni CHECK (id));
29 COMMIT;
30  ");
31  $row = $dbManager->getSingleRow("SELECT count(instance_uuid) FROM instance;", array(), 'instance_uuid.count' );
32  if ($row['count'] == 0){
33  echo "INSTANCE UUID Empty - creating...\n";
34  $dbManager->queryOnce("INSERT INTO instance DEFAULT VALUES;");
35  }
36 
37  $row_uuid = $dbManager->getSingleRow("SELECT instance_uuid FROM instance;", array(), 'instance_uuid' );
38  echo "INSTANCE UUID: ", $row_uuid['instance_uuid'], "\n";
39 
40  }
41 
42 echo "*** Instance UUID ***\n";
43 CreateInstanceUUIDTable($dbManager);