FOSSology  4.4.0
Open Source License Compliance by Open Source Software
dbmigrate_2.5-2.6.php
Go to the documentation of this file.
1 <?php
2 /*
3 SPDX-FileCopyrightText: © 2014 Siemens AG
4  SPDX-FileCopyrightText: © 2014 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
25 function setActiveGroup($verbose)
26 {
27  global $dbManager;
28  $stmt = __METHOD__;
29  $sql = "SELECT user_pk,group_pk FROM users LEFT JOIN groups ON group_name=user_name WHERE group_fk IS NULL";
30  $dbManager->prepare($stmt,$sql);
31  $res = $dbManager->execute($stmt);
32  if (pg_num_rows($res)==0)
33  {
34  pg_free_result($res);
35  return 0;
36  }
37  $userGroupMap = pg_fetch_all($res);
38  pg_free_result($res);
39  $selectStmt = __METHOD__.'.select';
40  $sql = "SELECT user_fk,min(group_fk) group_fk FROM group_user_member WHERE user_fk=$1";
41  $updateStmt = __METHOD__.'.update';
42  $dbManager->prepare($updateStmt,"UPDATE users SET group_fk=$2 WHERE user_pk=$1");
43  foreach($userGroupMap as $row)
44  {
45  if (!empty($row['group_pk']))
46  {
47  pg_free_result( $dbManager->execute($updateStmt,$row) );
48  continue;
49  }
50  $rowrow = $dbManager->getSingleRow($sql,array($row['user_pk']),$selectStmt);
51  pg_fetch_result($dbManager->execute($updateStmt,$rowrow) );
52  }
53 }
54 
61 function blowAudit($verbose)
62 {
63  global $dbManager;
64 
65  $stmt = __METHOD__.".blowAudit";
66  $sql = "SELECT min(ut.uploadtree_pk) uploadtree_id, lfa.user_fk user_id, lfa.date date_added, lfa.reason reportinfo,
67  lfa.rf_fk license_id, ut.pfile_fk pfile_id
68  FROM license_file_audit lfa INNER JOIN license_file lf ON lfa.fl_fk=lf.fl_pk
69  INNER JOIN uploadtree ut ON lf.pfile_fk=ut.pfile_fk
70  GROUP BY lfa.user_fk, lfa.date, lfa.reason, lfa.rf_fk, ut.pfile_fk";
71  // ensure that these results were not inserted before
72  $sql = "SELECT pureInserts.* FROM ($sql) pureInserts
73  LEFT JOIN clearing_decision cd
74  ON pureInserts.uploadtree_id=cd.uploadtree_fk and pureInserts.user_id=cd.user_fk
75  AND pureInserts.date_added=cd.date_added and pureInserts.reportinfo=cd.reportinfo
76  WHERE cd.clearing_pk is null";
77  $dbManager->prepare($stmt,$sql);
78  $res = $dbManager->execute($stmt);
79  if (pg_num_rows($res)==0)
80  {
81  if ($verbose)
82  {
83  echo "no unknown decision\n";
84  }
85  $dbManager->freeResult($res);
86  return 0;
87  }
88  $auditDecisions = pg_fetch_all($res);
89  $dbManager->freeResult($res);
90  $scope = $dbManager->getSingleRow('SELECT scope_pk FROM clearing_decision_scope WHERE meaning=$1',array('global'));
91  $scope = $scope['scope_pk'];
92  $type = $dbManager->getSingleRow('SELECT type_pk FROM clearing_decision_type WHERE meaning=$1',array('userDecision'));
93  $type = $scope['type_pk'];
94  $dbManager->prepare($stmt='insertClearingDecision',
95  'INSERT INTO clearing_decision'
96  . ' (uploadtree_fk,pfile_fk,user_fk,type_fk,scope_fk,comment,reportinfo,date_added) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)'
97  . ' RETURNING clearing_pk');
98  $dbManager->prepare($stmt='insertClearingLicense','INSERT INTO clearing_licenses'
99  . ' (clearing_fk,rf_fk) VALUES ($1,$2)');
100  $pfiles = array();
101  foreach($auditDecisions as $audit)
102  {
103  $cd = $dbManager->execute('insertClearingDecision',
104  array($audit['uploadtree_id'],$audit['pfile_id'] ,$audit['user_id'],$type,$scope,'migrated',$audit['reportinfo'],$audit['date_added']));
105  $clearing = $dbManager->fetchArray($cd);
106  $clearingId = $clearing['clearing_pk'];
107  $dbManager->freeResult($cd);
108  $dbManager->freeResult( $dbManager->execute('insertClearingLicense',array($clearingId,$audit['license_id'])) );
109  $pfiles[$audit['pfile_id']] = 0;
110  }
111  if ($verbose)
112  {
113  echo "inserted ".count($auditDecisions)." clearing decisions for ".count($pfiles)." files\n";
114  }
115  return count($auditDecisions);
116 }
117 
118 
124 function migrate_25_26($verbose)
125 {
126  setActiveGroup($verbose);
127  //$nInsertedDecisions = blowAudit($verbose);
128  $nInsertedDecisions = 0;
129  return $nInsertedDecisions;
130 }
blowAudit($verbose)
Copy decisions from license_file_audit table to clearing_decision @global type $dbManager.
migrate_25_26($verbose)
setActiveGroup($verbose)
Set active group for existing users from group_user_member table.