mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-06 18:31:05 +00:00
fix(fediverse): set model instances as non shared to prevent overlapping
This commit is contained in:
parent
d9d139eefa
commit
91128fad7a
@ -198,7 +198,7 @@ class Podcast extends Entity
|
|||||||
|
|
||||||
if ($this->actor === null) {
|
if ($this->actor === null) {
|
||||||
// @phpstan-ignore-next-line
|
// @phpstan-ignore-next-line
|
||||||
$this->actor = model(ActorModel::class)
|
$this->actor = model(ActorModel::class, false)
|
||||||
->getActorById($this->actor_id);
|
->getActorById($this->actor_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ if (! function_exists('interact_as_actor')) {
|
|||||||
|
|
||||||
$session = session();
|
$session = session();
|
||||||
if ($session->has('interact_as_actor_id')) {
|
if ($session->has('interact_as_actor_id')) {
|
||||||
return model(ActorModel::class)->getActorById($session->get('interact_as_actor_id'));
|
return model(ActorModel::class, false)->getActorById($session->get('interact_as_actor_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -21,7 +21,7 @@ class FediverseController extends BaseController
|
|||||||
{
|
{
|
||||||
helper(['form']);
|
helper(['form']);
|
||||||
|
|
||||||
$blockedActors = model('ActorModel')
|
$blockedActors = model('ActorModel', false)
|
||||||
->getBlockedActors();
|
->getBlockedActors();
|
||||||
|
|
||||||
return view('fediverse/blocked_actors', [
|
return view('fediverse/blocked_actors', [
|
||||||
@ -33,7 +33,7 @@ class FediverseController extends BaseController
|
|||||||
{
|
{
|
||||||
helper(['form']);
|
helper(['form']);
|
||||||
|
|
||||||
$blockedDomains = model('BlockedDomainModel')
|
$blockedDomains = model('BlockedDomainModel', false)
|
||||||
->getBlockedDomains();
|
->getBlockedDomains();
|
||||||
|
|
||||||
return view('fediverse/blocked_domains', [
|
return view('fediverse/blocked_domains', [
|
||||||
|
@ -44,7 +44,7 @@ class ActorController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
($actor = model('ActorModel')->getActorByUsername($params[0])) === null
|
($actor = model('ActorModel', false)->getActorByUsername($params[0])) === null
|
||||||
) {
|
) {
|
||||||
throw PageNotFoundException::forPageNotFound();
|
throw PageNotFoundException::forPageNotFound();
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ class ActorController extends Controller
|
|||||||
$payloadActor = get_or_create_actor_from_uri($payload->actor);
|
$payloadActor = get_or_create_actor_from_uri($payload->actor);
|
||||||
|
|
||||||
// store activity to database
|
// store activity to database
|
||||||
$activityId = model('ActivityModel')
|
$activityId = model('ActivityModel', false)
|
||||||
->newActivity(
|
->newActivity(
|
||||||
$payload->type,
|
$payload->type,
|
||||||
$payloadActor->id,
|
$payloadActor->id,
|
||||||
@ -101,7 +101,7 @@ class ActorController extends Controller
|
|||||||
->setJSON([]);
|
->setJSON([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$replyToPost = model('PostModel')
|
$replyToPost = model('PostModel', false)
|
||||||
->getPostByUri($payload->object->inReplyTo);
|
->getPostByUri($payload->object->inReplyTo);
|
||||||
|
|
||||||
$reply = null;
|
$reply = null;
|
||||||
@ -120,10 +120,10 @@ class ActorController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($reply !== null) {
|
if ($reply !== null) {
|
||||||
$postId = model('PostModel')
|
$postId = model('PostModel', false)
|
||||||
->addReply($reply, true, false);
|
->addReply($reply, true, false);
|
||||||
|
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($activityId, [
|
->update($activityId, [
|
||||||
'post_id' => $postId,
|
'post_id' => $postId,
|
||||||
]);
|
]);
|
||||||
@ -136,11 +136,11 @@ class ActorController extends Controller
|
|||||||
return $this->response->setStatusCode(501)
|
return $this->response->setStatusCode(501)
|
||||||
->setJSON([]);
|
->setJSON([]);
|
||||||
case 'Delete':
|
case 'Delete':
|
||||||
$postToDelete = model('PostModel')
|
$postToDelete = model('PostModel', false)
|
||||||
->getPostByUri($payload->object->id);
|
->getPostByUri($payload->object->id);
|
||||||
|
|
||||||
if ($postToDelete !== null) {
|
if ($postToDelete !== null) {
|
||||||
model('PostModel')
|
model('PostModel', false)
|
||||||
->removePost($postToDelete, false);
|
->removePost($postToDelete, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ class ActorController extends Controller
|
|||||||
->setJSON([]);
|
->setJSON([]);
|
||||||
case 'Follow':
|
case 'Follow':
|
||||||
// add to followers table
|
// add to followers table
|
||||||
model('FollowModel')
|
model('FollowModel', false)
|
||||||
->addFollower($payloadActor, $this->actor, false);
|
->addFollower($payloadActor, $this->actor, false);
|
||||||
|
|
||||||
// Automatically accept follow by returning accept activity
|
// Automatically accept follow by returning accept activity
|
||||||
@ -160,15 +160,15 @@ class ActorController extends Controller
|
|||||||
|
|
||||||
case 'Like':
|
case 'Like':
|
||||||
// get favourited post
|
// get favourited post
|
||||||
$post = model('PostModel')
|
$post = model('PostModel', false)
|
||||||
->getPostByUri($payload->object);
|
->getPostByUri($payload->object);
|
||||||
|
|
||||||
if ($post !== null) {
|
if ($post !== null) {
|
||||||
// Like side-effect
|
// Like side-effect
|
||||||
model('FavouriteModel')
|
model('FavouriteModel', false)
|
||||||
->addFavourite($payloadActor, $post, false);
|
->addFavourite($payloadActor, $post, false);
|
||||||
|
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($activityId, [
|
->update($activityId, [
|
||||||
'post_id' => $post->id,
|
'post_id' => $post->id,
|
||||||
]);
|
]);
|
||||||
@ -177,16 +177,16 @@ class ActorController extends Controller
|
|||||||
return $this->response->setStatusCode(200)
|
return $this->response->setStatusCode(200)
|
||||||
->setJSON([]);
|
->setJSON([]);
|
||||||
case 'Announce':
|
case 'Announce':
|
||||||
$post = model('PostModel')
|
$post = model('PostModel', false)
|
||||||
->getPostByUri($payload->object);
|
->getPostByUri($payload->object);
|
||||||
|
|
||||||
if ($post !== null) {
|
if ($post !== null) {
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($activityId, [
|
->update($activityId, [
|
||||||
'post_id' => $post->id,
|
'post_id' => $post->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
model('PostModel')
|
model('PostModel', false)
|
||||||
->reblog($payloadActor, $post, false);
|
->reblog($payloadActor, $post, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,22 +198,22 @@ class ActorController extends Controller
|
|||||||
switch ($payload->object->type) {
|
switch ($payload->object->type) {
|
||||||
case 'Follow':
|
case 'Follow':
|
||||||
// revert side-effect by removing follow from database
|
// revert side-effect by removing follow from database
|
||||||
model('FollowModel')
|
model('FollowModel', false)
|
||||||
->removeFollower($payloadActor, $this->actor, false);
|
->removeFollower($payloadActor, $this->actor, false);
|
||||||
|
|
||||||
// TODO: undo has been accepted! (202 - Accepted)
|
// TODO: undo has been accepted! (202 - Accepted)
|
||||||
return $this->response->setStatusCode(202)
|
return $this->response->setStatusCode(202)
|
||||||
->setJSON([]);
|
->setJSON([]);
|
||||||
case 'Like':
|
case 'Like':
|
||||||
$post = model('PostModel')
|
$post = model('PostModel', false)
|
||||||
->getPostByUri($payload->object->object);
|
->getPostByUri($payload->object->object);
|
||||||
|
|
||||||
if ($post !== null) {
|
if ($post !== null) {
|
||||||
// revert side-effect by removing favourite from database
|
// revert side-effect by removing favourite from database
|
||||||
model('FavouriteModel')
|
model('FavouriteModel', false)
|
||||||
->removeFavourite($payloadActor, $post, false);
|
->removeFavourite($payloadActor, $post, false);
|
||||||
|
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($activityId, [
|
->update($activityId, [
|
||||||
'post_id' => $post->id,
|
'post_id' => $post->id,
|
||||||
]);
|
]);
|
||||||
@ -222,12 +222,12 @@ class ActorController extends Controller
|
|||||||
return $this->response->setStatusCode(200)
|
return $this->response->setStatusCode(200)
|
||||||
->setJSON([]);
|
->setJSON([]);
|
||||||
case 'Announce':
|
case 'Announce':
|
||||||
$post = model('PostModel')
|
$post = model('PostModel', false)
|
||||||
->getPostByUri($payload->object->object);
|
->getPostByUri($payload->object->object);
|
||||||
|
|
||||||
$reblogPost = null;
|
$reblogPost = null;
|
||||||
if ($post !== null) {
|
if ($post !== null) {
|
||||||
$reblogPost = model('PostModel')
|
$reblogPost = model('PostModel', false)
|
||||||
->where([
|
->where([
|
||||||
'actor_id' => $payloadActor->id,
|
'actor_id' => $payloadActor->id,
|
||||||
'reblog_of_id' => service('uuid')
|
'reblog_of_id' => service('uuid')
|
||||||
@ -238,10 +238,10 @@ class ActorController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($reblogPost !== null) {
|
if ($reblogPost !== null) {
|
||||||
model('PostModel')
|
model('PostModel', false)
|
||||||
->undoReblog($reblogPost, false);
|
->undoReblog($reblogPost, false);
|
||||||
|
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($activityId, [
|
->update($activityId, [
|
||||||
'post_id' => $post->id,
|
'post_id' => $post->id,
|
||||||
]);
|
]);
|
||||||
@ -268,7 +268,7 @@ class ActorController extends Controller
|
|||||||
public function outbox(): ResponseInterface
|
public function outbox(): ResponseInterface
|
||||||
{
|
{
|
||||||
// get published activities by publication date
|
// get published activities by publication date
|
||||||
$actorActivity = model('ActivityModel')
|
$actorActivity = model('ActivityModel', false)
|
||||||
->where('actor_id', $this->actor->id)
|
->where('actor_id', $this->actor->id)
|
||||||
->where('`created_at` <= NOW()', null, false)
|
->where('`created_at` <= NOW()', null, false)
|
||||||
->orderBy('created_at', 'DESC');
|
->orderBy('created_at', 'DESC');
|
||||||
@ -303,7 +303,7 @@ class ActorController extends Controller
|
|||||||
->tablesPrefix;
|
->tablesPrefix;
|
||||||
|
|
||||||
// get followers for a specific actor
|
// get followers for a specific actor
|
||||||
$followers = model('ActorModel')
|
$followers = model('ActorModel', false)
|
||||||
->join($tablesPrefix . 'follows', $tablesPrefix . 'follows.actor_id = id', 'inner')
|
->join($tablesPrefix . 'follows', $tablesPrefix . 'follows.actor_id = id', 'inner')
|
||||||
->where($tablesPrefix . 'follows.target_actor_id', $this->actor->id)
|
->where($tablesPrefix . 'follows.target_actor_id', $this->actor->id)
|
||||||
->orderBy($tablesPrefix . 'follows.created_at', 'DESC');
|
->orderBy($tablesPrefix . 'follows.created_at', 'DESC');
|
||||||
@ -383,7 +383,7 @@ class ActorController extends Controller
|
|||||||
public function activity(string $activityId): ResponseInterface
|
public function activity(string $activityId): ResponseInterface
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
! ($activity = model('ActivityModel')->getActivityById($activityId))
|
! ($activity = model('ActivityModel', false)->getActivityById($activityId))
|
||||||
) {
|
) {
|
||||||
throw PageNotFoundException::forPageNotFound();
|
throw PageNotFoundException::forPageNotFound();
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class BlockController extends Controller
|
|||||||
->with('error', lang('Fediverse.messages.actorNotFound'));
|
->with('error', lang('Fediverse.messages.actorNotFound'));
|
||||||
}
|
}
|
||||||
|
|
||||||
model('ActorModel')
|
model('ActorModel', false)
|
||||||
->blockActor($actor->id);
|
->blockActor($actor->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ class BlockController extends Controller
|
|||||||
->with('errors', $this->validator->getErrors());
|
->with('errors', $this->validator->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
model('ActorModel')
|
model('ActorModel', false)
|
||||||
->unblockActor((int) $this->request->getPost('actor_id'));
|
->unblockActor((int) $this->request->getPost('actor_id'));
|
||||||
|
|
||||||
return redirect()->back()
|
return redirect()->back()
|
||||||
@ -89,7 +89,7 @@ class BlockController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$domain = $this->request->getPost('domain');
|
$domain = $this->request->getPost('domain');
|
||||||
model('BlockedDomainModel')
|
model('BlockedDomainModel', false)
|
||||||
->blockDomain($domain);
|
->blockDomain($domain);
|
||||||
|
|
||||||
return redirect()->back()
|
return redirect()->back()
|
||||||
@ -112,7 +112,7 @@ class BlockController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$domain = $this->request->getPost('domain');
|
$domain = $this->request->getPost('domain');
|
||||||
model('BlockedDomainModel')
|
model('BlockedDomainModel', false)
|
||||||
->unblockDomain($domain);
|
->unblockDomain($domain);
|
||||||
|
|
||||||
return redirect()->back()
|
return redirect()->back()
|
||||||
|
@ -17,13 +17,13 @@ class NodeInfo2Controller extends Controller
|
|||||||
{
|
{
|
||||||
public function index(): ResponseInterface
|
public function index(): ResponseInterface
|
||||||
{
|
{
|
||||||
$totalUsers = model('ActorModel')
|
$totalUsers = model('ActorModel', false)
|
||||||
->getTotalLocalActors();
|
->getTotalLocalActors();
|
||||||
$totalPosts = model('PostModel')
|
$totalPosts = model('PostModel', false)
|
||||||
->getTotalLocalPosts();
|
->getTotalLocalPosts();
|
||||||
$activeMonth = model('ActorModel')
|
$activeMonth = model('ActorModel', false)
|
||||||
->getActiveLocalActors(1);
|
->getActiveLocalActors(1);
|
||||||
$activeHalfyear = model('ActorModel')
|
$activeHalfyear = model('ActorModel', false)
|
||||||
->getActiveLocalActors(6);
|
->getActiveLocalActors(6);
|
||||||
|
|
||||||
$nodeInfo2 = [
|
$nodeInfo2 = [
|
||||||
|
@ -42,7 +42,7 @@ class PostController extends Controller
|
|||||||
|
|
||||||
public function _remap(string $method, string ...$params): mixed
|
public function _remap(string $method, string ...$params): mixed
|
||||||
{
|
{
|
||||||
if (($post = model('PostModel')->getPostById($params[0])) === null) {
|
if (($post = model('PostModel', false)->getPostById($params[0])) === null) {
|
||||||
throw PageNotFoundException::forPageNotFound();
|
throw PageNotFoundException::forPageNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ class PostController extends Controller
|
|||||||
/**
|
/**
|
||||||
* get post replies
|
* get post replies
|
||||||
*/
|
*/
|
||||||
$postReplies = model('PostModel')
|
$postReplies = model('PostModel', false)
|
||||||
->where('in_reply_to_id', service('uuid') ->fromString($this->post->id) ->getBytes())
|
->where('in_reply_to_id', service('uuid') ->fromString($this->post->id) ->getBytes())
|
||||||
->where('`published_at` <= NOW()', null, false)
|
->where('`published_at` <= NOW()', null, false)
|
||||||
->orderBy('published_at', 'ASC');
|
->orderBy('published_at', 'ASC');
|
||||||
@ -127,7 +127,7 @@ class PostController extends Controller
|
|||||||
'published_at' => Time::now(),
|
'published_at' => Time::now(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$postModel = model('PostModel');
|
$postModel = model('PostModel', false);
|
||||||
if (! $postModel->addPost($newPost)) {
|
if (! $postModel->addPost($newPost)) {
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
@ -153,10 +153,10 @@ class PostController extends Controller
|
|||||||
->with('errors', $this->validator->getErrors());
|
->with('errors', $this->validator->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
$actor = model('ActorModel')
|
$actor = model('ActorModel', false)
|
||||||
->getActorById($this->request->getPost('actor_id'));
|
->getActorById($this->request->getPost('actor_id'));
|
||||||
|
|
||||||
model('FavouriteModel')
|
model('FavouriteModel', false)
|
||||||
->toggleFavourite($actor, $this->post->id);
|
->toggleFavourite($actor, $this->post->id);
|
||||||
|
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
@ -175,10 +175,10 @@ class PostController extends Controller
|
|||||||
->with('errors', $this->validator->getErrors());
|
->with('errors', $this->validator->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
$actor = model('ActorModel')
|
$actor = model('ActorModel', false)
|
||||||
->getActorById($this->request->getPost('actor_id'));
|
->getActorById($this->request->getPost('actor_id'));
|
||||||
|
|
||||||
model('PostModel')
|
model('PostModel', false)
|
||||||
->toggleReblog($actor, $this->post);
|
->toggleReblog($actor, $this->post);
|
||||||
|
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
@ -205,7 +205,7 @@ class PostController extends Controller
|
|||||||
'published_at' => Time::now(),
|
'published_at' => Time::now(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (! model('PostModel')->addReply($newReplyPost)) {
|
if (! model('PostModel', false)->addReply($newReplyPost)) {
|
||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->withInput()
|
->withInput()
|
||||||
@ -265,14 +265,14 @@ class PostController extends Controller
|
|||||||
|
|
||||||
public function attemptBlockActor(): RedirectResponse
|
public function attemptBlockActor(): RedirectResponse
|
||||||
{
|
{
|
||||||
model('ActorModel')->blockActor($this->post->actor->id);
|
model('ActorModel', false)->blockActor($this->post->actor->id);
|
||||||
|
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attemptBlockDomain(): RedirectResponse
|
public function attemptBlockDomain(): RedirectResponse
|
||||||
{
|
{
|
||||||
model('BlockedDomainModel')->blockDomain($this->post->actor->domain);
|
model('BlockedDomainModel', false)->blockDomain($this->post->actor->domain);
|
||||||
|
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class SchedulerController extends Controller
|
|||||||
public function activity(): void
|
public function activity(): void
|
||||||
{
|
{
|
||||||
// retrieve scheduled activities from database
|
// retrieve scheduled activities from database
|
||||||
$scheduledActivities = model('ActivityModel')
|
$scheduledActivities = model('ActivityModel', false)
|
||||||
->getScheduledActivities();
|
->getScheduledActivities();
|
||||||
|
|
||||||
// Send activity to all followers
|
// Send activity to all followers
|
||||||
@ -45,7 +45,7 @@ class SchedulerController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set activity post to delivered
|
// set activity post to delivered
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($scheduledActivity->id, [
|
->update($scheduledActivity->id, [
|
||||||
'status' => 'delivered',
|
'status' => 'delivered',
|
||||||
]);
|
]);
|
||||||
|
@ -50,12 +50,12 @@ class FediverseFilter implements FilterInterface
|
|||||||
$domain = (new URI($actorUri))->getHost();
|
$domain = (new URI($actorUri))->getHost();
|
||||||
|
|
||||||
// check first if domain is blocked
|
// check first if domain is blocked
|
||||||
if (model('BlockedDomainModel')->isDomainBlocked($domain)) {
|
if (model('BlockedDomainModel', false)->isDomainBlocked($domain)) {
|
||||||
throw PageNotFoundException::forPageNotFound();
|
throw PageNotFoundException::forPageNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if actor is blocked
|
// check if actor is blocked
|
||||||
if (model('ActorModel')->isActorBlocked($actorUri)) {
|
if (model('ActorModel', false)->isActorBlocked($actorUri)) {
|
||||||
throw PageNotFoundException::forPageNotFound();
|
throw PageNotFoundException::forPageNotFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ if (! function_exists('accept_follow')) {
|
|||||||
$db = db_connect();
|
$db = db_connect();
|
||||||
$db->transStart();
|
$db->transStart();
|
||||||
|
|
||||||
$activityModel = model('ActivityModel');
|
$activityModel = model('ActivityModel', false);
|
||||||
$activityId = $activityModel->newActivity(
|
$activityId = $activityModel->newActivity(
|
||||||
'Accept',
|
'Accept',
|
||||||
$actor->id,
|
$actor->id,
|
||||||
@ -183,7 +183,7 @@ if (! function_exists('create_preview_card_from_url')) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
! ($newPreviewCardId = model('PreviewCardModel')->insert($newPreviewCard, true))
|
! ($newPreviewCardId = model('PreviewCardModel', false)->insert($newPreviewCard, true))
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ if (! function_exists('get_or_create_preview_card_from_url')) {
|
|||||||
{
|
{
|
||||||
// check if preview card has already been generated
|
// check if preview card has already been generated
|
||||||
if (
|
if (
|
||||||
$previewCard = model('PreviewCardModel')
|
$previewCard = model('PreviewCardModel', false)
|
||||||
->getPreviewCardFromUrl((string) $url)
|
->getPreviewCardFromUrl((string) $url)
|
||||||
) {
|
) {
|
||||||
return $previewCard;
|
return $previewCard;
|
||||||
@ -224,7 +224,7 @@ if (! function_exists('get_or_create_actor_from_uri')) {
|
|||||||
function get_or_create_actor_from_uri(string $actorUri): ?Actor
|
function get_or_create_actor_from_uri(string $actorUri): ?Actor
|
||||||
{
|
{
|
||||||
// check if actor exists in database already and return it
|
// check if actor exists in database already and return it
|
||||||
if ($actor = model('ActorModel')->getActorByUri($actorUri)) {
|
if ($actor = model('ActorModel', false)->getActorByUri($actorUri)) {
|
||||||
return $actor;
|
return $actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ if (! function_exists('get_or_create_actor')) {
|
|||||||
{
|
{
|
||||||
// check if actor exists in database already and return it
|
// check if actor exists in database already and return it
|
||||||
if (
|
if (
|
||||||
$actor = model('ActorModel')
|
$actor = model('ActorModel', false)
|
||||||
->getActorByUsername($username, $domain)
|
->getActorByUsername($username, $domain)
|
||||||
) {
|
) {
|
||||||
return $actor;
|
return $actor;
|
||||||
@ -287,7 +287,7 @@ if (! function_exists('create_actor_from_uri')) {
|
|||||||
$newActor->outbox_url = property_exists($actorPayload, 'outbox') ? $actorPayload->outbox : null;
|
$newActor->outbox_url = property_exists($actorPayload, 'outbox') ? $actorPayload->outbox : null;
|
||||||
$newActor->followers_url = property_exists($actorPayload, 'followers') ? $actorPayload->followers : null;
|
$newActor->followers_url = property_exists($actorPayload, 'followers') ? $actorPayload->followers : null;
|
||||||
|
|
||||||
if (! ($newActorId = model('ActorModel')->insert($newActor, true))) {
|
if (! ($newActorId = model('ActorModel', false)->insert($newActor, true))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -431,7 +431,7 @@ if (! function_exists('linkify')) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
$actor = model('ActorModel')
|
$actor = model('ActorModel', false)
|
||||||
->getActorByUsername($match['username'])
|
->getActorByUsername($match['username'])
|
||||||
) {
|
) {
|
||||||
return '<' .
|
return '<' .
|
||||||
|
@ -100,7 +100,7 @@ class BlockedDomainModel extends BaseModel
|
|||||||
$this->db->transStart();
|
$this->db->transStart();
|
||||||
|
|
||||||
// set all actors from the domain as blocked
|
// set all actors from the domain as blocked
|
||||||
model('ActorModel')
|
model('ActorModel', false)
|
||||||
->where('domain', $name)
|
->where('domain', $name)
|
||||||
->set('is_blocked', '1')
|
->set('is_blocked', '1')
|
||||||
->update();
|
->update();
|
||||||
@ -131,7 +131,7 @@ class BlockedDomainModel extends BaseModel
|
|||||||
|
|
||||||
$this->db->transStart();
|
$this->db->transStart();
|
||||||
// unblock all actors from the domain
|
// unblock all actors from the domain
|
||||||
model('ActorModel')
|
model('ActorModel', false)
|
||||||
->where('domain', $name)
|
->where('domain', $name)
|
||||||
->set('is_blocked', '0')
|
->set('is_blocked', '0')
|
||||||
->update();
|
->update();
|
||||||
|
@ -55,7 +55,7 @@ class FavouriteModel extends BaseUuidModel
|
|||||||
'post_id' => $post->id,
|
'post_id' => $post->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
model('PostModel')
|
model('PostModel', false)
|
||||||
->where('id', service('uuid') ->fromString($post->id) ->getBytes())
|
->where('id', service('uuid') ->fromString($post->id) ->getBytes())
|
||||||
->increment('favourites_count');
|
->increment('favourites_count');
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class FavouriteModel extends BaseUuidModel
|
|||||||
$likeActivity->set('actor', $actor->uri)
|
$likeActivity->set('actor', $actor->uri)
|
||||||
->set('object', $post->uri);
|
->set('object', $post->uri);
|
||||||
|
|
||||||
$activityId = model('ActivityModel')
|
$activityId = model('ActivityModel', false)
|
||||||
->newActivity(
|
->newActivity(
|
||||||
'Like',
|
'Like',
|
||||||
$actor->id,
|
$actor->id,
|
||||||
@ -77,7 +77,7 @@ class FavouriteModel extends BaseUuidModel
|
|||||||
|
|
||||||
$likeActivity->set('id', url_to('activity', $actor->username, $activityId));
|
$likeActivity->set('id', url_to('activity', $actor->username, $activityId));
|
||||||
|
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($activityId, [
|
->update($activityId, [
|
||||||
'payload' => $likeActivity->toJSON(),
|
'payload' => $likeActivity->toJSON(),
|
||||||
]);
|
]);
|
||||||
@ -85,7 +85,7 @@ class FavouriteModel extends BaseUuidModel
|
|||||||
|
|
||||||
Events::trigger('on_post_favourite', $actor, $post);
|
Events::trigger('on_post_favourite', $actor, $post);
|
||||||
|
|
||||||
model('PostModel')
|
model('PostModel', false)
|
||||||
->clearCache($post);
|
->clearCache($post);
|
||||||
|
|
||||||
$this->db->transComplete();
|
$this->db->transComplete();
|
||||||
@ -95,7 +95,7 @@ class FavouriteModel extends BaseUuidModel
|
|||||||
{
|
{
|
||||||
$this->db->transStart();
|
$this->db->transStart();
|
||||||
|
|
||||||
model('PostModel')
|
model('PostModel', false)
|
||||||
->where('id', service('uuid') ->fromString($post->id) ->getBytes())
|
->where('id', service('uuid') ->fromString($post->id) ->getBytes())
|
||||||
->decrement('favourites_count');
|
->decrement('favourites_count');
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ class FavouriteModel extends BaseUuidModel
|
|||||||
if ($registerActivity) {
|
if ($registerActivity) {
|
||||||
$undoActivity = new UndoActivity();
|
$undoActivity = new UndoActivity();
|
||||||
// get like activity
|
// get like activity
|
||||||
$activity = model('ActivityModel')
|
$activity = model('ActivityModel', false)
|
||||||
->where([
|
->where([
|
||||||
'type' => 'Like',
|
'type' => 'Like',
|
||||||
'actor_id' => $actor->id,
|
'actor_id' => $actor->id,
|
||||||
@ -130,7 +130,7 @@ class FavouriteModel extends BaseUuidModel
|
|||||||
->set('actor', $actor->uri)
|
->set('actor', $actor->uri)
|
||||||
->set('object', $likeActivity);
|
->set('object', $likeActivity);
|
||||||
|
|
||||||
$activityId = model('ActivityModel')
|
$activityId = model('ActivityModel', false)
|
||||||
->newActivity(
|
->newActivity(
|
||||||
'Undo',
|
'Undo',
|
||||||
$actor->id,
|
$actor->id,
|
||||||
@ -143,7 +143,7 @@ class FavouriteModel extends BaseUuidModel
|
|||||||
|
|
||||||
$undoActivity->set('id', url_to('activity', $actor->username, $activityId));
|
$undoActivity->set('id', url_to('activity', $actor->username, $activityId));
|
||||||
|
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($activityId, [
|
->update($activityId, [
|
||||||
'payload' => $undoActivity->toJSON(),
|
'payload' => $undoActivity->toJSON(),
|
||||||
]);
|
]);
|
||||||
@ -151,7 +151,7 @@ class FavouriteModel extends BaseUuidModel
|
|||||||
|
|
||||||
Events::trigger('on_post_undo_favourite', $actor, $post);
|
Events::trigger('on_post_undo_favourite', $actor, $post);
|
||||||
|
|
||||||
model('PostModel')
|
model('PostModel', false)
|
||||||
->clearCache($post);
|
->clearCache($post);
|
||||||
|
|
||||||
$this->db->transComplete();
|
$this->db->transComplete();
|
||||||
|
@ -61,7 +61,7 @@ class FollowModel extends BaseModel
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// increment followers_count for target actor
|
// increment followers_count for target actor
|
||||||
model('ActorModel')
|
model('ActorModel', false)
|
||||||
->where('id', $targetActor->id)
|
->where('id', $targetActor->id)
|
||||||
->increment('followers_count');
|
->increment('followers_count');
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class FollowModel extends BaseModel
|
|||||||
->set('actor', $actor->uri)
|
->set('actor', $actor->uri)
|
||||||
->set('object', $targetActor->uri);
|
->set('object', $targetActor->uri);
|
||||||
|
|
||||||
$activityId = model('ActivityModel')
|
$activityId = model('ActivityModel', false)
|
||||||
->newActivity(
|
->newActivity(
|
||||||
'Follow',
|
'Follow',
|
||||||
$actor->id,
|
$actor->id,
|
||||||
@ -85,7 +85,7 @@ class FollowModel extends BaseModel
|
|||||||
|
|
||||||
$followActivity->set('id', url_to('activity', $actor->username, $activityId));
|
$followActivity->set('id', url_to('activity', $actor->username, $activityId));
|
||||||
|
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($activityId, [
|
->update($activityId, [
|
||||||
'payload' => $followActivity->toJSON(),
|
'payload' => $followActivity->toJSON(),
|
||||||
]);
|
]);
|
||||||
@ -93,7 +93,7 @@ class FollowModel extends BaseModel
|
|||||||
|
|
||||||
Events::trigger('on_follow', $actor, $targetActor);
|
Events::trigger('on_follow', $actor, $targetActor);
|
||||||
|
|
||||||
model('ActorModel')
|
model('ActorModel', false)
|
||||||
->clearCache($targetActor);
|
->clearCache($targetActor);
|
||||||
|
|
||||||
$this->db->transComplete();
|
$this->db->transComplete();
|
||||||
@ -118,14 +118,14 @@ class FollowModel extends BaseModel
|
|||||||
])->delete();
|
])->delete();
|
||||||
|
|
||||||
// decrement followers_count for target actor
|
// decrement followers_count for target actor
|
||||||
model('ActorModel')
|
model('ActorModel', false)
|
||||||
->where('id', $targetActor->id)
|
->where('id', $targetActor->id)
|
||||||
->decrement('followers_count');
|
->decrement('followers_count');
|
||||||
|
|
||||||
if ($registerActivity) {
|
if ($registerActivity) {
|
||||||
$undoActivity = new UndoActivity();
|
$undoActivity = new UndoActivity();
|
||||||
// get follow activity from database
|
// get follow activity from database
|
||||||
$followActivity = model('ActivityModel')
|
$followActivity = model('ActivityModel', false)
|
||||||
->where([
|
->where([
|
||||||
'type' => 'Follow',
|
'type' => 'Follow',
|
||||||
'actor_id' => $actor->id,
|
'actor_id' => $actor->id,
|
||||||
@ -137,7 +137,7 @@ class FollowModel extends BaseModel
|
|||||||
->set('actor', $actor->uri)
|
->set('actor', $actor->uri)
|
||||||
->set('object', $followActivity->payload);
|
->set('object', $followActivity->payload);
|
||||||
|
|
||||||
$activityId = model('ActivityModel')
|
$activityId = model('ActivityModel', false)
|
||||||
->newActivity(
|
->newActivity(
|
||||||
'Undo',
|
'Undo',
|
||||||
$actor->id,
|
$actor->id,
|
||||||
@ -150,7 +150,7 @@ class FollowModel extends BaseModel
|
|||||||
|
|
||||||
$undoActivity->set('id', url_to('activity', $actor->username, $activityId));
|
$undoActivity->set('id', url_to('activity', $actor->username, $activityId));
|
||||||
|
|
||||||
model('ActivityModel')
|
model('ActivityModel', false)
|
||||||
->update($activityId, [
|
->update($activityId, [
|
||||||
'payload' => $undoActivity->toJSON(),
|
'payload' => $undoActivity->toJSON(),
|
||||||
]);
|
]);
|
||||||
@ -158,7 +158,7 @@ class FollowModel extends BaseModel
|
|||||||
|
|
||||||
Events::trigger('on_undo_follow', $actor, $targetActor);
|
Events::trigger('on_undo_follow', $actor, $targetActor);
|
||||||
|
|
||||||
model('ActorModel')
|
model('ActorModel', false)
|
||||||
->clearCache($targetActor);
|
->clearCache($targetActor);
|
||||||
|
|
||||||
$this->db->transComplete();
|
$this->db->transComplete();
|
||||||
|
@ -62,7 +62,7 @@ class WebFinger
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
! ($actor = model('ActorModel')->getActorByUsername($username, $domain))
|
! ($actor = model('ActorModel', false)->getActorByUsername($username, $domain))
|
||||||
) {
|
) {
|
||||||
throw new Exception('Could not find actor');
|
throw new Exception('Could not find actor');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user