?
avatar eorisis
eorisis
6 May 2017

When a component uses category sections such ascom_example.section, every such category gets stored in the "categories" table, "extension" column, with such a value and not just the extension element. While the "Content - Smart Search" and "Smart Search - Categories" plugins are enabled, if you attempt to save, trash, publish/unpublish a category, the method index() in /plugins/finder/categories/categories.php takes the $item from the database and does not check the extension value before proceeding, but directly fires the following check:

// Check if the extension that owns the category is also enabled.
if (JComponentHelper::isEnabled($item->extension) == false)
{
	return;
}

In this case isEnabled() will pass the wrong value to load() which will consider it a fatal error on this part:

[...]
if (empty(static::$components[$option]))
{
	/*
	 * Fatal error
	 *
	 * It is possible for this error to be reached before the global JLanguage instance has been loaded so we check for its presence
	 * before logging the error to ensure a human friendly message is always given
	 */

	if (JFactory::$language)
	{
		$msg = JText::sprintf('JLIB_APPLICATION_ERROR_COMPONENT_NOT_LOADING', $option, JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'));
	}
	else
	{
		$msg = sprintf('Error loading component: %1$s, %2$s', $option, 'Component not found.');
	}

	JLog::add($msg, JLog::WARNING, 'jerror');

	return false;
}
[...]

This will cause a warning displayed in the browser that looks like this:

Error loading component: com_example.section, Component not found.

Also, it will not get indexed by the Smart Search component. I am not aware of what else wrong happens. I was able to track this problem since Joomla 3.7.0 (still exists in 3.7.2) because of the changes in the above methods, while in 3.6.5 and older it would pass unnoticed.

EDIT:
If we observe the file /administrator/components/com_categories/models/category.php we see that the section part of a category is being taken in to account in various of places such as in getForm() populateState() and preprocessForm()

In particular by taking a look at this part in populateState()

[...]
$extension = $app->input->get('extension', 'com_content');
$this->setState('category.extension', $extension);
$parts = explode('.', $extension);

// Extract the component name
$this->setState('category.component', $parts[0]);

// Extract the optional section name
$this->setState('category.section', (count($parts) > 1) ? $parts[1] : null);
[...]

We see nothing like this being done in the index() method in /plugins/finder/categories/categories.php

Expected result

No warnings, get the category indexed.

Actual result

A warning is displayed such as:
Error loading component: com_example.section, Component not found.

Plus, the category does not get indexed.

System information (as much as possible)

PHP Built On: Linux development-server 3.16.0-4-amd64 #1 SMP Debian 3.16.43-2 (2017-04-30) x86_64
Database Version: 5.5.55-0+deb8u1
Database Collation: utf8mb4_unicode_ci
Database Connection Collation: utf8mb4_general_ci
PHP Version: 5.6.30-0+deb8u1
Web Server: Apache
WebServer to PHP Interface: cgi-fcgi
Joomla! Version: Joomla! 3.7.2 Stable [ Amani ] 22-May-2017 09:46 GMT
Joomla! Platform Version: Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
User Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0

The Fix

Explode $item->extension and take the first value of the array as the actual element of the extension into a variable $extension_element and then use that variable in all the rest of the index() method. Example:

[...]
// Check if the extension is enabled.
if (JComponentHelper::isEnabled($this->extension) == false)
{
	return;
}

// Extract the extension element
$parts = explode('.', $item->extension);
$extension_element = $parts[0];

// Check if the extension that owns the category is also enabled.
if (JComponentHelper::isEnabled($extension_element) == false)
{
	return;
}
[...]

fix_j372.tar.gz

Steps to reproduce the issue

  1. Install a component that uses categories with sections.
  2. Enable "Content - Smart Search" and "Smart Search - Categories" plugins.
  3. Create a category in the component and click on Save.
  4. Observe the Warning.
  5. Check that the category did not get indexed in the Smart Search component.
avatar eorisis eorisis - open - 6 May 2017
avatar joomla-cms-bot joomla-cms-bot - change - 6 May 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 6 May 2017
avatar eorisis
eorisis - comment - 6 May 2017

Here is the file with the fix.
fix.tar.gz

avatar eorisis eorisis - edited - 6 May 2017
avatar eorisis eorisis - change - 6 May 2017
The description was changed
avatar eorisis eorisis - edited - 6 May 2017
avatar joomla-cms-bot joomla-cms-bot - change - 6 May 2017
The description was changed
avatar joomla-cms-bot joomla-cms-bot - edited - 6 May 2017
avatar eorisis eorisis - change - 6 May 2017
The description was changed
avatar eorisis eorisis - edited - 6 May 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 6 May 2017
The description was changed
avatar franz-wohlkoenig franz-wohlkoenig - change - 6 May 2017
Category com_search
avatar eorisis eorisis - change - 26 May 2017
The description was changed
avatar eorisis eorisis - edited - 26 May 2017
avatar eorisis eorisis - change - 26 May 2017
The description was changed
avatar eorisis eorisis - edited - 26 May 2017
avatar eorisis eorisis - change - 26 May 2017
The description was changed
avatar eorisis eorisis - edited - 26 May 2017
avatar brianteeman
brianteeman - comment - 26 May 2017

Closed as we have a problem see #16728

avatar brianteeman brianteeman - change - 26 May 2017
The description was changed
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-05-26 13:46:48
Closed_By brianteeman
avatar brianteeman brianteeman - close - 26 May 2017

Add a Comment

Login with GitHub to post a comment