PDA

Zobacz pełną wersję : Smart search / Inteligentwa wyszukiwarka



MrRoger
20-11-2017, 23:08
Witam;

Świeżak w joomli i na forum jestem, więc witam się z kolegami serdecznie i pytam.


Joomla! 3.8.2 stable

Mam dwa problemy z db, a mianowicie:

Komponenty —> Wyszukiwarka —> Indeks zawartości —> Indeksuj

Wywala mi błąd:

pl:
"
Indekser inteligentnego wyszukiwania

Wystąpił błąd

Error decoding JSON data: Syntax error


"

ang:
Smart Search: Indexed Content
"
Smart Search Indexer

An Error Has Occurred
Error decoding JSON data: Syntax error


"

"Przeleciałem" :up: bazę "json-db-check.php", który wyrzucił:
Checking 'params, rules, attribs' Entries for Invalid Syntax

Checking table: ngx70_assets, column rules

Checking table: ngx70_banners, column params

Checking table: ngx70_categories, column params

Checking table: ngx70_contact_details, column params

Checking table: ngx70_content, column attribs
Row 7 is not valid JSON. Error: (Syntax error)
Content: {"menu_image":"-1","show_title":"0","show_section":"0","show_category":"0","show_vote":"0","show_author":"0","show_create_date":"0","show_modify_date":"0","show_pdf_icon":"0","show_print_icon":"0","show_email_icon":"0","pageclass_sfx":""

Checking table: ngx70_content_types, column rules

Checking table: ngx70_extensions, column params

Checking table: ngx70_fields, column params

Checking table: ngx70_fields_groups, column params

Checking table: ngx70_finder_filters, column params

Checking table: ngx70_menu, column params

Checking table: ngx70_modules, column params

Checking table: ngx70_newsfeeds, column params

Checking table: ngx70_tags, column params

Checking table: ngx70_template_styles, column params

Checking table: ngx70_users, column params

Checking table: ngx70_viewlevels, column rules

Checking table: ngx70_wf_profiles, column params
Finished checking invalid parameters

Myślę, że bałaganu narobiła wtyczka (podejrzewam:
com_autotweet_v8.17.0-free), ale pewności nie mam.

Ktoś podpowie jak poprawić wpisy bazy i formatowania szablonu?

Jola
21-11-2017, 02:57
Jeśli wpis jest kompletny, to brakuje na końcu zamykającego nawiasu: }

MrRoger
21-11-2017, 15:38
Super! +2zł do 4paka lub szmninki — co wolisz :D

Nie zauważyłem braku "}"
znalazłem atrybut w bazie, poprawiłem i "szukajka" działa.

Wieczorem zajmę się szablonem.

Temat do zamknięcia.

PS: Z koleżankami też się witam :zakochany:

Jola
21-11-2017, 17:40
Wystarczy dziękuję :)

MrRoger
21-11-2017, 18:19
Dla potomności, jeśli ktokolwiek ma problemy w db z "JSON data: Syntax error", polecam skrypt "json-db-check.php".

Do pobrania z:

https://github.com/robwent/joomla-json-db-check

Jak nie śpicie podobnie jak ja do 8 nad ranem edytując bazę z "kopyta", skrypcik znajdzie błędy, a Jola Wam literówki wyłapie. :zakochany:


<?php
/**
* Turn on outputbuffering for servers that have it disabled.
*/
ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Joomla json Check</title>
<style>
.btn {
/* Structure */
display: inline-block;
zoom: 1;
line-height: normal;
white-space: nowrap;
vertical-align: middle;
text-align: center;
cursor: pointer;
-webkit-user-drag: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font-family: inherit;
font-size: 100%;
padding: 0.5em 1em;
border: 1px solid #999; /*IE 6/7/8*/
border: none rgba(0, 0, 0, 0); /*IE9 + everything else*/
background-color: rgb(0, 120, 231);
color: #fff;
text-decoration: none;
border-radius: 2px;
}
</style>
</head>
<body>
<?php
//Initiate Joomla so we can use it's functions
/**
* Constant that is checked in included files to prevent direct access.
* define() is used in the installation folder rather than "const" to not error for PHP 5.2 and lower
*/
define('_JEXEC', 1);

if (file_exists(__DIR__ . '/defines.php'))
{
include_once __DIR__ . '/defines.php';
}

if (!defined('_JDEFINES'))
{
define('JPATH_BASE', __DIR__);
require_once JPATH_BASE . '/includes/defines.php';
}

require_once JPATH_BASE . '/includes/framework.php';

// Instantiate the application.
$app = JFactory::getApplication('site');
$db = JFactory::getDbo();
$config = JFactory::getConfig();

$jinput = $app->input;
$fullcheck = $jinput->get('fullcheck', 0, 'INT');
$columns = $jinput->get('columns', array(), 'array');

function is_trying_to_be_json($data)
{
$data = trim($data);

return ((substr($data, 0, 1) === '{') || (substr($data, -1, 1) === '}')) ? true : false;
}

