INFRA-132 - Civi - PHPStorm cleanup
[civicrm-core.git] / CRM / Core / CodeGen / Config.php
CommitLineData
5e434adf
ARW
1<?php
2
3/**
4 * Generate configuration files
5 */
6class 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
ARW
18 if (!in_array($this->config->cms, array(
19 'drupal', 'joomla', 'wordpress'))) {
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');
0db6c3e1
TO
28 }
29 else {
5e434adf
ARW
30 throw new Exception("Failed to locate template for civicrm.config.php");
31 }
32 }
33
34 echo "Generating civicrm-version file\n";
35 $template = new CRM_Core_CodeGen_Util_Template('php');
36 $template->assign('db_version', $this->config->db_version);
37 $template->assign('cms', ucwords($this->config->cms));
38 $template->run('civicrm_version.tpl', $this->config->phpCodePath . "civicrm-version.php");
39 }
40
41 /**
6a0b768e
TO
42 * @param string $cms
43 * "drupal"|"wordpress".
5e434adf
ARW
44 * @return null|string path to config template
45 */
46 public function findConfigTemplate($cms) {
47 $candidates = array();
48 switch ($cms) {
49 case 'drupal':
50 $candidates[] = "../drupal/civicrm.config.php.drupal";
2aa397bc 51 $candidates[] = "../../drupal/civicrm.config.php.drupal";
5e434adf 52 break;
2aa397bc 53
5e434adf
ARW
54 case 'wordpress':
55 $candidates[] = "../../civicrm.config.php.wordpress";
56 $candidates[] = "../WordPress/civicrm.config.php.wordpress";
57 $candidates[] = "../drupal/civicrm.config.php.drupal";
58 break;
59 }
60 foreach ($candidates as $candidate) {
61 if (file_exists($candidate)) {
62 return $candidate;
63 break;
64 }
65 }
66 return NULL;
67 }
68}