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