# ZitiNexus UI File Organization Cleanup Script (PowerShell Version) # This script automatically fixes common file organization issues Write-Host "==============================================" -ForegroundColor Cyan Write-Host "ZitiNexus UI File Organization Cleanup" -ForegroundColor Cyan Write-Host "==============================================" -ForegroundColor Cyan Write-Host "" $FIXED = 0 $SKIPPED = 0 # Function to report fix function Report-Fix { param($Message) Write-Host "✅ FIXED: $Message" -ForegroundColor Green $script:FIXED++ } # Function to report skip function Report-Skip { param($Message) Write-Host "⏭️ SKIPPED: $Message" -ForegroundColor Yellow $script:SKIPPED++ } # Function to report info function Report-Info { param($Message) Write-Host "ℹ️ INFO: $Message" -ForegroundColor Cyan } Write-Host "Starting cleanup process..." -ForegroundColor White Write-Host "" # 1. Remove duplicate PHP files Write-Host "1. Removing duplicate PHP files..." -ForegroundColor White Write-Host "-----------------------------------" -ForegroundColor White if (Test-Path "UI\index.php") { try { Remove-Item "UI\index.php" -Force Report-Fix "Removed duplicate UI\index.php" } catch { Write-Host "❌ ERROR: Failed to remove UI\index.php - $($_.Exception.Message)" -ForegroundColor Red } } else { Report-Skip "UI\index.php does not exist" } if (Test-Path "UI\dashboard.php") { try { Remove-Item "UI\dashboard.php" -Force Report-Fix "Removed duplicate UI\dashboard.php" } catch { Write-Host "❌ ERROR: Failed to remove UI\dashboard.php - $($_.Exception.Message)" -ForegroundColor Red } } else { Report-Skip "UI\dashboard.php does not exist" } # 2. Remove test files directory Write-Host "" Write-Host "2. Removing test files directory..." -ForegroundColor White Write-Host "------------------------------------" -ForegroundColor White if (Test-Path "UI\testfiles") { try { # List files being removed $TestFiles = Get-ChildItem "UI\testfiles" -Recurse -File if ($TestFiles.Count -gt 0) { Report-Info "Files to be removed:" $TestFiles | ForEach-Object { Write-Host " - $($_.Name)" -ForegroundColor Gray } } Remove-Item "UI\testfiles" -Recurse -Force Report-Fix "Removed UI\testfiles directory and all contents" } catch { Write-Host "❌ ERROR: Failed to remove UI\testfiles - $($_.Exception.Message)" -ForegroundColor Red } } else { Report-Skip "UI\testfiles directory does not exist" } # 3. Remove debug files from public directory Write-Host "" Write-Host "3. Removing debug files from public directory..." -ForegroundColor White Write-Host "-------------------------------------------------" -ForegroundColor White $DebugFiles = @() $DebugFiles += Get-ChildItem "UI\public" -Filter "debug-*.php" -ErrorAction SilentlyContinue $DebugFiles += Get-ChildItem "UI\public" -Filter "test-*.php" -ErrorAction SilentlyContinue $DebugFiles += Get-ChildItem "UI\public" -Filter "*-debug.php" -ErrorAction SilentlyContinue if ($DebugFiles.Count -gt 0) { $DebugFiles | ForEach-Object { try { Remove-Item $_.FullName -Force Report-Fix "Removed debug file: $($_.Name)" } catch { Write-Host "❌ ERROR: Failed to remove $($_.Name) - $($_.Exception.Message)" -ForegroundColor Red } } } else { Report-Skip "No debug files found in public directory" } # 4. Remove any misplaced assets directory Write-Host "" Write-Host "4. Checking for misplaced assets directory..." -ForegroundColor White Write-Host "----------------------------------------------" -ForegroundColor White if (Test-Path "UI\assets") { try { # Check if it's empty or has content $AssetFiles = Get-ChildItem "UI\assets" -Recurse -File -ErrorAction SilentlyContinue if ($AssetFiles.Count -gt 0) { Report-Info "UI\assets contains files. Manual review recommended:" $AssetFiles | Select-Object -First 5 | ForEach-Object { Write-Host " - $($_.FullName)" -ForegroundColor Gray } if ($AssetFiles.Count -gt 5) { Write-Host " ... and $($AssetFiles.Count - 5) more files" -ForegroundColor Gray } Write-Host "⚠️ WARNING: UI\assets directory contains files. Please review and move to UI\public\assets\ if needed." -ForegroundColor Yellow } else { Remove-Item "UI\assets" -Recurse -Force Report-Fix "Removed empty UI\assets directory" } } catch { Write-Host "❌ ERROR: Failed to process UI\assets - $($_.Exception.Message)" -ForegroundColor Red } } else { Report-Skip "UI\assets directory does not exist" } # 5. Create missing directories if needed Write-Host "" Write-Host "5. Ensuring required directories exist..." -ForegroundColor White Write-Host "-----------------------------------------" -ForegroundColor White $RequiredDirs = @( "UI\public", "UI\includes", "UI\public\assets", "UI\public\assets\css", "UI\public\assets\js", "UI\logs" ) foreach ($Dir in $RequiredDirs) { if (!(Test-Path $Dir)) { try { New-Item -ItemType Directory -Path $Dir -Force | Out-Null Report-Fix "Created missing directory: $Dir" } catch { Write-Host "❌ ERROR: Failed to create $Dir - $($_.Exception.Message)" -ForegroundColor Red } } else { Report-Skip "$Dir already exists" } } # 6. Set proper file permissions (if running as administrator) Write-Host "" Write-Host "6. Checking file permissions..." -ForegroundColor White Write-Host "--------------------------------" -ForegroundColor White $IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") if ($IsAdmin) { try { # Set permissions for logs directory to be writable if (Test-Path "UI\logs") { $Acl = Get-Acl "UI\logs" $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("Everyone", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow") $Acl.SetAccessRule($AccessRule) Set-Acl "UI\logs" $Acl Report-Fix "Set write permissions for UI\logs directory" } } catch { Write-Host "⚠️ WARNING: Could not set permissions - $($_.Exception.Message)" -ForegroundColor Yellow } } else { Report-Info "Not running as administrator - skipping permission changes" } Write-Host "" Write-Host "==============================================" -ForegroundColor Cyan Write-Host "CLEANUP SUMMARY" -ForegroundColor Cyan Write-Host "==============================================" -ForegroundColor Cyan Write-Host "✅ Fixed: $FIXED items" -ForegroundColor Green Write-Host "⏭️ Skipped: $SKIPPED items" -ForegroundColor Yellow if ($FIXED -gt 0) { Write-Host "" Write-Host "🎉 Cleanup completed successfully!" -ForegroundColor Green Write-Host " $FIXED issue(s) have been resolved." -ForegroundColor Green Write-Host "" Write-Host "NEXT STEPS:" -ForegroundColor Cyan Write-Host "1. Run the audit script to verify fixes:" -ForegroundColor White Write-Host " powershell -ExecutionPolicy Bypass -File check-organization.ps1" -ForegroundColor Gray Write-Host "2. Test the UI to ensure everything works correctly" -ForegroundColor White Write-Host "3. Review UI\DEVELOPMENT_INSTRUCTIONS.md for ongoing best practices" -ForegroundColor White } else { Write-Host "" Write-Host "ℹ️ No issues found to fix." -ForegroundColor Cyan Write-Host " Your file organization appears to be correct already." -ForegroundColor Cyan } Write-Host "" Write-Host "For detailed guidelines, see: UI\DEVELOPMENT_INSTRUCTIONS.md" -ForegroundColor Cyan Write-Host "==============================================" -ForegroundColor Cyan