Merge pull request #10541 from JMAConsulting/CRM-20411
[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 {
00be9182 7 public function run() {
5e434adf
ARW
8 $this->setupCms();
9 }
10
00be9182 11 public function setupCms() {
5e434adf 12 if (!in_array($this->config->cms, array(
be2c3268 13 'backdrop',
353ffa53 14 'drupal',
6de76322 15 'drupal8',
353ffa53 16 'joomla',
8d7a9d07
CB
17 'wordpress',
18 ))) {
5e434adf
ARW
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');
0db6c3e1
TO
27 }
28 else {
5e434adf
ARW
29 throw new Exception("Failed to locate template for civicrm.config.php");
30 }
31 }
5e434adf
ARW
32 }
33
34 /**
6a0b768e
TO
35 * @param string $cms
36 * "drupal"|"wordpress".
72b3a70c
CW
37 * @return null|string
38 * path to config template
5e434adf
ARW
39 */
40 public function findConfigTemplate($cms) {
41 $candidates = array();
42 switch ($cms) {
be2c3268
JL
43 case 'backdrop':
44 // FIXME!!!!
17740013
TO
45 $candidates[] = "../backdrop/civicrm.config.php.backdrop";
46 $candidates[] = "../../backdrop/civicrm.config.php.backdrop";
be2c3268
JL
47 $candidates[] = "../drupal/civicrm.config.php.backdrop";
48 $candidates[] = "../../drupal/civicrm.config.php.backdrop";
49 break;
50
5e434adf
ARW
51 case 'drupal':
52 $candidates[] = "../drupal/civicrm.config.php.drupal";
2aa397bc 53 $candidates[] = "../../drupal/civicrm.config.php.drupal";
5e434adf 54 break;
2aa397bc 55
6de76322
E
56 case 'drupal8':
57 $candidates[] = "../../modules/civicrm/civicrm.config.php.drupal";
58 $candidates[] = "../../../modules/civicrm/civicrm.config.php.drupal";
59 break;
60
5e434adf
ARW
61 case 'wordpress':
62 $candidates[] = "../../civicrm.config.php.wordpress";
63 $candidates[] = "../WordPress/civicrm.config.php.wordpress";
5e434adf
ARW
64 break;
65 }
66 foreach ($candidates as $candidate) {
67 if (file_exists($candidate)) {
68 return $candidate;
69 break;
70 }
71 }
72 return NULL;
73 }
96025800 74
5e434adf 75}