function is_json()
{
call_user_func_array('json_decode', func_get_args());

return (json_last_error() === JSON_ERROR_NONE);
}

//The columns to check
$column_string = 'COLUMN_NAME = \'params\' OR COLUMN_NAME = \'rules\' OR COLUMN_NAME = \'attribs\'';
if(count($columns) > 0)
{
$column_string = '';
$first = 1;

if(in_array('params', $columns))
{
$column_string .= 'COLUMN_NAME = \'params\'';
$first = 0;
}

if(in_array('rules', $columns))
{
$column_string .= $first ? 'COLUMN_NAME = \'rules\'' : ' OR COLUMN_NAME = \'rules\'';
$first = 0;
}

if(in_array('attribs', $columns))
{
$column_string .= $first ? 'COLUMN_NAME = \'attribs\'' : ' OR COLUMN_NAME = \'attribs\'';
}
}

//We use this for both checks
$query = $db->getQuery(true)
->select('TABLE_NAME,COLUMN_NAME')
->from('INFORMATION_SCHEMA.COLUMNS')
->where($column_string)
->andWhere('TABLE_SCHEMA = \'' . $config->get('db') . '\'');

$db->setQuery($query);
$results = $db->loadObjectList();
?>
<?php if ($fullcheck == 0) : ?>
<h4>Checking for Invalid Empty Parameters</h4>
<?php
if ($results)
{
foreach ($results as $result)
{
echo "Checking table: {$result->TABLE_NAME}, column {$result->COLUMN_NAME}<br>";
$query = $db->getQuery(true)
->update($result->TABLE_NAME)
->set($result->COLUMN_NAME . ' = "{}"')
->where($result->COLUMN_NAME . ' = "" OR ' . $result->COLUMN_NAME . ' = \'{\"\"}\' OR ' . $result->COLUMN_NAME . ' = \'{\\\\\"\\\\\"}\' ');

$db->setQuery($query);
$results = $db->execute();
$changes = $db->getAffectedRows();

if ($changes != 0)
{
echo $changes . " rows modified.<br>";
}
}
}
?>
<h4>Finished checking empty parameters</h4>
<form>
<button class="btn" name="fullcheck" value="1">Check For All Invalid Values</button>
Columns to check:
<label for="params" class="pure-checkbox">
<input id="params" type="checkbox" name="columns[]" value="params" checked>
params
</label>
<label for="params" class="pure-checkbox">
<input id="params" type="checkbox" name="columns[]" value="rules" checked>
rules
</label>
<label for="params" class="pure-checkbox">
<input id="params" type="checkbox" name="columns[]" value="attribs" checked>
attribs
</label>
</form>
<p></p>
<p><small>(This will not replace any values, you will need to manaully fix them)</small></p>
<?php else :
if(count($columns) > 0)
{
?>
<h4>Checking '<?php echo implode(', ', $columns) ?>' Entries for Invalid Syntax</h4>
<?php
// Check all params for invalid syntax
if ($results)
{
foreach ($results as $result)
{
echo "<p>Checking table: {$result->TABLE_NAME}, column {$result->COLUMN_NAME}</p>";
$query = $db->getQuery(true)
->select('*')
->from($result->TABLE_NAME)
->where($result->COLUMN_NAME . ' != "{}"');

$db->setQuery($query);

$results = $db->loadAssocList();

if ($results)
{
foreach ($results as $row)
{
if (!is_json($row[$result->COLUMN_NAME]) && is_trying_to_be_json($row[$result->COLUMN_NAME]))
{
$error = json_last_error_msg();
reset($row);
$first_key = key($row);
echo "Row {$row[$first_key]} is not valid JSON. Error: ($error)<br>";
echo "Content: {$row[$result->COLUMN_NAME]}<br><hr>";
}
}
}
}
}?>

<h4>Finished checking invalid parameters</h4>
<p>Check invalid rules at <a target="_blank" href="http://jsonlint.com/">jsonlint.com</a></p>
<?php }
else
{
//No columns selected ?>
<h4>You need to select at least one column to check!</h4>

<?php } ?>
<form>
<button class="btn" name="fullcheck" value="1">Check Again</button>
Columns to check:
<label for="params" class="pure-checkbox">
<input id="params" type="checkbox" name="columns[]" value="params" <?php echo (in_array('params', $columns)) ? 'checked' : ''; ?>>
params
</label>
<label for="params" class="pure-checkbox">
<input id="params" type="checkbox" name="columns[]" value="rules" <?php echo (in_array('rules', $columns)) ? 'checked' : ''; ?>>
rules
</label>
<label for="params" class="pure-checkbox">
<input id="params" type="checkbox" name="columns[]" value="attribs" <?php echo (in_array('attribs', $columns)) ? 'checked' : ''; ?>>
attribs
</label>
</form>

<?php endif; ?>
</body>
</html>