Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' 53152bf and later
Browse files Browse the repository at this point in the history
  • Loading branch information
Giraffaman committed Jan 5, 2024
2 parents 8cdf143 + 87368ac commit 3f3c896
Show file tree
Hide file tree
Showing 25 changed files with 714 additions and 549 deletions.
85 changes: 43 additions & 42 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions core/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@
use FFSPHP\PDO;
use FFSPHP\PDOStatement;

require_once __DIR__ . '/exceptions.php';

enum DatabaseDriverID: string
{
case MYSQL = "mysql";
case PGSQL = "pgsql";
case SQLITE = "sqlite";
}

class DatabaseException extends SCoreException
{
public string $query;
public array $args;

public function __construct(string $msg, string $query, array $args)
{
parent::__construct($msg);
$this->error = $msg;
$this->query = $query;
$this->args = $args;
}
}

/**
* A class for controlled database access
*/
Expand Down Expand Up @@ -158,18 +174,13 @@ public function notify(string $channel, ?string $data = null): void
public function _execute(string $query, array $args = []): PDOStatement
{
try {
$ret = $this->get_db()->execute(
return $this->get_db()->execute(
"-- " . str_replace("%2F", "/", urlencode($_GET['q'] ?? '')). "\n" .
$query,
$args
);
if ($ret === false) {
throw new SCoreException("Query failed", $query);
}
/** @noinspection PhpIncompatibleReturnTypeInspection */
return $ret;
} catch (\PDOException $pdoe) {
throw new SCoreException($pdoe->getMessage(), $query);
throw new DatabaseException($pdoe->getMessage(), $query, $args);
}
}

Expand Down
4 changes: 1 addition & 3 deletions core/exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
*/
class SCoreException extends \RuntimeException
{
public ?string $query;
public string $error;
public int $http_code = 500;

public function __construct(string $msg, ?string $query = null)
public function __construct(string $msg)
{
parent::__construct($msg);
$this->error = $msg;
$this->query = $query;
}
}

Expand Down
16 changes: 11 additions & 5 deletions core/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,6 @@ function _fatal_error(\Exception $e): void
$version = VERSION;
$message = $e->getMessage();
$phpver = phpversion();
$query = is_subclass_of($e, "Shimmie2\SCoreException") ? $e->query : null;
$code = is_subclass_of($e, "Shimmie2\SCoreException") ? $e->http_code : 500;

//$hash = exec("git rev-parse HEAD");
//$h_hash = $hash ? "<p><b>Hash:</b> $hash" : "";
Expand All @@ -646,13 +644,21 @@ function _fatal_error(\Exception $e): void

print("Message: $message\n");

if ($query) {
print("Query: {$query}\n");
if (is_a($e, DatabaseException::class)) {
print("Query: {$e->query}\n");
print("Args: ".var_export($e->args, true)."\n");
}

print("Version: $version (on $phpver)\n");
} else {
$q = $query ? "" : "<p><b>Query:</b> " . html_escape($query);
$query = is_a($e, DatabaseException::class) ? $e->query : null;
$code = is_a($e, SCoreException::class) ? $e->http_code : 500;

$q = "";
if(is_a($e, DatabaseException::class)) {
$q .= "<p><b>Query:</b> " . html_escape($query);
$q .= "<p><b>Args:</b> " . html_escape(var_export($e->args, true));
}
if ($code >= 500) {
error_log("Shimmie Error: $message (Query: $query)\n{$e->getTraceAsString()}");
}
Expand Down
4 changes: 2 additions & 2 deletions ext/cron_uploader/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private function move_uploaded(string $path, string $filename, string $output_su
/**
* Generate the necessary DataUploadEvent for a given image and tags.
*/
private function add_image(string $tmpname, string $filename, string $tags): DataUploadEvent
private function add_image(string $tmpname, string $filename, array $tags): DataUploadEvent
{
$event = add_image($tmpname, $filename, $tags, null);

Expand Down Expand Up @@ -512,7 +512,7 @@ private function generate_image_queue(): \Generator
foreach (new \RecursiveIteratorIterator($ite) as $fullpath => $cur) {
if (!is_link($fullpath) && !is_dir($fullpath) && !$this->is_skippable_file($fullpath)) {
$relativePath = substr($fullpath, strlen($base));
$tags = Tag::implode(path_to_tags($relativePath));
$tags = path_to_tags($relativePath);

yield [
0 => $fullpath,
Expand Down
Loading

0 comments on commit 3f3c896

Please sign in to comment.