rsanchez / eecli

Command line interface for ExpressionEngine
MIT License
37 stars 13 forks source link

Add create channel entry command #22

Open iainsaxon opened 9 years ago

iainsaxon commented 9 years ago

This is perhaps classified as a work in progress in its current state but it is functional for simpler custom fields such as Wygwam, text inputs, text areas, RTE fields, etc.

Grids, Matrixes, Assets, relationships, etc need to have their data formed exactly as expected to be successfully created.

I tried using the Content_publish controller but had to use the Channel Entries API instead because there are some important properties on the controller that are private and therefore break functionality when attempting to extend the object.

The API approach works well in most cases and there is some simple key to ID conversions that assist when creating entries using this command.

This is an example of the create:channel_entry command when receiving piped JSON content:

echo '{"cf_movie_synopsis": "Neo (Keanu Reeves) believes that Morpheus (Laurence Fishburne), an elusive figure considered to be the most dangerous man alive, can answer his question -- What is the Matrix?", "cf_movie_rating": 5}' | ./bin/eecli create:channel_entry "The Matrix" movies --url_title="the-matrix-1999" --status="pending" --author="johndoe" --categories=action --categories=scifi --stdin

The channels, statuses, categories and author names will need to exist in the database first otherwise the command will throw an exception to prevent potentially broken data from entering the system. The IDs can be used as an alternative but I suspect the names will be a more widely used approach to entering the data.

Testing automation may benefit from a command like this as EE entries with simple placeholder data and category assignments can be inserted via EECLI so that testing tools can ensure the pages appear on the site properly.