Jump to content


Photo

Empty IN Clause when viewing blogs


blogFunctions::rebuildMyBlogsCache()

if all of the returned blogs are disabled we can end up with an empty IN clause.

$this->DB->build( array('select' => 'blog_id, count(*) as entries, SUM(entry_num_comments) as comments', 'from' => 'blog_entries', 'where' => 'blog_id IN (' . implode( ',', array_keys( $blogs ) ) . ')', 'group' => 'blog_id') );

we need to check for a populated array here.

Status: Fixed
Version: 2.5.2
Fixed In: 2.5.2


1 Comments

I have noticed a few tickets on this already and also a duplicate bug report, we've gone ahead and rebuilt the package with this fix. For those that upgraded to Blog 2.5.2 before this reply you can overwrite the old files with the new ones or apply this manual fix below.


Open the file "\admin\applications_addon\ips\blog\sources\classes\blogFunctions.php" and find (lines 1198-1208):
   /* Get entries and comments */
   $this->DB->build( array('select' => 'blog_id, count(*) as entries, SUM(entry_num_comments) as comments', 'from' => 'blog_entries', 'where' => 'blog_id IN (' . implode( ',', array_keys( $blogs ) ) . ')', 'group' => 'blog_id') );
   $this->DB->execute();
   while( $row = $this->DB->fetch() )
   {
    if ( isset($blogs[ $row['blog_id'] ]) )
    {
	 $blogs[ $row['blog_id'] ]['num_entries']	   = $row['entries'];
	 $blogs[ $row['blog_id'] ]['blog_num_comments'] = $row['comments'];
    }
   }

replace with:
   /* Get entries and comments */
   if ( count($blogs) )
   {
    $this->DB->build( array('select' => 'blog_id, count(*) as entries, SUM(entry_num_comments) as comments', 'from' => 'blog_entries', 'where' => 'blog_id IN (' . implode( ',', array_keys( $blogs ) ) . ')', 'group' => 'blog_id') );
    $this->DB->execute();
    while( $row = $this->DB->fetch() )
    {
	 if ( isset($blogs[ $row['blog_id'] ]) )
	 {
	  $blogs[ $row['blog_id'] ]['num_entries']	   = $row['entries'];
	  $blogs[ $row['blog_id'] ]['blog_num_comments'] = $row['comments'];
	 }
    }
   }