From 7e5b98ea3e29ea12b30c13e4e38390faede13560 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 27 Mar 2024 11:49:06 +0800 Subject: [PATCH] MDL-81327 core: Remove unnecessary table filter The \Traversable interface does not define the `valid` method. Furthermore, the `valid` method actually checks that there is a _next_ value, which requires the value already be fetched and waiting. This is not the case for all Iterators. For example the CallbackFilterIterator does not load the initial value until it is requested. It is completely unnecessary to do this check anyway as an invalid Iterator will just not return any values. --- lib/tablelib.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/tablelib.php b/lib/tablelib.php index 8409b5972c8..33e268824c9 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -2048,6 +2048,8 @@ class table_sql extends flexible_table { } /** + * Build the table from the fetched data. + * * Take the data returned from the db_query and go through all the rows * processing each col using either col_{columnname} method or other_cols * method or if other_cols returns NULL then put the data straight into the @@ -2056,18 +2058,13 @@ class table_sql extends flexible_table { * After calling this function, don't forget to call close_recordset. */ public function build_table() { - - if ($this->rawdata instanceof \Traversable && !$this->rawdata->valid()) { - return; - } if (!$this->rawdata) { return; } foreach ($this->rawdata as $row) { $formattedrow = $this->format_row($row); - $this->add_data_keyed($formattedrow, - $this->get_row_class($row)); + $this->add_data_keyed($formattedrow, $this->get_row_class($row)); } }