X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPost.php;h=2e8bbe22e3650fdc7ffd265f5c3428d37b2b608d;hb=f23ecaff6af1982112469f90d6bcdf0408b0f22e;hp=770ab083178f41b3ee8d3a14021bbb433581ca33;hpb=be8251ef0ca39376745dd0ab298208fb41395cce;p=friendica.git diff --git a/src/Model/Post.php b/src/Model/Post.php index 770ab08317..2e8bbe22e3 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -23,7 +23,6 @@ namespace Friendica\Model; use BadMethodCallException; use Friendica\Core\Logger; -use Friendica\Core\System; use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; @@ -36,10 +35,10 @@ class Post * * @param integer $uri_id * @param array $fields - * @return int ID of inserted post + * @return bool Success of the insert process * @throws \Exception */ - public static function insert(int $uri_id, array $data = []): int + public static function insert(int $uri_id, array $data = []): bool { if (empty($uri_id)) { throw new BadMethodCallException('Empty URI_id'); @@ -50,11 +49,7 @@ class Post // Additionally assign the key fields $fields['uri-id'] = $uri_id; - if (!DBA::insert('post', $fields, Database::INSERT_IGNORE)) { - return 0; - } - - return DBA::lastInsertId(); + return DBA::insert('post', $fields, Database::INSERT_IGNORE); } /** @@ -453,12 +448,10 @@ class Post AND (NOT `causer-blocked` OR `causer-id` = ? OR `causer-id` IS NULL) AND NOT `contact-blocked` AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?))) OR `self` OR `contact-uid` = ?) - AND NOT `" . $view . "`.`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `uid` = ? AND `hidden`) - AND NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked` AND `cid` = `author-id`) - AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked` AND `cid` = `owner-id`) - AND NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `author-id`) - AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `owner-id`)", - 0, Contact::SHARING, Contact::FRIEND, 0, $uid, $uid, $uid, $uid, $uid]); + AND NOT EXISTS(SELECT `uri-id` FROM `post-user` WHERE `uid` = ? AND `uri-id` = " . DBA::quoteIdentifier($view) . ".`uri-id` AND `hidden`) + AND NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` IN (`author-id`, `owner-id`) AND (`blocked` OR `ignored`)) + AND NOT EXISTS(SELECT `gsid` FROM `user-gserver` WHERE `uid` = ? AND `gsid` IN (`author-gsid`, `owner-gsid`, `causer-gsid`) AND `ignored`)", + 0, Contact::SHARING, Contact::FRIEND, 0, $uid, $uid, $uid]); $select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected)); @@ -503,6 +496,23 @@ class Post return self::selectViewForUser('post-view', $uid, $selected, $condition, $params); } + /** + * Select rows from the post-timeline-view view for a given user + * This function is used for API calls. + * + * @param integer $uid User ID + * @param array $selected Array of selected fields, empty for all + * @param array $condition Array of fields for condition + * @param array $params Array of several parameters + * + * @return boolean|object + * @throws \Exception + */ + public static function selectTimelineForUser(int $uid, array $selected = [], array $condition = [], array $params = []) + { + return self::selectViewForUser('post-timeline-view', $uid, $selected, $condition, $params); + } + /** * Select rows from the post-thread-user-view view for a given user * @@ -600,7 +610,7 @@ class Post { $affected = 0; - Logger::info('Start Update', ['fields' => $fields, 'condition' => $condition, 'uid' => DI::userSession()->getLocalUserId(),'callstack' => System::callstack(10)]); + Logger::info('Start Update', ['fields' => $fields, 'condition' => $condition, 'uid' => DI::userSession()->getLocalUserId()]); // Don't allow changes to fields that are responsible for the relation between the records unset($fields['id']);