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