From 69db696ab1b5d505394fafae1221d0da844a317f Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Jul 2018 05:29:06 +0000 Subject: [PATCH] Improve test behaviour --- include/dba.php | 2 ++ src/App.php | 12 +++++++++--- src/Object/Image.php | 29 +++++++++++++++-------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/include/dba.php b/include/dba.php index 061f5399c7..b95589970e 100644 --- a/include/dba.php +++ b/include/dba.php @@ -955,6 +955,8 @@ class dba { * @return boolean Was the command executed successfully? */ public static function rollback() { + $ret = false; + switch (self::$driver) { case 'pdo': if (!self::$db->inTransaction()) { diff --git a/src/App.php b/src/App.php index 92ff057138..a2bdd03df6 100644 --- a/src/App.php +++ b/src/App.php @@ -412,11 +412,17 @@ class App public function set_baseurl($url) { $parsed = @parse_url($url); + $hostname = ''; if (x($parsed)) { - $this->scheme = $parsed['scheme']; + if (!empty($parsed['scheme'])) { + $this->scheme = $parsed['scheme']; + } + + if (!empty($parsed['host'])) { + $hostname = $parsed['host']; + } - $hostname = $parsed['host']; if (x($parsed, 'port')) { $hostname .= ':' . $parsed['port']; } @@ -432,7 +438,7 @@ class App $this->hostname = Config::get('config', 'hostname'); } - if (!isset($this->hostname) || ( $this->hostname == '')) { + if (!isset($this->hostname) || ($this->hostname == '')) { $this->hostname = $hostname; } } diff --git a/src/Object/Image.php b/src/Object/Image.php index 9621badaba..7e6b758f1c 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -781,22 +781,23 @@ class Image $img_str = Network::fetchUrl($url, true, $redirects, 4); $filesize = strlen($img_str); - // The tests are failing with an read error. This can be caused by memory shortage - // See https://stackoverflow.com/questions/10175758/getimagesize-read-error - // So we use the alternate method instead - //if (function_exists("getimagesizefromstring")) { - // $data = getimagesizefromstring($img_str); - //} else { - $tempfile = tempnam(get_temppath(), "cache"); + try { + if (function_exists("getimagesizefromstring")) { + $data = getimagesizefromstring($img_str); + } else { + $tempfile = tempnam(get_temppath(), "cache"); - $a = get_app(); - $stamp1 = microtime(true); - file_put_contents($tempfile, $img_str); - $a->save_timestamp($stamp1, "file"); + $a = get_app(); + $stamp1 = microtime(true); + file_put_contents($tempfile, $img_str); + $a->save_timestamp($stamp1, "file"); - $data = getimagesize($tempfile); - unlink($tempfile); - //} + $data = getimagesize($tempfile); + unlink($tempfile); + } + } catch (Exception $e) { + return false; + } if ($data) { $data["size"] = $filesize;