original_string: protected function _recoverTree($counter = 0, $parentId = null, $level = -1)
      {
          $config = $this->getConfig();
          list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']];
          $primaryKey = $this->_getPrimaryKey();
          $aliasedPrimaryKey = $this->_table->aliasField($primaryKey);
          $order = $config['recoverOrder'] ?: $aliasedPrimaryKey;
  
          $query = $this->_scope($this->_table->query())
              ->select([$aliasedPrimaryKey])
              ->where([$this->_table->aliasField($parent) . ' IS' => $parentId])
              ->order($order)
              ->disableHydration();
  
          $leftCounter = $counter;
          $nextLevel = $level + 1;
          foreach ($query as $row) {
              $counter++;
              $counter = $this->_recoverTree($counter, $row[$primaryKey], $nextLevel);
          }
  
          if ($parentId === null) {
              return $counter;
          }
  
          $fields = [$left => $leftCounter, $right => $counter + 1];
          if ($config['level']) {
              $fields[$config['level']] = $level;
          }
  
          $this->_table->updateAll(
              $fields,
              [$primaryKey => $parentId]
          );
  
          return $counter + 1;
      }
code: protected function _recoverTree($counter = 0, $parentId = null, $level = -1)
      {
          $config = $this->getConfig();
          list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']];
          $primaryKey = $this->_getPrimaryKey();
          $aliasedPrimaryKey = $this->_table->aliasField($primaryKey);
          $order = $config['recoverOrder'] ?: $aliasedPrimaryKey;
  
          $query = $this->_scope($this->_table->query())
              ->select([$aliasedPrimaryKey])
              ->where([$this->_table->aliasField($parent) . ' IS' => $parentId])
              ->order($order)
              ->disableHydration();
  
          $leftCounter = $counter;
          $nextLevel = $level + 1;
          foreach ($query as $row) {
              $counter++;
              $counter = $this->_recoverTree($counter, $row[$primaryKey], $nextLevel);
          }
  
          if ($parentId === null) {
              return $counter;
          }
  
          $fields = [$left => $leftCounter, $right => $counter + 1];
          if ($config['level']) {
              $fields[$config['level']] = $level;
          }
  
          $this->_table->updateAll(
              $fields,
              [$primaryKey => $parentId]
          );
  
          return $counter + 1;
      }
code_tokens: protected function _recoverTree ( $ counter = 0 , $ parentId = null , $ level = - 1 ) { $ config = $ this -> getConfig ( ) ; list ( $ parent , $ left , $ right ) = [ $ config [ 'parent' ] , $ config [ 'left' ] , $ config [ 'right' ] ] ; $ primaryKey = $ this -> _getPrimaryKey ( ) ; $ aliasedPrimaryKey = $ this -> _table -> aliasField ( $ primaryKey ) ; $ order = $ config [ 'recoverOrder' ] ? : $ aliasedPrimaryKey ; $ query = $ this -> _scope ( $ this -> _table -> query ( ) ) -> select ( [ $ aliasedPrimaryKey ] ) -> where ( [ $ this -> _table -> aliasField ( $ parent ) . ' IS' => $ parentId ] ) -> order ( $ order ) -> disableHydration ( ) ; $ leftCounter = $ counter ; $ nextLevel = $ level + 1 ; foreach ( $ query as $ row ) { $ counter ++ ; $ counter = $ this -> _recoverTree ( $ counter , $ row [ $ primaryKey ] , $ nextLevel ) ; } if ( $ parentId === null ) { return $ counter ; } $ fields = [ $ left => $ leftCounter , $ right => $ counter + 1 ] ; if ( $ config [ 'level' ] ) { $ fields [ $ config [ 'level' ] ] = $ level ; } $ this -> _table -> updateAll ( $ fields , [ $ primaryKey => $ parentId ] ) ; return $ counter + 1 ; }
docstring: Recursive method used to recover a single level of the tree
  
  @param int $counter The Last left column value that was assigned
  @param mixed $parentId the parent id of the level to be recovered
  @param int $level Node level
  @return int The next value to use for the left column
docstring_tokens: Recursive method used to recover a single level of the tree