mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-11 02:36:42 +02:00
feat: add task to housekeeping setting for resetting all instance counts
set two toggle switches to run housekeeping tasks seperately if needed
This commit is contained in:
parent
e65e236bbc
commit
9303e51bc5
16 changed files with 348 additions and 85 deletions
|
|
@ -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;
|
||||
|
|
@ -158,93 +160,112 @@ 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');
|
||||
|
||||
// Delete all podcast image sizes to recreate them
|
||||
$allPodcasts = (new PodcastModel())->findAll();
|
||||
foreach ($allPodcasts as $podcast) {
|
||||
$podcastImages = glob(media_path("/podcasts/{$podcast->handle}/*_*{jpg,png,webp}"), GLOB_BRACE);
|
||||
if ($this->request->getPost('rewrite_media') === 'yes') {
|
||||
|
||||
if ($podcastImages) {
|
||||
foreach ($podcastImages as $podcastImage) {
|
||||
if (is_file($podcastImage)) {
|
||||
unlink($podcastImage);
|
||||
// Delete all podcast image sizes to recreate them
|
||||
$allPodcasts = (new PodcastModel())->findAll();
|
||||
foreach ($allPodcasts as $podcast) {
|
||||
$podcastImages = glob(media_path("/podcasts/{$podcast->handle}/*_*{jpg,png,webp}"), GLOB_BRACE);
|
||||
|
||||
if ($podcastImages) {
|
||||
foreach ($podcastImages as $podcastImage) {
|
||||
if (is_file($podcastImage)) {
|
||||
unlink($podcastImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete all person image sizes to recreate them
|
||||
$personsImages = glob(media_path('/persons/*_*{jpg,png,webp}'), GLOB_BRACE);
|
||||
if ($personsImages) {
|
||||
foreach ($personsImages as $personsImage) {
|
||||
if (is_file($personsImage)) {
|
||||
unlink($personsImage);
|
||||
// Delete all person image sizes to recreate them
|
||||
$personsImages = glob(media_path('/persons/*_*{jpg,png,webp}'), GLOB_BRACE);
|
||||
if ($personsImages) {
|
||||
foreach ($personsImages as $personsImage) {
|
||||
if (is_file($personsImage)) {
|
||||
unlink($personsImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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')) {
|
||||
$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'
|
||||
)) {
|
||||
$image->sizes = config('Images')
|
||||
->podcastBannerSizes;
|
||||
} else {
|
||||
$image->sizes = config('Images')
|
||||
->podcastCoverSizes;
|
||||
}
|
||||
} elseif (str_starts_with($image->file_path, 'persons')) {
|
||||
$image->sizes = config('Images')
|
||||
->podcastBannerSizes;
|
||||
} else {
|
||||
$image->sizes = config('Images')
|
||||
->podcastCoverSizes;
|
||||
->personAvatarSizes;
|
||||
}
|
||||
} elseif (str_starts_with($image->file_path, 'persons')) {
|
||||
$image->sizes = config('Images')
|
||||
->personAvatarSizes;
|
||||
$image->setFile(new File(media_path($image->file_path)));
|
||||
|
||||
(new MediaModel('image'))->updateMedia($image);
|
||||
}
|
||||
$image->setFile(new File(media_path($image->file_path)));
|
||||
|
||||
(new MediaModel('image'))->updateMedia($image);
|
||||
}
|
||||
$allAudio = (new MediaModel('audio'))->getAllOfType();
|
||||
foreach ($allAudio as $audio) {
|
||||
$audio->setFile(new File(media_path($audio->file_path)));
|
||||
|
||||
$allAudio = (new MediaModel('audio'))->getAllOfType();
|
||||
foreach ($allAudio as $audio) {
|
||||
$audio->setFile(new File(media_path($audio->file_path)));
|
||||
(new MediaModel('audio'))->updateMedia($audio);
|
||||
}
|
||||
|
||||
(new MediaModel('audio'))->updateMedia($audio);
|
||||
}
|
||||
$allTranscripts = (new MediaModel('transcript'))->getAllOfType();
|
||||
foreach ($allTranscripts as $transcript) {
|
||||
$transcript->setFile(new File(media_path($transcript->file_path)));
|
||||
|
||||
$allTranscripts = (new MediaModel('transcript'))->getAllOfType();
|
||||
foreach ($allTranscripts as $transcript) {
|
||||
$transcript->setFile(new File(media_path($transcript->file_path)));
|
||||
(new MediaModel('transcript'))->updateMedia($transcript);
|
||||
}
|
||||
|
||||
(new MediaModel('transcript'))->updateMedia($transcript);
|
||||
}
|
||||
$allChapters = (new MediaModel('chapters'))->getAllOfType();
|
||||
foreach ($allChapters as $chapters) {
|
||||
$chapters->setFile(new File(media_path($chapters->file_path)));
|
||||
|
||||
$allChapters = (new MediaModel('chapters'))->getAllOfType();
|
||||
foreach ($allChapters as $chapters) {
|
||||
$chapters->setFile(new File(media_path($chapters->file_path)));
|
||||
(new MediaModel('chapters'))->updateMedia($chapters);
|
||||
}
|
||||
|
||||
(new MediaModel('chapters'))->updateMedia($chapters);
|
||||
}
|
||||
$allVideos = (new MediaModel('video'))->getAllOfType();
|
||||
foreach ($allVideos as $video) {
|
||||
$video->setFile(new File(media_path($video->file_path)));
|
||||
|
||||
$allVideos = (new MediaModel('video'))->getAllOfType();
|
||||
foreach ($allVideos as $video) {
|
||||
$video->setFile(new File(media_path($video->file_path)));
|
||||
(new MediaModel('video'))->updateMedia($video);
|
||||
}
|
||||
|
||||
(new MediaModel('video'))->updateMedia($video);
|
||||
}
|
||||
// reset avatar and banner image urls for each podcast actor
|
||||
foreach ($allPodcasts as $podcast) {
|
||||
$actorModel = new ActorModel();
|
||||
$actor = $actorModel->getActorById($podcast->actor_id);
|
||||
|
||||
// reset avatar and banner image urls for each podcast actor
|
||||
foreach ($allPodcasts as $podcast) {
|
||||
$actorModel = new ActorModel();
|
||||
$actor = $actorModel->getActorById($podcast->actor_id);
|
||||
if ($actor !== null) {
|
||||
// update values
|
||||
$actor->avatar_image_url = $podcast->cover->federation_url;
|
||||
$actor->avatar_image_mimetype = $podcast->cover->file_mimetype;
|
||||
$actor->cover_image_url = $podcast->banner->federation_url;
|
||||
$actor->cover_image_mimetype = $podcast->banner->file_mimetype;
|
||||
|
||||
if ($actor !== null) {
|
||||
// update values
|
||||
$actor->avatar_image_url = $podcast->cover->federation_url;
|
||||
$actor->avatar_image_mimetype = $podcast->cover->file_mimetype;
|
||||
$actor->cover_image_url = $podcast->banner->federation_url;
|
||||
$actor->cover_image_mimetype = $podcast->banner->file_mimetype;
|
||||
|
||||
if ($actor->hasChanged()) {
|
||||
$actorModel->update($actor->id, $actor);
|
||||
if ($actor->hasChanged()) {
|
||||
$actorModel->update($actor->id, $actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue