FOSSology  4.7.1
Open Source License Compliance by Open Source Software
dbmigrate_legacy-license-names.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2026 Fossology contributors
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
29 {
30  return array(
31  /* nomos reported GFDL-1.3 until the SPDX -only form was adopted. */
32  'GFDL-1.3' => 'GFDL-1.3-only',
33 
34  /* SPDX defines CMU-Mach and MIT-CMU, but no bare CMU. Rows survive from
35  * scans made before nomos stopped emitting the name. */
36  'CMU' => 'CMU-Mach',
37 
38  /* Was misspelled ('Reponsible') and is now named for the RAIL family. */
39  'Reponsible-AI-Source-Code-License-v1.0' => 'RAIL-S-1.0',
40 
41  /* nomos named every Autoconf exception wording it could not version by
42  * the bare name; nearly all of them were the generic wording. */
43  'Autoconf-exception' => 'Autoconf-exception-generic',
44  /* The hyphenated forms are FOSSology-local and not valid SPDX. */
45  'GPL-2.0-with-autoconf-exception' => 'GPL-2.0-only WITH Autoconf-exception-3.0',
46  'GPL-2.0-with-bison-exception' => 'GPL-2.0-only WITH Bison-exception-2.2',
47  'GPL-2.0-with-classpath-exception' => 'GPL-2.0-only WITH Classpath-exception-2.0',
48  'GPL-2.0-with-font-exception' => 'GPL-2.0-only WITH Font-exception-2.0',
49  'GPL-2.0-with-GCC-exception' => 'GPL-2.0-only WITH GCC-exception-3.1',
50  'GPL-2.0+-with-bison-exception' => 'GPL-2.0-or-later WITH Bison-exception-2.2',
51  'GPL-2.0-or-later-with-Bison-2.2-exception' => 'GPL-2.0-or-later WITH Bison-exception-2.2',
52  'GPL-2.0+-with-classpath-exception' => 'GPL-2.0-or-later WITH Classpath-exception-2.0',
53  'GPL-3.0-with-autoconf-exception' => 'GPL-3.0-only WITH Autoconf-exception-3.0',
54  'GPL-3.0-with-bison-exception' => 'GPL-3.0-only WITH Bison-exception-2.2',
55  'GPL-3.0-with-classpath-exception' => 'GPL-3.0-only WITH Classpath-exception-2.0',
56  'GPL-3.0-with-GCC-exception' => 'GPL-3.0-only WITH GCC-exception-3.1',
57  'GPL-3.0+-with-bison-exception' => 'GPL-3.0-or-later WITH Bison-exception-2.2',
58  'GPL-3.0+-with-classpath-exception' => 'GPL-3.0-or-later WITH Classpath-exception-2.0',
59 
60  /* Not valid SPDX idstrings. convertToSpdxId() prefixes at report time. */
61  'Alliance for Open Media Patent License 1.0' => 'AOM-Patent-1.0',
62  'unRAR restriction' => 'unRAR-restriction',
63  'GPL-2.1[sic]' => 'GPL-2.1-sic',
64  'GPL-2.1+[sic]' => 'GPL-2.1-or-later-sic',
65  'CopyLeft[1]' => 'CopyLeft-1',
66  'CopyLeft[2]' => 'CopyLeft-2',
67  'GPL(rms)' => 'GPL-rms',
68  'X/Open' => 'X-Open',
69  'X/Open-style' => 'X-Open-style',
70  'CECILL(dual)' => 'CECILL-dual',
71  'ImageMagick(Apache)' => 'ImageMagick-Apache',
72  'SGI_GLX' => 'SGI-GLX',
73  'ANT+SharedSource' => 'ANT-SharedSource',
74  'AgainstDRM' => 'Against-DRM',
75  'M-Plus-Project' => 'M-Plus',
76  'GPL-2.0-or-laterKDEupgradeClause' => 'GPL-2.0-or-later-with-KDE-upgrade-clause',
77  'SGI_GLX-1.0' => 'SGI-GLX-1.0',
78  'Public-domain(C)' => 'Public-domain-copyright',
79  'UnclassifiedLicense(PS)' => 'UnclassifiedLicense-PS',
80  'Empty-file-no-data!' => 'Empty-file-no-data',
81  'Platform-Computing(RESTRICTED)' => 'Platform-Computing-RESTRICTED',
82 
83  /* Written exception-first; nomos uses <license>-with-<exception>. */
84  'openssl-exception-AGPL-3.0-or-later' => 'AGPL-3.0-or-later-with-openssl-exception',
85  'openssl-exception-GPL-2.0-or-later' => 'GPL-2.0-or-later-with-openssl-exception',
86  'GPL-3.0-or-later-openssl' => 'GPL-3.0-or-later-with-openssl-exception',
87  'cygwin-exception-LGPL-3.0-or-later' => 'LGPL-3.0-or-later-with-Cygwin-exception',
88  'spell-checker-exception-LGPL-2.1-or-later' => 'LGPL-2.1-or-later-with-spell-checker-exception',
89  'opensc-openssl-openpace-exception-gpl' => 'GPL-with-opensc-openssl-openpace-exception',
90 
91  /* Case differed from the seeded entry, so each scan created a second row. */
92  'DOCBOOK' => 'Docbook',
93  'MindTerm' => 'Mindterm',
94  'Qt.Commercial' => 'QT.Commercial',
95  'SpikeSource' => 'Spikesource',
96  'VMware-EULA' => 'VMWare-EULA',
97  'WxWindows' => 'wxWindows',
98  'ubuntu-font-1.0' => 'Ubuntu-font-1.0',
99  'universal-foss-exception-1.0' => 'Universal-FOSS-exception-1.0',
100  'naist-2003' => 'NAIST-2003',
101  );
102 }
103 
109 {
110  return array(
111  array('clearing_event', 'rf_fk'),
112  array('custom_phrase_license_map', 'rf_fk'),
113  array('license_file', 'rf_fk'),
114  array('license_map', 'rf_fk'),
115  array('license_map', 'rf_parent'),
116  array('license_set_bulk', 'rf_fk'),
117  array('obligation_candidate_map', 'rf_fk'),
118  array('obligation_map', 'rf_fk'),
119  array('upload_clearing_license', 'rf_fk'),
120  array('comp_result', 'first_rf_fk'),
121  array('comp_result', 'second_rf_fk'),
122  array('license_rules', 'first_rf_fk'),
123  array('license_rules', 'second_rf_fk'),
124  );
125 }
126 
135 function legacyLicenseWrite(DbManager $dbManager, $sql, $params, $statementName)
136 {
137  $dbManager->prepare($statementName, $sql);
138  $res = $dbManager->execute($statementName, $params);
139  $dbManager->freeResult($res);
140 }
141 
154 function updateExcludedObligationNames(DbManager $dbManager, $old, $new)
155 {
156  if (!$dbManager->existsTable('report_info')) {
157  return;
158  }
159 
160  /* Match the escaping the column was written with, then the one the pattern
161  * needs. A literal backslash has to survive the replacement string too. */
162  $oldName = trim(json_encode($old), '"');
163  $newName = trim(json_encode($new), '"');
164  $pattern = '(^|[^A-Za-z0-9-])' . preg_quote($oldName) . '([^A-Za-z0-9-]|$)';
165  $replacement = '\1' . str_replace('\\', '\\\\', $newName) . '\2';
166 
167  legacyLicenseWrite($dbManager,
168  "UPDATE report_info
169  SET ri_excluded_obligations =
170  regexp_replace(ri_excluded_obligations::text, $1, $2, 'g')::json
171  WHERE ri_excluded_obligations::text ~ $1",
172  array($pattern, $replacement), __FUNCTION__);
173 }
174 
183 function renameOrMergeLicense(DbManager $dbManager, $old, $new, $verbose = false)
184 {
185  $row = $dbManager->getSingleRow(
186  "SELECT
187  (SELECT rf_pk FROM license_ref WHERE rf_shortname=$1 LIMIT 1) AS old_id,
188  (SELECT rf_pk FROM license_ref WHERE rf_shortname=$2 LIMIT 1) AS new_id",
189  array($old, $new),
190  __FUNCTION__ . '.getIds'
191  );
192 
193  $oldId = (!empty($row) && !empty($row['old_id'])) ? intval($row['old_id']) : 0;
194  $newId = (!empty($row) && !empty($row['new_id'])) ? intval($row['new_id']) : 0;
195 
196  if ($oldId === 0 || $oldId === $newId) {
197  return;
198  }
199 
200  if ($newId === 0) {
201  legacyLicenseWrite($dbManager, "UPDATE license_ref SET rf_shortname=$1 WHERE rf_pk=$2",
202  array($new, $oldId), __FUNCTION__ . '.rename');
203  if ($verbose) {
204  print "renamed license $old to $new\n";
205  }
206  return;
207  }
208 
209  foreach (getLicenseRefReferences() as $ref) {
210  list ($table, $column) = $ref;
211  if (!$dbManager->existsTable($table)) {
212  continue;
213  }
214  legacyLicenseWrite($dbManager, "UPDATE $table SET $column=$1 WHERE $column=$2",
215  array($newId, $oldId), __FUNCTION__ . ".move.$table.$column");
216  }
217 
218  legacyLicenseWrite($dbManager, "DELETE FROM license_ref WHERE rf_pk=$1",
219  array($oldId), __FUNCTION__ . '.deleteLegacy');
220  if ($verbose) {
221  print "merged license $old into existing $new\n";
222  }
223 }
224 
230 function Migrate_Legacy_License_Names(DbManager $dbManager, $verbose = false)
231 {
232  if (!$dbManager->existsTable('license_ref')) {
233  return;
234  }
235 
236  $dbManager->begin();
237  foreach (getLegacyLicenseNames() as $old => $new) {
238  renameOrMergeLicense($dbManager, $old, $new, $verbose);
239  updateExcludedObligationNames($dbManager, $old, $new);
240  }
241  $dbManager->commit();
242 }
Migrate_Legacy_License_Names(DbManager $dbManager, $verbose=false)
updateExcludedObligationNames(DbManager $dbManager, $old, $new)
Rewrite a shortname held in report_info.ri_excluded_obligations.
getLicenseRefReferences()
Columns referencing license_ref.rf_pk, as table => column pairs.
legacyLicenseWrite(DbManager $dbManager, $sql, $params, $statementName)
Run a parameterised write; getSingleRow() would fetch a command result.
getLegacyLicenseNames()
Deprecated shortname => current shortname.
renameOrMergeLicense(DbManager $dbManager, $old, $new, $verbose=false)
Rename a license, or merge it away when the target already exists.
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690