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