18 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
42 $this->uses_trans = FALSE;
44 $GLOBALS[
'SQ_SYSTEM']->lm->includePackageStrings(
'funnelback');
45 $this->_hipo_vars[
'job_dir'] = SQ_PACKAGES_PATH.
'/funnelback/hipo_jobs';
59 public static function paintConfig(&$o, $class, $write_access)
61 $o->openField(translate(
'fnb_hipo_reindex'));
64 text_box($class.
'[SQ_HIPO_REINDEX_FUNNELBACK]', SQ_HIPO_REINDEX_FUNNELBACK, 1);
66 echo SQ_HIPO_REINDEX_FUNNELBACK;
83 'SQ_HIPO_REINDEX_FUNNELBACK' => Array(
'editable' => 1,
'default' => 5),
116 return parent::getCodeName().
'-funnelback-reindex';
129 return translate(
'fnb_hipo_reindex');
145 'name' => translate(
'fnb_hipo_reindex_step_name0'),
146 'function_call' => Array(
147 'process_function' =>
'processReindex',
149 'running_mode' =>
'server',
154 'allow_cancel' => TRUE,
170 if (array_get_index(
'contextid', $this->_running_vars)) {
171 $this->_running_vars[
'contextid'] = $GLOBALS[
'SQ_SYSTEM']->getContextId();
174 while (!empty($this->_running_vars[
'todo_collections'])) {
175 if (!$this->
processReindex($this->_steps[0], get_class_lower($this))) {
194 $this->_running_vars[
'todo_collections'] = Array();
195 $this->_running_vars[
'done_collections'] = Array();
196 $fm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'funnelback_manager');
198 trigger_localised_error(
'FNB0020', E_USER_WARNING);
201 $collections = $fm->getCollections();
206 if (array_get_index(
'contextid', $this->_running_vars)) {
207 $this->_running_vars[
'contextid'] = $GLOBALS[
'SQ_SYSTEM']->getContextId();
211 if (!isset($this->_running_vars[
'collections']) || (is_null($this->_running_vars[
'collections']) || empty($this->_running_vars[
'collections']))) {
213 foreach ($collections as $collection_id => $collection_info) {
215 $collection_type = array_get_index($collection_info,
'type',
'web');
216 if ($collection_type ==
'meta')
continue;
218 $collection_valid = array_get_index($collection_info,
'valid', FALSE);
219 if ($collection_valid === TRUE) {
220 $this->_running_vars[
'todo_collections'][] = Array($collection_id => $collection_info);
225 if (!is_array($this->_running_vars[
'collections'])) {
227 $this->_running_vars[
'collections'] = Array($this->_running_vars[
'collections']);
230 foreach ($this->_running_vars[
'collections'] as $todo_collection) {
232 foreach ($collections as $collection_id => $collection_info) {
234 $collection_type = array_get_index($collection_info,
'type',
'web');
235 if ($collection_type ==
'meta')
continue;
237 $collection_valid = array_get_index($collection_info,
'valid', FALSE);
238 if ($collection_valid === TRUE && $collection_id == $todo_collection) {
239 $this->_running_vars[
'todo_collections'][] = Array($collection_id => $collection_info);
245 return parent::prepare();
261 $GLOBALS[
'SQ_SYSTEM']->changeContext(array_get_index($this->_running_vars,
'contextid', 0));
263 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
264 $fm = $am->getSystemAsset(
'funnelback_manager');
270 if (!empty($this->_running_vars[
'todo_collections'])) {
271 reset($this->_running_vars[
'todo_collections']);
272 $next = key($this->_running_vars[
'todo_collections']);
273 $collection_id = key($this->_running_vars[
'todo_collections'][$next]);
274 $collection_info = $this->_running_vars[
'todo_collections'][$next][$collection_id];
275 $url = array_get_index($collection_info,
'url', Array());
276 $assetid = array_get_index($collection_info,
'asset', 0);
277 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'', TRUE);
278 unset($this->_running_vars[
'todo_collections'][$next]);
280 if (!empty($url) && !is_null($asset)) {
282 $step_data[
'message'] = translate(
'fnb_hipo_reindexing_url', htmlspecialchars($asset->attr(
'name')));
286 $xml = $fm->generateXMLCache($url, $assetid, FALSE);
287 $log_file = SQ_LOG_PATH.
'/funnelback.log';
288 $bin_path = $fm->getFunnelbackPath();
289 $coll_path = $fm->getCollectionDataPath($collection_id);
290 $coll_log_path = $fm->getCollectionDataPath($collection_id,
'log');
291 $data_path = $fm->getCollectionDataPath($collection_id,
'idx_new');
292 $live_path = $fm->getCollectionDataPath($collection_id,
'idx');
293 if (empty($data_path))
return FALSE;
294 $options = $fm->getIndexingOptions();
297 if (!is_writable($data_path)) {
298 trigger_localised_error(
'FNB0030', E_USER_WARNING);
303 file_put_contents($data_path.
'/sitemap.xml', $xml);
305 preg_match(
'/[0-9]+/', exec(
'wc -L '.$data_path.
'/sitemap.xml'), $matches);
306 $maxLineLength = isset($matches[0]) ? $matches[0] : NULL;
309 $user_id = $fm->attr(
'user');
310 if (!empty($user_id)) {
311 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($user_id,
'', TRUE);
312 if (!is_null($user)) {
313 $username = $user->attr(
'username');
314 $password = $fm->attr(
'password');
315 file_put_contents($data_path.
'/creds', $username.
' '.$password);
316 $options[] =
'-CF='.$data_path.
'/creds';
317 $options[] =
'-loginPrefix='.SQ_CONF_LOGIN_SUFFIX;
322 if (file_exists($coll_log_path.
'/click.log')) {
323 $options[] =
'-F'.$coll_log_path.
'/click.log';
327 $options[] =
'-security_level=1';
330 $command = $bin_path.
'/bin/padre-iw';
331 $command .=
' -secmap '.escapeshellarg($data_path.
'/sitemap.xml');
332 $command .=
' '.escapeshellarg($collection_id);
333 $command .=
' '.implode(
' ', $options);
334 $command .= isset($maxLineLength) ?
' -mdsfml'.$maxLineLength :
'';
337 $status = $fm->runCommand($command, $output, NULL, $log_file, $data_path, Array(
'SITE_SEARCH_ROOT'=>$coll_path));
340 if (file_exists($data_path.
'/creds')) {
341 unlink($data_path.
'/creds');
346 $make_live_cmd =
'rm -rf idx_old; mv idx idx_old; mv idx_new idx';
347 $final_status = $fm->runCommand($make_live_cmd, $output, NULL, $log_file, $coll_path);
350 trigger_localised_error(
'FNB0032', E_USER_WARNING);
355 trigger_localised_error(
'FNB0031', E_USER_WARNING);
360 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset, TRUE);
364 $this->_running_vars[
'done_collections'][] = $collection_id;
367 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
369 if (empty($this->_running_vars[
'todo_collections'])) {
370 $step_data[
'percent_done'] = 100;
371 $step_data[
'complete'] = TRUE;
373 $total = count($this->_running_vars[
'todo_collections']) + count($this->_running_vars[
'done_collections']);
374 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_collections']) / $total) * 100;
375 $step_data[
'complete'] = FALSE;