I finally found the time to look at how the process I suggested affects the database. Unless you set them explicitly, the createdon
, createdby
, alias
, and publishedon
(if you set published
to 1) fields are not set. The publish_default
and automatic_alias
System Settings are ignored, as are the other defaults like richtext
, hidemenu
, searchable
, etc.
In addition, the normal events, OnBeforeDocFormSave
and OnDocFormSave
are not fired, so any plugins attached to those events will not execute.
A much better method is to just use the resource/create
processor:
/* Article Creation Code */
$articleFields = array(
/* set this to the ID of an Articles Container */
'parent' => 12, /* Required */
/* set this to the ID of the Article Template
(*not* the Articles container template) */
'template' => 122, /* Required */
'pagetitle' => 'Blog5', /* Required */
'class_key' => 'Article', /* Required */
'content' => '<h3>Blog 5</h3>', /* Optional */
);
$modx->runProcessor('resource/create', $articleFields);
The other fields will be set automatically, though you’re free to set them yourself if you don’t want the defaults or have other fields to set (e.g., introtext
or description
).
The System Setting defaults (including automatic_alias
) will be honored.
And if you set published
to 1
, the publishedon
and publishedby
fields will be set.
You may also want to set the createdby
and publishedby
fields to the ID of a user other than the admin.
The events will be fired and any relevant plugins will execute.
Note that the process may throw a few harmless warning and info messages, but normally, you won’t see them.