1 |
37810
|
eri.katsar
|
<?php
|
2 |
|
|
require_once('./js/log4php/Logger.php');
|
3 |
|
|
require_once('./paths.php');
|
4 |
|
|
require_once('./MYDB.php');
|
5 |
|
|
|
6 |
|
|
class PromoteCharts {
|
7 |
|
|
private $log;
|
8 |
|
|
private $db;
|
9 |
|
|
private $cache = null; //predis
|
10 |
|
|
public function __construct(){
|
11 |
|
|
|
12 |
|
|
global $redis_host;
|
13 |
|
|
global $redis_port;
|
14 |
|
|
global $redis_scheme;
|
15 |
|
|
global $host;
|
16 |
|
|
|
17 |
|
|
$this->log = Logger::getLogger(__CLASS__);
|
18 |
|
|
Logger::configure('./js/log4php/log4php.xml');
|
19 |
|
|
|
20 |
|
|
if(class_exists("Predis\Client")){
|
21 |
|
|
|
22 |
|
|
try {
|
23 |
|
|
//todo changed timeout from 0 to -1
|
24 |
|
|
$this->cache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_host,"port" => $redis_port,"read_write_timeout" => -1));
|
25 |
|
|
$this->log->info("redis host: ".$redis_host." and redis port: ".$redis_port);
|
26 |
|
|
} catch(Exception $e) {
|
27 |
|
|
$this->log->error("Error connecting to Redis server: ".$e->getMessage());
|
28 |
|
|
$this->cache = null;
|
29 |
|
|
}
|
30 |
|
|
}
|
31 |
|
|
else{
|
32 |
|
|
$this->log->info("cache does not exist"); //predis
|
33 |
|
|
exit;
|
34 |
|
|
}
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
public function replace()
|
39 |
|
|
{
|
40 |
|
|
global $redis_host;
|
41 |
|
|
global $redis_port;
|
42 |
|
|
global $redis_scheme;
|
43 |
|
|
$this->cache = new Predis\Client(array("scheme" => $redis_scheme, "host" => $redis_host, "port" => $redis_port));
|
44 |
|
|
$this->cache->connect(); //predis
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
//now promote all other entries
|
48 |
|
|
$keys = $this->cache->keys("*");
|
49 |
|
|
|
50 |
|
|
$this->log->info("Promoting data queries...");
|
51 |
|
|
$this->log->info("*******************************************");
|
52 |
|
|
for($x=0;$x<count($keys);$x++) {
|
53 |
|
|
$this->log->info("Looking up for key: ".$keys[$x]);
|
54 |
|
|
if ((strpos($keys[$x],'chart')===false)&&(strpos($keys[$x],'table')===false)&&(strpos($keys[$x],'STATS')===false) )
|
55 |
|
|
{
|
56 |
|
|
try
|
57 |
|
|
{
|
58 |
|
|
$query = $this->cache->hget($keys[$x],'query');
|
59 |
|
|
$persistent= $this->cache->hget($keys[$x],'persistent');
|
60 |
|
|
if($query!=null)
|
61 |
|
|
{ $this->log->info("going to replace the results for key: ".$keys[$x]." : \n ".$query."\n");
|
62 |
|
|
$fetchMode = $this->cache->hget($keys[$x], 'fetchMode');
|
63 |
|
|
$shadowResults = $this->cache->hget($keys[$x],'shadow');
|
64 |
|
|
$result = $this->cache->hget($keys[$x], 'results');
|
65 |
|
|
$backup = $this->cache->hget($keys[$x], 'backup');
|
66 |
|
|
//$this->log->info("Currently stored backup".$backup);
|
67 |
|
|
//$this->log->info("With currently stored results".$result );
|
68 |
|
|
$this->cache->hmset($keys[$x],array("results" =>$shadowResults,"query" =>$query,"persistent" =>$persistent,"shadow" =>$shadowResults,"fetchMode" =>$fetchMode,"backup" =>$backup));
|
69 |
|
|
//$this->log->info(" Promoted Stored Entry : ");
|
70 |
|
|
}
|
71 |
|
|
else{
|
72 |
|
|
$this->log->info("going to delete the key: ".$keys[$x]);
|
73 |
|
|
$this->cache->del($keys[$x]);
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
}//catch
|
77 |
|
|
catch(Exception $e) {
|
78 |
|
|
|
79 |
|
|
$this->log->error('Error : '.$e->getMessage());
|
80 |
|
|
|
81 |
|
|
$this->log->info("going to delete problematic key: ".$keys[$x]);
|
82 |
|
|
$this->cache->del($keys[$x]);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
}
|
87 |
|
|
else
|
88 |
|
|
{
|
89 |
|
|
|
90 |
|
|
$this->log->info("Ignoring chart key: ".$keys[$x]);
|
91 |
|
|
if (strpos($keys[$x],'STATS')===false)
|
92 |
|
|
{
|
93 |
|
|
//todO here should we delete chart entries so that changes are visible in portal?
|
94 |
|
|
$this->log->info("going to delete the key: ".$keys[$x]);
|
95 |
|
|
$this->cache->del($keys[$x]);
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
$this->log->info("All Shadow Entries Promoted Sucessfully!");
|
100 |
|
|
$this->cache->quit();
|
101 |
|
|
|
102 |
|
|
}
|
103 |
|
|
}
|
104 |
|
|
?>
|