]> git.mxchange.org Git - friendica.git/commitdiff
Fix errors in Database namespace
authorArt4 <art4@wlabs.de>
Tue, 19 Nov 2024 07:24:27 +0000 (07:24 +0000)
committerArt4 <art4@wlabs.de>
Tue, 19 Nov 2024 07:24:27 +0000 (07:24 +0000)
src/Core/Storage/Type/ExternalResource.php
src/Database/DBStructure.php
src/Database/Database.php
src/Database/PostUpdate.php
src/Database/View.php
src/Factory/Api/Twitter/DirectMessage.php

index b9b67a122ab78e318d883baea4c666448df45140..0345f3ae8e5843ef16da8934fbcf1ea07c7d2162 100644 (file)
@@ -54,16 +54,13 @@ class ExternalResource implements ICanReadFromStorage
                        $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);
                }
-               if (!empty($fetchResult) && $fetchResult->isSuccess()) {
-                       $this->logger->debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => $data->uid, 'url' => $data->url]);
-                       return $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()));
-                       }
+
+               if (!$fetchResult->isSuccess()) {
+                       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();
        }
 
        /**
index 65a9f450eade53465ae6b8c2ca94cf3a8f61cac6..098a47d67543286b78dc0da49e61047381580148 100644 (file)
@@ -275,7 +275,7 @@ class DBStructure
                        $is_new_table = false;
                        $sql3         = "";
                        if (!isset($database[$name])) {
-                               $sql = DbaDefinitionSqlWriter::createTable($name, $structure, $verbose, $action);
+                               $sql = DbaDefinitionSqlWriter::createTable($name, $structure);
                                if ($verbose) {
                                        echo $sql;
                                }
index 1deb45419076fafc3027041c44e0bfdd6d92e2a3..15bb84765aa42b48ee09583201b444fcfefc423b 100644 (file)
@@ -534,6 +534,8 @@ class Database
                        throw new ServiceUnavailableException('The Connection is empty, although connected is set true.');
                }
 
+               $retval = false;
+
                switch ($this->driver) {
                        case self::PDO:
                                // If there are no arguments we use "query"
@@ -1074,6 +1076,8 @@ class Database
         */
        public function lastInsertId(): int
        {
+               $id = 0;
+
                switch ($this->driver) {
                        case self::PDO:
                                $id = $this->connection->lastInsertId();
@@ -1681,6 +1685,8 @@ class Database
                        return false;
                }
 
+               $ret = false;
+
                switch ($this->driver) {
                        case self::PDO:
                                $ret = $stmt->closeCursor();
@@ -1695,8 +1701,6 @@ class Database
                                } elseif ($stmt instanceof mysqli_result) {
                                        $stmt->free();
                                        $ret = true;
-                               } else {
-                                       $ret = false;
                                }
                                break;
                }
@@ -1770,8 +1774,8 @@ class Database
        /**
         * Acquire a lock to prevent a table optimization
         *
-        * @return bool 
-        * @throws LockPersistenceException 
+        * @return bool
+        * @throws LockPersistenceException
         */
        public function acquireOptimizeLock(): bool
        {
@@ -1781,8 +1785,8 @@ class Database
        /**
         * Release the table optimization lock
         *
-        * @return bool 
-        * @throws LockPersistenceException 
+        * @return bool
+        * @throws LockPersistenceException
         */
        public function releaseOptimizeLock(): bool
        {
index 0f0eb12899135ad679b1ac7ec1166c95e10546c9..65c8e98c229e07f4e4c6b68d1e736b4044403fc6 100644 (file)
@@ -284,7 +284,7 @@ class PostUpdate
                }
 
                while ($item = DBA::fetch($items)) {
-                       Tag::storeFromBody($item['uri-id'], $item['body'], '#!@', false);
+                       Tag::storeFromBody($item['uri-id'], $item['body'], '#!@');
                        $id = $item['uri-id'];
                        ++$rows;
                        if ($rows % 1000 == 0) {
@@ -775,11 +775,8 @@ class PostUpdate
 
                while ($photo = DBA::fetch($photos)) {
                        $img = Photo::getImageForPhoto($photo);
-                       if (!empty($img)) {
-                               $md5 = md5($img->asString());
-                       } else {
-                               $md5 = '';
-                       }
+                       $md5 = md5($img->asString());
+
                        DBA::update('photo', ['hash' => $md5], ['id' => $photo['id']]);
                        ++$rows;
                }
@@ -1220,7 +1217,7 @@ class PostUpdate
                        $parts = parse_url($contact['url']);
                        unset($parts['path']);
                        $server = (string)Uri::fromParts($parts);
-               
+
                        DBA::update('contact',
                                ['gsid' => GServer::getID($server, true), 'baseurl' => GServer::cleanURL($server)],
                                ['id' => $contact['id']]);
index dee61428ff316468c7eebdeb13a14850d5c324b3..0d34c3a4bcf9a2edd9f3c9f141556e3556f0d795 100644 (file)
@@ -25,11 +25,11 @@ class View
                foreach (['post-view', 'post-thread-view'] as $view) {
                        if (self::isView($view)) {
                                $sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($view));
-                               if (!empty($sql) && $verbose) {
+                               if ($verbose) {
                                        echo $sql . ";\n";
                                }
 
-                               if (!empty($sql) && $action) {
+                               if ($action) {
                                        DBA::e($sql);
                                }
                        }
index f80bdd85cc4b18200e106d5a9f9e0c7ee41ebb60..fd276bd205452d6c72cdb9c7e89596c2c4eefcb7 100644 (file)
@@ -48,6 +48,9 @@ class DirectMessage extends BaseFactory
                        throw new HTTPException\NotFoundException('Direct message with ID ' . $mail . ' not found.');
                }
 
+               $title = '';
+               $text  = '';
+
                if (!empty($text_mode)) {
                        $title = $mail['title'];
                        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);
                        }
                } else {
-                       $title = '';
                        $text  = $mail['title'] . "\n" . HTML::toPlaintext(BBCode::convertForUriId($mail['uri-id'], $mail['body'], BBCode::TWITTER_API), 0);
                }