Skip to content

Conversation

@vitorbb1989
Copy link

Título: fix(brandkit): resolve theme_slug + invalidate theme cache

Contexto
BrandKit estava gravando overrides/CSS com theme_slug = default quando o request não enviava theme_slug, mesmo com tema ativo diferente no DB (theme_configs.selected_theme). Resultado: “salva no admin, mas não aplica no tema ativo”.

Causa raiz
Fallback hardcoded em validateBase() usava 'default' ignorando:

preview de tema em sessão (theme_preview)

tema selecionado no DB (theme_configs.selected_theme)

Solução

Adicionado ThemeSlugResolver com precedência: preview > DB > default

Atualizado BrandKitControllerHelpers para usar o resolver

Listener InvalidateThemeCacheOnUpdate registrado em theme.update.after para invalidar cache imediatamente ao trocar tema

Override upgrade-safe de ThemeConfig para permitir selected_theme fillable (quando aplicável)

Higiene: .gitignore para ignorar arquivos locais/junk (Claude + logs + nul)

Commits

05bdbe9 feat: ThemeSlugResolver

3070827 fix: BrandKit resolve theme_slug via resolver

313e127 fix: invalidate cache ao trocar tema

388f568 feat: ThemeConfig override (selected_theme fillable)

009e797 chore: ignore arquivos locais/junk

Validação

ThemeSlugResolver::resolve() retorna slug do tema ativo

Override criado sem theme_slug grava com tema ativo no DB

Troca de tema reflete imediatamente (listener)

