1
0
mirror of https://github.com/mbirth/tcl_update_db.git synced 2024-12-27 04:54:08 +00:00
tcl_update_db/bin/parse_files.php

44 lines
1.1 KiB
PHP
Raw Normal View History

#!/usr/bin/env php
<?php
2017-12-18 14:02:24 +00:00
require_once __DIR__ . '/../lib/autoloader.php';
use \TclUpdates\GotuObject;
use \TclUpdates\XmlParser;
use \TclUpdates\SQLiteWriter;
2017-12-18 14:02:24 +00:00
$bkup_dir = __DIR__ . '/../data/';
$file_list = glob($bkup_dir . '*.xml');
$sqlw = new SQLiteWriter();
foreach ($file_list as $file) {
$filename = basename($file);
$file_stamp = substr($filename, 0, strpos($filename, '.'));
$file_date = gmdate('c', intval($file_stamp));
$data = file_get_contents($file);
$xp = new XmlParser();
$load_ok = $xp->loadXmlFromString($data);
if (!$load_ok) {
echo 'Could not load ' . $filename . '!' . PHP_EOL;
continue;
}
if (!$xp->validateGOTU()) {
echo 'XML not valid in ' . $filename . '!' . PHP_EOL;
continue;
}
2017-12-16 13:17:18 +00:00
echo 'Processing ' . $filename . ' ...';
$g = GotuObject::fromXmlParser($xp);
//print_r($g);
2017-12-11 00:28:52 +00:00
if ($g->tv) {
2017-12-16 13:17:18 +00:00
$result = $sqlw->addGotu($g, $file_date);
if ($result !== false) {
echo ' added as #' . $result . PHP_EOL;
} else {
echo ' NOT ADDED.' . PHP_EOL;
}
} else {
echo ' not a check XML' . PHP_EOL;
2017-12-11 00:28:52 +00:00
}
}