Commit d8076a08 authored by Shaheem Azmal M MD's avatar Shaheem Azmal M MD

feat(licenseref): convert licenseref file from sql to json format

Signed-off-by: Shaheem Azmal M MD's avatarShaheem Azmal M MD <shaheem.azmal@gmail.com>
parent 6c4fc482
......@@ -15,7 +15,7 @@ dbcreate: dbcreate-process
install: all
$(INSTALL_DATA) fossologyinit.sql $(DESTDIR)$(LIBEXECDIR)/fossologyinit.sql
$(INSTALL_DATA) licenseref.sql $(DESTDIR)$(LIBEXECDIR)/licenseref.sql
$(INSTALL_DATA) licenseRef.json $(DESTDIR)$(LIBEXECDIR)/licenseRef.json
$(INSTALL_DATA) dbmigrate_1.4-2.0.php $(DESTDIR)$(LIBEXECDIR)/dbmigrate_1.4-2.0.php
$(INSTALL_DATA) dbmigrate_2.0-2.1.php $(DESTDIR)$(LIBEXECDIR)/dbmigrate_2.0-2.1.php
$(INSTALL_DATA) dbmigrate_2.1-2.2.php $(DESTDIR)$(LIBEXECDIR)/dbmigrate_2.1-2.2.php
......@@ -44,7 +44,7 @@ install: all
uninstall:
rm -f $(DESTDIR)$(LIBEXECDIR)/fossologyinit.sql
rm -f $(DESTDIR)$(LIBEXECDIR)/licenseref.sql
rm -f $(DESTDIR)$(LIBEXECDIR)/licenseRef.json
rm -f $(DESTDIR)$(LIBEXECDIR)/clearingProperties.*
rm -f $(DESTDIR)$(LIBEXECDIR)/dbcreate
rm -f $(DESTDIR)$(LIBEXECDIR)/dbmigrate_1.4-2.0.php
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,7 @@
<?php
/***********************************************************
Copyright (C) 2008-2015 Hewlett-Packard Development Company, L.P.
Copyright (C) 2014-2015 Siemens AG
Copyright (C) 2014-2015,2019 Siemens AG
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -210,16 +210,14 @@ if ($UpdateLiceneseRef)
initLicenseRefTable(false);
}
else if ($row['count'] == 0) {
/** import licenseref.sql */
$sqlstmts = file_get_contents("$LIBEXECDIR/licenseref.sql");
$dbManager->queryOnce($sqlstmts,$stmt=__METHOD__."$LIBEXECDIR/licenseref.sql");
insertInToLicenseRefTableUsingJson('license_ref');
$row_max = $dbManager->getSingleRow("SELECT max(rf_pk) from license_ref",array(),'license_ref.max.rf_pk');
$current_license_ref_rf_pk_seq = $row_max['max'];
$dbManager->getSingleRow("SELECT setval('license_ref_rf_pk_seq', $current_license_ref_rf_pk_seq)",array(),
'set next license_ref_rf_pk_seq value');
print "fresh install, import licenseref.sql \n";
print "fresh install, import licenseRef.json \n";
}
}
......@@ -378,16 +376,12 @@ if($errors>0)
}
exit($errors);
/**
* \brief Load the license_ref table with licenses.
*
* \param $Verbose display database load progress information. If $Verbose is false,
* this function only prints errors.
* \brief insert into license_ref table using json file.
*
* \return 0 on success, 1 on failure
* \param $tableName
**/
function initLicenseRefTable($Verbose)
function insertInToLicenseRefTableUsingJson($tableName)
{
global $LIBEXECDIR;
global $dbManager;
......@@ -396,22 +390,53 @@ function initLicenseRefTable($Verbose)
print "FATAL: Directory '$LIBEXECDIR' does not exist.\n";
return (1);
}
$dir = opendir($LIBEXECDIR);
if (!$dir) {
print "FATAL: Unable to access '$LIBEXECDIR'.\n";
return (1);
}
$dbManager->begin();
if ($tableName === 'license_ref_2') {
$dbManager->queryOnce("DROP TABLE IF EXISTS license_ref_2", $statment = __METHOD__.'.dropAncientBackUp');
$dbManager->queryOnce("CREATE TABLE license_ref_2 AS SELECT * FROM license_ref WHERE 1=2", $statment = __METHOD__.'.backUpData');
}
/** import licenseRef.json */
$keysToBeChanged = array(
'rf_OSIapproved' => '"rf_OSIapproved"',
'rf_FSFfree'=> '"rf_FSFfree"',
'rf_GPLv2compatible' => '"rf_GPLv2compatible"',
'rf_GPLv3compatible'=> '"rf_GPLv3compatible"',
'rf_Fedora' => '"rf_Fedora"'
);
$jsonData = json_decode(file_get_contents("$LIBEXECDIR/licenseRef.json"), true);
$statementName = __METHOD__.'.insertInTo'.$tableName;
foreach($jsonData as $licenseArrayKey => $licenseArray) {
$keys = strtr(implode(",", array_keys($licenseArray)), $keysToBeChanged);
$valuePlaceHolders = "$" . join(",$",range(1, count(array_keys($licenseArray))));
$SQL = "INSERT INTO $tableName ( $keys ) VALUES ($valuePlaceHolders);";
$dbManager->prepare($statementName, $SQL);
$dbManager->execute($statementName, array_values($licenseArray));
}
$dbManager->commit();
return;
}
$dbManager->queryOnce("BEGIN");
$dbManager->queryOnce("DROP TABLE IF EXISTS license_ref_2",$stmt=__METHOD__.'.dropAncientBackUp');
/* create a new temp table structure only - license_ref_2 */
$dbManager->queryOnce("CREATE TABLE license_ref_2 as select * from license_ref WHERE 1=2",$stmt=__METHOD__.'.backUpData');
/** import licenseref.sql */
$sqlstmts = file_get_contents("$LIBEXECDIR/licenseref.sql");
$sqlstmts = str_replace("license_ref","license_ref_2", $sqlstmts);
$dbManager->queryOnce($sqlstmts);
/**
* \brief Load the license_ref table with licenses.
*
* \param $Verbose display database load progress information. If $Verbose is false,
* this function only prints errors.
*
* \return 0 on success, 1 on failure
**/
function initLicenseRefTable($Verbose)
{
global $dbManager;
$dbManager->queryOnce("BEGIN");
insertInToLicenseRefTableUsingJson('license_ref_2');
$dbManager->prepare(__METHOD__.".newLic", "select * from license_ref_2");
$result_new = $dbManager->execute(__METHOD__.".newLic");
......@@ -449,10 +474,10 @@ function initLicenseRefTable($Verbose)
$rf_flag_check = $row_check['rf_flag'];
$sql = "UPDATE license_ref set ";
if($rf_flag_check == 1 || $rf_flag == 1) {
if ($rf_text_check != $rf_text && !empty($rf_text) && !(stristr($rf_text, 'License by Nomos'))) $sql .= " rf_text='$rf_text', rf_flag='1',";
} else {
if ($rf_flag_check == 2 && $rf_flag == 1) {
$sql .= " rf_text='$rf_text_check',";
} else {
if ($rf_text_check != $rf_text && !empty($rf_text) && !(stristr($rf_text, 'License by Nomos'))) $sql .= " rf_text='$rf_text', rf_flag='1',";
}
if ($rf_url_check != $rf_url && !empty($rf_url)) $sql .= " rf_url='$rf_url',";
if ($rf_fullname_check != $rf_fullname && !empty($rf_fullname)) $sql .= " rf_fullname ='$rf_fullname',";
......
<?php
/*
Copyright (C) 2014-2018, Siemens AG
Copyright (C) 2014-2019, Siemens AG
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -199,7 +199,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpTables();
$this->setUpRepo();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licId1 = $licenseRef1->getId();
......@@ -245,7 +245,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpTables();
$this->setUpRepo();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licId1 = $licenseRef1->getId();
......@@ -292,7 +292,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpTables();
$this->setUpRepo();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licId1 = $licenseRef1->getId();
......@@ -340,7 +340,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpTables();
$this->setUpRepo();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licId1 = $licenseRef1->getId();
......@@ -392,9 +392,9 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpTables();
$this->setUpRepo();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef2 = $this->licenseDao->getLicenseByShortName("GPL-1.0")->getRef();
$licenseRef3 = $this->licenseDao->getLicenseByShortName("APL-1.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licenseRef2 = $this->licenseDao->getLicenseByShortName("BSL-1.0")->getRef();
$licenseRef3 = $this->licenseDao->getLicenseByShortName("ZPL-1.1")->getRef();
$licId1 = $licenseRef1->getId();
$licId2 = $licenseRef2->getId();
......@@ -451,9 +451,9 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpTables();
$this->setUpRepo();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef2 = $this->licenseDao->getLicenseByShortName("GPL-1.0")->getRef();
$licenseRef3 = $this->licenseDao->getLicenseByShortName("APL-1.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licenseRef2 = $this->licenseDao->getLicenseByShortName("BSL-1.0")->getRef();
$licenseRef3 = $this->licenseDao->getLicenseByShortName("ZPL-1.1")->getRef();
$licId1 = $licenseRef1->getId();
$licId2 = $licenseRef2->getId();
......@@ -510,9 +510,9 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpTables();
$this->setUpRepo();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef2 = $this->licenseDao->getLicenseByShortName("GPL-1.0")->getRef();
$licenseRef3 = $this->licenseDao->getLicenseByShortName("APL-1.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licenseRef2 = $this->licenseDao->getLicenseByShortName("BSL-1.0")->getRef();
$licenseRef3 = $this->licenseDao->getLicenseByShortName("ZPL-1.1")->getRef();
$licId1 = $licenseRef1->getId();
$licId2 = $licenseRef2->getId();
......@@ -565,7 +565,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpTables();
$this->setUpRepo();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licId1 = $licenseRef1->getId();
$agentBulk = 6;
......@@ -612,7 +612,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpRepo();
$monkAgentId = 5;
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licId1 = $licenseRef1->getId();
$pfile = 4;
......@@ -656,7 +656,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpRepo();
$monkAgentId = 5;
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licId1 = $licenseRef1->getId();
$pfile = 4;
......
<?php
/*
Copyright (C) 2014-2015, Siemens AG
Copyright (C) 2014-2015,2019 Siemens AG
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -205,7 +205,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$jobId = 42;
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licenseRef2 = $this->licenseDao->getLicenseByShortName("Glide")->getRef();
$addedLicenses = array($licenseRef1, $licenseRef2);
......@@ -272,7 +272,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$this->setUpTables();
$this->setUpRepo();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licId1 = $licenseRef1->getId();
......@@ -416,7 +416,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
$jobId = 42;
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licenseRef2 = $this->licenseDao->getLicenseByShortName("Glide")->getRef();
$agentLicId = $this->licenseDao->getLicenseByShortName("Adaptec")->getRef()->getId();
......
<?php
/*
Copyright (C) 2015, Siemens AG
Copyright (C) 2015,2019 Siemens AG
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -82,16 +82,25 @@ abstract class TestAbstractDb
public function insertData_license_ref($limit=140)
{
$keysToBeChanged = array(
'rf_OSIapproved' => '"rf_OSIapproved"',
'rf_FSFfree'=> '"rf_FSFfree"',
'rf_GPLv2compatible' => '"rf_GPLv2compatible"',
'rf_GPLv3compatible'=> '"rf_GPLv3compatible"',
'rf_Fedora' => '"rf_Fedora"'
);
/** import licenseRef.json */
$LIBEXECDIR = $this->dirnameRec(__FILE__, 5) . '/install/db';
$sqlstmts = file_get_contents("$LIBEXECDIR/licenseref.sql");
$delimiter = "INSERT INTO license_ref";
$splitted = explode($delimiter, $sqlstmts);
for ($i = 1; $i < count($splitted); $i ++) {
$sql = $this->queryConverter($splitted[$i]);
$this->dbManager->queryOnce($delimiter . $sql);
if ($i > $limit) {
$jsonData = json_decode(file_get_contents("$LIBEXECDIR/licenseRef.json"), true);
$statementName = __METHOD__.'.insertInToLicenseRef';
foreach ($jsonData as $licenseArrayKey => $licenseArray) {
$keys = strtr(implode(",", array_keys($licenseArray)), $keysToBeChanged);
$valuePlaceHolders = "$" . join(",$",range(1, count(array_keys($licenseArray))));
$SQL = "INSERT INTO license_ref ( $keys ) VALUES ($valuePlaceHolders);";
$this->dbManager->prepare($statementName, $SQL);
$this->dbManager->execute($statementName, array_values($licenseArray));
if ($licenseArrayKey >= $limit) {
break;
}
}
......
<?php
/*
Copyright (C) 2014-2015, Siemens AG
Copyright (C) 2014-2015,2019 Siemens AG
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -120,7 +120,7 @@ class MonkScheduledTest extends \PHPUnit\Framework\TestCase
$this->testDb->alterTables(array('agent','pfile','upload','ars_master','license_ref_bulk','license_set_bulk','clearing_event','license_file','highlight','clearing_decision'),false);
$this->testDb->createInheritedTables();
$this->testDb->insertData(array('pfile','upload','uploadtree_a','users'), false);
$this->testDb->insertData_license_ref();
$this->testDb->insertData_license_ref(200);
}
private function getHeartCount($output)
......
<?php
/*
Copyright (C) 2014-2015, Siemens AG
Copyright (C) 2014-2015,2019 Siemens AG
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
......@@ -281,7 +281,7 @@ class SchedulerTest extends \PHPUnit\Framework\TestCase
*/
protected function insertDecisionFromTwoEvents($scope=DecisionScopes::ITEM,$originallyClearedItemId=23)
{
$licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
$licenseRef1 = $this->licenseDao->getLicenseByShortName("SPL-1.0")->getRef();
$licenseRef2 = $this->licenseDao->getLicenseByShortName("Glide")->getRef();
$addedLicenses = array($licenseRef1, $licenseRef2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment