Skip to content

Commit

Permalink
Release of 5.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Mar 2, 2023
1 parent 658ab81 commit 5708151
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 43 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

## 5.2.1 - 2023-03-02

* Improved the message about the database version and if migrations are available
* Temporary disabling translations, this version is only available in English

## 5.2.0 - 2023-02-24

* G-Obs right panel
Expand Down
98 changes: 55 additions & 43 deletions gobs/gobs_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import webbrowser

from functools import partial
from typing import Tuple

from qgis.core import (
Qgis,
Expand All @@ -24,6 +25,7 @@
)
from gobs.plugin_tools import (
format_version_integer,
available_migrations,
)
from gobs.processing.algorithms.import_observation_data import (
ImportObservationData,
Expand Down Expand Up @@ -97,7 +99,7 @@ def __init__(self, iface, parent=None):
self.set_information_from_project()

@staticmethod
def database_version():
def check_database_version():
""" Get the database G-Obs version"""
# Query the database
sql = '''
Expand Down Expand Up @@ -125,11 +127,9 @@ def set_information_from_project(self):

# Active connection
connection_name = QgsExpressionContextUtils.projectScope(self.project).variable('gobs_connection_name')
stylesheet = 'padding: 3px;'
connection_stylesheet = stylesheet
connection_stylesheet = 'padding: 3px;'
connection_exists = False

connection_info = '-'
if connection_name:
if connection_name in get_postgis_connection_list():
connection_info = connection_name
Expand All @@ -150,44 +150,7 @@ def set_information_from_project(self):
# Check database version against plugin version
plugin_version = version()
self.plugin_version.setText(plugin_version)
version_comment = ''
version_stylesheet = ''
if connection_exists:
db_version = self.database_version()

if db_version:
self.database_version.setText(db_version)
db_version_integer = format_version_integer(db_version)
plugin_version_integer = format_version_integer(plugin_version)
if db_version_integer == plugin_version_integer:
version_comment = tr(
'The version of the database structure and QGIS G-Obs plugin match.'
)
version_stylesheet = "font-weight: bold; color: green;"
else:
if plugin_version_integer != 999999:
if db_version_integer > plugin_version_integer:
version_comment = tr(
'The G-Obs plugin version is older than the database G-Obs version.'
' You need to upgrade your G-Obs QGIS plugin.'
)
version_stylesheet = "font-weight: bold; color: orange;"
else:
version_comment = tr(
'The database G-Obs version is older than your plugin version.'
' You need to run the algorithm "Upgrade database structure".'
)
version_stylesheet = "font-weight: bold; color: orange;"
else:
version_comment = tr(
'The G-Obs plugin version is either "master" or "dev".'
)
version_stylesheet = "font-weight: bold; color: green;"
else:
version_comment = tr(
'The database G-Obs version cannot be fetched from the given connection.'
)
version_stylesheet = "font-weight: bold; color: orange;"
version_comment, version_stylesheet = self.check_database_status(connection_exists)

self.version_comment.setText(version_comment)
self.version_comment.setStyleSheet(version_stylesheet)
Expand Down Expand Up @@ -219,6 +182,53 @@ def set_information_from_project(self):
else:
button.show()

def check_database_status(self, connection_exists) -> Tuple[str, str]:
""" Compare the plugin version versus the database version. """
# First check, if there isn't any connection set.
if not connection_exists:
version_comment = tr('Unknown database version')
version_stylesheet = "font-weight: bold; color: orange;"
return version_comment, version_stylesheet

db_version = self.check_database_version()

# Second check, if no metadata table has been found.
if not db_version:
version_comment = tr(
'The database G-Obs version cannot be fetched from the given connection.'
)
version_stylesheet = "font-weight: bold; color: orange;"
return version_comment, version_stylesheet

self.database_version.setText(db_version)
db_version_integer = format_version_integer(db_version)
plugin_version_integer = format_version_integer(version())

# Third check, if the database is in front of the plugin for their versions.
if db_version_integer > plugin_version_integer:
version_comment = tr(
'The G-Obs plugin version is older than the database G-Obs version.'
' You need to upgrade your G-Obs QGIS plugin.'
)
version_stylesheet = "font-weight: bold; color: orange;"
return version_comment, version_stylesheet

has_migrations = len(available_migrations(plugin_version_integer)) >= 1
# Fourth check, if there is a migration to run
if has_migrations:
# db_version_integer < plugin_version_integer
version_comment = tr(
'The database G-Obs version is older than your plugin version.'
' You need to run the algorithm "Upgrade database structure".'
)
version_stylesheet = "font-weight: bold; color: orange;"
return version_comment, version_stylesheet

# Finally, everything is alright
version_comment = tr('The database is OK')
version_stylesheet = "font-weight: bold; color: green;"
return version_comment, version_stylesheet

def run_algorithm(self, name):

if name not in self.algorithms:
Expand All @@ -231,8 +241,10 @@ def run_algorithm(self, name):

# Run alg
param = {}
alg_name = 'gobs:{0}'.format(name)
alg_name = 'gobs:{}'.format(name)
execAlgorithmDialog(alg_name, param)
if name in ('create_database_structure', 'upgrade_database_structure'):
self.set_information_from_project()

@staticmethod
def get_series():
Expand Down

1 comment on commit 5708151

@Gustry
Copy link
Member Author

@Gustry Gustry commented on 5708151 Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit also includes the bugfix about the database checks. Sorry for the mess in the commit.

Please sign in to comment.