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( |
353ffa53 | 19 | 'drupal', |
6de76322 | 20 | 'drupal8', |
353ffa53 | 21 | 'joomla', |
8d7a9d07 CB |
22 | 'wordpress', |
23 | ))) { | |
5e434adf ARW |
24 | echo "Config file for '{$this->config->cms}' not known."; |
25 | exit(); | |
26 | } | |
27 | elseif ($this->config->cms !== 'joomla') { | |
28 | $configTemplate = $this->findConfigTemplate($this->config->cms); | |
29 | if ($configTemplate) { | |
30 | echo "Generating civicrm.config.php\n"; | |
31 | copy($configTemplate, '../civicrm.config.php'); | |
0db6c3e1 TO |
32 | } |
33 | else { | |
5e434adf ARW |
34 | throw new Exception("Failed to locate template for civicrm.config.php"); |
35 | } | |
36 | } | |
37 | ||
38 | echo "Generating civicrm-version file\n"; | |
39 | $template = new CRM_Core_CodeGen_Util_Template('php'); | |
40 | $template->assign('db_version', $this->config->db_version); | |
41 | $template->assign('cms', ucwords($this->config->cms)); | |
42 | $template->run('civicrm_version.tpl', $this->config->phpCodePath . "civicrm-version.php"); | |
43 | } | |
44 | ||
45 | /** | |
6a0b768e TO |
46 | * @param string $cms |
47 | * "drupal"|"wordpress". | |
72b3a70c CW |
48 | * @return null|string |
49 | * path to config template | |
5e434adf ARW |
50 | */ |
51 | public function findConfigTemplate($cms) { | |
52 | $candidates = array(); | |
53 | switch ($cms) { | |
54 | case 'drupal': | |
55 | $candidates[] = "../drupal/civicrm.config.php.drupal"; | |
2aa397bc | 56 | $candidates[] = "../../drupal/civicrm.config.php.drupal"; |
5e434adf | 57 | break; |
2aa397bc | 58 | |
6de76322 E |
59 | case 'drupal8': |
60 | $candidates[] = "../../modules/civicrm/civicrm.config.php.drupal"; | |
61 | $candidates[] = "../../../modules/civicrm/civicrm.config.php.drupal"; | |
62 | break; | |
63 | ||
5e434adf ARW |
64 | case 'wordpress': |
65 | $candidates[] = "../../civicrm.config.php.wordpress"; | |
66 | $candidates[] = "../WordPress/civicrm.config.php.wordpress"; | |
67 | $candidates[] = "../drupal/civicrm.config.php.drupal"; | |
68 | break; | |
69 | } | |
70 | foreach ($candidates as $candidate) { | |
71 | if (file_exists($candidate)) { | |
72 | return $candidate; | |
73 | break; | |
74 | } | |
75 | } | |
76 | return NULL; | |
77 | } | |
96025800 | 78 | |
5e434adf | 79 | } |