Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cContentTypePifaForm
  • DefaultFormModule
  • DefaultFormProcessor
  • ExampleOptionsDatasource
  • MailedFormProcessor
  • Pifa
  • PifaAbstractFormModule
  • PifaAbstractFormProcessor
  • PifaAjaxHandler
  • PifaExporter
  • PifaExternalOptionsDatasourceInterface
  • PifaField
  • PifaFieldCollection
  • PifaForm
  • PifaFormCollection
  • PifaImporter
  • PifaLeftBottomPage
  • PifaRightBottomFormDataPage
  • PifaRightBottomFormExportPage
  • PifaRightBottomFormFieldsPage
  • PifaRightBottomFormImportPage
  • PifaRightBottomFormPage
  • SolrRightBottomPage

Exceptions

  • PifaDatabaseException
  • PifaException
  • PifaIllegalStateException
  • PifaMailException
  • PifaNotImplementedException
  • PifaNotYetStoredException
  • PifaValidationException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * @package Plugin
  6:  * @subpackage FormAssistant
  7:  * @version SVN Revision $Rev:$
  8:  * @author marcus.gnass
  9:  * @copyright four for business AG
 10:  * @link http://www.4fb.de
 11:  */
 12: 
 13: // assert CONTENIDO framework
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Creates a page to be displayed in the right bottom frame.
 18:  *
 19:  * secure
 20:  * hostname
 21:  * port
 22:  * path
 23:  * wt
 24:  * login
 25:  * password
 26:  * proxy_host
 27:  * proxy_port
 28:  * proxy_login
 29:  * proxy_password
 30:  * timeout
 31:  * ssl_cert
 32:  * ssl_key
 33:  * ssl_keypassword
 34:  * ssl_cainfo
 35:  * ssl_capath
 36:  *
 37:  * @author marcus.gnass
 38:  */
 39: class SolrRightBottomPage extends cGuiPage {
 40: 
 41:     /**
 42:      *
 43:      * @var array
 44:      */
 45:     private $_clientOptions;
 46: 
 47:     /**
 48:      * @global string $action to be performed
 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('right_bottom.css');
 58:         $this->addScript('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:         // get client options
 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:         // actions will be disabled if any required client option is missing
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:         // dispatch action
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:      * Dispatches the given action.
128:      *
129:      * @param string $action to be executed
130:      * @throws InvalidArgumentException if the given action is unknown
131:      */
132:     protected function _dispatch($action) {
133:         global $area;
134: 
135:         // check for permission
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:         // dispatch action
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:      * @return string
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:                 // Solr system properties w/o values are not stored to prevent
181:                 // property pollution
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:      * Call the relaod action.
191:      *
192:      * http://client-uat70.4fb.net:8080/solr/admin/cores?action=STATUS
193:      * http://client-uat70.4fb.net:8080/solr/admin/cores?action=RENAME&core=collection1&other=contenido
194:      * http://client-uat70.4fb.net:8080/solr/admin/cores?action=RELOAD&core=contenido
195:      * Cannot be done with Solr extension (or can it?).
196:      *
197:      * @return string
198:      */
199:     private function _reload() {
200: 
201:         // build URL
202:         // @see https://en.wikipedia.org/wiki/Basic_access_authentication
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:         // create curl resource
212:         $ch = curl_init();
213: 
214:         $data = false;
215:         if (false !== $ch) {
216: 
217:             $opt = array(
218:                 // set url
219:                 CURLOPT_URL => $url,
220:                 // TRUE to reset the HTTP request method to GET.
221:                 CURLOPT_HTTPGET => true,
222:                 // The contents of the "User-Agent: " header to be used
223:                 // in a HTTP request.
224:                 CURLOPT_USERAGENT => 'CONTENIDO Solr Plugin v1.0',
225:                 // The maximum number of milliseconds to allow cURL
226:                 // functions to execute.
227:                 CURLOPT_TIMEOUT_MS => 5000,
228:                 // The number of milliseconds to wait while trying to
229:                 // connect.
230:                 CURLOPT_CONNECTTIMEOUT_MS => 5000,
231:                 // return the transfer as a string
232:                 CURLOPT_RETURNTRANSFER => 1,
233:                 // TRUE to include the header in the output.
234:                 CURLOPT_HEADER => false
235:             );
236: 
237:             curl_setopt_array($ch, $opt);
238: 
239:             // $data contains the output string
240:             $data = curl_exec($ch);
241: 
242:             // get curl info
243:             $curlInfo = curl_getinfo($ch);
244: 
245:             // close curl resource to free up system resources
246:             curl_close($ch);
247: 
248:             if (200 !== (int) $curlInfo['http_code']) {
249:                 $msg = 'HTTP status code ' . $curlInfo['http_code'];
250:                 // may contain an error message
251:                 // $msg .= '\ndata: ' . $sData;
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:      * @return string
273:      */
274:     private function _reindex() {
275: 
276:         $cfg = cRegistry::getConfig();
277: 
278:         // statement is not correct if articles are related to more than one category.
279:         $db = cRegistry::getDb();
280:         $db->query("-- SolrRightBottomPage->_reindex()
281:             SELECT
282:                 art.idclient
283:                 , art_lang.idlang
284:                 , cat_art.idcat
285:                 , cat_lang.idcatlang
286:                 , art_lang.idart
287:                 , art_lang.idartlang
288:             FROM
289:                 `{$cfg['tab']['art_lang']}` AS art_lang
290:             INNER JOIN
291:                 `{$cfg['tab']['art']}` AS art
292:             ON
293:                 art_lang.idart = art.idart
294:             INNER JOIN
295:                 `{$cfg['tab']['cat_art']}` AS cat_art
296:             ON
297:                 art_lang.idart = cat_art.idart
298:             INNER JOIN
299:                 `{$cfg['tab']['cat_lang']}` AS cat_lang
300:             ON
301:                 cat_art.idcat = cat_lang.idcat
302:                 AND art_lang.idlang = cat_lang.idlang
303:             ORDER BY
304:                 art_lang.idartlang
305:             ;");
306: 
307:         $articleIds = array();
308:         while ($db->nextRecord()) {
309:             array_push($articleIds, array(
310:                 'idclient' => $db->f('idclient'),
311:                 'idlang' => $db->f('idlang'),
312:                 'idcat' => $db->f('idcat'),
313:                 'idcatlang' => $db->f('idcatlang'),
314:                 'idart' => $db->f('idart'),
315:                 'idartlang' => $db->f('idartlang')
316:             ));
317:         }
318: 
319:         $indexer = new SolrIndexer($articleIds);
320:         $indexer->updateArticles();
321: 
322:         $cGuiNotification = new cGuiNotification();
323:         return $cGuiNotification->returnNotification(cGuiNotification::LEVEL_INFO, 'core was reindexed');
324:     }
325: 
326: }
327: 
CMS CONTENIDO 4.9.5 API documentation generated by ApiGen 2.8.0