wilr / silverstripe-googlesitemaps

Google Sitemaps module for the SilverStripe CMS
BSD 3-Clause "New" or "Revised" License
74 stars 95 forks source link

response was array, need to check boolean value #179

Closed td204 closed 1 year ago

td204 commented 3 years ago

Fixes #166

canIncludeInGoogleSitemap() returns an array, with one item which can be false, e.g. $array[0] = false;

GoogleSitemap.php checks as follows:

                if ($obj->canIncludeInGoogleSitemap()) {
                    $output->push($obj);
                }

Which will always return true if it is an array with count > 0, regardless of the value in first item.

wilr commented 3 years ago

@td204 Not sure I follow the fix however. I think a better solution if I understand your issue is to use if (min($obj->canIncludeInGoogleSitemap())) { which will return the minimum value (if it is an array rather than boolean).

td204 commented 3 years ago

min() is triggering a E_WARNING on an empty array. In our use case there is always only one item in the array, but as you mention it I believe this might not be the best way, possibly multiple values from multiple extensions can be in the array? min() would work, but I worry about the empty arrays. An extra check in this if statement looks like triggering unnecessary performance issues.

wilr commented 3 years ago

That might be solved with a if (!empty($var) && min($var)) {