Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V12 compatibility #25

Merged
merged 4 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .editorconfig
100644 → 100755
Empty file.
Empty file modified .github/FUNDING.yml
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE.md
100644 → 100755
Empty file.
Empty file modified .github/PULL_REQUEST_TEMPLATE.md
100644 → 100755
Empty file.
Empty file modified .github/workflows/ci.yaml
100644 → 100755
Empty file.
Empty file modified .github/workflows/codecoverage.yaml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .php-cs-fixer.php
100644 → 100755
Empty file.
Empty file modified CONTRIBUTING.md
100644 → 100755
Empty file.
15 changes: 3 additions & 12 deletions Classes/Client/ApiClient.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,11 @@

class ApiClient implements ApiClientInterface
{
private Feed $feed;

private RequestFactory $requestFactory;

private string $apiBaseUrl;

public function __construct(
Feed $feed,
RequestFactory $requestFactory,
string $apiBaseUrl
private readonly Feed $feed,
private readonly RequestFactory $requestFactory,
private readonly string $apiBaseUrl,
) {
$this->feed = $feed;
$this->requestFactory = $requestFactory;
$this->apiBaseUrl = $apiBaseUrl;
}

/**
Expand Down
Empty file modified Classes/Client/ApiClientInterface.php
100644 → 100755
Empty file.
6 changes: 1 addition & 5 deletions Classes/Command/AccessTokenRefresherCommand.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@

final class AccessTokenRefresherCommand extends Command
{
private AccessTokenRefresher $accessTokenRefresher;

public function __construct(
AccessTokenRefresher $accessTokenRefresher
private readonly AccessTokenRefresher $accessTokenRefresher,
) {
$this->accessTokenRefresher = $accessTokenRefresher;

parent::__construct();
}

Expand Down
20 changes: 6 additions & 14 deletions Classes/Command/ImportPostsCommand.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace SvenPetersen\Instagram\Command;

use SvenPetersen\Instagram\Domain\Model\Feed;
use SvenPetersen\Instagram\Domain\Repository\FeedRepository;
use SvenPetersen\Instagram\Factory\ApiClientFactoryInterface;
use SvenPetersen\Instagram\Service\PostUpserter;
Expand All @@ -24,21 +25,11 @@

class ImportPostsCommand extends Command
{
private FeedRepository $feedRepository;

private ApiClientFactoryInterface $apiClientFactory;

private PostUpserter $postUpserter;

public function __construct(
FeedRepository $feedRepository,
ApiClientFactoryInterface $apiClientFactory,
PostUpserter $postUpserter
private readonly FeedRepository $feedRepository,
private readonly ApiClientFactoryInterface $apiClientFactory,
private readonly PostUpserter $postUpserter,
) {
$this->feedRepository = $feedRepository;
$this->apiClientFactory = $apiClientFactory;
$this->postUpserter = $postUpserter;

parent::__construct();
}

Expand Down Expand Up @@ -89,7 +80,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$querySettings->setRespectStoragePage(false);
$this->feedRepository->setDefaultQuerySettings($querySettings);

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

if ($feed === null) {
$output->writeln(sprintf('<fg=red>No feed entity found for given username "%s".</>', $username));
Expand Down
16 changes: 5 additions & 11 deletions Classes/Controller/PostController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,29 @@

namespace SvenPetersen\Instagram\Controller;

use Psr\Http\Message\ResponseInterface;
use SvenPetersen\Instagram\Domain\Model\Post;
use SvenPetersen\Instagram\Domain\Repository\PostRepository;
use SvenPetersen\Instagram\Event\Controller\PreRenderActionEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

class PostController extends ActionController
{
public function listAction(): void
public function listAction(): ResponseInterface
{
/** @var PostRepository $postRepository */
$postRepository = GeneralUtility::makeInstance(PostRepository::class);
$posts = $postRepository->findBySettings($this->settings);

$this->view->assign('posts', $posts);

/** @var PreRenderActionEvent $event */
$event = $this->eventDispatcher->dispatch(new PreRenderActionEvent($this->view, __METHOD__));

$this->view = $event->view;
return $this->htmlResponse();
}

public function showAction(Post $post): void
public function showAction(Post $post): ResponseInterface
{
$this->view->assign('post', $post);

/** @var PreRenderActionEvent $event */
$event = $this->eventDispatcher->dispatch(new PreRenderActionEvent($this->view, __METHOD__));

$this->view = $event->view;
return $this->htmlResponse();
}
}
32 changes: 22 additions & 10 deletions Classes/Controller/TokenGeneratorController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@

