Merge pull request #14704 from pradpnayak/REF-1
[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 $candidates = [];
43 switch ($cms) {
44 case 'backdrop':
45 // FIXME!!!!
46 $candidates[] = "../backdrop/civicrm.config.php.backdrop";
47 $candidates[] = "../../backdrop/civicrm.config.php.backdrop";
48 $candidates[] = "../drupal/civicrm.config.php.backdrop";
49 $candidates[] = "../../drupal/civicrm.config.php.backdrop";
50 break;
51
52 case 'drupal':
53 $candidates[] = "../drupal/civicrm.config.php.drupal";
54 $candidates[] = "../../drupal/civicrm.config.php.drupal";
55 break;
56
57 case 'drupal8':
58 $candidates[] = "../../modules/civicrm/civicrm.config.php.drupal";
59 $candidates[] = "../../../modules/civicrm/civicrm.config.php.drupal";
60 $candidates[] = "../../../modules/civicrm-drupal/civicrm.config.php.drupal";
61 break;
62
63 case 'wordpress':
64 $candidates[] = "../../civicrm.config.php.wordpress";
65 $candidates[] = "../WordPress/civicrm.config.php.wordpress";
66 break;
67 }
68 foreach ($candidates as $candidate) {
69 if (file_exists($candidate)) {
70 return $candidate;
71 break;
72 }
73 }
74 return NULL;
75 }
76
77 }