Exemplo n.º 1
0
 * Check the database if there are XML files that haven't been parsed
 * If there are any, parse them and insert the results into your database
 */
require_once "db.class.php";
require_once "XMLParser.php";
require_once "NotificationObject.php";
$config = (require 'config.php');
//Initiate the database connection and the parser
$db = new db_mysql($config);
$parser = new XMLParser();
//In SpoCoSy, we do not hard delete rows, we set "del" to "yes"
//This is probably not what you want, so if del equals yes, this code will delete the element
//If you set this to false, it will only set "del" to "yes" and not remove the row
$HARD_DELETE = true;
//Check if there any files to parse
$toParse = $db->query("SELECT * from saved_xml ORDER BY `ut` ASC LIMIT 10") or $db->raise_error();
//Loop over these files
while ($fileToParse = $db->fetch_array($toParse)) {
    $filename = "files/" . $fileToParse["id"] . ".xml";
    //Once parse move this file to here
    $parsedfile = "files/parsed/" . $fileToParse["id"] . ".xml";
    echo "Procesing {$filename} \n";
    if (file_exists($filename)) {
        $output = "";
        $file = fopen($filename, "r");
        if (FALSE === $file) {
            echo "cannot open {$filesToParse['id']}.xml , exiting..\n";
            exit;
        }
        while (!feof($file)) {
            //read file line by line into variable