- Update namespace from OCA\NCdiscordhook to OCA\Ncbotwebhooks - Update app ID, name, and namespace in appinfo/info.xml - Update composer.json and autoload files - Update CLI command names from ncdiscordhook:* to nc_bot_webhooks:* - Update image directory name to nc_bot_webhooks-images - Update documentation in README.md and INSTALL.md - Update JavaScript APP_ID and navigation provider paths - Update admin settings and controller app references
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace OCA\Ncbotwebhooks\Cron;
|
|
|
|
use OCA\Ncbotwebhooks\Service\TalkService;
|
|
use OCP\BackgroundJob\IJob;
|
|
use OCP\Files\IRootFolder;
|
|
use OCP\IConfig;
|
|
use OCP\IUserManager;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class ImageCleanup implements IJob {
|
|
private TalkService $talkService;
|
|
private IRootFolder $rootFolder;
|
|
private IUserManager $userManager;
|
|
private LoggerInterface $logger;
|
|
|
|
public function __construct(
|
|
TalkService $talkService,
|
|
IRootFolder $rootFolder,
|
|
IUserManager $userManager,
|
|
LoggerInterface $logger,
|
|
) {
|
|
$this->talkService = $talkService;
|
|
$this->rootFolder = $rootFolder;
|
|
$this->userManager = $userManager;
|
|
$this->logger = $logger;
|
|
}
|
|
|
|
public function run($argument = null): void {
|
|
// Check if bot user exists
|
|
$bot = $this->userManager->get('talk-bot');
|
|
if (!$bot) {
|
|
return;
|
|
}
|
|
|
|
// Check if images directory exists
|
|
try {
|
|
$userFolder = $this->rootFolder->getUserFolder($bot->getUID());
|
|
$imagesDir = $userFolder->getFolder('nc_bot_webhooks-images');
|
|
} catch (\Exception $e) {
|
|
return;
|
|
}
|
|
|
|
$count = $this->talkService->purgeOldImages();
|
|
|
|
if ($count > 0) {
|
|
$this->logger->info(
|
|
'NCbotwebhooks: purged ' . $count . ' old image files',
|
|
['app' => 'nc_bot_webhooks'],
|
|
);
|
|
}
|
|
}
|
|
}
|