HummingBirdAnimeClient/src/AnimeClient/Command/ClearThumbnails.php

60 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
*
2021-02-04 11:57:01 -05:00
* PHP version 8
2018-11-09 10:38:35 -05:00
*
* @package HummingbirdAnimeClient
2022-03-04 12:32:17 -05:00
* @author Timothy J. Warren <tim@timshome.page>
* @copyright 2015 - 2022 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
{
2018-11-09 10:38:35 -05:00
public function execute(array $args, array $options = []): void
{
$this->clearThumbs();
$this->echoBox('All cached images have been removed');
}
private function clearThumbs(): void
{
2021-02-03 09:46:36 -05:00
$imgDir = dirname(__DIR__, 3) . '/public/images';
2018-11-09 10:38:35 -05:00
$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)
2018-11-09 10:38:35 -05:00
{
$cmd = "find {$imgDir} -path \"*/{$path}\" | xargs rm -f";
2018-11-09 10:38:35 -05:00
exec($cmd);
}
}
}