2021-08-13 11:07:29 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2021 Ad Aures
|
2021-08-13 11:07:29 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use App\Entities\Post;
|
2021-08-27 10:58:22 +00:00
|
|
|
use Modules\Fediverse\Models\PostModel as FediversePostModel;
|
2021-08-13 11:07:29 +00:00
|
|
|
|
2021-08-27 10:58:22 +00:00
|
|
|
class PostModel extends FediversePostModel
|
2021-08-13 11:07:29 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $returnType = Post::class;
|
|
|
|
|
|
|
|
/**
|
2024-04-28 16:39:01 +00:00
|
|
|
* @var list<string>
|
2021-08-13 11:07:29 +00:00
|
|
|
*/
|
|
|
|
protected $allowedFields = [
|
|
|
|
'id',
|
|
|
|
'uri',
|
|
|
|
'actor_id',
|
|
|
|
'in_reply_to_id',
|
|
|
|
'reblog_of_id',
|
|
|
|
'episode_id',
|
|
|
|
'message',
|
|
|
|
'message_html',
|
|
|
|
'favourites_count',
|
|
|
|
'reblogs_count',
|
|
|
|
'replies_count',
|
|
|
|
'created_by',
|
|
|
|
'published_at',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves all published posts for a given episode ordered by publication date
|
|
|
|
*
|
|
|
|
* @return Post[]
|
|
|
|
*/
|
|
|
|
public function getEpisodePosts(int $episodeId): array
|
|
|
|
{
|
|
|
|
return $this->where([
|
|
|
|
'episode_id' => $episodeId,
|
|
|
|
])
|
2022-01-14 17:42:55 +00:00
|
|
|
->where('in_reply_to_id', null)
|
2022-04-14 14:33:53 +00:00
|
|
|
->where('`published_at` <= UTC_TIMESTAMP()', null, false)
|
2021-08-13 11:07:29 +00:00
|
|
|
->orderBy('published_at', 'DESC')
|
|
|
|
->findAll();
|
|
|
|
}
|
2022-01-14 17:42:55 +00:00
|
|
|
|
|
|
|
public function setEpisodeIdForRepliesOfEpisodePosts(): int | false
|
|
|
|
{
|
|
|
|
// make sure that posts in reply to episode activities have an episode id
|
2023-08-26 13:03:01 +00:00
|
|
|
$postsToUpdate = $this->db->table('fediverse_posts as p1')
|
|
|
|
->join('fediverse_posts as p2', 'p1.id = p2.in_reply_to_id')
|
2022-01-14 17:42:55 +00:00
|
|
|
->select('p2.id, p1.episode_id')
|
|
|
|
->where([
|
|
|
|
'p2.in_reply_to_id IS NOT' => null,
|
2023-06-12 14:47:38 +00:00
|
|
|
'p2.episode_id' => null,
|
|
|
|
'p1.episode_id IS NOT' => null,
|
2022-01-14 17:42:55 +00:00
|
|
|
])
|
|
|
|
->get()
|
|
|
|
->getResultArray();
|
|
|
|
|
|
|
|
if ($postsToUpdate !== []) {
|
|
|
|
$postModel = new self();
|
|
|
|
$postModel->uuidUseBytes = false;
|
|
|
|
return $postModel->updateBatch($postsToUpdate, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-08-13 11:07:29 +00:00
|
|
|
}
|