Commit c5a6e7fb authored by Thomas Löffler's avatar Thomas Löffler
Browse files

Merge branch 'develop' into 'main'

Release 16-06-2021

See merge request !439
parents 41a92385 3579043f
Pipeline #12475 passed with stages
in 7 minutes and 46 seconds
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4bd1433c5b5962f510f3fac11cf47f27",
"content-hash": "e4f9d0baef023126f6526f4fd8bd0bb4",
"packages": [
{
"name": "adoy/fastcgi-client",
......@@ -6441,19 +6441,22 @@
},
{
"name": "t3o/randombanners",
"version": "2.0.3",
"dist": {
"type": "zip",
"url": "https://gitlab.typo3.org/api/v4/projects/12/packages/composer/archives/t3o/randombanners.zip?sha=b492499ac8011ebff9bbcf65d1587bb86f1da967",
"reference": "b492499ac8011ebff9bbcf65d1587bb86f1da967",
"shasum": ""
"version": "2.1.1",
"source": {
"type": "git",
"url": "https://gitlab.typo3.org/services/t3o-sites/typo3.org/randombanners.git",
"reference": "eb79c2fca8ad66e4f7acb66a02190432cf9071da"
},
"require": {
"t3o/t3o_membership": "^3.0",
"typo3/cms-core": ">=10.3.0,<10.9.99",
"typo3/cms-scheduler": ">=10.3.0,<10.9.99"
},
"type": "typo3-cms-extension",
"extra": {
"typo3/cms": {
"extension-key": "randombanners"
}
},
"autoload": {
"psr-4": {
"T3o\\Randombanners\\": "Classes"
......@@ -6466,7 +6469,8 @@
"homepage": "https://typo3.org",
"keywords": [
"TYPO3 CMS"
]
],
"time": "2021-06-01T16:09:41+00:00"
},
{
"name": "t3o/t3o_donation",
......
<?php
namespace T3o\T3orgLayout\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use T3o\T3orgLayout\Service\FetchMembersService;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class FetchMembersCommand extends Command
{
protected ?QueryBuilder $queryBuilder = null;
protected ?FetchMembersService $fetchMembersService = null;
protected array $extConfig = [];
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_t3omembership_domain_model_member');
$this->extConfig = GeneralUtility::makeInstance(ExtensionConfiguration::class)
->get('t3org_layout');
$this->fetchMembersService = GeneralUtility::makeInstance(FetchMembersService::class);
$this->fetchMembersService->token = $this->extConfig['BearerToken'];
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Importing members via API from my.typo3.org');
if (!$this->extConfig['BearerToken']) {
$io->error('No token for authentication to API found!');
return 1;
}
$io->section('Fetching members...');
$members = $this->fetchMembersService->getMembers();
if ($members) {
$io->success('Found ' . count($members) . ' members');
} else {
$io->warning('No members found. Please check the settings and API.');
return 1;
}
$io->section('Importing members...');
$this->queryBuilder
->update('tx_t3omembership_domain_model_member')
->where(
$this->queryBuilder->expr()->neq('external_identifier', '""')
)
->set('hidden', 1)
->execute();
$this->queryBuilder = $this->queryBuilder->getConnection()->createQueryBuilder();
$warnings = false;
foreach ($members as $member) {
$this->queryBuilder = $this->queryBuilder->getConnection()->createQueryBuilder();
$this->queryBuilder
->getRestrictions()
->removeByType(HiddenRestriction::class);
$existingMember = $this->queryBuilder
->select('uid')
->from('tx_t3omembership_domain_model_member')
->where(
$this->queryBuilder->expr()->eq(
'external_identifier',
$this->queryBuilder->quote($member['identifier'])
)
)
->execute()
->fetch();
$this->queryBuilder = $this->queryBuilder->getConnection()->createQueryBuilder();
if (!$existingMember) {
// Prepare member date for DB insert
$data = $member;
$data['external_identifier'] = $data['identifier'];
$data['url'] = $data['backlink'] ?? '';
$data['hidden'] = 0;
$data['pid'] = (int)$this->extConfig['MemberStorage'];
$data['tstamp'] = time();
$data['crdate'] = time();
$data['membership'] = $this->getMembershipId($data['membership']);
unset($data['votingEmail']);
unset($data['identifier']);
unset($data['backlink']);
$this->queryBuilder
->insert('tx_t3omembership_domain_model_member')
->values($data)
->execute();
} else {
$this->queryBuilder
->update('tx_t3omembership_domain_model_member')
->where(
$this->queryBuilder->expr()->eq(
'uid',
$existingMember['uid']
)
)
->set('name', $member['name'])
->set('email', $member['email'] ?? '')
->set('url', $member['backlink'] ?? '')
->set('membership', $this->getMembershipId($member['membership']))
->set('hidden', 0)
->set('tstamp', time())
->execute();
}
$io->success('Imported member: ' . $member['name']);
}
$io->section('Flushing caches on page with UID 160');
// Flush caches on page ID 160
GeneralUtility::makeInstance(CacheManager::class)
->flushCachesInGroupByTags(
'pages',
['pageId_160']
);
$io->success('Finished.');
return 0;
}
private function getMembershipId(string $membership): int
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_t3omembership_domain_model_membership');
$membershipRecord = $queryBuilder
->select('uid')
->from('tx_t3omembership_domain_model_membership')
->where(
$queryBuilder->expr()->eq('external_identifier', $queryBuilder->quote($membership))
)
->execute()
->fetch();
return $membershipRecord['uid'] ?? 0;
}
}
<?php
namespace T3o\T3orgLayout\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use T3o\T3orgLayout\Service\FetchMembersService;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class FetchPlatinumMembersCommand extends Command
{
protected ?QueryBuilder $queryBuilder = null;
protected ?FetchMembersService $fetchMembersService = null;
protected array $extConfig = [];
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_randombanners_domain_model_banner');
$this->extConfig = GeneralUtility::makeInstance(ExtensionConfiguration::class)
->get('t3org_layout');
$this->fetchMembersService = GeneralUtility::makeInstance(FetchMembersService::class);
$this->fetchMembersService->token = $this->extConfig['BearerToken'];
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Importing platinum members via API from my.typo3.org');
if (!$this->extConfig['BearerToken']) {
$io->error('No token for authentication to API found!');
return 1;
}
$io->section('Fetching members...');
$members = $this->fetchMembersService->getPlatinumMembers();
if ($members) {
$io->success('Found ' . count($members) . ' platinum members');
} else {
$io->warning('No members found. Please check the settings and API.');
return 1;
}
$io->section('Importing members...');
$this->queryBuilder
->update('tx_randombanners_domain_model_banner')
->where(
$this->queryBuilder->expr()->neq('external_identifier', '""')
)
->set('hidden', 1)
->execute();
$this->queryBuilder = $this->queryBuilder->getConnection()->createQueryBuilder();
$warnings = false;
foreach ($members as $member) {
$this->queryBuilder = $this->queryBuilder->getConnection()->createQueryBuilder();
$this->queryBuilder
->getRestrictions()
->removeByType(HiddenRestriction::class);
$existingMember = $this->queryBuilder
->select('uid')
->from('tx_randombanners_domain_model_banner')
->where(
$this->queryBuilder->expr()->eq(
'external_identifier',
$this->queryBuilder->quote($member['identifier'])
)
)
->execute()
->fetch();
$this->queryBuilder = $this->queryBuilder->getConnection()->createQueryBuilder();
if (!$existingMember) {
// Prepare member date for DB insert
$data = $member;
$data['external_logo'] = $data['logo'] ?? '';
$data['external_identifier'] = $data['identifier'];
$data['link'] = $data['backlink'] ?? '';
$data['hidden'] = 0;
$data['pid'] = (int)$this->extConfig['BannerStorage'];
$data['tstamp'] = time();
$data['crdate'] = time();
unset($data['logo']);
unset($data['identifier']);
unset($data['backlink']);
unset($data['membership']);
$this->queryBuilder
->insert('tx_randombanners_domain_model_banner')
->values($data)
->execute();
} else {
$this->queryBuilder
->update('tx_randombanners_domain_model_banner')
->where(
$this->queryBuilder->expr()->eq(
'uid',
$existingMember['uid']
)
)
->set('name', $member['name'])
->set('email', $member['email'] ?? '')
->set('external_logo', $member['logo'] ?? '')
->set('link', $member['backlink'] ?? '')
->set('hidden', 0)
->set('tstamp', time())
->execute();
}
if (!$member['logo'] || !$member['backlink']) {
$io->warning('Logo or backlink missing for member: ' . $member['name']);
$warnings = true;
}
$io->success('Imported platinum member: ' . $member['name']);
}
$io->section('Flushing caches on page with UID 1');
// Flush caches on page ID 1
GeneralUtility::makeInstance(CacheManager::class)
->flushCachesInGroupByTags(
'pages',
['pageId_1']
);
if ($warnings) {
$io->warning('Finished with warnings.');
} else {
$io->success('Finished.');
}
return 0;
}
}
<?php
namespace T3o\T3orgLayout\Domain\Model;
class Banner extends \T3o\Randombanners\Domain\Model\Banner
{
protected string $externalIdentifier = '';
protected string $externalLogo = '';
/**
* @return string
*/
public function getExternalIdentifier(): string
{
return $this->externalIdentifier;
}
/**
* @return string
*/
public function getExternalLogo(): string
{
return $this->externalLogo;
}
}
<?php
namespace T3o\T3orgLayout\Service;
use Symfony\Component\HttpClient\HttpClient;
class FetchMembersService
{
public string $token = '';
protected string $baseUri = 'https://my.typo3.org/api/t3o/memberships/';
protected function fetchDataFromApi($uri = ''): array
{
$client = HttpClient::create();
$response = $client->request(
'GET',
$uri ?: $this->baseUri,
[
'auth_bearer' => $this->token
]
);
if ($response->getStatusCode() === 200) {
return $response->toArray();
}
return [];
}
public function getMembers(): array
{
return $this->fetchDataFromApi();
}
public function getPlatinumMembers(): array
{
return $this->fetchDataFromApi($this->baseUri . 'platinum/');
}
}
<?php
declare(strict_types = 1);
return [
\T3o\T3orgLayout\Domain\Model\Banner::class => [
'tableName' => 'tx_randombanners_domain_model_banner'
],
];
services:
_defaults:
autowire: true
autoconfigure: true
public: false
T3o\T3orgLayout\:
resource: '../Classes/*'
T3o\T3orgLayout\Command\FetchPlatinumMembersCommand:
tags:
- name: 'console.command'
command: 't3o:fetchplatinummembers'
description: 'Fetch TYPO3 platinum members for import in randombanners'
T3o\T3orgLayout\Command\FetchMembersCommand:
tags:
- name: 'console.command'
command: 't3o:fetchmembers'
description: 'Fetch TYPO3 members for import in t3o_membership'
T3o\T3orgLayout\Event\ModifyDetailViewVariablesEvent:
tags:
- name: event.listener
......
<?php
$columns = [
'external_identifier' => [
'label' => 'External identifier (my.typo3.org)',
'exclude' => 1,
'config' => [
'type' => 'input',
'readOnly' => true,
],
],
'external_logo' => [
'label' => 'External logo (my.typo3.org)',
'exclude' => 1,
'config' => [
'type' => 'input',
'readOnly' => true,
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_randombanners_domain_model_banner',
$columns
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tx_randombanners_domain_model_banner',
'external_identifier,external_logo',
'',
'after:hidden'
);
<?php
$columns = [
'external_identifier' => [
'label' => 'External identifier (my.typo3.org)',
'exclude' => 1,
'config' => [
'type' => 'input',
'readOnly' => true,
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_t3omembership_domain_model_member',
$columns
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tx_t3omembership_domain_model_member',
'external_identifier',
'',
'after:hidden'
);
<?php
$columns = [
'external_identifier' => [
'label' => 'External identifier (my.typo3.org)',
'exclude' => 1,
'config' => [
'type' => 'input',
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_t3omembership_domain_model_membership',
$columns
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tx_t3omembership_domain_model_membership',
'external_identifier',
'',
'after:hidden'
);
......@@ -72,4 +72,7 @@ config.cache {
544 := addToList(tx_news_domain_model_news:470)
544 := addToList(tx_news_domain_model_news:474)
544 := addToList(tx_news_domain_model_news:475)
# Platinum members
1 := addToList(tx_randombanners_domain_model_banner:425)
}
plugin.tx_randombanners {
view {
templateRootPaths.50 = EXT:t3org_layout/Resources/Private/Extensions/Randombanners/Templates/
}
}
Randombanners / Listing of Platinum Mmebers
===========================================
The Random Banners are used to display logos and links of Platinum Members of the TYPO3 Association.
To import the members the Scheduler Taks / Command Line Command "FetchPlatinumMembersCommand" must be used.
</