forked from openenergymonitor/emoncms3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conv.php
77 lines (58 loc) · 2.32 KB
/
conv.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
<?php
/*
All Emoncms code is released under the GNU Affero General Public License.
See COPYRIGHT.txt and LICENSE.txt.
---------------------------------------------------------------------
Emoncms - open source energy visualisation
Part of the OpenEnergyMonitor project:
http://openenergymonitor.org
*/
//=====================================================
//$runnable = TRUE; // ENABLE THIS ONCE TO FORCE UPDATE
//=====================================================
if(!$runnable) {echo "to run script uncomment runnable"; die;}
set_time_limit ( 1000 );
error_reporting(E_ALL);
ini_set('display_errors','on');
error_reporting(E_ALL ^ E_NOTICE);
require "Includes/db.php";
$e = db_connect();
require "Models/feed_model.php";
//$feeds = get_all_feeds();
//$feeds = get_user_feed_ids(1);
foreach ($feeds as $feed ){
if (get_feed_type($feed['id'])==0)
{
echo "converted feed: ".$feed['id']."<br/>";
$feedname = "feed_".trim($feed['id'])."";
// 1) rename feed to be converted as temporary
$result = db_query("RENAME TABLE `$feedname` TO `feed_tmp`");
$result = db_query("SELECT * FROM feed_tmp LIMIT 1");
$row = db_fetch_array($result);
if(!isset($row['data2']))
{
// 2) Create the new feed table with index
$result = db_query("CREATE TABLE $feedname (
`time` INT UNSIGNED NOT NULL ,
`data` FLOAT NOT NULL ,
INDEX ( `time` ))");
// 3) Copy over and convert time from datetime to unix timestamp
$result = db_query("INSERT $feedname SELECT UNIX_TIMESTAMP (time),data FROM feed_tmp");
} else {
// 2) Create the new feed table with index
$result = db_query("CREATE TABLE $feedname (
`time` INT UNSIGNED NOT NULL ,
`data` FLOAT NOT NULL ,
`data2` FLOAT NOT NULL ,
INDEX ( `time` ))");
// 3) Copy over and convert time from datetime to unix timestamp
$result = db_query("INSERT $feedname SELECT UNIX_TIMESTAMP (time),data,data2 FROM feed_tmp");
}
// 4) Drop the temporary feed table
$result = db_query("DROP TABLE `feed_tmp`");
// 5) Update feed type status
$feedid = $feed['id'];
$result = db_query("UPDATE feeds SET type = 1 WHERE id='$feedid'");
} else { echo "feed: ".$feed['id']." already converted<br/>";}
}
?>