Commit a90fd20e authored by robertokir's avatar robertokir

[bp/r70421][FIX][ENH] Report all occurrences of a string in any table: fixes and enhancements

parent 1f80801c
Pipeline #72080843 failed with stages
in 25 minutes and 39 seconds
......@@ -107,10 +107,14 @@ $smarty->assign('engine_info', $unifiedsearchlib->getEngineInfo());
if ($tiki_p_admin == 'y' && $access->ticketMatch()) {
if (isset($_REQUEST['rebuild']) && $_REQUEST['rebuild'] == 'now') {
$access->redirect(TikiLib::lib('service')->getUrl([
'controller' => 'search',
'action' => 'rebuild',
]));
$access->redirect(
TikiLib::lib('service')->getUrl(
[
'controller' => 'search',
'action' => 'rebuild',
]
)
);
}
if (isset($_REQUEST['optimize']) && $_REQUEST['optimize'] == 'now') {
......@@ -119,43 +123,78 @@ if ($tiki_p_admin == 'y' && $access->ticketMatch()) {
$stat = $unifiedsearchlib->getIndex('data-write')->optimize();
}
if (! empty($_REQUEST['refresh_index_all_now']) && $_REQUEST['refresh_index_all_now'] == 'y') {
if (! empty($_REQUEST['refresh_index_all_now'])
&& $_REQUEST['refresh_index_all_now'] == 'y'
) {
require_once('lib/search/refresh-functions.php');
foreach (activated_features() as $feature) {
refresh_index($feature);
}
$smarty->assign('refresh_index_all_now', $_REQUEST['refresh_index_all_now']);
$smarty->assign(
'refresh_index_all_now', $_REQUEST['refresh_index_all_now']
);
}
if (! empty($_REQUEST['refresh_files_index_now']) && $_REQUEST['refresh_files_index_now'] == 'y') {
if (! empty($_REQUEST['refresh_files_index_now'])
&& $_REQUEST['refresh_files_index_now'] == 'y'
) {
require_once('lib/search/refresh-functions.php');
refresh_index('files');
$smarty->assign('refresh_files_index_now', $_REQUEST['refresh_files_index_now']);
$smarty->assign(
'refresh_files_index_now', $_REQUEST['refresh_files_index_now']
);
}
if (! empty($_REQUEST['refresh_index_now']) && $_REQUEST['refresh_index_now'] == 'y') {
if (! empty($_REQUEST['refresh_index_now'])
&& $_REQUEST['refresh_index_now'] == 'y'
) {
require_once('lib/search/refresh-functions.php');
refresh_index('pages');
$smarty->assign('refresh_index_now', $_REQUEST['refresh_index_now']);
}
if (! empty($_REQUEST['refresh_tracker_index_now']) && $_REQUEST['refresh_tracker_index_now'] == 'y') {
if (! empty($_REQUEST['refresh_tracker_index_now'])
&& $_REQUEST['refresh_tracker_index_now'] == 'y'
) {
require_once('lib/search/refresh-functions.php');
refresh_index('tracker_items');
$smarty->assign('refresh_tracker_index_now', $_REQUEST['refresh_tracker_index_now']);
$smarty->assign(
'refresh_tracker_index_now', $_REQUEST['refresh_tracker_index_now']
);
}
if (! empty($_POST['string_in_db_search'])) {
require_once('lib/search/report_string_in_db.php');
$smarty->assign('searchString', $_REQUEST['string_in_db_search']);
$smarty->assign('searchStringAgain', $_REQUEST['string_in_db_search']);
if (! empty($_REQUEST['string_in_db_search_table'])) {
$smarty->assign(
'tableFilter', $_REQUEST['string_in_db_search_table']
);
}
}
if (! empty($_POST['query'])) {
require_once('lib/search/report_string_in_db.php');
$smarty->assign('searchStringAgain', $_REQUEST['query']);
$smarty->assign('tableName', $_REQUEST['table']);
if (! empty($_REQUEST['string_in_db_search_table'])) {
$smarty->assign(
'tableFilter', $_REQUEST['string_in_db_search_table']
);
}
}
}
if ($tiki_p_admin == 'y') {
$tikilib = TikiLib::lib('tiki');
$allTables = $tikilib->listTables();
foreach ($allTables as $table) {
if (substr($table,0, 6) !== 'index_' || substr($table,0, 10) == 'index_pref') {
$tables[] = $table;
}
}
$smarty->assign('tables', $tables);
}
$lastLogItem = $unifiedsearchlib->getLastLogItem();
......
......@@ -41,6 +41,22 @@ if (! empty($_POST['string_in_db_search'])) {
$sql = "select * from `" . $table . "` where `" . $column . "` like ?";
$rs = $tikilib->fetchAll($sql, $args);
foreach ($rs as $row) {
if ($table == 'tiki_pages') {
$stringpos = strpos($row['data'], $_POST['query']);
$stringend = $stringpos + strlen($_POST['query']);
$startsnip = max($stringpos - 100, 0);
$endsnip = $stringend + 100;
$length = ($endsnip - $startsnip);
$snippet = substr($row['data'], $startsnip, $length);
$snippet = str_replace($_POST['query'],"<span class='highlight'>".$_POST['query']."</span>", $snippet);
if ($startsnip > 0) {
$snippet = '...' . $snippet;
}
if ($endsnip < strlen($row['data'])) {
$snippet = $snippet . '...';
}
$row['snippet'] = $snippet;
}
$tableData[] = $row;
}
$smarty->assign('tableData', $tableData);
......@@ -63,7 +79,7 @@ function searchAllDB($search)
foreach ($rs as $key => $val) {
$vals = array_values($val);
$table = $vals[0];
if (substr($table, 0, 6) == 'index_') {
if (substr($table, 0, 6) == 'index_' && substr($table,0, 10) !== 'index_pref') {
continue;
}
$sql2 = "SHOW COLUMNS FROM `$table`";
......
{* $Id$ *}
<h2 class="panel-title">Occurences of string in database</h2>
<input type="text" id="string_in_db_search" name="string_in_db_search" size="60" value="{$searchStringAgain|escape}" /> <input type="submit" class="btn btn-default btn-sm" value="Search" onClick="document.getElementById('redirect').value='0';"/>
<input type="hidden" id="redirect" name="redirect" value="1">
<h2 class="panel-title">{tr}Occurrences of string in database{/tr}</h2>
<div class="adminoptionbox clearfix form-group row">
<label for="string_in_db_search_table" class="col-form-label col-sm-4">
{tr}Set default table:{/tr}
</label>
<div class="col-sm-7">
<div class="input-group">
<select name="string_in_db_search_table" class="form-control" id="string_in_db_search_table">
<option value="">All tables</option>
{foreach $tables as $table}
<option value="{$table|escape}" {if isset($tableFilter) && $table eq $tableFilter} selected="selected"{/if}>{$table|escape}</option>
{/foreach}
</select>
</div>
</div>
</div>
<div class="adminoptionbox clearfix form-group row">
<label for="string_in_db_search" class="col-form-label col-sm-4">
{tr}Text to search:{/tr}
</label>
<div class="col-sm-4">
<div class="input-group">
<input type="text" id="string_in_db_search" name="string_in_db_search" class="form-control" value="{$searchStringAgain|escape}" />
</div>
</div>
<div class="col-sm-3">
<div class="input-group">
<input type="submit" id="string_in_db_search_button" class="btn btn-primary" value="{tr}Search{/tr}" onClick="document.getElementById('redirect').value='0';"/>
</div>
</div>
{jq}
$('#string_in_db_search').keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
$('#string_in_db_search_button').click();
return false;
}
});
{/jq}
<input type="hidden" id="redirect" name="redirect" value="1">
</div>
<hr/>
{if isset($errorMsg)}
<span id="error">{$errorMsg}</span>
{else}
{if isset($searchString)}
{remarksbox}{tr}Results for {/tr}<b>{$searchString|escape}</b> {tr}in all tables:{/tr}{/remarksbox}
{remarksbox}{tr}Results for {/tr}<b>{$searchString|escape}</b> {tr}in {if isset($tableFilter)}table <b>{$tableFilter|escape}</b>{else}all tables{/if}:{/tr}{/remarksbox}
<p>
<input type="hidden" name="query" value="{$searchString|escape}">
......@@ -24,6 +63,9 @@
{$last = ''}
{foreach from=$searchResult item=res}
{$table = $res['table']}
{if isset($tableFilter) && $table neq $tableFilter}
{continue}
{/if}
<tr>
{if $last eq '' || $last neq $table}
{$span = $tableCount["$table"]}
......@@ -39,8 +81,8 @@
{/if}
{if isset($tableHeaders)}
{remarksbox}{tr}Results for {/tr}<b>{$searchStringAgain|escape}</b> {tr}in table {/tr} <b>{$tableName}</b>, {tr}column{/tr} <b>{$columnName}</b>:{/remarksbox}
<table class="table">
{remarksbox}{tr}Results for {/tr}<b>{$searchStringAgain|escape}</b> {tr}in table {/tr} <b>{$tableName}</b>, {tr}column{/tr} <b>{$columnName}</b>:{/remarksbox}
<table class="table-responsive">
<tr>
{foreach from=$tableHeaders item=hdr}
<th>{if $hdr eq $columnName}<em>{$hdr}</em>{else}{$hdr}{/if}</th>
......@@ -52,8 +94,15 @@
{foreach from=$row key=column item=val}
{$value = $val|truncate:30|escape}
{if $tableName=='tiki_pages' && ($column=='pageName' || $column=='pageSlug' || $column=='data' || $column=='description') && $val}
<td><a href="{$row['pageName']|sefurl:wiki}" class="link tips" title="{$row['pageName']}: {tr}View page{/tr}" target="_blank">{$value}</a></td>
<!-- TODO: (see note about object_link in templates/tiki-listpages_content.tpl) <td>{object_link type='wiki page' id={$row['pageName']|escape} class="link tips" title="{$val|escape}:{tr}View page{/tr}"}</td> -->
{if $column=='data'}
<td><a tabindex='0' target='_blank' data-trigger='hover' title='{tr}Page preview{/tr}' class="ajaxtips" data-ajaxtips="{service controller='wiki' action='get_page' page=$row['pageName']}">
{$row['snippet']}
</a>
</td>
{else}
<td><a href="{$row['pageName']|sefurl:wiki}" class="link tips" title="{$row['pageName']}: {tr}View page{/tr}" target="_blank">{$value}</a></td>
<!-- TODO: (but see note about object_link in templates/tiki-listpages_content.tpl) <td>{object_link type='wiki page' id={$row['pageName']|escape} class="link tips" title="{$val|escape}:{tr}View page{/tr}"}</td> -->
{/if}
{elseif $column=='lastModif' || $column=='created' || $column=='commentDate' || $column=='publishDate' || $column=='expireDate'}
<td>{$value|tiki_short_datetime}</td>
{elseif $tableName=='tiki_blog_posts' && ($column=='data' || $column=='title')}
......@@ -101,7 +150,7 @@
{/if}
{elseif $row['objectType']=='wiki page'}
{if ($column=='objectType' || $column=='data' || $column=='object')}
<td><a href="{$row['object']|sefurl}?threadId={$row['threadId']|escape:"url"}&comzone=show#threadId{$row['threadId']|escape:"url"}" class="link tips" title="{$row['object']|escape}: {tr}View page{/tr}" target="_blank">{$value}</a></td>
<td><a href="{$row['object']|sefUrl:wiki}?threadId={$row['threadId']|escape:"url"}&comzone=show#threadId{$row['threadId']|escape:"url"}" class="link tips" title="{$row['object']|escape}: {tr}View page{/tr}" target="_blank">{$value}</a></td>
{else}
<td>{$value}</td>
{/if}
......@@ -114,6 +163,7 @@
{/foreach}
</tr>
{/foreach}
</table>
</table>
<p><a href="javascript:void(0)" class="btn btn-primary btn-sm" title="{tr}Back to first level results{/tr}" onClick="document.getElementById('string_in_db_search').value='{$searchStringAgain|escape}'; document.getElementById('string_in_db_search_button').click();">{tr}Back to first level results{/tr}</a></p>
{/if}
{/if}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment