-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added package for generating Persoo articles feed
- the feed contains both blog articles and regular articles (with type "site")
- Loading branch information
0 parents
commit 5edc128
Showing
19 changed files
with
574 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
on: [push] | ||
concurrency: | ||
group: ${{ github.ref }} | ||
cancel-in-progress: true | ||
name: "Checks and tests" | ||
jobs: | ||
checks-and-tests: | ||
name: Run checks and tests | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: GIT checkout branch - ${{ github.ref }} | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.ref }} | ||
- name: Install PHP, extensions and tools | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.1' | ||
extensions: bcmath, gd, intl, pdo_pgsql, redis, pgsql, zip | ||
tools: composer | ||
- name: Install Composer dependencies | ||
run: composer install --optimize-autoloader --no-interaction | ||
- name: Run parallel-lint | ||
run: php vendor/bin/parallel-lint ./src ./tests | ||
- name: Run Easy Coding Standards | ||
run: php vendor/bin/ecs check --verbose ./src ./tests | ||
- name: Run PHPUnit | ||
run: php vendor/bin/phpunit tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/.idea | ||
/.php_cs.cache | ||
/composer.lock | ||
/vendor | ||
/.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Contributing | ||
|
||
Thank you for your contributions to Shopsys Article Feed Persoo package. | ||
Together we are making Shopsys Platform better. | ||
|
||
This repository is READ-ONLY. | ||
If you want to [report issues](https://github.com/shopsys/shopsys/issues/new) and/or send [pull requests](https://github.com/shopsys/shopsys/compare), | ||
please use the main [Shopsys repository](https://github.com/shopsys/shopsys). | ||
|
||
Please, check our [Contribution Guide](https://docs.shopsys.com/en/latest/contributing/) before contributing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017-2023 Shopsys s.r.o., http://www.shopsys.com | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Shopsys Article Feed Persoo | ||
|
||
[![Downloads](https://img.shields.io/packagist/dt/shopsys/article-feed-persoo.svg)](https://packagist.org/packages/shopsys/article-feed-persoo) | ||
|
||
Plugin for [Shopsys Platform](https://www.shopsys.com/shopsys-platform/) responsible for generating XML article feed for [Persoo](https://persoo.cz). | ||
|
||
For detailed information about the feed see [official documentation](https://support.persoo.ai). | ||
|
||
This repository is maintained by [shopsys/shopsys] monorepo, information about changes is in [monorepo CHANGELOG.md](https://github.com/shopsys/shopsys/blob/master/CHANGELOG.md). | ||
|
||
## Installation | ||
|
||
The plugin is a Symfony bundle and is installed in the same way: | ||
|
||
### Download | ||
|
||
Download the package using [Composer](https://getcomposer.org/): | ||
|
||
``` | ||
composer require shopsys/article-feed-persoo | ||
``` | ||
|
||
## How to use | ||
|
||
You should see the new feed immediately after installation in the administration feed list. | ||
All output XML files will be automatically generated by a cron module or they can be generated manually in administration when logged as superadmin. | ||
|
||
## Contributing | ||
|
||
Thank you for your contributions to Shopsys Article Feed Persoo package. | ||
Together we are making Shopsys Platform better. | ||
|
||
This repository is READ-ONLY. | ||
If you want to [report issues](https://github.com/shopsys/shopsys/issues/new) and/or send [pull requests](https://github.com/shopsys/shopsys/compare), | ||
please use the main [Shopsys repository](https://github.com/shopsys/shopsys). | ||
|
||
Please, check our [Contribution Guide](https://docs.shopsys.com/en/latest/contributing/) before contributing. | ||
|
||
## Support | ||
|
||
What to do when you are in troubles or need some help? | ||
The best way is to join our [Slack](https://join.slack.com/t/shopsysframework/shared_invite/zt-11wx9au4g-e5pXei73UJydHRQ7nVApAQ). | ||
|
||
If you want to [report issues](https://github.com/shopsys/shopsys/issues/new), please use the main [Shopsys repository](https://github.com/shopsys/shopsys). | ||
|
||
[shopsys/shopsys]: (https://github.com/shopsys/shopsys) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "shopsys/article-feed-persoo", | ||
"type": "library", | ||
"description": "Shopsys Platform plugin interface for Persoo XML article feed generation", | ||
"keywords": ["Persoo", "article feed", "XML feed", "plugin", "Shopsys Platform", "SSFW", "SSP"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Shopsys", | ||
"homepage": "https://www.shopsys.com/" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Shopsys\\ArticleFeed\\PersooBundle\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\ArticleFeed\\PersooBundle\\": "tests/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^8.1", | ||
"ext-json": "*", | ||
"ext-pdo": "*", | ||
"doctrine/dbal": "^3.3.3", | ||
"doctrine/doctrine-bundle": "^2.5.7", | ||
"doctrine/orm": "^2.11.2", | ||
"doctrine/persistence": "^2.4", | ||
"shopsys/framework": "14.0.x-dev", | ||
"shopsys/migrations": "14.0.x-dev", | ||
"shopsys/plugin-interface": "14.0.x-dev", | ||
"symfony/config": "^5.4", | ||
"symfony/dependency-injection": "^5.4", | ||
"symfony/form": "^5.4", | ||
"symfony/http-kernel": "^5.4", | ||
"symfony/translation": "^5.4" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5.20", | ||
"shopsys/coding-standards": "14.0.x-dev", | ||
"twig/twig": "^3.5.0" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"symfony/flex": true, | ||
"dealerdirect/phpcodesniffer-composer-installer": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer; | ||
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer; | ||
use Shopsys\CodingStandards\CsFixer\ForbiddenPrivateVisibilityFixer; | ||
use Shopsys\CodingStandards\Sniffs\ForceLateStaticBindingForProtectedConstantsSniff; | ||
use Shopsys\CodingStandards\Sniffs\ObjectIsCreatedByFactorySniff; | ||
use SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff; | ||
use Symplify\EasyCodingStandard\Config\ECSConfig; | ||
|
||
/** | ||
* @param Symplify\EasyCodingStandard\Config\ECSConfig $ecsConfig | ||
*/ | ||
return static function (ECSConfig $ecsConfig): void { | ||
$ecsConfig->rule(ForceLateStaticBindingForProtectedConstantsSniff::class); | ||
|
||
/* | ||
* this package is meant to be extensible using class inheritance, | ||
* so we want to avoid private visibilities in the model namespace | ||
*/ | ||
$services = $ecsConfig->services(); | ||
$services->set('forbidden_private_visibility_fixer.article_feed_persoo', ForbiddenPrivateVisibilityFixer::class) | ||
->call('configure', [ | ||
[ | ||
'analyzed_namespaces' => [ | ||
'Shopsys\ArticleFeed\PersooBundle\Model', | ||
], | ||
], | ||
]); | ||
|
||
$ecsConfig->skip([ | ||
ObjectIsCreatedByFactorySniff::class => [ | ||
__DIR__ . '/tests/*', | ||
], | ||
PhpdocToPropertyTypeFixer::class => [ | ||
__DIR__ . '/src/*', | ||
], | ||
DeclareStrictTypesFixer::class => [ | ||
__DIR__ . '/src/*', | ||
], | ||
]); | ||
|
||
$ecsConfig->import(__DIR__ . '/vendor/shopsys/coding-standards/ecs.php', null, true); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
failOnWarning="true" | ||
beStrictAboutTestsThatDoNotTestAnything="false" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
> | ||
<coverage/> | ||
</phpunit> |
35 changes: 35 additions & 0 deletions
35
src/DependencyInjection/ShopsysArticleFeedPersooExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\ArticleFeed\PersooBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
class ShopsysArticleFeedPersooExtension extends Extension implements PrependExtensionInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | ||
$loader->load('services.yaml'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function prepend(ContainerBuilder $container): void | ||
{ | ||
$container->prependExtensionConfig('doctrine_migrations', [ | ||
'migrations_paths' => [ | ||
'Shopsys\ArticleFeed\PersooBundle\Migrations' => __DIR__ . '/../Migrations', | ||
], | ||
]); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\ArticleFeed\PersooBundle\Model; | ||
|
||
use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig; | ||
use Shopsys\FrameworkBundle\Model\CombinedArticle\CombinedArticleElasticsearchFacade; | ||
|
||
class PersooArticleFacade | ||
{ | ||
/** | ||
* @param \Shopsys\ArticleFeed\PersooBundle\Model\PersooArticleFeedItemFactory $persooArticleFeedItemFactory | ||
* @param \Shopsys\FrameworkBundle\Model\CombinedArticle\CombinedArticleElasticsearchFacade $combinedArticleElasticsearchFacade | ||
*/ | ||
public function __construct( | ||
protected readonly PersooArticleFeedItemFactory $persooArticleFeedItemFactory, | ||
protected readonly CombinedArticleElasticsearchFacade $combinedArticleElasticsearchFacade, | ||
) { | ||
} | ||
|
||
/** | ||
* @param \Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig $domainConfig | ||
* @param int|null $lastSeekId | ||
* @param int $maxResults | ||
* @return iterable<int, \Shopsys\ArticleFeed\PersooBundle\Model\PersooArticleFeedItem> | ||
*/ | ||
public function getItems(DomainConfig $domainConfig, ?int $lastSeekId, int $maxResults): iterable | ||
{ | ||
if ($lastSeekId === null) { | ||
$lastSeekId = 0; | ||
} | ||
$articlesData = $this->combinedArticleElasticsearchFacade->getArticlesByDomainId($domainConfig->getId(), $lastSeekId, $maxResults); | ||
|
||
foreach ($articlesData as $article) { | ||
yield $this->persooArticleFeedItemFactory->create($article, $lastSeekId); | ||
$lastSeekId++; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\ArticleFeed\PersooBundle\Model; | ||
|
||
use Shopsys\FrameworkBundle\Model\Feed\FeedItemInterface; | ||
|
||
class PersooArticleFeedItem implements FeedItemInterface | ||
{ | ||
/** | ||
* @param int $id | ||
* @param string $title | ||
* @param string $link | ||
* @param string|null $description | ||
* @param string|null $imageLink | ||
*/ | ||
public function __construct( | ||
protected readonly int $id, | ||
public readonly string $title, | ||
public readonly string $link, | ||
public readonly ?string $description, | ||
public readonly ?string $imageLink, | ||
) { | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getSeekId(): int | ||
{ | ||
return $this->id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\ArticleFeed\PersooBundle\Model; | ||
|
||
use Shopsys\FrameworkBundle\Model\Feed\FeedItemImageHelper; | ||
|
||
class PersooArticleFeedItemFactory | ||
{ | ||
/** | ||
* @param array $articleData | ||
* @param int $itemNumber | ||
* @return \Shopsys\ArticleFeed\PersooBundle\Model\PersooArticleFeedItem | ||
*/ | ||
public function create(array $articleData, int $itemNumber): PersooArticleFeedItem | ||
{ | ||
return new PersooArticleFeedItem( | ||
$itemNumber, | ||
$articleData['name'], | ||
$articleData['url'], | ||
$articleData['text'], | ||
$this->getImageUrl($articleData), | ||
); | ||
} | ||
|
||
/** | ||
* @param array $articleData | ||
* @return string|null | ||
*/ | ||
protected function getImageUrl(array $articleData): ?string | ||
{ | ||
if (!array_key_exists('imageUrl', $articleData) || $articleData['imageUrl'] === null) { | ||
return null; | ||
} | ||
|
||
return FeedItemImageHelper::limitWidthInImageUrl($articleData['imageUrl']); | ||
} | ||
} |
Oops, something went wrong.