]> git.mxchange.org Git - friendica.git/commitdiff
Create event for dbstructure_definition hook
authorArt4 <art4@wlabs.de>
Fri, 14 Mar 2025 12:24:02 +0000 (12:24 +0000)
committerArt4 <art4@wlabs.de>
Fri, 14 Mar 2025 12:24:02 +0000 (12:24 +0000)
src/Core/Hooks/HookEventBridge.php
src/Database/Definition/DbaDefinition.php
src/Event/ArrayFilterEvent.php
tests/Unit/Core/Hooks/HookEventBridgeTest.php
tests/Unit/Event/ArrayFilterEventTest.php

index 6dc9d01e20728ebf969e889466c44ceb27a6e9ab..7c23e333f1136e6648d89596224d20191620599f 100644 (file)
@@ -70,6 +70,7 @@ final class HookEventBridge
                ArrayFilterEvent::ADD_WORKER_TASK                 => 'proc_run',
                ArrayFilterEvent::STORAGE_CONFIG                  => 'storage_config',
                ArrayFilterEvent::STORAGE_INSTANCE                => 'storage_instance',
+               ArrayFilterEvent::DB_STRUCTURE_DEFINITION         => 'dbstructure_definition',
                HtmlFilterEvent::HEAD                             => 'head',
                HtmlFilterEvent::FOOTER                           => 'footer',
                HtmlFilterEvent::PAGE_HEADER                      => 'page_header',
@@ -120,6 +121,7 @@ final class HookEventBridge
                        ArrayFilterEvent::ADD_WORKER_TASK                 => 'onArrayFilterEvent',
                        ArrayFilterEvent::STORAGE_CONFIG                  => 'onArrayFilterEvent',
                        ArrayFilterEvent::STORAGE_INSTANCE                => 'onArrayFilterEvent',
+                       ArrayFilterEvent::DB_STRUCTURE_DEFINITION         => 'onArrayFilterEvent',
                        HtmlFilterEvent::HEAD                             => 'onHtmlFilterEvent',
                        HtmlFilterEvent::FOOTER                           => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_HEADER                      => 'onHtmlFilterEvent',
index 378ba86867016f1a316d8b282b67a65a7a32e7be..ecc75f6aa3b20d020adc17646430f0aa504c8bde 100644 (file)
@@ -8,9 +8,9 @@
 namespace Friendica\Database\Definition;
 
 use Exception;
-use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\Hook;
 use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
 
 /**
  * Stores the whole database definition
@@ -109,12 +109,16 @@ class DbaDefinition
        {
                $definition = require $this->configFile;
 
-               if (!$definition) {
+               if (!is_array($definition)) {
                        throw new Exception('Corrupted database structure config file static/dbstructure.config.php');
                }
 
                if ($withAddonStructure) {
-                       Hook::callAll('dbstructure_definition', $definition);
+                       $eventDispatcher = DI::eventDispatcher();
+
+                       $definition = $eventDispatcher->dispatch(
+                               new ArrayFilterEvent(ArrayFilterEvent::DB_STRUCTURE_DEFINITION, $definition),
+                       )->getArray();
                }
 
                $this->definition = $definition;
index 4a08ba4fa3a757d8779ef21fe6ed03aaa14e7eea..f8e19bdad59ee56ab3f386aa0749f267496b51a7 100644 (file)
@@ -78,6 +78,8 @@ final class ArrayFilterEvent extends Event
 
        public const STORAGE_INSTANCE = 'friendica.data.storage_instance';
 
+       public const DB_STRUCTURE_DEFINITION = 'friendica.data.db_structure_definition';
+
        private array $array;
 
        public function __construct(string $name, array $array)
index 8ae803bdab67baffe1fd4a85878fb197a408104b..ca0cb2c160ed5c861109e97dbd96027e730071a8 100644 (file)
@@ -59,6 +59,7 @@ class HookEventBridgeTest extends TestCase
                        ArrayFilterEvent::ADD_WORKER_TASK                 => 'onArrayFilterEvent',
                        ArrayFilterEvent::STORAGE_CONFIG                  => 'onArrayFilterEvent',
                        ArrayFilterEvent::STORAGE_INSTANCE                => 'onArrayFilterEvent',
+                       ArrayFilterEvent::DB_STRUCTURE_DEFINITION         => 'onArrayFilterEvent',
                        HtmlFilterEvent::HEAD                             => 'onHtmlFilterEvent',
                        HtmlFilterEvent::FOOTER                           => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_HEADER                      => 'onHtmlFilterEvent',
@@ -294,6 +295,7 @@ class HookEventBridgeTest extends TestCase
                        [ArrayFilterEvent::ADD_WORKER_TASK, 'proc_run'],
                        [ArrayFilterEvent::STORAGE_CONFIG, 'storage_config'],
                        [ArrayFilterEvent::STORAGE_INSTANCE, 'storage_instance'],
+                       [ArrayFilterEvent::DB_STRUCTURE_DEFINITION, 'dbstructure_definition'],
                ];
        }
 
index c57b45ceb1330dc9c04e01ebc3b87b9a25d2d0d1..67b2e8a5769e414b65def49f97b722d7f663d4c7 100644 (file)
@@ -42,6 +42,7 @@ class ArrayFilterEventTest extends TestCase
                        [ArrayFilterEvent::PAGE_INFO, 'friendica.data.page_info'],
                        [ArrayFilterEvent::SMILEY_LIST, 'friendica.data.smiley_list'],
                        [ArrayFilterEvent::BBCODE_TO_HTML_START, 'friendica.data.bbcode_to_html_start'],
+                       [ArrayFilterEvent::HTML_TO_BBCODE_END, 'friendica.data.html_to_bbcode_end'],
                        [ArrayFilterEvent::BBCODE_TO_MARKDOWN_END, 'friendica.data.bbcode_to_markdown_end'],
                        [ArrayFilterEvent::JOT_NETWORKS, 'friendica.data.jot_networks'],
                        [ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'friendica.data.protocol_supports_follow'],
@@ -55,6 +56,7 @@ class ArrayFilterEventTest extends TestCase
                        [ArrayFilterEvent::ADD_WORKER_TASK, 'friendica.data.add_worker_task'],
                        [ArrayFilterEvent::STORAGE_CONFIG, 'friendica.data.storage_config'],
                        [ArrayFilterEvent::STORAGE_INSTANCE, 'friendica.data.storage_instance'],
+                       [ArrayFilterEvent::DB_STRUCTURE_DEFINITION, 'friendica.data.db_structure_definition'],
                ];
        }