mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-16 21:17:45 +02:00
refactor(modules): extract castopod parts into a modules/ folder for a scalable HMVC structure
- create Admin, Analytics, Auth, Fediverse and Install modules in the root modules/ folder - rename ActivityPub to Fediverse
This commit is contained in:
parent
94872f2338
commit
5083cd2fda
268 changed files with 4221 additions and 2186 deletions
120
modules/Fediverse/Models/ActivityModel.php
Normal file
120
modules/Fediverse/Models/ActivityModel.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2021 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
namespace Modules\Fediverse\Models;
|
||||
|
||||
use CodeIgniter\Database\BaseResult;
|
||||
use CodeIgniter\I18n\Time;
|
||||
use DateTimeInterface;
|
||||
use Michalsn\Uuid\UuidModel;
|
||||
use Modules\Fediverse\Entities\Activity;
|
||||
|
||||
class ActivityModel extends UuidModel
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'activitypub_activities';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $uuidFields = ['id', 'post_id'];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $allowedFields = [
|
||||
'id',
|
||||
'actor_id',
|
||||
'target_actor_id',
|
||||
'post_id',
|
||||
'type',
|
||||
'payload',
|
||||
'task_status',
|
||||
'scheduled_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $returnType = Activity::class;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $useTimestamps = true;
|
||||
|
||||
protected $updatedField;
|
||||
|
||||
public function getActivityById(string $activityId): ?Activity
|
||||
{
|
||||
$cacheName =
|
||||
config('Fediverse')
|
||||
->cachePrefix . "activity#{$activityId}";
|
||||
if (! ($found = cache($cacheName))) {
|
||||
$found = $this->find($activityId);
|
||||
|
||||
cache()
|
||||
->save($cacheName, $found, DECADE);
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a new activity record in the database
|
||||
*
|
||||
* @param Time $scheduledAt
|
||||
*/
|
||||
public function newActivity(
|
||||
string $type,
|
||||
int $actorId,
|
||||
?int $targetActorId,
|
||||
?string $postId,
|
||||
string $payload,
|
||||
DateTimeInterface $scheduledAt = null,
|
||||
?string $taskStatus = null
|
||||
): BaseResult | int | string | false {
|
||||
return $this->insert(
|
||||
[
|
||||
'actor_id' => $actorId,
|
||||
'target_actor_id' => $targetActorId,
|
||||
'post_id' => $postId,
|
||||
'type' => $type,
|
||||
'payload' => $payload,
|
||||
'scheduled_at' => $scheduledAt,
|
||||
'task_status' => $taskStatus,
|
||||
],
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Activity[]
|
||||
*/
|
||||
public function getScheduledActivities(): array
|
||||
{
|
||||
return $this->where('`scheduled_at` <= NOW()', null, false)
|
||||
->where('task_status', 'queued')
|
||||
->orderBy('scheduled_at', 'ASC')
|
||||
->findAll();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue