Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21203 Fixes for Joomla 3.8+ CRON/cli and directories #11062

Merged
merged 3 commits into from
Oct 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 41 additions & 21 deletions CRM/Utils/System/Joomla.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,8 @@ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realP
$row = $users[0];
}

$joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
if (!defined('JVERSION')) {
require $joomlaBase . '/libraries/cms/version/version.php';
$jversion = new JVersion();
define('JVERSION', $jversion->getShortVersion());
}
$joomlaBase = self::getBasePath();
self::getJVersion($joomlaBase);

if (!empty($row)) {
$dbPassword = $row->password;
Expand All @@ -389,8 +385,13 @@ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realP
return FALSE;
}

if (version_compare(JVERSION, '3.8.0', 'ge')) {
jimport('joomla.application.helper');
jimport('joomla.application.cms');
jimport('joomla.application.administrator');
}
//include additional files required by Joomla 3.2.1+
if (version_compare(JVERSION, '3.2.1', 'ge')) {
elseif (version_compare(JVERSION, '3.2.1', 'ge')) {
require_once $joomlaBase . '/libraries/cms/application/helper.php';
require_once $joomlaBase . '/libraries/cms/application/cms.php';
require_once $joomlaBase . '/libraries/cms/application/administrator.php';
Expand Down Expand Up @@ -507,6 +508,32 @@ public function getVersion() {
}
}

public function getJVersion($joomlaBase) {
// Files may be in different places depending on Joomla version
if (!defined('JVERSION')) {
// Joomla 3.8.0+
$versionPhp = $joomlaBase . '/libraries/src/Version.php';
if (!file_exists($versionPhp)) {
// Joomla < 3.8.0
$versionPhp = $joomlaBase . '/libraries/cms/version/version.php';
}
require $versionPhp;
$jversion = new JVersion();
define('JVERSION', $jversion->getShortVersion());
}
}

/**
* Setup the base path related constant.
* @return mixed
*/
public function getBasePath() {
global $civicrm_root;
$joomlaPath = explode('/administrator', $civicrm_root);
$joomlaBase = $joomlaPath[0];
return $joomlaBase;
}

/**
* Load joomla bootstrap.
*
Expand All @@ -521,8 +548,7 @@ public function getVersion() {
* @return bool
*/
public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL, $loadDefines = TRUE) {
// Setup the base path related constant.
$joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
$joomlaBase = self::getBasePath();

// load BootStrap here if needed
// We are a valid Joomla entry point.
Expand All @@ -531,30 +557,25 @@ public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError =
define('DS', DIRECTORY_SEPARATOR);
define('JPATH_BASE', $joomlaBase . '/administrator');
require $joomlaBase . '/administrator/includes/defines.php';
require $joomlaBase . '/administrator/includes/framework.php';
}

// Get the framework.
if (file_exists($joomlaBase . '/libraries/import.legacy.php')) {
require $joomlaBase . '/libraries/import.legacy.php';
}
require $joomlaBase . '/libraries/cms.php';
require $joomlaBase . '/libraries/import.php';
require $joomlaBase . '/libraries/joomla/event/dispatcher.php';
require $joomlaBase . '/configuration.php';

// Files may be in different places depending on Joomla version
if (!defined('JVERSION')) {
require $joomlaBase . '/libraries/cms/version/version.php';
$jversion = new JVersion();
define('JVERSION', $jversion->getShortVersion());
}
require_once $joomlaBase . '/configuration.php';
self::getJVersion($joomlaBase);

if (version_compare(JVERSION, '3.0', 'lt')) {
require $joomlaBase . '/libraries/joomla/environment/uri.php';
require $joomlaBase . '/libraries/joomla/application/component/helper.php';
}
else {
require $joomlaBase . '/libraries/cms.php';
require $joomlaBase . '/libraries/joomla/uri/uri.php';
jimport('joomla.environment.uri');
}

jimport('joomla.application.cli');
Expand Down Expand Up @@ -704,8 +725,7 @@ public function cmsRootPath() {
}

list($url, $siteName, $siteRoot) = $this->getDefaultSiteSettings();
$includePath = "$siteRoot/libraries/cms/version";
if (file_exists("$includePath/version.php")) {
if (file_exists("$siteRoot/administrator/index.php")) {
return $siteRoot;
}
return NULL;
Expand Down