namespace SvenPetersen\Instagram\Controller;

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
{
private AccessTokenService $accessTokenService;

public function __construct(AccessTokenService $accessTokenService)
{
$this->accessTokenService = $accessTokenService;
public function __construct(
private readonly ModuleTemplateFactory $moduleTemplateFactory,
private readonly AccessTokenService $accessTokenService,
) {
}

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

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

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

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

Expand All @@ -35,17 +41,21 @@ public function stepTwoAction(): void

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

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

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

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

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

Expand All @@ -68,8 +78,10 @@ public function stepThreeAction(): void
$storagePid
);

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

return $view->renderResponse('StepThree');
}
}
40 changes: 4 additions & 36 deletions Classes/Domain/Model/Dto/FeedDTO.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,11 @@

class FeedDTO
{
private string $id;

private string $username;

private string $accountType;

private int $mediaCount;

public function __construct(
string $id,
string $username,
string $accountType,
int $mediaCount
public readonly string $id,
public readonly string $username,
public readonly string $accountType,
public readonly int $mediaCount,
) {
$this->id = $id;
$this->username = $username;
$this->accountType = $accountType;
$this->mediaCount = $mediaCount;
}

public function getId(): string
{
return $this->id;
}

public function getUsername(): string
{
return $this->username;
}

public function getAccountType(): string
{
return $this->accountType;
}

public function getMediaCount(): int
{
return $this->mediaCount;
}
}
Empty file modified Classes/Domain/Model/Dto/PostDTO.php
100644 → 100755
Empty file.
5 changes: 1 addition & 4 deletions Classes/Domain/Model/Feed.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ class Feed extends AbstractEntity

protected string $username = '';

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

/**
* @var ObjectStorage<\SvenPetersen\Instagram\Domain\Model\Post>
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Post.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Post extends AbstractEntity
/**
* @var int
*/
protected $_languageUid = -1;
protected ?int $_languageUid = -1;

protected string $caption = '';

Expand Down
4 changes: 0 additions & 4 deletions Classes/Domain/Repository/FeedRepository.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@

namespace SvenPetersen\Instagram\Domain\Repository;

use SvenPetersen\Instagram\Domain\Model\Feed;
use TYPO3\CMS\Extbase\Persistence\Repository;

/**
* @method Feed|null findOneByUsername(string $username)
*/
class FeedRepository extends Repository
{
}
35 changes: 3 additions & 32 deletions Classes/Domain/Repository/PostRepository.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@

namespace SvenPetersen\Instagram\Domain\Repository;

use SvenPetersen\Instagram\Domain\Model\Post;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;

/**
* @method Post|null findOneByInstagramid($id)
*/
class PostRepository extends Repository
{
protected $defaultOrderings = [
Expand All @@ -44,7 +40,7 @@ public function findBySettings(array $settings): QueryResultInterface
$feedConstraints[] = $query->equals('feed', $feed);
}

$constraints[] = $query->logicalOr($feedConstraints);
$constraints[] = $query->logicalOr(...$feedConstraints);
}

// MediaType constraints
Expand All @@ -55,7 +51,7 @@ public function findBySettings(array $settings): QueryResultInterface
$mediaTypeConstraints[] = $query->equals('mediaType', $mediaType);
}

$constraints[] = $query->logicalOr($mediaTypeConstraints);
$constraints[] = $query->logicalOr(...$mediaTypeConstraints);
}

// Hashtag constraints
Expand All @@ -73,31 +69,6 @@ public function findBySettings(array $settings): QueryResultInterface
$query->setLimit((int)$settings['maxPostsToShow']);
}

return $query->matching($query->logicalAnd($constraints))->execute();
}

/**
* @param array<string, mixed> $constraints
* @return Post|null
*/
public function findOneBy(array $constraints)
{
$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(false);

$constrains = [];
foreach ($constraints as $field => $value) {
$constrains[] = $query->equals($field, $value);
}

$query->matching($query->logicalAnd($constrains));

/** @var Post|null $result */
$result = $query
->setLimit(1)
->execute()
->getFirst();

return $result;
return $query->matching($query->logicalAnd(...$constraints))->execute();
}
}
35 changes: 0 additions & 35 deletions Classes/Event/Controller/PreRenderActionEvent.php

This file was deleted.

Empty file modified Classes/Factory/ApiClientFactory.php
100644 → 100755
Empty file.
Empty file modified Classes/Factory/ApiClientFactoryInterface.php
100644 → 100755
Empty file.
Empty file modified Classes/Factory/Dto/FeedDTOFactory.php
100644 → 100755
Empty file.
Empty file modified Classes/Factory/Dto/PostDTOFactory.php
100644 → 100755
Empty file.
Empty file modified Classes/Factory/FeedFactory.php
100644 → 100755
Empty file.
Empty file modified Classes/Factory/FeedFactoryInterface.php
100644 → 100755
Empty file.
Empty file modified Classes/Hooks/ItemsProcFunc.php
100644 → 100755
Empty file.
Empty file modified Classes/Service/AccessTokenRefresher.php
100644 → 100755
Empty file.
Empty file modified Classes/Service/AccessTokenService.php
100644 → 100755
Empty file.
Empty file modified Classes/Service/EmojiRemover.php
100644 → 100755
Empty file.
Loading