Skip to content

Commit

Permalink
Rename php version assert action
Browse files Browse the repository at this point in the history
We decided to name it as assert minimal version because there could
be different reasons to restrict versions
  • Loading branch information
Mikhail Sandakov committed Feb 15, 2024
1 parent b4b5ae4 commit f2e41c2
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions pleskdistup/actions/common_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


# This action should be considered as deprecated
# It was split into AssertOutdatedPhpVersionNotInstalled and AssertWebsitesDontUseOutdatedPHP
# It was split into AssertMinPHPVersionInstalled and AssertMinPHPVersionUsedByWebsites
# because there still can be domains connected with outdated php version even when we
# remove this version from the system. So we should check it separately.
class AssertMinPhpVersion(action.CheckAction):
Expand Down Expand Up @@ -98,28 +98,28 @@ def _do_check(self) -> bool:
return False


class AssertOutdatedPhpVersionNotInstalled(action.CheckAction):
first_modern: version.PHPVersion
class AssertMinPHPVersionInstalled(action.CheckAction):
min_version: version.PHPVersion

def __init__(
self,
first_modern: str,
min_version: str,
):
self.name = "check for outdated PHP versions"
self.first_modern = version.PHPVersion(first_modern)
self.min_version = version.PHPVersion(min_version)
self.description = """Outdated PHP versions were detected: '{versions}'.
\tRemove outdated PHP packages via Plesk Installer to proceed with the conversion:
\tYou can do it by calling the following command:
\tplesk installer remove --components {remove_arg}
"""

def _do_check(self) -> bool:
log.debug(f"Checking for minimal PHP version of {self.first_modern}")
log.debug(f"Checking for minimal PHP version of {self.min_version}")
# TODO: get rid of the explicit version list
known_php_versions = php.get_known_php_versions()

log.debug(f"Known PHP versions: {known_php_versions}")
outdated_php_versions = [php for php in known_php_versions if php < self.first_modern]
outdated_php_versions = [php for php in known_php_versions if php < self.min_version]
outdated_php_packages = {f"plesk-php{php.major}{php.minor}": str(php) for php in outdated_php_versions}
log.debug(f"Outdated PHP versions: {outdated_php_versions}")

Expand All @@ -138,15 +138,15 @@ def _do_check(self) -> bool:
return False


class AssertWebsitesDontUseOutdatedPHP(action.CheckAction):
class AssertMinPHPVersionUsedByWebsites(action.CheckAction):
first_modern: version.PHPVersion

def __init__(
self,
first_modern: str,
min_version: str,
):
self.name = "checking domains uses outdated PHP"
self.first_modern = version.PHPVersion(first_modern)
self.min_version = version.PHPVersion(min_version)
self.description = """We have identified that the domains are using older versions of PHP.
\tSwitch the following domains to {modern} or later in order to continue with the conversion process:
\t- {domains}
Expand All @@ -156,12 +156,12 @@ def __init__(
"""

def _do_check(self) -> bool:
log.debug(f"Checking for minimal PHP version of {self.first_modern}")
log.debug(f"Checking for minimal PHP version of {self.min_version}")
if not plesk.is_plesk_database_ready():
log.info("Plesk database is not ready. Skipping the outdated php for websites check.")
return True

outdated_php_handlers = php.get_outdated_php_handlers(self.first_modern)
outdated_php_handlers = php.get_outdated_php_handlers(self.min_version)
log.debug(f"Outdated PHP handlers: {outdated_php_handlers}")
try:
looking_for_domains_sql_request = """
Expand All @@ -175,7 +175,7 @@ def _do_check(self) -> bool:
log.debug(f"Outdated PHP domains: {outdated_php_domains}")
outdated_php_domains = "\n\t- ".join(outdated_php_domains)
self.description = self.description.format(
modern=self.first_modern,
modern=self.min_version,
domains=outdated_php_domains
)
except Exception as ex:
Expand All @@ -185,15 +185,15 @@ def _do_check(self) -> bool:
return False


class AssertCronDoesntUseOutdatedPHP(action.CheckAction):
first_modern: version.PHPVersion
class AssertMinPHPVersionUsedByCron(action.CheckAction):
min_version: version.PHPVersion

def __init__(
self,
first_modern: str,
min_version: str,
):
self.name = "checking cronjob uses outdated PHP"
self.first_modern = version.PHPVersion(first_modern)
self.min_version = version.PHPVersion(min_version)
self.description = """We have detected that some cronjobs are using outdated PHP versions.
\tSwitch the following cronjobs to {modern} or later in order to continue with the conversion process:"
\t- {cronjobs}
Expand All @@ -202,12 +202,12 @@ def __init__(
"""

def _do_check(self) -> bool:
log.debug(f"Checking for outdated PHP version in cronjobs. {self.first_modern}")
log.debug(f"Checking for outdated PHP version in cronjobs. {self.min_version}")
if not plesk.is_plesk_database_ready():
log.info("Plesk database is not ready. Skipping the outdated php for websites check.")
return True

outdated_php_handlers = php.get_outdated_php_handlers(self.first_modern)
outdated_php_handlers = php.get_outdated_php_handlers(self.min_version)
log.debug(f"Outdated PHP handlers: {outdated_php_handlers}")

try:
Expand All @@ -223,7 +223,7 @@ def _do_check(self) -> bool:
outdated_php_cronjobs = "\n\t- ".join(outdated_php_cronjobs)

self.description = self.description.format(
modern=self.first_modern,
modern=self.min_version,
cronjobs=outdated_php_cronjobs)
except Exception as ex:
log.err("Unable to get cronjobs list from plesk database!")
Expand Down

0 comments on commit f2e41c2

Please sign in to comment.