Skip to content

Commit

Permalink
[SYNC] [FAU-405] feat: flush rewrite rules after cache warming for th…
Browse files Browse the repository at this point in the history
…e consuming website (#139)

Co-authored-by: Philipp Bammes <[email protected]>
  • Loading branch information
inpsyde-deploybot and tyrann0us committed Mar 27, 2024
1 parent d213525 commit 3c4226d
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 6 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/quality-assurance-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ jobs:
secrets:
COMPOSER_AUTH_JSON: ${{ secrets.PACKAGIST_AUTH_JSON }}
with:
PHP_VERSION: "8.0"
PHP_VERSION: "8.2"
static-code-analysis-php:
uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main
secrets:
COMPOSER_AUTH_JSON: ${{ secrets.PACKAGIST_AUTH_JSON }}
with:
PHP_VERSION: "8.0"
PHP_VERSION: "8.2"
lint-php:
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
strategy:
matrix:
php: [ "8.2", "8.3" ]
with:
PHP_MATRIX: >-
["8.0", "8.1", "8.2"]
PHP_VERSION: ${{ matrix.php }}
tests-unit-php:
needs: [ coding-standards-analysis-php, static-code-analysis-php ]
uses: inpsyde/reusable-workflows/.github/workflows/tests-unit-php.yml@main
strategy:
matrix:
php: [ "8.2", "8.3" ]
with:
PHP_MATRIX: >-
["8.0", "8.1", "8.2"]
PHP_VERSION: ${{ matrix.php }}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Degree program URL returns 404 for consuming websites.

## [1.0.2] - 2023-11-23
### Fixed
Expand Down
5 changes: 5 additions & 0 deletions src/Infrastructure/QueueModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Fau\DegreeProgram\Common\Infrastructure\Queue\WpCronMessageBus;
use Fau\DegreeProgram\Output\Infrastructure\Cache\WarmCacheMessage;
use Fau\DegreeProgram\Output\Infrastructure\Cache\WarmCacheMessageHandler;
use Fau\DegreeProgram\Output\Infrastructure\Rewrite\FlushRewriteRulesMessageHandler;
use Fau\DegreeProgram\Output\Infrastructure\Rewrite\FlushRewriteRulesMessage;
use Fau\DegreeProgram\Output\Infrastructure\Search\UpdateFilterablePostsMetaMessageHandler;
use Fau\DegreeProgram\Output\Infrastructure\Search\UpdateFilterableTermsMessage;
use Fau\DegreeProgram\Output\Infrastructure\Search\UpdateFilterableTermsMessageHandler;
Expand Down Expand Up @@ -46,6 +48,9 @@ public function services(): array
UpdateFilterableTermsMessage::class => [
$container->get(UpdateFilterableTermsMessageHandler::class),
],
FlushRewriteRulesMessage::class => [
$container->get(FlushRewriteRulesMessageHandler::class),
],
],
),
SyncMessageBus::class => static fn(ContainerInterface $container) => new SyncMessageBus(
Expand Down
29 changes: 29 additions & 0 deletions src/Infrastructure/Rewrite/FlushRewriteRulesMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Fau\DegreeProgram\Output\Infrastructure\Rewrite;

use Fau\DegreeProgram\Common\Application\Queue\Message;

final class FlushRewriteRulesMessage implements Message
{
private function __construct()
{
}

public static function new(): self
{
return new self();
}

public static function fromArray(array $array): static
{
return new self();
}

public function jsonSerialize(): array
{
return [];
}
}
22 changes: 22 additions & 0 deletions src/Infrastructure/Rewrite/FlushRewriteRulesMessageHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Fau\DegreeProgram\Output\Infrastructure\Rewrite;

use Psr\Log\LoggerInterface;

final class FlushRewriteRulesMessageHandler
{
public function __construct(
private LoggerInterface $logger,
) {
}

public function __invoke(): void
{
flush_rewrite_rules();

$this->logger->info('Rewrite rules flushed.');
}
}
22 changes: 22 additions & 0 deletions src/Infrastructure/Rewrite/RewriteModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

namespace Fau\DegreeProgram\Output\Infrastructure\Rewrite;

use Fau\DegreeProgram\Common\Application\Event\CacheWarmed;
use Fau\DegreeProgram\Common\Application\Queue\MessageBus;
use Fau\DegreeProgram\Output\Infrastructure\Environment\EnvironmentDetector;
use Fau\DegreeProgram\Output\Infrastructure\Repository\PostsRepository;
use Inpsyde\Modularity\Module\ExecutableModule;
use Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
use Inpsyde\Modularity\Module\ServiceModule;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

class RewriteModule implements ServiceModule, ExecutableModule
{
Expand All @@ -21,6 +25,12 @@ public function services(): array
$container->get(PostsRepository::class)
),
CurrentRequest::class => static fn() => new CurrentRequest(),
FlushRewriteRulesMessageHandler::class => static fn(ContainerInterface $container) => new FlushRewriteRulesMessageHandler(
$container->get(LoggerInterface::class),
),
WhenCacheWarmed::class => static fn(ContainerInterface $container) => new WhenCacheWarmed(
$container->get(MessageBus::class),
),
];
}

Expand All @@ -31,6 +41,18 @@ public function run(ContainerInterface $container): bool
[$container->get(ModifyRequestArgs::class), 'modify']
);

if ($container->get(EnvironmentDetector::class)->isProvidingWebsite()) {
return true;
}

add_action(
CacheWarmed::NAME,
[
$container->get(WhenCacheWarmed::class),
'scheduleFlushRewriting',
]
);

return true;
}
}
22 changes: 22 additions & 0 deletions src/Infrastructure/Rewrite/WhenCacheWarmed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Fau\DegreeProgram\Output\Infrastructure\Rewrite;

use Fau\DegreeProgram\Common\Application\Queue\MessageBus;

final class WhenCacheWarmed
{
public function __construct(
private MessageBus $messageBus,
) {
}

public function scheduleFlushRewriting(): void
{
$this->messageBus->dispatch(
FlushRewriteRulesMessage::new(),
);
}
}

0 comments on commit 3c4226d

Please sign in to comment.