@@ -34,93 +34,93 @@ |
||
| 34 | 34 | * Provide miscellaneous improvements to webtrees. |
| 35 | 35 | */ |
| 36 | 36 | class MiscExtensionsModule extends AbstractModule implements |
| 37 | - ModuleMyArtJaubInterface, |
|
| 38 | - ModuleConfigInterface, |
|
| 39 | - ModuleHookSubscriberInterface |
|
| 37 | + ModuleMyArtJaubInterface, |
|
| 38 | + ModuleConfigInterface, |
|
| 39 | + ModuleHookSubscriberInterface |
|
| 40 | 40 | { |
| 41 | - use ModuleMyArtJaubTrait { |
|
| 42 | - boot as traitBoot; |
|
| 43 | - } |
|
| 44 | - use ModuleConfigTrait; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * {@inheritDoc} |
|
| 48 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 49 | - */ |
|
| 50 | - public function title(): string |
|
| 51 | - { |
|
| 52 | - return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * {@inheritDoc} |
|
| 57 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 58 | - */ |
|
| 59 | - public function description(): string |
|
| 60 | - { |
|
| 61 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 62 | - return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * {@inheritDoc} |
|
| 67 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 68 | - */ |
|
| 69 | - public function boot(): void |
|
| 70 | - { |
|
| 71 | - $this->traitBoot(); |
|
| 72 | - View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy'); |
|
| 73 | - |
|
| 74 | - if ((int) $this->getPreference('MAJ_USE_LEGACY_XREF') === 1) { |
|
| 75 | - Registry::xrefFactory(new LegacyXrefFactory()); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * {@inheritDoc} |
|
| 81 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 82 | - */ |
|
| 83 | - public function loadRoutes(Map $router): void |
|
| 84 | - { |
|
| 85 | - $router->attach('', '', static function (Map $router): void { |
|
| 86 | - |
|
| 87 | - $router->attach('', '/module-maj/misc', static function (Map $router): void { |
|
| 88 | - |
|
| 89 | - $router->attach('', '/config/admin', static function (Map $router): void { |
|
| 90 | - |
|
| 91 | - $router->get(AdminConfigPage::class, '', AdminConfigPage::class); |
|
| 92 | - $router->post(AdminConfigAction::class, '', AdminConfigAction::class); |
|
| 93 | - }); |
|
| 94 | - }); |
|
| 95 | - }); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * {@inheritDoc} |
|
| 100 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 101 | - */ |
|
| 102 | - public function customModuleVersion(): string |
|
| 103 | - { |
|
| 104 | - return '2.1.3-v.2'; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * {@inheritDoc} |
|
| 109 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
| 110 | - */ |
|
| 111 | - public function getConfigLink(): string |
|
| 112 | - { |
|
| 113 | - return route(AdminConfigPage::class); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * {@inheritDoc} |
|
| 118 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 119 | - */ |
|
| 120 | - public function listSubscribedHooks(): array |
|
| 121 | - { |
|
| 122 | - return [ |
|
| 123 | - app()->makeWith(TitlesCardHook::class, [ 'module' => $this ]) |
|
| 124 | - ]; |
|
| 125 | - } |
|
| 41 | + use ModuleMyArtJaubTrait { |
|
| 42 | + boot as traitBoot; |
|
| 43 | + } |
|
| 44 | + use ModuleConfigTrait; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * {@inheritDoc} |
|
| 48 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 49 | + */ |
|
| 50 | + public function title(): string |
|
| 51 | + { |
|
| 52 | + return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * {@inheritDoc} |
|
| 57 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 58 | + */ |
|
| 59 | + public function description(): string |
|
| 60 | + { |
|
| 61 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 62 | + return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * {@inheritDoc} |
|
| 67 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 68 | + */ |
|
| 69 | + public function boot(): void |
|
| 70 | + { |
|
| 71 | + $this->traitBoot(); |
|
| 72 | + View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy'); |
|
| 73 | + |
|
| 74 | + if ((int) $this->getPreference('MAJ_USE_LEGACY_XREF') === 1) { |
|
| 75 | + Registry::xrefFactory(new LegacyXrefFactory()); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * {@inheritDoc} |
|
| 81 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 82 | + */ |
|
| 83 | + public function loadRoutes(Map $router): void |
|
| 84 | + { |
|
| 85 | + $router->attach('', '', static function (Map $router): void { |
|
| 86 | + |
|
| 87 | + $router->attach('', '/module-maj/misc', static function (Map $router): void { |
|
| 88 | + |
|
| 89 | + $router->attach('', '/config/admin', static function (Map $router): void { |
|
| 90 | + |
|
| 91 | + $router->get(AdminConfigPage::class, '', AdminConfigPage::class); |
|
| 92 | + $router->post(AdminConfigAction::class, '', AdminConfigAction::class); |
|
| 93 | + }); |
|
| 94 | + }); |
|
| 95 | + }); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * {@inheritDoc} |
|
| 100 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 101 | + */ |
|
| 102 | + public function customModuleVersion(): string |
|
| 103 | + { |
|
| 104 | + return '2.1.3-v.2'; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * {@inheritDoc} |
|
| 109 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
| 110 | + */ |
|
| 111 | + public function getConfigLink(): string |
|
| 112 | + { |
|
| 113 | + return route(AdminConfigPage::class); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * {@inheritDoc} |
|
| 118 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 119 | + */ |
|
| 120 | + public function listSubscribedHooks(): array |
|
| 121 | + { |
|
| 122 | + return [ |
|
| 123 | + app()->makeWith(TitlesCardHook::class, [ 'module' => $this ]) |
|
| 124 | + ]; |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -23,67 +23,67 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class LegacyXrefFactory extends XrefFactory |
| 25 | 25 | { |
| 26 | - protected const TYPE_TO_PREFIX = [ |
|
| 27 | - 'INDI' => 'I', |
|
| 28 | - 'FAM' => 'F', |
|
| 29 | - 'OBJE' => 'M', |
|
| 30 | - 'NOTE' => 'N', |
|
| 31 | - 'SOUR' => 'S', |
|
| 32 | - 'REPO' => 'R', |
|
| 33 | - ]; |
|
| 26 | + protected const TYPE_TO_PREFIX = [ |
|
| 27 | + 'INDI' => 'I', |
|
| 28 | + 'FAM' => 'F', |
|
| 29 | + 'OBJE' => 'M', |
|
| 30 | + 'NOTE' => 'N', |
|
| 31 | + 'SOUR' => 'S', |
|
| 32 | + 'REPO' => 'R', |
|
| 33 | + ]; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * {@inheritDoc} |
|
| 37 | - * @see \Fisharebest\Webtrees\Factories\XrefFactory::make() |
|
| 38 | - */ |
|
| 39 | - public function make(string $record_type): string |
|
| 40 | - { |
|
| 41 | - $prefix = static::TYPE_TO_PREFIX[$record_type] ?? 'X'; |
|
| 35 | + /** |
|
| 36 | + * {@inheritDoc} |
|
| 37 | + * @see \Fisharebest\Webtrees\Factories\XrefFactory::make() |
|
| 38 | + */ |
|
| 39 | + public function make(string $record_type): string |
|
| 40 | + { |
|
| 41 | + $prefix = static::TYPE_TO_PREFIX[$record_type] ?? 'X'; |
|
| 42 | 42 | |
| 43 | - return $this->generate($prefix, ''); |
|
| 44 | - } |
|
| 43 | + return $this->generate($prefix, ''); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * {@inheritDoc} |
|
| 48 | - * @see \Fisharebest\Webtrees\Factories\XrefFactory::generate() |
|
| 49 | - */ |
|
| 50 | - protected function generate($prefix, $suffix): string |
|
| 51 | - { |
|
| 52 | - $tree = app(Tree::class); |
|
| 53 | - if (!$tree instanceof Tree) { |
|
| 54 | - return parent::generate($prefix, $suffix); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * {@inheritDoc} |
|
| 48 | + * @see \Fisharebest\Webtrees\Factories\XrefFactory::generate() |
|
| 49 | + */ |
|
| 50 | + protected function generate($prefix, $suffix): string |
|
| 51 | + { |
|
| 52 | + $tree = app(Tree::class); |
|
| 53 | + if (!$tree instanceof Tree) { |
|
| 54 | + return parent::generate($prefix, $suffix); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $setting_name = 'MAJ_MISC_XREF_NEXT_' . $prefix; |
|
| 58 | - // Lock the row, so that only one new XREF may be generated at a time. |
|
| 59 | - DB::table('gedcom_setting') |
|
| 60 | - ->where('gedcom_id', '=', $tree->id()) |
|
| 61 | - ->where('setting_name', '=', $setting_name) |
|
| 62 | - ->lockForUpdate() |
|
| 63 | - ->get(); |
|
| 57 | + $setting_name = 'MAJ_MISC_XREF_NEXT_' . $prefix; |
|
| 58 | + // Lock the row, so that only one new XREF may be generated at a time. |
|
| 59 | + DB::table('gedcom_setting') |
|
| 60 | + ->where('gedcom_id', '=', $tree->id()) |
|
| 61 | + ->where('setting_name', '=', $setting_name) |
|
| 62 | + ->lockForUpdate() |
|
| 63 | + ->get(); |
|
| 64 | 64 | |
| 65 | - $increment = 1.0; |
|
| 66 | - do { |
|
| 67 | - $num = (int) $tree->getPreference($setting_name) + (int) $increment; |
|
| 65 | + $increment = 1.0; |
|
| 66 | + do { |
|
| 67 | + $num = (int) $tree->getPreference($setting_name) + (int) $increment; |
|
| 68 | 68 | |
| 69 | - // This exponential increment allows us to scan over large blocks of |
|
| 70 | - // existing data in a reasonable time. |
|
| 71 | - $increment *= 1.01; |
|
| 69 | + // This exponential increment allows us to scan over large blocks of |
|
| 70 | + // existing data in a reasonable time. |
|
| 71 | + $increment *= 1.01; |
|
| 72 | 72 | |
| 73 | - $xref = $prefix . $num . $suffix; |
|
| 73 | + $xref = $prefix . $num . $suffix; |
|
| 74 | 74 | |
| 75 | - // Records may already exist with this sequence number. |
|
| 76 | - $already_used = |
|
| 77 | - DB::table('individuals')->where('i_file', '=', $tree->id())->where('i_id', '=', $xref)->exists() || |
|
| 78 | - DB::table('families')->where('f_file', '=', $tree->id())->where('f_id', '=', $xref)->exists() || |
|
| 79 | - DB::table('sources')->where('s_file', '=', $tree->id())->where('s_id', '=', $xref)->exists() || |
|
| 80 | - DB::table('media')->where('m_file', '=', $tree->id())->where('m_id', '=', $xref)->exists() || |
|
| 81 | - DB::table('other')->where('o_file', '=', $tree->id())->where('o_id', '=', $xref)->exists() || |
|
| 82 | - DB::table('change')->where('gedcom_id', '=', $tree->id())->where('xref', '=', $xref)->exists(); |
|
| 83 | - } while ($already_used); |
|
| 75 | + // Records may already exist with this sequence number. |
|
| 76 | + $already_used = |
|
| 77 | + DB::table('individuals')->where('i_file', '=', $tree->id())->where('i_id', '=', $xref)->exists() || |
|
| 78 | + DB::table('families')->where('f_file', '=', $tree->id())->where('f_id', '=', $xref)->exists() || |
|
| 79 | + DB::table('sources')->where('s_file', '=', $tree->id())->where('s_id', '=', $xref)->exists() || |
|
| 80 | + DB::table('media')->where('m_file', '=', $tree->id())->where('m_id', '=', $xref)->exists() || |
|
| 81 | + DB::table('other')->where('o_file', '=', $tree->id())->where('o_id', '=', $xref)->exists() || |
|
| 82 | + DB::table('change')->where('gedcom_id', '=', $tree->id())->where('xref', '=', $xref)->exists(); |
|
| 83 | + } while ($already_used); |
|
| 84 | 84 | |
| 85 | - $tree->setPreference($setting_name, (string) $num); |
|
| 85 | + $tree->setPreference($setting_name, (string) $num); |
|
| 86 | 86 | |
| 87 | - return $xref; |
|
| 88 | - } |
|
| 87 | + return $xref; |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -29,54 +29,54 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class AdminConfigAction implements RequestHandlerInterface |
| 31 | 31 | { |
| 32 | - private ?MiscExtensionsModule $module; |
|
| 32 | + private ?MiscExtensionsModule $module; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor for AdminConfigPage Request Handler |
|
| 36 | - * |
|
| 37 | - * @param ModuleService $module_service |
|
| 38 | - */ |
|
| 39 | - public function __construct(ModuleService $module_service) |
|
| 40 | - { |
|
| 41 | - $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first(); |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor for AdminConfigPage Request Handler |
|
| 36 | + * |
|
| 37 | + * @param ModuleService $module_service |
|
| 38 | + */ |
|
| 39 | + public function __construct(ModuleService $module_service) |
|
| 40 | + { |
|
| 41 | + $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * {@inheritDoc} |
|
| 46 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 47 | - */ |
|
| 48 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 49 | - { |
|
| 50 | - if ($this->module === null) { |
|
| 51 | - FlashMessages::addMessage( |
|
| 52 | - I18N::translate('The attached module could not be found.'), |
|
| 53 | - 'danger' |
|
| 54 | - ); |
|
| 55 | - return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
| 56 | - } |
|
| 44 | + /** |
|
| 45 | + * {@inheritDoc} |
|
| 46 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 47 | + */ |
|
| 48 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 49 | + { |
|
| 50 | + if ($this->module === null) { |
|
| 51 | + FlashMessages::addMessage( |
|
| 52 | + I18N::translate('The attached module could not be found.'), |
|
| 53 | + 'danger' |
|
| 54 | + ); |
|
| 55 | + return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $this->module->setPreference( |
|
| 59 | - 'MAJ_TITLE_PREFIX', |
|
| 60 | - Validator::parsedBody($request)->string('MAJ_TITLE_PREFIX', '') |
|
| 61 | - ); |
|
| 62 | - $this->module->setPreference( |
|
| 63 | - 'MAJ_DISPLAY_CNIL', |
|
| 64 | - (string) Validator::parsedBody($request)->integer('MAJ_DISPLAY_CNIL', 0) |
|
| 65 | - ); |
|
| 66 | - $this->module->setPreference( |
|
| 67 | - 'MAJ_CNIL_REFERENCE', |
|
| 68 | - Validator::parsedBody($request)->string('MAJ_CNIL_REFERENCE', '') |
|
| 69 | - ); |
|
| 70 | - $this->module->setPreference( |
|
| 71 | - 'MAJ_USE_LEGACY_XREF', |
|
| 72 | - (string) Validator::parsedBody($request)->integer('MAJ_USE_LEGACY_XREF', 0) |
|
| 73 | - ); |
|
| 58 | + $this->module->setPreference( |
|
| 59 | + 'MAJ_TITLE_PREFIX', |
|
| 60 | + Validator::parsedBody($request)->string('MAJ_TITLE_PREFIX', '') |
|
| 61 | + ); |
|
| 62 | + $this->module->setPreference( |
|
| 63 | + 'MAJ_DISPLAY_CNIL', |
|
| 64 | + (string) Validator::parsedBody($request)->integer('MAJ_DISPLAY_CNIL', 0) |
|
| 65 | + ); |
|
| 66 | + $this->module->setPreference( |
|
| 67 | + 'MAJ_CNIL_REFERENCE', |
|
| 68 | + Validator::parsedBody($request)->string('MAJ_CNIL_REFERENCE', '') |
|
| 69 | + ); |
|
| 70 | + $this->module->setPreference( |
|
| 71 | + 'MAJ_USE_LEGACY_XREF', |
|
| 72 | + (string) Validator::parsedBody($request)->integer('MAJ_USE_LEGACY_XREF', 0) |
|
| 73 | + ); |
|
| 74 | 74 | |
| 75 | - FlashMessages::addMessage( |
|
| 76 | - I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
| 77 | - 'success' |
|
| 78 | - ); |
|
| 75 | + FlashMessages::addMessage( |
|
| 76 | + I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
| 77 | + 'success' |
|
| 78 | + ); |
|
| 79 | 79 | |
| 80 | - return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
| 81 | - } |
|
| 80 | + return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
| 81 | + } |
|
| 82 | 82 | } |