Skip to content

Commit

Permalink
Garante que o metadado spam_sent_email esteja sempre registrados nos …
Browse files Browse the repository at this point in the history
…momentos de ação do plugin Ref.: #1
  • Loading branch information
erleibiazzio committed Sep 2, 2024
1 parent 2c67c78 commit a300d9d
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function _init()
// Verifica se existem termos maliciosos e dispara o e-mail e a notificação
$app->hook("entity(<<{$hooks}>>).save:after", function () use ($plugin, $last_spam_sent) {
/** @var Entity $this */
$plugin->registerSpamSentEmailMetadata($this);
$users = $plugin->getAdminUsers($this);
$terms = array_merge($plugin->config['termsBlock'], $plugin->config['terms']);

Expand Down Expand Up @@ -129,6 +130,7 @@ public function _init()
// remove a permissão de publicar caso encontre termos que estão na lista de termos elegível a bloqueio
$app->hook("entity(<<{$hooks}>>).canUser(publish)", function ($user, &$result) use($plugin, &$last_spam_sent) {
/** @var Entity $this */
$plugin->registerSpamSentEmailMetadata($this);
if($plugin->getSpamTerms($this, $plugin->config['termsBlock']) && !$user->is('admin')) {
$last_spam_sent = $this->spam_sent_email ?? null;
$this->spam_sent_email = new DateTime();
Expand All @@ -139,19 +141,28 @@ public function _init()
});
}

public function register() {
public function register()
{
$entities = $this->config['entities'];

foreach($entities as $entity) {
$namespace = "MapasCulturais\\Entities\\{$entity}";

$this->registerMetadata($namespace,'spam_sent_email', [
'label' => i::__('Data de envio do e-mail'),
'type' => 'DateTime',
'default' => null,
]);
$this->registerSpamSentEmailMetadata($entity);
}
}

/**
* @param string $entity
* @return void
*/
public function registerSpamSentEmailMetadata(string $entity): void
{
$namespace = "MapasCulturais\\Entities\\{$entity}";

$this->registerMetadata($namespace,'spam_sent_email', [
'label' => i::__('Data de envio do e-mail'),
'type' => 'DateTime',
'default' => null,
]);
}

public function createNotification($recipient, $entity, $spam_detections)
{
Expand Down

0 comments on commit a300d9d

Please sign in to comment.