@@ -35,78 +35,78 @@ |
||
35 | 35 | */ |
36 | 36 | class AncestorsListFamily implements RequestHandlerInterface |
37 | 37 | { |
38 | - use ViewResponseTrait; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var SosaModule|null $module |
|
42 | - */ |
|
43 | - private $module; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var SosaRecordsService $sosa_record_service |
|
47 | - */ |
|
48 | - private $sosa_record_service; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor for AncestorsListFamily Request Handler |
|
52 | - * |
|
53 | - * @param ModuleService $module_service |
|
54 | - * @param SosaRecordsService $sosa_record_service |
|
55 | - */ |
|
56 | - public function __construct( |
|
57 | - ModuleService $module_service, |
|
58 | - SosaRecordsService $sosa_record_service |
|
59 | - ) { |
|
60 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
61 | - $this->sosa_record_service = $sosa_record_service; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
67 | - */ |
|
68 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
69 | - { |
|
70 | - $this->layout = 'layouts/ajax'; |
|
71 | - |
|
72 | - if ($this->module === null) { |
|
73 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
74 | - } |
|
75 | - |
|
76 | - $tree = Validator::attributes($request)->tree(); |
|
77 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
78 | - $current_gen = Validator::attributes($request)->integer('gen', 0); |
|
79 | - |
|
80 | - if ($current_gen <= 0) { |
|
81 | - return Registry::responseFactory()->response( |
|
82 | - 'Invalid generation', |
|
83 | - StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - $list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen); |
|
88 | - $nb_families_all = $list_families->count(); |
|
89 | - |
|
90 | - /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */ |
|
91 | - $list_families = $list_families |
|
92 | - ->filter(function (stdClass $value) use ($tree): bool { |
|
93 | - $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
94 | - return $fam !== null && $fam->canShow(); |
|
95 | - }) |
|
96 | - ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
97 | - $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
98 | - return [(int) $value->majs_sosa => $fam]; |
|
99 | - }); |
|
100 | - |
|
101 | - $nb_families_shown = $list_families->count(); |
|
102 | - |
|
103 | - return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [ |
|
104 | - 'module_name' => $this->module->name(), |
|
105 | - 'title' => I18N::translate('Sosa Ancestors'), |
|
106 | - 'tree' => $tree, |
|
107 | - 'list_families' => $list_families, |
|
108 | - 'nb_families_all' => $nb_families_all, |
|
109 | - 'nb_families_shown' => $nb_families_shown |
|
110 | - ]); |
|
111 | - } |
|
38 | + use ViewResponseTrait; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var SosaModule|null $module |
|
42 | + */ |
|
43 | + private $module; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var SosaRecordsService $sosa_record_service |
|
47 | + */ |
|
48 | + private $sosa_record_service; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor for AncestorsListFamily Request Handler |
|
52 | + * |
|
53 | + * @param ModuleService $module_service |
|
54 | + * @param SosaRecordsService $sosa_record_service |
|
55 | + */ |
|
56 | + public function __construct( |
|
57 | + ModuleService $module_service, |
|
58 | + SosaRecordsService $sosa_record_service |
|
59 | + ) { |
|
60 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
61 | + $this->sosa_record_service = $sosa_record_service; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
67 | + */ |
|
68 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
69 | + { |
|
70 | + $this->layout = 'layouts/ajax'; |
|
71 | + |
|
72 | + if ($this->module === null) { |
|
73 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
74 | + } |
|
75 | + |
|
76 | + $tree = Validator::attributes($request)->tree(); |
|
77 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
78 | + $current_gen = Validator::attributes($request)->integer('gen', 0); |
|
79 | + |
|
80 | + if ($current_gen <= 0) { |
|
81 | + return Registry::responseFactory()->response( |
|
82 | + 'Invalid generation', |
|
83 | + StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + $list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen); |
|
88 | + $nb_families_all = $list_families->count(); |
|
89 | + |
|
90 | + /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */ |
|
91 | + $list_families = $list_families |
|
92 | + ->filter(function (stdClass $value) use ($tree): bool { |
|
93 | + $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
94 | + return $fam !== null && $fam->canShow(); |
|
95 | + }) |
|
96 | + ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
97 | + $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
98 | + return [(int) $value->majs_sosa => $fam]; |
|
99 | + }); |
|
100 | + |
|
101 | + $nb_families_shown = $list_families->count(); |
|
102 | + |
|
103 | + return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [ |
|
104 | + 'module_name' => $this->module->name(), |
|
105 | + 'title' => I18N::translate('Sosa Ancestors'), |
|
106 | + 'tree' => $tree, |
|
107 | + 'list_families' => $list_families, |
|
108 | + 'nb_families_all' => $nb_families_all, |
|
109 | + 'nb_families_shown' => $nb_families_shown |
|
110 | + ]); |
|
111 | + } |
|
112 | 112 | } |
@@ -33,49 +33,49 @@ |
||
33 | 33 | */ |
34 | 34 | class PedigreeCollapseData implements RequestHandlerInterface |
35 | 35 | { |
36 | - /** |
|
37 | - * @var SosaModule|null $module |
|
38 | - */ |
|
39 | - private $module; |
|
36 | + /** |
|
37 | + * @var SosaModule|null $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor for PedigreeCollapseData Request Handler |
|
43 | - * |
|
44 | - * @param ModuleService $module_service |
|
45 | - */ |
|
46 | - public function __construct(ModuleService $module_service) |
|
47 | - { |
|
48 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
49 | - } |
|
41 | + /** |
|
42 | + * Constructor for PedigreeCollapseData Request Handler |
|
43 | + * |
|
44 | + * @param ModuleService $module_service |
|
45 | + */ |
|
46 | + public function __construct(ModuleService $module_service) |
|
47 | + { |
|
48 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * {@inheritDoc} |
|
53 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
54 | - */ |
|
55 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
56 | - { |
|
57 | - if ($this->module === null) { |
|
58 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
59 | - } |
|
51 | + /** |
|
52 | + * {@inheritDoc} |
|
53 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
54 | + */ |
|
55 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
56 | + { |
|
57 | + if ($this->module === null) { |
|
58 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
59 | + } |
|
60 | 60 | |
61 | - $tree = Validator::attributes($request)->tree(); |
|
62 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
61 | + $tree = Validator::attributes($request)->tree(); |
|
62 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
63 | 63 | |
64 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
65 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
66 | - $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData(); |
|
64 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
65 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
66 | + $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData(); |
|
67 | 67 | |
68 | - $response = [ 'cells' => [] ]; |
|
69 | - $last_pedi_collapse = 0; |
|
70 | - foreach ($pedi_collapse_data as $gen => $rec) { |
|
71 | - $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [ |
|
72 | - 'pedi_collapse_roots' => $rec['pedi_collapse_roots'], |
|
73 | - 'pedi_collapse_xgen' => $rec['pedi_collapse_xgen'] |
|
74 | - ]); |
|
75 | - $last_pedi_collapse = $rec['pedi_collapse_roots']; |
|
76 | - } |
|
77 | - $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2); |
|
68 | + $response = [ 'cells' => [] ]; |
|
69 | + $last_pedi_collapse = 0; |
|
70 | + foreach ($pedi_collapse_data as $gen => $rec) { |
|
71 | + $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [ |
|
72 | + 'pedi_collapse_roots' => $rec['pedi_collapse_roots'], |
|
73 | + 'pedi_collapse_xgen' => $rec['pedi_collapse_xgen'] |
|
74 | + ]); |
|
75 | + $last_pedi_collapse = $rec['pedi_collapse_roots']; |
|
76 | + } |
|
77 | + $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2); |
|
78 | 78 | |
79 | - return Registry::responseFactory()->response($response); |
|
80 | - } |
|
79 | + return Registry::responseFactory()->response($response); |
|
80 | + } |
|
81 | 81 | } |
@@ -32,101 +32,101 @@ |
||
32 | 32 | */ |
33 | 33 | class SosaByGenerationGeoAnalysis implements GeoAnalysisInterface |
34 | 34 | { |
35 | - private SosaRecordsService $records_service; |
|
36 | - |
|
37 | - /** |
|
38 | - * Constructor for SosaByGenerationGeoAnalysis |
|
39 | - * |
|
40 | - * @param SosaRecordsService $records_service |
|
41 | - */ |
|
42 | - public function __construct(SosaRecordsService $records_service) |
|
43 | - { |
|
44 | - $this->records_service = $records_service; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
50 | - */ |
|
51 | - public function title(): string |
|
52 | - { |
|
53 | - return I18N::translate('Sosa ancestors places by generation'); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
59 | - */ |
|
60 | - public function itemsDescription(): callable |
|
61 | - { |
|
62 | - return fn(int $count): string => I18N::plural('ancestor', 'ancestors', $count); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * {@inheritDoc} |
|
67 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
68 | - */ |
|
69 | - public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
70 | - { |
|
71 | - $results = new GeoAnalysisResults(); |
|
72 | - |
|
73 | - $unique_ancestors = $this->records_service |
|
74 | - ->listAncestors($tree, Auth::check() ? Auth::user() : new DefaultUser()) |
|
75 | - ->uniqueStrict(fn(stdClass $item): string => $item->majs_i_id); |
|
76 | - |
|
77 | - foreach ($unique_ancestors as $item) { |
|
78 | - $ancestor = Registry::individualFactory()->make($item->majs_i_id, $tree); |
|
79 | - if ($ancestor === null || !$ancestor->canShow()) { |
|
80 | - continue; |
|
81 | - } |
|
82 | - $generation = $this->records_service->generation((int) $item->majs_sosa); |
|
83 | - $significantplace = new GeoAnalysisPlace($tree, null, $depth); |
|
84 | - foreach ($this->significantPlaces($ancestor) as $place) { |
|
85 | - $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true); |
|
86 | - if ($significantplace->isKnown()) { |
|
87 | - break; |
|
88 | - } |
|
89 | - } |
|
90 | - $results->addPlace($significantplace); |
|
91 | - $results->addPlaceInCategory( |
|
92 | - I18N::translate('Generation %s', I18N::number($generation)), |
|
93 | - $generation, |
|
94 | - $significantplace |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - return $results; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Returns significant places in order of priority for an individual |
|
103 | - * |
|
104 | - * @param Individual $individual |
|
105 | - * @return Generator<\Fisharebest\Webtrees\Place> |
|
106 | - */ |
|
107 | - protected function significantPlaces(Individual $individual): Generator |
|
108 | - { |
|
109 | - yield $individual->getBirthPlace(); |
|
110 | - |
|
111 | - /** @var \Fisharebest\Webtrees\Fact $fact */ |
|
112 | - foreach ($individual->facts(['RESI']) as $fact) { |
|
113 | - yield $fact->place(); |
|
114 | - } |
|
115 | - |
|
116 | - yield $individual->getDeathPlace(); |
|
117 | - |
|
118 | - /** @var \Fisharebest\Webtrees\Family $family */ |
|
119 | - foreach ($individual->childFamilies() as $family) { |
|
120 | - foreach ($family->facts(['RESI']) as $fact) { |
|
121 | - yield $fact->place(); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** @var \Fisharebest\Webtrees\Family $family */ |
|
126 | - foreach ($individual->spouseFamilies() as $family) { |
|
127 | - foreach ($family->facts(['RESI']) as $fact) { |
|
128 | - yield $fact->place(); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
35 | + private SosaRecordsService $records_service; |
|
36 | + |
|
37 | + /** |
|
38 | + * Constructor for SosaByGenerationGeoAnalysis |
|
39 | + * |
|
40 | + * @param SosaRecordsService $records_service |
|
41 | + */ |
|
42 | + public function __construct(SosaRecordsService $records_service) |
|
43 | + { |
|
44 | + $this->records_service = $records_service; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
50 | + */ |
|
51 | + public function title(): string |
|
52 | + { |
|
53 | + return I18N::translate('Sosa ancestors places by generation'); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
59 | + */ |
|
60 | + public function itemsDescription(): callable |
|
61 | + { |
|
62 | + return fn(int $count): string => I18N::plural('ancestor', 'ancestors', $count); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * {@inheritDoc} |
|
67 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
68 | + */ |
|
69 | + public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
70 | + { |
|
71 | + $results = new GeoAnalysisResults(); |
|
72 | + |
|
73 | + $unique_ancestors = $this->records_service |
|
74 | + ->listAncestors($tree, Auth::check() ? Auth::user() : new DefaultUser()) |
|
75 | + ->uniqueStrict(fn(stdClass $item): string => $item->majs_i_id); |
|
76 | + |
|
77 | + foreach ($unique_ancestors as $item) { |
|
78 | + $ancestor = Registry::individualFactory()->make($item->majs_i_id, $tree); |
|
79 | + if ($ancestor === null || !$ancestor->canShow()) { |
|
80 | + continue; |
|
81 | + } |
|
82 | + $generation = $this->records_service->generation((int) $item->majs_sosa); |
|
83 | + $significantplace = new GeoAnalysisPlace($tree, null, $depth); |
|
84 | + foreach ($this->significantPlaces($ancestor) as $place) { |
|
85 | + $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true); |
|
86 | + if ($significantplace->isKnown()) { |
|
87 | + break; |
|
88 | + } |
|
89 | + } |
|
90 | + $results->addPlace($significantplace); |
|
91 | + $results->addPlaceInCategory( |
|
92 | + I18N::translate('Generation %s', I18N::number($generation)), |
|
93 | + $generation, |
|
94 | + $significantplace |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + return $results; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Returns significant places in order of priority for an individual |
|
103 | + * |
|
104 | + * @param Individual $individual |
|
105 | + * @return Generator<\Fisharebest\Webtrees\Place> |
|
106 | + */ |
|
107 | + protected function significantPlaces(Individual $individual): Generator |
|
108 | + { |
|
109 | + yield $individual->getBirthPlace(); |
|
110 | + |
|
111 | + /** @var \Fisharebest\Webtrees\Fact $fact */ |
|
112 | + foreach ($individual->facts(['RESI']) as $fact) { |
|
113 | + yield $fact->place(); |
|
114 | + } |
|
115 | + |
|
116 | + yield $individual->getDeathPlace(); |
|
117 | + |
|
118 | + /** @var \Fisharebest\Webtrees\Family $family */ |
|
119 | + foreach ($individual->childFamilies() as $family) { |
|
120 | + foreach ($family->facts(['RESI']) as $fact) { |
|
121 | + yield $fact->place(); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** @var \Fisharebest\Webtrees\Family $family */ |
|
126 | + foreach ($individual->spouseFamilies() as $family) { |
|
127 | + foreach ($family->facts(['RESI']) as $fact) { |
|
128 | + yield $fact->place(); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | 132 | } |
@@ -30,291 +30,291 @@ |
||
30 | 30 | */ |
31 | 31 | class SosaRecordsService |
32 | 32 | { |
33 | - private ?int $max_system_generations = null; |
|
33 | + private ?int $max_system_generations = null; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Maximum number of generation the system is able to hold. |
|
37 | - * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
38 | - * |
|
39 | - * @return int |
|
40 | - */ |
|
41 | - public function maxSystemGenerations(): int |
|
42 | - { |
|
43 | - if ($this->max_system_generations === null) { |
|
44 | - $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
45 | - } |
|
46 | - return $this->max_system_generations; |
|
47 | - } |
|
35 | + /** |
|
36 | + * Maximum number of generation the system is able to hold. |
|
37 | + * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
38 | + * |
|
39 | + * @return int |
|
40 | + */ |
|
41 | + public function maxSystemGenerations(): int |
|
42 | + { |
|
43 | + if ($this->max_system_generations === null) { |
|
44 | + $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
45 | + } |
|
46 | + return $this->max_system_generations; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Calculate the generation of a sosa |
|
51 | - * Sosa 1 is of generation 1. |
|
52 | - * |
|
53 | - * @param int $sosa |
|
54 | - * @return int |
|
55 | - */ |
|
56 | - public function generation(int $sosa): int |
|
57 | - { |
|
58 | - return BigInteger::of($sosa)->getBitLength(); |
|
59 | - } |
|
49 | + /** |
|
50 | + * Calculate the generation of a sosa |
|
51 | + * Sosa 1 is of generation 1. |
|
52 | + * |
|
53 | + * @param int $sosa |
|
54 | + * @return int |
|
55 | + */ |
|
56 | + public function generation(int $sosa): int |
|
57 | + { |
|
58 | + return BigInteger::of($sosa)->getBitLength(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Calculate the descendant sosa of the given sosa, at the given generation. |
|
63 | - * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
64 | - * |
|
65 | - * @param int $sosa |
|
66 | - * @param int $gen |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public function sosaDescendantOf(int $sosa, int $gen): int |
|
70 | - { |
|
71 | - $gen_sosa = $this->generation($sosa); |
|
72 | - return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
73 | - ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
74 | - ->toInt(); |
|
75 | - } |
|
61 | + /** |
|
62 | + * Calculate the descendant sosa of the given sosa, at the given generation. |
|
63 | + * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
64 | + * |
|
65 | + * @param int $sosa |
|
66 | + * @param int $gen |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public function sosaDescendantOf(int $sosa, int $gen): int |
|
70 | + { |
|
71 | + $gen_sosa = $this->generation($sosa); |
|
72 | + return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
73 | + ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
74 | + ->toInt(); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Check whether an individual is a Sosa ancestor. |
|
79 | - * |
|
80 | - * @param Tree $tree |
|
81 | - * @param UserInterface $user |
|
82 | - * @param Individual $indi |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
86 | - { |
|
87 | - return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
88 | - } |
|
77 | + /** |
|
78 | + * Check whether an individual is a Sosa ancestor. |
|
79 | + * |
|
80 | + * @param Tree $tree |
|
81 | + * @param UserInterface $user |
|
82 | + * @param Individual $indi |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
86 | + { |
|
87 | + return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Returns all Sosa numbers associated to an Individual |
|
92 | - * |
|
93 | - * @param Tree $tree |
|
94 | - * @param UserInterface $user |
|
95 | - * @param Individual $indi |
|
96 | - * @return Collection<int, int> |
|
97 | - */ |
|
98 | - public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
99 | - { |
|
100 | - return Registry::cache()->array()->remember( |
|
101 | - 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
102 | - function () use ($tree, $user, $indi): Collection { |
|
103 | - return DB::table('maj_sosa') |
|
104 | - ->select(['majs_sosa', 'majs_gen']) |
|
105 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
106 | - ->where('majs_user_id', '=', $user->id()) |
|
107 | - ->where('majs_i_id', '=', $indi->xref()) |
|
108 | - ->orderBy('majs_sosa') |
|
109 | - ->get()->pluck('majs_gen', 'majs_sosa'); |
|
110 | - } |
|
111 | - ); |
|
112 | - } |
|
90 | + /** |
|
91 | + * Returns all Sosa numbers associated to an Individual |
|
92 | + * |
|
93 | + * @param Tree $tree |
|
94 | + * @param UserInterface $user |
|
95 | + * @param Individual $indi |
|
96 | + * @return Collection<int, int> |
|
97 | + */ |
|
98 | + public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
99 | + { |
|
100 | + return Registry::cache()->array()->remember( |
|
101 | + 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
102 | + function () use ($tree, $user, $indi): Collection { |
|
103 | + return DB::table('maj_sosa') |
|
104 | + ->select(['majs_sosa', 'majs_gen']) |
|
105 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
106 | + ->where('majs_user_id', '=', $user->id()) |
|
107 | + ->where('majs_i_id', '=', $indi->xref()) |
|
108 | + ->orderBy('majs_sosa') |
|
109 | + ->get()->pluck('majs_gen', 'majs_sosa'); |
|
110 | + } |
|
111 | + ); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Return a list of the Sosa ancestors across all generation |
|
116 | - * |
|
117 | - * @param Tree $tree |
|
118 | - * @param UserInterface $user |
|
119 | - * @return Collection<\stdClass> |
|
120 | - */ |
|
121 | - public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
122 | - { |
|
123 | - return DB::table('maj_sosa') |
|
124 | - ->select(['majs_sosa', 'majs_i_id']) |
|
125 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
126 | - ->where('majs_user_id', '=', $user->id()) |
|
127 | - ->orderBy('majs_sosa') |
|
128 | - ->get(); |
|
129 | - } |
|
114 | + /** |
|
115 | + * Return a list of the Sosa ancestors across all generation |
|
116 | + * |
|
117 | + * @param Tree $tree |
|
118 | + * @param UserInterface $user |
|
119 | + * @return Collection<\stdClass> |
|
120 | + */ |
|
121 | + public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
122 | + { |
|
123 | + return DB::table('maj_sosa') |
|
124 | + ->select(['majs_sosa', 'majs_i_id']) |
|
125 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
126 | + ->where('majs_user_id', '=', $user->id()) |
|
127 | + ->orderBy('majs_sosa') |
|
128 | + ->get(); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Return a list of the Sosa ancestors at a given generation |
|
133 | - * |
|
134 | - * @param Tree $tree |
|
135 | - * @param UserInterface $user |
|
136 | - * @param int $gen |
|
137 | - * @return Collection<\stdClass> |
|
138 | - */ |
|
139 | - public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
140 | - { |
|
141 | - return DB::table('maj_sosa') |
|
142 | - ->select(['majs_sosa', 'majs_i_id']) |
|
143 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
144 | - ->where('majs_user_id', '=', $user->id()) |
|
145 | - ->where('majs_gen', '=', $gen) |
|
146 | - ->orderBy('majs_sosa') |
|
147 | - ->get(); |
|
148 | - } |
|
131 | + /** |
|
132 | + * Return a list of the Sosa ancestors at a given generation |
|
133 | + * |
|
134 | + * @param Tree $tree |
|
135 | + * @param UserInterface $user |
|
136 | + * @param int $gen |
|
137 | + * @return Collection<\stdClass> |
|
138 | + */ |
|
139 | + public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
140 | + { |
|
141 | + return DB::table('maj_sosa') |
|
142 | + ->select(['majs_sosa', 'majs_i_id']) |
|
143 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
144 | + ->where('majs_user_id', '=', $user->id()) |
|
145 | + ->where('majs_gen', '=', $gen) |
|
146 | + ->orderBy('majs_sosa') |
|
147 | + ->get(); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Return a list of the Sosa families at a given generation |
|
152 | - * |
|
153 | - * @param Tree $tree |
|
154 | - * @param UserInterface $user |
|
155 | - * @param int $gen |
|
156 | - * @return Collection<\stdClass> |
|
157 | - */ |
|
158 | - public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
159 | - { |
|
160 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
161 | - return DB::table('families') |
|
162 | - ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
163 | - // Link to family husband |
|
164 | - $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
165 | - ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
166 | - ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
167 | - ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
168 | - }) |
|
169 | - ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
170 | - // Link to family husband |
|
171 | - $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
172 | - ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
173 | - ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
174 | - ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
175 | - }) |
|
176 | - ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
177 | - ->where('sosa_husb.majs_gen', '=', $gen) |
|
178 | - ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
179 | - ->orderBy('sosa_husb.majs_sosa') |
|
180 | - ->get(); |
|
181 | - } |
|
150 | + /** |
|
151 | + * Return a list of the Sosa families at a given generation |
|
152 | + * |
|
153 | + * @param Tree $tree |
|
154 | + * @param UserInterface $user |
|
155 | + * @param int $gen |
|
156 | + * @return Collection<\stdClass> |
|
157 | + */ |
|
158 | + public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
159 | + { |
|
160 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
161 | + return DB::table('families') |
|
162 | + ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
163 | + // Link to family husband |
|
164 | + $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
165 | + ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
166 | + ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
167 | + ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
168 | + }) |
|
169 | + ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
170 | + // Link to family husband |
|
171 | + $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
172 | + ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
173 | + ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
174 | + ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
175 | + }) |
|
176 | + ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
177 | + ->where('sosa_husb.majs_gen', '=', $gen) |
|
178 | + ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
179 | + ->orderBy('sosa_husb.majs_sosa') |
|
180 | + ->get(); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Return a list of Sosa ancestors missing at a given generation. |
|
185 | - * It includes the reference of either parent if it is known. |
|
186 | - * |
|
187 | - * @param Tree $tree |
|
188 | - * @param UserInterface $user |
|
189 | - * @param int $gen |
|
190 | - * @return Collection<\stdClass> |
|
191 | - */ |
|
192 | - public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
193 | - { |
|
194 | - if ($gen === 1) { |
|
195 | - return collect(); |
|
196 | - } |
|
183 | + /** |
|
184 | + * Return a list of Sosa ancestors missing at a given generation. |
|
185 | + * It includes the reference of either parent if it is known. |
|
186 | + * |
|
187 | + * @param Tree $tree |
|
188 | + * @param UserInterface $user |
|
189 | + * @param int $gen |
|
190 | + * @return Collection<\stdClass> |
|
191 | + */ |
|
192 | + public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
193 | + { |
|
194 | + if ($gen === 1) { |
|
195 | + return collect(); |
|
196 | + } |
|
197 | 197 | |
198 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
199 | - return DB::table('maj_sosa AS sosa') |
|
200 | - ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
201 | - ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
202 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
203 | - // Link to sosa's father |
|
204 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
205 | - ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
206 | - ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
207 | - }) |
|
208 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
209 | - // Link to sosa's mother |
|
210 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
211 | - ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
212 | - ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
213 | - }) |
|
214 | - ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
215 | - ->where('sosa.majs_user_id', '=', $user->id()) |
|
216 | - ->where('sosa.majs_gen', '=', $gen - 1) |
|
217 | - ->where(function (Builder $query): void { |
|
218 | - $query->whereNull('sosa_fat.majs_i_id') |
|
219 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
220 | - }) |
|
221 | - ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
222 | - ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
223 | - ->get(); |
|
224 | - } |
|
198 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
199 | + return DB::table('maj_sosa AS sosa') |
|
200 | + ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
201 | + ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
202 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
203 | + // Link to sosa's father |
|
204 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
205 | + ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
206 | + ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
207 | + }) |
|
208 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
209 | + // Link to sosa's mother |
|
210 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
211 | + ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
212 | + ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
213 | + }) |
|
214 | + ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
215 | + ->where('sosa.majs_user_id', '=', $user->id()) |
|
216 | + ->where('sosa.majs_gen', '=', $gen - 1) |
|
217 | + ->where(function (Builder $query): void { |
|
218 | + $query->whereNull('sosa_fat.majs_i_id') |
|
219 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
220 | + }) |
|
221 | + ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
222 | + ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
223 | + ->get(); |
|
224 | + } |
|
225 | 225 | |
226 | - /** |
|
227 | - * Remove all Sosa entries related to the gedcom file and user |
|
228 | - * |
|
229 | - * @param Tree $tree |
|
230 | - * @param UserInterface $user |
|
231 | - */ |
|
232 | - public function deleteAll(Tree $tree, UserInterface $user): void |
|
233 | - { |
|
234 | - DB::table('maj_sosa') |
|
235 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
236 | - ->where('majs_user_id', '=', $user->id()) |
|
237 | - ->delete(); |
|
238 | - } |
|
226 | + /** |
|
227 | + * Remove all Sosa entries related to the gedcom file and user |
|
228 | + * |
|
229 | + * @param Tree $tree |
|
230 | + * @param UserInterface $user |
|
231 | + */ |
|
232 | + public function deleteAll(Tree $tree, UserInterface $user): void |
|
233 | + { |
|
234 | + DB::table('maj_sosa') |
|
235 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
236 | + ->where('majs_user_id', '=', $user->id()) |
|
237 | + ->delete(); |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * |
|
242 | - * @param Tree $tree |
|
243 | - * @param UserInterface $user |
|
244 | - * @param int $sosa |
|
245 | - */ |
|
246 | - public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
247 | - { |
|
248 | - DB::table('maj_sosa') |
|
249 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
250 | - ->where('majs_user_id', '=', $user->id()) |
|
251 | - ->where('majs_sosa', '>=', $sosa) |
|
252 | - ->whereRaw( |
|
253 | - 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
254 | - [$this->generation($sosa), $sosa] |
|
255 | - ) |
|
256 | - ->delete(); |
|
257 | - } |
|
240 | + /** |
|
241 | + * |
|
242 | + * @param Tree $tree |
|
243 | + * @param UserInterface $user |
|
244 | + * @param int $sosa |
|
245 | + */ |
|
246 | + public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
247 | + { |
|
248 | + DB::table('maj_sosa') |
|
249 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
250 | + ->where('majs_user_id', '=', $user->id()) |
|
251 | + ->where('majs_sosa', '>=', $sosa) |
|
252 | + ->whereRaw( |
|
253 | + 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
254 | + [$this->generation($sosa), $sosa] |
|
255 | + ) |
|
256 | + ->delete(); |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * Insert (or update if already existing) a list of Sosa individuals |
|
261 | - * |
|
262 | - * @param Tree $tree |
|
263 | - * @param UserInterface $user |
|
264 | - * @param array<array<string,mixed>> $sosa_records |
|
265 | - */ |
|
266 | - public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
267 | - { |
|
268 | - $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
259 | + /** |
|
260 | + * Insert (or update if already existing) a list of Sosa individuals |
|
261 | + * |
|
262 | + * @param Tree $tree |
|
263 | + * @param UserInterface $user |
|
264 | + * @param array<array<string,mixed>> $sosa_records |
|
265 | + */ |
|
266 | + public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
267 | + { |
|
268 | + $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
269 | 269 | |
270 | - $bindings_placeholders = $bindings_values = []; |
|
271 | - $has_records = false; |
|
272 | - foreach ($sosa_records as $i => $row) { |
|
273 | - $gen = $this->generation($row['sosa']); |
|
274 | - if ($gen <= $this->maxSystemGenerations()) { |
|
275 | - $has_records = true; |
|
276 | - if ($mass_update) { |
|
277 | - $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
278 | - ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
279 | - ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
280 | - $bindings_values += [ |
|
281 | - 'tree_id' . $i => $tree->id(), |
|
282 | - 'user_id' . $i => $user->id(), |
|
283 | - 'sosa' . $i => $row['sosa'], |
|
284 | - 'indi_id' . $i => $row['indi'], |
|
285 | - 'gen' . $i => $gen, |
|
286 | - 'byear' . $i => $row['birth_year'], |
|
287 | - 'byearest' . $i => $row['birth_year_est'], |
|
288 | - 'dyear' . $i => $row['death_year'], |
|
289 | - 'dyearest' . $i => $row['death_year_est'] |
|
290 | - ]; |
|
291 | - } else { |
|
292 | - DB::table('maj_sosa')->updateOrInsert( |
|
293 | - [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
294 | - [ |
|
295 | - 'majs_i_id' => $row['indi'], |
|
296 | - 'majs_gen' => $gen, |
|
297 | - 'majs_birth_year' => $row['birth_year'], |
|
298 | - 'majs_birth_year_est' => $row['birth_year_est'], |
|
299 | - 'majs_death_year' => $row['death_year'], |
|
300 | - 'majs_death_year_est' => $row['death_year_est'] |
|
301 | - ] |
|
302 | - ); |
|
303 | - } |
|
304 | - } |
|
305 | - } |
|
270 | + $bindings_placeholders = $bindings_values = []; |
|
271 | + $has_records = false; |
|
272 | + foreach ($sosa_records as $i => $row) { |
|
273 | + $gen = $this->generation($row['sosa']); |
|
274 | + if ($gen <= $this->maxSystemGenerations()) { |
|
275 | + $has_records = true; |
|
276 | + if ($mass_update) { |
|
277 | + $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
278 | + ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
279 | + ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
280 | + $bindings_values += [ |
|
281 | + 'tree_id' . $i => $tree->id(), |
|
282 | + 'user_id' . $i => $user->id(), |
|
283 | + 'sosa' . $i => $row['sosa'], |
|
284 | + 'indi_id' . $i => $row['indi'], |
|
285 | + 'gen' . $i => $gen, |
|
286 | + 'byear' . $i => $row['birth_year'], |
|
287 | + 'byearest' . $i => $row['birth_year_est'], |
|
288 | + 'dyear' . $i => $row['death_year'], |
|
289 | + 'dyearest' . $i => $row['death_year_est'] |
|
290 | + ]; |
|
291 | + } else { |
|
292 | + DB::table('maj_sosa')->updateOrInsert( |
|
293 | + [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
294 | + [ |
|
295 | + 'majs_i_id' => $row['indi'], |
|
296 | + 'majs_gen' => $gen, |
|
297 | + 'majs_birth_year' => $row['birth_year'], |
|
298 | + 'majs_birth_year_est' => $row['birth_year_est'], |
|
299 | + 'majs_death_year' => $row['death_year'], |
|
300 | + 'majs_death_year_est' => $row['death_year_est'] |
|
301 | + ] |
|
302 | + ); |
|
303 | + } |
|
304 | + } |
|
305 | + } |
|
306 | 306 | |
307 | - if ($has_records && $mass_update) { |
|
308 | - DB::connection()->statement( |
|
309 | - 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
310 | - ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
311 | - ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
312 | - ' VALUES ' . implode(',', $bindings_placeholders) . |
|
313 | - ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
314 | - ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
315 | - ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
316 | - $bindings_values |
|
317 | - ); |
|
318 | - } |
|
319 | - } |
|
307 | + if ($has_records && $mass_update) { |
|
308 | + DB::connection()->statement( |
|
309 | + 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
310 | + ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
311 | + ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
312 | + ' VALUES ' . implode(',', $bindings_placeholders) . |
|
313 | + ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
314 | + ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
315 | + ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
316 | + $bindings_values |
|
317 | + ); |
|
318 | + } |
|
319 | + } |
|
320 | 320 | } |
@@ -27,52 +27,52 @@ |
||
27 | 27 | */ |
28 | 28 | class SosaIconHook implements RecordNameTextExtenderInterface |
29 | 29 | { |
30 | - private ModuleInterface $module; |
|
31 | - private SosaRecordsService $sosa_records_service; |
|
30 | + private ModuleInterface $module; |
|
31 | + private SosaRecordsService $sosa_records_service; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor for SosaIconHook |
|
35 | - * |
|
36 | - * @param ModuleInterface $module |
|
37 | - * @param SosaRecordsService $sosa_records_service |
|
38 | - */ |
|
39 | - public function __construct(ModuleInterface $module, SosaRecordsService $sosa_records_service) |
|
40 | - { |
|
41 | - $this->module = $module; |
|
42 | - $this->sosa_records_service = $sosa_records_service; |
|
43 | - } |
|
33 | + /** |
|
34 | + * Constructor for SosaIconHook |
|
35 | + * |
|
36 | + * @param ModuleInterface $module |
|
37 | + * @param SosaRecordsService $sosa_records_service |
|
38 | + */ |
|
39 | + public function __construct(ModuleInterface $module, SosaRecordsService $sosa_records_service) |
|
40 | + { |
|
41 | + $this->module = $module; |
|
42 | + $this->sosa_records_service = $sosa_records_service; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritDoc} |
|
47 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
48 | - */ |
|
49 | - public function module(): ModuleInterface |
|
50 | - { |
|
51 | - return $this->module; |
|
52 | - } |
|
45 | + /** |
|
46 | + * {@inheritDoc} |
|
47 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
48 | + */ |
|
49 | + public function module(): ModuleInterface |
|
50 | + { |
|
51 | + return $this->module; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritDoc} |
|
56 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
57 | - */ |
|
58 | - public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
59 | - { |
|
60 | - return ''; |
|
61 | - } |
|
54 | + /** |
|
55 | + * {@inheritDoc} |
|
56 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
57 | + */ |
|
58 | + public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
59 | + { |
|
60 | + return ''; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritDoc} |
|
65 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
66 | - */ |
|
67 | - public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
68 | - { |
|
69 | - $current_user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
70 | - if ( |
|
71 | - $record instanceof Individual && |
|
72 | - $this->sosa_records_service->isSosa($record->tree(), $current_user, $record) |
|
73 | - ) { |
|
74 | - return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]); |
|
75 | - } |
|
76 | - return ''; |
|
77 | - } |
|
63 | + /** |
|
64 | + * {@inheritDoc} |
|
65 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
66 | + */ |
|
67 | + public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
68 | + { |
|
69 | + $current_user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
70 | + if ( |
|
71 | + $record instanceof Individual && |
|
72 | + $this->sosa_records_service->isSosa($record->tree(), $current_user, $record) |
|
73 | + ) { |
|
74 | + return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]); |
|
75 | + } |
|
76 | + return ''; |
|
77 | + } |
|
78 | 78 | } |
@@ -41,165 +41,165 @@ |
||
41 | 41 | */ |
42 | 42 | class HealthCheckEmailTask implements TaskInterface, ConfigurableTaskInterface |
43 | 43 | { |
44 | - /** |
|
45 | - * Name of the Tree preference to check if the task is enabled for that tree |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - public const TREE_PREFERENCE_NAME = 'MAJ_AT_HEALTHCHECK_ENABLED'; |
|
49 | - |
|
50 | - private ?AdminTasksModule $module; |
|
51 | - private HealthCheckService $healthcheck_service; |
|
52 | - private EmailService $email_service; |
|
53 | - private UserService $user_service; |
|
54 | - private TreeService $tree_service; |
|
55 | - private UpgradeService $upgrade_service; |
|
56 | - |
|
57 | - /** |
|
58 | - * Constructor for HealthCheckTask |
|
59 | - * |
|
60 | - * @param ModuleService $module_service |
|
61 | - * @param HealthCheckService $healthcheck_service |
|
62 | - * @param EmailService $email_service |
|
63 | - * @param UserService $user_service |
|
64 | - * @param TreeService $tree_service |
|
65 | - * @param UpgradeService $upgrade_service |
|
66 | - */ |
|
67 | - public function __construct( |
|
68 | - ModuleService $module_service, |
|
69 | - HealthCheckService $healthcheck_service, |
|
70 | - EmailService $email_service, |
|
71 | - UserService $user_service, |
|
72 | - TreeService $tree_service, |
|
73 | - UpgradeService $upgrade_service |
|
74 | - ) { |
|
75 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
76 | - $this->healthcheck_service = $healthcheck_service; |
|
77 | - $this->email_service = $email_service; |
|
78 | - $this->user_service = $user_service; |
|
79 | - $this->tree_service = $tree_service; |
|
80 | - $this->upgrade_service = $upgrade_service; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * {@inheritDoc} |
|
86 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::name() |
|
87 | - */ |
|
88 | - public function name(): string |
|
89 | - { |
|
90 | - return I18N::translate('Healthcheck Email'); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * {@inheritDoc} |
|
95 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::defaultFrequency() |
|
96 | - */ |
|
97 | - public function defaultFrequency(): int |
|
98 | - { |
|
99 | - return 10080; // = 1 week = 7 * 24 * 60 min |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * {@inheritDoc} |
|
104 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::run() |
|
105 | - */ |
|
106 | - public function run(TaskSchedule $task_schedule): bool |
|
107 | - { |
|
108 | - if ($this->module === null) { |
|
109 | - return false; |
|
110 | - } |
|
111 | - |
|
112 | - $res = true; |
|
113 | - |
|
114 | - // Compute the number of days to compute |
|
115 | - $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(CarbonImmutable::now()); |
|
116 | - $interval_frequency = CarbonInterval::minutes($task_schedule->frequency()); |
|
117 | - $interval = $interval_lastrun->greaterThan($interval_frequency) ? $interval_lastrun : $interval_frequency; |
|
118 | - $nb_days = (int) $interval->ceilDay()->totalDays; |
|
119 | - |
|
120 | - $view_params_site = [ |
|
121 | - 'nb_days' => $nb_days, |
|
122 | - 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
|
123 | - 'latest_version' => $this->upgrade_service->latestVersion(), |
|
124 | - 'download_url' => $this->upgrade_service->downloadUrl(), |
|
125 | - 'all_users' => $this->user_service->all(), |
|
126 | - 'unapproved' => $this->user_service->unapproved(), |
|
127 | - 'unverified' => $this->user_service->unverified(), |
|
128 | - ]; |
|
129 | - |
|
130 | - foreach ($this->tree_service->all() as $tree) { |
|
131 | - /** @var Tree $tree */ |
|
132 | - |
|
133 | - if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
|
134 | - continue; |
|
135 | - } |
|
136 | - |
|
137 | - $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
138 | - if ($webmaster === null) { |
|
139 | - continue; |
|
140 | - } |
|
141 | - I18N::init($webmaster->getPreference('language')); |
|
142 | - |
|
143 | - $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
|
144 | - $nb_errors = $error_logs->sum('nblogs'); |
|
145 | - |
|
146 | - $view_params = $view_params_site + [ |
|
147 | - 'tree' => $tree, |
|
148 | - 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
|
149 | - 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
|
150 | - 'error_logs' => $error_logs, |
|
151 | - 'nb_errors' => $nb_errors |
|
152 | - ]; |
|
153 | - |
|
154 | - $res = $res && $this->email_service->send( |
|
155 | - new TreeUser($tree), |
|
156 | - $webmaster, |
|
157 | - new NoReplyUser(), |
|
158 | - I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
159 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
160 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
161 | - ); |
|
162 | - } |
|
163 | - |
|
164 | - return $res; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * {@inheritDoc} |
|
169 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface::configView() |
|
170 | - */ |
|
171 | - public function configView(ServerRequestInterface $request): string |
|
172 | - { |
|
173 | - return $this->module === null ? '' : view($this->module->name() . '::tasks/healthcheck/config', [ |
|
174 | - 'all_trees' => $this->tree_service->all() |
|
175 | - ]); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * {@inheritDoc} |
|
180 | - * @see \MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface::updateConfig() |
|
181 | - */ |
|
182 | - public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
|
183 | - { |
|
184 | - try { |
|
185 | - $validator = Validator::parsedBody($request); |
|
186 | - |
|
187 | - foreach ($this->tree_service->all() as $tree) { |
|
188 | - if (Auth::isManager($tree)) { |
|
189 | - $tree_enabled = $validator->boolean('HEALTHCHECK_ENABLED_' . $tree->id(), false); |
|
190 | - $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
|
191 | - } |
|
192 | - } |
|
193 | - return true; |
|
194 | - } catch (Throwable $ex) { |
|
195 | - Log::addErrorLog( |
|
196 | - sprintf( |
|
197 | - 'Error while updating the Task schedule "%s". Exception: %s', |
|
198 | - $task_schedule->id(), |
|
199 | - $ex->getMessage() |
|
200 | - ) |
|
201 | - ); |
|
202 | - } |
|
203 | - return false; |
|
204 | - } |
|
44 | + /** |
|
45 | + * Name of the Tree preference to check if the task is enabled for that tree |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + public const TREE_PREFERENCE_NAME = 'MAJ_AT_HEALTHCHECK_ENABLED'; |
|
49 | + |
|
50 | + private ?AdminTasksModule $module; |
|
51 | + private HealthCheckService $healthcheck_service; |
|
52 | + private EmailService $email_service; |
|
53 | + private UserService $user_service; |
|
54 | + private TreeService $tree_service; |
|
55 | + private UpgradeService $upgrade_service; |
|
56 | + |
|
57 | + /** |
|
58 | + * Constructor for HealthCheckTask |
|
59 | + * |
|
60 | + * @param ModuleService $module_service |
|
61 | + * @param HealthCheckService $healthcheck_service |
|
62 | + * @param EmailService $email_service |
|
63 | + * @param UserService $user_service |
|
64 | + * @param TreeService $tree_service |
|
65 | + * @param UpgradeService $upgrade_service |
|
66 | + */ |
|
67 | + public function __construct( |
|
68 | + ModuleService $module_service, |
|
69 | + HealthCheckService $healthcheck_service, |
|
70 | + EmailService $email_service, |
|
71 | + UserService $user_service, |
|
72 | + TreeService $tree_service, |
|
73 | + UpgradeService $upgrade_service |
|
74 | + ) { |
|
75 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
76 | + $this->healthcheck_service = $healthcheck_service; |
|
77 | + $this->email_service = $email_service; |
|
78 | + $this->user_service = $user_service; |
|
79 | + $this->tree_service = $tree_service; |
|
80 | + $this->upgrade_service = $upgrade_service; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * {@inheritDoc} |
|
86 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::name() |
|
87 | + */ |
|
88 | + public function name(): string |
|
89 | + { |
|
90 | + return I18N::translate('Healthcheck Email'); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * {@inheritDoc} |
|
95 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::defaultFrequency() |
|
96 | + */ |
|
97 | + public function defaultFrequency(): int |
|
98 | + { |
|
99 | + return 10080; // = 1 week = 7 * 24 * 60 min |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * {@inheritDoc} |
|
104 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface::run() |
|
105 | + */ |
|
106 | + public function run(TaskSchedule $task_schedule): bool |
|
107 | + { |
|
108 | + if ($this->module === null) { |
|
109 | + return false; |
|
110 | + } |
|
111 | + |
|
112 | + $res = true; |
|
113 | + |
|
114 | + // Compute the number of days to compute |
|
115 | + $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(CarbonImmutable::now()); |
|
116 | + $interval_frequency = CarbonInterval::minutes($task_schedule->frequency()); |
|
117 | + $interval = $interval_lastrun->greaterThan($interval_frequency) ? $interval_lastrun : $interval_frequency; |
|
118 | + $nb_days = (int) $interval->ceilDay()->totalDays; |
|
119 | + |
|
120 | + $view_params_site = [ |
|
121 | + 'nb_days' => $nb_days, |
|
122 | + 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
|
123 | + 'latest_version' => $this->upgrade_service->latestVersion(), |
|
124 | + 'download_url' => $this->upgrade_service->downloadUrl(), |
|
125 | + 'all_users' => $this->user_service->all(), |
|
126 | + 'unapproved' => $this->user_service->unapproved(), |
|
127 | + 'unverified' => $this->user_service->unverified(), |
|
128 | + ]; |
|
129 | + |
|
130 | + foreach ($this->tree_service->all() as $tree) { |
|
131 | + /** @var Tree $tree */ |
|
132 | + |
|
133 | + if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
|
134 | + continue; |
|
135 | + } |
|
136 | + |
|
137 | + $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
138 | + if ($webmaster === null) { |
|
139 | + continue; |
|
140 | + } |
|
141 | + I18N::init($webmaster->getPreference('language')); |
|
142 | + |
|
143 | + $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
|
144 | + $nb_errors = $error_logs->sum('nblogs'); |
|
145 | + |
|
146 | + $view_params = $view_params_site + [ |
|
147 | + 'tree' => $tree, |
|
148 | + 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
|
149 | + 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
|
150 | + 'error_logs' => $error_logs, |
|
151 | + 'nb_errors' => $nb_errors |
|
152 | + ]; |
|
153 | + |
|
154 | + $res = $res && $this->email_service->send( |
|
155 | + new TreeUser($tree), |
|
156 | + $webmaster, |
|
157 | + new NoReplyUser(), |
|
158 | + I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
159 | + view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
160 | + view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
161 | + ); |
|
162 | + } |
|
163 | + |
|
164 | + return $res; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * {@inheritDoc} |
|
169 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface::configView() |
|
170 | + */ |
|
171 | + public function configView(ServerRequestInterface $request): string |
|
172 | + { |
|
173 | + return $this->module === null ? '' : view($this->module->name() . '::tasks/healthcheck/config', [ |
|
174 | + 'all_trees' => $this->tree_service->all() |
|
175 | + ]); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * {@inheritDoc} |
|
180 | + * @see \MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface::updateConfig() |
|
181 | + */ |
|
182 | + public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
|
183 | + { |
|
184 | + try { |
|
185 | + $validator = Validator::parsedBody($request); |
|
186 | + |
|
187 | + foreach ($this->tree_service->all() as $tree) { |
|
188 | + if (Auth::isManager($tree)) { |
|
189 | + $tree_enabled = $validator->boolean('HEALTHCHECK_ENABLED_' . $tree->id(), false); |
|
190 | + $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
|
191 | + } |
|
192 | + } |
|
193 | + return true; |
|
194 | + } catch (Throwable $ex) { |
|
195 | + Log::addErrorLog( |
|
196 | + sprintf( |
|
197 | + 'Error while updating the Task schedule "%s". Exception: %s', |
|
198 | + $task_schedule->id(), |
|
199 | + $ex->getMessage() |
|
200 | + ) |
|
201 | + ); |
|
202 | + } |
|
203 | + return false; |
|
204 | + } |
|
205 | 205 | } |
@@ -32,92 +32,92 @@ |
||
32 | 32 | */ |
33 | 33 | class TasksList implements RequestHandlerInterface |
34 | 34 | { |
35 | - private ?AdminTasksModule $module; |
|
36 | - private TaskScheduleService $taskschedules_service; |
|
35 | + private ?AdminTasksModule $module; |
|
36 | + private TaskScheduleService $taskschedules_service; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor for TasksList Request Handler |
|
40 | - * |
|
41 | - * @param ModuleService $module_service |
|
42 | - * @param TaskScheduleService $taskschedules_service |
|
43 | - */ |
|
44 | - public function __construct( |
|
45 | - ModuleService $module_service, |
|
46 | - TaskScheduleService $taskschedules_service |
|
47 | - ) { |
|
48 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
49 | - $this->taskschedules_service = $taskschedules_service; |
|
50 | - } |
|
38 | + /** |
|
39 | + * Constructor for TasksList Request Handler |
|
40 | + * |
|
41 | + * @param ModuleService $module_service |
|
42 | + * @param TaskScheduleService $taskschedules_service |
|
43 | + */ |
|
44 | + public function __construct( |
|
45 | + ModuleService $module_service, |
|
46 | + TaskScheduleService $taskschedules_service |
|
47 | + ) { |
|
48 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
49 | + $this->taskschedules_service = $taskschedules_service; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | - */ |
|
56 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | - { |
|
58 | - if ($this->module === null) { |
|
59 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | - } |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | + */ |
|
56 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | + { |
|
58 | + if ($this->module === null) { |
|
59 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | + } |
|
61 | 61 | |
62 | - $module = $this->module; |
|
63 | - $module_name = $this->module->name(); |
|
64 | - return Registry::responseFactory()->response(['data' => $this->taskschedules_service->all(true, true) |
|
65 | - ->map(function (TaskSchedule $schedule) use ($module, $module_name): array { |
|
66 | - $task = $this->taskschedules_service->findTask($schedule->taskId()); |
|
67 | - $task_name = $task !== null ? $task->name() : I18N::translate('Task not found'); |
|
68 | - $last_run_timestamp = Registry::timestampFactory()->make($schedule->lastRunTime()->getTimestamp()); |
|
62 | + $module = $this->module; |
|
63 | + $module_name = $this->module->name(); |
|
64 | + return Registry::responseFactory()->response(['data' => $this->taskschedules_service->all(true, true) |
|
65 | + ->map(function (TaskSchedule $schedule) use ($module, $module_name): array { |
|
66 | + $task = $this->taskschedules_service->findTask($schedule->taskId()); |
|
67 | + $task_name = $task !== null ? $task->name() : I18N::translate('Task not found'); |
|
68 | + $last_run_timestamp = Registry::timestampFactory()->make($schedule->lastRunTime()->getTimestamp()); |
|
69 | 69 | |
70 | - return [ |
|
71 | - 'edit' => view($module_name . '::admin/tasks-table-options', [ |
|
72 | - 'task_sched_id' => $schedule->id(), |
|
73 | - 'task_sched_enabled' => $schedule->isEnabled(), |
|
74 | - 'task_edit_route' => route(TaskEditPage::class, ['task' => $schedule->id()]), |
|
75 | - 'task_status_route' => route(TaskStatusAction::class, [ |
|
76 | - 'task' => $schedule->id(), |
|
77 | - 'enable' => $schedule->isEnabled() ? 0 : 1 |
|
78 | - ]) |
|
79 | - ]), |
|
80 | - 'status' => [ |
|
81 | - 'display' => view($module_name . '::components/yes-no-icons', [ |
|
82 | - 'yes' => $schedule->isEnabled() |
|
83 | - ]), |
|
84 | - 'raw' => $schedule->isEnabled() ? 1 : 0 |
|
85 | - ], |
|
86 | - 'task_name' => [ |
|
87 | - 'display' => '<bdi>' . e($task_name) . '</bdi>', |
|
88 | - 'raw' => $task_name |
|
89 | - ], |
|
90 | - 'last_run' => [ |
|
91 | - 'display' => $last_run_timestamp->timestamp() === 0 ? |
|
92 | - view('components/datetime', ['timestamp' => $last_run_timestamp]) : |
|
93 | - view('components/datetime-diff', ['timestamp' => $last_run_timestamp]), |
|
94 | - 'raw' => $schedule->lastRunTime()->getTimestamp() |
|
95 | - ], |
|
96 | - 'last_result' => [ |
|
97 | - 'display' => view($module_name . '::components/yes-no-icons', [ |
|
98 | - 'yes' => $schedule->wasLastRunSuccess() |
|
99 | - ]), |
|
100 | - 'raw' => $schedule->wasLastRunSuccess() ? 1 : 0 |
|
101 | - ], |
|
102 | - 'frequency' => |
|
103 | - '<bdi>' . e(CarbonInterval::minutes($schedule->frequency())->cascade()->forHumans()) . '</bdi>', |
|
104 | - 'nb_occurrences' => $schedule->remainingOccurrences() > 0 ? |
|
105 | - I18N::number($schedule->remainingOccurrences()) : |
|
106 | - I18N::translate('Unlimited'), |
|
107 | - 'running' => view($module_name . '::components/yes-no-icons', [ |
|
108 | - 'yes' => $schedule->isRunning(), |
|
109 | - 'text_yes' => I18N::translate('Running'), |
|
110 | - 'text_no' => I18N::translate('Not running') |
|
111 | - ]), |
|
112 | - 'run' => view($module_name . '::admin/tasks-table-run', [ |
|
113 | - 'task_sched_id' => $schedule->id(), |
|
114 | - 'run_route' => route(TaskTrigger::class, [ |
|
115 | - 'task' => $schedule->taskId(), |
|
116 | - 'force' => $module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN') |
|
117 | - ]) |
|
118 | - ]) |
|
119 | - ]; |
|
120 | - }) |
|
121 | - ]); |
|
122 | - } |
|
70 | + return [ |
|
71 | + 'edit' => view($module_name . '::admin/tasks-table-options', [ |
|
72 | + 'task_sched_id' => $schedule->id(), |
|
73 | + 'task_sched_enabled' => $schedule->isEnabled(), |
|
74 | + 'task_edit_route' => route(TaskEditPage::class, ['task' => $schedule->id()]), |
|
75 | + 'task_status_route' => route(TaskStatusAction::class, [ |
|
76 | + 'task' => $schedule->id(), |
|
77 | + 'enable' => $schedule->isEnabled() ? 0 : 1 |
|
78 | + ]) |
|
79 | + ]), |
|
80 | + 'status' => [ |
|
81 | + 'display' => view($module_name . '::components/yes-no-icons', [ |
|
82 | + 'yes' => $schedule->isEnabled() |
|
83 | + ]), |
|
84 | + 'raw' => $schedule->isEnabled() ? 1 : 0 |
|
85 | + ], |
|
86 | + 'task_name' => [ |
|
87 | + 'display' => '<bdi>' . e($task_name) . '</bdi>', |
|
88 | + 'raw' => $task_name |
|
89 | + ], |
|
90 | + 'last_run' => [ |
|
91 | + 'display' => $last_run_timestamp->timestamp() === 0 ? |
|
92 | + view('components/datetime', ['timestamp' => $last_run_timestamp]) : |
|
93 | + view('components/datetime-diff', ['timestamp' => $last_run_timestamp]), |
|
94 | + 'raw' => $schedule->lastRunTime()->getTimestamp() |
|
95 | + ], |
|
96 | + 'last_result' => [ |
|
97 | + 'display' => view($module_name . '::components/yes-no-icons', [ |
|
98 | + 'yes' => $schedule->wasLastRunSuccess() |
|
99 | + ]), |
|
100 | + 'raw' => $schedule->wasLastRunSuccess() ? 1 : 0 |
|
101 | + ], |
|
102 | + 'frequency' => |
|
103 | + '<bdi>' . e(CarbonInterval::minutes($schedule->frequency())->cascade()->forHumans()) . '</bdi>', |
|
104 | + 'nb_occurrences' => $schedule->remainingOccurrences() > 0 ? |
|
105 | + I18N::number($schedule->remainingOccurrences()) : |
|
106 | + I18N::translate('Unlimited'), |
|
107 | + 'running' => view($module_name . '::components/yes-no-icons', [ |
|
108 | + 'yes' => $schedule->isRunning(), |
|
109 | + 'text_yes' => I18N::translate('Running'), |
|
110 | + 'text_no' => I18N::translate('Not running') |
|
111 | + ]), |
|
112 | + 'run' => view($module_name . '::admin/tasks-table-run', [ |
|
113 | + 'task_sched_id' => $schedule->id(), |
|
114 | + 'run_route' => route(TaskTrigger::class, [ |
|
115 | + 'task' => $schedule->taskId(), |
|
116 | + 'force' => $module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN') |
|
117 | + ]) |
|
118 | + ]) |
|
119 | + ]; |
|
120 | + }) |
|
121 | + ]); |
|
122 | + } |
|
123 | 123 | } |
@@ -30,41 +30,41 @@ |
||
30 | 30 | */ |
31 | 31 | class TaskTrigger implements RequestHandlerInterface |
32 | 32 | { |
33 | - private ?AdminTasksModule $module; |
|
34 | - private TaskScheduleService $taskschedules_service; |
|
33 | + private ?AdminTasksModule $module; |
|
34 | + private TaskScheduleService $taskschedules_service; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for TaskTrigger request handler |
|
38 | - * @param ModuleService $module_service |
|
39 | - * @param TaskScheduleService $taskschedules_service |
|
40 | - */ |
|
41 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
42 | - { |
|
43 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
44 | - $this->taskschedules_service = $taskschedules_service; |
|
45 | - } |
|
36 | + /** |
|
37 | + * Constructor for TaskTrigger request handler |
|
38 | + * @param ModuleService $module_service |
|
39 | + * @param TaskScheduleService $taskschedules_service |
|
40 | + */ |
|
41 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
42 | + { |
|
43 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
44 | + $this->taskschedules_service = $taskschedules_service; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | - */ |
|
51 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | - { |
|
53 | - if ($this->module === null) { |
|
54 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
55 | - } |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | + */ |
|
51 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | + { |
|
53 | + if ($this->module === null) { |
|
54 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
55 | + } |
|
56 | 56 | |
57 | - $task_id = Validator::attributes($request)->string('task', ''); |
|
58 | - $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
59 | - $force_token = Validator::queryParams($request)->string('force', ''); |
|
60 | - $force = $token !== '' && $token === $force_token; |
|
57 | + $task_id = Validator::attributes($request)->string('task', ''); |
|
58 | + $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
59 | + $force_token = Validator::queryParams($request)->string('force', ''); |
|
60 | + $force = $token !== '' && $token === $force_token; |
|
61 | 61 | |
62 | - $task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id); |
|
62 | + $task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id); |
|
63 | 63 | |
64 | - foreach ($task_schedules as $task_schedule) { |
|
65 | - $this->taskschedules_service->run($task_schedule, $force); |
|
66 | - } |
|
64 | + foreach ($task_schedules as $task_schedule) { |
|
65 | + $this->taskschedules_service->run($task_schedule, $force); |
|
66 | + } |
|
67 | 67 | |
68 | - return Registry::responseFactory()->response(); |
|
69 | - } |
|
68 | + return Registry::responseFactory()->response(); |
|
69 | + } |
|
70 | 70 | } |
@@ -34,146 +34,146 @@ |
||
34 | 34 | */ |
35 | 35 | class TaskEditAction implements RequestHandlerInterface |
36 | 36 | { |
37 | - private ?AdminTasksModule $module; |
|
38 | - private TaskScheduleService $taskschedules_service; |
|
39 | - |
|
40 | - /** |
|
41 | - * Constructor for TaskEditAction Request Handler |
|
42 | - * |
|
43 | - * @param ModuleService $module_service |
|
44 | - * @param TaskScheduleService $taskschedules_service |
|
45 | - */ |
|
46 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
47 | - { |
|
48 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
49 | - $this->taskschedules_service = $taskschedules_service; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | - */ |
|
56 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | - { |
|
58 | - if ($this->module === null) { |
|
59 | - FlashMessages::addMessage( |
|
60 | - I18N::translate('The attached module could not be found.'), |
|
61 | - 'danger' |
|
62 | - ); |
|
63 | - return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
64 | - } |
|
65 | - |
|
66 | - $task_sched_id = Validator::attributes($request)->integer('task', -1); |
|
67 | - $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
68 | - |
|
69 | - if ($task_schedule === null) { |
|
70 | - FlashMessages::addMessage( |
|
71 | - I18N::translate('The task shedule with ID “%s” does not exist.', I18N::number($task_sched_id)), |
|
72 | - 'danger' |
|
73 | - ); |
|
74 | - return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
75 | - } |
|
76 | - |
|
77 | - $success = $this->updateGeneralSettings($task_schedule, $request); |
|
78 | - $success = $success && $this->updateSpecificSettings($task_schedule, $request); |
|
79 | - |
|
80 | - if ($success) { |
|
81 | - FlashMessages::addMessage( |
|
82 | - I18N::translate('The scheduled task has been successfully updated.'), |
|
83 | - 'success' |
|
84 | - ); |
|
85 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
86 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
87 | - } |
|
88 | - |
|
89 | - return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Update general settings for the task, based on the request parameters |
|
94 | - * |
|
95 | - * @param TaskSchedule $task_schedule |
|
96 | - * @param ServerRequestInterface $request |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - private function updateGeneralSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
100 | - { |
|
101 | - if ($this->module === null) { |
|
102 | - return false; |
|
103 | - } |
|
104 | - |
|
105 | - $frequency = Validator::parsedBody($request)->integer('frequency', 0); |
|
106 | - if ($frequency > 0) { |
|
107 | - $task_schedule->setFrequency($frequency); |
|
108 | - } else { |
|
109 | - FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format.'), 'danger'); |
|
110 | - } |
|
111 | - |
|
112 | - $is_limited = Validator::parsedBody($request)->boolean('is_limited', false); |
|
113 | - $nb_occur = Validator::parsedBody($request)->integer('nb_occur', 1); |
|
114 | - if ($is_limited) { |
|
115 | - if ($nb_occur > 0) { |
|
116 | - $task_schedule->setRemainingOccurrences($nb_occur); |
|
117 | - } else { |
|
118 | - FlashMessages::addMessage( |
|
119 | - I18N::translate('The number of remaining occurrences is not in a valid format.'), |
|
120 | - 'danger' |
|
121 | - ); |
|
122 | - } |
|
123 | - } else { |
|
124 | - $task_schedule->setRemainingOccurrences(0); |
|
125 | - } |
|
126 | - |
|
127 | - try { |
|
128 | - $this->taskschedules_service->update($task_schedule); |
|
129 | - return true; |
|
130 | - } catch (Throwable $ex) { |
|
131 | - Log::addErrorLog( |
|
132 | - sprintf( |
|
133 | - 'Error while updating the Task Schedule "%s". Exception: %s', |
|
134 | - $task_schedule->id(), |
|
135 | - $ex->getMessage() |
|
136 | - ) |
|
137 | - ); |
|
138 | - } |
|
139 | - |
|
140 | - FlashMessages::addMessage(I18N::translate('An error occured while updating the scheduled task.'), 'danger'); |
|
141 | - //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
142 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
143 | - return false; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Update general settings for the task, based on the request parameters |
|
148 | - * |
|
149 | - * @param TaskSchedule $task_schedule |
|
150 | - * @param ServerRequestInterface $request |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - private function updateSpecificSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
154 | - { |
|
155 | - if ($this->module === null) { |
|
156 | - return false; |
|
157 | - } |
|
158 | - |
|
159 | - $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
160 | - if ($task === null || !($task instanceof ConfigurableTaskInterface)) { |
|
161 | - return true; |
|
162 | - } |
|
163 | - |
|
164 | - /** @var \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface&\MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface $task */ |
|
165 | - if (!$task->updateConfig($request, $task_schedule)) { |
|
166 | - FlashMessages::addMessage( |
|
167 | - I18N::translate( |
|
168 | - 'An error occured while updating the specific settings of administrative task “%s”.', |
|
169 | - $task->name() |
|
170 | - ), |
|
171 | - 'danger' |
|
172 | - ); |
|
173 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
174 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.'); |
|
175 | - } |
|
176 | - |
|
177 | - return true; |
|
178 | - } |
|
37 | + private ?AdminTasksModule $module; |
|
38 | + private TaskScheduleService $taskschedules_service; |
|
39 | + |
|
40 | + /** |
|
41 | + * Constructor for TaskEditAction Request Handler |
|
42 | + * |
|
43 | + * @param ModuleService $module_service |
|
44 | + * @param TaskScheduleService $taskschedules_service |
|
45 | + */ |
|
46 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
47 | + { |
|
48 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
49 | + $this->taskschedules_service = $taskschedules_service; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | + */ |
|
56 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | + { |
|
58 | + if ($this->module === null) { |
|
59 | + FlashMessages::addMessage( |
|
60 | + I18N::translate('The attached module could not be found.'), |
|
61 | + 'danger' |
|
62 | + ); |
|
63 | + return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
64 | + } |
|
65 | + |
|
66 | + $task_sched_id = Validator::attributes($request)->integer('task', -1); |
|
67 | + $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
68 | + |
|
69 | + if ($task_schedule === null) { |
|
70 | + FlashMessages::addMessage( |
|
71 | + I18N::translate('The task shedule with ID “%s” does not exist.', I18N::number($task_sched_id)), |
|
72 | + 'danger' |
|
73 | + ); |
|
74 | + return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
75 | + } |
|
76 | + |
|
77 | + $success = $this->updateGeneralSettings($task_schedule, $request); |
|
78 | + $success = $success && $this->updateSpecificSettings($task_schedule, $request); |
|
79 | + |
|
80 | + if ($success) { |
|
81 | + FlashMessages::addMessage( |
|
82 | + I18N::translate('The scheduled task has been successfully updated.'), |
|
83 | + 'success' |
|
84 | + ); |
|
85 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
86 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
87 | + } |
|
88 | + |
|
89 | + return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Update general settings for the task, based on the request parameters |
|
94 | + * |
|
95 | + * @param TaskSchedule $task_schedule |
|
96 | + * @param ServerRequestInterface $request |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + private function updateGeneralSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
100 | + { |
|
101 | + if ($this->module === null) { |
|
102 | + return false; |
|
103 | + } |
|
104 | + |
|
105 | + $frequency = Validator::parsedBody($request)->integer('frequency', 0); |
|
106 | + if ($frequency > 0) { |
|
107 | + $task_schedule->setFrequency($frequency); |
|
108 | + } else { |
|
109 | + FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format.'), 'danger'); |
|
110 | + } |
|
111 | + |
|
112 | + $is_limited = Validator::parsedBody($request)->boolean('is_limited', false); |
|
113 | + $nb_occur = Validator::parsedBody($request)->integer('nb_occur', 1); |
|
114 | + if ($is_limited) { |
|
115 | + if ($nb_occur > 0) { |
|
116 | + $task_schedule->setRemainingOccurrences($nb_occur); |
|
117 | + } else { |
|
118 | + FlashMessages::addMessage( |
|
119 | + I18N::translate('The number of remaining occurrences is not in a valid format.'), |
|
120 | + 'danger' |
|
121 | + ); |
|
122 | + } |
|
123 | + } else { |
|
124 | + $task_schedule->setRemainingOccurrences(0); |
|
125 | + } |
|
126 | + |
|
127 | + try { |
|
128 | + $this->taskschedules_service->update($task_schedule); |
|
129 | + return true; |
|
130 | + } catch (Throwable $ex) { |
|
131 | + Log::addErrorLog( |
|
132 | + sprintf( |
|
133 | + 'Error while updating the Task Schedule "%s". Exception: %s', |
|
134 | + $task_schedule->id(), |
|
135 | + $ex->getMessage() |
|
136 | + ) |
|
137 | + ); |
|
138 | + } |
|
139 | + |
|
140 | + FlashMessages::addMessage(I18N::translate('An error occured while updating the scheduled task.'), 'danger'); |
|
141 | + //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
142 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
143 | + return false; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Update general settings for the task, based on the request parameters |
|
148 | + * |
|
149 | + * @param TaskSchedule $task_schedule |
|
150 | + * @param ServerRequestInterface $request |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + private function updateSpecificSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
154 | + { |
|
155 | + if ($this->module === null) { |
|
156 | + return false; |
|
157 | + } |
|
158 | + |
|
159 | + $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
160 | + if ($task === null || !($task instanceof ConfigurableTaskInterface)) { |
|
161 | + return true; |
|
162 | + } |
|
163 | + |
|
164 | + /** @var \MyArtJaub\Webtrees\Contracts\Tasks\TaskInterface&\MyArtJaub\Webtrees\Contracts\Tasks\ConfigurableTaskInterface $task */ |
|
165 | + if (!$task->updateConfig($request, $task_schedule)) { |
|
166 | + FlashMessages::addMessage( |
|
167 | + I18N::translate( |
|
168 | + 'An error occured while updating the specific settings of administrative task “%s”.', |
|
169 | + $task->name() |
|
170 | + ), |
|
171 | + 'danger' |
|
172 | + ); |
|
173 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
174 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.'); |
|
175 | + } |
|
176 | + |
|
177 | + return true; |
|
178 | + } |
|
179 | 179 | } |