summaryrefslogtreecommitdiff
path: root/update.php
blob: 174970ed2a17e95dd5d766405cddfb59a3061832 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env php
<?php

$input = 'LIKAT Publications.xml';
$output = 'dbxml_new.xml';

/* Check filetime and do import only if the input xml was updated */
if (filemtime($input) <= filemtime($output))
	exit;

$xml = new DOMDocument();
$xml->load($input);

/* TODO Check whether the input xml is valid – if not it is probably changed currently.
 * Add 5min timeout and try again */

$preprocess = new DOMDocument();
$preprocess->load('convert-style-to-html.xsl');

$process = new DOMDocument();
$process->load('endnote-to-dbxml.xsl');

$proc1 = new XSLTProcessor();
$proc1->importStyleSheet($preprocess);

$proc2 = new XSLTProcessor();
$proc2->importStyleSheet($process);

$step1 = $proc1->transformToDoc($xml);
$step2 = $proc2->transformToXML($step1);
/*
 * LOAD XML has bugs (NULL columns) when there are empty, self closing tags like
 * <title/> Replace those with <title></title>
 */
$step3 = preg_replace('#<([^>]*)/>#', '<\1></\1>', $step2);

file_put_contents($output, $step3);

/* TODO: Issue the mysql command directly from php */

/* TODO: Write mail, add exception handler and write mail on error as well */