-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The settings are made from the control panel (Closes #2)
No more parameters are exposed to the api (this may change)
- Loading branch information
Showing
10 changed files
with
450 additions
and
94 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 EvanG\Modules\MailSystem; | ||
|
||
use Fisharebest\Webtrees\FlashMessages; | ||
use Fisharebest\Webtrees\I18N; | ||
use Fisharebest\Webtrees\Validator; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
class AdminAction implements RequestHandlerInterface | ||
{ | ||
protected MailSystem $module; | ||
|
||
public function __construct(MailSystem $msys) { $this->module = $msys; } | ||
|
||
public function handle(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
$params = Validator::queryParams($request); | ||
$settings = $this->module->getSettings(); | ||
|
||
$settings->setTrees($params->array("EVANG_MAILSYSTEM_TREES")); | ||
$settings->setUsers($params->array("EVANG_MAILSYSTEM_USERS")); | ||
$settings->setTags($params->array("EVANG_MAILSYSTEM_TAGS")); | ||
$settings->setEmpty($params->integer("EVANG_MAILSYSTEM_EMPTY")); | ||
$settings->setDays($params->integer("EVANG_MAILSYSTEM_DAYS")); | ||
$settings->setImageFormat($params->string("EVANG_MAILSYSTEM_IMAGEFORMAT")); | ||
|
||
FlashMessages::addMessage(I18N::translate('The Mail System preferences have been updated.'), 'success'); | ||
return redirect(route(AdminPage::class)); | ||
} | ||
} |
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 | ||
|
||
namespace EvanG\Modules\MailSystem; | ||
|
||
use Fisharebest\Webtrees\Http\ViewResponseTrait; | ||
use Fisharebest\Webtrees\I18N; | ||
use Fisharebest\Webtrees\Services\TreeService; | ||
use Fisharebest\Webtrees\Services\UserService; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
/** | ||
* Edit the site preferences. | ||
*/ | ||
class AdminPage implements RequestHandlerInterface | ||
{ | ||
use ViewResponseTrait; | ||
|
||
protected UserService $userService; | ||
protected TreeService $treeService; | ||
|
||
protected MailSystem $module; | ||
|
||
public function __construct(MailSystem $msys) | ||
{ | ||
$this->module = $msys; | ||
$this->userService = app(UserService::class); | ||
$this->treeService = app(TreeService::class); | ||
} | ||
|
||
/** | ||
* @param ServerRequestInterface $request | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function handle(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
$settings = $this->module->getSettings(); | ||
$this->layout = 'layouts/administration'; | ||
|
||
$title = I18N::translate('Mail system preferences'); | ||
|
||
return $this->viewResponse($this->module->name() . '::admin', [ | ||
'title' => $title, | ||
'settings' => $settings | ||
]); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,25 +1,10 @@ | ||
# Mail System | ||
Sends a mail with recent changes to [Webtrees](https://github.com/fisharebest/webtrees) users | ||
Sends a mail with recent changes to [Webtrees](https://github.com/fisharebest/webtrees) users. | ||
|
||
To use the plugin, you just have to add a cron task (replacing `YOURWEBTREESSERVER` by the url of your Webtrees installation) | ||
``` | ||
0 0 * * 1 wget -O - -q "YOURWEBTREESSERVER/mail-sys/send" | ||
``` | ||
> *Make sure to configure the cron job as described in the module settings.* | ||
## Endpoints | ||
## APIs | ||
|
||
* `/mail-sys/api`: a (fairly simple) api | ||
* `/mail-sys/html`: a preview of the mail that will be sent | ||
* `/mail-sys/send`: sends the mail | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | Default value | | ||
|:---------:|:---------:|:------------------------------------------------------------------------------------------------------------:|:-----------------------------:| | ||
| `users` | `list` | Users to send the mail to | All | | ||
| `trees` | `list` | Names of trees to be considered | All | | ||
| `days` | `integer` | The period (in days) to be considered | `7` | | ||
| `tags` | `list` | Types of changes to be considered | `INDI,FAM` | | ||
| `empty` | `boolean` | Display trees without changes <br>(If the value is `False` and there is no changes, the email won't be sent) | `True` | | ||
| `title` | `string` | Customised title of the mail | `Changes in the last %s days` | | ||
| `format` | `string` | The image format (either `png` or `svg`) | `png` | | ||
* `/mail-sys/get`: lists all the changes with a JSON format. | ||
* `/mail-sys/html`: a preview of the mail that will be sent. | ||
* `/mail-sys/cron`: needs to be called regularly, it will check if a mail needs to be sent. |
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
Oops, something went wrong.