Files
rspade_system/app/RSpade/Commands/Rsx/RsxFileInfoCommand.php
root 29c657f7a7 Exclude tests directory from framework publish
Add 100+ automated unit tests from .expect file specifications
Add session system test
Add rsx:constants:regenerate command test
Add rsx:logrotate command test
Add rsx:clean command test
Add rsx:manifest:stats command test
Add model enum system test
Add model mass assignment prevention test
Add rsx:check command test
Add migrate:status command test

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-25 03:59:58 +00:00

161 lines
5.0 KiB
PHP

<?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;
/**
* File Info Command
* ==================
*
* PURPOSE:
* Display detailed information about a file attachment by its key.
*
* DISPLAYS:
* - File identification (key, name, extension)
* - File type and size
* - Storage information (hash, path)
* - Attachment metadata (category, type_meta, meta JSON)
* - Polymorphic relationship (if attached to model)
* - Site and user information
* - Timestamps
*/
class RsxFileInfoCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rsx:file:info {key : 64-char hex attachment key}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Display detailed information about a file attachment';
/**
* Execute the console command.
*/
public function handle()
{
$key = $this->argument('key');
// Find attachment by key
$attachment = File_Attachment_Model::where('key', $key)->first();
if (!$attachment) {
$this->error("Error: File attachment not found with key: {$key}");
return 1;
}
// Load relationships explicitly
$storage = null;
if ($attachment->file_storage_id) {
$storage = \App\Models\File_Storage_Model::find($attachment->file_storage_id);
}
$site = null;
if ($attachment->site_id) {
$site = \Rsx\Models\Site_Model::find($attachment->site_id);
}
// Display file information
$this->info('');
$this->info('File Attachment Information');
$this->info('===========================');
$this->info('');
$this->info('Identification:');
$this->info(" Key: {$attachment->key}");
$this->info(" Filename: {$attachment->file_name}");
$this->info(" Extension: {$attachment->file_extension}");
$this->info('');
$this->info('File Properties:');
$this->info(" Type: {$attachment->file_type_id_label}");
if ($storage) {
$this->info(" Size: {$storage->get_human_size()}");
$this->info(' MIME: ' . mime_content_type($storage->get_full_path()));
}
$this->info('');
if ($storage) {
$this->info('Storage:');
$this->info(" Hash: {$storage->hash}");
$this->info(" Path: {$storage->get_storage_path()}");
$this->info(' File Exists: ' . ($storage->file_exists() ? 'Yes' : 'No'));
// Count references
$ref_count = File_Attachment_Model::where('file_storage_id', $storage->id)->count();
$this->info(" References: {$ref_count}");
$this->info('');
}
if ($attachment->fileable_type) {
$this->info('Attached To:');
$this->info(" Model: {$attachment->fileable_type}");
$this->info(" Model ID: {$attachment->fileable_id}");
$this->info('');
}
if ($attachment->fileable_category || $attachment->fileable_type_meta || $attachment->fileable_meta) {
$this->info('Metadata:');
if ($attachment->fileable_category) {
$this->info(" Category: {$attachment->fileable_category}");
}
if ($attachment->fileable_type_meta) {
$this->info(" Type Meta: {$attachment->fileable_type_meta}");
}
if ($attachment->fileable_order !== null) {
$this->info(" Order: {$attachment->fileable_order}");
}
if ($attachment->fileable_meta) {
$meta = $attachment->get_meta();
$this->info(' Meta JSON: ' . json_encode($meta, JSON_PRETTY_PRINT));
}
$this->info('');
}
$this->info('Site:');
$this->info(" Site ID: {$attachment->site_id}");
if ($site) {
$this->info(" Site Name: {$site->name}");
}
$this->info('');
$this->info('Timestamps:');
$this->info(" Created: {$attachment->created_at}");
$this->info(" Updated: {$attachment->updated_at}");
if ($attachment->created_by) {
$this->info(" Created By: User #{$attachment->created_by}");
}
if ($attachment->updated_by) {
$this->info(" Updated By: User #{$attachment->updated_by}");
}
$this->info('');
$this->info('URLs:');
$this->info(" View: {$attachment->get_url()}");
$this->info(" Download: {$attachment->get_download_url()}");
$this->info('');
return 0;
}
}