Merge pull request #14266 from seamuslee001/dev_core_369
[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) {
be2fb01f 42 $candidates = [];
5e434adf 43 switch ($cms) {
be2c3268
JL
44 case 'backdrop':
45 // FIXME!!!!
17740013
TO
46 $candidates[] = "../backdrop/civicrm.config.php.backdrop";
47 $candidates[] = "../../backdrop/civicrm.config.php.backdrop";
be2c3268
JL
48 $candidates[] = "../drupal/civicrm.config.php.backdrop";
49 $candidates[] = "../../drupal/civicrm.config.php.backdrop";
50 break;
51
5e434adf
ARW
52 case 'drupal':
53 $candidates[] = "../drupal/civicrm.config.php.drupal";
2aa397bc 54 $candidates[] = "../../drupal/civicrm.config.php.drupal";
5e434adf 55 break;
2aa397bc 56
6de76322
E
57 case 'drupal8':
58 $candidates[] = "../../modules/civicrm/civicrm.config.php.drupal";
59 $candidates[] = "../../../modules/civicrm/civicrm.config.php.drupal";
7aa4dc43 60 $candidates[] = "../../../modules/civicrm-drupal/civicrm.config.php.drupal";
6de76322
E
61 break;
62
5e434adf
ARW
63 case 'wordpress':
64 $candidates[] = "../../civicrm.config.php.wordpress";
65 $candidates[] = "../WordPress/civicrm.config.php.wordpress";
5e434adf
ARW
66 break;
67 }
68 foreach ($candidates as $candidate) {
69 if (file_exists($candidate)) {
70 return $candidate;
71 break;
72 }
73 }
74 return NULL;
75 }
96025800 76
5e434adf 77}