aa50e059577a81794bd8228a966167b73b0d0910
[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 ])) {
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');
28 }
29 else {
30 throw new Exception("Failed to locate template for civicrm.config.php");
31 }
32 }
33 }
34
35 /**
36 * @param string $cms
37 * "drupal"|"wordpress".
38 * @return null|string
39 * path to config template
40 */
41 public function findConfigTemplate($cms) {
42 if (getenv('GENCODE_CONFIG_TEMPLATE')) {
43 return getenv('GENCODE_CONFIG_TEMPLATE');
44 }
45
46 $candidates = [];
47 switch ($cms) {
48 case 'backdrop':
49 // FIXME!!!!
50 $candidates[] = "../backdrop/civicrm.config.php.backdrop";
51 $candidates[] = "../../backdrop/civicrm.config.php.backdrop";
52 $candidates[] = "../drupal/civicrm.config.php.backdrop";
53 $candidates[] = "../../drupal/civicrm.config.php.backdrop";
54 break;
55
56 case 'drupal':
57 $candidates[] = "../drupal/civicrm.config.php.drupal";
58 $candidates[] = "../../drupal/civicrm.config.php.drupal";
59 break;
60
61 case 'drupal8':
62 $candidates[] = "../../modules/civicrm/civicrm.config.php.drupal";
63 $candidates[] = "../../../modules/civicrm/civicrm.config.php.drupal";
64 $candidates[] = "../../../modules/civicrm-drupal/civicrm.config.php.drupal";
65 break;
66
67 case 'wordpress':
68 $candidates[] = "../../civicrm.config.php.wordpress";
69 $candidates[] = "../WordPress/civicrm.config.php.wordpress";
70 break;
71 }
72 foreach ($candidates as $candidate) {
73 if (file_exists($candidate)) {
74 return $candidate;
75 break;
76 }
77 }
78 return NULL;
79 }
80
81 }