-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.php
120 lines (100 loc) · 3.33 KB
/
cron.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* Created by PhpStorm.
* User: Stefano "Yoghi" Tamagnini
* Date: 01/02/15 - 17:28.
*/
define('BASE_DIR', realpath(__DIR__).'/');
date_default_timezone_set('Europe/Rome');
require BASE_DIR.'vendor/autoload.php';
function fatal_handler($config)
{
$errfile = 'unknown file';
$errstr = 'shutdown';
$errno = E_CORE_ERROR;
$errline = 0;
$error = error_get_last();
if ($error !== null) {
$errfile = $error['file'];
$errstr = $error['message'];
$errno = $error['type'];
$errline = $error['line'];
$msg = json_encode([
'no' => $errno,
'str' => $errstr,
'file' => $errfile,
'line' => $errline,
]
);
// format_error( $errno, $errstr, $errfile, $errline, false);
file_put_contents($config['log']['filename'], $msg."\n", FILE_APPEND);
}
}
use RedBean_Facade as R;
//$strict = in_array('--strict', $_SERVER['argv']);
//$arguments = new \cli\Arguments(compact('strict'));
//
//$arguments->addFlag(array('verbose', 'v'), 'Turn on verbose output');
//$arguments->addFlag('version', 'Display the version');
//$arguments->addFlag(array('quiet', 'q'), 'Disable all output');
//$arguments->addFlag(array('help', 'h'), 'Show this help screen');
//
//$arguments->addOption(array('configfile','c'), array(
// 'default' => BASE_DIR.'config.php',
// 'description' => 'Setta la posizione del file di config'));
//
//$arguments->addFlag(array('mail', 'm'), 'Invia mail in coda');
//
//$arguments->parse();
//if ($arguments['help']) {
// echo $arguments->getHelpScreen();
// echo "\n\n";
//}
//
//$arguments_parsed = $arguments->getArguments();
//
//if ( isset($arguments_parsed['configfile']) ) {
// require $arguments_parsed['configfile'];
//} else {
// \cli\err('Parametro -c config mancante');
// exit -1;
//}
require '../config.php';
require BASE_DIR.'includes/configuration.php';
extract(configure_slim($config), EXTR_SKIP);
register_shutdown_function('fatal_handler', $config);
$streamToFile = new \Monolog\Handler\StreamHandler($config['log']['filenameCron']);
$output = "[%datetime%] [%level_name%] [%extra%] : %message% %context%\n";
$formatter = new Monolog\Formatter\LineFormatter($output);
$streamToFile->setFormatter($formatter);
$handlers[] = $streamToFile;
if (isset($config['loggy'])) {
$handlers[] = new \Monolog\Handler\LogglyHandler($config['loggy']['token'].'/tag/cron', \Monolog\Logger::INFO);
}
$logger_writer = new \Flynsarmy\SlimMonolog\Log\MonologWriter([
'handlers' => $handlers,
'processors' => [
new Monolog\Processor\UidProcessor(),
new Monolog\Processor\WebProcessor($_SERVER),
],
]);
$logger = new \Slim\Log($logger_writer);
if (strcmp('sqlite', $config['db']['type']) == 0) {
$dsn = $config['db']['type'].':'.$config['db']['host'];
} else {
$dsn = $config['db']['type'].':host='.$config['db']['host'].';dbname='.$config['db']['database'];
}
$username = $config['db']['user'];
$password = $config['db']['password'];
R::setup($dsn, $username, $password);
if (DEBUG) {
R::freeze(false);
} else {
R::freeze(true);
}
//if ( isset($arguments_parsed['mail']) ){
$logger->info('Cron start send mail');
$spooler = new \BitPrepared\Mail\Spool($logger, $config);
$spooler->flushQueue();
$logger->info('Cron end send mail');
//}