...
 
Commits (1)
<?php
namespace T3o\TerFe2\Event;
/**
* 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!
*/
class Typo3ExtensionsEvent implements \TYPO3\CMS\Core\SingletonInterface
{
/**
* @param \T3o\TerFe2\Domain\Model\Version $version
* @return void
*/
public function newVersionUpload(\T3o\TerFe2\Domain\Model\Version $version)
{
$payload = [
'token' => $this->getAccessToken(),
'source' => 'extensions.typo3.org',
'data' => [
'extension_key' => $version->getExtension()->getExtKey(),
'version' => $version->getVersionString(),
'integer_version' => $version->getVersionNumber(),
'state' => $version->getState(),
'title' => $version->getTitle(),
'description' => $version->getDescription(),
'author_name' => $version->getAuthor()->getName(),
'last_updated' => $version->getUploadDate()
]
];
$this->sendCurlRequest($payload);
}
protected function sendCurlRequest(array $payload)
{
$curl = curl_init();
curl_setopt_array(
$curl,
[
CURLOPT_URL => 'https://slack.t3extensions.org/v1/UpdateExtension',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
'cache-control: no-cache',
'content-type: application/json'
],
]
);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
}
/**
* @return string
*/
protected function getAccessToken()
{
$configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class);
$configuration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TerFe2');
return (string)$configuration['api']['t3extensions']['accessToken'];
}
/**
* @return string
*/
protected function getApiEndpointUrl()
{
$configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class);
$configuration = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TerFe2');
return (string)$configuration['api']['t3extensions']['endpointUrl'];
}
}