Fix errors in Database namespace

This commit is contained in:
Art4 2024-11-19 07:24:27 +00:00
parent 17e5ba715e
commit a5f623a86a
6 changed files with 26 additions and 26 deletions

View file

@ -54,16 +54,13 @@ class ExternalResource implements ICanReadFromStorage
$this->logger->notice('URL is invalid', ['url' => $data->url, 'error' => $exception]); $this->logger->notice('URL is invalid', ['url' => $data->url, 'error' => $exception]);
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception); throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
} }
if (!empty($fetchResult) && $fetchResult->isSuccess()) {
$this->logger->debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => $data->uid, 'url' => $data->url]); if (!$fetchResult->isSuccess()) {
return $fetchResult->getBodyString(); throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBodyString()));
} else {
if (empty($fetchResult)) {
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference));
} else {
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBodyString()));
}
} }
$this->logger->debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => $data->uid, 'url' => $data->url]);
return $fetchResult->getBodyString();
} }
/** /**

View file

@ -275,7 +275,7 @@ class DBStructure
$is_new_table = false; $is_new_table = false;
$sql3 = ""; $sql3 = "";
if (!isset($database[$name])) { if (!isset($database[$name])) {
$sql = DbaDefinitionSqlWriter::createTable($name, $structure, $verbose, $action); $sql = DbaDefinitionSqlWriter::createTable($name, $structure);
if ($verbose) { if ($verbose) {
echo $sql; echo $sql;
} }

View file

@ -534,6 +534,8 @@ class Database
throw new ServiceUnavailableException('The Connection is empty, although connected is set true.'); throw new ServiceUnavailableException('The Connection is empty, although connected is set true.');
} }
$retval = false;
switch ($this->driver) { switch ($this->driver) {
case self::PDO: case self::PDO:
// If there are no arguments we use "query" // If there are no arguments we use "query"
@ -1074,6 +1076,8 @@ class Database
*/ */
public function lastInsertId(): int public function lastInsertId(): int
{ {
$id = 0;
switch ($this->driver) { switch ($this->driver) {
case self::PDO: case self::PDO:
$id = $this->connection->lastInsertId(); $id = $this->connection->lastInsertId();
@ -1681,6 +1685,8 @@ class Database
return false; return false;
} }
$ret = false;
switch ($this->driver) { switch ($this->driver) {
case self::PDO: case self::PDO:
$ret = $stmt->closeCursor(); $ret = $stmt->closeCursor();
@ -1695,8 +1701,6 @@ class Database
} elseif ($stmt instanceof mysqli_result) { } elseif ($stmt instanceof mysqli_result) {
$stmt->free(); $stmt->free();
$ret = true; $ret = true;
} else {
$ret = false;
} }
break; break;
} }

View file

@ -284,7 +284,7 @@ class PostUpdate
} }
while ($item = DBA::fetch($items)) { while ($item = DBA::fetch($items)) {
Tag::storeFromBody($item['uri-id'], $item['body'], '#!@', false); Tag::storeFromBody($item['uri-id'], $item['body'], '#!@');
$id = $item['uri-id']; $id = $item['uri-id'];
++$rows; ++$rows;
if ($rows % 1000 == 0) { if ($rows % 1000 == 0) {
@ -775,11 +775,8 @@ class PostUpdate
while ($photo = DBA::fetch($photos)) { while ($photo = DBA::fetch($photos)) {
$img = Photo::getImageForPhoto($photo); $img = Photo::getImageForPhoto($photo);
if (!empty($img)) { $md5 = md5($img->asString());
$md5 = md5($img->asString());
} else {
$md5 = '';
}
DBA::update('photo', ['hash' => $md5], ['id' => $photo['id']]); DBA::update('photo', ['hash' => $md5], ['id' => $photo['id']]);
++$rows; ++$rows;
} }

View file

@ -25,11 +25,11 @@ class View
foreach (['post-view', 'post-thread-view'] as $view) { foreach (['post-view', 'post-thread-view'] as $view) {
if (self::isView($view)) { if (self::isView($view)) {
$sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($view)); $sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($view));
if (!empty($sql) && $verbose) { if ($verbose) {
echo $sql . ";\n"; echo $sql . ";\n";
} }
if (!empty($sql) && $action) { if ($action) {
DBA::e($sql); DBA::e($sql);
} }
} }

View file

@ -48,6 +48,9 @@ class DirectMessage extends BaseFactory
throw new HTTPException\NotFoundException('Direct message with ID ' . $mail . ' not found.'); throw new HTTPException\NotFoundException('Direct message with ID ' . $mail . ' not found.');
} }
$title = '';
$text = '';
if (!empty($text_mode)) { if (!empty($text_mode)) {
$title = $mail['title']; $title = $mail['title'];
if ($text_mode == 'html') { if ($text_mode == 'html') {
@ -56,7 +59,6 @@ class DirectMessage extends BaseFactory
$text = HTML::toPlaintext(BBCode::convertForUriId($mail['uri-id'], $mail['body'], BBCode::TWITTER_API), 0); $text = HTML::toPlaintext(BBCode::convertForUriId($mail['uri-id'], $mail['body'], BBCode::TWITTER_API), 0);
} }
} else { } else {
$title = '';
$text = $mail['title'] . "\n" . HTML::toPlaintext(BBCode::convertForUriId($mail['uri-id'], $mail['body'], BBCode::TWITTER_API), 0); $text = $mail['title'] . "\n" . HTML::toPlaintext(BBCode::convertForUriId($mail['uri-id'], $mail['body'], BBCode::TWITTER_API), 0);
} }