Commit | Line | Data |
---|---|---|
5e434adf ARW |
1 | <?php |
2 | ||
3 | /** | |
4 | * Generate configuration files | |
5 | */ | |
6 | class CRM_Core_CodeGen_Config extends CRM_Core_CodeGen_BaseTask { | |
00be9182 | 7 | public function run() { |
5e434adf ARW |
8 | $this->generateTemplateVersion(); |
9 | ||
10 | $this->setupCms(); | |
11 | } | |
12 | ||
00be9182 | 13 | public function generateTemplateVersion() { |
5e434adf ARW |
14 | file_put_contents($this->config->tplCodePath . "/CRM/common/version.tpl", $this->config->db_version); |
15 | } | |
16 | ||
00be9182 | 17 | public function setupCms() { |
5e434adf | 18 | if (!in_array($this->config->cms, array( |
be2c3268 | 19 | 'backdrop', |
353ffa53 | 20 | 'drupal', |
6de76322 | 21 | 'drupal8', |
353ffa53 | 22 | 'joomla', |
8d7a9d07 CB |
23 | 'wordpress', |
24 | ))) { | |
5e434adf ARW |
25 | echo "Config file for '{$this->config->cms}' not known."; |
26 | exit(); | |
27 | } | |
28 | elseif ($this->config->cms !== 'joomla') { | |
29 | $configTemplate = $this->findConfigTemplate($this->config->cms); | |
30 | if ($configTemplate) { | |
31 | echo "Generating civicrm.config.php\n"; | |
32 | copy($configTemplate, '../civicrm.config.php'); | |
0db6c3e1 TO |
33 | } |
34 | else { | |
5e434adf ARW |
35 | throw new Exception("Failed to locate template for civicrm.config.php"); |
36 | } | |
37 | } | |
38 | ||
39 | echo "Generating civicrm-version file\n"; | |
40 | $template = new CRM_Core_CodeGen_Util_Template('php'); | |
41 | $template->assign('db_version', $this->config->db_version); | |
42 | $template->assign('cms', ucwords($this->config->cms)); | |
43 | $template->run('civicrm_version.tpl', $this->config->phpCodePath . "civicrm-version.php"); | |
44 | } | |
45 | ||
46 | /** | |
6a0b768e TO |
47 | * @param string $cms |
48 | * "drupal"|"wordpress". | |
72b3a70c CW |
49 | * @return null|string |
50 | * path to config template | |
5e434adf ARW |
51 | */ |
52 | public function findConfigTemplate($cms) { | |
53 | $candidates = array(); | |
54 | switch ($cms) { | |
be2c3268 JL |
55 | case 'backdrop': |
56 | // FIXME!!!! | |
17740013 TO |
57 | $candidates[] = "../backdrop/civicrm.config.php.backdrop"; |
58 | $candidates[] = "../../backdrop/civicrm.config.php.backdrop"; | |
be2c3268 JL |
59 | $candidates[] = "../drupal/civicrm.config.php.backdrop"; |
60 | $candidates[] = "../../drupal/civicrm.config.php.backdrop"; | |
61 | break; | |
62 | ||
5e434adf ARW |
63 | case 'drupal': |
64 | $candidates[] = "../drupal/civicrm.config.php.drupal"; | |
2aa397bc | 65 | $candidates[] = "../../drupal/civicrm.config.php.drupal"; |
5e434adf | 66 | break; |
2aa397bc | 67 | |
6de76322 E |
68 | case 'drupal8': |
69 | $candidates[] = "../../modules/civicrm/civicrm.config.php.drupal"; | |
70 | $candidates[] = "../../../modules/civicrm/civicrm.config.php.drupal"; | |
71 | break; | |
72 | ||
5e434adf ARW |
73 | case 'wordpress': |
74 | $candidates[] = "../../civicrm.config.php.wordpress"; | |
75 | $candidates[] = "../WordPress/civicrm.config.php.wordpress"; | |
5e434adf ARW |
76 | break; |
77 | } | |
78 | foreach ($candidates as $candidate) { | |
79 | if (file_exists($candidate)) { | |
80 | return $candidate; | |
81 | break; | |
82 | } | |
83 | } | |
84 | return NULL; | |
85 | } | |
96025800 | 86 | |
5e434adf | 87 | } |