1
|
<?php
|
2
|
/*<!--<html>
|
3
|
<head>
|
4
|
<title>...</title>
|
5
|
<style type=”text/css”>
|
6
|
table {
|
7
|
margin: 8px;
|
8
|
}
|
9
|
h1 {
|
10
|
text-align: center;
|
11
|
text-transform: uppercase;
|
12
|
color: #A7C942;
|
13
|
}
|
14
|
|
15
|
|
16
|
|
17
|
p {
|
18
|
text-indent: 50px;
|
19
|
text-align:justify;
|
20
|
letter-spacing:3px;
|
21
|
font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif;
|
22
|
|
23
|
}
|
24
|
a {
|
25
|
text-decoration:none;
|
26
|
|
27
|
}
|
28
|
|
29
|
|
30
|
|
31
|
|
32
|
</style>
|
33
|
</head>
|
34
|
<body>
|
35
|
-->*/
|
36
|
//<?php
|
37
|
require_once('./js/log4php/Logger.php');
|
38
|
include_once('./refreshNums.php');
|
39
|
include_once('./refreshCharts.php');
|
40
|
include_once('./promoteNums.php');
|
41
|
include_once('./promoteCharts.php');
|
42
|
include_once('./backupCache.php');
|
43
|
include_once('./restoreCache.php');
|
44
|
include_once('./migrateCache.php');
|
45
|
|
46
|
class CacheController
|
47
|
{
|
48
|
public function __construct($action){
|
49
|
$this->log = Logger::getLogger(__CLASS__);
|
50
|
Logger::configure('./js/log4php/log4php.xml');
|
51
|
$this->log->info("Calling scripts to modify Cache....");
|
52
|
$this->log->info("Script Mode:".$action);
|
53
|
|
54
|
|
55
|
if(!$action=='help'){
|
56
|
echo ("Performing Action : ".$action."<br><br>"); }
|
57
|
|
58
|
|
59
|
if ($action=='refreshNums')
|
60
|
{$this->refreshNums();}
|
61
|
else if ($action=='refreshCharts')
|
62
|
{$this->refreshCharts();}
|
63
|
else if ($action=='refreshAll')
|
64
|
{ $this->refreshAll(); }
|
65
|
else if ($action=='promoteNums')
|
66
|
{$this->promoteNums();}
|
67
|
else if ($action=='promoteCharts')
|
68
|
{$this->promoteCharts();}
|
69
|
else if ($action=='promoteAll')
|
70
|
{ $this->promoteAll(); }
|
71
|
else if ($action=='restore')
|
72
|
{ $this->restore(); }
|
73
|
else if ($action=='backup')
|
74
|
{
|
75
|
$this->backup(); }
|
76
|
else if ($action=='migrate')
|
77
|
{$this->migrate(); }
|
78
|
else if ($action=='help')
|
79
|
{$this->printHelp();}
|
80
|
else
|
81
|
{$this->log->info("Wrong argument given");
|
82
|
$this->printHelp();}
|
83
|
|
84
|
|
85
|
if($action!=='help'){
|
86
|
echo("<br>Action Finished! <br>");
|
87
|
}
|
88
|
|
89
|
|
90
|
}
|
91
|
|
92
|
private function printHelp()
|
93
|
{
|
94
|
$msg="<h1>Cache Controls <br><br> </h1> Availiable options for <b> refresh :</b> <br><br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=refreshNums\"> refreshNums </a> -> Refresh Stats Numbers Only <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=refreshCharts\"> refreshCharts</a> -> Refresh Chart Queries <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=refreshAll\"> refreshAll</a > -> Refresh every entry in the cache.<br> <br>Availiable options for <b>promote</b> :<br> <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=promoteNums\"> promoteNums </a> -> Promotes Stats Numbers Only; <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=promoteCharts\"> promoteCharts </a> -> Promote Chart Queries ; <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=promoteAll\"> promoteAll</a> ->Promote every entry in the cache. <br> <br>Availiable options for <b>backup</b> : <br><br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=backup\"> backup </a> <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=restore\"> restore </a> <br> <a href=\"https://beta.openaire.eu/stats/cacheController?action=migrate\"> migrate </a> <br>"; $this->log->info($msg); echo($msg);
|
95
|
}
|
96
|
|
97
|
public function refreshNums(){
|
98
|
$this->log->info("Refreshing Numbers...");
|
99
|
$csn = new ComputeStatsNumbers();
|
100
|
$csn->computeStats();
|
101
|
$this->log->info("Done!");
|
102
|
}
|
103
|
|
104
|
public function refreshCharts()
|
105
|
{
|
106
|
$this->log->info("Refreshing Charts...");
|
107
|
$csn = new RefreshCharts();$csn->refresh();
|
108
|
$this->log->info("Done!");
|
109
|
}
|
110
|
|
111
|
public function refreshAll()
|
112
|
{
|
113
|
$this->refreshNums();
|
114
|
$this->refreshCharts();
|
115
|
}
|
116
|
|
117
|
public function promoteNums(){
|
118
|
$this->log->info(" Promoting Numbers...");
|
119
|
$csn = new PromoteShadowNums();
|
120
|
$csn->replace();
|
121
|
$this->log->info("Done!");
|
122
|
}
|
123
|
|
124
|
public function promoteCharts()
|
125
|
{
|
126
|
$this->log->info("Promoting Charts...");
|
127
|
$csn = new PromoteCharts();$csn->replace();
|
128
|
$this->log->info("Done!");
|
129
|
}
|
130
|
|
131
|
public function migrate()
|
132
|
{
|
133
|
$this->log->info("Cache Migration not yet implemented");
|
134
|
//$csn = new MigrateCache();
|
135
|
//$csn->migrate();
|
136
|
//$this->log->info("Done!");
|
137
|
echo("Cache Migration not yet implemented <br>");
|
138
|
}
|
139
|
|
140
|
public function backup()
|
141
|
{
|
142
|
$this->log->info("Backing Up Cache...");
|
143
|
$csn = new BackupCache();$csn->backup();
|
144
|
$this->log->info("Done!");
|
145
|
}
|
146
|
|
147
|
public function restore()
|
148
|
{
|
149
|
$this->log->info("Restoring Cache...");
|
150
|
$csn = new RestoreCache();$csn->restore();
|
151
|
$this->log->info("Done!");
|
152
|
}
|
153
|
|
154
|
|
155
|
public function promoteAll()
|
156
|
{ $this->promoteNums();
|
157
|
$this->promoteCharts();
|
158
|
}
|
159
|
|
160
|
|
161
|
|
162
|
}
|
163
|
|
164
|
//if(!empty($_SERVER['argv'][0]) {
|
165
|
//$action = $_SERVER['argv'][1];
|
166
|
|
167
|
//} else {
|
168
|
// $action = $_GET['action'];
|
169
|
//}
|
170
|
|
171
|
|
172
|
if ($_GET) {
|
173
|
$action = $_GET['action'];
|
174
|
} else {
|
175
|
$action = $argv[1];
|
176
|
}
|
177
|
$rc = new CacheController($action);
|
178
|
|
179
|
/*
|
180
|
</body>
|
181
|
</html>
|
182
|
*/
|
183
|
?>
|