22 require_once(dirname(dirname(dirname(dirname(__FILE__)))) .
"/vendor/autoload.php");
31 protected function dirnameRec($path, $depth = 1)
33 for ($i = 0; $i < $depth; $i ++) {
34 $path = dirname($path);
49 public function insertData($tableList, $invert=FALSE, $dataFile=null)
51 $testdataFile = $dataFile ?: dirname(__FILE__) .
'/testdata.sql';
52 $testdata = file_get_contents($testdataFile);
53 $delimiter =
'INSERT INTO ';
54 $offset = strpos($testdata, $delimiter);
55 while (
false !== $offset) {
56 $nextOffset = strpos($testdata, $delimiter, $offset + 1);
57 if (
false === $nextOffset) {
58 $sql = substr($testdata, $offset);
60 $sql = substr($testdata, $offset, $nextOffset - $offset);
63 preg_match(
'/^INSERT INTO (?P<name>\w+) /', $sql, $table);
64 if (($invert ^ ! in_array($table[
'name'], $tableList))) {
65 $offset = $nextOffset;
69 $offset = $nextOffset;
85 $keysToBeChanged = array(
86 'rf_OSIapproved' =>
'"rf_OSIapproved"',
87 'rf_FSFfree'=>
'"rf_FSFfree"',
88 'rf_GPLv2compatible' =>
'"rf_GPLv2compatible"',
89 'rf_GPLv3compatible'=>
'"rf_GPLv3compatible"',
90 'rf_Fedora' =>
'"rf_Fedora"' 94 $LIBEXECDIR = $this->dirnameRec(__FILE__, 5) .
'/install/db';
95 $jsonData = json_decode(file_get_contents(
"$LIBEXECDIR/licenseRef.json"),
true);
96 $statementName = __METHOD__.
'.insertInToLicenseRef';
97 foreach ($jsonData as $licenseArrayKey => $licenseArray) {
98 $keys = strtr(implode(
",", array_keys($licenseArray)), $keysToBeChanged);
99 $valuePlaceHolders =
"$" . join(
",$",range(1, count(array_keys($licenseArray))));
100 $SQL =
"INSERT INTO license_ref ( $keys ) VALUES ($valuePlaceHolders);";
101 $this->
dbManager->prepare($statementName, $SQL);
102 $this->
dbManager->execute($statementName, array_values($licenseArray));
103 if ($licenseArrayKey >= $limit) {
114 protected function applySchema($type, $elementList, $invert=
false)
116 $coreSchemaFile = $this->dirnameRec(__FILE__, 4) .
'/www/ui/core-schema.dat';
118 require($coreSchemaFile);
119 foreach ($Schema[$type] as $viewName => $sql) {
120 if ($invert ^ ! in_array($viewName, $elementList)) {
123 $sqlCreate = is_array($sql) ? $sql[
'CREATE'] : $sql;
143 $coreSchemaFile = $this->dirnameRec(__FILE__, 4) .
'/www/ui/core-schema.dat';
145 require($coreSchemaFile);
146 $attributeKey =
"ALTER";
147 foreach ($Schema[
'TABLE'] as $tableName => $tableCols) {
148 if ($invert ^ ! in_array($tableName, $tableList)) {
151 foreach ($tableCols as $attributes) {
152 if (array_key_exists($attributeKey, $attributes)) {
153 $this->
dbManager->queryOnce($attributes[$attributeKey]);
159 public function &getDbManager()
161 return $this->dbManager;
insertData_license_ref($limit=140)
applySchema($type, $elementList, $invert=false)
alterTables($tableList, $invert=FALSE)
queryConverter($sql)
convert sql string to something the drive understands
createViews($viewList, $invert=FALSE)
createPlainTables($tableList, $invert=false)
insertData($tableList, $invert=FALSE, $dataFile=null)
fo_dbManager * dbManager
fo_dbManager object