Skip to content

Commit

Permalink
deprecate(core): elgg_get_version has been replaced by elgg_get_release
Browse files Browse the repository at this point in the history
fixes #8463
  • Loading branch information
jdalsem committed Oct 26, 2021
1 parent e8d3478 commit cc71881
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 76 deletions.
1 change: 1 addition & 0 deletions docs/appendix/upgrade-notes.rst
Expand Up @@ -8,6 +8,7 @@ See the administrator guides for :doc:`how to upgrade a live site </admin/upgrad
.. toctree::
:maxdepth: 1

upgrade-notes/4.0-to-4.1
upgrade-notes/3.x-to-4.0
upgrade-notes/3.2-to-3.3
upgrade-notes/3.1-to-3.2
Expand Down
11 changes: 11 additions & 0 deletions docs/appendix/upgrade-notes/4.0-to-4.1.rst
@@ -0,0 +1,11 @@
From 4.0 to 4.1
===============

.. contents:: Contents
:local:
:depth: 1

Deprecated APIs
---------------

* ``elgg_get_version()`` use ``elgg_get_release()``
1 change: 1 addition & 0 deletions engine/classes/Elgg/Application.php
Expand Up @@ -721,6 +721,7 @@ private static function getEngineLibs() {
'constants.php',
'context.php',
'deprecated-4.0.php',
'deprecated-4.1.php',
'deprecation.php',
'entities.php',
'filestore.php',
Expand Down
6 changes: 0 additions & 6 deletions engine/classes/Elgg/Cache/MetadataCache.php
Expand Up @@ -239,12 +239,6 @@ public function populateFromEntities(...$guids) {
return null;
}

$version = (int) _elgg_services()->config->version;
if (!empty($version) && ($version < 2016110900)) {
// can't use this during upgrade from 2.x to 3.0
return null;
}

$cached_values = [];

foreach ($guids as $i => $guid) {
Expand Down
4 changes: 2 additions & 2 deletions engine/classes/Elgg/Cli/InstallCommand.php
Expand Up @@ -77,9 +77,9 @@ protected function execute(InputInterface $input, OutputInterface $output) {

\Elgg\Application::start();

$version = elgg_get_version(true);
$release = elgg_get_release();

$this->notice("Elgg $version install successful");
$this->notice("Elgg {$release} install successful");
$this->notice("wwwroot: " . elgg_get_site_url());
$this->notice("dataroot: " . elgg_get_data_path());
$this->notice("cacheroot: " . elgg_get_cache_path());
Expand Down
1 change: 0 additions & 1 deletion engine/classes/Elgg/Config.php
Expand Up @@ -126,7 +126,6 @@
* @property bool $testing_mode Is the current application running (PHPUnit) tests
* @property string $time_format Preferred PHP time format
* @property string $url Alias of "wwwroot"
* @property int $version
* @property string $view Default viewtype (usually not set)
* @property bool $walled_garden Is current site in walled garden mode?
* @property string $who_can_change_language Who can change the language of a user
Expand Down
4 changes: 1 addition & 3 deletions engine/classes/Elgg/Di/ServiceProvider.php
Expand Up @@ -260,9 +260,7 @@ public function __construct(Config $config) {
});

$this->setFactory('cli', function(ServiceProvider $sp) {
$version = elgg_get_version(true);

$console = new \Elgg\Cli\Application('Elgg', $version);
$console = new \Elgg\Cli\Application('Elgg', elgg_get_release());
$console->setup($sp->cli_input, $sp->cli_output);

return new \Elgg\Cli(
Expand Down
7 changes: 1 addition & 6 deletions engine/classes/Elgg/Diagnostics/Reports.php
Expand Up @@ -15,12 +15,7 @@ class Reports {
* @return string
*/
public static function getBasic(\Elgg\Hook $hook) {

// Get version information
$version = elgg_get_version();
$release = elgg_get_version(true);

return $hook->getValue() . elgg_echo('diagnostics:report:basic', [$release, $version]);
return $hook->getValue() . elgg_echo('diagnostics:report:basic', [elgg_get_release(), elgg_get_version()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion engine/classes/Elgg/Menus/Footer.php
Expand Up @@ -60,7 +60,7 @@ public static function registerElggBranding(\Elgg\Hook $hook) {
'name' => 'powered',
'text' => elgg_echo('elgg:powered'),
'href' => 'https://elgg.org',
'title' => 'Elgg ' . elgg_get_version(true),
'title' => 'Elgg ' . elgg_get_release(),
'section' => 'meta',
'priority' => 600,
]);
Expand Down
4 changes: 2 additions & 2 deletions engine/classes/Elgg/Plugin/Composer.php
Expand Up @@ -141,8 +141,8 @@ public function assertConflicts() {
}

if (isset($conflicts['elgg'])) {
if ($this->checkConstraints(elgg_get_version(true), $conflicts['elgg'])) {
throw new ConflictException('Elgg version: ' . elgg_get_version(true) . ' conflicts with constraint '. $conflicts['elgg']);
if ($this->checkConstraints(elgg_get_release(), $conflicts['elgg'])) {
throw new ConflictException('Elgg version: ' . elgg_get_release() . ' conflicts with constraint '. $conflicts['elgg']);
}
unset($conflicts['elgg']);
}
Expand Down
1 change: 0 additions & 1 deletion engine/classes/ElggInstaller.php
Expand Up @@ -1443,7 +1443,6 @@ protected function saveSiteSettings($submissionVars) {

$sets = [
'installed' => time(),
'version' => elgg_get_version(),
'simplecache_enabled' => 1,
'system_cache_enabled' => 1,
'simplecache_minify_js' => true,
Expand Down
2 changes: 1 addition & 1 deletion engine/classes/ElggPlugin.php
Expand Up @@ -1519,7 +1519,7 @@ public function getVersion(): string {

// bundled plugins use elgg version
if (in_array($this->getID(), Plugins::BUNDLED_PLUGINS)) {
return elgg_get_version(true);
return elgg_get_release();
}

return '0.1';
Expand Down
31 changes: 31 additions & 0 deletions engine/lib/configuration.php
Expand Up @@ -93,6 +93,37 @@ function elgg_get_engine_path() {
return Paths::elgg() . 'engine';
}

/**
* Get the current Elgg release
*
* @return string
* @throws Exception if something wrong with the composer.json
* @since 4.1
*/
function elgg_get_release(): string {
static $release;

if (!isset($release)) {
$composerJson = file_get_contents(\Elgg\Project\Paths::elgg() . 'composer.json');
if ($composerJson === false) {
throw new Exception("Unable to read composer.json file!");
}

$composer = json_decode($composerJson);
if ($composer === null) {
throw new Exception("JSON parse error while reading composer.json!");
}

// Human-friendly version name
if (!isset($composer->version)) {
throw new Exception("Version field must be set in composer.json!");
}
$release = $composer->version;
}

return $release;
}

/**
* Get an Elgg configuration value
*
Expand Down
24 changes: 24 additions & 0 deletions engine/lib/deprecated-4.1.php
@@ -0,0 +1,24 @@
<?php
/**
* Bundle all functions which have been deprecated in Elgg 4.1
*/

/**
* Get the current Elgg version information
*
* @param bool $human_readable Whether to return a human readable version (default: false)
*
* @return string|false Depending on success
* @since 1.9
* @deprecated 4.1
*/
function elgg_get_version($human_readable = false) {

if ($human_readable) {
elgg_deprecated_notice(__METHOD__ . ' has been deprecated, use elgg_get_release()', '4.1');
return elgg_get_release();
}

elgg_deprecated_notice(__METHOD__ . ' has been deprecated. Do not rely on the version number. Instead use elgg_get_release() to get a release tag.', '4.1');
return '2017041200';
}
22 changes: 0 additions & 22 deletions engine/lib/elgglib.php
Expand Up @@ -548,28 +548,6 @@ function elgg_dump($value) {
_elgg_services()->logger->dump($value);
}

/**
* Get the current Elgg version information
*
* @param bool $human_readable Whether to return a human readable version (default: false)
*
* @return string|false Depending on success
* @since 1.9
*/
function elgg_get_version($human_readable = false) {
static $version, $release;

if (!isset($version) || !isset($release)) {
$path = \Elgg\Application::elggDir()->getPath('version.php');
if (!is_file($path)) {
return false;
}
include $path;
}

return $human_readable ? $release : $version;
}

/**
* Builds a URL from the a parts array like one returned by {@link parse_url()}.
*
Expand Down
3 changes: 1 addition & 2 deletions engine/lib/views.php
Expand Up @@ -1464,8 +1464,7 @@ function elgg_views_boot() {
function _elgg_get_js_site_data() {
return [
'elgg.data' => (object) elgg_trigger_plugin_hook('elgg.data', 'site', null, []),
'elgg.version' => elgg_get_version(),
'elgg.release' => elgg_get_version(true),
'elgg.release' => elgg_get_release(),
'elgg.config.wwwroot' => elgg_get_site_url(),

// refresh token 3 times during its lifetime (in microseconds 1000 * 1/3)
Expand Down
1 change: 0 additions & 1 deletion engine/tests/classes/Elgg/Mocks/Database/ConfigTable.php
Expand Up @@ -16,7 +16,6 @@ class ConfigTable extends \Elgg\Database\ConfigTable {
'language' => 'en',
'simplecache_enabled' => 0,
'system_cache_enabled' => 0,
'version' => 2017041200,
'min_password_length' => 6,
];

Expand Down
27 changes: 0 additions & 27 deletions version.php

This file was deleted.

2 changes: 1 addition & 1 deletion views/default/admin/header.php
Expand Up @@ -10,7 +10,7 @@
<a href="<?= elgg_get_site_url(); ?>admin">
<?= elgg_get_site_entity()->getDisplayName() ?>
<small><?= elgg_echo('admin') ?></small>
<small title="<?= elgg_echo('admin:header:release', [elgg_get_version(true)]); ?>">[v<?= elgg_get_version(true); ?>]</small>
<small title="<?= elgg_echo('admin:header:release', [elgg_get_release()]); ?>">[v<?= elgg_get_release(); ?>]</small>
</a>
</h1>
</div>
Expand Down

0 comments on commit cc71881

Please sign in to comment.