11 require_once(dirname(dirname(dirname(dirname(__FILE__)))) .
"/vendor/autoload.php");
20 protected function dirnameRec($path, $depth = 1)
22 for ($i = 0; $i < $depth; $i ++) {
23 $path = dirname($path);
38 public function insertData($tableList, $invert=FALSE, $dataFile=
null)
40 $testdataFile = $dataFile ?: dirname(__FILE__) .
'/testdata.sql';
41 $testdata = file_get_contents($testdataFile);
42 $delimiter =
'INSERT INTO ';
43 $offset = strpos($testdata, $delimiter);
44 while (
false !== $offset) {
45 $nextOffset = strpos($testdata, $delimiter, $offset + 1);
46 if (
false === $nextOffset) {
47 $sql = substr($testdata, $offset);
49 $sql = substr($testdata, $offset, $nextOffset - $offset);
52 preg_match(
'/^INSERT INTO (?P<name>\w+) /', $sql, $table);
53 if (($invert ^ ! in_array($table[
'name'], $tableList))) {
54 $offset = $nextOffset;
58 $offset = $nextOffset;
74 $keysToBeChanged = array(
75 'rf_OSIapproved' =>
'"rf_OSIapproved"',
76 'rf_FSFfree'=>
'"rf_FSFfree"',
77 'rf_GPLv2compatible' =>
'"rf_GPLv2compatible"',
78 'rf_GPLv3compatible'=>
'"rf_GPLv3compatible"',
79 'rf_Fedora' =>
'"rf_Fedora"'
82 "rf_spdx_id" =>
"rf_shortname",
89 $LIBEXECDIR = $this->dirnameRec(__FILE__, 5) .
'/install/db';
90 $jsonData = json_decode(file_get_contents(
"$LIBEXECDIR/licenseRef.json"),
true);
91 $statementName = __METHOD__.
'.insertInToLicenseRef';
92 foreach ($jsonData as $licenseArrayKey => $licenseArray) {
93 foreach ($keysToReplicate as $duplicateKey => $originalKey) {
94 if ($licenseArray[
'rf_spdx_compatible'] ==
't') {
95 $licenseArray[$duplicateKey] = $licenseArray[$originalKey];
97 $licenseArray[$duplicateKey] =
"";
100 foreach ($keysToRemove as $key) {
101 unset($licenseArray[$key]);
103 ksort($licenseArray);
104 $arrayKeys = array_keys($licenseArray);
105 $arrayValues = array_values($licenseArray);
106 $keys = strtr(implode(
",", $arrayKeys), $keysToBeChanged);
107 $valuePlaceHolders =
"$" . join(
",$",range(1, count($arrayKeys)));
108 $md5PlaceHolder =
"$". (count($arrayKeys) + 1);
109 $arrayValues[] = $licenseArray[
'rf_text'];
110 $SQL =
"INSERT INTO license_ref ( $keys,rf_md5 ) " .
111 "VALUES ($valuePlaceHolders,md5($md5PlaceHolder));";
112 $this->
dbManager->prepare($statementName, $SQL);
113 $this->
dbManager->execute($statementName, $arrayValues);
114 if ($licenseArrayKey >= $limit) {
125 protected function applySchema($type, $elementList, $invert=
false)
127 $coreSchemaFile = $this->dirnameRec(__FILE__, 4) .
'/www/ui/core-schema.dat';
129 require($coreSchemaFile);
130 foreach ($Schema[$type] as $viewName => $sql) {
131 if ($invert ^ ! in_array($viewName, $elementList)) {
134 $sqlCreate = is_array($sql) ? $sql[
'CREATE'] : $sql;
154 $coreSchemaFile = $this->dirnameRec(__FILE__, 4) .
'/www/ui/core-schema.dat';
156 require($coreSchemaFile);
157 $attributeKey =
"ALTER";
158 foreach ($Schema[
'TABLE'] as $tableName => $tableCols) {
159 if ($invert ^ ! in_array($tableName, $tableList)) {
162 foreach ($tableCols as $attributes) {
163 if (array_key_exists($attributeKey, $attributes)) {
164 $this->
dbManager->queryOnce($attributes[$attributeKey]);
170 public function &getDbManager()
172 return $this->dbManager;
applySchema($type, $elementList, $invert=false)
createViews($viewList, $invert=FALSE)
alterTables($tableList, $invert=FALSE)
queryConverter($sql)
convert sql string to something the drive understands
createPlainTables($tableList, $invert=false)
insertData($tableList, $invert=FALSE, $dataFile=null)
insertData_license_ref($limit=140)
fo_dbManager * dbManager
fo_dbManager object