Files
rspade_system/app/RSpade/Commands/Rsx/RsxFileDetachCommand.php
root 77b4d10af8 Refactor filename naming system and apply convention-based renames
Standardize settings file naming and relocate documentation files
Fix code quality violations from rsx:check
Reorganize user_management directory into logical subdirectories
Move Quill Bundle to core and align with Tom Select pattern
Simplify Site Settings page to focus on core site information
Complete Phase 5: Multi-tenant authentication with login flow and site selection
Add route query parameter rule and synchronize filename validation logic
Fix critical bug in UpdateNpmCommand causing missing JavaScript stubs
Implement filename convention rule and resolve VS Code auto-rename conflict
Implement js-sanitizer RPC server to eliminate 900+ Node.js process spawns
Implement RPC server architecture for JavaScript parsing
WIP: Add RPC server infrastructure for JS parsing (partial implementation)
Update jqhtml terminology from destroy to stop, fix datagrid DOM preservation
Add JQHTML-CLASS-01 rule and fix redundant class names
Improve code quality rules and resolve violations
Remove legacy fatal error format in favor of unified 'fatal' error type
Filter internal keys from window.rsxapp output
Update button styling and comprehensive form/modal documentation
Add conditional fly-in animation for modals
Fix non-deterministic bundle compilation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-13 19:10:02 +00:00

98 lines
2.6 KiB
PHP
Executable File

<?php
/**
* CODING CONVENTION:
* This file follows the coding convention where variable_names and function_names
* use snake_case (underscore_wherever_possible).
*/
namespace App\RSpade\Commands\Rsx;
use Illuminate\Console\Command;
use Rsx\Models\File_Attachment_Model;
use App\RSpade\Core\Locks\RsxLocks;
/**
* File Detach Command
* ====================
*
* PURPOSE:
* Detach a file from its parent model (sets fileable_type/id to NULL).
*
* WARNING:
* Detached files become orphans and may be deleted by cleanup operations
* after 24 hours if not re-attached to a model.
*
* LOCKING:
* Uses file write lock to ensure atomic operation.
*/
class RsxFileDetachCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rsx:file:detach {key : 64-char hex attachment key}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Detach file from its parent model';
/**
* Execute the console command.
*/
public function handle()
{
$key = $this->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);
}
}
}