Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Oct 20, 2023
1 parent f26f32a commit 67b85b7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
@@ -1,3 +1,3 @@
<h{{ block.data.level }}{{ blockWrapperAttr(block) }}{{ block.tunes.textAlign.alignment == 'center' ? ' class="text-center"' : ''}}{{ block.tunes.textAlign.alignment == 'right' ? ' class="text-right"' : ''}}>
<h{{ block.data.level }}{{ blockWrapperAttr(block) }}{{ block.tunes.textAlign.alignment|default('') == 'center' ? ' class="text-center"' : ''}}{{ block.tunes.textAlign.alignment|default('') == 'right' ? ' class="text-right"' : ''}}>
{{ block.data.text|raw }}
</h{{ block.data.level }}>
27 changes: 19 additions & 8 deletions packages/page-update-notifier/src/PageUpdateNotifier.php
Expand Up @@ -3,7 +3,7 @@
namespace Pushword\PageUpdateNotifier;

use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Log\LoggerInterface;
use Pushword\Core\Component\App\AppPool;
use Pushword\Core\Entity\PageInterface;
use Pushword\Core\Repository\Repository;
Expand Down Expand Up @@ -48,24 +48,33 @@ class PageUpdateNotifier
/**
* @param class-string<PageInterface> $pageClass
*/
public function __construct(private readonly string $pageClass, private readonly MailerInterface $mailer, private readonly AppPool $apps, private readonly string $varDir, private readonly EntityManagerInterface $em, private readonly TranslatorInterface $translator, private readonly Twig $twig)
{
public function __construct(
private readonly string $pageClass,
private readonly MailerInterface $mailer,
private readonly AppPool $apps,
private readonly string $varDir,
private readonly EntityManagerInterface $em,
private readonly TranslatorInterface $translator,
private readonly Twig $twig,
private readonly ?LoggerInterface $logger = null,
) {
}

public function postUpdate(PageInterface $page): void
{
try {
$this->run($page);
} catch (\Exception) {
} catch (\Exception $e) {
$this->logger?->info('[PageUpdateNotifier] '.$e->getMessage());
}
}

public function postPersist(PageInterface $page): void
{
try {
$this->run($page);
} catch (\Exception) {
// todo log exception
} catch (\Exception $e) {
$this->logger?->info('[PageUpdateNotifier] '.$e->getMessage());
}
}

Expand Down Expand Up @@ -124,7 +133,7 @@ public function getCacheDir(): string

public function getCacheFilePath(): string
{
return $this->getCacheDir().'/lastPageUpdateNotification'.md5($this->app->getMainHost());
return $this->getCacheDir().'/lastPageUpdateNotification'; // .md5($this->app->getMainHost())
}

public function run(PageInterface $page): int|string
Expand Down Expand Up @@ -163,6 +172,8 @@ public function run(PageInterface $page): int|string
$lastTime->set();
$this->mailer->send($message);

return 'Notify send for '.\count($pages).' page(s)';
$this->logger?->info('[PageUpdateNotifier] Notification sent for '.\count($pages).' page(s)');

return 'Notification sent';
}
}
19 changes: 2 additions & 17 deletions packages/page-update-notifier/tests/PageUpdateNotifierTest.php
Expand Up @@ -32,7 +32,7 @@ protected function getNotifier()
sys_get_temp_dir(),
$entityManager,
$translator,
$twig
$twig,
);
}

Expand All @@ -51,21 +51,6 @@ protected function getPage()
->setHost('localhost.dev');
}

public function testNoEmailToException()
{
$notifier = $this->getNotifier();
$this->expectExceptionCode(PageUpdateNotifier::ERROR_NO_EMAIL);
$notifier->run($this->getPage());
}

public function testNoEmailFromException()
{
$notifier = $this->getNotifier();
$this->getApps()->get()->setCustomProperty('page_update_notification_from', 'contact@example.tld');
$this->expectExceptionCode(PageUpdateNotifier::ERROR_NO_EMAIL);
$notifier->run($this->getPage());
}

public function testRun()
{
$notifier = $this->getNotifier();
Expand All @@ -79,7 +64,7 @@ public function testRun()
self::$kernel->getContainer()->get('doctrine.orm.default_entity_manager')->persist($this->getPage());
self::$kernel->getContainer()->get('doctrine.orm.default_entity_manager')->flush();

$this->assertSame('Notify send for 1 page(s)', $notifier->run($this->getPage()));
$this->assertSame('Notification sent', $notifier->run($this->getPage()));

$this->assertSame(PageUpdateNotifier::WAS_EVER_RUN_SINCE_INTERVAL, $notifier->run($this->getPage()));

Expand Down
5 changes: 4 additions & 1 deletion packages/skeleton/config/packages/pushword.yaml
Expand Up @@ -9,7 +9,10 @@ pushword:
generated_og_image: true,
admin_block_editor: false,
admin_block_editor_disable_listener: true,
locales: 'fr|en'
locales: 'fr|en',
page_update_notification_from: test@example.tld,
page_update_notification_to: test@example.tld

}
- {
hosts: [pushword.piedweb.com],
Expand Down
Binary file modified packages/skeleton/var/app.db
Binary file not shown.

0 comments on commit 67b85b7

Please sign in to comment.