misuzu/tools/purge-user-uploads

24 lines
1,001 B
PHP
Executable file

#!/usr/bin/env php
<?php
require_once __DIR__ . '/../misuzu.php';
if(empty($msz->storageCtx->filesCtx->storage->localPath))
die(sprintf('No storage path is specified.%s', PHP_EOL));
if(!is_dir($msz->storageCtx->filesCtx->storage->localPath))
die(sprintf('Storage directory does not exist.%s', PHP_EOL));
if(fileowner($msz->storageCtx->filesCtx->storage->localPath) !== posix_getuid())
die(sprintf('Script must be run as the owner of the storage directory.%s', PHP_EOL));
if($argc <= 1)
die(sprintf('No uploader ID specified.%s', PHP_EOL));
$userId = $argv[1];
try {
printf('Attempting to delete uploads by user #%s...%s', $userId, PHP_EOL);
$msz->storageCtx->uploadsCtx->uploads->deleteUploadsByUser($userId);
printf('Done! Actual purging of data in storage will be handled by the next cron cycle.%s', PHP_EOL);
} catch(Exception $ex) {
printf('Exception occurred while trying to delete user uploads:%s', PHP_EOL);
printf('%s%s', $ex->getMessage(), PHP_EOL);
}