-
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.
Initial commit ... nothing useful yet
- Loading branch information
0 parents
commit e3e4899
Showing
13 changed files
with
1,175 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,38 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
pull_request: ~ | ||
|
||
jobs: | ||
test: | ||
name: "Test (PHP ${{ matrix.php-versions }}, Neos ${{ matrix.neos-versions }})" | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php-versions: ['8.2', '8.3'] | ||
neos-versions: ['8.3'] | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
path: ${{ env.FLOW_FOLDER }} | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
extensions: mbstring, xml, json, zlib, iconv, intl, pdo_sqlite | ||
ini-values: date.timezone="Africa/Tunis", opcache.fast_shutdown=0, apc.enable_cli=on | ||
|
||
- name: Set Neos Version | ||
run: composer require neos/neos ^${{ matrix.neos-versions }} --no-progress --no-interaction | ||
|
||
- name: Run Tests | ||
run: composer test |
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,3 @@ | ||
composer.lock | ||
Packages | ||
vendor |
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,116 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\GrapeVine\Command; | ||
|
||
use Neos\Flow\Cli\CommandController; | ||
use Neos\Flow\Persistence\Doctrine\PersistenceManager; | ||
use Neos\Flow\Security\Account; | ||
use Neos\Flow\Security\AccountRepository; | ||
use Neos\Flow\Security\Policy\PolicyService; | ||
use Neos\Neos\Domain\Model\User; | ||
use Neos\Party\Domain\Model\AbstractParty; | ||
use Neos\Party\Domain\Repository\PartyRepository; | ||
use Sitegeist\GrapeVine\Domain\Model\Message; | ||
use Sitegeist\GrapeVine\Domain\Model\Notification; | ||
use Sitegeist\GrapeVine\Domain\Repository\MessageRepository; | ||
use Sitegeist\GrapeVine\Domain\Repository\NotificationRepository; | ||
|
||
class MessageCommandController extends CommandController | ||
{ | ||
protected function __construct( | ||
private readonly MessageRepository $messageRepository, | ||
private readonly NotificationRepository $notificationRepository, | ||
private readonly PolicyService $policyService, | ||
private readonly AccountRepository $accountRepository, | ||
private readonly PersistenceManager $persistenceManager | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @phpstan-param string[] $recipient | ||
* | ||
* @param string $title | ||
* @param string $text | ||
* @param array $recipient | ||
*/ | ||
public function addCommand(string $title, string $text, array $recipient = [], bool $notify = false): void | ||
{ | ||
|
||
$roles = array_map( | ||
fn(string $roleId) => $this->policyService->getRole($roleId), | ||
$recipient | ||
); | ||
|
||
$message = new Message(); | ||
$message->setTitle($title); | ||
$message->setText($text); | ||
$message->setRecipientRoles($recipient); | ||
$message->setDate(new \DateTimeImmutable()); | ||
|
||
$this->messageRepository->add($message); | ||
|
||
if ($notify) { | ||
/** | ||
* @var Account[] $accountsToNotify | ||
*/ | ||
$accountsToNotify = []; | ||
foreach ($roles as $role) { | ||
/** | ||
* @var Account[] $accounts | ||
* @phpstan-ignore method.notFound | ||
*/ | ||
$accounts = $this->accountRepository->findByRoleIdentifiers($role->getIdentifier()); | ||
foreach ($accounts as $account) { | ||
$id = $this->persistenceManager->getIdentifierByObject($account); | ||
$accountsToNotify[$id] = $account; | ||
} | ||
} | ||
|
||
foreach ($accountsToNotify as $account) { | ||
$notification = new Notification(); | ||
$notification->setAccount($account); | ||
$notification->setMessage($message); | ||
$this->notificationRepository->add($notification); | ||
} | ||
} | ||
} | ||
|
||
public function listCommand(): void | ||
{ | ||
$messages = $this->messageRepository->findAll(); | ||
$this->output->outputTable( | ||
array_map( | ||
fn(Message $message) => [ | ||
$message->getTitle(), | ||
(strlen($message->getText()) > 20) | ||
? substr($message->getText(), 0, 20) . ' ...' | ||
: $message->getText(), | ||
implode(', ', $message->getRecipientRoles()), | ||
$message->getDate()->format('Y-m-d H:i:s'), | ||
], | ||
iterator_to_array($messages) | ||
), | ||
['Title', 'Text', 'Recipients', 'Date'] | ||
); | ||
} | ||
|
||
/** | ||
* @param bool $yes If set no confirmation is required | ||
*/ | ||
public function pruneCommand(bool $yes = false): void | ||
{ | ||
if ($yes) { | ||
$confirm = $yes; | ||
} else { | ||
$confirm = $this->output->askConfirmation('Are you sure?'); | ||
} | ||
if ($confirm) { | ||
$count = $this->messageRepository->countAll(); | ||
$this->messageRepository->removeAll(); | ||
$this->outputLine('Removed %d messages', [$count]); | ||
} | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\GrapeVine\Command; | ||
|
||
use GPBMetadata\Google\Monitoring\V3\NotificationService; | ||
use Neos\Flow\Cli\CommandController; | ||
use Neos\Flow\Persistence\Doctrine\PersistenceManager; | ||
use Sitegeist\GrapeVine\Domain\Model\Notification; | ||
use Sitegeist\GrapeVine\Domain\Repository\NotificationRepository; | ||
|
||
class NotificationCommandController extends CommandController | ||
{ | ||
protected function __construct( | ||
private readonly NotificationRepository $notificationRepository, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function listCommand(): void | ||
{ | ||
$this->notificationRepository->findAll(); | ||
$this->output->outputTable( | ||
array_map( | ||
fn(Notification $notification) => [$notification->getAccount()->getAccountIdentifier(), $notification->getMessage()->getTitle()], | ||
$this->notificationRepository->findAll()->toArray() | ||
), | ||
['Account', 'Message'] | ||
); | ||
} | ||
|
||
/** | ||
* @param bool $yes If set no confirmation is required | ||
*/ | ||
public function pruneCommand(bool $yes): void | ||
{ | ||
if ($yes) { | ||
$confirm = $yes; | ||
} else { | ||
$confirm = $this->output->askConfirmation('Are you sure?'); | ||
} | ||
if ($confirm) { | ||
$count = $this->notificationRepository->countAll(); | ||
$this->notificationRepository->removeAll(); | ||
$this->outputLine('Removed %d notifications', [$count]); | ||
} | ||
} | ||
} |
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,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\GrapeVine\Domain\Model; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Neos\Flow\Security\Account; | ||
use Neos\Neos\Domain\Model\User; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* @Flow\Entity | ||
*/ | ||
class Message | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $title; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $text; | ||
|
||
/** | ||
* @var \DateTimeImmutable | ||
*/ | ||
protected $date; | ||
|
||
/** | ||
* @ORM\Column(type="simple_array", nullable=true) | ||
* @var array<string> | ||
*/ | ||
protected $recipientRoles; | ||
|
||
/** | ||
* @var Account|null | ||
* @ORM\Column(nullable=true) | ||
* @ORM\ManyToOne | ||
*/ | ||
protected $author; | ||
|
||
/** | ||
* @phpstan-var ArrayCollection<int, Notification> | ||
* @var ArrayCollection<Notification> | ||
* @ORM\OneToMany(mappedBy="message", cascade={"all"}, orphanRemoval=true) | ||
*/ | ||
protected $notifications; | ||
|
||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function setTitle(string $title): void | ||
{ | ||
$this->title = $title; | ||
} | ||
|
||
public function getText(): string | ||
{ | ||
return $this->text; | ||
} | ||
|
||
public function setText(string $text): void | ||
{ | ||
$this->text = $text; | ||
} | ||
|
||
public function getDate(): \DateTimeImmutable | ||
{ | ||
return $this->date; | ||
} | ||
|
||
public function setDate(\DateTimeImmutable $date): void | ||
{ | ||
$this->date = $date; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getRecipientRoles(): array | ||
{ | ||
return $this->recipientRoles; | ||
} | ||
|
||
/** | ||
* @param string[] $recipientRoles | ||
*/ | ||
public function setRecipientRoles(array $recipientRoles): void | ||
{ | ||
$this->recipientRoles = $recipientRoles; | ||
} | ||
|
||
public function getAuthor(): ?Account | ||
{ | ||
return $this->author; | ||
} | ||
|
||
public function setAuthor(?Account $author): void | ||
{ | ||
$this->author = $author; | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\GrapeVine\Domain\Model; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Security\Account; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @Flow\Entity | ||
*/ | ||
class Notification | ||
{ | ||
/** | ||
* @var Account | ||
* @ORM\ManyToOne | ||
*/ | ||
protected $account; | ||
|
||
/** | ||
* @var Message | ||
* @ORM\ManyToOne | ||
*/ | ||
protected $message; | ||
|
||
public function getAccount(): Account | ||
{ | ||
return $this->account; | ||
} | ||
|
||
public function setAccount(Account $account): void | ||
{ | ||
$this->account = $account; | ||
} | ||
|
||
public function getMessage(): Message | ||
{ | ||
return $this->message; | ||
} | ||
|
||
public function setMessage(Message $message): void | ||
{ | ||
$this->message = $message; | ||
} | ||
} |
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 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\GrapeVine\Domain\Repository; | ||
|
||
use Neos\Flow\Persistence\Repository; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
#[Flow\Scope('singleton')] | ||
class MessageRepository extends Repository | ||
{ | ||
/** | ||
* @var array<string, string> | ||
*/ | ||
protected $defaultOrderings = ['date' => 'desc']; | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\GrapeVine\Domain\Repository; | ||
|
||
use Neos\Flow\Persistence\Repository; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
#[Flow\Scope('singleton')] | ||
class NotificationRepository extends Repository | ||
{ | ||
} |
Oops, something went wrong.