INFRA-132 - CRM/Core - Convert single-line @param to multi-line
[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', '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');
28 } else {
29 throw new Exception("Failed to locate template for civicrm.config.php");
30 }
31 }
32
33 echo "Generating civicrm-version file\n";
34 $template = new CRM_Core_CodeGen_Util_Template('php');
35 $template->assign('db_version', $this->config->db_version);
36 $template->assign('cms', ucwords($this->config->cms));
37 $template->run('civicrm_version.tpl', $this->config->phpCodePath . "civicrm-version.php");
38 }
39
40 /**
41 * @param string $cms
42 * "drupal"|"wordpress".
43 * @return null|string path to config template
44 */
45 public function findConfigTemplate($cms) {
46 $candidates = array();
47 switch ($cms) {
48 case 'drupal':
49 $candidates[] = "../drupal/civicrm.config.php.drupal";
50 $candidates[] = "../../drupal/civicrm.config.php.drupal";
51 break;
52 case 'wordpress':
53 $candidates[] = "../../civicrm.config.php.wordpress";
54 $candidates[] = "../WordPress/civicrm.config.php.wordpress";
55 $candidates[] = "../drupal/civicrm.config.php.drupal";
56 break;
57 }
58 foreach ($candidates as $candidate) {
59 if (file_exists($candidate)) {
60 return $candidate;
61 break;
62 }
63 }
64 return NULL;
65 }
66 }