| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Generate configuration files |
| 5 | */ |
| 6 | class CRM_Core_CodeGen_Config extends CRM_Core_CodeGen_BaseTask { |
| 7 | function run() { |
| 8 | $this->generateTemplateVersion(); |
| 9 | |
| 10 | $this->setupCms(); |
| 11 | } |
| 12 | |
| 13 | function generateTemplateVersion() { |
| 14 | file_put_contents($this->config->tplCodePath . "/CRM/common/version.tpl", $this->config->db_version); |
| 15 | } |
| 16 | |
| 17 | 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 "drupal"|"wordpress" |
| 42 | * @return null|string path to config template |
| 43 | */ |
| 44 | public function findConfigTemplate($cms) { |
| 45 | $candidates = array(); |
| 46 | switch ($cms) { |
| 47 | case 'drupal': |
| 48 | $candidates[] = "../drupal/civicrm.config.php.drupal"; |
| 49 | $candidates[] = "../../drupal/civicrm.config.php.drupal"; |
| 50 | break; |
| 51 | case 'wordpress': |
| 52 | $candidates[] = "../../civicrm.config.php.wordpress"; |
| 53 | $candidates[] = "../WordPress/civicrm.config.php.wordpress"; |
| 54 | $candidates[] = "../drupal/civicrm.config.php.drupal"; |
| 55 | break; |
| 56 | } |
| 57 | foreach ($candidates as $candidate) { |
| 58 | if (file_exists($candidate)) { |
| 59 | return $candidate; |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | return NULL; |
| 64 | } |
| 65 | } |