HummingBirdAnimeClient/src/AnimeClient/Command/ClearThumbnails.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2018-11-09 10:38:35 -05:00
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu to manage anime and manga watch lists
*
2020-12-10 17:06:50 -05:00
* PHP version 7.4+
2018-11-09 10:38:35 -05:00
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
2020-01-08 15:39:49 -05:00
* @copyright 2015 - 2020 Timothy J. Warren
2018-11-09 10:38:35 -05:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2018-11-09 10:38:35 -05:00
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Command;
/**
* Clears out image cache directories
*/
class ClearThumbnails extends BaseCommand {
public function execute(array $args, array $options = []): void
{
$this->clearThumbs();
$this->echoBox('All cached images have been removed');
}
private function clearThumbs(): void
{
$imgDir = realpath(__DIR__ . '/../../public/images');
$paths = [
'anime/*.jpg',
'anime/*.png',
'anime/*.webp',
2018-11-09 10:38:35 -05:00
'avatars/*.gif',
'avatars/*.jpg',
'avatars/*.png',
'avatars/*.webp',
'characters/*.jpg',
'characters/*.png',
'characters/*.webp',
'manga/*.jpg',
'manga/*.png',
'manga/*.webp',
2018-11-09 10:38:35 -05:00
'people/*.jpg',
'people/*.png',
'people/*.webp',
];
foreach($paths as $path)
{
$cmd = "find {$imgDir} -path \"*/{$path}\" | xargs rm -f";
2018-11-09 10:38:35 -05:00
exec($cmd);
}
}
}