Skip to content

Commit

Permalink
Merge pull request #12469 from escopecz/php8.2
Browse files Browse the repository at this point in the history
PHP 8.2 support
  • Loading branch information
escopecz committed Feb 6, 2024
2 parents e22ebba + 9d69788 commit ca468e6
Show file tree
Hide file tree
Showing 27 changed files with 133 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type: php
docroot: ""
php_version: "8.0"
php_version: "8.2"
webserver_type: apache-fpm
router_http_port: "80"
router_https_port: "443"
Expand All @@ -12,7 +12,7 @@ mysql_version: ""
provider: default
use_dns_when_possible: true
composer_version: "2"
webimage_extra_packages: [php8.0-imap]
webimage_extra_packages: [php8.2-imap]
hooks:
post-start:
# Fix line endings on Windows
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

strategy:
matrix:
php-versions: ['8.0', '8.1']
php-versions: ['8.0', '8.1', '8.2']
db-types: ['mysql', 'mariadb']

name: PHPUnit ${{ matrix.php-versions }} ${{ matrix.db-types }}
Expand Down
4 changes: 3 additions & 1 deletion app/bundles/CoreBundle/Controller/ExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public function showAction(Request $request, \Throwable $exception, ThemeHelper
$layout = 'prod' == MAUTIC_ENV ? 'Error' : 'Exception';
$code = $exception->getStatusCode();

if (0 === $code) {
// All valid status codes are within the range of 100 to 599, inclusive
// @see https://www.rfc-editor.org/rfc/rfc9110.html#name-status-codes
if ($code < 100 || $code > 599) {
// thrown exception that didn't set a code
$code = 500;
}
Expand Down
9 changes: 0 additions & 9 deletions app/bundles/CoreBundle/Doctrine/Type/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Mautic\CoreBundle\Helper\UTF8Helper;

/**
* Type that maps a PHP array to a clob SQL type.
Expand All @@ -19,14 +18,6 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
return (null === $value) ? 'N;' : 'a:0:{}';
}

// MySQL will crap out on corrupt UTF8 leading to broken serialized strings
array_walk(
$value,
function (&$entry): void {
$entry = UTF8Helper::toUTF8($entry);
}
);

$serialized = serialize($value);

if (str_contains($serialized, chr(0))) {
Expand Down
3 changes: 1 addition & 2 deletions app/bundles/CoreBundle/Helper/InputHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ public static function html($value)
// Special handling for HTML comments
$value = str_replace(['<!-->', '<!--', '-->'], ['<mcomment></mcomment>', '<mcomment>', '</mcomment>'], $value, $commentCount);

// detect if there is any unicode character in the passed string
$hasUnicode = strlen($value) != strlen(utf8_decode($value));
$hasUnicode = strlen($value) != strlen(iconv('UTF-8', 'Windows-1252', $value));

$value = self::getFilter(true)->clean($value, $hasUnicode ? 'raw' : 'html');

Expand Down
24 changes: 11 additions & 13 deletions app/bundles/CoreBundle/Helper/UTF8Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Mautic\CoreBundle\Helper;

/**
* @deprecated as unused and unnecessary. To be removed in Mautic 6 without replacement.
*/
class UTF8Helper
{
public const ICONV_TRANSLIT = 'TRANSLIT';
Expand Down Expand Up @@ -299,20 +302,15 @@ public static function encode($encodingLabel, $text)
return self::toUTF8($text);
}

/**
* @return string|false
*/
protected static function utf8_decode($text, $option)
{
if (self::WITHOUT_ICONV == $option || !function_exists('iconv')) {
$o = utf8_decode(
str_replace(array_keys(self::$utf8ToWin1252), array_values(self::$utf8ToWin1252), self::toUTF8($text))
);
} else {
$o = iconv(
'UTF-8',
'Windows-1252'.(self::ICONV_TRANSLIT == $option ? '//TRANSLIT' : (self::ICONV_IGNORE == $option ? '//IGNORE' : '')),
$text
);
}

return $o;
return iconv(
'UTF-8',
'Windows-1252'.(self::ICONV_TRANSLIT == $option ? '//TRANSLIT' : (self::ICONV_IGNORE == $option ? '//IGNORE' : '')),
$text
);
}
}
4 changes: 3 additions & 1 deletion app/bundles/CoreBundle/IpLookup/AbstractRemoteDataLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Mautic\CoreBundle\IpLookup;

use GuzzleHttp\Exception\GuzzleException;

abstract class AbstractRemoteDataLookup extends AbstractLookup
{
/**
Expand Down Expand Up @@ -59,7 +61,7 @@ protected function lookup()
]);

$this->parseResponse($response->getBody());
} catch (\Exception $exception) {
} catch (GuzzleException $exception) {
if ($this->logger) {
$this->logger->warning('IP LOOKUP: '.$exception->getMessage());
}
Expand Down
11 changes: 11 additions & 0 deletions app/bundles/CoreBundle/IpLookup/ExtremeIpLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

class ExtremeIpLookup extends AbstractRemoteDataLookup
{
public string $businessWebsite = '';
public string $continent = '';
public string $countryCode = '';
public string $ipName = '';
public string $ipType = '';
public string $lat = '';
public string $lon = '';
public string $org = '';
public string $query = '';
public string $status = '';

/**
* Return attribution HTML displayed in the configuration UI.
*/
Expand Down
19 changes: 19 additions & 0 deletions app/bundles/CoreBundle/IpLookup/GeobytesLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@

class GeobytesLookup extends AbstractRemoteDataLookup
{
public string $forwarderfor = '';
public string $remoteip = '';
public string $ipaddress = '';
public string $certainty = '';
public string $internet = '';
public string $regionlocationcode = '';
public string $code = '';
public string $locationcode = '';
public string $cityid = '';
public string $fqcn = '';
public string $capital = '';
public string $nationalitysingular = '';
public string $population = '';
public string $nationalityplural = '';
public string $mapreference = '';
public string $currency = '';
public string $currencycode = '';
public string $title = '';

public function getAttribution(): string
{
return '<a href="http://geobytes.com/" target="_blank">Geobytes</a> offers both free (16,000 lookups per hour) and VIP (paid) offerings.';
Expand Down
6 changes: 6 additions & 0 deletions app/bundles/CoreBundle/IpLookup/GeoipsLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

class GeoipsLookup extends AbstractRemoteDataLookup
{
public string $continent_name = '';
public string $continent_code = '';
public string $country_code = '';
public string $region_code = '';
public string $county_name = '';

public function getAttribution(): string
{
return '<a href="http://www.geoips.com/" target="_blank">GeoIPs</a> offers tiered subscriptions for lookups.';
Expand Down
5 changes: 5 additions & 0 deletions app/bundles/CoreBundle/IpLookup/IpinfodbLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

class IpinfodbLookup extends AbstractRemoteDataLookup
{
public string $statusCode = '';
public string $statusMessage = '';
public string $ipAddress = '';
public string $countryCode = '';

public function getAttribution(): string
{
return '<a href="http://www.ipinfodb.com/" target="_blank">iPInfoDB</a> offers a free service (2 lookups per second) that leverages data from IP2Location. API key required.';
Expand Down
4 changes: 4 additions & 0 deletions app/bundles/CoreBundle/IpLookup/IpstackLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

class IpstackLookup extends AbstractRemoteDataLookup
{
public string $country_code = '';
public string $region_code = '';
public string $metro_code = '';

public function getAttribution(): string
{
return '<a href="https://ipstack.com/" target="_blank">ipstack.com</a> is a free lookup service that leverages GeoLite2 data created by MaxMind.';
Expand Down
8 changes: 8 additions & 0 deletions app/bundles/CoreBundle/IpLookup/TelizeLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

class TelizeLookup extends AbstractRemoteDataLookup
{
public string $offset = '';
public string $area_code = '';
public string $dma_code = '';
public string $country_code3 = '';
public string $continent_code = '';
public string $country_code = '';
public string $region_code = '';

public function getAttribution(): string
{
return '<a href="https://market.mashape.com/fcambus/telize/" target="_blank">Telize</a> is a paid lookup service.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function decodeTokens(PageDisplayEvent $event): void

// replace slots
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10FFFF, 0, 0xFFFFF], 'UTF-8'), LIBXML_NOERROR);
$xpath = new \DOMXPath($dom);

$divContent = $xpath->query('//*[@data-slot="dwc"]');
Expand All @@ -174,7 +174,7 @@ public function decodeTokens(PageDisplayEvent $event): void
}

$newnode = $dom->createDocumentFragment();
$newnode->appendXML('<![CDATA['.mb_convert_encoding($slotContent, 'HTML-ENTITIES', 'UTF-8').']]>');
$newnode->appendXML('<![CDATA['.mb_encode_numericentity($slotContent, [0x80, 0x10FFFF, 0, 0xFFFFF], 'UTF-8').']]>');
$slot->parentNode->replaceChild($newnode, $slot);
}

Expand Down
8 changes: 5 additions & 3 deletions app/bundles/EmailBundle/Tests/Model/EmailModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
* @property LeadDeviceRepository|(LeadDeviceRepository&object&MockObject)|(LeadDeviceRepository&MockObject)|(object&MockObject)|MockObject $leadDeviceRepository
*/
class EmailModelTest extends \PHPUnit\Framework\TestCase
{
public const SEGMENT_A = 'segment A';

public const SEGMENT_B = 'segment B';

/**
* @var Connection|LeadDeviceRepository
*/
private \PHPUnit\Framework\MockObject\MockObject $leadDeviceRepository;

/**
* @var Connection|MockObject
*/
Expand Down
4 changes: 2 additions & 2 deletions app/bundles/FormBundle/Model/FormModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,9 +874,9 @@ public function getFormList($limit = 10, \DateTime $dateFrom = null, \DateTime $
private function loadHTML(&$dom, $html): void
{
if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) {
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$dom->loadHTML(mb_encode_numericentity($html, [0x80, 0x10FFFF, 0, 0xFFFFF], 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
} else {
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
$dom->loadHTML(mb_encode_numericentity($html, [0x80, 0x10FFFF, 0, 0xFFFFF], 'UTF-8'));
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/bundles/InstallBundle/Configurator/Step/CheckStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function checkOptionalSettings(): array
$messages[] = 'mautic.install.function.iconv';
}

if (!function_exists('utf8_decode')) {
if (!extension_loaded('xml')) {
$messages[] = 'mautic.install.function.xml';
}

Expand Down
5 changes: 5 additions & 0 deletions app/bundles/InstallBundle/Configurator/Step/DoctrineStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class DoctrineStep implements StepInterface
*/
public $host = 'localhost';

/**
* Database host. Read Only Replica.
*/
public ?string $host_ro = null;

/**
* Database table prefix.
* Required in step.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Mautic\IntegrationsBundle\Sync\DAO\Sync\Order\FieldDAO as OrderFieldDAO;
use Mautic\IntegrationsBundle\Sync\DAO\Sync\Order\ObjectChangeDAO;
use Mautic\IntegrationsBundle\Sync\DAO\Value\NormalizedValueDAO;
use Mautic\IntegrationsBundle\Sync\SyncDataExchange\Internal\Object as SyncObject;
use Mautic\IntegrationsBundle\Sync\SyncDataExchange\Internal\Object\Company as SyncObjectCompany;
use Mautic\IntegrationsBundle\Sync\SyncDataExchange\Internal\ObjectHelper\CompanyObjectHelper;
use Mautic\IntegrationsBundle\Sync\SyncDataExchange\MauticSyncDataExchange;
use Mautic\LeadBundle\Entity\Company;
Expand Down Expand Up @@ -66,7 +66,7 @@ public function testUpdate(): void

private function buildObjectChangeDAO(Company $company, string $name, string $value): ObjectChangeDAO
{
$objectChangeDAO = new ObjectChangeDAO('Test', MauticSyncDataExchange::OBJECT_COMPANY, $company->getId(), SyncObject\Company::NAME, $company->getId(), new \DateTime());
$objectChangeDAO = new ObjectChangeDAO('Test', MauticSyncDataExchange::OBJECT_COMPANY, $company->getId(), SyncObjectCompany::NAME, $company->getId(), new \DateTime());
$objectChangeDAO->addField(new OrderFieldDAO($name, new NormalizedValueDAO(NormalizedValueDAO::PHONE_TYPE, $value)));

return $objectChangeDAO;
Expand Down
2 changes: 2 additions & 0 deletions app/bundles/LeadBundle/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Tag
*/
private $description;

public ?int $deletedId;

public function __construct(string $tag = null, bool $clean = true)
{
$this->tag = $clean && $tag ? $this->validateTag($tag) : $tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testTagWorkflow(): void
// Delete:
$this->client->request('DELETE', "/api/tags/{$tagId}/delete");
$clientResponse = $this->client->getResponse();
$this->assertSame(Response::HTTP_OK, $clientResponse->getStatusCode());
$this->assertSame(Response::HTTP_OK, $clientResponse->getStatusCode(), $clientResponse->getContent());

// Get (ensure it's deleted):
$this->client->request('GET', "/api/tags/{$tagId}");
Expand Down
4 changes: 2 additions & 2 deletions app/bundles/PageBundle/EventListener/BuilderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public function onPageDisplay(Events\PageDisplayEvent $event): void
// replace slots
if (count($params)) {
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10FFFF, 0, 0xFFFFF], 'UTF-8'), LIBXML_NOERROR);
$xpath = new \DOMXPath($dom);

$divContent = $xpath->query('//*[@data-slot="segmentlist"]');
Expand Down Expand Up @@ -422,7 +422,7 @@ public function onPageDisplay(Events\PageDisplayEvent $event): void
// add form before first block of prefs center
if (isset($params['startform']) && str_contains($content, 'data-prefs-center')) {
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10FFFF, 0, 0xFFFFF], 'UTF-8'), LIBXML_NOERROR);
$xpath = new \DOMXPath($dom);
// If use slots
$divContent = $xpath->query('//*[@data-prefs-center="1"]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function testEmailReportWithAggregatedColumnsAndTotals(): void
$result = [];
$content = $response->getContent();
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10FFFF, 0, 0xFFFFF], 'UTF-8'), LIBXML_NOERROR);
$tbody = $dom->getElementById('reportTable')->getElementsByTagName('tbody')[0];
$rows = $tbody->getElementsByTagName('tr');

Expand Down Expand Up @@ -228,7 +228,7 @@ public function testContactReportNotLikeExpression(): void

$dom = new \DOMDocument('1.0', 'utf-8');

$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10FFFF, 0, 0xFFFFF], 'UTF-8'), LIBXML_NOERROR);
$tbody = $dom->getElementById('reportTable')->getElementsByTagName('tbody')[0];
$rows = $tbody->getElementsByTagName('tr');

Expand Down
2 changes: 2 additions & 0 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ext-zip": "*",
"ext-imap": "*",
"ext-pdo": "*",
"ext-iconv": "*",
"symfony/amqp-messenger": "~5.4",
"symfony/console": "~5.4.0",
"symfony/form": "~5.4.0",
Expand Down Expand Up @@ -103,6 +104,7 @@
"composer/composer": "^2.2",
"beberlei/doctrineextensions": "^1.3",
"exercise/htmlpurifier-bundle": "^4.1",
"ezyang/htmlpurifier": "^4.16",
"giggsey/libphonenumber-for-php": "^8.12",
"symfony/doctrine-messenger": "^5.4",
"symfony/mailer": "~5.4",
Expand Down
2 changes: 1 addition & 1 deletion app/release_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "5.0.2",
"stability": "stable",
"minimum_php_version": "8.0.2",
"maximum_php_version": "8.1.99",
"maximum_php_version": "8.2.99",
"minimum_mysql_version": "5.7.14",
"minimum_mariadb_version": "10.2.7",
"show_php_version_warning_if_under": "8.0.2",
Expand Down

0 comments on commit ca468e6

Please sign in to comment.