CMS MADE SIMPLE FORGE

CMS Made Simple Core

 

[#12618] HasChildren() in class.ContentBase.php in 2.2.16 is broken

avatar
Created By: R Hamster (Hammy)
Date Submitted: Tue May 30 10:48:59 -0400 2023

Assigned To:
Version: 2.2.16
CMSMS Version: 2.2.16
Severity: Minor
Resolution: Fixed
State: Open
Summary:
HasChildren() in class.ContentBase.php in 2.2.16 is broken
Detailed Description:
Here's HasChildren() in class.ContentBase.php in 2.2.16 


  /**
   * Method to indicate whether the current page has children.
   *
   * @param bool $activeonly Should we test only for active children.
   * @return bool
   */
  public function HasChildren($activeonly = false)
  {
      $node = ContentOperations::get_instance()->quickfind_node_by_id($id);
      if( !$node->has_children() ) return false;
      if( $activeonly == false) return true;

      $children = $node->get_children();
      if( $children ) {
          for( $i = 0, $n = count($children); $i < $n; $i++ ) {
              $content = $children[$i]->getContent();
              if( $content->Active() ) return true;
          }
      }

      return false;
  }



But $id (L2067) is not present in this function. So function breaks.

Compare with 1.12

	
  /**
   * Method to indicate wether the current page has children.
   *
   * @param boolean should we test only for active children.
   * @return booelan
   */
  public function HasChildren($activeonly = false)
  {
      $hm = cmsms()->GetHierarchyManager();
      $node = $hm->getNodeById($this->mId);
      if( !$node->has_children() ) return false;
      if( $activeonly == false) return true;

      $children = $node->get_children();
      if( $children )
      {
          for( $i = 0; $i < count($children); $i++ )
          {
              $content = $children[$i]->getContent();
              if( $content->Active() ) return true;
          }
      }

      return false;
   }


Thanks.


History

Comments
avatar
Date: 2023-05-30 13:59
Posted By: Fernando Morgado (JoMorg)

fixed in svn, thanks
      
avatar
Date: 2023-05-31 20:08
Posted By: tom (tomphantoo)

Use quickfind_node_by_id($this->mId) in next release
      
avatar
Date: 2023-06-05 15:47
Posted By: Fernando Morgado (JoMorg)

Notice: I'm re-opening this BR until we release and confirm the fix, thanks
      
avatar
Date: 2023-06-06 07:55
Posted By: R Hamster (Hammy)

I've retested, and confirm the fix in svn fixes the PHP Fatal error
      
Updates

Updated: 2023-06-05 15:47
state: Closed => Open

Updated: 2023-05-31 20:08
state: Open => Closed

Updated: 2023-05-30 13:59
resolution_id: => 7
severity_id: 2 => 3