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

[FEATURE] Fetch platinum members for randombanners via API

parent e04f53ef
Pipeline #12091 failed with stages
in 23 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 T3o\T3orgLayout\Service\FetchMembersService;
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)
{
$members = $this->fetchMembersService->getPlatinumMembers();
$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();
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();
}
}
}
}
<?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\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'
);
plugin.tx_randombanners {
view {
templateRootPaths.50 = EXT:t3org_layout/Resources/Private/Extensions/Randombanners/Templates/
}
}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:section name="content">
<div class="container">
<h2 class="text-center">{contentData.header}</h2>
<h3 class="text-center">{contentData.subheader}</h3>
<ul class="t3o-banners t3js-banners text-center">
<f:for each="{banners}" as="banner">
<li>
<f:link.page class="t3js-banner" target="_blank" additionalParams="{randombanners: '{banner: banner.uid}'}" additionalAttributes="{data-uid: banner.uid, rel: settings.linkAttributeRel}">
<f:if condition="{banner.externalLogo}">
<f:then>
<f:image src="{banner.externalLogo}" alt="{banner.name}" maxWidth="150" />
</f:then>
<f:else>
<f:if condition="{banner.logo}">
<f:image image="{banner.logo}" alt="{banner.name}" maxWidth="150" />
</f:if>
</f:else>
</f:if>
</f:link.page>
</li>
</f:for>
</ul>
</div>
</f:section>
</html>
# cat=PlatinumMembers; type=string; label=Authentication Bearer for importing members from my.typo3.org
BearerToken =
# cat=PlatinumMembers; type=int; label=PID for storing randombanner records after import
BannerStorage =
......@@ -23,3 +23,9 @@ $signalSlotDispatcher->connect(
\T3o\T3orgLayout\Slot\SolrSlot::class,
'addResultsWithoutFacets'
);
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
->registerImplementation(
\T3o\Randombanners\Domain\Model\Banner::class,
\T3o\T3orgLayout\Domain\Model\Banner::class
);
......@@ -22,3 +22,8 @@ CREATE TABLE tx_t3orglayout_domain_model_contributors (
role varchar(100) DEFAULT '' NOT NULL,
parent int(11) DEFAULT '0' NOT NULL
);
CREATE TABLE tx_randombanners_domain_model_banner (
external_identifier varchar(255) DEFAULT '' NOT NULL,
external_logo varchar(1024) DEFAULT '' NOT NULL
);
......@@ -127,6 +127,10 @@ return [
'loginFormPid' => '229',
'loginPid' => '178',
],
't3org_layout' => [
'BannerStorage' => '',
'BearerToken' => '',
],
],
'FE' => [
'cacheHash' => [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment