Jump to content

Featured Replies

Posted

I have a custom application with an Item class that doesn't implement the \IPS\Content\Searchable interface since they are not supposed to be available in search:

class _Item extends \IPS\Content\Item implements \IPS\Content\Hideable, \IPS\Content\Shareable, \IPS\Content\Embeddable, \IPS\Content\MetaData

I was testing the restore function for deleted content in the Moderator CP, and I received this error below when I tried to restore one of the items:

TypeError thrown with message "IPS\Content\Search\Mysql\_Index::index(): Argument #1 ($object) must be of type IPS\Content\Searchable, IPS\customapp\Item given, called in \system\Content\Content.php on line 1301"

Stacktrace:
#8 TypeError in \system\Content\Search\Mysql\Index.php:55
#7 IPS\Content\Search\Mysql\_Index:index in \system\Content\Content.php:1301
#6 IPS\_Content:restore in \system\Content\Content.php:1113
#5 IPS\_Content:modAction in \init.php:947
#4 IPS\core\extensions\core\ModCp\_Deleted:modaction in \applications\core\extensions\core\ModCp\Deleted.php:50
#3 IPS\core\extensions\core\ModCp\_Deleted:manage in \applications\core\modules\front\modcp\modcp.php:114
#2 IPS\core\modules\front\modcp\_modcp:manage in \system\Dispatcher\Controller.php:118
#1 IPS\Dispatcher\_Controller:execute in \system\Dispatcher\Dispatcher.php:153
#0 IPS\_Dispatcher:run in \init.php:947

The \IPS\Content::restore() function should not try to index the item if the interface is not implemented.

Thank you for bringing this issue to our attention! I can confirm this should be further reviewed and I have logged an internal bug report for our development team to investigate and address as necessary, in a future maintenance release.

  • 4 weeks later...
  • Author

Since the client couldn't wait for a future version with the fix, I made this change for them:

		/* Reindex the now hidden content - if this is a content item with comments or reviews, then make sure to do those too. */
		if ( $this instanceof \IPS\Content\Searchable )
		{
			if ( $this instanceof \IPS\Content\Item AND ( isset( static::$commentClass ) OR isset( static::$reviewClass ) ) )
			{
				\IPS\Content\Search\Index::i()->index( ( static::$firstCommentRequired ) ? $this->firstComment() : $this );
				\IPS\Content\Search\Index::i()->indexSingleItem( $this );
			}
			else
			{
				/* Either this is a comment / review, or the item doesn't support comments or reviews, so we can just reindex it now. */
				\IPS\Content\Search\Index::i()->index( $this );
			}
		}

I simply added an extra IF check on \IPS\Content\Searchable.

Posted it here in case someone else needs it.

Related, from April/2024:

  • Author

Yep. Same exact issue.

Recently Browsing 0

  • No registered users viewing this page.