Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Do not store the 'mediaVersion' in the database #197

Merged
merged 1 commit into from
Jul 7, 2015
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
49 changes: 11 additions & 38 deletions lib/libraries/cms/version/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ final class JVersion
/** @var string Link text. */
public $URL = '<a href="http://www.joomla.org">Joomla!</a> is Free Software released under the GNU General Public License.';

/** @var string Media version */
private $mediaVersion;

/**
* Compares two a "PHP standardized" version number against the current Joomla version.
*
Expand Down Expand Up @@ -148,10 +151,8 @@ public function getUserAgent($component = null, $mask = false, $add_version = tr
*/
public function generateMediaVersion()
{
$date = new JDate;
$config = JFactory::getConfig();

return md5($this->getLongVersion() . $config->get('secret') . $date->toSql());
return md5($this->getLongVersion() . $config->get('secret'));
}

/**
Expand All @@ -167,30 +168,11 @@ public function generateMediaVersion()
*/
public function getMediaVersion()
{
// Load the media version and cache it for future use
static $mediaVersion = null;

if ($mediaVersion === null)
{
$config = JFactory::getConfig();
$debugEnabled = $config->get('debug', 0);

// Get the joomla library params
$params = JLibraryHelper::getParams('joomla');

// Get the media version
$mediaVersion = $params->get('mediaversion', '');

// Refresh assets in debug mode or when the media version is not set
if ($debugEnabled || empty($mediaVersion))
{
$mediaVersion = $this->generateMediaVersion();

$this->setMediaVersion($mediaVersion);
}
if (empty($this->mediaVersion)) {
$this->mediaVersion = $this->generateMediaVersion();
}

return $mediaVersion;
return $this->mediaVersion;
}

/**
Expand All @@ -202,9 +184,8 @@ public function getMediaVersion()
*/
public function refreshMediaVersion()
{
$newMediaVersion = $this->generateMediaVersion();

return $this->setMediaVersion($newMediaVersion);
$mediaVersion = $this->generateMediaVersion();
return $this->setMediaVersion($mediaVersion);
}

/**
Expand All @@ -218,16 +199,8 @@ public function refreshMediaVersion()
*/
public function setMediaVersion($mediaVersion)
{
// Do not allow empty media versions
if (!empty($mediaVersion))
{
// Get library parameters
$params = JLibraryHelper::getParams('joomla');

$params->set('mediaversion', $mediaVersion);

// Save modified params
JLibraryHelper::saveParams('joomla', $params);
if (!empty($mediaVersion)) {
$this->mediaVersion = $mediaVersion;
}

return $this;
Expand Down