-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.php
70 lines (59 loc) · 1.98 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
<?php
define("BASE_PATH", dirname(__FILE__));
// Timeout: 2.5min
set_time_limit(150);
// Only allow one process at a time
$lockfile = sys_get_temp_dir() .'/cron.pid';
if (file_exists($lockfile)) {
$pid = file_get_contents($lockfile);
if (posix_getsid($pid) !== false) {
die();
}
}
file_put_contents($lockfile, getmypid());
// Configuration storage
require_once BASE_PATH.'/ConfigProvider.interface.php';
require_once BASE_PATH.'/PHPFileConfig.class.php';
ConfigProvider::create("PHPFileConfig");
// Base Plugin classes
require_once BASE_PATH.'/DataProvider.class.php';
require_once BASE_PATH.'/StorageProvider.class.php';
// Data Providers
include(BASE_PATH.'/provider/foursquare.php');
include(BASE_PATH.'/provider/trakt.php');
include(BASE_PATH.'/provider/putio.php');
include(BASE_PATH.'/provider/withings.php');
include(BASE_PATH.'/provider/appnet.php');
include(BASE_PATH.'/provider/mail.php');
include(BASE_PATH.'/provider/github.php');
// Storage Providers
include(BASE_PATH.'/storage/CosmStorage.class.php');
include(BASE_PATH.'/storage/MongoStorage.class.php');
// Find all storage providers
$datastore_classes = array_filter(get_declared_classes(), function($className) {
return in_array('StorageProvider', class_parents($className));
});
// Instanciate all storage providers
$datastores = array();
foreach ($datastore_classes as $datastore_class) {
if ($datastore_class::isActive()) {
$datastore = new $datastore_class();
$datastores[] = $datastore;
}
}
// find all data providers
$providers = array_filter(get_declared_classes(), function($className) {
return in_array('DataProvider', class_parents($className));
});
// get data from each data provider, and push it to the storage providers
foreach ($providers as $provider_class) {
$provider = new $provider_class();
if ($provider->isActive()) {
foreach ($datastores as $datastore) {
$meta = $provider->getMetaData();
$raw = $provider->getRawData();
$datastore->putData($provider, $meta, $raw);
}
}
}
unlink($lockfile);