-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.php
62 lines (47 loc) · 1.63 KB
/
import.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
<?php
use App\Config;
require 'vendor/autoload.php';
require 'include/import-functions.php';
function main(array $argv): void {
try {
$config = Config::getInstance();
if (!isset($argv)) {
throw new Exception("Aucun argument spécifié");
}
$options = getopt('d:c:v');
$date = isset($options['d']) ? $options['d'] : null;
$chemin = isset($options['c']) ? $options['c'] : $config->get('importDir');
$verbose = isset($options['v']);
$yesterday = isset($options['y']);
$folder = date('Y/m');
$path = '';
if ($date !== null) {
$folder = $date;
} elseif ($yesterday) {
$folder = date('Y/m', time() - 24*60*60);
}
if ($chemin !== null) {
if (!is_dir($chemin)) {
throw new Exception("Le chemin précisé n'existe pas");
}
$path = is_dir($chemin) ? $chemin : $path;
if (substr($path, -1) != '/') {
$path .= '/';
}
}
if ($path === '/') {
$path = '';
}
if(!is_dir($path . $folder)) {
throw new Exception("Le dossier n'existe pas {$path}{$folder}");
}
vlog("Démarrage de l'import");
importDataEtabs($path.$folder, $verbose, $config->get('env'));
vlog("Fin de l'import");
} catch (PDOException $e) {
die("Erreur PDO : ".$e->getMessage());
} catch (Exception $e) {
die("Erreur : ".$e->getMessage()."\n");
}
}
main($argv);