Merge pull request #20096 from larssandergreen/copy-template_type-when-cloning-mailing
[civicrm-core.git] / setup / src / Setup / Model.php
CommitLineData
4bcd4c62
TO
1<?php
2namespace Civi\Setup;
3
4/**
5 * Class Model
6 * @package Civi\Setup
7 *
8 * The `Model` defines the main options and inputs that are used to configure
9 * the installer.
10 *
11 * @property string $srcPath
12 * Path to CiviCRM-core source tree.
13 * Ex: '/var/www/sites/all/modules/civicrm'.
14 * @property string $setupPath
15 * Path to CiviCRM-setup source tree.
16 * Ex: '/var/www/sites/all/modules/civicrm/setup'.
17 * @property string $settingsPath
18 * Ex: '/var/www/sites/default/civicrm.settings.php'.
19 * @property string $templateCompilePath
20 * Ex: '/var/www/sites/default/files/civicrm/templates_c'.
21 * @property string $cms
22 * Ex: 'Backdrop', 'Drupal', 'Drupal8', 'Joomla', 'WordPress'.
23 * @property string $cmsBaseUrl
24 * Ex: 'http://example.org/'.
25 * @property array $db
26 * Ex: ['server'=>'localhost:3306', 'username'=>'admin', 'password'=>'s3cr3t', 'database'=>'mydb']
27 * @property array $cmsDb
28 * Ex: ['server'=>'localhost:3306', 'username'=>'admin', 'password'=>'s3cr3t', 'database'=>'mydb']
29 * @property string $siteKey
30 * Ex: 'abcd1234ABCD9876'.
2ce5684a
TO
31 * @property string[] $credKeys
32 * Ex: ['::abcd1234ABCD9876'].
8846c128
TO
33 * @property string[] $signKeys
34 * Ex: ['jwt-hs256::abcd1234ABCD9876'].
4bcd4c62
TO
35 * @property string|NULL $lang
36 * The language of the default dataset.
37 * Ex: 'fr_FR'.
38 * @property bool $loadGenerated
39 * UNSUPPORTED: Load example dataset (in lieu of the standard dataset).
40 * This was copied-in from the previous installer code, but it should probably be
41 * reconceived.
42 * @property array $components
43 * Ex: ['CiviMail', 'CiviContribute', 'CiviEvent', 'CiviMember', 'CiviReport']
44 * @property array $extensions
45 * Ex: ['org.civicrm.flexmailer', 'org.civicrm.shoreditch'].
46 * @property array $paths
47 * List of hard-coded path-overrides.
48 * Ex: ['wp.frontend.base'=>['url'=>'http://example.org/']].
49 * @property array $settings
50 * List of domain settings to apply.
51 * These are defaults during installation; they could be changed by the admin post-install via GUI or API.
52 * Ex: ['ajaxPopupsEnabled' => 0].
53 * @property array $mandatorySettings
54 * List of hard-coded setting-overrides.
55 * These are mandatory settings which are hard-coded into the config file. Changing requires editing the file.
56 * This makes sense for path/URL settings that are generally system-local and not migrated between dev/prod/etc.
57 * Ex: ['ajaxPopupsEnabled' => 0].
58 * @property array $extras
59 * Open-ended list of private, adhoc fields/flags/tags.
60 * Keys should be prefixed based on which plugin manages the field.
61 * Values must only be scalars (bool/int/string) and arrays.
62 * Ex: ['opt-in.version-check' => TRUE].
63 */
64class Model {
65
66 protected $sorted = FALSE;
67 protected $fields = array();
68 protected $values = array();
69
70 public function __construct() {
71 $this->addField(array(
72 'description' => 'Local path of the CiviCRM-core tree',
73 'name' => 'srcPath',
74 'type' => 'string',
75 ));
76 $this->addField(array(
77 'description' => 'Local path of the CiviCRM-setup tree',
78 'name' => 'setupPath',
79 'type' => 'string',
80 ));
81 $this->addField(array(
82 'description' => 'Local path to civicrm.settings.php',
83 'name' => 'settingsPath',
84 'type' => 'string',
85 ));
86 $this->addField(array(
87 'description' => 'Local path to the PHP compilation cache',
88 'name' => 'templateCompilePath',
89 'type' => 'string',
90 ));
91 $this->addField(array(
92 'description' => 'Symbolic name of the CMS/user-framework',
93 'name' => 'cms',
94 'type' => 'string',
95 ));
96 $this->addField(array(
97 'description' => 'The CMS base URL',
98 'name' => 'cmsBaseUrl',
99 'type' => 'string',
100 ));
101 $this->addField(array(
102 'description' => 'Credentials for Civi database',
103 'name' => 'db',
104 'type' => 'dsn',
105 ));
106 $this->addField(array(
107 'description' => 'Credentials for CMS database',
108 'name' => 'cmsDb',
109 'type' => 'dsn',
110 ));
111 $this->addField(array(
112 'description' => 'Site key',
113 'name' => 'siteKey',
114 'type' => 'string',
115 ));
2ce5684a
TO
116 $this->addField(array(
117 'description' => 'Credential encryption keys',
118 'name' => 'credKeys',
119 'type' => 'array',
120 ));
8846c128
TO
121 $this->addField(array(
122 'description' => 'Signing keys',
123 'name' => 'signKeys',
124 'type' => 'array',
125 ));
4bcd4c62
TO
126 $this->addField(array(
127 'description' => 'Load example data',
128 'name' => 'loadGenerated',
129 'type' => 'bool',
130 ));
131 $this->addField(array(
132 'description' => 'Language',
133 'name' => 'lang',
134 'type' => 'string',
135 'options' => array(),
136 ));
137 $this->addField(array(
138 'description' => 'List of CiviCRM components to enable',
139 'name' => 'components',
140 'type' => 'array',
141 'value' => array(),
142 ));
143 $this->addField(array(
144 'description' => 'List of CiviCRM extensions to enable',
145 'name' => 'extensions',
146 'type' => 'array',
147 'value' => array(),
148 ));
149 $this->addField(array(
150 'description' => 'List of mandatory path overrides.',
151 'name' => 'paths',
152 'type' => 'array',
153 'value' => array(),
154 ));
155 $this->addField(array(
156 'description' => 'List of setting overrides.',
157 'name' => 'settings',
158 'type' => 'array',
159 'value' => array(),
160 ));
161 $this->addField(array(
162 'description' => 'List of mandatory settings',
163 'name' => 'mandatorySettings',
164 'type' => 'array',
165 'value' => array(),
166 ));
167 $this->addField(array(
168 'description' => 'Open-ended list of private, adhoc fields/flags/tags',
169 'name' => 'extras',
170 'type' => 'array',
171 'value' => array(),
172 ));
173 }
174
175 /**
176 * @param array $field
177 * - name: string
178 * - description: string
179 * - type: string. One of "checkbox", "string".
180 * - weight: int. (Default: 0)
181 * - visible: bool. (Default: TRUE)
182 * - value: mixed. (Default: NULL)
183 * @return $this
184 */
185 public function addField($field) {
186 $defaults = array(
187 'weight' => 0,
188 'visible' => TRUE,
189 );
190 $field = array_merge($defaults, $field);
191
192 if (array_key_exists('value', $field) || !array_key_exists($field['name'], $this->values)) {
2e1f50d6 193 $this->values[$field['name']] = $field['value'] ?? NULL;
4bcd4c62
TO
194 unset($field['value']);
195 }
196
197 $this->fields[$field['name']] = $field;
198
199 $this->sorted = FALSE;
200 return $this;
201 }
202
203 public function setField($field, $property, $value) {
204 $this->fields[$field][$property] = $value;
205 return $this;
206 }
207
208 /**
209 * @param string $field
210 * The name of the field.
211 * Ex: 'cmsDb', 'lang'.
212 * @param string $property
213 * A specific property of the field to load.
214 * Ex: 'name', 'description', 'type', 'options'.
215 * @return mixed|NULL
216 */
217 public function getField($field, $property = NULL) {
218 if ($property) {
2e1f50d6 219 return $this->fields[$field][$property] ?? NULL;
4bcd4c62
TO
220 }
221 else {
2e1f50d6 222 return $this->fields[$field] ?? NULL;
4bcd4c62
TO
223 }
224 }
225
226 public function getFields() {
227 if (!$this->sorted) {
228 uasort($this->fields, function ($a, $b) {
229 if ($a['weight'] < $b['weight']) {
230 return -1;
231 }
232 if ($a['weight'] > $b['weight']) {
233 return 1;
234 }
235 return strcmp($a['name'], $b['name']);
236 });
237 }
238 return $this->fields;
239 }
240
241 /**
242 * Set the values of multiple fields.
243 *
244 * @param array $values
245 * Ex: array('root' => '/var/www/sites/default/files/civicrm')
246 * @return $this
247 */
248 public function setValues($values) {
249 foreach ($values as $key => $value) {
250 $this->values[$key] = $value;
251 }
252 return $this;
253 }
254
255 public function getValues() {
256 return $this->values;
257 }
258
259 public function &__get($name) {
260 return $this->values[$name];
261 }
262
263 public function __set($name, $value) {
264 $this->values[$name] = $value;
265 }
266
267 public function __isset($name) {
268 return isset($this->values[$name]);
269 }
270
271 public function __unset($name) {
272 unset($this->values[$name]);
273 }
274
275}