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