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