diff --git a/docs/guides/upgrading.rst b/docs/guides/upgrading.rst index b0646563b5d..b020f9b77c2 100644 --- a/docs/guides/upgrading.rst +++ b/docs/guides/upgrading.rst @@ -12,6 +12,14 @@ See the administrator guides for :doc:`how to upgrade a live site fingerprintCallback($callback); - } else { - // TODO do something about invalid callbacks - $callback = null; + if (!is_callable($callback)) { + $inspector = new \Elgg\Debug\Inspector(); + throw new \RuntimeException('$callback must be a callable function. Given ' . $inspector->describeCallable($callback)); } - } else { - $is_callable = false; + $query_id .= $this->fingerprintCallback($callback); } // MD5 yields smaller mem usage for cache and cleaner logs $hash = md5($query_id); @@ -348,7 +344,7 @@ protected function getResults($query, $callback = null, $single = false) { if ($result = $this->executeQuery("$query", $dblink)) { while ($row = mysql_fetch_object($result)) { - if ($is_callable) { + if ($callback) { $row = call_user_func($callback, $row); } diff --git a/engine/classes/Elgg/Debug/Inspector.php b/engine/classes/Elgg/Debug/Inspector.php index 5e17c3a1d57..b432fe7069d 100644 --- a/engine/classes/Elgg/Debug/Inspector.php +++ b/engine/classes/Elgg/Debug/Inspector.php @@ -344,7 +344,7 @@ public function describeCallable($callable, $file_root = '') { if (is_object($callable)) { return "(" . get_class($callable) . ")->__invoke()"; } - return "(unknown)"; + return print_r($callable, true); } /** diff --git a/engine/tests/phpunit/Elgg/DatabaseTest.php b/engine/tests/phpunit/Elgg/DatabaseTest.php index 0b5431d2591..efaf0e5bc08 100644 --- a/engine/tests/phpunit/Elgg/DatabaseTest.php +++ b/engine/tests/phpunit/Elgg/DatabaseTest.php @@ -95,6 +95,12 @@ public function testFingerprintingOfCallbacks() { $this->assertEquals($uniques, count($prints)); } + public function testInvalidCallbacksThrow() { + $this->setExpectedException('RuntimeException', '$callback must be a callable function. Given blorg!'); + + $this->getDbMock()->getData("SELECT 1", 'blorg!'); + } + private function getFixture($filename) { return dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' .