Files
wticreatorstudio/Modules/StudioPlus/Console/CleanupTemporaryUserVideoUploads.php
T
2024-02-12 22:54:20 -05:00

92 lines
2.6 KiB
PHP

<?php
namespace Modules\StudioPlus\Console;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Modules\StudioPlus\Entities\StudioPlusVideo;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class CleanupTemporaryUserVideoUploads extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'cleanup-temporary-user-video-uploads';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete the temporary user video uploads.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$users = Storage::allDirectories($this->getTempStoragePath());
foreach ($users as $user) {
$sessions = Storage::allDirectories($user);
foreach ($sessions as $session) {
$uploads = Storage::allDirectories($session);
foreach ($uploads as $upload) {
Log::channel('tracing')->info(basename($upload));
$basename = basename($upload);
$video = StudioPlusVideo::where('video_url', 'LIKE', "%$basename%")->first();
if ($video) {
Log::channel('tracing')->info('Inuse');
} else {
Log::channel('tracing')->info('Can be safely deleted.');
Storage::deleteDirectory($upload);
Log::channel('tracing')->info('Temp upload has been deleted.');
}
Log::channel('tracing')->info('===========');
}
}
/*$object_name = Storage::get($file);
$current_timestamp = Carbon::now()->timestamp;
$timestamp = filemtime(storage_path("app/$file"));
$time_passed = $current_timestamp - $timestamp;
if ($time_passed > $this->expiration) {
Log::channel('video-link-creation')->info("[Cleanup] Deleting $object_name");
$this->deleteTemporaryVideoLink($object_name);
Storage::delete($file);
Log::channel('video-link-creation')->info('[Cleanup] Deleted successfully.');
}*/
}
}
protected function getTempStoragePath()
{
return "CreatorStudio/temp/user";
}
}