| Server IP : 89.108.64.180 / Your IP : 216.73.216.229 Web Server : Apache/2.4.41 (Ubuntu) System : Linux 89-108-64-180.cloudvps.regruhosting.ru 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-root ( 1010) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/otel-vershina.ru/dup-installer/src/Utils/Tests/ |
Upload File : |
<?php
/**
* Customizes final report error messages
*
* Standard: PSR-2
* @link http://www.php-fig.org/psr/psr-2 Full Documentation
*
* @package SC\DUPX\U
*
*/
namespace Duplicator\Installer\Utils\Tests;
class MessageCustomizer
{
const CONTEXT_SHORT_MESSAGE = 'short';
const CONTEXT_LONG_MESSAGE = 'long';
const CONTEXT_NOTICE_ID = 'notice-id';
/**
* Tries to apply each customization until one of them works
*
* @param string $shortMessage short message of notice to be customized
* @param string $longMessage long message of notice to be customized
* @param string $noticeId notice IDfinal-tests.php
* @return bool true if any of the customizations were applied, false otherwise
*/
public static function applyAllNoticeCustomizations(&$shortMessage, &$longMessage, &$noticeId)
{
foreach (self::getCustomizationItems() as $item) {
if ($item->conditionSatisfied($longMessage)) {
$shortMessage = $item->apply($shortMessage, self::CONTEXT_SHORT_MESSAGE);
$longMessage = $item->apply($longMessage, self::CONTEXT_LONG_MESSAGE);
$noticeId = $item->apply($noticeId, self::CONTEXT_NOTICE_ID);
return true;
}
}
return false;
}
/**
* Get customization to apply at error messages
*
* @return MessageCustomizerItem[] customizations list
* @throws \Exception
*/
protected static function getCustomizationItems()
{
$items = array();
$items[] = new MessageCustomizerItem(
function ($string) {
if (self::getArchiveConfigData() == false) {
return false;
}
return preg_match("/undefined.*create_function/", $string) &&
version_compare(phpversion(), "8") >= 0 &&
version_compare(self::getArchiveConfigData()->version_php, "8") < 0;
},
function ($string, $context) {
if (self::getArchiveConfigData() == false) {
return $string;
}
$phpVersionNew = self::getTwoLevelVersion(phpversion());
$phpVersionOld = self::getTwoLevelVersion(self::getArchiveConfigData()->version_php);
$longMsgPrefix = "There is code in this site that is not compatible with PHP " . $phpVersionNew . ". " .
"To make the install work you will either have to\ninstall on PHP " .
$phpVersionOld . " or ";
switch ($context) {
case self::CONTEXT_SHORT_MESSAGE:
return "Source site or plugins are incompatible with PHP " . $phpVersionNew;
case self::CONTEXT_LONG_MESSAGE:
if (($plugin = self::getProblematicPluginFromError($string)) !== false) {
return $longMsgPrefix . "disable the plugin '{$plugin->name}' (slug: $plugin->slug) using a " .
"file manager of your choice.\nSee full error message below: \n\n" . $string;
} elseif (($theme = self::getProblematicThemeFromError($string)) !== false) {
return $longMsgPrefix . "disable the theme '{$theme->themeName}' (slug: $theme->slug) using a " .
"file manager of your choice.\nSee full error message below: \n\n" . $string;
} else {
return $longMsgPrefix . "manually modify the affected files mentioned in the error trace below: \n\n" .
$string;
}
case self::CONTEXT_NOTICE_ID:
return $string . '_php8';
}
}
);
return $items;
}
/**
* Return the plugin that is causing the error message if present
*
* @param string $longMessage the long error message containing the error trace
*
* @return false|object object containing plugin info or false on failure
*/
protected static function getProblematicPluginFromError($longMessage)
{
if (($archiveConfig = self::getArchiveConfigData()) === false) {
return false;
}
$oldMain = $archiveConfig->wpInfo->targetRoot;
$oldMuPlugins = $archiveConfig->wpInfo->configs->realValues->originalPaths->muplugins;
$oldPlugins = $archiveConfig->wpInfo->configs->realValues->originalPaths->plugins;
$relativeMuPlugins = str_replace($oldMain, "", $oldMuPlugins);
$relativePlugins = str_replace($oldMain, "", $oldPlugins);
$regex = "/(?:" . preg_quote($relativePlugins, "/") . "\/|" . preg_quote($relativeMuPlugins, "/") . "\/)(.*?)(\/|\.php).*$/m";
if (!preg_match($regex, $longMessage, $matches)) {
return false;
}
//matches the first part of the slug related to the plugin directory
$slug = $matches[1];
foreach ($archiveConfig->wpInfo->plugins as $plugin) {
if (strpos($plugin->slug, $slug) === 0) {
return $plugin;
}
}
return false;
}
/**
* Returns the theme that is causing the error message if present
*
* @param string $longMessage the long error message containing the error trace
*
* @return false|object object containing theme info or false
*/
protected static function getProblematicThemeFromError($longMessage)
{
$archiveConfig = self::getArchiveConfigData();
$oldMain = $archiveConfig->wpInfo->targetRoot;
$oldThemes = $archiveConfig->wpInfo->configs->realValues->originalPaths->themes;
$relativeThemes = str_replace($oldMain, "", $oldThemes);
file_put_contents(
DUPX_INIT . "/my_log.txt",
"OLD THEMES: {$oldThemes} \n" .
"Relative themes: {$relativeThemes} \n" .
"regex: " . "/(" . preg_quote($relativeThemes, "/") . "\/)(.*?)(\/|\.php).*$/m"
);
if (!preg_match("/(?:" . preg_quote($relativeThemes, "/") . "\/)(.*?)(?:\/|\.php).*$/m", $longMessage, $matches)) {
return false;
}
$slug = $matches[1];
foreach ($archiveConfig->wpInfo->themes as $theme) {
if ($theme->slug == $slug) {
return $theme;
}
}
return false;
}
/**
* Get package config data
*
* @return false|object package config data or false on failure
*/
protected static function getArchiveConfigData()
{
static $archiveConfig = null;
if (is_null($archiveConfig)) {
if (
($path = glob(DUPX_INIT . "/dup-archive__*.txt")) === false ||
count($path) !== 1
) {
return $archiveConfig = false;
}
if (($json = file_get_contents($path[0])) === false) {
return $archiveConfig = false;
}
$archiveConfig = json_decode($json);
if (!is_object($archiveConfig)) {
$archiveConfig = false;
}
}
return $archiveConfig;
}
/**
* @param string $version a version number
* @return string returns only the first 2 levels of the version numbers
*/
private static function getTwoLevelVersion($version)
{
$arr = explode(".", $version);
return $arr[0] . "." . $arr[1];
}
}