1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
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: class SolrRightBottomPage extends cGuiPage {
40:
41: 42: 43: 44:
45: private $_clientOptions;
46:
47: 48: 49:
50: public function __construct() {
51:
52: global $action;
53:
54: parent::__construct('right_bottom', Solr::getName());
55:
56: $this->addStyle('smoothness/jquery-ui-1.8.20.custom.css');
57: $this->addStyle('../plugins/' . Solr::getName() . '/styles/right_bottom.css');
58: $this->addScript('../plugins/' . Solr::getName() . '/scripts/right_bottom.js');
59:
60: $this->set('s', 'CONTENIDO', cRegistry::getBackendSessionId());
61:
62: $this->set('s', 'I18N_CLIENT_OPTIONS', Solr::i18n('CLIENT_OPTIONS'));
63: $this->set('s', 'I18N_OPTION', Solr::i18n('OPTION'));
64: $this->set('s', 'I18N_VALUE', Solr::i18n('VALUE'));
65: $this->set('s', 'I18N_DESCRIPTION', Solr::i18n('DESCRIPTION'));
66: $this->set('s', 'I18N_DESCR_HOSTNAME', Solr::i18n('DESCR_HOSTNAME'));
67: $this->set('s', 'I18N_DESCR_PORT', Solr::i18n('DESCR_PORT'));
68: $this->set('s', 'I18N_DESCR_PATH', Solr::i18n('DESCR_PATH'));
69: $this->set('s', 'I18N_DESCR_LOGIN', Solr::i18n('DESCR_LOGIN'));
70: $this->set('s', 'I18N_DESCR_PASSWORD', Solr::i18n('DESCR_PASSWORD'));
71: $this->set('s', 'I18N_DESCR_SECURE', Solr::i18n('DESCR_SECURE'));
72: $this->set('s', 'I18N_DESCR_TIMEOUT', Solr::i18n('DESCR_TIMEOUT'));
73: $this->set('s', 'I18N_DESCR_WT', Solr::i18n('DESCR_WT'));
74: $this->set('s', 'I18N_DESCR_PROXY_HOST', Solr::i18n('DESCR_PROXY_HOST'));
75: $this->set('s', 'I18N_DESCR_PROXY_PORT', Solr::i18n('DESCR_PROXY_PORT'));
76: $this->set('s', 'I18N_DESCR_PROXY_LOGIN', Solr::i18n('DESCR_PROXY_LOGIN'));
77: $this->set('s', 'I18N_DESCR_PROXY_PASSWORD', Solr::i18n('DESCR_PROXY_PASSWORD'));
78: $this->set('s', 'I18N_DESCR_SSL_CERT', Solr::i18n('DESCR_SSL_CERT'));
79: $this->set('s', 'I18N_DESCR_SSL_KEY', Solr::i18n('DESCR_SSL_KEY'));
80: $this->set('s', 'I18N_DESCR_SSL_KEYPASSWORD', Solr::i18n('DESCR_SSL_KEYPASSWORD'));
81: $this->set('s', 'I18N_DESCR_SSL_CAINFO', Solr::i18n('DESCR_SSL_CAINFO'));
82: $this->set('s', 'I18N_DESCR_SSL_CAPATH', Solr::i18n('DESCR_SSL_CAPATH'));
83: $this->set('s', 'I18N_DESCR_RELOAD', Solr::i18n('DESCR_RELOAD'));
84: $this->set('s', 'I18N_DESCR_REINDEX', Solr::i18n('DESCR_REINDEX'));
85:
86:
87: $this->_clientOptions = Solr::getClientOptions();
88: $this->set('s', 'HOSTNAME', $this->_clientOptions['hostname']);
89: $this->set('s', 'PORT', $this->_clientOptions['port']);
90: $this->set('s', 'PATH', $this->_clientOptions['path']);
91: $this->set('s', 'LOGIN', $this->_clientOptions['login']);
92: $this->set('s', 'PASSWORD', $this->_clientOptions['password']);
93: $this->set('s', 'SECURE', 'true' == $this->_clientOptions['secure'] ? 'checked="checked"' : '');
94: $this->set('s', 'TIMEOUT', $this->_clientOptions['timeout']);
95: $this->set('s', 'WT', $this->_clientOptions['wt']);
96: $this->set('s', 'PROXY_HOST', $this->_clientOptions['proxy_host']);
97: $this->set('s', 'PROXY_PORT', $this->_clientOptions['proxy_port']);
98: $this->set('s', 'PROXY_LOGIN', $this->_clientOptions['proxy_login']);
99: $this->set('s', 'PROXY_PASSWORD', $this->_clientOptions['proxy_password']);
100: $this->set('s', 'SSL_CERT', $this->_clientOptions['ssl_cert']);
101: $this->set('s', 'SSL_KEY', $this->_clientOptions['ssl_key']);
102: $this->set('s', 'SSL_KEYPASSWORD', $this->_clientOptions['ssl_keypassword']);
103: $this->set('s', 'SSL_CAINFO', $this->_clientOptions['ssl_cainfo']);
104: $this->set('s', 'SSL_CAPATH', $this->_clientOptions['ssl_capath']);
105:
106:
107: $validClientOptions = true;
108: $validClientOptions &= array_key_exists('hostname', $this->_clientOptions);
109: $validClientOptions &= array_key_exists('port', $this->_clientOptions);
110: $validClientOptions &= array_key_exists('path', $this->_clientOptions);
111: $validClientOptions &= array_key_exists('login', $this->_clientOptions);
112: $validClientOptions &= array_key_exists('password', $this->_clientOptions);
113: $this->set('s', 'DISABLED_RELOAD', $validClientOptions ? '' : 'disabled="disabled"');
114: $this->set('s', 'DISABLED_REINDEX', $validClientOptions ? '' : 'disabled="disabled"');
115:
116:
117: try {
118: $this->_dispatch($action);
119: } catch (InvalidArgumentException $e) {
120: $cGuiNotification = new cGuiNotification();
121: $notification = $cGuiNotification->returnNotification(cGuiNotification::LEVEL_ERROR, $e->getMessage());
122: $this->set('s', 'notification', $notification);
123: }
124: }
125:
126: 127: 128: 129: 130: 131:
132: protected function _dispatch($action) {
133: global $area;
134:
135:
136: $perm = cRegistry::getPerm();
137: if (!$perm->have_perm_area_action($area, $action)) {
138: throw new IllegalStateException('no permissions');
139: }
140:
141: if (NULL === $action) {
142: $this->set('s', 'notification', '');
143: $this->set('s', 'content', '');
144: return;
145: }
146:
147:
148: try {
149: switch ($action) {
150: case 'store_client_options':
151: $this->set('s', 'notification', $this->_storeClientOptions());
152: break;
153: case 'reload':
154: $this->set('s', 'notification', $this->_reload());
155: break;
156: case 'reindex':
157: $this->set('s', 'notification', $this->_reindex());
158: break;
159: default:
160: throw new InvalidArgumentException('unknown action ' . $action);
161: }
162: } catch (Exception $e) {
163: $notification = Solr::notifyException($e);
164: }
165: }
166:
167: 168: 169: 170:
171: private function _storeClientOptions() {
172: $settings = 'secure,hostname,port,path,wt,login,password,timeout,';
173: $settings .= 'proxy_host,proxy_port,proxy_login,proxy_password,';
174: $settings .= 'ssl_cert,ssl_key,ssl_keypassword,ssl_cainfo,ssl_capath';
175: foreach (explode(',', $settings) as $setting) {
176: $value = $_POST[$setting];
177: if (0 < strlen(trim($value))) {
178: setSystemProperty('solr', $setting, $value);
179: } else {
180:
181:
182: deleteSystemProperty('solr', $setting);
183: }
184: }
185: $cGuiNotification = new cGuiNotification();
186: return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, 'client options were stored');
187: }
188:
189: 190: 191: 192: 193: 194: 195: 196: 197: 198:
199: private function _reload() {
200:
201:
202:
203: $url = 'http://';
204: $url .= $this->_clientOptions['login'] . ':' . $this->_clientOptions['password'] . '@';
205: $url .= $this->_clientOptions['hostname'] . ':' . $this->_clientOptions['port'];
206: $url .= '/solr/admin/cores?' . http_build_query(array(
207: 'action' => 'RELOAD',
208: 'core' => array_pop(explode('/', $this->_clientOptions['path']))
209: ));
210:
211:
212: $ch = curl_init();
213:
214: $data = false;
215: if (false !== $ch) {
216:
217: $opt = array(
218:
219: CURLOPT_URL => $url,
220:
221: CURLOPT_HTTPGET => true,
222:
223:
224: CURLOPT_USERAGENT => 'CONTENIDO Solr Plugin v1.0',
225:
226:
227: CURLOPT_TIMEOUT_MS => 5000,
228:
229:
230: CURLOPT_CONNECTTIMEOUT_MS => 5000,
231:
232: CURLOPT_RETURNTRANSFER => 1,
233:
234: CURLOPT_HEADER => false
235: );
236:
237: curl_setopt_array($ch, $opt);
238:
239:
240: $data = curl_exec($ch);
241:
242:
243: $curlInfo = curl_getinfo($ch);
244:
245:
246: curl_close($ch);
247:
248: if (200 !== (int) $curlInfo['http_code']) {
249: $msg = 'HTTP status code ' . $curlInfo['http_code'];
250:
251:
252: $msg .= "\n(complete cUrl-Info:";
253: foreach ($curlInfo as $key => $value) {
254: $msg .= "\n\t" . $key . ' => ' . $value;
255: }
256: $msg .= "\n)";
257:
258: throw new cException($msg);
259: }
260: }
261:
262: if (false === $data) {
263: throw new cException('server did not answer');
264: }
265:
266: $cGuiNotification = new cGuiNotification();
267: return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, 'core was reloaded');
268: }
269:
270: 271: 272: 273:
274: private function _reindex() {
275:
276:
277: $db = cRegistry::getDb();
278: $db->query("-- SolrRightBottomPage->_reindex()
279: SELECT
280: con_art.idclient
281: , con_art_lang.idlang
282: , con_cat_art.idcat
283: , con_cat_lang.idcatlang
284: , con_art_lang.idart
285: , con_art_lang.idartlang
286: FROM
287: con_art_lang
288: INNER JOIN
289: con_art
290: ON
291: con_art_lang.idart = con_art.idart
292: INNER JOIN
293: con_cat_art
294: ON
295: con_art_lang.idart = con_cat_art.idart
296: INNER JOIN
297: con_cat_lang
298: ON
299: con_cat_art.idcat = con_cat_lang.idcat
300: and con_art_lang.idlang = con_cat_lang.idlang
301: ORDER BY
302: con_art_lang.idartlang
303: ;");
304:
305: $articleIds = array();
306: while ($db->nextRecord()) {
307: array_push($articleIds, array(
308: 'idclient' => $db->f('idclient'),
309: 'idlang' => $db->f('idlang'),
310: 'idcat' => $db->f('idcat'),
311: 'idcatlang' => $db->f('idcatlang'),
312: 'idart' => $db->f('idart'),
313: 'idartlang' => $db->f('idartlang')
314: ));
315: }
316:
317: $indexer = new SolrIndexer($articleIds);
318: $indexer->updateArticles();
319:
320: $cGuiNotification = new cGuiNotification();
321: return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, 'core was reindexed');
322: }
323:
324: }
325: