Create event for dbstructure_definition hook

This commit is contained in:
Art4 2025-03-14 12:24:02 +00:00
parent 04818781a7
commit 9e3b0b3c40
5 changed files with 15 additions and 3 deletions

View 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',

View 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;

View 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)

View 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'],
];
}

View 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'],
];
}