Jump to content

[4.6.3] Error when IPS\Content\Item has only a $reviewClass


teraßyte
 Share

Go to solution Solved by Daniel F,

Recommended Posts

I have an application that uses only $reviewClass and NO $commentClass which throws an error after upgrading to 4.6. This happens because loading the reviews then goes on to call the function _comments() from system\Content\Item::reviews() to load the data.

 

The error is because of this code added in system\Content\Item::_comments() to handle solved contents, statistics, and recognized content (lines 4349-4400):

		/* Solved count */
		$commentClass = static::$commentClass;
		$showSolvedStats = FALSE;

		if ( method_exists( $this, 'isQuestion' ) and $this->isQuestion() )
		{
			$showSolvedStats = TRUE;
		}
		else if ( \IPS\IPS::classUsesTrait( $this, 'IPS\Content\Solvable' ) and ( $this->containerAllowsMemberSolvable() OR $this->containerAllowsSolvable() ) )
		{
			$showSolvedStats = TRUE;
		}

		if ( $showSolvedStats )
		{
			$memberIds = array();
			$solvedCounts = array();
			$authorField = $commentClass::$databaseColumnMap['author'];

			foreach( $results as $id => $data )
			{
				$memberIds[ $data->$authorField ] = $data->$authorField;
			}

			if ( \count( $memberIds ) )
			{
				foreach( \IPS\Db::i()->select( 'COUNT(*) as count, member_id', 'core_solved_index', array( \IPS\Db::i()->in( 'member_id', $memberIds ) ), NULL, NULL, 'member_id' ) as $member )
				{
					$solvedCounts[ $member['member_id'] ] = $member['count'];
				}

				foreach( $results as $id => $data )
				{
					if ( isset( $solvedCounts[ $data->$authorField ] ) )
					{
						$results[ $id ]->author_solved_count = $solvedCounts[ $data->$authorField ];
					}
				}
			}
		}

		/* Recognized content */
		if ( \IPS\IPS::classUsesTrait( $commentClass, 'IPS\Content\Recognizable' ) )
		{
			foreach( \IPS\Db::i()->select( '*', 'core_member_recognize', [ [ 'r_content_class=?', $commentClass ], [ \IPS\Db::i()->in('r_content_id', array_keys( $results ) ) ] ] ) as $row )
			{
				if ( isset( $results[ $row['r_content_id'] ] ) )
				{
					$results[ $row['r_content_id'] ]->recognized = \IPS\core\Achievements\Recognize::constructFromData( $row );
				}
			}
		}

 

To solve the issue I had to wrap the whole thing in an IF check for the class:

		if ( isset(static::$commentClass) )
		{
			//...
		{

 

Link to comment
Share on other sites

I forgot to post the error I'm getting, here it is: class_uses(): object or string expected

 

This happens because the function isQuestion() doesn't exist and once the code reaches the else part with the \IPS\IPS::classUsesTrait( $this, 'IPS\Content\Solvable' ) check the static::$commentClass variable doesn't exist and NULL is used instead.

Link to comment
Share on other sites

  • 1 month later...
54 minutes ago, teraßyte said:

It's been more than a month since I posted. Nothing? At least I see this is still not fixed in 4.6.5.1.

It is from 25 November 2020 that I sent you a PM to ask for assistance for one of your plugins that you have no longer updated and made compatible for version 4.5.
Can you kindly check and reply? I also wrote to you on your site and I no longer know how to contact you except in this way (I also apologize to the Invisioncommunity Staff but I take this opportunity)

Link to comment
Share on other sites

18 minutes ago, Aurora17 said:

It is from 25 November 2020 that I sent you a PM to ask for assistance for one of your plugins that you have no longer updated and made compatible for version 4.5.
Can you kindly check and reply? I also wrote to you on your site and I no longer know how to contact you except in this way (I also apologize to the Invisioncommunity Staff but I take this opportunity)

Hmm, I never got the PM notification on here but I do see it listed after checking just now. I'll reply there.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...