Background
I am in the process of upgrading a quite old WonderCMS installation (3.0.4) and hit this problem.
Fixed here
main...hightowe:wondercms-subpage-bugfix:main
Description
A PHP Fatal error occurs when attempting to create or save a subpage in WonderCMS (v3.6.0) if the parent page was created in an older version of WonderCMS that did not explicitly initialize the subpages property in database.js.
When the parent page lacks the subpages key, the code attempts to descend into it, resulting in a null value. Subsequent attempts to assign properties to this null object trigger a Fatal Error.
Error Trace
PHP Fatal error: Uncaught Error: Attempt to assign property "testsubpage" on null in index.php:798
Stack trace:
#0 index.php(2656): Wcms->createPage()
#1 index.php(164): Wcms->saveAction()
#2 index.php(15): Wcms->init()
Additionally, several PHP warnings are triggered in findAndUpdateMenuKey due to null values being passed to explode() and foreach().
Root Cause
The core issue is that many existing WonderCMS installations have a database.js where pages do not have a subpages key. The current code assumes this key always exists after a depth of 1, which fails on legacy data or after certain upgrade paths.
Proposed Fix
The fix involves adding surgical property_exists checks and ensuring that the subpages property is initialized as a stdClass before assignment. This ensures compatibility with older database structures without requiring a full database migration.
Key Changes:
- createPage(): Add
property_exists checks before descending into child pages.
- findAndUpdateMenuKey(): Ensure the menu key is cast to a string and return an empty array if null to prevent
foreach warnings.
- Initialization: Use the internal
self::DB_PAGES_SUBPAGE_KEY constant consistently.
Impact
This affects users who have upgraded their WonderCMS installation over time and are now trying to utilize subpage functionality on older parent pages.
Background
I am in the process of upgrading a quite old WonderCMS installation (3.0.4) and hit this problem.
Fixed here
main...hightowe:wondercms-subpage-bugfix:main
Description
A PHP Fatal error occurs when attempting to create or save a subpage in WonderCMS (v3.6.0) if the parent page was created in an older version of WonderCMS that did not explicitly initialize the
subpagesproperty in database.js.When the parent page lacks the
subpageskey, the code attempts to descend into it, resulting in anullvalue. Subsequent attempts to assign properties to thisnullobject trigger a Fatal Error.Error Trace
Additionally, several PHP warnings are triggered in findAndUpdateMenuKey due to
nullvalues being passed toexplode()andforeach().Root Cause
The core issue is that many existing WonderCMS installations have a database.js where pages do not have a
subpageskey. The current code assumes this key always exists after a depth of 1, which fails on legacy data or after certain upgrade paths.Proposed Fix
The fix involves adding surgical
property_existschecks and ensuring that thesubpagesproperty is initialized as astdClassbefore assignment. This ensures compatibility with older database structures without requiring a full database migration.Key Changes:
property_existschecks before descending into child pages.foreachwarnings.self::DB_PAGES_SUBPAGE_KEYconstant consistently.Impact
This affects users who have upgraded their WonderCMS installation over time and are now trying to utilize subpage functionality on older parent pages.