This document describes the enhanced update functionality in MODX CLI that allows for partial updates without requiring all fields to be specified.
All update commands in MODX CLI have been enhanced to support partial updates. This means you only need to specify the ID of the object you want to update and the fields you want to change. The CLI automatically fetches the existing object data to populate any required fields that aren't specified.
The following update commands have been improved:
category:update- Update MODX categorieschunk:update- Update MODX chunkscontext:update- Update MODX contextscontext:setting:update- Update context settingscontext:permissions:update- Update context permissionsns:update- Update MODX namespacesresource:update- Update MODX resourcessnippet:update- Update MODX snippetssource:update- Update media sourcestemplate:update- Update MODX templatestv:update- Update MODX template variables
Previously, update commands required you to specify all required fields, even if you only wanted to change one field:
# This would fail because --name was required
modx chunk:update 5 --description="New description"Now you can update any field without specifying all required fields:
# This now works - the CLI fetches existing data automatically
modx chunk:update 5 --description="New description"The enhancement works by:
- Pre-populating existing data: Before running the processor, the CLI fetches the existing object and pre-populates all its current values
- Selective overrides: Only the fields you specify in the command are overridden
- Type conversion: Boolean and integer fields are properly converted
- Error handling: Clear error messages if the object doesn't exist
- Critical field validation: For resources, ensures essential fields like
class_key,context_key, andcontent_typeare always properly set - Safety defaults: Automatically applies safe defaults for missing critical fields (e.g.,
class_keydefaults to 'modDocument')
Update only the description:
modx chunk:update 5 --description="Updated description"Update multiple fields:
modx chunk:update 5 --description="New description" --snippet="<p>New content</p>" --category=2Update boolean fields:
modx chunk:update 5 --locked=1 --static=0Update only the template name:
modx template:update 3 --templatename="New Template Name"Update content and category:
modx template:update 3 --content="<html>New content</html>" --category=1Update snippet code:
modx snippet:update 7 --snippet="<?php return 'Hello World';"Update name and description:
modx snippet:update 7 --name="MySnippet" --description="Updated snippet"Update default value:
modx tv:update 10 --default_text="New default"Update multiple properties:
modx tv:update 10 --caption="New Caption" --description="Updated TV" --type="textarea"Update template associations (comma-separated):
modx tv:update 10 --templates="1,2,3"Update page title:
modx resource:update 123 --pagetitle="New Page Title"Update multiple fields:
modx resource:update 123 --pagetitle="New Title" --content="New content" --published=1Change parent and template:
modx resource:update 123 --parent=5 --template=2Update alias (this was previously failing with null classKey error):
modx resource:update 6 --alias="about-us"Update context description:
modx context:update web --description="Public site context"Update source name:
modx source:update 2 --name="Uploads Source"Resource updates have been enhanced with special handling for critical MODX processor requirements:
- Automatic class_key handling: Ensures
class_keyis always set (defaults to 'modDocument') - Context validation: Ensures
context_keyis always set (defaults to 'web') - Content type handling: Ensures
content_typeis always set (defaults to 1) - Comprehensive field mapping: Pre-populates all essential resource fields including alias, content, hidemenu, searchable, and cacheable
This resolves previous issues where resource updates would fail with "null classKey" errors when updating specific fields.
Boolean fields (like published, locked, static, etc.) accept various formats:
1or0trueorfalseyesornoonoroff
Examples:
modx resource:update 123 --published=true
modx resource:update 123 --published=1
modx resource:update 123 --published=yesIf an object doesn't exist, you'll get a clear error message:
modx chunk:update 999 --description="test"
# Output: Chunk with ID 999 not foundAll update commands support JSON output for scripting:
modx chunk:update 5 --description="New description" --jsonThese enhancements are fully backward compatible. Existing scripts that specify all fields will continue to work exactly as before.
- Improved usability: No need to remember and specify all required fields
- Reduced errors: Less chance of accidentally overwriting fields with empty values
- Better workflow: More intuitive command-line experience
- Consistent behavior: All update commands work the same way
- Clear feedback: Better error messages when operations fail
- See List Commands for information about pagination support
- See SSH and Aliases for remote command execution
- See Internal API for programmatic usage