Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-02-09-11-44-07
[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->generateTemplateVersion();
9
10 $this->setupCms();
11 }
12
13 public function generateTemplateVersion() {
14 file_put_contents($this->config->tplCodePath . "/CRM/common/version.tpl", $this->config->db_version);
15 }
16
17 public function setupCms() {
18 if (!in_array($this->config->cms, array(
19 'drupal',
20 'joomla',
21 'wordpress',
22 ))) {
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');
31 }
32 else {
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 /**
45 * @param string $cms
46 * "drupal"|"wordpress".
47 * @return null|string
48 * path to config template
49 */
50 public function findConfigTemplate($cms) {
51 $candidates = array();
52 switch ($cms) {
53 case 'drupal':
54 $candidates[] = "../drupal/civicrm.config.php.drupal";
55 $candidates[] = "../../drupal/civicrm.config.php.drupal";
56 break;
57
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 }
72
73 }