Sem alterações em packages/Webkul/* ou vendor/* (upgrade-safe)

Rollback
Reverter commits individualmente (especialmente listener e resolver) sem impacto no core.

vitorbb1989 and others added 23 commits December 21, 2025 04:27
Add complete ThemeManager package that enables comprehensive visual
customization of Krayin CRM including colors, logos, login page, and
empty states.

Features:
- Theme activation/deactivation toggle
- Primary color customization (6 color options)
- Logo management (main, light, icon, favicon)
- Login page customization (background, card, overlay)
- Empty state images for all modules
- CSS injection via middleware
- Bilingual support (EN/PT-BR)
- File upload with proper storage handling
- Cache management for performance

Technical Implementation:
- Full Concord module integration
- Repository pattern for data access
- Middleware for CSS injection
- Helper facade for theme access
- Database singleton pattern
- PSR-4 autoloading
- Storage symlink support

Configuration:
- Registered in composer.json autoload
- Added to config/app.php providers
- Registered in config/concord.php modules
- Migration for theme_configs table

Bug Fixes Applied:
- Fixed "Theme Active" select showing blank value
- Fixed logo implementation via CSS content replacement
- Fixed button visibility with proper color defaults
- Created storage symlink for file accessibility

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

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
… support

## Theme System Core
- Add ThemeCache helper for centralized cache management (v2 keys)
- Add ThemeConfigResolver for deterministic config resolution
- Add ThemeContext value object for type-safe theme data
- Add ThemeContextFactory with preview support

## Middlewares
- Add HandleThemePreview for session-based preview (?theme_preview=slug)
- Add ShareThemeContext to share theme data with views
- Add CaptureThemeSelection to capture theme selection on save
- Add ThemePermission for ACL protection

## Controllers & Routes
- Add ThemeController with restore/rollback actions
- Add routes for /admin/settings/theme/restore and /rollback

## Views (Upgrade-safe overrides)
- Override anonymous.blade.php for themed login layout
- Override login.blade.php for custom login styling
- Override theme-head.blade.php for CSS variables
- Override theme/index.blade.php for preview/rollback UI

## Configuration
- Add config/acl-theme.php for permissions
- Add migrations for selected_theme and previous_theme columns

## Testing & Documentation
- Add 26 unit tests for ThemeContextFactory (all passing)
- Add docs/ reorganized structure
- Add RUNBOOK_THEME_SMOKE.md for post-deploy validation
- Add CHANGELOG_THEME_REFACTORING.md
- Add tools/deploy-theme.sh for automated deployment

## Technical Details
- Precedence: DB (if active) > theme.json > defaults
- Preview uses session (not cache) for user isolation
- Zero side-effects in resolver (no DB writes on fallback)
- Zero edits to packages/ (upgrade-safe)

Tag: theme-refactor-v1
- Add multi-stage Dockerfile optimized for PHP 8.2 + Laravel
- Add docker-compose.yml for local development
- Add docker-stack.yml for Docker Swarm production deployment
- Add Nginx configuration with security headers and rate limiting
- Add PHP-FPM configuration with OPcache optimization
- Add entrypoint and healthcheck scripts
- Add supervisord configuration for queue workers
- Add comprehensive Docker Swarm deployment documentation
- Add .dockerignore for optimized build context
- Environment matrix (local/staging/prod)
- Cache driver configuration (Redis recommended)
- Queue driver with Supervisor setup
- Storage and filesystem structure
- File permissions guide (Linux)
- Nginx configuration (complete)
- Apache configuration with VirtualHost
- PHP configuration and extensions
- Deploy checklist with automation script
- Environment troubleshooting guide
- Runbook krayin#11: View não atualiza (blade cache, OPcache, vendor publish)
- Runbook krayin#12: Assets/Versionamento (Vite build, manifest, CDN cache)
- Runbook krayin#13: Migration travou/Rollback (status, rollback, foreign keys)

Includes checklists, common errors, and specific scenarios for each
- Internal modules (Repository, Resolver, Validator, ThemeContext)
- Cache keys and patterns
- Folder structure conventions
- Naming conventions (PHP, DB, routes, views)
- Domain terminology (BrandKit, Override, Preset, Scope, Snapshot)
- Database tables schema
- Events and Jobs (planned)
- Configuration reference (env, config, KEY_MAP)
- Quick reference commands and API URLs
- Root identification and verification
- Complete folder tree (3 levels)
- Git status (modified, deleted, untracked files)
- Version info (PHP 8.2, Laravel 10, dependencies)
- Storage structure (themes and uploads)
- Grep inventory for BrandKit patterns
- Environment config (.env without secrets)
- Cache/Session/Queue configurations
- Documentation listing
- Validation checklist with identified issues
- Risks and rollback procedures
- Initial triage answers
Removed:
- routes/brand-kit.php (not loaded, routes defined elsewhere)
- app/Http/Controllers/BrandKitController.php (monolithic, replaced by split controllers)
- app/Support/BrandKitRepository.php (duplicate, using app/Repositories/ instead)

Active components:
- Controllers: app/Http/Controllers/Admin/BrandKit/*
- Repository: app/Repositories/BrandKitRepository.php
ThemeContext:
- Add logo(type) method for views
- Add showPoweredBy() method
- Add inPreviewMode() method (alias for isPreview)

Views:
- Create resources/views/vendor/admin/brandkit/index.blade.php

AppServiceProvider:
- Add View Composer to inject availableThemes into theme-manager view
Phase 4 - Hardening & Production Ready:

- Add 77 unit tests for BrandKit/Theme system (~11s execution)
- Create BrandKitTestSchema trait for SQLite :memory: isolation
- Add GitHub Actions workflow for PR gate (tests.yml)
- Add GitHub Actions nightly workflow (tests-full.yml)
- Add GitLab CI equivalent (.gitlab-ci.yml)
- Add test runner scripts (PowerShell + Bash)
- Add composer scripts: test:brandkit, test:full
- Update theme-runbook.md with testing documentation

Test coverage:
- BrandKitResolverTest: 16 tests (precedence, CLEAR, casting)
- BrandKitSnapshotServiceTest: 12 tests (transactions, atomicity)
- BrandKitCacheInvalidatorTest: 6 tests (cache invalidation)
- PreviewSessionTest: 16 tests (isolation, expiration)
- ThemeContextFactoryTest: 26 tests (factory, config resolution)

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The BrandKitResolver tests were failing in GitHub Actions because
the storage/app/public/themes directory didn't exist. Added directory
creation in setUp() for both BrandKitResolverTest and
BrandKitCacheInvalidatorTest.

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@vitorbb1989 vitorbb1989 force-pushed the feat/brandkit-split-controllers branch from ae6b4fc to 7236a7c Compare December 29, 2025 01:55
@vitorbb1989 vitorbb1989 force-pushed the feat/brandkit-split-controllers branch from 1603d5f to 98055a3 Compare December 29, 2025 02:29
vitorbb1989 and others added 3 commits December 28, 2025 23:29
- Add full BrandKitController with overrides, snapshots, custom CSS
- Add ThemeAssetValidator for asset path validation
- Add ThemeConfigRepository methods for theme management
- Enhance ThemeContext and ThemeContextFactory with preview support
- Add production config and JSON API documentation
- Fix theme-runbook.md duplicate separator

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@vitorbb1989 vitorbb1989 deleted the feat/brandkit-split-controllers branch December 29, 2025 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant