forked from spotweb/spotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
importMc.php
72 lines (60 loc) · 2.04 KB
/
importMc.php
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
error_reporting(2147483647);
/*
* We need loads of memory to make sure we can cache everything, preventing
* us from going to the database too often
*/
ini_set('memory_limit', '2048M');
try {
/*
* If we are run from another directory, try to change the current
* working directory to a directory the script is in
*/
if (@!file_exists(getcwd() . '/' . basename($argv[0]))) {
chdir(dirname(__FILE__));
} # if
require_once "lib/SpotClassAutoload.php";
SpotClassAutoload::register();
require_once "lib/Bootstrap.php";
/*
* Create a DAO factory. We cannot use the bootstrapper here,
* because it validates for a valid settings etc. version.
*/
$bootstrap = new Bootstrap();
list($settings, $daoFactory, $req) = $bootstrap->boot();
echo $argv[0] . " - tmdb distribution import script" . PHP_EOL . PHP_EOL;
if ($argc < 2) {
echo "Je moet de filenaam welke je gekregen hebt als eerste parameter meegeven" . PHP_EOL;
die();
}
if (!is_readable($argv[1])) {
echo "Bestand '" . $argv[1] . "' kan niet worden gelezen" . PHP_EOL;
die();
} // if
/* Retrieve the current connection */
$conn = $daoFactory->getConnection();
/*
* Start reading the CSV file
*/
$h = fopen($argv[1], "r");
$conn->beginTransaction();
while (($buffer = fgets($h, 4096)) !== false) {
$line = explode(';', trim($buffer, "\r\n"));
echo "Updating TMDBid for '" . $line[3] . "', (id: " . $line[0] . ') ';
$conn->exec("UPDATE mastercollections SET tmdb_id = " . $line[1] .
" WHERE id = " . $line[0]);
echo ", done" . PHP_EOL;
}
fclose($h);
$conn->commit();
echo "Done importing collections" . PHP_EOL;
}
catch(Exception $x) {
echo PHP_EOL . PHP_EOL;
echo 'SpotWeb crashed' . PHP_EOL . PHP_EOL;
echo "Import of collections failed:" . PHP_EOL;
echo " " . $x->getMessage() . PHP_EOL;
echo PHP_EOL . PHP_EOL;
echo $x->getTraceAsString();
die(1);
} # catch