Jump to content

Community

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


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

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We use technologies, such as cookies, to customise content and advertising, to provide social media features and to analyse traffic to the site. We also share information about your use of our site with our trusted social media, advertising and analytics partners. See more about cookies and our Privacy Policy