Merge pull request #24117 from civicrm/5.52
[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
8 public function run() {
9 $this->setupCms();
10 }
11
12 public function setupCms() {
13 if (!in_array($this->config->cms, [
14 'backdrop',
15 'drupal',
16 'drupal8',
17 'joomla',
18 'wordpress',
19 'standalone',
20 ])) {
21 echo "Config file for '{$this->config->cms}' not known.";
22 exit();
23 }
24 elseif ($this->config->cms !== 'joomla') {
25 $configTemplate = $this->findConfigTemplate($this->config->cms);
26 if ($configTemplate) {
27 echo "Generating civicrm.config.php\n";
28 copy($configTemplate, '../civicrm.config.php');
29 }
30 else {
31 throw new Exception("Failed to locate template for civicrm.config.php");
32 }
33 }
34 }
35
36 /**
37 * @param string $cms
38 * "drupal"|"wordpress".
39 * @return null|string
40 * path to config template
41 */
42 public function findConfigTemplate($cms) {
43 if (getenv('GENCODE_CONFIG_TEMPLATE')) {
44 return getenv('GENCODE_CONFIG_TEMPLATE');
45 }
46
47 $candidates = [];
48 switch ($cms) {
49 case 'backdrop':
50 // FIXME!!!!
51 $candidates[] = "../backdrop/civicrm.config.php.backdrop";
52 $candidates[] = "../../backdrop/civicrm.config.php.backdrop";
53 $candidates[] = "../drupal/civicrm.config.php.backdrop";
54 $candidates[] = "../../drupal/civicrm.config.php.backdrop";
55 break;
56
57 case 'drupal':
58 $candidates[] = "../drupal/civicrm.config.php.drupal";
59 $candidates[] = "../../drupal/civicrm.config.php.drupal";
60 break;
61
62 case 'drupal8':
63 $candidates[] = "../../modules/civicrm/civicrm.config.php.drupal";
64 $candidates[] = "../../../modules/civicrm/civicrm.config.php.drupal";
65 $candidates[] = "../../../modules/civicrm-drupal/civicrm.config.php.drupal";
66 break;
67
68 case 'standalone':
69 $candidates[] = "../../../../civicrm.config.php.standalone";
70 break;
71
72 case 'wordpress':
73 $candidates[] = "../../civicrm.config.php.wordpress";
74 $candidates[] = "../WordPress/civicrm.config.php.wordpress";
75 break;
76 }
77 foreach ($candidates as $candidate) {
78 if (file_exists($candidate)) {
79 return $candidate;
80 break;
81 }
82 }
83 return NULL;
84 }
85
86 }