Jump to content

[BUG 4.7.18] Moving all images to another category throws a read property "album_id" on null error


Recommended Posts

Posted (edited)

This happens when the setLastComment function is called on a category that doesn't have any more images/albums in it:

Whoops\Exception\ErrorException: Attempt to read property "album_id" on null (2)
#0 \applications\gallery\sources\Category\Category.php(625): Whoops\Run->handleError(2, 'Attempt to read...', 'C:\\wamp64\\www\\d...', 625)
#1 \applications\gallery\sources\Category\Category.php(580): IPS\gallery\_Category->setLastImage(NULL)
#2 \system\Node\Model.php(1084): IPS\gallery\_Category->_setLastComment(NULL, NULL)

 

The setLastComment() function in turns calls setLastImage() which contains this code:

Quote
	/**
	 * Set last image data
	 *
	 * @param	\IPS\gallery\Image|NULL	$image	The latest image or NULL to work it out
	 * @return	void
	 */
	public function setLastImage( \IPS\gallery\Image $image=NULL )
	{
		/* Make sure the image is actually the latest */
		if( $image !== null and $image->date < $this->last_img_date )
		{
			$image = null;
		}

		/* If we have one, just use it */
		if( $image !== null )
		{
			$this->last_img_date = $image->date;
			$this->last_img_id = $image->id;
		}
		else
		{
			try
			{
				$result	= \IPS\Db::i()->select( '*', 'gallery_images', array( 'image_category_id=? AND image_approved=1 AND ( image_album_id = 0 OR album_type NOT IN ( 2, 3 ) )', $this->id ), 'image_date DESC', 1 )->join(
					'gallery_albums',
					"image_album_id=album_id"
				)->first();

				$image	= \IPS\gallery\Image::constructFromData( $result );
				$this->last_img_id = $image->id;
				$this->last_img_date = $image->date;
			}
			catch ( \UnderflowException $e )
			{
				$this->last_img_id		= 0;
				$this->last_img_date	= 0;
			}
		}

		$this->save();

		if( $image->album_id )
		{
			$album = isset( $result ) ? \IPS\gallery\Album::constructFromData( $result ) : $image->directContainer();
			$album->setLastImage( $image );
			$album->save();
		}
	}

 

If no image is passed to the function, the code tries to load the last image in it. However, when there is no image the $image variable remains NULL and causes the error to be thrown. The code after the save() call needs a simple check to see if the variable is set before trying to load the album_id value:

		if( $image !== null AND $image->album_id )
Edited by teraßyte
  • Recently Browsing   0 members

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