17 $usage =
"Usage: " . basename($argv[0]) .
" [options]
18 Update FOSSology database. This should be used immediately after an install or update. Options are:
19 -c path to fossology configuration files
20 -d {database name} default is 'fossology'
21 -f {file} update the schema with file generated by schema-export.php
22 -l update the license_ref table with fossology supplied licenses
23 -r {prefix} drop database with name starts with prefix
24 -v enable verbose preview (prints sql that would happen, but does not execute it, DB is not updated)
25 --force-decision force recalculation of SHA256 for decision tables
26 --force-pfile force recalculation of SHA256 for pfile entries
27 --force-encode force recode of copyright and sister tables
47 $AllPossibleOpts =
"abc:d:ef:ghijklmnopqr:stuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
56 $DatabaseName =
"fossology";
57 $UpdateLiceneseRef =
false;
59 $delDbPattern =
'the option -rfosstest will drop data bases with datname like "fosstest%"';
60 $forceDecision =
false;
64 $Options = getopt($AllPossibleOpts, $longOpts);
65 foreach(
$Options as $optKey => $optVal)
70 $sysconfdir = $optVal;
73 $DatabaseName = $optVal;
76 $SchemaFilePath = $optVal;
81 $UpdateLiceneseRef =
true;
87 $delDbPattern = $optVal ?
"$optVal%" :
"fosstest%";
89 case "force-decision":
90 $forceDecision =
true;
96 putenv(
'FOSSENCODING=1');
99 echo
"Invalid Option \"$optKey\".\n";
104 require_once
'fossinit-common.php';
108 $SysConf[
"DBCONF"][
"dbname"] = $DatabaseName;
109 $GLOBALS[
"SysConf"] = array_merge($GLOBALS[
"SysConf"], $SysConf);
110 $projectGroup = $SysConf[
'DIRECTORIES'][
'PROJECTGROUP'] ?:
'fossy';
111 $gInfo = posix_getgrnam($projectGroup);
112 posix_setgid($gInfo[
'gid']);
114 if (!preg_match(
"/\s$projectGroup\s/",$groups) && (posix_getgid() != $gInfo[
'gid']))
116 print
"FATAL: You must be in group '$projectGroup'.\n";
120 require_once(
"$MODDIR/vendor/autoload.php");
121 require_once(
"$MODDIR/lib/php/common-db.php");
122 require_once(
"$MODDIR/lib/php/common-container.php");
123 require_once(
"$MODDIR/lib/php/common-cache.php");
124 require_once(
"$MODDIR/lib/php/common-sysconfig.php");
125 require_once(
"$MODDIR/lib/php/fossdash-config.php");
128 $GLOBALS[
"PG_CONN"] =
get_pg_conn($SYSCONFDIR, $SysConf);
140 if (empty($SchemaFilePath)) {
141 $SchemaFilePath =
"$MODDIR/www/ui/core-schema.dat";
144 if (!file_exists($SchemaFilePath))
146 print
"FAILED: Schema data file ($SchemaFilePath) not found.\n";
150 require_once(
"$MODDIR/lib/php/libschema.php");
152 $libschema->setDriver($pgDriver);
153 $previousSchema = $libschema->getCurrSchema();
154 $isUpdating = array_key_exists(
'TABLE', $previousSchema) && array_key_exists(
'users', $previousSchema[
'TABLE']);
156 if ($dbManager->existsTable(
'sysconfig'))
158 $sysconfig = $dbManager->createMap(
'sysconfig',
'variablename',
'conf_value');
159 if(!array_key_exists(
'Release', $sysconfig))
161 $sysconfig[
'Release'] = 0;
163 print
"Old release was $sysconfig[Release]\n";
166 $migrateColumns = array(
'clearing_decision'=>array(
'reportinfo',
'clearing_pk',
'type_fk',
'comment'),
167 'license_ref_bulk'=>array(
'rf_fk',
'removing'));
168 if($isUpdating && !empty($sysconfig) && $sysconfig[
'Release'] ==
'2.6.3.1')
170 $dbManager->queryOnce(
'begin;
171 CREATE TABLE uploadtree_b AS (SELECT * FROM uploadtree_a);
172 DROP TABLE uploadtree_a;
173 CREATE TABLE uploadtree_a () INHERITS (uploadtree);
174 ALTER TABLE uploadtree_a ADD CONSTRAINT uploadtree_a_pkey PRIMARY KEY (uploadtree_pk);
175 INSERT INTO uploadtree_a SELECT * FROM uploadtree_b;
176 DROP TABLE uploadtree_b;
177 COMMIT;',__FILE__.
'.rebuild.uploadtree_a');
180 if($dbManager->existsTable(
"author"))
182 require_once(
"$LIBEXECDIR/resequence_author_table.php");
186 require_once(
"$LIBEXECDIR/dbmigrate_3.3-3.4.php");
189 $FailMsg = $libschema->applySchema($SchemaFilePath, $Verbose, $DatabaseName, $migrateColumns);
192 print
"ApplySchema failed: $FailMsg\n";
200 $Filename =
"$MODDIR/www/ui/init.ui";
201 $flagRemoved = !file_exists($Filename);
206 print
"Removing flag '$Filename'\n";
208 if (is_writable(
"$MODDIR/www/ui/"))
210 $flagRemoved = unlink($Filename);
215 print
"Failed to remove $Filename\n";
216 print
"Remove this file to complete the initialization.\n";
220 print
"Database schema update completed successfully.\n";
223 $FAILED_LICENSE_IMPORT = array();
225 if (array_key_exists(
'r',
$Options))
227 $dbManager->prepare(__METHOD__.
".getDelDbNames",
'SELECT datname FROM pg_database WHERE datistemplate = false and datname like $1');
228 $resDelDbNames = $dbManager->execute(__METHOD__.
".getDelDbNames",array($delDbPattern));
229 $delDbNames=pg_fetch_all($resDelDbNames);
230 pg_free_result($resDelDbNames);
231 foreach ($delDbNames as $deleteDatabaseName)
233 $dbManager->queryOnce(
"DROP DATABASE $deleteDatabaseName[datname]");
237 echo
"dropped " . count($delDbNames) .
" databases ";
242 $currSchema = $libschema->getCurrSchema();
243 $sysconfig = $dbManager->createMap(
'sysconfig',
'variablename',
'conf_value');
245 if($isUpdating && empty($sysconfig[
'Release'])) {
246 require_once(
"$LIBEXECDIR/dbmigrate_2.0-2.1.php");
248 require_once(
"$LIBEXECDIR/dbmigrate_2.1-2.2.php");
249 print
"Migrate data from 2.1 to 2.2 in $LIBEXECDIR\n";
251 if($dbManager->existsTable(
'license_file_audit') && array_key_exists(
'clearing_pk', $currSchema[
'TABLE'][
'clearing_decision']))
253 require_once(
"$LIBEXECDIR/dbmigrate_2.5-2.6.php");
256 if(!array_key_exists(
'clearing_pk', $currSchema[
'TABLE'][
'clearing_decision']) && $isUpdating)
259 echo
"Missing column clearing_decision.clearing_pk, you should update to version 2.6.2 before migration\n";
260 echo
"Enter 'i' within $timeoutSec seconds to ignore this warning and run the risk of losing clearing decisions: ";
261 $handle = fopen (
"php://stdin",
"r");
262 stream_set_blocking($handle,0);
263 for($s=0;$s<$timeoutSec;$s++)
266 $line = fread($handle,1);
271 if(
trim($line) !=
'i')
277 $sysconfig[
'Release'] =
'2.6';
280 require_once (
"$LIBEXECDIR/dbmigrate_2.1-2.2.php");
281 print
"Creating default user\n";
284 require_once (
"$LIBEXECDIR/dbmigrate_3.5-3.6.php");
286 updatePfileSha256($dbManager, $forcePfile);
289 $release = array_key_exists(
'Release', $sysconfig) ? $sysconfig[
'Release'] : 0;
290 if (version_compare($release,
'4.3.0',
'<')) {
291 require_once(
"$LIBEXECDIR/dbmigrate_4.2-4.3.php");
295 require_once(
"$LIBEXECDIR/dbmigrate_cmu-mach.php");
299 if ($UpdateLiceneseRef)
301 if (version_compare($release,
'4.8.0',
'<')) {
303 $dbManager->queryOnce(
304 "UPDATE license_ref SET rf_licensetype='Unknown'
305 WHERE rf_licensetype IN ('UNKNOWN', 'PERMISSIVE')",
306 'migrate.rf_licensetype.case');
308 $row = $dbManager->getSingleRow(
"SELECT count(*) FROM license_ref",array(),
'license_ref.count');
309 if ($row[
'count'] > 0) {
310 print
"Update reference licenses\n";
311 initLicenseRefTable(
false);
313 else if ($row[
'count'] == 0) {
316 $row_max = $dbManager->getSingleRow(
"SELECT max(rf_pk) from license_ref",array(),
'license_ref.max.rf_pk');
317 $current_license_ref_rf_pk_seq = $row_max[
'max'];
318 $dbManager->getSingleRow(
"SELECT setval('license_ref_rf_pk_seq', $current_license_ref_rf_pk_seq)",array(),
319 'set next license_ref_rf_pk_seq value');
321 print
"fresh install, import licenseRef.json \n";
325 if(!$isUpdating || $sysconfig[
'Release'] ==
'2.6')
327 if(!$dbManager->existsTable(
'license_candidate'))
329 $dbManager->queryOnce(
"CREATE TABLE license_candidate (group_fk integer) INHERITS (license_ref)");
331 if ($isUpdating && array_key_exists(
'clearing_pk', $currSchema[
'TABLE'][
'clearing_decision']))
333 require_once(
"$LIBEXECDIR/dbmigrate_clearing-event.php");
334 $libschema->dropColumnsFromTable(array(
'reportinfo',
'clearing_pk',
'type_fk',
'comment'),
'clearing_decision');
336 $sysconfig[
'Release'] =
'2.6.3';
339 if($sysconfig[
'Release'] ==
'2.6.3')
341 require_once(
"$LIBEXECDIR/dbmigrate_real-parent.php");
344 $expiredDbReleases = array(
'2.6.3',
'2.6.3.1',
'2.6.3.2');
345 if($isUpdating && (empty($sysconfig[
'Release']) || in_array($sysconfig[
'Release'], $expiredDbReleases)))
347 require_once(
"$LIBEXECDIR/fo_mapping_license.php");
348 print
"Rename license (using $LIBEXECDIR) for SPDX validity\n";
352 $expiredDbReleases[] =
'2.6.3.3';
353 $expiredDbReleases[] =
'3.0.0';
354 if($isUpdating && (empty($sysconfig[
'Release']) || in_array($sysconfig[
'Release'], $expiredDbReleases)))
356 require_once(
"$LIBEXECDIR/dbmigrate_bulk_license.php");
359 if(in_array($sysconfig[
'Release'], $expiredDbReleases))
361 $sysconfig[
'Release'] =
'3.0.1';
366 if($isUpdating && (empty($sysconfig[
'Release']) || $sysconfig[
'Release'] ==
'3.0.1'))
369 $row = $dbManager->getSingleRow(
"
370 SELECT rf1.rf_pk AS id_3dfx,
371 rf2.rf_pk AS id_glide
373 INNER JOIN license_ref rf2 USING (rf_fullname)
374 WHERE rf1.rf_shortname='3DFX'
375 AND rf2.rf_shortname='Glide'
376 LIMIT 1", array(),
'old.3dfx.rf_pk');
379 $id_3dfx = intval($row[
'id_3dfx']);
380 $id_glide = intval($row[
'id_glide']);
381 $dbManager->queryOnce(
"DELETE FROM license_ref WHERE rf_pk=$id_glide");
382 $dbManager->queryOnce(
"UPDATE license_ref SET rf_shortname='Glide' WHERE rf_pk=$id_3dfx");
384 $dbManager->commit();
386 $sysconfig[
'Release'] =
"3.0.2";
389 if($isUpdating && (empty($sysconfig[
'Release']) || $sysconfig[
'Release'] ==
'3.0.2'))
391 require_once(
"$LIBEXECDIR/dbmigrate_multiple_copyright_decisions.php");
393 $sysconfig[
'Release'] =
"3.1.0";
397 if($isUpdating && (empty($sysconfig[
'Release']) || $sysconfig[
'Release'] ==
"3.1.0")) {
398 $sysconfig[
'Release'] =
"3.3.0";
402 $new_version = $SysConf[
"BUILD"][
"VERSION"] ??
'';
403 if ($new_version !==
''){
405 $dbManager->getSingleRow(
"DELETE FROM sysconfig WHERE variablename=$1",array(
'Release'),
'drop.sysconfig.release');
406 $dbManager->insertTableRow(
'sysconfig',
407 array(
'variablename'=>
'Release',
'conf_value'=>$SysConf[
"BUILD"][
"VERSION"],
408 'ui_label'=>
'Release',
'vartype'=>2,
'group_name'=>
'Release',
'description'=>
'')
410 $dbManager->commit();
414 require_once(
"$LIBEXECDIR/dbmigrate_copyright-author.php");
417 require_once(
"$LIBEXECDIR/dbmigrate_3.6-3.7.php");
421 require_once(
"$LIBEXECDIR/instance_uuid.php");
424 require_once(
"$LIBEXECDIR/dbmigrate_3.7-3.8.php");
428 require_once(
"$LIBEXECDIR/dbmigrate_4.0-4.1.php");
432 require_once(
"$LIBEXECDIR/dbmigrate_copyright-event.php");
436 require_once (
"$LIBEXECDIR/sanity_check.php");
438 $errors = $checker->check();
440 require_once(
"$LIBEXECDIR/dbmigrate_licensedb_compatibility.php");
443 require_once(
"$LIBEXECDIR/dbmigrate_token.php");
444 Token_timestamp_migration();
446 require_once(
"$LIBEXECDIR/dbmigrate_kotoba_candidate_licenses.php");
451 echo
"ERROR: $errors sanity check".($errors>1?
's':
'').
" failed\n";
453 if (! empty($FAILED_LICENSE_IMPORT)) {
454 $failedInsert = array_filter($FAILED_LICENSE_IMPORT,
456 return $x[1] ==
"INSERT";
458 $failedUpdate = array_filter($FAILED_LICENSE_IMPORT,
460 return $x[1] ==
"UPDATE";
462 $failedPromote = array_filter($FAILED_LICENSE_IMPORT,
464 return $x[1] ==
"CANPROMOTE";
466 if (! empty($failedInsert)) {
467 echo
"*** Failed to insert following licenses ***\n";
468 echo implode(
",", array_map(
function ($x) {
470 }, $failedInsert)) .
"\n";
472 if (! empty($failedUpdate)) {
473 echo
"*** Failed to update following licenses ***\n";
474 echo implode(
",", array_map(
function ($x) {
476 }, $failedUpdate)) .
"\n";
478 if (! empty($failedPromote)) {
479 echo
"*** Failed to move following licenses from candidate table ***\n";
480 echo implode(
",", array_map(
function ($x) {
482 }, $failedPromote)) .
"\n";
493 $rows = $dbManager->getRows(
494 "SELECT DISTINCT rf_licensetype FROM license_ref
495 WHERE rf_licensetype IS NOT NULL AND rf_licensetype <> ''
496 ORDER BY rf_licensetype",
497 array(),
'updateLicenseTypesConfig.fetchTypes');
503 foreach ($rows as $row) {
504 $dbTypes[$row[
'rf_licensetype']] =
true;
507 $confRow = $dbManager->getSingleRow(
508 "SELECT conf_value FROM sysconfig WHERE variablename=$1",
509 array(
'LicenseTypes'),
'updateLicenseTypesConfig.fetchConf');
511 if ($confRow ===
false || $confRow ===
null) {
515 $existingTypes = array();
516 $existingTypesLower = array();
517 if (!empty($confRow[
'conf_value'])) {
518 foreach (explode(
',', $confRow[
'conf_value']) as $t) {
520 if ($trimmed !==
'') {
521 $existingTypes[$trimmed] =
true;
522 $existingTypesLower[strtolower($trimmed)] =
true;
528 foreach ($dbTypes as $type => $_) {
529 if (!isset($existingTypesLower[strtolower($type)])) {
533 if (empty($newTypes)) {
537 $merged = array_merge(array_keys($existingTypes), $newTypes);
538 $newValue = implode(
', ', $merged);
541 "UPDATE sysconfig SET conf_value=$1 WHERE variablename=$2",
542 array($newValue,
'LicenseTypes'),
'updateLicenseTypesConfig.update');
544 print
"LicenseTypes updated: $newValue\n";
557 if (!is_dir($LIBEXECDIR)) {
558 print
"FATAL: Directory '$LIBEXECDIR' does not exist.\n";
562 if (!is_readable($LIBEXECDIR)) {
563 print
"FATAL: Unable to access '$LIBEXECDIR'.\n";
567 if ($tableName ===
'license_ref_2') {
568 $dbManager->queryOnce(
"DROP TABLE IF EXISTS license_ref_2",
569 __METHOD__.
'.dropAncientBackUp');
570 $dbManager->queryOnce(
"CREATE TABLE license_ref_2 (LIKE license_ref INCLUDING DEFAULTS)",
571 __METHOD__.
'.backUpData');
574 $keysToBeChanged = array(
575 'rf_OSIapproved' =>
'"rf_OSIapproved"',
576 'rf_FSFfree'=>
'"rf_FSFfree"',
577 'rf_GPLv2compatible' =>
'"rf_GPLv2compatible"',
578 'rf_GPLv3compatible'=>
'"rf_GPLv3compatible"',
579 'rf_Fedora' =>
'"rf_Fedora"'
582 "rf_spdx_id" =>
"rf_shortname",
588 $jsonData = json_decode(file_get_contents(
"$LIBEXECDIR/licenseRef.json"),
true);
589 foreach($jsonData as $licenseArray) {
590 foreach ($keysToReplicate as $duplicateKey => $originalKey) {
591 if ($licenseArray[
'rf_spdx_compatible'] ==
't') {
592 $licenseArray[$duplicateKey] = $licenseArray[$originalKey];
594 $licenseArray[$duplicateKey] =
"";
597 foreach ($keysToRemove as $key) {
598 unset($licenseArray[$key]);
600 ksort($licenseArray);
601 $arrayKeys = array_keys($licenseArray);
602 $arrayValues = array_values($licenseArray);
603 $keys = strtr(implode(
",", $arrayKeys), $keysToBeChanged);
604 $statementName = __METHOD__ .
'.insertInTo' . $tableName .
'.' . md5($tableName . $keys);
605 $valuePlaceHolders =
"$" . join(
",$",range(1, count($arrayKeys)));
606 $md5PlaceHolder =
"$". (count($arrayKeys) + 1);
607 $arrayValues[] = $licenseArray[
'rf_text'];
608 $SQL =
"INSERT INTO $tableName ( $keys,rf_md5 ) " .
609 "VALUES ($valuePlaceHolders,md5($md5PlaceHolder));";
610 $dbManager->prepare($statementName, $SQL);
611 $dbManager->execute($statementName, $arrayValues);
613 $dbManager->commit();
625 function initLicenseRefTable($Verbose)
634 $dbManager->prepare(__METHOD__.
".newLic",
"SELECT * FROM license_ref_2");
635 $result_new = $dbManager->execute(__METHOD__.
".newLic");
637 $dbManager->prepare(__METHOD__.
'.licenseRefByShortname',
638 'SELECT *,md5(rf_text) AS hash FROM license_ref WHERE rf_shortname=$1');
641 while ($row = pg_fetch_assoc($result_new))
643 $rf_shortname = $row[
'rf_shortname'];
644 $result_check = $dbManager->execute(__METHOD__.
'.licenseRefByShortname', array($rf_shortname));
645 $count = pg_num_rows($result_check);
647 $rf_text = $row[
'rf_text'];
648 $rf_url = $row[
'rf_url'];
649 $rf_fullname = $row[
'rf_fullname'];
650 $rf_notes = $row[
'rf_notes'];
651 $rf_active = $row[
'rf_active'];
652 $marydone = $row[
'marydone'];
653 $rf_text_updatable = $row[
'rf_text_updatable'];
654 $rf_detector_type = $row[
'rf_detector_type'];
655 $rf_flag = $row[
'rf_flag'];
656 $rf_spdx_id = $row[
'rf_spdx_id'];
657 $rf_licensetype = $row[
'rf_licensetype'];
661 $row_check = pg_fetch_assoc($result_check);
662 pg_free_result($result_check);
664 $rf_text_check = $row_check[
'rf_text'];
665 $rf_url_check = $row_check[
'rf_url'];
666 $rf_fullname_check = $row_check[
'rf_fullname'];
667 $rf_notes_check = $row_check[
'rf_notes'];
668 $rf_active_check = $row_check[
'rf_active'];
669 $marydone_check = $row_check[
'marydone'];
670 $rf_text_updatable_check = $row_check[
'rf_text_updatable'];
671 $rf_detector_type_check = $row_check[
'rf_detector_type'];
672 $rf_flag_check = $row_check[
'rf_flag'];
673 $rf_spdx_id_check = $row_check[
'rf_spdx_id'];
674 $rf_licensetype_check = $row_check[
'rf_licensetype'];
677 if ($candidateLicense) {
681 $statement = __METHOD__ .
".updateLicenseRef";
682 $sql =
"UPDATE license_ref SET ";
683 if (($rf_flag_check == 1 && $rf_flag == 1) &&
684 ($rf_text_check != $rf_text && !empty($rf_text) &&
685 !(stristr($rf_text,
'License by Nomos')) &&
686 !(stristr($rf_text,
'License by OJO')))) {
687 $params[] = $rf_text;
688 $position =
"$" . count($params);
689 $sql .=
"rf_text=$position,rf_md5=md5($position),rf_flag=1,";
690 $statement .=
".insertT";
692 if ($rf_url_check != $rf_url && !empty($rf_url)) {
694 $position =
"$" . count($params);
695 $sql .=
"rf_url=$position,";
696 $statement .=
".url";
698 if ($rf_fullname_check != $rf_fullname && !empty($rf_fullname)) {
699 $params[] = $rf_fullname;
700 $position =
"$" . count($params);
701 $sql .=
"rf_fullname=$position,";
702 $statement .=
".name";
704 if ($rf_notes_check != $rf_notes && !empty($rf_notes)) {
705 $params[] = $rf_notes;
706 $position =
"$" . count($params);
707 $sql .=
"rf_notes=$position,";
708 $statement .=
".notes";
710 if ($rf_active_check != $rf_active && !empty($rf_active)) {
711 $params[] = $rf_active;
712 $position =
"$" . count($params);
713 $sql .=
"rf_active=$position,";
714 $statement .=
".active";
716 if ($marydone_check != $marydone && !empty($marydone)) {
717 $params[] = $marydone;
718 $position =
"$" . count($params);
719 $sql .=
"marydone=$position,";
720 $statement .=
".marydone";
722 if ($rf_text_updatable_check != $rf_text_updatable && !empty($rf_text_updatable)) {
723 $params[] = $rf_text_updatable;
724 $position =
"$" . count($params);
725 $sql .=
"rf_text_updatable=$position,";
726 $statement .=
".tUpdate";
728 if ($rf_detector_type_check != $rf_detector_type && !empty($rf_detector_type)) {
729 $params[] = $rf_detector_type;
730 $position =
"$" . count($params);
731 $sql .=
"rf_detector_type=$position,";
732 $statement .=
".dType";
734 if (empty($rf_spdx_id_check) && !empty($rf_spdx_id) &&
735 $rf_spdx_id_check != $rf_spdx_id) {
736 $params[] = $rf_spdx_id;
737 $position =
"$" . count($params);
738 $sql .=
"rf_spdx_id=$position,";
739 $statement .=
".spdxId";
741 if (!empty($rf_licensetype) && $rf_licensetype_check != $rf_licensetype) {
742 $params[] = $rf_licensetype;
743 $position =
"$" . count($params);
744 $sql .=
"rf_licensetype=$position,";
745 $statement .=
".licType";
747 $sql = substr_replace($sql,
"", -1);
749 if ($sql !=
"UPDATE license_ref SET") {
750 $params[] = $rf_shortname;
751 $position =
"$" . count($params);
752 $sql .=
" WHERE rf_shortname=$position;";
754 $dbManager->getSingleRow($sql, $params, $statement);
755 }
catch (\Exception $e) {
756 global $FAILED_LICENSE_IMPORT;
757 $FAILED_LICENSE_IMPORT[] = array($rf_shortname,
"UPDATE");
761 pg_free_result($result_check);
763 $params[
'rf_shortname'] = $rf_shortname;
764 $params[
'rf_text'] = $rf_text;
765 $params[
'rf_url'] = $rf_url;
766 $params[
'rf_fullname'] = $rf_fullname;
767 $params[
'rf_notes'] = $rf_notes;
768 $params[
'rf_active'] = $rf_active;
769 $params[
'rf_text_updatable'] = $rf_text_updatable;
770 $params[
'rf_detector_type'] = $rf_detector_type;
771 $params[
'marydone'] = $marydone;
772 $params[
'rf_spdx_id'] = $rf_spdx_id;
773 $params[
'rf_licensetype'] = $rf_licensetype;
777 pg_free_result($result_new);
779 $dbManager->queryOnce(
"DROP TABLE IF EXISTS license_ref_2");
780 $dbManager->commit();
795 $tableName =
"license_ref";
797 $tableName =
"license_candidate";
799 $statement = __METHOD__ .
".$tableName";
800 $sql =
"SELECT * FROM ONLY $tableName WHERE rf_shortname = $1;";
801 $licenseRow = $dbManager->getSingleRow($sql, array($rf_shortname),
803 if (! empty($licenseRow)) {
819 $mainLicense =
isLicenseExists($dbManager, $candidateLicense[
'rf_shortname'],
821 $statement = __METHOD__ .
".md5Exists";
822 $sql =
"SELECT rf_pk FROM ONLY license_ref WHERE md5(rf_text) = md5($1);";
823 $licenseRow = $dbManager->getSingleRow($sql,
824 array($candidateLicense[
'rf_text']), $statement);
825 if (! empty($licenseRow)) {
830 if ($mainLicense !==
false && $md5Exists) {
832 $updateStatements = __METHOD__ .
".updateCandidateToMain";
833 $updateCeSql =
"UPDATE clearing_event SET rf_fk = $1 WHERE rf_fk = $2;";
834 $updateCeSt = $updateStatements .
".ce";
835 $updateLsbSql =
"UPDATE license_set_bulk SET rf_fk = $1 WHERE rf_fk = $2;";
836 $updateLsbSt = $updateStatements .
".lsb";
837 $updateUclSql =
"UPDATE upload_clearing_license SET rf_fk = $1 " .
839 $updateUclSt = $updateStatements .
".ucl";
840 $deleteOcmSql =
"DELETE FROM obligation_candidate_map WHERE rf_fk = $1;";
841 $deleteOcmSt = $updateStatements .
".ocm";
843 $dbManager->getSingleRow($updateCeSql,
844 array($mainLicense[
'rf_pk'], $candidateLicense[
'rf_pk']), $updateCeSt);
845 $dbManager->getSingleRow($updateLsbSql,
846 array($mainLicense[
'rf_pk'], $candidateLicense[
'rf_pk']), $updateLsbSt);
847 $dbManager->getSingleRow($updateUclSql,
848 array($mainLicense[
'rf_pk'], $candidateLicense[
'rf_pk']), $updateUclSt);
849 $dbManager->getSingleRow($deleteOcmSql, array($candidateLicense[
'rf_pk']),
851 $dbManager->commit();
852 } elseif ($mainLicense !==
false || $md5Exists) {
858 $deleteSql =
"DELETE FROM license_candidate WHERE rf_pk = $1;";
859 $deleteStatement = __METHOD__ .
".deleteCandidte";
860 $dbManager->prepare($deleteStatement, $deleteSql);
861 $dbManager->execute($deleteStatement, array($candidateLicense[
'rf_pk']));
862 if ($mainLicense ===
false && $md5Exists ===
false) {
866 $dbManager->commit();
880 $insertStatement = __METHOD__ .
".insertNewLicense";
881 $sql =
"INSERT INTO license_ref (";
884 $insertStatement .=
".wasCandidate";
886 $sql .=
"rf_shortname, rf_text, rf_url, rf_fullname, rf_notes, rf_active, " .
887 "rf_text_updatable, rf_detector_type, marydone, rf_spdx_id, rf_licensetype, " .
888 "rf_md5, rf_add_date) VALUES (";
891 $params[] = $license[
'rf_pk'];
893 $params[] = $license[
'rf_shortname'];
894 $params[] = $license[
'rf_text'];
895 $params[] = $license[
'rf_url'];
896 $params[] = $license[
'rf_fullname'];
897 $params[] = $license[
'rf_notes'];
898 $params[] = $license[
'rf_active'];
899 $params[] = $license[
'rf_text_updatable'];
900 $params[] = $license[
'rf_detector_type'];
901 $params[] = $license[
'marydone'];
902 $params[] = $license[
'rf_spdx_id'];
903 $params[] = !empty($license[
'rf_licensetype']) ? $license[
'rf_licensetype'] :
'Unknown';
905 for ($i = 1; $i <= count($params); $i++) {
906 $sql .=
"$" . $i .
",";
909 $params[] = $license[
'rf_text'];
910 $textPos =
"$" . count($params);
912 $sql .=
"md5($textPos),now())";
915 $rfPk = $dbManager->insertPreparedAndReturn($insertStatement, $sql, $params,
917 }
catch (\Exception $e) {
918 global $FAILED_LICENSE_IMPORT;
921 $type =
"CANPROMOTE";
923 $FAILED_LICENSE_IMPORT[] = array($license[
'rf_shortname'], $type);
Populate_sysconfig()
Populate the sysconfig table with core variables.
get_pg_conn($sysconfdir, &$SysConf, $exitOnDbFail=true)
populate_from_sysconfig($conn, &$SysConf)
Migrate_20_21($DryRun)
Migrate to the uploadtree_a table.
Migrate_21_22($Verbose)
Create new groups, group_user_member, perm_upload and perm_folder records to support 2....
Migrate_33_34($dbManager, $dryRun)
migrate_35_36($dbManager, $force=false)
Migrate_36_37($dbManager, $verbose)
Migrate_37_38($dbManager, $MODDIR)
Migrate_40_41($dbManager)
Migrate_42_43(bool $verbose)
Migrate_Cmu_Mach(DbManager $dbManager, $verbose=false)
createCopyrightMigrationForCopyrightEvents($dbManager)
Kotoba_candidate_license_migration()
LicenseDB_compatibility_migration()
if(!function_exists('resolve_config_value')) $Options
renameLicensesForSpdxValidation($verbose)
Create map of old_shortname to new_shortname for SPDX and call renameLicenses.
char * trim(char *ptext)
Trimming whitespace.
FossdashConfigInit($sysconfdir, &$SysConf)
Initialize the fossdash configuration after bootstrap().
insertInToLicenseRefTableUsingJson($tableName)
insert into license_ref table using json file.
mergeCandidateLicense($dbManager, $candidateLicense)
isLicenseExists($dbManager, $rf_shortname, $isCandidate=true)
updateLicenseTypesConfig()
Append new rf_licensetype values found in license_ref to the LicenseTypes sysconfig entry.
insertNewLicense($dbManager, $license, $wasCandidate=false)
explainUsage()
Print Usage statement.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
bootstrap($sysconfdir="")
Bootstrap the fossology php library.