Loading app/Controllers/PostController.php +11 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ use CodeIgniter\HTTP\URI; use CodeIgniter\I18n\Time; use Modules\Analytics\AnalyticsTrait; use Modules\Fediverse\Controllers\PostController as FediversePostController; use Modules\Fediverse\Entities\Post as FediversePost; use Modules\Fediverse\Models\FavouriteModel; class PostController extends FediversePostController Loading @@ -33,6 +32,11 @@ class PostController extends FediversePostController protected Actor $actor; /** * @var CastopodPost */ protected $post; /** * @var string[] */ Loading @@ -53,6 +57,7 @@ class PostController extends FediversePostController count($params) > 1 && ($post = (new PostModel())->getPostById($params[1])) !== null ) { /** @var CastopodPost $post */ $this->post = $post; unset($params[0]); Loading Loading @@ -163,7 +168,7 @@ class PostController extends FediversePostController ->with('errors', $this->validator->getErrors()); } $newPost = new FediversePost([ $newPost = new CastopodPost([ 'actor_id' => interact_as_actor_id(), 'in_reply_to_id' => $this->post->id, 'message' => $this->request->getPost('message'), Loading @@ -171,6 +176,10 @@ class PostController extends FediversePostController 'created_by' => user_id(), ]); if ($this->post->in_reply_to_id === null && $this->post->episode_id !== null) { $newPost->episode_id = $this->post->episode_id; } $postModel = new PostModel(); if (! $postModel->addReply($newPost)) { return redirect() Loading app/Models/EpisodeCommentModel.php +35 −1 Original line number Diff line number Diff line Loading @@ -149,7 +149,10 @@ class EpisodeCommentModel extends UuidModel ->whereIn('in_reply_to_id', function (BaseBuilder $builder) use (&$episodeId): BaseBuilder { return $builder->select('id') ->from(config('Fediverse')->tablesPrefix . 'posts') ->where('episode_id', $episodeId); ->where([ 'episode_id' => $episodeId, 'in_reply_to_id' => null, ]); }) ->where('`created_at` <= NOW()', null, false) ->getCompiledSelect(); Loading Loading @@ -179,6 +182,37 @@ class EpisodeCommentModel extends UuidModel ->findAll(); } public function resetLikesCount(): int | false { $commentsLikesCount = $this->db->table('likes') ->select('comment_id as id, COUNT(*) as `likes_count`') ->groupBy('id') ->get() ->getResultArray(); if ($commentsLikesCount !== []) { $this->uuidUseBytes = false; return $this->updateBatch($commentsLikesCount, 'id'); } return 0; } public function resetRepliesCount(): int | false { $commentsRepliesCount = $this->select('episode_comments.id, COUNT(*) as `replies_count`') ->join('episode_comments as c2', 'episode_comments.id = c2.in_reply_to_id') ->groupBy('episode_comments.id') ->get() ->getResultArray(); if ($commentsRepliesCount !== []) { $this->uuidUseBytes = false; return $this->updateBatch($commentsRepliesCount, 'id'); } return 0; } /** * @param array<string, array<string|int, mixed>> $data * @return array<string, array<string|int, mixed>> Loading app/Models/EpisodeModel.php +52 −0 Original line number Diff line number Diff line Loading @@ -322,6 +322,58 @@ class EpisodeModel extends Model return $stats; } public function resetCommentsCount(): int | false { $episodeCommentsCount = $this->select('episodes.id, COUNT(*) as `comments_count`') ->join('episode_comments', 'episodes.id = episode_comments.episode_id') ->where('in_reply_to_id', null) ->groupBy('episodes.id') ->getCompiledSelect(); $episodePostsRepliesCount = $this ->select('episodes.id, COUNT(*) as `comments_count`') ->join( config('Fediverse') ->tablesPrefix . 'posts', 'episodes.id = ' . config('Fediverse')->tablesPrefix . 'posts.episode_id' ) ->where('in_reply_to_id IS NOT', null) ->groupBy('episodes.id') ->getCompiledSelect(); $query = $this->db->query( 'SELECT `id`, SUM(`comments_count`) as `comments_count` FROM (' . $episodeCommentsCount . ' UNION ALL ' . $episodePostsRepliesCount . ') x GROUP BY `id`' ); $countsPerEpisodeId = $query->getResultArray(); if ($countsPerEpisodeId !== []) { return $this->updateBatch($countsPerEpisodeId, 'id'); } return 0; } public function resetPostsCount(): int | false { $episodePostsCount = $this->select('episodes.id, COUNT(*) as `posts_count`') ->join( config('Fediverse') ->tablesPrefix . 'posts', 'episodes.id = ' . config('Fediverse')->tablesPrefix . 'posts.episode_id' ) ->where('in_reply_to_id', null) ->groupBy('episodes.id') ->get() ->getResultArray(); if ($episodePostsCount !== []) { return $this->updateBatch($episodePostsCount, 'id'); } return 0; } /** * @param mixed[] $data * Loading app/Models/PostModel.php +25 −0 Original line number Diff line number Diff line Loading @@ -49,8 +49,33 @@ class PostModel extends FediversePostModel return $this->where([ 'episode_id' => $episodeId, ]) ->where('in_reply_to_id', null) ->where('`published_at` <= NOW()', null, false) ->orderBy('published_at', 'DESC') ->findAll(); } public function setEpisodeIdForRepliesOfEpisodePosts(): int | false { // make sure that posts in reply to episode activities have an episode id $postsToUpdate = $this->db->table(config('Fediverse')->tablesPrefix . 'posts as p1') ->join(config('Fediverse')->tablesPrefix . 'posts as p2', 'p1.id = p2.in_reply_to_id') ->select('p2.id, p1.episode_id') ->where([ 'p1.in_reply_to_id' => null, 'p2.in_reply_to_id IS NOT' => null, 'p2.episode_id' => null, 'p1.episode_id IS NOT' => null, ]) ->get() ->getResultArray(); if ($postsToUpdate !== []) { $postModel = new self(); $postModel->uuidUseBytes = false; return $postModel->updateBatch($postsToUpdate, 'id'); } return 0; } } modules/Admin/Controllers/SettingsController.php +86 −65 Original line number Diff line number Diff line Loading @@ -10,11 +10,13 @@ declare(strict_types=1); namespace Modules\Admin\Controllers; use App\Entities\Media\Image; use App\Models\ActorModel; use App\Models\EpisodeCommentModel; use App\Models\EpisodeModel; use App\Models\MediaModel; use App\Models\PersonModel; use App\Models\PodcastModel; use App\Models\PostModel; use CodeIgniter\Files\File; use CodeIgniter\HTTP\RedirectResponse; use PHP_ICO; Loading Loading @@ -158,8 +160,23 @@ class SettingsController extends BaseController public function runHousekeeping(): RedirectResponse { if ($this->request->getPost('reset_counts') === 'yes') { // recalculate fediverse counts (new ActorModel())->resetFollowersCount(); (new ActorModel())->resetPostsCount(); (new PostModel())->setEpisodeIdForRepliesOfEpisodePosts(); (new PostModel())->resetFavouritesCount(); (new PostModel())->resetReblogsCount(); (new PostModel())->resetRepliesCount(); (new EpisodeModel())->resetCommentsCount(); (new EpisodeModel())->resetPostsCount(); (new EpisodeCommentModel())->resetLikesCount(); (new EpisodeCommentModel())->resetRepliesCount(); } helper('media'); if ($this->request->getPost('rewrite_media') === 'yes') { // Delete all podcast image sizes to recreate them $allPodcasts = (new PodcastModel())->findAll(); foreach ($allPodcasts as $podcast) { Loading Loading @@ -187,7 +204,10 @@ class SettingsController extends BaseController $allImages = (new MediaModel('image'))->getAllOfType(); foreach ($allImages as $image) { if (str_starts_with($image->file_path, 'podcasts')) { if (str_ends_with($image->file_path, 'banner.jpg') || str_ends_with($image->file_path, 'banner.png')) { if (str_ends_with($image->file_path, 'banner.jpg') || str_ends_with( $image->file_path, 'banner.png' )) { $image->sizes = config('Images') ->podcastBannerSizes; } else { Loading Loading @@ -248,6 +268,7 @@ class SettingsController extends BaseController } } } } return redirect('settings-general')->with('message', lang('Settings.housekeeping.runSuccess')); } Loading Loading
app/Controllers/PostController.php +11 −2 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ use CodeIgniter\HTTP\URI; use CodeIgniter\I18n\Time; use Modules\Analytics\AnalyticsTrait; use Modules\Fediverse\Controllers\PostController as FediversePostController; use Modules\Fediverse\Entities\Post as FediversePost; use Modules\Fediverse\Models\FavouriteModel; class PostController extends FediversePostController Loading @@ -33,6 +32,11 @@ class PostController extends FediversePostController protected Actor $actor; /** * @var CastopodPost */ protected $post; /** * @var string[] */ Loading @@ -53,6 +57,7 @@ class PostController extends FediversePostController count($params) > 1 && ($post = (new PostModel())->getPostById($params[1])) !== null ) { /** @var CastopodPost $post */ $this->post = $post; unset($params[0]); Loading Loading @@ -163,7 +168,7 @@ class PostController extends FediversePostController ->with('errors', $this->validator->getErrors()); } $newPost = new FediversePost([ $newPost = new CastopodPost([ 'actor_id' => interact_as_actor_id(), 'in_reply_to_id' => $this->post->id, 'message' => $this->request->getPost('message'), Loading @@ -171,6 +176,10 @@ class PostController extends FediversePostController 'created_by' => user_id(), ]); if ($this->post->in_reply_to_id === null && $this->post->episode_id !== null) { $newPost->episode_id = $this->post->episode_id; } $postModel = new PostModel(); if (! $postModel->addReply($newPost)) { return redirect() Loading
app/Models/EpisodeCommentModel.php +35 −1 Original line number Diff line number Diff line Loading @@ -149,7 +149,10 @@ class EpisodeCommentModel extends UuidModel ->whereIn('in_reply_to_id', function (BaseBuilder $builder) use (&$episodeId): BaseBuilder { return $builder->select('id') ->from(config('Fediverse')->tablesPrefix . 'posts') ->where('episode_id', $episodeId); ->where([ 'episode_id' => $episodeId, 'in_reply_to_id' => null, ]); }) ->where('`created_at` <= NOW()', null, false) ->getCompiledSelect(); Loading Loading @@ -179,6 +182,37 @@ class EpisodeCommentModel extends UuidModel ->findAll(); } public function resetLikesCount(): int | false { $commentsLikesCount = $this->db->table('likes') ->select('comment_id as id, COUNT(*) as `likes_count`') ->groupBy('id') ->get() ->getResultArray(); if ($commentsLikesCount !== []) { $this->uuidUseBytes = false; return $this->updateBatch($commentsLikesCount, 'id'); } return 0; } public function resetRepliesCount(): int | false { $commentsRepliesCount = $this->select('episode_comments.id, COUNT(*) as `replies_count`') ->join('episode_comments as c2', 'episode_comments.id = c2.in_reply_to_id') ->groupBy('episode_comments.id') ->get() ->getResultArray(); if ($commentsRepliesCount !== []) { $this->uuidUseBytes = false; return $this->updateBatch($commentsRepliesCount, 'id'); } return 0; } /** * @param array<string, array<string|int, mixed>> $data * @return array<string, array<string|int, mixed>> Loading
app/Models/EpisodeModel.php +52 −0 Original line number Diff line number Diff line Loading @@ -322,6 +322,58 @@ class EpisodeModel extends Model return $stats; } public function resetCommentsCount(): int | false { $episodeCommentsCount = $this->select('episodes.id, COUNT(*) as `comments_count`') ->join('episode_comments', 'episodes.id = episode_comments.episode_id') ->where('in_reply_to_id', null) ->groupBy('episodes.id') ->getCompiledSelect(); $episodePostsRepliesCount = $this ->select('episodes.id, COUNT(*) as `comments_count`') ->join( config('Fediverse') ->tablesPrefix . 'posts', 'episodes.id = ' . config('Fediverse')->tablesPrefix . 'posts.episode_id' ) ->where('in_reply_to_id IS NOT', null) ->groupBy('episodes.id') ->getCompiledSelect(); $query = $this->db->query( 'SELECT `id`, SUM(`comments_count`) as `comments_count` FROM (' . $episodeCommentsCount . ' UNION ALL ' . $episodePostsRepliesCount . ') x GROUP BY `id`' ); $countsPerEpisodeId = $query->getResultArray(); if ($countsPerEpisodeId !== []) { return $this->updateBatch($countsPerEpisodeId, 'id'); } return 0; } public function resetPostsCount(): int | false { $episodePostsCount = $this->select('episodes.id, COUNT(*) as `posts_count`') ->join( config('Fediverse') ->tablesPrefix . 'posts', 'episodes.id = ' . config('Fediverse')->tablesPrefix . 'posts.episode_id' ) ->where('in_reply_to_id', null) ->groupBy('episodes.id') ->get() ->getResultArray(); if ($episodePostsCount !== []) { return $this->updateBatch($episodePostsCount, 'id'); } return 0; } /** * @param mixed[] $data * Loading
app/Models/PostModel.php +25 −0 Original line number Diff line number Diff line Loading @@ -49,8 +49,33 @@ class PostModel extends FediversePostModel return $this->where([ 'episode_id' => $episodeId, ]) ->where('in_reply_to_id', null) ->where('`published_at` <= NOW()', null, false) ->orderBy('published_at', 'DESC') ->findAll(); } public function setEpisodeIdForRepliesOfEpisodePosts(): int | false { // make sure that posts in reply to episode activities have an episode id $postsToUpdate = $this->db->table(config('Fediverse')->tablesPrefix . 'posts as p1') ->join(config('Fediverse')->tablesPrefix . 'posts as p2', 'p1.id = p2.in_reply_to_id') ->select('p2.id, p1.episode_id') ->where([ 'p1.in_reply_to_id' => null, 'p2.in_reply_to_id IS NOT' => null, 'p2.episode_id' => null, 'p1.episode_id IS NOT' => null, ]) ->get() ->getResultArray(); if ($postsToUpdate !== []) { $postModel = new self(); $postModel->uuidUseBytes = false; return $postModel->updateBatch($postsToUpdate, 'id'); } return 0; } }
modules/Admin/Controllers/SettingsController.php +86 −65 Original line number Diff line number Diff line Loading @@ -10,11 +10,13 @@ declare(strict_types=1); namespace Modules\Admin\Controllers; use App\Entities\Media\Image; use App\Models\ActorModel; use App\Models\EpisodeCommentModel; use App\Models\EpisodeModel; use App\Models\MediaModel; use App\Models\PersonModel; use App\Models\PodcastModel; use App\Models\PostModel; use CodeIgniter\Files\File; use CodeIgniter\HTTP\RedirectResponse; use PHP_ICO; Loading Loading @@ -158,8 +160,23 @@ class SettingsController extends BaseController public function runHousekeeping(): RedirectResponse { if ($this->request->getPost('reset_counts') === 'yes') { // recalculate fediverse counts (new ActorModel())->resetFollowersCount(); (new ActorModel())->resetPostsCount(); (new PostModel())->setEpisodeIdForRepliesOfEpisodePosts(); (new PostModel())->resetFavouritesCount(); (new PostModel())->resetReblogsCount(); (new PostModel())->resetRepliesCount(); (new EpisodeModel())->resetCommentsCount(); (new EpisodeModel())->resetPostsCount(); (new EpisodeCommentModel())->resetLikesCount(); (new EpisodeCommentModel())->resetRepliesCount(); } helper('media'); if ($this->request->getPost('rewrite_media') === 'yes') { // Delete all podcast image sizes to recreate them $allPodcasts = (new PodcastModel())->findAll(); foreach ($allPodcasts as $podcast) { Loading Loading @@ -187,7 +204,10 @@ class SettingsController extends BaseController $allImages = (new MediaModel('image'))->getAllOfType(); foreach ($allImages as $image) { if (str_starts_with($image->file_path, 'podcasts')) { if (str_ends_with($image->file_path, 'banner.jpg') || str_ends_with($image->file_path, 'banner.png')) { if (str_ends_with($image->file_path, 'banner.jpg') || str_ends_with( $image->file_path, 'banner.png' )) { $image->sizes = config('Images') ->podcastBannerSizes; } else { Loading Loading @@ -248,6 +268,7 @@ class SettingsController extends BaseController } } } } return redirect('settings-general')->with('message', lang('Settings.housekeeping.runSuccess')); } Loading