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)
37 $userGroupMap = pg_fetch_all($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)
45 if (!empty($row[
'group_pk']))
47 pg_free_result( $dbManager->execute($updateStmt,$row) );
50 $rowrow = $dbManager->getSingleRow($sql,array($row[
'user_pk']),$selectStmt);
51 pg_fetch_result($dbManager->execute($updateStmt,$rowrow) );
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";
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)
83 echo
"no unknown decision\n";
85 $dbManager->freeResult($res);
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)');
101 foreach($auditDecisions as $audit)
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;
113 echo
"inserted ".count($auditDecisions).
" clearing decisions for ".count($pfiles).
" files\n";
115 return count($auditDecisions);
128 $nInsertedDecisions = 0;
129 return $nInsertedDecisions;
blowAudit($verbose)
Copy decisions from license_file_audit table to clearing_decision @global type $dbManager.
setActiveGroup($verbose)
Set active group for existing users from group_user_member table.