Skip to content

Commit

Permalink
[FEATURE] Compatibility with TYPO3 v11 and PHP 8.1 (#22)
Browse files Browse the repository at this point in the history
Raises version to 1.2.0
  • Loading branch information
mabolek authored Aug 18, 2022
1 parent 199a429 commit d4529bb
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Classes/Configuration/ExtensionConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function configureForSite(Site $site, int $languageId = 0): void
if ($language !== null) {
$languageConfiguration = $language->toArray();

if ($languageConfiguration['qbank_deploymentSites']) {
if ($languageConfiguration['qbank_deploymentSites'] ?? false) {
$this->deploymentSites = GeneralUtility::intExplode(
',',
$languageConfiguration['qbank_deploymentSites'],
Expand All @@ -160,7 +160,7 @@ public function configureForSite(Site $site, int $languageId = 0): void
}
}

if ($site->getConfiguration()['qbank_deploymentSites']) {
if ($site->getConfiguration()['qbank_deploymentSites'] ?? false) {
$this->deploymentSites = GeneralUtility::intExplode(
',',
$site->getConfiguration()['qbank_deploymentSites'],
Expand Down
11 changes: 8 additions & 3 deletions Classes/FormEngine/Container/QbankSelectorButtonContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Pixelant\Qbank\FormEngine\Container;

use Pixelant\Qbank\Configuration\ExtensionConfigurationManager;
use Pixelant\Qbank\Utility\CompatibilityUtility;
use Pixelant\Qbank\Utility\QbankUtility;
use TYPO3\CMS\Backend\Form\Container\InlineControlContainer;
use TYPO3\CMS\Core\Imaging\Icon;
Expand Down Expand Up @@ -167,12 +168,16 @@ protected function getExtensionConfigurationManager(): ExtensionConfigurationMan

$languageId = -1;
if ($languageField) {
$languageId = (int)$this->data['databaseRow'][$languageField][0];
if (CompatibilityUtility::typo3VersionIsLessThan('11')) {
$languageId = (int)$this->data['databaseRow'][$languageField][0];
} else {
$languageId = (int)$this->data['databaseRow'][$languageField];
}
}

$pageId = $this->data['defaultLanguageRow']['pid'];
$pageId = $this->data['defaultLanguageRow']['pid'] ?? null;
if ($this->data['tableName'] === 'pages') {
$pageId = $this->data['defaultLanguageRow']['uid'];
$pageId = $this->data['defaultLanguageRow']['uid'] ?? null;
}

if ($pageId === null) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/Repository/MediaUsageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function add(MediaUsage $mediaUsage): void
*/
public function removeOneByQbankAndLocalId(int $qbankId, string $localId): void
{
$usage = $this->findByQbankAndLocalId($qbankId, $localId)[0];
$usage = $this->findByQbankAndLocalId($qbankId, $localId)[0] ?? false;

if (!$usage) {
return;
Expand Down
5 changes: 3 additions & 2 deletions Classes/Service/QbankService.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,13 @@ public function synchronizeMetadata(int $fileId): void
/** @var MediaPropertyValue $qbankPropertyValue */
foreach ($qbankPropertyValues as $qbankPropertyValue) {
$sourceProperty = $qbankPropertyValue->getProperty()->getKey();
$targetProperty = $metaDataMappings[$sourceProperty];

if (!isset($targetProperty)) {
if (!isset($metaDataMappings[$sourceProperty])) {
continue;
}

$targetProperty = $metaDataMappings[$sourceProperty];

$this->eventDispatcher->dispatch(new FilePropertyChangeEvent(
$file,
$targetProperty,
Expand Down
80 changes: 80 additions & 0 deletions Classes/Utility/CompatibilityUtility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace Pixelant\Qbank\Utility;

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Utility\VersionNumberUtility;

/**
* Miscellaneous functions relating to compatibility with different TYPO3 versions
*/
class CompatibilityUtility
{
/**
* Returns true if the current TYPO3 version is less than $version
*
* @param string $version
* @return bool
*/
public static function typo3VersionIsLessThan(string $version)
{
return self::getTypo3VersionInteger() < VersionNumberUtility::convertVersionNumberToInteger($version);
}

/**
* Returns true if the current TYPO3 version is less than or equal to $version
*
* @param string $version
* @return bool
*/
public static function typo3VersionIsLessThanOrEqualTo(string $version)
{
return self::getTypo3VersionInteger() <= VersionNumberUtility::convertVersionNumberToInteger($version);
}

/**
* Returns true if the current TYPO3 version is greater than $version
*
* @param string $version
* @return bool
*/
public static function typo3VersionIsGreaterThan(string $version)
{
return self::getTypo3VersionInteger() > VersionNumberUtility::convertVersionNumberToInteger($version);
}

/**
* Returns true if the current TYPO3 version is greater than or equal to $version
*
* @param string $version
* @return bool
*/
public static function typo3VersionIsGreaterThanOrEqualTo(string $version)
{
return self::getTypo3VersionInteger() >= VersionNumberUtility::convertVersionNumberToInteger($version);
}

/**
* Returns the TYPO3 version as an integer
*
* @return int
*/
public static function getTypo3VersionInteger()
{
return VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getNumericTypo3Version());
}
}
7 changes: 6 additions & 1 deletion Classes/Utility/QbankUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ public static function getApi(): QBankApi
*/
public static function getAccessToken(): string
{
return self::getApi()->getTokens()['accessToken']->getToken();
// qbnk/qbank3api-phpwrapper ^4.9 returns an object. In later versions the value is a string.
if (is_object(self::getApi()->getTokens()['accessToken'])) {
return self::getApi()->getTokens()['accessToken']->getToken();
}

return self::getApi()->getTokens()['accessToken'];
}

/**
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
}
],
"require": {
"php": "^7.2",
"qbnk/qbank3api-phpwrapper": "^3.4",
"typo3/cms-core": "^10.4"
"php": "~7.2.0 || ~7.3.0 || ~7.4.0 || ~8.0",
"qbnk/qbank3api-phpwrapper": "^4.9 || ^5.1",
"typo3/cms-core": "^10.4 || ^11.5.2"
},
"replace": {
"typo3-ter/qbank": "self.version"
Expand All @@ -30,9 +30,9 @@
"codeception/codeception": "^4.1.5",
"helhum/typo3-composer-setup": "^0.5.7",
"nimut/testing-framework": "^5.0.3",
"phpunit/phpunit": "^7.5.20",
"seld/jsonlint": "^1.8",
"typo3/cms-fluid-styled-content": "^9.5 || ^10.4"
"phpunit/phpunit": "^8.5.28",
"seld/jsonlint": "^1.9",
"typo3/cms-fluid-styled-content": "^10.4 || ^11.5.2"
},
"suggest": {
"typo3/cms-filemetadata": "For additional meta data fields."
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'state' => 'stable',
'createDirs' => '',
'clearCacheOnLoad' => true,
'version' => '1.1.1',
'version' => '1.2.0',
'constraints' => [
'depends' => [
'typo3' => '10.4.0-10.4.99',
Expand Down

0 comments on commit d4529bb

Please sign in to comment.