Skip to content

Commit

Permalink
Upgrade to webtrees 2.1.x support
Browse files Browse the repository at this point in the history
  • Loading branch information
Uksusov Kirill committed Apr 30, 2022
1 parent 5911a17 commit 430e000
Show file tree
Hide file tree
Showing 7 changed files with 12,204 additions and 80 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This module send message with list of the anniversaries that occur today.
## System requirements
Same as [webtrees#system-requirements](https://github.com/fisharebest/webtrees#system-requirements) and cron.

Tested with 2.0.11 version.
Tested with 2.1.1 version.

## Installation
1. Download the [latest release](https://github.com/UksusoFF/webtrees-reminder/releases/latest)
Expand All @@ -16,5 +16,8 @@ Tested with 2.0.11 version.
1. Rename the folder to `reminder`
1. [Config cron task](https://www.google.ru/search?ie=UTF-8&hl=ru&q=how%20to%20config%20cron%20task&gws_rd=ssl) for execute module action url. You can find this url on module [config page](https://github.com/UksusoFF/webtrees-reminder/issues/2#issuecomment-616511474)

### Old version
For webtrees 2.0.x, you can use [version 2.0.6](https://github.com/UksusoFF/webtrees-reminder/releases/tag/v2.0.6).

## Todo
* Make notification config per tree
12,187 changes: 12,160 additions & 27 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions resources/views/admin/config.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ use Fisharebest\Webtrees\View;

<h3>
Cron settings
<span class="btn btn-primary" data-toggle="collapse" data-target="#reminder-admin-config-cron-content">
Done
</span>
</h3>

<div class="collapse show" id="reminder-admin-config-cron-content">

<div>
<p>Module require configured Cron entry for work.</p>
<p>You only need to add the following Cron entry to your server:</p>

Expand Down
6 changes: 3 additions & 3 deletions resources/views/admin/parts/reminder_email.phtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<span class="custom-control custom-switch">
<span class="form-switch">
<input type="checkbox"
class="custom-control-input"
class="form-check-input"
id="reminder-email-state-<?= e($id) ?>"
data-action="email"
data-url="<?= e($url) ?>"
<?= $checked ? 'checked' : '' ?>>
<label class="custom-control-label" for="reminder-email-state-<?= e($id) ?>">E-mail</label>
<label class="form-check-label" for="reminder-email-state-<?= e($id) ?>">E-mail</label>
</span>
8 changes: 5 additions & 3 deletions src/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace UksusoFF\WebtreesModules\Reminder\Http\Controllers;

use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Exceptions\HttpAccessDeniedException;
use Fisharebest\Webtrees\Exceptions\HttpNotFoundException;
use Fisharebest\Webtrees\Http\Exceptions\HttpAccessDeniedException;
use Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException;
use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\ViewResponseTrait;
use Fisharebest\Webtrees\I18N;
Expand All @@ -20,7 +20,7 @@ class AdminController implements RequestHandlerInterface

public const ROUTE_PREFIX = 'reminder-admin';

protected $module;
protected ReminderModule $module;

public function __construct(ReminderModule $module)
{
Expand All @@ -29,6 +29,8 @@ public function __construct(ReminderModule $module)

public function handle(ServerRequestInterface $request): Response
{
$this->layout = 'layouts/administration';

if (!Auth::isAdmin()) {
throw new HttpAccessDeniedException();
}
Expand Down
63 changes: 27 additions & 36 deletions src/Http/Controllers/CronController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

use Exception;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Carbon;
use Fisharebest\Webtrees\Exceptions\HttpAccessDeniedException;
use Fisharebest\Webtrees\Exceptions\HttpNotFoundException;
use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Gedcom;
use Fisharebest\Webtrees\Http\Exceptions\HttpAccessDeniedException;
use Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\NoReplyUser;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Services\CalendarService;
use Fisharebest\Webtrees\Services\EmailService;
use Fisharebest\Webtrees\Services\TreeService;
use Fisharebest\Webtrees\Services\UserService;
use Fisharebest\Webtrees\SiteUser;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\User;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
Expand All @@ -29,19 +30,15 @@ class CronController implements RequestHandlerInterface
{
public const ROUTE_PREFIX = 'reminder-cron';

protected $module;
protected ReminderModule $module;

/** @var \Fisharebest\Webtrees\Services\TreeService */
protected $trees;
protected TreeService $trees;

/** @var \Fisharebest\Webtrees\Services\CalendarService */
protected $events;
protected CalendarService $events;

/** @var \Fisharebest\Webtrees\Services\UserService */
protected $users;
protected UserService $users;

/** @var \Fisharebest\Webtrees\Services\EmailService */
protected $email;
protected EmailService $email;

public function __construct(ReminderModule $module)
{
Expand Down Expand Up @@ -92,38 +89,32 @@ private function run(Request $request): Response
Auth::login($user);
I18N::init($user->getPreference(User::PREF_LANGUAGE, 'en'));

$this->trees->all()->each(function(Tree $tree) use ($user, $reminders) {
/** @var \Illuminate\Support\Collection<Fact>|array $facts */
$startJd = Registry::timestampFactory()->now()->julianDay();
$endJd = Registry::timestampFactory()->now()->julianDay();

$this->trees->all()->each(function(Tree $tree) use ($user, $reminders, $startJd, $endJd) {
$facts = $this->events->getEventsList(
Carbon::now()->julianDay(),
Carbon::now()->julianDay(),
$startJd,
$endJd,
implode(',', [
'BIRT',
'MARR',
]),
true,
'alpha',
$tree
);

if ((is_array($facts) && !empty($facts))) {
$this->sendFacts($tree, $user, collect($facts), $reminders);
}
)->filter(static function(Fact $fact) {
$record = $fact->record();

if ($facts instanceof Collection) {
$facts = $facts->filter(static function(Fact $fact) {
$record = $fact->record();

if ($record instanceof Family) {
return $record->facts(Gedcom::DIVORCE_EVENTS)->isEmpty();
}
if ($record instanceof Family) {
return $record->facts(Gedcom::DIVORCE_EVENTS)->isEmpty();
}

return true;
});
return true;
});

if ($facts->isNotEmpty()) {
$this->sendFacts($tree, $user, $facts, $reminders);
}
if ($facts->isNotEmpty()) {
$this->sendFacts($tree, $user, $facts, $reminders);
}
});
Auth::logout();
Expand Down Expand Up @@ -169,8 +160,8 @@ private function groupFacts(Collection $facts): Collection
{
return $facts
->sortBy(static function(Fact $fact) {
$month = strip_tags($fact->date()->display(false, '%m'));
$day = strip_tags($fact->date()->display(false, '%d'));
$month = strip_tags($fact->date()->display(null, '%m'));
$day = strip_tags($fact->date()->display(null, '%d'));
$day = !empty($day) ? $day : '01';

$year = Carbon::createFromFormat('m d', "{$month} {$day}")->isPast()
Expand All @@ -180,7 +171,7 @@ private function groupFacts(Collection $facts): Collection
return $year . $month . $day;
})
->groupBy(static function(Fact $fact) {
return strip_tags($fact->date()->display(false, '%j %F'));
return strip_tags($fact->date()->display(null, '%j %F'));
});
}
}
9 changes: 4 additions & 5 deletions src/Modules/ReminderModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Aura\Router\Route;
use Aura\Router\RouterContainer;
use Fig\Http\Message\RequestMethodInterface;
use Fisharebest\Webtrees\Exceptions\HttpNotFoundException;
use Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException;
use Fisharebest\Webtrees\Http\RequestHandlers\AccountUpdate;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
Expand Down Expand Up @@ -33,7 +33,7 @@ class ReminderModule extends AbstractModule implements ModuleCustomInterface, Mo
use ModuleGlobalTrait;
use ModuleConfigTrait;

public const CUSTOM_VERSION = '2.0.6';
public const CUSTOM_VERSION = '2.1.0';

public const CUSTOM_WEBSITE = 'https://github.com/UksusoFF/webtrees-reminder';

Expand All @@ -43,10 +43,9 @@ class ReminderModule extends AbstractModule implements ModuleCustomInterface, Mo

public const SETTING_SLACK_NAME = 'REMINDER_SLACK';

public $query;
public DatabaseHelper $query;

/** @var \Fisharebest\Webtrees\Services\UserService */
public $users;
public UserService $users;

public function __construct()
{
Expand Down

0 comments on commit 430e000

Please sign in to comment.