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

index 7c23e333f1136e6648d89596224d20191620599f..6c477dae36f0c79f1e5651f2e2d851e214ebff9f 100644 (file)
@@ -71,6 +71,7 @@ final class HookEventBridge
                ArrayFilterEvent::STORAGE_CONFIG                  => 'storage_config',
                ArrayFilterEvent::STORAGE_INSTANCE                => 'storage_instance',
                ArrayFilterEvent::DB_STRUCTURE_DEFINITION         => 'dbstructure_definition',
+               ArrayFilterEvent::DB_VIEW_DEFINITION              => 'dbview_definition',
                HtmlFilterEvent::HEAD                             => 'head',
                HtmlFilterEvent::FOOTER                           => 'footer',
                HtmlFilterEvent::PAGE_HEADER                      => 'page_header',
@@ -122,6 +123,7 @@ final class HookEventBridge
                        ArrayFilterEvent::STORAGE_CONFIG                  => 'onArrayFilterEvent',
                        ArrayFilterEvent::STORAGE_INSTANCE                => 'onArrayFilterEvent',
                        ArrayFilterEvent::DB_STRUCTURE_DEFINITION         => 'onArrayFilterEvent',
+                       ArrayFilterEvent::DB_VIEW_DEFINITION              => 'onArrayFilterEvent',
                        HtmlFilterEvent::HEAD                             => 'onHtmlFilterEvent',
                        HtmlFilterEvent::FOOTER                           => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_HEADER                      => 'onHtmlFilterEvent',
index ecc75f6aa3b20d020adc17646430f0aa504c8bde..c5d77d3a46b0063b58aed0a4daa2fa8da5f6e067 100644 (file)
@@ -8,7 +8,6 @@
 namespace Friendica\Database\Definition;
 
 use Exception;
-use Friendica\Core\Hook;
 use Friendica\DI;
 use Friendica\Event\ArrayFilterEvent;
 
index b64e0d0ffc22e779a3f043f53335b81299032aaa..3c6cb2f43a9cc215e8b37cec8cabfc297c44980c 100644 (file)
@@ -8,7 +8,8 @@
 namespace Friendica\Database\Definition;
 
 use Exception;
-use Friendica\Core\Hook;
+use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
 
 /**
  * Stores the whole View definitions
@@ -62,12 +63,16 @@ class ViewDefinition
        {
                $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('dbview_definition', $definition);
+                       $eventDispatcher = DI::eventDispatcher();
+
+                       $definition = $eventDispatcher->dispatch(
+                               new ArrayFilterEvent(ArrayFilterEvent::DB_VIEW_DEFINITION, $definition),
+                       )->getArray();
                }
 
                $this->definition = $definition;
index f8e19bdad59ee56ab3f386aa0749f267496b51a7..f62d7f02c67a5deeccfb751cec7a90c815727a38 100644 (file)
@@ -80,6 +80,8 @@ final class ArrayFilterEvent extends Event
 
        public const DB_STRUCTURE_DEFINITION = 'friendica.data.db_structure_definition';
 
+       public const DB_VIEW_DEFINITION = 'friendica.data.db_view_definition';
+
        private array $array;
 
        public function __construct(string $name, array $array)
index ca0cb2c160ed5c861109e97dbd96027e730071a8..f496467e54a1984be7409565971595bff8caf3b9 100644 (file)
@@ -60,6 +60,7 @@ class HookEventBridgeTest extends TestCase
                        ArrayFilterEvent::STORAGE_CONFIG                  => 'onArrayFilterEvent',
                        ArrayFilterEvent::STORAGE_INSTANCE                => 'onArrayFilterEvent',
                        ArrayFilterEvent::DB_STRUCTURE_DEFINITION         => 'onArrayFilterEvent',
+                       ArrayFilterEvent::DB_VIEW_DEFINITION              => 'onArrayFilterEvent',
                        HtmlFilterEvent::HEAD                             => 'onHtmlFilterEvent',
                        HtmlFilterEvent::FOOTER                           => 'onHtmlFilterEvent',
                        HtmlFilterEvent::PAGE_HEADER                      => 'onHtmlFilterEvent',
@@ -296,6 +297,7 @@ class HookEventBridgeTest extends TestCase
                        [ArrayFilterEvent::STORAGE_CONFIG, 'storage_config'],
                        [ArrayFilterEvent::STORAGE_INSTANCE, 'storage_instance'],
                        [ArrayFilterEvent::DB_STRUCTURE_DEFINITION, 'dbstructure_definition'],
+                       [ArrayFilterEvent::DB_VIEW_DEFINITION, 'dbview_definition'],
                ];
        }
 
index 67b2e8a5769e414b65def49f97b722d7f663d4c7..e55fa313a66bd6dec7915b5c9e7d63fc535c6c1c 100644 (file)
@@ -57,6 +57,7 @@ class ArrayFilterEventTest extends TestCase
                        [ArrayFilterEvent::STORAGE_CONFIG, 'friendica.data.storage_config'],
                        [ArrayFilterEvent::STORAGE_INSTANCE, 'friendica.data.storage_instance'],
                        [ArrayFilterEvent::DB_STRUCTURE_DEFINITION, 'friendica.data.db_structure_definition'],
+                       [ArrayFilterEvent::DB_VIEW_DEFINITION, 'friendica.data.db_view_definition'],
                ];
        }