FOSSology  3.2.0rc1
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  Copyright (C) 2014 Siemens AG
4  Copyright (C) 2014 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***********************************************************/
19 
36 function setActiveGroup($verbose)
37 {
38  global $dbManager;
39  $stmt = __METHOD__;
40  $sql = "SELECT user_pk,group_pk FROM users LEFT JOIN groups ON group_name=user_name WHERE group_fk IS NULL";
41  $dbManager->prepare($stmt,$sql);
42  $res = $dbManager->execute($stmt);
43  if (pg_num_rows($res)==0)
44  {
45  pg_free_result($res);
46  return 0;
47  }
48  $userGroupMap = pg_fetch_all($res);
49  pg_free_result($res);
50  $selectStmt = __METHOD__.'.select';
51  $sql = "SELECT user_fk,min(group_fk) group_fk FROM group_user_member WHERE user_fk=$1";
52  $updateStmt = __METHOD__.'.update';
53  $dbManager->prepare($updateStmt,"UPDATE users SET group_fk=$2 WHERE user_pk=$1");
54  foreach($userGroupMap as $row)
55  {
56  if (!empty($row['group_pk']))
57  {
58  pg_free_result( $dbManager->execute($updateStmt,$row) );
59  continue;
60  }
61  $rowrow = $dbManager->getSingleRow($sql,array($row['user_pk']),$selectStmt);
62  pg_fetch_result($dbManager->execute($updateStmt,$rowrow) );
63  }
64 }
65 
72 function blowAudit($verbose)
73 {
74  global $dbManager;
75 
76  $stmt = __METHOD__.".blowAudit";
77  $sql = "SELECT min(ut.uploadtree_pk) uploadtree_id, lfa.user_fk user_id, lfa.date date_added, lfa.reason reportinfo,
78  lfa.rf_fk license_id, ut.pfile_fk pfile_id
79  FROM license_file_audit lfa INNER JOIN license_file lf ON lfa.fl_fk=lf.fl_pk
80  INNER JOIN uploadtree ut ON lf.pfile_fk=ut.pfile_fk
81  GROUP BY lfa.user_fk, lfa.date, lfa.reason, lfa.rf_fk, ut.pfile_fk";
82  // ensure that these results were not inserted before
83  $sql = "SELECT pureInserts.* FROM ($sql) pureInserts
84  LEFT JOIN clearing_decision cd
85  ON pureInserts.uploadtree_id=cd.uploadtree_fk and pureInserts.user_id=cd.user_fk
86  AND pureInserts.date_added=cd.date_added and pureInserts.reportinfo=cd.reportinfo
87  WHERE cd.clearing_pk is null";
88  $dbManager->prepare($stmt,$sql);
89  $res = $dbManager->execute($stmt);
90  if (pg_num_rows($res)==0)
91  {
92  if ($verbose)
93  {
94  echo "no unknown decision\n";
95  }
96  $dbManager->freeResult($res);
97  return 0;
98  }
99  $auditDecisions = pg_fetch_all($res);
100  $dbManager->freeResult($res);
101  $scope = $dbManager->getSingleRow('SELECT scope_pk FROM clearing_decision_scope WHERE meaning=$1',array('global'));
102  $scope = $scope['scope_pk'];
103  $type = $dbManager->getSingleRow('SELECT type_pk FROM clearing_decision_type WHERE meaning=$1',array('userDecision'));
104  $type = $scope['type_pk'];
105  $dbManager->prepare($stmt='insertClearingDecision',
106  'INSERT INTO clearing_decision'
107  . ' (uploadtree_fk,pfile_fk,user_fk,type_fk,scope_fk,comment,reportinfo,date_added) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)'
108  . ' RETURNING clearing_pk');
109  $dbManager->prepare($stmt='insertClearingLicense','INSERT INTO clearing_licenses'
110  . ' (clearing_fk,rf_fk) VALUES ($1,$2)');
111  $pfiles = array();
112  foreach($auditDecisions as $audit)
113  {
114  $cd = $dbManager->execute('insertClearingDecision',
115  array($audit['uploadtree_id'],$audit['pfile_id'] ,$audit['user_id'],$type,$scope,'migrated',$audit['reportinfo'],$audit['date_added']));
116  $clearing = $dbManager->fetchArray($cd);
117  $clearingId = $clearing['clearing_pk'];
118  $dbManager->freeResult($cd);
119  $dbManager->freeResult( $dbManager->execute('insertClearingLicense',array($clearingId,$audit['license_id'])) );
120  $pfiles[$audit['pfile_id']] = 0;
121  }
122  if ($verbose)
123  {
124  echo "inserted ".count($auditDecisions)." clearing decisions for ".count($pfiles)." files\n";
125  }
126  return count($auditDecisions);
127 }
128 
129 
135 function migrate_25_26($verbose)
136 {
137  setActiveGroup($verbose);
138  //$nInsertedDecisions = blowAudit($verbose);
139  $nInsertedDecisions = 0;
140  return $nInsertedDecisions;
141 }
setActiveGroup($verbose)
Set active group for existing users from group_user_member table.
blowAudit($verbose)
Copy decisions from license_file_audit table to clearing_decision type $dbManager.
migrate_25_26($verbose)