In this post, we look at how to use CakePHP's Queue Plugin to efficiently manage and execute background tasks. We'll explore the structure, implementation, and benefits of this approach, with a focus on the `src/Job` directory and related components of Willow CMS.
Refactoring Model Layer Code in Willow CMS with CakePHP Behaviors
This post covers refactoring code related to the CakePHP Tree Behavior and slugs in Willow CMS. Originally, both Articles and Tags had duplicated code for tree operations. This was refactored into the OrderableBehavior, making the code reusable and testable. Similarly, slug management, previously scattered across multiple locations, was consolidated into the new SlugBehavior. This behavior handles slug generation, validation, and history, simplifying the ArticlesTable and TagsTable classes while adding features like automatic slug generation from titles, custom slugs, and slug history tracking for better SEO. This refactoring significantly reduced code duplication and improved maintainability and testability.
Migrations in CakePHP
Migrations are a tool in CakePHP for managing database schema changes. They provide a version-controlled way to modify your database structure, making it easier to track, share, and deploy changes across different environments or installations of your application. CakePHP has tools to generate snapshots of your database structure and migrations between them. Given that migrations can also execute query language statements on your database, they can also be used to modify data. Willow CMS has evolved through several releases since going live for this site, with some of those releases requiring changes to the database schema and data. In this post I'll talk you through some practical examples of how I handled this.
Simplifying Display of Images with PHP Traits and Magic Methods
In this technical deep-dive, we explore how combining PHP traits and magic methods can dramatically simplify image URL generation in a CMS. The article describes the implementation of ImageUrlTrait, a clever solution that replaces verbose, error-prone code with a clean, maintainable approach. By leveraging PHP's trait mechanism for code reuse and magic methods for dynamic property handling, the solution allows developers to easily access different image sizes through intuitive properties like $image->smallImageUrl or $image->largeImageUrl. The transformation from complex, nested HTML helper calls to a streamlined element-based approach demonstrates significant improvements in code readability and maintainability.
Rate Limiting and IP Blocking in Willow CMS
This blog post details the implementation of rate limiting and IP blocking within a Willow CMS, focusing on the key code components and their rationale. This information is intended for developers looking to implement similar security measures in their projects. Since putting Willow live for this site, it has been interesting to view the logs and see all the attempts from Singapore trying to find exploits!
PHPUnit Testing in Willow CMS
This comprehensive guide details how PHPUnit testing is implemented in Willow CMS, both locally and through GitHub Actions. The testing infrastructure includes 116 tests and 414 assertions, providing robust quality assurance. The setup revolves around five key components: a PHPUnit configuration file, GitHub Actions for continuous integration, shared test case code for DRY principles, controller tests for critical functionality, and code coverage reporting. The system uses random test execution to ensure independence and includes both admin and non-admin testing scenarios. The GitHub Actions workflow is particularly noteworthy, running tests across multiple PHP versions and incorporating various quality checks including PHPStan and PHP CodeSniffer.
About
Welcome to willowcms.app. This site uses Willow - a content management system I'm building in the open. Here you'll find development updates, feature highlights, and guides on using Willow for your own sites.