argument('key'); // Find attachment $attachment = File_Attachment_Model::where('key', $key)->first(); if (!$attachment) { $this->error("Error: File attachment not found with key: {$key}"); return 1; } // Check if already detached if (!$attachment->fileable_type && !$attachment->fileable_id) { $this->info("File is already detached from any model"); return 0; } $attached_to = "{$attachment->fileable_type}:{$attachment->fileable_id}"; // Acquire file write lock $lock = RsxLocks::get_lock( RsxLocks::SERVER_LOCK, RsxLocks::LOCK_FILE_WRITE, RsxLocks::WRITE_LOCK, 30 ); try { $attachment->fileable_type = null; $attachment->fileable_id = null; $attachment->save(); $this->info(''); $this->info('[OK] File detached from model'); $this->info(''); $this->info(" File: {$attachment->file_name}"); $this->info(" Key: {$attachment->key}"); $this->info(" Was Attached: {$attached_to}"); $this->info(''); $this->warn('Warning: This file is now orphaned and may be deleted by cleanup'); $this->warn(' operations after 24 hours if not re-attached.'); $this->info(''); return 0; } finally { RsxLocks::release_lock($lock); } } }