Skip to content

Commit

Permalink
Make it possible to failfast on minimum php version checking if datab…
Browse files Browse the repository at this point in the history
…ase is unreacable
  • Loading branch information
Mikhail Sandakov committed Feb 22, 2024
1 parent 45db542 commit c390d61
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pleskdistup/actions/common_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ def _do_check(self) -> bool:

class AssertMinPhpVersionUsedByWebsites(action.CheckAction):
min_version: version.PHPVersion
optional: bool

def __init__(
self,
min_version: str,
optional: bool = True,
):
self.name = "checking domains uses outdated PHP"
self.min_version = version.PHPVersion(min_version)
self.optional = optional
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 @@ -158,8 +161,10 @@ def __init__(
def _do_check(self) -> bool:
log.debug(f"Checking the minimum PHP version being used by the websites. The restriction is: {self.min_version}")
if not plesk.is_plesk_database_ready():
log.info("Plesk database is not ready. Skipping the minimum PHP for websites check.")
return True
if self.optional:
log.info("Plesk database is not ready. Skipping the minimum PHP for websites check.")
return True
raise RuntimeError("Plesk database is not ready. Skipping the minimum PHP for websites check.")

outdated_php_handlers = [f"'{handler}'" for handler in php.get_outdated_php_handlers(self.min_version)]
log.debug(f"Outdated PHP handlers: {outdated_php_handlers}")
Expand Down Expand Up @@ -187,13 +192,16 @@ def _do_check(self) -> bool:

class AssertMinPhpVersionUsedByCron(action.CheckAction):
min_version: version.PHPVersion
optional: bool

def __init__(
self,
min_version: str,
optional: bool = True,
):
self.name = "checking cronjob uses outdated PHP"
self.min_version = version.PHPVersion(min_version)
self.optional = optional
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 @@ -204,8 +212,10 @@ def __init__(
def _do_check(self) -> bool:
log.debug(f"Checking the minimum PHP version used in cronjobs. Restriction is: {self.min_version}")
if not plesk.is_plesk_database_ready():
log.info("Plesk database is not ready. Skipping the minimum PHP for websites check.")
return True
if self.optional:
log.info("Plesk database is not ready. Skipping the minimum PHP for cronjobs check.")
return True
raise RuntimeError("Plesk database is not ready. Skipping the minimum PHP for cronjobs check.")

outdated_php_handlers = [f"'{handler}'" for handler in php.get_outdated_php_handlers(self.min_version)]
log.debug(f"Outdated PHP handlers: {outdated_php_handlers}")
Expand Down

0 comments on commit c390d61

Please sign in to comment.