@@ -107,7 +107,7 @@ |
||
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
| 110 | + return $root_lineages->sort(function(LineageRootNode $a, LineageRootNode $b) { |
|
| 111 | 111 | |
| 112 | 112 | if ($a->numberChildNodes() == $b->numberChildNodes()) { |
| 113 | 113 | return 0; |
@@ -29,220 +29,220 @@ |
||
| 29 | 29 | class LineageBuilder |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string $surname Reference surname |
|
| 34 | - */ |
|
| 35 | - private $surname; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var Tree $tree Reference tree |
|
| 39 | - */ |
|
| 40 | - private $tree; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var IndividualListModule $indilist_module |
|
| 44 | - */ |
|
| 45 | - private $indilist_module; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var Collection $used_indis Individuals already processed |
|
| 49 | - */ |
|
| 50 | - private $used_indis; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Constructor for Lineage Builder |
|
| 54 | - * |
|
| 55 | - * @param string $surname Reference surname |
|
| 56 | - * @param Tree $tree Gedcom tree |
|
| 57 | - */ |
|
| 58 | - public function __construct($surname, Tree $tree, IndividualListModule $indilist_module) |
|
| 59 | - { |
|
| 60 | - $this->surname = $surname; |
|
| 61 | - $this->tree = $tree; |
|
| 62 | - $this->indilist_module = $indilist_module; |
|
| 63 | - $this->used_indis = new Collection(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Build all patronymic lineages for the reference surname. |
|
| 68 | - * |
|
| 69 | - * @return Collection|NULL List of root patronymic lineages |
|
| 70 | - */ |
|
| 71 | - public function buildLineages(): ?Collection |
|
| 72 | - { |
|
| 73 | - if ($this->indilist_module === null) { |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale()); |
|
| 78 | - //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality |
|
| 79 | - if (count($indis) == 0) { |
|
| 80 | - return null; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $root_lineages = new Collection(); |
|
| 84 | - |
|
| 85 | - foreach ($indis as $indi) { |
|
| 86 | - /** @var Individual $indi */ |
|
| 87 | - if ($this->used_indis->get($indi->xref(), false) === false) { |
|
| 88 | - $indi_first = $this->getLineageRootIndividual($indi); |
|
| 89 | - if ($indi_first !== null) { |
|
| 90 | - // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
| 91 | - $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
| 92 | - } |
|
| 93 | - if ($indi_first === null) { |
|
| 94 | - continue; |
|
| 95 | - } |
|
| 96 | - $this->used_indis->put($indi_first->xref(), true); |
|
| 97 | - if ($indi_first->canShow()) { |
|
| 98 | - //Check if the root individual has brothers and sisters, without parents |
|
| 99 | - $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
| 100 | - if ($indi_first_child_family !== null) { |
|
| 101 | - $root_node = new LineageRootNode(null); |
|
| 102 | - $root_node->addFamily($indi_first_child_family); |
|
| 103 | - } else { |
|
| 104 | - $root_node = new LineageRootNode($indi_first); |
|
| 105 | - } |
|
| 106 | - $root_node = $this->buildLineage($root_node); |
|
| 107 | - $root_lineages->add($root_node); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
| 113 | - |
|
| 114 | - if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
| 115 | - return 0; |
|
| 116 | - } |
|
| 117 | - return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
| 118 | - }); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Retrieve the root individual, from any individual, by recursion. |
|
| 123 | - * The Root individual is the individual without a father, or without a mother holding the same name. |
|
| 124 | - * |
|
| 125 | - * @param Individual $indi |
|
| 126 | - * @return Individual|NULL Root individual |
|
| 127 | - */ |
|
| 128 | - private function getLineageRootIndividual(Individual $indi): ?Individual |
|
| 129 | - { |
|
| 130 | - $child_families = $indi->childFamilies(); |
|
| 131 | - if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
| 132 | - return null; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - foreach ($child_families as $child_family) { |
|
| 136 | - /** @var Family $child_family */ |
|
| 137 | - $child_family->husband(); |
|
| 138 | - if (($husb = $child_family->husband()) !== null) { |
|
| 139 | - if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
| 140 | - return $indi; |
|
| 141 | - } |
|
| 142 | - return $this->getLineageRootIndividual($husb); |
|
| 143 | - } elseif (($wife = $child_family->wife()) !== null) { |
|
| 144 | - if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
| 145 | - $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
| 146 | - $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
| 147 | - if ( |
|
| 148 | - $indi->canShowName() |
|
| 149 | - && $wife->canShowName() |
|
| 150 | - && I18N::strcasecmp($indi_surname, $wife_surname) == 0 |
|
| 151 | - ) { |
|
| 152 | - return $this->getLineageRootIndividual($wife); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - return $indi; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - return $indi; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Computes descendent Lineage from a node. |
|
| 163 | - * Uses recursion to build the lineage tree |
|
| 164 | - * |
|
| 165 | - * @param LineageNode $node |
|
| 166 | - * @return LineageNode Computed lineage |
|
| 167 | - */ |
|
| 168 | - private function buildLineage(LineageNode $node): LineageNode |
|
| 169 | - { |
|
| 170 | - $indi_surname = ''; |
|
| 171 | - |
|
| 172 | - $indi_node = $node->individual(); |
|
| 173 | - if ($indi_node !== null) { |
|
| 174 | - if ($node->families()->count() == 0) { |
|
| 175 | - foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
| 176 | - $node->addFamily($spouse_family); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
| 181 | - $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
| 182 | - |
|
| 183 | - //Tag the individual as used |
|
| 184 | - $this->used_indis->put($indi_node->xref(), true); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - foreach ($node->families() as $family_node) { |
|
| 188 | - /** @var Family $spouse_family */ |
|
| 189 | - $spouse_family = $family_node->family; |
|
| 190 | - $spouse_surname = ''; |
|
| 191 | - $spouse = null; |
|
| 192 | - if ( |
|
| 193 | - $indi_node !== null && |
|
| 194 | - ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
| 195 | - ) { |
|
| 196 | - $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $nb_children = $nb_natural = 0; |
|
| 200 | - |
|
| 201 | - foreach ($spouse_family->children() as $child) { |
|
| 202 | - if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
| 203 | - $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
| 204 | - |
|
| 205 | - $nb_children++; |
|
| 206 | - if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
| 207 | - //Print only lineages of children with the same surname as their mother |
|
| 208 | - //(supposing they are natural children) |
|
| 209 | - if ( |
|
| 210 | - $spouse === null || |
|
| 211 | - ($spouse_surname !== '' && I18N::strcasecmp($child_surname, $spouse_surname) != 0) |
|
| 212 | - ) { |
|
| 213 | - if (I18N::strcasecmp($child_surname, $indi_surname) == 0) { |
|
| 214 | - $nb_natural++; |
|
| 215 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
| 216 | - $node_child = $this->buildLineage($node_child); |
|
| 217 | - $node->addChild($spouse_family, $node_child); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } else { //If the root individual is the father |
|
| 221 | - $nb_natural++; |
|
| 222 | - //Print if the children does not bear the same name as his mother |
|
| 223 | - //(and different from his father) |
|
| 224 | - if ( |
|
| 225 | - mb_strlen($child_surname) == 0 || |
|
| 226 | - mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
| 227 | - I18N::strcasecmp($child_surname, $indi_surname) == 0 || |
|
| 228 | - I18N::strcasecmp($child_surname, $spouse_surname) != 0 |
|
| 229 | - ) { |
|
| 230 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
| 231 | - $node_child = $this->buildLineage($node_child); |
|
| 232 | - } else { |
|
| 233 | - $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
| 234 | - } |
|
| 235 | - $node->addChild($spouse_family, $node_child); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - //Do not print other children |
|
| 241 | - if (($nb_children - $nb_natural) > 0) { |
|
| 242 | - $node->addChild($spouse_family, null); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - return $node; |
|
| 247 | - } |
|
| 32 | + /** |
|
| 33 | + * @var string $surname Reference surname |
|
| 34 | + */ |
|
| 35 | + private $surname; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var Tree $tree Reference tree |
|
| 39 | + */ |
|
| 40 | + private $tree; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var IndividualListModule $indilist_module |
|
| 44 | + */ |
|
| 45 | + private $indilist_module; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var Collection $used_indis Individuals already processed |
|
| 49 | + */ |
|
| 50 | + private $used_indis; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Constructor for Lineage Builder |
|
| 54 | + * |
|
| 55 | + * @param string $surname Reference surname |
|
| 56 | + * @param Tree $tree Gedcom tree |
|
| 57 | + */ |
|
| 58 | + public function __construct($surname, Tree $tree, IndividualListModule $indilist_module) |
|
| 59 | + { |
|
| 60 | + $this->surname = $surname; |
|
| 61 | + $this->tree = $tree; |
|
| 62 | + $this->indilist_module = $indilist_module; |
|
| 63 | + $this->used_indis = new Collection(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Build all patronymic lineages for the reference surname. |
|
| 68 | + * |
|
| 69 | + * @return Collection|NULL List of root patronymic lineages |
|
| 70 | + */ |
|
| 71 | + public function buildLineages(): ?Collection |
|
| 72 | + { |
|
| 73 | + if ($this->indilist_module === null) { |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale()); |
|
| 78 | + //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality |
|
| 79 | + if (count($indis) == 0) { |
|
| 80 | + return null; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $root_lineages = new Collection(); |
|
| 84 | + |
|
| 85 | + foreach ($indis as $indi) { |
|
| 86 | + /** @var Individual $indi */ |
|
| 87 | + if ($this->used_indis->get($indi->xref(), false) === false) { |
|
| 88 | + $indi_first = $this->getLineageRootIndividual($indi); |
|
| 89 | + if ($indi_first !== null) { |
|
| 90 | + // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
| 91 | + $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
| 92 | + } |
|
| 93 | + if ($indi_first === null) { |
|
| 94 | + continue; |
|
| 95 | + } |
|
| 96 | + $this->used_indis->put($indi_first->xref(), true); |
|
| 97 | + if ($indi_first->canShow()) { |
|
| 98 | + //Check if the root individual has brothers and sisters, without parents |
|
| 99 | + $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
| 100 | + if ($indi_first_child_family !== null) { |
|
| 101 | + $root_node = new LineageRootNode(null); |
|
| 102 | + $root_node->addFamily($indi_first_child_family); |
|
| 103 | + } else { |
|
| 104 | + $root_node = new LineageRootNode($indi_first); |
|
| 105 | + } |
|
| 106 | + $root_node = $this->buildLineage($root_node); |
|
| 107 | + $root_lineages->add($root_node); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
| 113 | + |
|
| 114 | + if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
| 115 | + return 0; |
|
| 116 | + } |
|
| 117 | + return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
| 118 | + }); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Retrieve the root individual, from any individual, by recursion. |
|
| 123 | + * The Root individual is the individual without a father, or without a mother holding the same name. |
|
| 124 | + * |
|
| 125 | + * @param Individual $indi |
|
| 126 | + * @return Individual|NULL Root individual |
|
| 127 | + */ |
|
| 128 | + private function getLineageRootIndividual(Individual $indi): ?Individual |
|
| 129 | + { |
|
| 130 | + $child_families = $indi->childFamilies(); |
|
| 131 | + if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
| 132 | + return null; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + foreach ($child_families as $child_family) { |
|
| 136 | + /** @var Family $child_family */ |
|
| 137 | + $child_family->husband(); |
|
| 138 | + if (($husb = $child_family->husband()) !== null) { |
|
| 139 | + if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
| 140 | + return $indi; |
|
| 141 | + } |
|
| 142 | + return $this->getLineageRootIndividual($husb); |
|
| 143 | + } elseif (($wife = $child_family->wife()) !== null) { |
|
| 144 | + if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
| 145 | + $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
| 146 | + $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
| 147 | + if ( |
|
| 148 | + $indi->canShowName() |
|
| 149 | + && $wife->canShowName() |
|
| 150 | + && I18N::strcasecmp($indi_surname, $wife_surname) == 0 |
|
| 151 | + ) { |
|
| 152 | + return $this->getLineageRootIndividual($wife); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + return $indi; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + return $indi; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Computes descendent Lineage from a node. |
|
| 163 | + * Uses recursion to build the lineage tree |
|
| 164 | + * |
|
| 165 | + * @param LineageNode $node |
|
| 166 | + * @return LineageNode Computed lineage |
|
| 167 | + */ |
|
| 168 | + private function buildLineage(LineageNode $node): LineageNode |
|
| 169 | + { |
|
| 170 | + $indi_surname = ''; |
|
| 171 | + |
|
| 172 | + $indi_node = $node->individual(); |
|
| 173 | + if ($indi_node !== null) { |
|
| 174 | + if ($node->families()->count() == 0) { |
|
| 175 | + foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
| 176 | + $node->addFamily($spouse_family); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
| 181 | + $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
| 182 | + |
|
| 183 | + //Tag the individual as used |
|
| 184 | + $this->used_indis->put($indi_node->xref(), true); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + foreach ($node->families() as $family_node) { |
|
| 188 | + /** @var Family $spouse_family */ |
|
| 189 | + $spouse_family = $family_node->family; |
|
| 190 | + $spouse_surname = ''; |
|
| 191 | + $spouse = null; |
|
| 192 | + if ( |
|
| 193 | + $indi_node !== null && |
|
| 194 | + ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
| 195 | + ) { |
|
| 196 | + $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $nb_children = $nb_natural = 0; |
|
| 200 | + |
|
| 201 | + foreach ($spouse_family->children() as $child) { |
|
| 202 | + if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
| 203 | + $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
| 204 | + |
|
| 205 | + $nb_children++; |
|
| 206 | + if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
| 207 | + //Print only lineages of children with the same surname as their mother |
|
| 208 | + //(supposing they are natural children) |
|
| 209 | + if ( |
|
| 210 | + $spouse === null || |
|
| 211 | + ($spouse_surname !== '' && I18N::strcasecmp($child_surname, $spouse_surname) != 0) |
|
| 212 | + ) { |
|
| 213 | + if (I18N::strcasecmp($child_surname, $indi_surname) == 0) { |
|
| 214 | + $nb_natural++; |
|
| 215 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
| 216 | + $node_child = $this->buildLineage($node_child); |
|
| 217 | + $node->addChild($spouse_family, $node_child); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } else { //If the root individual is the father |
|
| 221 | + $nb_natural++; |
|
| 222 | + //Print if the children does not bear the same name as his mother |
|
| 223 | + //(and different from his father) |
|
| 224 | + if ( |
|
| 225 | + mb_strlen($child_surname) == 0 || |
|
| 226 | + mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
| 227 | + I18N::strcasecmp($child_surname, $indi_surname) == 0 || |
|
| 228 | + I18N::strcasecmp($child_surname, $spouse_surname) != 0 |
|
| 229 | + ) { |
|
| 230 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
| 231 | + $node_child = $this->buildLineage($node_child); |
|
| 232 | + } else { |
|
| 233 | + $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
| 234 | + } |
|
| 235 | + $node->addChild($spouse_family, $node_child); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + //Do not print other children |
|
| 241 | + if (($nb_children - $nb_natural) > 0) { |
|
| 242 | + $node->addChild($spouse_family, null); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + return $node; |
|
| 247 | + } |
|
| 248 | 248 | } |
@@ -26,89 +26,89 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | abstract class AbstractModuleMaj extends AbstractModule implements ModuleCustomInterface |
| 28 | 28 | { |
| 29 | - use ModuleCustomTrait; |
|
| 29 | + use ModuleCustomTrait; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * {@inheritDoc} |
|
| 33 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 34 | - */ |
|
| 35 | - public function boot() : void |
|
| 36 | - { |
|
| 37 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
| 31 | + /** |
|
| 32 | + * {@inheritDoc} |
|
| 33 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 34 | + */ |
|
| 35 | + public function boot() : void |
|
| 36 | + { |
|
| 37 | + View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
| 38 | 38 | |
| 39 | - $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
| 40 | - } |
|
| 39 | + $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * {@inheritDoc} |
|
| 44 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
| 45 | - */ |
|
| 46 | - public function resourcesFolder(): string |
|
| 47 | - { |
|
| 48 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
| 49 | - } |
|
| 42 | + /** |
|
| 43 | + * {@inheritDoc} |
|
| 44 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
| 45 | + */ |
|
| 46 | + public function resourcesFolder(): string |
|
| 47 | + { |
|
| 48 | + return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * {@inheritDoc} |
|
| 53 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
| 54 | - */ |
|
| 55 | - public function customModuleAuthorName() : string |
|
| 56 | - { |
|
| 57 | - return 'Jonathan Jaubart'; |
|
| 58 | - } |
|
| 51 | + /** |
|
| 52 | + * {@inheritDoc} |
|
| 53 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
| 54 | + */ |
|
| 55 | + public function customModuleAuthorName() : string |
|
| 56 | + { |
|
| 57 | + return 'Jonathan Jaubart'; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * {@inheritDoc} |
|
| 62 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
| 63 | - */ |
|
| 64 | - public function customModuleSupportUrl() : string |
|
| 65 | - { |
|
| 66 | - return 'https://github.com/jon48/webtrees-lib'; |
|
| 67 | - } |
|
| 60 | + /** |
|
| 61 | + * {@inheritDoc} |
|
| 62 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
| 63 | + */ |
|
| 64 | + public function customModuleSupportUrl() : string |
|
| 65 | + { |
|
| 66 | + return 'https://github.com/jon48/webtrees-lib'; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * {@inheritDoc} |
|
| 71 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
| 72 | - */ |
|
| 73 | - public function customTranslations(string $language) : array |
|
| 74 | - { |
|
| 75 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
| 69 | + /** |
|
| 70 | + * {@inheritDoc} |
|
| 71 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
| 72 | + */ |
|
| 73 | + public function customTranslations(string $language) : array |
|
| 74 | + { |
|
| 75 | + $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
| 76 | 76 | |
| 77 | - try { |
|
| 78 | - $translation = new Translation($translation_file); |
|
| 79 | - return $translation->asArray(); |
|
| 80 | - } catch (\Exception $e) { } |
|
| 77 | + try { |
|
| 78 | + $translation = new Translation($translation_file); |
|
| 79 | + return $translation->asArray(); |
|
| 80 | + } catch (\Exception $e) { } |
|
| 81 | 81 | |
| 82 | - return array(); |
|
| 83 | - } |
|
| 82 | + return array(); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Add module routes to webtrees route loader |
|
| 87 | - * |
|
| 88 | - * @param Map $router |
|
| 89 | - */ |
|
| 90 | - public abstract function loadRoutes(Map $router) : void; |
|
| 85 | + /** |
|
| 86 | + * Add module routes to webtrees route loader |
|
| 87 | + * |
|
| 88 | + * @param Map $router |
|
| 89 | + */ |
|
| 90 | + public abstract function loadRoutes(Map $router) : void; |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Returns the URL of the module specific stylesheets. |
|
| 94 | - * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
| 95 | - * and fallback to default.min.css if none are found |
|
| 96 | - * |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function moduleCssUrl() : string |
|
| 100 | - { |
|
| 101 | - /** @var ModuleThemeInterface $theme */ |
|
| 102 | - $theme = app(ModuleThemeInterface::class); |
|
| 103 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
| 92 | + /** |
|
| 93 | + * Returns the URL of the module specific stylesheets. |
|
| 94 | + * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
| 95 | + * and fallback to default.min.css if none are found |
|
| 96 | + * |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function moduleCssUrl() : string |
|
| 100 | + { |
|
| 101 | + /** @var ModuleThemeInterface $theme */ |
|
| 102 | + $theme = app(ModuleThemeInterface::class); |
|
| 103 | + $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
| 104 | 104 | |
| 105 | - if(file_exists($css_file)) { |
|
| 106 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
| 107 | - } |
|
| 108 | - else { |
|
| 109 | - return $this->assetUrl('css/default.min.css'); |
|
| 110 | - } |
|
| 111 | - } |
|
| 105 | + if(file_exists($css_file)) { |
|
| 106 | + return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
| 107 | + } |
|
| 108 | + else { |
|
| 109 | + return $this->assetUrl('css/default.min.css'); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | \ No newline at end of file |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function boot() : void |
| 36 | 36 | { |
| 37 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
| 37 | + View::registerNamespace($this->name(), $this->resourcesFolder().'views/'); |
|
| 38 | 38 | |
| 39 | 39 | $this->loadRoutes(app(RouterContainer::class)->getMap()); |
| 40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function resourcesFolder(): string |
| 47 | 47 | { |
| 48 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
| 48 | + return Webtrees::MODULES_DIR.trim($this->name(), '_').'/resources/'; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function customTranslations(string $language) : array |
| 74 | 74 | { |
| 75 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
| 75 | + $translation_file = $this->resourcesFolder().'lang/'.$language.'/messages.php'; |
|
| 76 | 76 | |
| 77 | 77 | try { |
| 78 | 78 | $translation = new Translation($translation_file); |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | /** @var ModuleThemeInterface $theme */ |
| 102 | 102 | $theme = app(ModuleThemeInterface::class); |
| 103 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
| 103 | + $css_file = $this->resourcesFolder().'css/'.$theme->name().'.min.css'; |
|
| 104 | 104 | |
| 105 | - if(file_exists($css_file)) { |
|
| 106 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
| 105 | + if (file_exists($css_file)) { |
|
| 106 | + return $this->assetUrl('css/'.$theme->name().'.min.css'); |
|
| 107 | 107 | } |
| 108 | 108 | else { |
| 109 | 109 | return $this->assetUrl('css/default.min.css'); |
@@ -104,8 +104,7 @@ |
||
| 104 | 104 | |
| 105 | 105 | if(file_exists($css_file)) { |
| 106 | 106 | return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
| 107 | - } |
|
| 108 | - else { |
|
| 107 | + } else { |
|
| 109 | 108 | return $this->assetUrl('css/default.min.css'); |
| 110 | 109 | } |
| 111 | 110 | } |
@@ -30,65 +30,65 @@ |
||
| 30 | 30 | class TaskStatusAction implements RequestHandlerInterface |
| 31 | 31 | { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var AdminTasksModule $module |
|
| 35 | - */ |
|
| 36 | - private $module; |
|
| 33 | + /** |
|
| 34 | + * @var AdminTasksModule $module |
|
| 35 | + */ |
|
| 36 | + private $module; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var TaskScheduleService $taskschedules_service |
|
| 40 | - */ |
|
| 41 | - private $taskschedules_service; |
|
| 38 | + /** |
|
| 39 | + * @var TaskScheduleService $taskschedules_service |
|
| 40 | + */ |
|
| 41 | + private $taskschedules_service; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Constructor for TaskStatusAction Request Handler |
|
| 45 | - * |
|
| 46 | - * @param ModuleService $module_service |
|
| 47 | - * @param TaskScheduleService $taskschedules_service |
|
| 48 | - */ |
|
| 49 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 50 | - { |
|
| 51 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 52 | - $this->taskschedules_service = $taskschedules_service; |
|
| 53 | - } |
|
| 43 | + /** |
|
| 44 | + * Constructor for TaskStatusAction Request Handler |
|
| 45 | + * |
|
| 46 | + * @param ModuleService $module_service |
|
| 47 | + * @param TaskScheduleService $taskschedules_service |
|
| 48 | + */ |
|
| 49 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 50 | + { |
|
| 51 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 52 | + $this->taskschedules_service = $taskschedules_service; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * {@inheritDoc} |
|
| 57 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 58 | - */ |
|
| 59 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 60 | - { |
|
| 61 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
| 62 | - $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
| 55 | + /** |
|
| 56 | + * {@inheritDoc} |
|
| 57 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 58 | + */ |
|
| 59 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 60 | + { |
|
| 61 | + $task_sched_id = (int) $request->getAttribute('task'); |
|
| 62 | + $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
| 63 | 63 | |
| 64 | - $admin_config_route = route(AdminConfigPage::class); |
|
| 64 | + $admin_config_route = route(AdminConfigPage::class); |
|
| 65 | 65 | |
| 66 | - if ($task_schedule === null) { |
|
| 67 | - FlashMessages::addMessage( |
|
| 68 | - I18N::translate('The task shedule with ID “%d” does not exist.', I18N::number($task_sched_id)), |
|
| 69 | - 'danger' |
|
| 70 | - ); |
|
| 71 | - return redirect($admin_config_route); |
|
| 72 | - } |
|
| 66 | + if ($task_schedule === null) { |
|
| 67 | + FlashMessages::addMessage( |
|
| 68 | + I18N::translate('The task shedule with ID “%d” does not exist.', I18N::number($task_sched_id)), |
|
| 69 | + 'danger' |
|
| 70 | + ); |
|
| 71 | + return redirect($admin_config_route); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - ((bool) $request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable(); |
|
| 74 | + ((bool) $request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable(); |
|
| 75 | 75 | |
| 76 | - if ($this->taskschedules_service->update($task_schedule) > 0) { |
|
| 77 | - FlashMessages::addMessage( |
|
| 78 | - I18N::translate('The scheduled task has been successfully updated'), |
|
| 79 | - 'success' |
|
| 80 | - ); |
|
| 81 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 82 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
| 83 | - } else { |
|
| 84 | - FlashMessages::addMessage( |
|
| 85 | - I18N::translate('An error occured while updating the scheduled task'), |
|
| 86 | - 'danger' |
|
| 87 | - ); |
|
| 88 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 89 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
| 90 | - } |
|
| 76 | + if ($this->taskschedules_service->update($task_schedule) > 0) { |
|
| 77 | + FlashMessages::addMessage( |
|
| 78 | + I18N::translate('The scheduled task has been successfully updated'), |
|
| 79 | + 'success' |
|
| 80 | + ); |
|
| 81 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 82 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
| 83 | + } else { |
|
| 84 | + FlashMessages::addMessage( |
|
| 85 | + I18N::translate('An error occured while updating the scheduled task'), |
|
| 86 | + 'danger' |
|
| 87 | + ); |
|
| 88 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 89 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return redirect($admin_config_route); |
|
| 93 | - } |
|
| 92 | + return redirect($admin_config_route); |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function handle(ServerRequestInterface $request): ResponseInterface |
| 60 | 60 | { |
| 61 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
| 61 | + $task_sched_id = (int)$request->getAttribute('task'); |
|
| 62 | 62 | $task_schedule = $this->taskschedules_service->find($task_sched_id); |
| 63 | 63 | |
| 64 | 64 | $admin_config_route = route(AdminConfigPage::class); |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | return redirect($admin_config_route); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - ((bool) $request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable(); |
|
| 74 | + ((bool)$request->getAttribute('enable', false)) ? $task_schedule->enable() : $task_schedule->disable(); |
|
| 75 | 75 | |
| 76 | 76 | if ($this->taskschedules_service->update($task_schedule) > 0) { |
| 77 | 77 | FlashMessages::addMessage( |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | 'success' |
| 80 | 80 | ); |
| 81 | 81 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 82 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
| 82 | + Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” has been updated.'); |
|
| 83 | 83 | } else { |
| 84 | 84 | FlashMessages::addMessage( |
| 85 | 85 | I18N::translate('An error occured while updating the scheduled task'), |
| 86 | 86 | 'danger' |
| 87 | 87 | ); |
| 88 | 88 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 89 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” could not be updated. See error log.'); |
|
| 89 | + Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” could not be updated. See error log.'); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | return redirect($admin_config_route); |
@@ -56,7 +56,7 @@ |
||
| 56 | 56 | |
| 57 | 57 | $token = Functions::generateRandomToken(); |
| 58 | 58 | $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
| 59 | - Log::addConfigurationLog($this->module->title() . ' : New token generated.'); |
|
| 59 | + Log::addConfigurationLog($this->module->title().' : New token generated.'); |
|
| 60 | 60 | |
| 61 | 61 | return response(['token' => $token]); |
| 62 | 62 | } |
@@ -29,35 +29,35 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class TokenGenerate implements RequestHandlerInterface |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * @var AdminTasksModule $module |
|
| 34 | - */ |
|
| 35 | - private $module; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Constructor for TokenGenerate request handler |
|
| 39 | - * |
|
| 40 | - * @param ModuleService $module_service |
|
| 41 | - */ |
|
| 42 | - public function __construct(ModuleService $module_service) |
|
| 43 | - { |
|
| 44 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 45 | - } |
|
| 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 | - } |
|
| 56 | - |
|
| 57 | - $token = Functions::generateRandomToken(); |
|
| 58 | - $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
|
| 59 | - Log::addConfigurationLog($this->module->title() . ' : New token generated.'); |
|
| 60 | - |
|
| 61 | - return response(['token' => $token]); |
|
| 62 | - } |
|
| 32 | + /** |
|
| 33 | + * @var AdminTasksModule $module |
|
| 34 | + */ |
|
| 35 | + private $module; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Constructor for TokenGenerate request handler |
|
| 39 | + * |
|
| 40 | + * @param ModuleService $module_service |
|
| 41 | + */ |
|
| 42 | + public function __construct(ModuleService $module_service) |
|
| 43 | + { |
|
| 44 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 45 | + } |
|
| 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 | + } |
|
| 56 | + |
|
| 57 | + $token = Functions::generateRandomToken(); |
|
| 58 | + $this->module->setPreference('MAJ_AT_FORCE_EXEC_TOKEN', $token); |
|
| 59 | + Log::addConfigurationLog($this->module->title() . ' : New token generated.'); |
|
| 60 | + |
|
| 61 | + return response(['token' => $token]); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -30,55 +30,55 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class AdminConfigPage implements RequestHandlerInterface |
| 32 | 32 | { |
| 33 | - use ViewResponseTrait; |
|
| 33 | + use ViewResponseTrait; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var AdminTasksModule $module |
|
| 37 | - */ |
|
| 38 | - private $module; |
|
| 35 | + /** |
|
| 36 | + * @var AdminTasksModule $module |
|
| 37 | + */ |
|
| 38 | + private $module; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * |
|
| 42 | - * @var UserService $user_service |
|
| 43 | - */ |
|
| 44 | - private $user_service; |
|
| 40 | + /** |
|
| 41 | + * |
|
| 42 | + * @var UserService $user_service |
|
| 43 | + */ |
|
| 44 | + private $user_service; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Constructor for Admin Config request handler |
|
| 48 | - * |
|
| 49 | - * @param ModuleService $module_service |
|
| 50 | - * @param UserService $user_service |
|
| 51 | - */ |
|
| 52 | - public function __construct(ModuleService $module_service, UserService $user_service) |
|
| 53 | - { |
|
| 54 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 55 | - $this->user_service = $user_service; |
|
| 56 | - } |
|
| 46 | + /** |
|
| 47 | + * Constructor for Admin Config request handler |
|
| 48 | + * |
|
| 49 | + * @param ModuleService $module_service |
|
| 50 | + * @param UserService $user_service |
|
| 51 | + */ |
|
| 52 | + public function __construct(ModuleService $module_service, UserService $user_service) |
|
| 53 | + { |
|
| 54 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 55 | + $this->user_service = $user_service; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * {@inheritDoc} |
|
| 60 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 61 | - */ |
|
| 62 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 63 | - { |
|
| 64 | - $this->layout = 'layouts/administration'; |
|
| 58 | + /** |
|
| 59 | + * {@inheritDoc} |
|
| 60 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 61 | + */ |
|
| 62 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 63 | + { |
|
| 64 | + $this->layout = 'layouts/administration'; |
|
| 65 | 65 | |
| 66 | - if ($this->module === null) { |
|
| 67 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 68 | - } |
|
| 66 | + if ($this->module === null) { |
|
| 67 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 71 | - if ($token === '') { |
|
| 72 | - $token = Functions::generateRandomToken(); |
|
| 73 | - $this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token); |
|
| 74 | - } |
|
| 70 | + $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 71 | + if ($token === '') { |
|
| 72 | + $token = Functions::generateRandomToken(); |
|
| 73 | + $this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
| 77 | - 'title' => $this->module->title(), |
|
| 78 | - 'trigger_token' => $token, |
|
| 79 | - 'trigger_route' => route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']), |
|
| 80 | - 'new_token_route' => route(TokenGenerate::class), |
|
| 81 | - 'tasks_data_route' => route(TasksList::class) |
|
| 82 | - ]); |
|
| 83 | - } |
|
| 76 | + return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
| 77 | + 'title' => $this->module->title(), |
|
| 78 | + 'trigger_token' => $token, |
|
| 79 | + 'trigger_route' => route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']), |
|
| 80 | + 'new_token_route' => route(TokenGenerate::class), |
|
| 81 | + 'tasks_data_route' => route(TasksList::class) |
|
| 82 | + ]); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -73,7 +73,7 @@ |
||
| 73 | 73 | $this->module->setPreference('PAT_FORCE_EXEC_TOKEN', $token); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
| 76 | + return $this->viewResponse($this->module->name().'::admin/config', [ |
|
| 77 | 77 | 'title' => $this->module->title(), |
| 78 | 78 | 'trigger_token' => $token, |
| 79 | 79 | 'trigger_route' => route(TaskTrigger::class, ['task' => '__TASKNAME__', 'force' => '__TOKEN__']), |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function handle(ServerRequestInterface $request): ResponseInterface |
| 64 | 64 | { |
| 65 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
| 65 | + $task_sched_id = (int)$request->getAttribute('task'); |
|
| 66 | 66 | $task_schedule = $this->taskschedules_service->find($task_sched_id); |
| 67 | 67 | |
| 68 | 68 | $admin_config_route = route(AdminConfigPage::class); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | 'success' |
| 85 | 85 | ); |
| 86 | 86 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 87 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
| 87 | + Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” has been updated.'); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | return redirect($admin_config_route); |
@@ -99,17 +99,17 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | private function updateGeneralSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
| 101 | 101 | { |
| 102 | - $params = (array) $request->getParsedBody(); |
|
| 102 | + $params = (array)$request->getParsedBody(); |
|
| 103 | 103 | |
| 104 | - $frequency = (int) $params['frequency']; |
|
| 104 | + $frequency = (int)$params['frequency']; |
|
| 105 | 105 | if ($frequency > 0) { |
| 106 | 106 | $task_schedule->setFrequency(CarbonInterval::minutes($frequency)); |
| 107 | 107 | } else { |
| 108 | 108 | FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format'), 'danger'); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $is_limited = (bool) $params['is_limited']; |
|
| 112 | - $nb_occur = (int) $params['nb_occur']; |
|
| 111 | + $is_limited = (bool)$params['is_limited']; |
|
| 112 | + $nb_occur = (int)$params['nb_occur']; |
|
| 113 | 113 | |
| 114 | 114 | if ($is_limited) { |
| 115 | 115 | if ($nb_occur > 0) { |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | FlashMessages::addMessage(I18N::translate('An error occured while updating the scheduled task'), 'danger'); |
| 141 | 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.'); |
|
| 142 | + Log::addConfigurationLog('Module '.$this->module->title().' : Task Schedule “'.$task_schedule->id().'” could not be updated. See error log.'); |
|
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | 145 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | 'danger' |
| 168 | 168 | ); |
| 169 | 169 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 170 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.'); |
|
| 170 | + Log::addConfigurationLog('Module '.$this->module->title().' : AdminTask “'.$task->name().'” specific settings could not be updated. See error log.'); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | return true; |
@@ -34,142 +34,142 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class TaskEditAction implements RequestHandlerInterface |
| 36 | 36 | { |
| 37 | - /** |
|
| 38 | - * @var AdminTasksModule $module |
|
| 39 | - */ |
|
| 40 | - private $module; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var TaskScheduleService $taskschedules_service |
|
| 44 | - */ |
|
| 45 | - private $taskschedules_service; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Constructor for TaskEditAction Request Handler |
|
| 49 | - * |
|
| 50 | - * @param ModuleService $module_service |
|
| 51 | - * @param TaskScheduleService $taskschedules_service |
|
| 52 | - */ |
|
| 53 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 54 | - { |
|
| 55 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 56 | - $this->taskschedules_service = $taskschedules_service; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * {@inheritDoc} |
|
| 61 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 62 | - */ |
|
| 63 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 64 | - { |
|
| 65 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
| 66 | - $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
| 67 | - |
|
| 68 | - $admin_config_route = route(AdminConfigPage::class); |
|
| 69 | - |
|
| 70 | - if ($task_schedule === null) { |
|
| 71 | - FlashMessages::addMessage( |
|
| 72 | - I18N::translate('The task shedule with ID “%d” does not exist.', I18N::number($task_sched_id)), |
|
| 73 | - 'danger' |
|
| 74 | - ); |
|
| 75 | - return redirect($admin_config_route); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $success = $this->updateGeneralSettings($task_schedule, $request); |
|
| 79 | - $success = $success && $this->updateSpecificSettings($task_schedule, $request); |
|
| 80 | - |
|
| 81 | - if ($success) { |
|
| 82 | - FlashMessages::addMessage( |
|
| 83 | - I18N::translate('The scheduled task has been successfully updated'), |
|
| 84 | - 'success' |
|
| 85 | - ); |
|
| 86 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 87 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return redirect($admin_config_route); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Update general settings for the task, based on the request parameters |
|
| 95 | - * |
|
| 96 | - * @param TaskSchedule $task_schedule |
|
| 97 | - * @param ServerRequestInterface $request |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 100 | - private function updateGeneralSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
| 101 | - { |
|
| 102 | - $params = (array) $request->getParsedBody(); |
|
| 103 | - |
|
| 104 | - $frequency = (int) $params['frequency']; |
|
| 105 | - if ($frequency > 0) { |
|
| 106 | - $task_schedule->setFrequency(CarbonInterval::minutes($frequency)); |
|
| 107 | - } else { |
|
| 108 | - FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format'), 'danger'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $is_limited = (bool) $params['is_limited']; |
|
| 112 | - $nb_occur = (int) $params['nb_occur']; |
|
| 113 | - |
|
| 114 | - if ($is_limited) { |
|
| 115 | - if ($nb_occur > 0) { |
|
| 116 | - $task_schedule->setRemainingOccurences($nb_occur); |
|
| 117 | - } else { |
|
| 118 | - FlashMessages::addMessage( |
|
| 119 | - I18N::translate('The number of remaining occurences is not in a valid format'), |
|
| 120 | - 'danger' |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - } else { |
|
| 124 | - $task_schedule->setRemainingOccurences(0); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - try { |
|
| 128 | - $this->taskschedules_service->update($task_schedule); |
|
| 129 | - return true; |
|
| 130 | - } catch (Exception $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 | - $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
| 156 | - if ($task === null || !($task instanceof ConfigurableTaskInterface)) { |
|
| 157 | - return true; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
| 161 | - if (!$task->updateConfig($request, $task_schedule)) { |
|
| 162 | - FlashMessages::addMessage( |
|
| 163 | - I18N::translate( |
|
| 164 | - 'An error occured while updating the specific settings of administrative task “%s”', |
|
| 165 | - $task->name() |
|
| 166 | - ), |
|
| 167 | - 'danger' |
|
| 168 | - ); |
|
| 169 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 170 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.'); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return true; |
|
| 174 | - } |
|
| 37 | + /** |
|
| 38 | + * @var AdminTasksModule $module |
|
| 39 | + */ |
|
| 40 | + private $module; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var TaskScheduleService $taskschedules_service |
|
| 44 | + */ |
|
| 45 | + private $taskschedules_service; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Constructor for TaskEditAction Request Handler |
|
| 49 | + * |
|
| 50 | + * @param ModuleService $module_service |
|
| 51 | + * @param TaskScheduleService $taskschedules_service |
|
| 52 | + */ |
|
| 53 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 54 | + { |
|
| 55 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 56 | + $this->taskschedules_service = $taskschedules_service; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * {@inheritDoc} |
|
| 61 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 62 | + */ |
|
| 63 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 64 | + { |
|
| 65 | + $task_sched_id = (int) $request->getAttribute('task'); |
|
| 66 | + $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
| 67 | + |
|
| 68 | + $admin_config_route = route(AdminConfigPage::class); |
|
| 69 | + |
|
| 70 | + if ($task_schedule === null) { |
|
| 71 | + FlashMessages::addMessage( |
|
| 72 | + I18N::translate('The task shedule with ID “%d” does not exist.', I18N::number($task_sched_id)), |
|
| 73 | + 'danger' |
|
| 74 | + ); |
|
| 75 | + return redirect($admin_config_route); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $success = $this->updateGeneralSettings($task_schedule, $request); |
|
| 79 | + $success = $success && $this->updateSpecificSettings($task_schedule, $request); |
|
| 80 | + |
|
| 81 | + if ($success) { |
|
| 82 | + FlashMessages::addMessage( |
|
| 83 | + I18N::translate('The scheduled task has been successfully updated'), |
|
| 84 | + 'success' |
|
| 85 | + ); |
|
| 86 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 87 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Task Schedule “' . $task_schedule->id() . '” has been updated.'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return redirect($admin_config_route); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Update general settings for the task, based on the request parameters |
|
| 95 | + * |
|
| 96 | + * @param TaskSchedule $task_schedule |
|
| 97 | + * @param ServerRequestInterface $request |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | + private function updateGeneralSettings(TaskSchedule $task_schedule, ServerRequestInterface $request): bool |
|
| 101 | + { |
|
| 102 | + $params = (array) $request->getParsedBody(); |
|
| 103 | + |
|
| 104 | + $frequency = (int) $params['frequency']; |
|
| 105 | + if ($frequency > 0) { |
|
| 106 | + $task_schedule->setFrequency(CarbonInterval::minutes($frequency)); |
|
| 107 | + } else { |
|
| 108 | + FlashMessages::addMessage(I18N::translate('The frequency is not in a valid format'), 'danger'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $is_limited = (bool) $params['is_limited']; |
|
| 112 | + $nb_occur = (int) $params['nb_occur']; |
|
| 113 | + |
|
| 114 | + if ($is_limited) { |
|
| 115 | + if ($nb_occur > 0) { |
|
| 116 | + $task_schedule->setRemainingOccurences($nb_occur); |
|
| 117 | + } else { |
|
| 118 | + FlashMessages::addMessage( |
|
| 119 | + I18N::translate('The number of remaining occurences is not in a valid format'), |
|
| 120 | + 'danger' |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + } else { |
|
| 124 | + $task_schedule->setRemainingOccurences(0); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + try { |
|
| 128 | + $this->taskschedules_service->update($task_schedule); |
|
| 129 | + return true; |
|
| 130 | + } catch (Exception $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 | + $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
| 156 | + if ($task === null || !($task instanceof ConfigurableTaskInterface)) { |
|
| 157 | + return true; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
| 161 | + if (!$task->updateConfig($request, $task_schedule)) { |
|
| 162 | + FlashMessages::addMessage( |
|
| 163 | + I18N::translate( |
|
| 164 | + 'An error occured while updating the specific settings of administrative task “%s”', |
|
| 165 | + $task->name() |
|
| 166 | + ), |
|
| 167 | + 'danger' |
|
| 168 | + ); |
|
| 169 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 170 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : AdminTask “' . $task->name() . '” specific settings could not be updated. See error log.'); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return true; |
|
| 174 | + } |
|
| 175 | 175 | } |
@@ -29,48 +29,48 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class TaskTrigger implements RequestHandlerInterface |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * @var AdminTasksModule $module |
|
| 34 | - */ |
|
| 35 | - private $module; |
|
| 32 | + /** |
|
| 33 | + * @var AdminTasksModule $module |
|
| 34 | + */ |
|
| 35 | + private $module; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var TaskScheduleService $taskschedules_service |
|
| 39 | - */ |
|
| 40 | - private $taskschedules_service; |
|
| 37 | + /** |
|
| 38 | + * @var TaskScheduleService $taskschedules_service |
|
| 39 | + */ |
|
| 40 | + private $taskschedules_service; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor for TaskTrigger request handler |
|
| 44 | - * @param ModuleService $module_service |
|
| 45 | - * @param TaskScheduleService $taskschedules_service |
|
| 46 | - */ |
|
| 47 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 48 | - { |
|
| 49 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 50 | - $this->taskschedules_service = $taskschedules_service; |
|
| 51 | - } |
|
| 42 | + /** |
|
| 43 | + * Constructor for TaskTrigger request handler |
|
| 44 | + * @param ModuleService $module_service |
|
| 45 | + * @param TaskScheduleService $taskschedules_service |
|
| 46 | + */ |
|
| 47 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
| 48 | + { |
|
| 49 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 50 | + $this->taskschedules_service = $taskschedules_service; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritDoc} |
|
| 55 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 56 | - */ |
|
| 57 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 58 | - { |
|
| 59 | - if ($this->module === null) { |
|
| 60 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritDoc} |
|
| 55 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 56 | + */ |
|
| 57 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 58 | + { |
|
| 59 | + if ($this->module === null) { |
|
| 60 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $task_id = $request->getAttribute('task'); |
|
| 64 | - $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 65 | - $force_token = $request->getQueryParams()['force'] ?? ''; |
|
| 66 | - $force = $token == $force_token; |
|
| 63 | + $task_id = $request->getAttribute('task'); |
|
| 64 | + $token = $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN'); |
|
| 65 | + $force_token = $request->getQueryParams()['force'] ?? ''; |
|
| 66 | + $force = $token == $force_token; |
|
| 67 | 67 | |
| 68 | - $task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id); |
|
| 68 | + $task_schedules = $this->taskschedules_service->findTasksToRun($force, $task_id); |
|
| 69 | 69 | |
| 70 | - foreach ($task_schedules as $task_schedule) { |
|
| 71 | - $this->taskschedules_service->run($task_schedule, $force); |
|
| 72 | - } |
|
| 70 | + foreach ($task_schedules as $task_schedule) { |
|
| 71 | + $this->taskschedules_service->run($task_schedule, $force); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return response(); |
|
| 75 | - } |
|
| 74 | + return response(); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(Carbon::now()); |
| 137 | 137 | //@phpcs:ignore Generic.Files.LineLength.TooLong |
| 138 | 138 | $interval = $interval_lastrun->greaterThan($task_schedule->frequency()) ? $interval_lastrun : $task_schedule->frequency(); |
| 139 | - $nb_days = (int) $interval->ceilDay()->totalDays; |
|
| 139 | + $nb_days = (int)$interval->ceilDay()->totalDays; |
|
| 140 | 140 | |
| 141 | 141 | $view_params_site = [ |
| 142 | 142 | 'nb_days' => $nb_days, |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | continue; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
| 158 | + $webmaster = $this->user_service->find((int)$tree->getPreference('WEBMASTER_USER_ID')); |
|
| 159 | 159 | if ($webmaster === null) { |
| 160 | 160 | continue; |
| 161 | 161 | } |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | new TreeUser($tree), |
| 177 | 177 | $webmaster, |
| 178 | 178 | new NoReplyUser(), |
| 179 | - I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
| 180 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
| 181 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
| 179 | + I18N::translate('Health Check Report').' - '.I18N::translate('Tree %s', $tree->name()), |
|
| 180 | + view($this->module->name().'::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
| 181 | + view($this->module->name().'::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
| 182 | 182 | ); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function configView(ServerRequestInterface $request): string |
| 193 | 193 | { |
| 194 | - return view($this->module->name() . '::tasks/healthcheck/config', [ |
|
| 194 | + return view($this->module->name().'::tasks/healthcheck/config', [ |
|
| 195 | 195 | 'all_trees' => $this->tree_service->all() |
| 196 | 196 | ]); |
| 197 | 197 | } |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
| 204 | 204 | { |
| 205 | 205 | try { |
| 206 | - $params = (array) $request->getParsedBody(); |
|
| 206 | + $params = (array)$request->getParsedBody(); |
|
| 207 | 207 | |
| 208 | 208 | foreach ($this->tree_service->all() as $tree) { |
| 209 | 209 | if (Auth::isManager($tree)) { |
| 210 | - $tree_enabled = (bool) ($params['HEALTHCHECK_ENABLED_' . $tree->id()] ?? false); |
|
| 210 | + $tree_enabled = (bool)($params['HEALTHCHECK_ENABLED_'.$tree->id()] ?? false); |
|
| 211 | 211 | $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -39,188 +39,188 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class HealthCheckEmailTask implements TaskInterface, ConfigurableTaskInterface |
| 41 | 41 | { |
| 42 | - /** |
|
| 43 | - * Name of the Tree preference to check if the task is enabled for that tree |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - public const TREE_PREFERENCE_NAME = 'MAJ_AT_HEALTHCHECK_ENABLED'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var AdminTasksModule $module |
|
| 50 | - */ |
|
| 51 | - private $module; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var HealthCheckService $healthcheck_service; |
|
| 55 | - */ |
|
| 56 | - private $healthcheck_service; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var EmailService $email_service; |
|
| 60 | - */ |
|
| 61 | - private $email_service; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var UserService $user_service |
|
| 65 | - */ |
|
| 66 | - private $user_service; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var TreeService $tree_service |
|
| 70 | - */ |
|
| 71 | - private $tree_service; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var UpgradeService $upgrade_service |
|
| 75 | - */ |
|
| 76 | - private $upgrade_service; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Constructor for HealthCheckTask |
|
| 80 | - * |
|
| 81 | - * @param ModuleService $module_service |
|
| 82 | - * @param HealthCheckService $healthcheck_service |
|
| 83 | - * @param EmailService $email_service |
|
| 84 | - * @param UserService $user_service |
|
| 85 | - * @param TreeService $tree_service |
|
| 86 | - * @param UpgradeService $upgrade_service |
|
| 87 | - */ |
|
| 88 | - public function __construct( |
|
| 89 | - ModuleService $module_service, |
|
| 90 | - HealthCheckService $healthcheck_service, |
|
| 91 | - EmailService $email_service, |
|
| 92 | - UserService $user_service, |
|
| 93 | - TreeService $tree_service, |
|
| 94 | - UpgradeService $upgrade_service |
|
| 95 | - ) { |
|
| 96 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 97 | - $this->healthcheck_service = $healthcheck_service; |
|
| 98 | - $this->email_service = $email_service; |
|
| 99 | - $this->user_service = $user_service; |
|
| 100 | - $this->tree_service = $tree_service; |
|
| 101 | - $this->upgrade_service = $upgrade_service; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * {@inheritDoc} |
|
| 107 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::name() |
|
| 108 | - */ |
|
| 109 | - public function name(): string |
|
| 110 | - { |
|
| 111 | - return I18N::translate('Healthcheck Email'); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * {@inheritDoc} |
|
| 116 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::defaultFrequency() |
|
| 117 | - */ |
|
| 118 | - public function defaultFrequency(): int |
|
| 119 | - { |
|
| 120 | - return 10080; // = 1 week = 7 * 24 * 60 min |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * {@inheritDoc} |
|
| 125 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::run() |
|
| 126 | - */ |
|
| 127 | - public function run(TaskSchedule $task_schedule): bool |
|
| 128 | - { |
|
| 129 | - if ($this->module === null) { |
|
| 130 | - return false; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $res = true; |
|
| 134 | - |
|
| 135 | - // Compute the number of days to compute |
|
| 136 | - $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(Carbon::now()); |
|
| 137 | - //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 138 | - $interval = $interval_lastrun->greaterThan($task_schedule->frequency()) ? $interval_lastrun : $task_schedule->frequency(); |
|
| 139 | - $nb_days = (int) $interval->ceilDay()->totalDays; |
|
| 140 | - |
|
| 141 | - $view_params_site = [ |
|
| 142 | - 'nb_days' => $nb_days, |
|
| 143 | - 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
|
| 144 | - 'latest_version' => $this->upgrade_service->latestVersion(), |
|
| 145 | - 'download_url' => $this->upgrade_service->downloadUrl(), |
|
| 146 | - 'all_users' => $this->user_service->all(), |
|
| 147 | - 'unapproved' => $this->user_service->unapproved(), |
|
| 148 | - 'unverified' => $this->user_service->unverified(), |
|
| 149 | - ]; |
|
| 150 | - |
|
| 151 | - foreach ($this->tree_service->all() as $tree) { |
|
| 152 | - /** @var Tree $tree */ |
|
| 153 | - |
|
| 154 | - if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
|
| 155 | - continue; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
| 159 | - if ($webmaster === null) { |
|
| 160 | - continue; |
|
| 161 | - } |
|
| 162 | - I18N::init($webmaster->getPreference('language')); |
|
| 163 | - |
|
| 164 | - $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
|
| 165 | - $nb_errors = $error_logs->sum('nblogs'); |
|
| 166 | - |
|
| 167 | - $view_params = array_merge($view_params_site, [ |
|
| 168 | - 'tree' => $tree, |
|
| 169 | - 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
|
| 170 | - 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
|
| 171 | - 'error_logs' => $error_logs, |
|
| 172 | - 'nb_errors' => $nb_errors |
|
| 173 | - ]); |
|
| 174 | - |
|
| 175 | - $res = $res && $this->email_service->send( |
|
| 176 | - new TreeUser($tree), |
|
| 177 | - $webmaster, |
|
| 178 | - new NoReplyUser(), |
|
| 179 | - I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
| 180 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
| 181 | - view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return $res; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * {@inheritDoc} |
|
| 190 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface::configView() |
|
| 191 | - */ |
|
| 192 | - public function configView(ServerRequestInterface $request): string |
|
| 193 | - { |
|
| 194 | - return view($this->module->name() . '::tasks/healthcheck/config', [ |
|
| 195 | - 'all_trees' => $this->tree_service->all() |
|
| 196 | - ]); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * {@inheritDoc} |
|
| 201 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface::updateConfig() |
|
| 202 | - */ |
|
| 203 | - public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
|
| 204 | - { |
|
| 205 | - try { |
|
| 206 | - $params = (array) $request->getParsedBody(); |
|
| 207 | - |
|
| 208 | - foreach ($this->tree_service->all() as $tree) { |
|
| 209 | - if (Auth::isManager($tree)) { |
|
| 210 | - $tree_enabled = (bool) ($params['HEALTHCHECK_ENABLED_' . $tree->id()] ?? false); |
|
| 211 | - $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - return true; |
|
| 215 | - } catch (Exception $ex) { |
|
| 216 | - Log::addErrorLog( |
|
| 217 | - sprintf( |
|
| 218 | - 'Error while updating the Task schedule "%s". Exception: %s', |
|
| 219 | - $task_schedule->id(), |
|
| 220 | - $ex->getMessage() |
|
| 221 | - ) |
|
| 222 | - ); |
|
| 223 | - } |
|
| 224 | - return false; |
|
| 225 | - } |
|
| 42 | + /** |
|
| 43 | + * Name of the Tree preference to check if the task is enabled for that tree |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + public const TREE_PREFERENCE_NAME = 'MAJ_AT_HEALTHCHECK_ENABLED'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var AdminTasksModule $module |
|
| 50 | + */ |
|
| 51 | + private $module; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var HealthCheckService $healthcheck_service; |
|
| 55 | + */ |
|
| 56 | + private $healthcheck_service; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var EmailService $email_service; |
|
| 60 | + */ |
|
| 61 | + private $email_service; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var UserService $user_service |
|
| 65 | + */ |
|
| 66 | + private $user_service; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var TreeService $tree_service |
|
| 70 | + */ |
|
| 71 | + private $tree_service; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var UpgradeService $upgrade_service |
|
| 75 | + */ |
|
| 76 | + private $upgrade_service; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Constructor for HealthCheckTask |
|
| 80 | + * |
|
| 81 | + * @param ModuleService $module_service |
|
| 82 | + * @param HealthCheckService $healthcheck_service |
|
| 83 | + * @param EmailService $email_service |
|
| 84 | + * @param UserService $user_service |
|
| 85 | + * @param TreeService $tree_service |
|
| 86 | + * @param UpgradeService $upgrade_service |
|
| 87 | + */ |
|
| 88 | + public function __construct( |
|
| 89 | + ModuleService $module_service, |
|
| 90 | + HealthCheckService $healthcheck_service, |
|
| 91 | + EmailService $email_service, |
|
| 92 | + UserService $user_service, |
|
| 93 | + TreeService $tree_service, |
|
| 94 | + UpgradeService $upgrade_service |
|
| 95 | + ) { |
|
| 96 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
| 97 | + $this->healthcheck_service = $healthcheck_service; |
|
| 98 | + $this->email_service = $email_service; |
|
| 99 | + $this->user_service = $user_service; |
|
| 100 | + $this->tree_service = $tree_service; |
|
| 101 | + $this->upgrade_service = $upgrade_service; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * {@inheritDoc} |
|
| 107 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::name() |
|
| 108 | + */ |
|
| 109 | + public function name(): string |
|
| 110 | + { |
|
| 111 | + return I18N::translate('Healthcheck Email'); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * {@inheritDoc} |
|
| 116 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::defaultFrequency() |
|
| 117 | + */ |
|
| 118 | + public function defaultFrequency(): int |
|
| 119 | + { |
|
| 120 | + return 10080; // = 1 week = 7 * 24 * 60 min |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * {@inheritDoc} |
|
| 125 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\TaskInterface::run() |
|
| 126 | + */ |
|
| 127 | + public function run(TaskSchedule $task_schedule): bool |
|
| 128 | + { |
|
| 129 | + if ($this->module === null) { |
|
| 130 | + return false; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $res = true; |
|
| 134 | + |
|
| 135 | + // Compute the number of days to compute |
|
| 136 | + $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(Carbon::now()); |
|
| 137 | + //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 138 | + $interval = $interval_lastrun->greaterThan($task_schedule->frequency()) ? $interval_lastrun : $task_schedule->frequency(); |
|
| 139 | + $nb_days = (int) $interval->ceilDay()->totalDays; |
|
| 140 | + |
|
| 141 | + $view_params_site = [ |
|
| 142 | + 'nb_days' => $nb_days, |
|
| 143 | + 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
|
| 144 | + 'latest_version' => $this->upgrade_service->latestVersion(), |
|
| 145 | + 'download_url' => $this->upgrade_service->downloadUrl(), |
|
| 146 | + 'all_users' => $this->user_service->all(), |
|
| 147 | + 'unapproved' => $this->user_service->unapproved(), |
|
| 148 | + 'unverified' => $this->user_service->unverified(), |
|
| 149 | + ]; |
|
| 150 | + |
|
| 151 | + foreach ($this->tree_service->all() as $tree) { |
|
| 152 | + /** @var Tree $tree */ |
|
| 153 | + |
|
| 154 | + if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
|
| 155 | + continue; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
|
| 159 | + if ($webmaster === null) { |
|
| 160 | + continue; |
|
| 161 | + } |
|
| 162 | + I18N::init($webmaster->getPreference('language')); |
|
| 163 | + |
|
| 164 | + $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
|
| 165 | + $nb_errors = $error_logs->sum('nblogs'); |
|
| 166 | + |
|
| 167 | + $view_params = array_merge($view_params_site, [ |
|
| 168 | + 'tree' => $tree, |
|
| 169 | + 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
|
| 170 | + 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
|
| 171 | + 'error_logs' => $error_logs, |
|
| 172 | + 'nb_errors' => $nb_errors |
|
| 173 | + ]); |
|
| 174 | + |
|
| 175 | + $res = $res && $this->email_service->send( |
|
| 176 | + new TreeUser($tree), |
|
| 177 | + $webmaster, |
|
| 178 | + new NoReplyUser(), |
|
| 179 | + I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
|
| 180 | + view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
|
| 181 | + view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return $res; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * {@inheritDoc} |
|
| 190 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface::configView() |
|
| 191 | + */ |
|
| 192 | + public function configView(ServerRequestInterface $request): string |
|
| 193 | + { |
|
| 194 | + return view($this->module->name() . '::tasks/healthcheck/config', [ |
|
| 195 | + 'all_trees' => $this->tree_service->all() |
|
| 196 | + ]); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * {@inheritDoc} |
|
| 201 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface::updateConfig() |
|
| 202 | + */ |
|
| 203 | + public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool |
|
| 204 | + { |
|
| 205 | + try { |
|
| 206 | + $params = (array) $request->getParsedBody(); |
|
| 207 | + |
|
| 208 | + foreach ($this->tree_service->all() as $tree) { |
|
| 209 | + if (Auth::isManager($tree)) { |
|
| 210 | + $tree_enabled = (bool) ($params['HEALTHCHECK_ENABLED_' . $tree->id()] ?? false); |
|
| 211 | + $tree->setPreference(self::TREE_PREFERENCE_NAME, $tree_enabled ? '1' : '0'); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + return true; |
|
| 215 | + } catch (Exception $ex) { |
|
| 216 | + Log::addErrorLog( |
|
| 217 | + sprintf( |
|
| 218 | + 'Error while updating the Task schedule "%s". Exception: %s', |
|
| 219 | + $task_schedule->id(), |
|
| 220 | + $ex->getMessage() |
|
| 221 | + ) |
|
| 222 | + ); |
|
| 223 | + } |
|
| 224 | + return false; |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -22,12 +22,12 @@ |
||
| 22 | 22 | class Migration0 implements MigrationInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * {@inheritDoc} |
|
| 27 | - * @see MigrationInterface::upgrade() |
|
| 28 | - */ |
|
| 29 | - public function upgrade(): void |
|
| 30 | - { |
|
| 31 | - // These migrations have been merged into migration 1. |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * {@inheritDoc} |
|
| 27 | + * @see MigrationInterface::upgrade() |
|
| 28 | + */ |
|
| 29 | + public function upgrade(): void |
|
| 30 | + { |
|
| 31 | + // These migrations have been merged into migration 1. |
|
| 32 | + } |
|
| 33 | 33 | } |