Merge pull request #13968 from eileenmcnaughton/array_format
[civicrm-core.git] / CRM / Core / CodeGen / Config.php
1 <?php
2
3 /**
4 * Generate configuration files
5 */
6 class CRM_Core_CodeGen_Config extends CRM_Core_CodeGen_BaseTask {
7 public function run() {
8 $this->setupCms();
9 }
10
11 public function setupCms() {
12 if (!in_array($this->config->cms, [
13 'backdrop',
14 'drupal',
15 'drupal8',
16 'joomla',
17 'wordpress',
18 ])) {
19 echo "Config file for '{$this->config->cms}' not known.";
20 exit();
21 }
22 elseif ($this->config->cms !== 'joomla') {
23 $configTemplate = $this->findConfigTemplate($this->config->cms);
24 if ($configTemplate) {
25 echo "Generating civicrm.config.php\n";
26 copy($configTemplate, '../civicrm.config.php');
27 }
28 else {
29 throw new Exception("Failed to locate template for civicrm.config.php");
30 }
31 }
32 }
33
34 /**
35 * @param string $cms
36 * "drupal"|"wordpress".
37 * @return null|string
38 * path to config template
39 */
40 public function findConfigTemplate($cms) {
41 $candidates = [];
42 switch ($cms) {
43 case 'backdrop':
44 // FIXME!!!!
45 $candidates[] = "../backdrop/civicrm.config.php.backdrop";
46 $candidates[] = "../../backdrop/civicrm.config.php.backdrop";
47 $candidates[] = "../drupal/civicrm.config.php.backdrop";
48 $candidates[] = "../../drupal/civicrm.config.php.backdrop";
49 break;
50
51 case 'drupal':
52 $candidates[] = "../drupal/civicrm.config.php.drupal";
53 $candidates[] = "../../drupal/civicrm.config.php.drupal";
54 break;
55
56 case 'drupal8':
57 $candidates[] = "../../modules/civicrm/civicrm.config.php.drupal";
58 $candidates[] = "../../../modules/civicrm/civicrm.config.php.drupal";
59 $candidates[] = "../../../modules/civicrm-drupal/civicrm.config.php.drupal";
60 break;
61
62 case 'wordpress':
63 $candidates[] = "../../civicrm.config.php.wordpress";
64 $candidates[] = "../WordPress/civicrm.config.php.wordpress";
65 break;
66 }
67 foreach ($candidates as $candidate) {
68 if (file_exists($candidate)) {
69 return $candidate;
70 break;
71 }
72 }
73 return NULL;
74 }
75
76 }