20 const MAX_SIZE_OF_ROW = 100000;
27 "copyright" =>
"copyright_event",
28 "author" =>
"author_event",
30 "keyword" =>
"keyword_event"
40 if ($dbManager == NULL) {
41 echo
"No connection object passed!\n";
45 $sql =
"SELECT count(*) AS cnt FROM ";
46 $statement = __METHOD__ .
".getCountsFor";
48 $row = $dbManager->getSingleRow($sql . $table .
" AS cp
49 INNER JOIN uploadtree AS ut ON cp.pfile_fk = ut.pfile_fk
50 WHERE cp.is_enabled=false;", array(), $statement . $table);
51 $length = intval($row[
'cnt']);
53 if (!empty($length)) {
54 echo
"*** Inserting $length records from $table to $tableEvent table ***\n";
56 echo
"*** Table $table already migrated to $tableEvent table ***\n";
60 $tablePk = $table.
"_pk";
61 $tableFk = $table.
"_fk";
65 $statement = __METHOD__ .
".updateContentFor.$tableEvent";
66 $dbManager->queryOnce(
"DROP FUNCTION IF EXISTS migrate_".$table.
"_events_event(upperuploadtreeid int, loweruploadtreeid int)", $statement.
"drop");
68 CREATE OR REPLACE FUNCTION migrate_".$table.
"_events_event(upperuploadtreeid int, loweruploadtreeid int) RETURNS VOID AS
71 INSERT INTO $tableEvent (upload_fk, $tableFk, uploadtree_fk)
72 SELECT upload_fk, $tablePk, uploadtree_pk FROM $table as cp
73 INNER JOIN uploadtree AS ut ON cp.pfile_fk = ut.pfile_fk
74 WHERE ut.uploadtree_pk >= loweruploadtreeid
75 AND ut.uploadtree_pk < upperuploadtreeid
76 AND cp.is_enabled=false
77 ORDER BY ut.uploadtree_pk;
81 $dbManager->queryOnce($sql, $statement.
'plPGsqlfunction');
82 while ($num <= $length) {
83 $startTime = microtime(
true);
85 $statementName = __METHOD__.
"insert from function".$table;
86 $dbManager->getSingleRow(
"SELECT 1 FROM migrate_".$table.
"_events_event($1, $2)", array($j, $i), $statementName);
87 $rows = $dbManager->getSingleRow(
"SELECT count(*) AS cnt, max(uploadtree_fk) AS uploadtree FROM $tableEvent", array(), $statement . $tableEvent. $table);
88 $num = intval($rows[
'cnt']);
89 if (!empty($rows[
'uploadtree'])) {
90 $i = $rows[
'uploadtree'];
94 $j += MAX_SIZE_OF_ROW;
96 $endTime = microtime(
true);
97 $totalTime = ($endTime - $startTime);
98 echo
"Inserted $num / $length rows to $tableEvent table in ".gmdate(
"i", $totalTime).
" minutes and ".gmdate(
"s", $totalTime).
" seconds. \n";
101 $sqlTable =
"UPDATE $table SET is_enabled=true WHERE is_enabled=false";
102 $dbManager->queryOnce($sqlTable, $statement.
"Update");
103 $dbManager->commit();
114 if ($dbManager == NULL){
115 echo
"No connection object passed!\n";
122 $migPossible =
false;
126 $migPossible =
false;
130 $migPossible =
false;
148 }
catch (Exception $e) {
149 echo
"Something went wrong. Try running postinstall again!\n";
150 $dbManager->rollback();
DB_ColExists($tableName, $colName, $DBName='fossology')
Check if a column exists.
DB_TableExists($tableName)
Check if table exists.
insertDataInToEventTables($dbManager)
checkIfMigratePossible($dbManager)
createCopyrightMigrationForCopyrightEvents($dbManager)