diff --git a/.gitignore b/.gitignore index f7aa94f65993..4e204a5b202c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ CRM/Case/xml/configuration CRM/Core/DAO/.listAll.php CRM/Core/DAO/listAll.php bin/setup.conf -civicrm-version.php civicrm-version.txt civicrm.config.php node_modules diff --git a/CRM/Core/CodeGen/Main.php b/CRM/Core/CodeGen/Main.php index f85deb401bbe..9edd7b781817 100644 --- a/CRM/Core/CodeGen/Main.php +++ b/CRM/Core/CodeGen/Main.php @@ -110,7 +110,6 @@ public function getTasks() { $tasks = array(); $tasks[] = new CRM_Core_CodeGen_Config($this); - $tasks[] = new CRM_Core_CodeGen_Version($this); $tasks[] = new CRM_Core_CodeGen_Reflection($this); $tasks[] = new CRM_Core_CodeGen_Schema($this); foreach (array_keys($this->tables) as $name) { diff --git a/CRM/Core/CodeGen/Version.php b/CRM/Core/CodeGen/Version.php deleted file mode 100644 index e98e38e88814..000000000000 --- a/CRM/Core/CodeGen/Version.php +++ /dev/null @@ -1,16 +0,0 @@ -assign('db_version', $this->config->db_version); - $template->assign('cms', ucwords($this->config->cms)); - $template->run('civicrm_version.tpl', $this->config->phpCodePath . "civicrm-version.php"); - } - -} diff --git a/civicrm-version.php b/civicrm-version.php new file mode 100755 index 000000000000..f99d34cad70b --- /dev/null +++ b/civicrm-version.php @@ -0,0 +1,128 @@ +version_no; + } + + trigger_error("Unknown version", E_USER_ERROR); + exit(); + } + + /** + * Get the CMS name + */ + public static function findCMS() { + if (defined('CIVICRM_UF')) { + return CIVICRM_UF; + } + elseif (defined('BACKDROP_VERSION')) { + return 'Backdrop'; + } + elseif (function_exists('drupal_bootstrap') && version_compare(VERSION, '6.0', '>=') && version_compare(VERSION, '7.0', '<')) { + return 'Drupal6'; + } + elseif (function_exists('drupal_bootstrap') && version_compare(VERSION, '7.0', '>=') && version_compare(VERSION, '8.0', '<')) { + return 'Drupal'; + } + elseif (defined('ABSPATH') && function_exists('get_bloginfo')) { + return 'WordPress'; + } + elseif (defined('DRUPAL_ROOT') && class_exists('Drupal') && version_compare(\Drupal::VERSION, '8.0', '>=') && version_compare(\Drupal::VERSION, '9.0', '<')) { + return 'Drupal8'; + } + else { + // guess CMS name from the current path + list($cmsType,) = self::findCMSRootPath(); + + if (!empty($cmsType)) { + return $cmsType; + } + } + } + + /** + * Get the CMS root path and CMS name + */ + public static function findCMSRootPath() { + $cmsPatterns = array( + 'Wordpress' => array( + 'wp-includes/version.php', + // Future? 'vendor/civicrm/wordpress/civicrm.php' => 'wp', + ), + 'Joomla' => array( + 'administrator/components/com_civicrm/civicrm/civicrm-version.php', + ), + 'Drupal' => array( + 'modules/system/system.module', // D7 + ), + 'Drupal8' => array( + 'core/core.services.yml', // D8 + ), + 'Backdrop' => array( + 'core/modules/layout/layout.module', + ), + ); + + $parts = explode('/', str_replace('\\', '/', self::getSearchDir())); + while (!empty($parts)) { + $basePath = implode('/', $parts); + + foreach ($cmsPatterns as $cmsType => $relPaths) { + foreach ($relPaths as $relPath) { + $matches = glob("$basePath/$relPath"); + if (!empty($matches)) { + return [$cmsType, $basePath]; + } + } + } + + array_pop($parts); + } + } + + /** + * Get the current path + */ + public static function getSearchDir() { + if ($_SERVER['SCRIPT_FILENAME']) { + return dirname($_SERVER['SCRIPT_FILENAME']); + } + // getenv('PWD') works better with symlinked source trees, but it's + // not portable to Windows. + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + return getcwd(); + } + else { + return getenv('PWD'); + } + } + + } +} + +namespace { + /** + * Get the CiviCRM version. + * TODO : For now this function is not included in \Civi\Version class so not to break any code + * which directly call civicrmVersion(). So those call need to replaced with \Civi\Version::civicrmVersion() + * when included in the class + * @deprecated + */ + function civicrmVersion() { + return [ + 'version' => \_CiviVersion_\Util::findVersion(), + 'cms' => \_CiviVersion_\Util::findCMS(), + ]; + } +} diff --git a/distmaker/dists/common.sh b/distmaker/dists/common.sh index 64fbf0426082..e760bf593054 100644 --- a/distmaker/dists/common.sh +++ b/distmaker/dists/common.sh @@ -220,6 +220,7 @@ function dm_generate_version() { # final touch echo " '$DM_VERSION', 'cms' => '$ufname',