Skip to content

Commit

Permalink
Added an action to verify if certain websites use PHP from the operat…
Browse files Browse the repository at this point in the history
…ing system vendor

It is important to avoid conversion in this case because the version of PHP
provided by the vendor is 5.4 on CentOS 7 and 7.2 on AlmaLinux 8.
After the conversion, there is uncertainty whether the websites will
function properly due to the non-trivial task of migrating from PHP 5.4 to PHP 7.2
  • Loading branch information
Mikhail Sandakov committed Mar 12, 2024
1 parent 9067f08 commit 8cb79c6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions actions/php.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,54 @@ def _do_check(self) -> bool:
return False


class AssertOSVendorPHPUsedByWebsites(action.CheckAction):
min_version: version.PHPVersion

def __init__(
self,
min_version: str,
):
self.name = "checking OS vendor PHP used by websites"
self.min_version = version.PHPVersion(min_version)
self.description = """We have detected that some domains are using the OS vendor PHP version.
\tSwitch the following domains to {modern} or later in order to continue with the conversion process:
\t- {domains}
\tYou can achieve this by executing the following command:
\t> plesk bin domain -u [domain] -php_handler_id plesk-php80-fastcgi
"""

def _do_check(self) -> bool:
log.debug("Checking the OS vendor PHP version used by the websites")
if not plesk.is_plesk_database_ready():
log.info("Plesk database is not ready. Skipping the OS vendor PHP check.")
return True

os_vendor_php_handlers = ["'fpm'", "'fastcgi'"]
log.debug(f"OS vendor PHP handlers: {os_vendor_php_handlers}")

try:
looking_for_domains_sql_request = """
SELECT d.name FROM domains d JOIN hosting h ON d.id = h.dom_id WHERE h.php_handler_id in ({});
""".format(", ".join(os_vendor_php_handlers))

os_vendor_php_domains = plesk.get_from_plesk_database(looking_for_domains_sql_request)
if not os_vendor_php_domains:
return True

log.debug(f"OS vendor PHP domains: {os_vendor_php_domains}")
os_vendor_php_domains = "\n\t- ".join(os_vendor_php_domains)
self.description = self.description.format(
modern=self.min_version,
domains=os_vendor_php_domains
)
except Exception as ex:
log.err("Unable to get domains list from plesk database!")
raise RuntimeError("Unable to get domains list from plesk database!") from ex

return False


OS_VENDOR_PHP_FPM_CONFIG = "/etc/php-fpm.d/www.conf"


Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def is_required_conditions_satisfied(options: typing.Any, stage_flag: Stages) ->
actions.AssertMinPhpVersionInstalled("7.2"),
actions.AssertMinPhpVersionUsedByWebsites("7.2"),
actions.AssertMinPhpVersionUsedByCron("7.2"),
actions.AssertOSVendorPHPUsedByWebsites("7.2"),
actions.CheckGrubInstalled(),
actions.CheckNoMoreThenOneKernelNamedNIC(),
actions.CheckIsInContainer(),
Expand Down

0 comments on commit 8cb79c6

Please sign in to comment.