Jump to content
  • Status: Moved to Github

This is the error I see trying to view a topic after upgrading a site to 5.0.2:

TypeError: IPS\forums\Topic::canViewFutureItems(): Return value must be of type bool, null returned (0)
#0 /home/nuovo/domains/domain.com/public_html/invision/system/Content/Item.php(3029): IPS\forums\Topic::canViewFutureItems()
#1 /home/nuovo/domains/domain.com/public_html/invision/applications/forums/sources/Topic/Topic.php(379): IPS\Content\Item::getItemsWithPermission()
#2 /home/nuovo/domains/domain.com/public_html/invision/system/Helpers/Table/Content.php(418): IPS\forums\Topic::getItemsWithPermission()
#3 /home/nuovo/domains/domain.com/public_html/invision/system/Helpers/Table/Table.php(531): IPS\Helpers\Table\Content->getRows()
#4 /home/nuovo/domains/domain.com/public_html/invision/applications/forums/modules/front/forums/forums.php(568): IPS\Helpers\Table\Table->__toString()
#5 /home/nuovo/domains/domain.com/public_html/invision/applications/forums/modules/front/forums/forums.php(75): IPS\forums\modules\front\forums\forums->_forum()
#6 /home/nuovo/domains/domain.com/public_html/invision/system/Dispatcher/Controller.php(139): IPS\forums\modules\front\forums\forums->manage()
#7 /home/nuovo/domains/domain.com/public_html/invision/system/Dispatcher/Dispatcher.php(169): IPS\Dispatcher\Controller->execute()
#8 /home/nuovo/domains/domain.com/public_html/invision/index.php(16): IPS\Dispatcher->run()
#9 {main}

The issue comes from the canFuturePublish() function in the FuturePublishing trait:

	/**
	 * Can set items to be published in the future?
	 *
	 * @param Member|NULL	    $member	        The member to check for (NULL for currently logged in member)
	 * @param Model|null    $container      Container
	 * @return	bool
	 */
	public static function canFuturePublish( ?Member $member=NULL, ?Model $container = NULL ): bool
	{
		$member = $member ?: Member::loggedIn();
		return $container ? static::modPermission( 'future_publish', $member, $container ) : $member->modPermission( "can_future_publish_content" );
	}

Without a container, the $member->modPermission( "can_future_publish_content" ) is executed code, and this specific function can return a NULL value:

	/**
	 * Get moderator permission
	 *
	 * @param string|null $key	Permission Key to check, or NULL to just test if they have any moderator permissions.
	 * @return	mixed
	 */
	public function modPermission( string $key=NULL ): mixed
	{
		/* Load our permissions */
		$permissions = $this->modPermissions();

		if ( $permissions == FALSE )
		{
			return FALSE;
		}
		
		/* If we have all permissions, return true */
		if ( $permissions === '*' or $key === NULL )
		{
			return TRUE;
		}
				
		/* Otherwise return it */
		return $permissions[$key] ?? NULL;
	}

===

This issue is because the user I'm logged in as is a restricted moderator. I then tried to set it as unrestricted to test if anything changed, and received this new error in ACP instead:

TypeError: IPS\core\extensions\core\ModeratorPermissions\ContentGenerator::onChange(): Argument #2 ($changed) must be of type array, string given, called in /home/nuovo/domains/domain.com/public_html/invision/applications/core/modules/admin/staff/moderators.php on line 527 (0)
#0 /home/nuovo/domains/domain.com/public_html/invision/applications/core/modules/admin/staff/moderators.php(527): IPS\core\extensions\core\ModeratorPermissions\ContentGenerator->onChange()
#1 /home/nuovo/domains/domain.com/public_html/invision/system/Dispatcher/Controller.php(128): IPS\core\modules\admin\staff\moderators->edit()
#2 /home/nuovo/domains/domain.com/public_html/invision/applications/core/modules/admin/staff/moderators.php(74): IPS\Dispatcher\Controller->execute()
#3 /home/nuovo/domains/domain.com/public_html/invision/system/Dispatcher/Dispatcher.php(169): IPS\core\modules\admin\staff\moderators->execute()
#4 /home/nuovo/domains/domain.com/public_html/invision/admin/index.php(15): IPS\Dispatcher->run()
#5 {main}

The moderator was still updated to Unrestricted despite the error, and trying to re-edit it generated no error.

User Feedback

Recommended Comments

teraßyte

Clients

The restricted moderator permissions also caused all sorts of template issues all over the place (userBar, WidgetContainer at the top, Sidebar, WidgetContainer at the bottom, etc.).

Once I edited the moderator and made it unrestricted, (despite the error above) all issues went away.

I believe some code assumes a certain moderator permission always exists while in fact, it's not there.

I'm saying this because this was a test upgrade from version 3.4.9 to 5.0.2 (passing through 4.7.20) and moderator permissions like posting topics in the future were not included in v3.

Esther E.

Invision Community Team

The second exception was already fixed. I'll log the first one.