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