forked from emoncms/sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_upload.php
66 lines (50 loc) · 1.96 KB
/
sync_upload.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
<?php
// Get script location
list($scriptPath) = get_included_files();
$scriptPath = str_replace("/sync_upload.php","",$scriptPath);
chdir($scriptPath);
require "lib/phpfina.php";
require "lib/phptimeseries.php";
require_once "/var/www/emoncms/Lib/load_emoncms.php";
require_once "Modules/feed/feed_model.php";
$feed = new Feed($mysqli,$redis,$settings["feed"]);
require_once "Modules/input/input_model.php";
$input = new Input($mysqli,$redis, $feed);
include "Modules/sync/sync_model.php";
$sync = new Sync($mysqli,$feed);
$userid = 1;
$r = $sync->remote_load($userid);
$host = $r->host;
$apikey_read = $r->apikey_read;
$apikey_write = $r->apikey_write;
$feeds = $sync->get_feed_list($userid);
foreach ($feeds as $tagname=>$feed){
$local = $feeds[$tagname]->local;
$remote = $feeds[$tagname]->remote;
if (!$local->exists && $remote->exists) {
// echo "remote only";
// Create local feeds
}
else if ($local->exists && !$remote->exists) {
// echo "local only";
// Create remote feeds
}
else if ($local->start_time==$remote->start_time && $local->interval==$remote->interval) {
// echo "both";
if ($local->npoints>$remote->npoints) {
// local ahead of remote
echo $tagname."\n";
if ($local->engine==Engine::PHPFINA) {
phpfina_upload($settings['feed']['phpfina']['datadir'],$local->id,$host,$remote->id,$apikey_write);
}
} /*else if ($local->npoints<$remote->npoints) {
echo "local behind remote";
if ($local->engine==Engine::PHPFINA) {
$lastvalue = phpfina_download($settings['feed']['phpfina']['datadir'],$local->id,$host,$remote->id,$apikey_read);
if ($lastvalue) $redis->hMset("feed:".$local->id, $lastvalue);
}
} else {
echo " local and remote the same";
}*/
}
}