Skip to content

Commit

Permalink
TYPO3 v13 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
svenpet90 committed Nov 18, 2024
1 parent d6ac4f5 commit 3393f33
Show file tree
Hide file tree
Showing 29 changed files with 401 additions and 766 deletions.
3 changes: 1 addition & 2 deletions Classes/Client/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public function __construct(
private readonly Feed $feed,
private readonly RequestFactory $requestFactory,
private readonly string $apiBaseUrl,
) {
}
) {}

/**
* @inheritDoc
Expand Down
7 changes: 1 addition & 6 deletions Classes/Command/ImportPostsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$username = $input->getArgument('username');
/** @var int<0,max> $storagePid */
$storagePid = $input->getArgument('storagePid');
$limit = $input->getArgument('limit');

Expand All @@ -63,12 +64,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::FAILURE;
}

if (is_numeric($storagePid) === false) {
$output->writeln(sprintf('<fg=red>The StoragePid argument must be an Integer. "%s" given.</>', $storagePid));

return Command::FAILURE;
}

if (is_numeric($limit) === false) {
$output->writeln(sprintf('<fg=red>The limit argument must be an Integer. "%s" given.</>', $limit));

Expand Down
36 changes: 14 additions & 22 deletions Classes/Controller/TokenGeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,59 @@

use Psr\Http\Message\ResponseInterface;
use SvenPetersen\Instagram\Service\AccessTokenService;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class TokenGeneratorController extends ActionController
{
public function __construct(
private readonly ModuleTemplateFactory $moduleTemplateFactory,
private readonly AccessTokenService $accessTokenService,
) {
}
) {}

public function stepOneAction(): ResponseInterface
{
$view = $this->moduleTemplateFactory->create($this->request);

return $view->renderResponse('StepOne');
return $this->htmlResponse();
}

public function stepTwoAction(): ResponseInterface
{
$view = $this->moduleTemplateFactory->create($this->request);

/** @var string $appId */
$appId = $this->request->getArgument('clientid');
assert(is_string($appId));

/** @var string $returnUrl */
$returnUrl = $this->request->getArgument('returnurl');
assert(is_string($returnUrl));

/** @var string $appSecret */
$appSecret = $this->request->getArgument('clientsecret');
assert(is_string($appSecret));

$storagePid = (int)$this->request->getArgument('storagePid');
assert(is_int($storagePid));

$link = $this->accessTokenService->getAuthorizationLink($appId, $returnUrl);

$view->assignMultiple([
$this->view->assignMultiple([
'link' => $link,
'appId' => $appId,
'returnUrl' => $returnUrl,
'appSecret' => $appSecret,
'storagePid' => $storagePid,
]);

return $view->renderResponse('StepTwo');
return $this->htmlResponse();
}

public function stepThreeAction(): ResponseInterface
{
$view = $this->moduleTemplateFactory->create($this->request);

/** @var string $instagramAppId */
$instagramAppId = $this->request->getArgument('clientid');
assert(is_string($instagramAppId));

/** @var string $clientSecret */
$clientSecret = $this->request->getArgument('clientsecret');
assert(is_string($clientSecret));

/** @var string $redirect_uri */
$redirect_uri = $this->request->getArgument('returnurl');
assert(is_string($redirect_uri));

/** @var string $code */
$code = $this->request->getArgument('code');
assert(is_string($code));

$storagePid = (int)$this->request->getArgument('storagePid');

Expand All @@ -78,10 +70,10 @@ public function stepThreeAction(): ResponseInterface
$storagePid
);

$view->assignMultiple([
$this->view->assignMultiple([
'feed' => $feed,
]);

return $view->renderResponse('StepThree');
return $this->htmlResponse();
}
}
3 changes: 1 addition & 2 deletions Classes/Domain/Model/Dto/FeedDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ public function __construct(
public readonly string $username,
public readonly string $accountType,
public readonly int $mediaCount,
) {
}
) {}
}
3 changes: 0 additions & 3 deletions Classes/Domain/Model/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class Post extends AbstractEntity
/** @var string */
public const MEDIA_TYPE_VIDEO = 'VIDEO';

/**
* @var int
*/
protected ?int $_languageUid = -1;

protected string $caption = '';
Expand Down
4 changes: 1 addition & 3 deletions Classes/Domain/Repository/FeedRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

use TYPO3\CMS\Extbase\Persistence\Repository;

class FeedRepository extends Repository
{
}
class FeedRepository extends Repository {}
23 changes: 10 additions & 13 deletions Classes/Factory/FeedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;

class FeedFactory implements FeedFactoryInterface
readonly class FeedFactory implements FeedFactoryInterface
{
private FeedRepository $feedRepository;

private PersistenceManagerInterface $persistenceManager;

public function __construct(
FeedRepository $feedRepository,
PersistenceManagerInterface $persistenceManager
) {
$this->feedRepository = $feedRepository;
$this->persistenceManager = $persistenceManager;
}
private FeedRepository $feedRepository,
private PersistenceManagerInterface $persistenceManager
) {}

public function create(): Feed
{
return new Feed();
}

/**
* @param int<0, max> $storagePid
*/
public function upsert(
string $token,
string $tokenType,
Expand All @@ -49,19 +45,20 @@ public function upsert(
$querySettings->setRespectStoragePage(false);
$this->feedRepository->setDefaultQuerySettings($querySettings);

/** @var Feed|null $feed */
$feed = $this->feedRepository->findOneBy(['username' => $username]);

if ($feed === null) {
$feed = $this->create();
}

$feed->setPid($storagePid);
$feed
->setToken($token)
->setTokenType($tokenType)
->setExpiresAt($expiresAt)
->setUserId($userId)
->setUsername($username);
->setUsername($username)
->setPid($storagePid);

$this->feedRepository->add($feed);
$this->persistenceManager->persistAll();
Expand Down
3 changes: 1 addition & 2 deletions Classes/Service/AccessTokenRefresher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace SvenPetersen\Instagram\Service;

use DateTime;
use SvenPetersen\Instagram\Domain\Model\Feed;
use SvenPetersen\Instagram\Domain\Repository\FeedRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -65,7 +64,7 @@ public function refreshAccessToken(Feed $feed): Feed
{
/** @var \DateTimeImmutable $expiresAt */
$expiresAt = $feed->getExpiresat();
$now = new DateTime();
$now = new \DateTime();
$diffInDays = $expiresAt->diff($now)->days;

if ($diffInDays >= 10) {
Expand Down
4 changes: 2 additions & 2 deletions Classes/Service/PostUpserter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public function upsertPost(PostDTO $dto, int $storagePid, ApiClientInterface $ap
$querySettings = $this->postRepository->createQuery()->getQuerySettings();
$querySettings->setStoragePageIds([$storagePid]);
$this->postRepository->setDefaultQuerySettings($querySettings);

$action = 'UPDATE';

/** @var Post|null $post */
$post = $this->postRepository->findOneBy([
'instagram_id' => $dto->getId(),
'pid' => $storagePid
'pid' => $storagePid,
]);

if ($post === null) {
Expand Down
9 changes: 3 additions & 6 deletions Configuration/Backend/Modules.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php

use SvenPetersen\Instagram\Controller\TokenGeneratorController;
use TYPO3\CMS\Core\Configuration\Features;

if (TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Features::class)
if (TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\Features::class)
->isFeatureEnabled('instagram.tokenGeneratorBeModule')
) {
return [
Expand All @@ -15,9 +12,9 @@
'path' => '/module/system/instagram',
'icon' => 'EXT:instagram/Resources/Public/Icons/instagram.jpg',
'labels' => 'LLL:EXT:instagram/Resources/Private/Language/locallang_db.xml:instagram',
'extensionName' => 'Examples',
'extensionName' => 'Instagram',
'controllerActions' => [
TokenGeneratorController::class => [
\SvenPetersen\Instagram\Controller\TokenGeneratorController::class => [
'stepOne', 'stepTwo', 'stepThree',
],
],
Expand Down
Loading

0 comments on commit 3393f33

Please sign in to comment.