1
0
mirror of https://github.com/mbirth/tcl_update_db.git synced 2024-11-09 23:06:45 +00:00

Restructure database. Also derive seenDate from filename (stamp).

This commit is contained in:
Markus Birth 2017-12-15 01:05:07 +01:00
parent 6d8f3bda7b
commit 7deee59c3a
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
3 changed files with 17 additions and 10 deletions

View File

@ -86,8 +86,11 @@ class SQLiteWriter
} }
} }
public function addGotu(GotuObject $g) public function addGotu(GotuObject $g, $seenDate = false)
{ {
if ($seenDate === false) {
$seenDate = gmdate('c');
}
$this->addFile(array( $this->addFile(array(
'file_sha1' => $g->file_chksum, 'file_sha1' => $g->file_chksum,
'file_name' => $g->filename, 'file_name' => $g->filename,
@ -103,10 +106,14 @@ class SQLiteWriter
'pubDate' => $g->time, 'pubDate' => $g->time,
)); ));
$ok = $this->insertArray('updates', array( $ok = $this->insertArray('updates', array(
'curef' => $g->curef,
'update_desc' => $g->update_desc,
'svn' => $g->svn, 'svn' => $g->svn,
'seenDate' => $seenDate,
'pubDate' => $g->time, 'pubDate' => $g->time,
'publisher' => $g->publisher, 'publisher' => $g->publisher,
'fwId' => $g->fw_id, 'fwId' => $g->fw_id,
'num_files' => $g->fileset_count,
'file_id' => $g->file_id, 'file_id' => $g->file_id,
'file_sha1' => $g->file_chksum, 'file_sha1' => $g->file_chksum,
)); ));

View File

@ -14,6 +14,8 @@ $sqlw = new SQLiteWriter();
foreach ($file_list as $file) { foreach ($file_list as $file) {
$filename = basename($file); $filename = basename($file);
$file_stamp = substr($filename, 0, strpos($filename, '.'));
$file_date = gmdate('c', intval($file_stamp));
$data = file_get_contents($file); $data = file_get_contents($file);
$xp = new XmlParser(); $xp = new XmlParser();
$load_ok = $xp->loadXmlFromString($data); $load_ok = $xp->loadXmlFromString($data);
@ -27,8 +29,8 @@ foreach ($file_list as $file) {
} }
echo 'Processing ' . $filename . PHP_EOL; echo 'Processing ' . $filename . PHP_EOL;
$g = GotuObject::fromXmlParser($xp); $g = GotuObject::fromXmlParser($xp);
print_r($g); //print_r($g);
if ($g->tv) { if ($g->tv) {
$sqlw->addGotu($g); $sqlw->addGotu($g, $file_date);
} }
} }

View File

@ -54,21 +54,19 @@ CREATE TABLE "files" (
-- a separate "files" table might get introduced later -- a separate "files" table might get introduced later
CREATE TABLE "updates" ( CREATE TABLE "updates" (
"updateId" INTEGER PRIMARY KEY AUTOINCREMENT, "updateId" INTEGER PRIMARY KEY AUTOINCREMENT,
"curef" TEXT, -- PRD number
"update_desc" TEXT,
"svn" TEXT, -- version info from <SVN> field "svn" TEXT, -- version info from <SVN> field
"seenDate" INTEGER, -- date added to db
"pubDate" INTEGER, -- published date "pubDate" INTEGER, -- published date
"publisher" TEXT, -- publisher "publisher" TEXT, -- publisher
"num_files" INTEGER, -- number of files total
"fwId" TEXT, -- <FW_ID> (CHANGES FOR THE SAME FILE_ID!!!) MAYBE MOVE TO update_map "fwId" TEXT, -- <FW_ID> (CHANGES FOR THE SAME FILE_ID!!!) MAYBE MOVE TO update_map
"file_id" TEXT, -- <FILE_ID> of first file "file_id" TEXT, -- <FILE_ID> of first file
"file_sha1" TEXT REFERENCES "files" ("sha1") -- SHA1 checksum of first file "file_sha1" TEXT REFERENCES "files" ("sha1") -- SHA1 checksum of first file
); );
CREATE UNIQUE INDEX "index_updates" ON "updates" ( CREATE UNIQUE INDEX "index_updates" ON "updates" (
"curef",
"fwId", "fwId",
"file_id" "file_id"
); );
-- Maps update files to devices
CREATE TABLE "update_map" (
"deviceId" INTEGER REFERENCES "devices" ("deviceId"),
"updateId" INTEGER REFERENCES "updates" ("updateId"),
"seenDate" INTEGER -- timestamp when this record was added
);