]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/Content.php
Merge pull request #12674 from nupplaphil/bug/config_typesafe
[friendica.git] / src / Model / Post / Content.php
index 5d9aaf62d637249c6fe82d2aef902cce633b9f00..0694b3a377b7fb8cb262c43a093f15ddfed2e23c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -26,6 +26,7 @@ use Friendica\Core\Protocol;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\Database\DBStructure;
+use Friendica\DI;
 use Friendica\Model\Post;
 
 class Content
@@ -44,11 +45,7 @@ class Content
                        throw new BadMethodCallException('Empty URI_id');
                }
 
-               if (DBA::exists('post-content', ['uri-id' => $uri_id])) {
-                       return false;
-               }
-
-               $fields = DBStructure::getFieldsForTable('post-content', $data);
+               $fields = DI::dbaDefinition()->truncateFieldsForTable('post-content', $data);
 
                // Additionally assign the key fields
                $fields['uri-id'] = $uri_id;
@@ -71,7 +68,7 @@ class Content
                        throw new BadMethodCallException('Empty URI_id');
                }
 
-               $fields = DBStructure::getFieldsForTable('post-content', $data);
+               $fields = DI::dbaDefinition()->truncateFieldsForTable('post-content', $data);
 
                // Remove the key fields
                unset($fields['uri-id']);
@@ -113,8 +110,8 @@ class Content
        public static function getURIIdListBySearch(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0)
        {
                $condition = ["`uri-id` IN (SELECT `uri-id` FROM `post-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE))
-                       AND (NOT `private` OR (`private` AND `uid` = ?)) AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
-                       $search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
+                       AND (`uid` = ? OR (`uid` = ? AND NOT `global`)) AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
+                       str_replace('@', ' ', $search), 0, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
 
                if (!empty($last_uriid)) {
                        $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]);
@@ -122,7 +119,6 @@ class Content
 
                $params = [
                        'order' => ['uri-id' => true],
-                       'group_by' => ['uri-id'],
                        'limit' => [$start, $limit]
                ];
 
@@ -140,8 +136,8 @@ class Content
        public static function countBySearch(string $search, int $uid = 0)
        {
                $condition = ["`uri-id` IN (SELECT `uri-id` FROM `post-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE))
-                       AND (NOT `private` OR (`private` AND `uid` = ?)) AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
-                       $search, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
+                       AND (`uid` = ? OR (`uid` = ? AND NOT `global`)) AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
+                       str_replace('@', ' ', $search), 0, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
                return Post::count($condition);
        }
 }