Skip to content

Commit

Permalink
Allowing fault tolerance in absence of open graph table to help with …
Browse files Browse the repository at this point in the history
…4.3 upgrades, moving some errors to exceptions for catching and moving some warnings to errors.
  • Loading branch information
timbuckingham committed Dec 20, 2018
1 parent 7ce42bc commit aa44faf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 6 additions & 2 deletions core/inc/bigtree/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,12 @@ public static function getNavId($path,$previewing = false) {
public static function getOpenGraph($table, $id) {
global $bigtree;

$og = SQL::fetch("SELECT * FROM bigtree_open_graph WHERE `table` = ? AND `entry` = ?", $table, $id);

try {
$og = SQL::fetch("SELECT * FROM bigtree_open_graph WHERE `table` = ? AND `entry` = ?", $table, $id);
} catch (Exception $e) {
$og = null;
}

if (!$og) {
return [
"title" => "",
Expand Down
16 changes: 8 additions & 8 deletions core/inc/bigtree/sql-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __call($method, $arguments) {
return call_user_func_array([$this, "_local_rows"], $arguments);
}

trigger_error("Invalid method called on BigTree\\SQL: $method", E_USER_WARNING);
trigger_error("Invalid method called on BigTree\\SQL: $method", E_USER_ERROR);

return null;
}
Expand All @@ -56,7 +56,7 @@ public static function __callStatic($method, $arguments) {
return call_user_func_array("static::_static_rows", $arguments);
}

trigger_error("Invalid static method called on BigTree\\SQL: $method", E_USER_WARNING);
trigger_error("Invalid static method called on BigTree\\SQL: $method", E_USER_ERROR);

return null;
}
Expand Down Expand Up @@ -910,7 +910,7 @@ public function _local_fetch() {
$last_query = htmlspecialchars($last_query);
}

trigger_error("SQL::fetch called on invalid query resource. The most likely cause is an invalid query call. Last error returned was: $last_query", E_USER_ERROR);
throw new Exception("SQL::fetch called on invalid query resource. The most likely cause is an invalid query call. Last error returned was: $last_query");

return null;
} else {
Expand Down Expand Up @@ -956,7 +956,7 @@ public function _local_fetchAll() {
$last_query = htmlspecialchars($last_query);
}

trigger_error("SQL::fetchAll called on invalid query resource. The most likely cause is an invalid query call. Last error returned was: $last_query", E_USER_ERROR);
throw new Exception("SQL::fetchAll called on invalid query resource. The most likely cause is an invalid query call. Last error returned was: $last_query");

return null;
} else {
Expand Down Expand Up @@ -1010,7 +1010,7 @@ public function _local_fetchAllSingle() {
$last_query = htmlspecialchars($last_query);
}

trigger_error("SQL::fetchAllSingle called on invalid query resource. The most likely cause is an invalid query call. Last error returned was: $last_query", E_USER_ERROR);
throw new Exception("SQL::fetchAllSingle called on invalid query resource. The most likely cause is an invalid query call. Last error returned was: $last_query");

return null;
} else {
Expand Down Expand Up @@ -1064,7 +1064,7 @@ public function _local_fetchSingle() {
$last_query = htmlspecialchars($last_query);
}

trigger_error("SQL::fetchSingle called on invalid query resource. The most likely cause is an invalid query call. Last error returned was: $last_query", E_USER_ERROR);
throw new Exception("SQL::fetchSingle called on invalid query resource. The most likely cause is an invalid query call. Last error returned was: $last_query");

return null;
} else {
Expand Down Expand Up @@ -1094,7 +1094,7 @@ public static function _static_fetchSingle() {

public static function insert($table, $values) {
if (!count($values)) {
trigger_error("SQL::inserts expects a non-empty array as its second parameter");
trigger_error("SQL::inserts expects a non-empty array as its second parameter", E_USER_ERROR);

return null;
}
Expand Down Expand Up @@ -1528,7 +1528,7 @@ public static function unique($table, $field, $value, $id = null, $inverse = fal

public static function update($table, $id, $values) {
if (!is_array($values) || !count($values)) {
trigger_error("SQL::update expects a non-empty array as its third parameter");
trigger_error("SQL::update expects a non-empty array as its third parameter", E_USER_ERROR);

return false;
}
Expand Down

0 comments on commit aa44faf

Please sign in to comment.