civicrm / civicrm-setup

MIT License
7 stars 5 forks source link

(docs) Clarify how installers can override model values #15

Open totten opened 6 years ago

totten commented 6 years ago

Background: The installation process blends together (a) values autodetected by the plugins with (b) values supplied by the installer.

Issue: The signature of Civi\Setup::init($modelValues) is misleading (as indicated by the existence of #14) -- it implies that any fields can be passed to init(...), but it really only works for a couple fields (cms, setupPath). If you try to set other values (db, cmsDb, components, et al), then the autodetection logic may override them.

The more general way to to manipulate the model is to let the autodetection run first:

Civi\Setup::init(['cms' => ..., 'setupPath' => ..., 'srcPath' => ...]);

And then get a reference to the model object:

$model = Civi\Setup::instance()->getModel();

And update its properties:

// Update some properties of the model
$model->db = ['server'=>'localhost:3306', 'username'=>'admin', 'password'=>'s3cr3t', 'database'=>'mydb'];
$model->cmsDb = ['server'=>'localhost:3306', 'username'=>'admin', 'password'=>'s3cr3t', 'database'=>'mydb'];

// Or, if you prefer arrays...
$model->setValues([
  'db' => ['server'=>'localhost:3306', 'username'=>'admin', 'password'=>'s3cr3t', 'database'=>'mydb'],
  'cmsDb' => ['server'=>'localhost:3306', 'username'=>'admin', 'password'=>'s3cr3t', 'database'=>'mydb'],
]);

See also: https://github.com/civicrm/civicrm-setup/pull/14#issuecomment-394559611