Merge pull request #9803 from annando/post

New post class in the rest of the classes
This commit is contained in:
Hypolite Petovan 2021-01-16 08:26:05 -05:00 committed by GitHub
commit c1226bff07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 33 additions and 20 deletions

View File

@ -27,6 +27,7 @@ use Friendica\Content\Text\BBCode;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Verb;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
@ -60,7 +61,7 @@ class Status extends BaseFactory
*/
public function createFromUriId(int $uriId, $uid = 0)
{
$item = Item::selectFirst([], ['uri-id' => $uriId, 'uid' => $uid]);
$item = Post::selectFirst([], ['uri-id' => $uriId, 'uid' => $uid]);
if (!$item) {
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . 'not found' . ($uid ? ' for user ' . $uid : '.'));
}
@ -93,7 +94,7 @@ class Status extends BaseFactory
if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
$reshare = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
$reshared_item = Item::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'], 'uid' => $uid]);
$reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'], 'uid' => $uid]);
$item['title'] = $reshared_item['title'] ?? $item['title'];
$item['body'] = $reshared_item['body'] ?? $item['body'];
} else {

View File

@ -40,7 +40,7 @@ class Source extends BaseAdmin
$item_id = '';
$terms = [];
if (!empty($guid)) {
$item = Model\Item::selectFirst(['id', 'uri-id', 'guid', 'uri'], ['guid' => $guid]);
$item = Model\Post::selectFirst(['id', 'uri-id', 'guid', 'uri'], ['guid' => $guid]);
if ($item) {
$conversation = Model\Conversation::getByItemUri($item['uri']);

View File

@ -35,6 +35,7 @@ use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Network\HTTPException;
@ -237,7 +238,7 @@ class Community extends BaseModule
}
if (!empty($_GET['item'])) {
$item = Item::selectFirst(['parent'], ['id' => $_GET['item']]);
$item = Post::selectFirst(['parent'], ['id' => $_GET['item']]);
self::$item_id = $item['parent'] ?? 0;
} else {
self::$item_id = 0;

View File

@ -17,6 +17,7 @@ use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Module\Contact as ModuleContact;
@ -215,7 +216,7 @@ class Network extends BaseModule
return;
}
$unseen = Item::exists($condition);
$unseen = Post::exists($condition);
if ($unseen) {
/// @todo handle huge "unseen" updates in the background to avoid timeout errors

View File

@ -24,6 +24,7 @@ namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
/**
@ -46,7 +47,7 @@ class ItemBody extends BaseModule
throw new HTTPException\NotFoundException(DI::l10n()->t('Item not found.'));
}
$item = Item::selectFirst(['body'], ['uid' => local_user(), 'id' => $itemId]);
$item = Post::selectFirst(['body'], ['uid' => local_user(), 'id' => $itemId]);
if (!empty($item)) {
if (DI::mode()->isAjax()) {

View File

@ -26,6 +26,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Diaspora;
@ -55,10 +56,10 @@ class Fetch extends BaseModule
'event-id', 'resource-id', 'author-link', 'author-avatar', 'author-name', 'plink', 'owner-link', 'uri-id'
];
$condition = ['wall' => true, 'private' => [Item::PUBLIC, Item::UNLISTED], 'guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
$item = Item::selectFirst($fields, $condition);
$item = Post::selectFirst($fields, $condition);
if (empty($item)) {
$condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
$item = Item::selectFirst(['author-link'], $condition);
$item = Post::selectFirst(['author-link'], $condition);
if (!empty($item["author-link"])) {
$parts = parse_url($item["author-link"]);
if (empty($parts["scheme"]) || empty($parts["host"])) {

View File

@ -29,6 +29,7 @@ use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
use Friendica\Util\Strings;
@ -55,7 +56,7 @@ class Like extends BaseModule
$itemId = (($app->argc > 1) ? Strings::escapeTags(trim($app->argv[1])) : 0);
if (in_array($verb, ['announce', 'unannounce'])) {
$item = Item::selectFirst(['network'], ['id' => $itemId]);
$item = Post::selectFirst(['network'], ['id' => $itemId]);
if ($item['network'] == Protocol::DIASPORA) {
self::performDiasporaReshare($itemId);
}
@ -86,7 +87,7 @@ class Like extends BaseModule
private static function performDiasporaReshare(int $itemId)
{
$fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Item::selectFirst($fields, ['id' => $itemId, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
$item = Post::selectFirst($fields, ['id' => $itemId, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
if (!DBA::isResult($item) || ($item['body'] == '')) {
return;
}

View File

@ -28,6 +28,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature;
@ -68,7 +69,7 @@ class Objects extends BaseModule
}
}
$item = Item::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid', 'gravity'],
$item = Post::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid', 'gravity'],
['uri-id' => $itemuri['id']], ['order' => ['origin' => true]]);
if (!DBA::isResult($item)) {

View File

@ -7,6 +7,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Group;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
/**
@ -27,7 +28,7 @@ class PermissionTooltip extends \Friendica\BaseModule
$condition = ['id' => $referenceId];
if ($type == 'item') {
$fields = ['uid', 'psid', 'private'];
$model = Item::selectFirst($fields, $condition);
$model = Post::selectFirst($fields, $condition);
} else {
$fields = ['uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
$model = DBA::selectFirst($type, $fields, $condition);

View File

@ -30,6 +30,7 @@ use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Post\Category;
use Friendica\Model\Profile as ProfileModel;
use Friendica\Model\User;
@ -206,7 +207,7 @@ class Status extends BaseProfile
}
if ($is_owner) {
$unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
$unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
if ($unseen) {
Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
}

View File

@ -31,6 +31,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
use Friendica\Util\Strings;
@ -314,7 +315,7 @@ class Acl extends BaseModule
if ($conv_id) {
// In multi threaded posts the conv_id is not the parent of the whole thread
$parent_item = Item::selectFirst(['parent'], ['id' => $conv_id]);
$parent_item = Post::selectFirst(['parent'], ['id' => $conv_id]);
if (DBA::isResult($parent_item)) {
$conv_id = $parent_item['parent'];
}

View File

@ -35,6 +35,7 @@ use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\ItemContent;
use Friendica\Model\Post;
use Friendica\Model\Tag;
use Friendica\Module\BaseSearch;
use Friendica\Network\HTTPException;
@ -288,7 +289,7 @@ class Index extends BaseSearch
}
if (!empty($item_id)) {
$item = Item::selectFirst(['guid'], ['id' => $item_id]);
$item = Post::selectFirst(['guid'], ['id' => $item_id]);
if (DBA::isResult($item)) {
DI::baseUrl()->redirect('display/' . $item['guid']);
}

View File

@ -5,6 +5,7 @@ namespace Friendica\Module\Update;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Module\Conversation\Network as NetworkModule;
class Network extends NetworkModule
@ -23,7 +24,7 @@ class Network extends NetworkModule
if (!DI::pConfig()->get($profile_uid, 'system', 'no_auto_update') || ($_GET['force'] == 1)) {
if (!empty($_GET['item'])) {
$item = Item::selectFirst(['parent'], ['id' => $_GET['item']]);
$item = Post::selectFirst(['parent'], ['id' => $_GET['item']]);
$parent = $item['parent'] ?? 0;
} else {
$parent = 0;

View File

@ -22,12 +22,12 @@
namespace Friendica\Module\Update;
use Friendica\BaseModule;
use Friendica\Content\Pager;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Profile as ProfileModel;
use Friendica\Network\HTTPException\ForbiddenException;
use Friendica\Util\DateTimeFormat;
@ -111,7 +111,7 @@ class Profile extends BaseModule
}
if ($is_owner) {
$unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
$unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
if ($unseen) {
Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
}

View File

@ -33,6 +33,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Post as PostModel;
use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Protocol\Activity;
@ -212,7 +213,7 @@ class Post
if (!$origin) {
/// @todo This shouldn't be done as query here, but better during the data creation.
// it is now done here, since during the RC phase we shouldn't make to intense changes.
$parent = Item::selectFirst(['origin'], ['id' => $item['parent']]);
$parent = PostModel::selectFirst(['origin'], ['id' => $item['parent']]);
if (DBA::isResult($parent)) {
$origin = $parent['origin'];
}
@ -875,7 +876,7 @@ class Post
return '';
}
$item = Item::selectFirst(['author-addr', 'uri-id'], ['id' => $this->getId()]);
$item = PostModel::selectFirst(['author-addr', 'uri-id'], ['id' => $this->getId()]);
if (!DBA::isResult($item) || empty($item['author-addr'])) {
// Should not happen
return '';