forked from keboola/db-writer-mssql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.php
More file actions
60 lines (48 loc) · 1.64 KB
/
Copy pathrun.php
File metadata and controls
60 lines (48 loc) · 1.64 KB
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
<?php
declare(strict_types=1);
use Keboola\DbWriter\MSSQL\Application;
use Keboola\DbWriter\Exception\ApplicationException;
use Keboola\DbWriter\Exception\UserException;
use Keboola\DbWriter\Logger;
use Keboola\DbWriter\MSSQL\Configuration\ConfigDefinition;
use Monolog\Handler\NullHandler;
require_once(dirname(__FILE__) . '/vendor/autoload.php');
$logger = new Logger('wr-db-mssql');
$action = 'run';
try {
$arguments = getopt('d::', ['data::']);
if (!isset($arguments['data'])) {
throw new UserException('Data folder not set.');
}
$config = json_decode(file_get_contents($arguments['data'] . '/config.json'), true);
$config['parameters']['data_dir'] = $arguments['data'];
$config['parameters']['writer_class'] = 'MSSQL';
$action = isset($config['action']) ? $config['action'] : $action;
$app = new Application($config, $logger);
if ($app['action'] !== 'run') {
$app['logger']->setHandlers(array(new NullHandler(Logger::INFO)));
}
echo $app->run();
} catch (UserException $e) {
$logger->log('error', $e->getMessage(), (array) $e->getData());
if ($action !== 'run') {
echo $e->getMessage();
}
exit(1);
} catch (ApplicationException $e) {
$logger->critical($e->getMessage(), [
'data' => $e->getData(),
'errFile' => $e->getFile(),
'errLine' => $e->getLine(),
'trace' => $e->getTrace(),
]);
exit($e->getCode() > 1 ? $e->getCode(): 2);
} catch (\Throwable $e) {
$logger->critical($e->getMessage(), [
'errFile' => $e->getFile(),
'errLine' => $e->getLine(),
'trace' => $e->getTrace(),
]);
exit(2);
}
exit(0);