dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxDDServerBindings.class.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5namespace dbx\dbxAdmin;
6
11{
12 public function run(): string
13 {
14 dbx()->get_include_obj('dbxInstallationService', 'dbxSetup');
15 $installerClass = '\\dbx\\dbxSetup\\dbxInstallationService';
17 $catalog = $installer->discoverDDs();
18 $db = dbx()->get_system_obj('dbxDB');
19 $config = dbx()->get_config('dbx');
20 $bindings = is_array($config['dd_server_bindings'] ?? null)
21 ? $config['dd_server_bindings']
22 : array();
23
24 $serverOptions = array();
25 foreach ((array)($config['db'] ?? array()) as $name => $serverConfig) {
26 if (is_array($serverConfig)
27 && $db->db_server_config_is_active((string)$name, $serverConfig)
28 ) {
29 $type = strtoupper((string)($serverConfig['type'] ?? 'DB'));
30 $serverOptions[(string)$name] = (string)$name . ' · ' . $type;
31 }
32 }
33
34 $form = dbx()->get_system_obj('dbxForm');
35 $form->init('admin-dd-server-bindings', 'dd-server-bindings');
36 $form->_fd = 'dbxAdmin|dd-server-bindings';
37 $form->load_fd_messages();
38 $form->_action = '?dbx_modul=dbxAdmin&dbx_run1=dd_bindings&dbx_page=admin';
39 $form->_msg_info = $form->get_fd_message('intro');
40 $form->_data = array_merge($form->_data, array('binding_save' => 1));
41 $form->add_fld('binding_save', 'dbx|hidden', rules: 'int', dd: '');
42
43 $fields = array();
44 $allowedValues = array();
45 foreach ($catalog as $record) {
46 $ddRef = (string)$record['dd'];
47 $info = $db->get_dd_server_binding_info($ddRef);
48 $declared = (string)($info['declared_server'] ?? '');
49 $field = 'binding_' . substr(hash('sha256', $ddRef), 0, 16);
50 $fields[$field] = $ddRef;
51
52 $options = array(
53 '__default__' => $form->format_fd_message(
54 'dd_default',
55 array('server' => $declared)
56 ),
57 ) + $serverOptions;
58 if ($declared !== '' && !isset($options[$declared])) {
59 $options[$declared] = $declared . ' · DB3/DD';
60 }
61 $current = (string)($bindings[$ddRef] ?? '__default__');
62 if ($current !== '__default__' && !isset($options[$current])) {
63 $options[$current] = $current . ' · ' . $form->get_fd_message('custom_binding');
64 }
65 $allowedValues[$field] = array_fill_keys(array_keys($options), true);
66
67 $form->_data[$field] = $current;
68 $form->add_fld(
69 $field,
70 'select-single-label',
71 label: $ddRef,
72 rules: 'parameter',
73 options: $options,
74 tooltip: $form->format_fd_message(
75 'binding_tooltip',
76 array(
77 'table' => (string)$db->get_dd_table($ddRef),
78 'server' => $declared,
79 )
80 ),
81 dd: ''
82 );
83 }
84
85 if ($form->submit() && !$form->errors()) {
86 $newBindings = array();
87 foreach ($fields as $field => $ddRef) {
88 $value = trim((string)$form->get_post_data(
89 $field,
90 '__default__',
91 'parameter'
92 ));
93 if ($value === '__default__') {
94 continue;
95 }
96 if (!isset($allowedValues[$field][$value])) {
97 $form->add_fld_error(
98 $field,
99 $form->get_fd_message('binding_invalid')
100 );
101 continue;
102 }
103 $newBindings[$ddRef] = $value;
104 }
105 ksort($newBindings);
106
107 if (!$form->errors()) {
109 'dbx',
110 'dd_server_bindings',
111 $newBindings
112 )) {
113 $form->set_error($form->get_fd_message('save_error'));
114 } else {
115 $form->_msg_success = $form->format_fd_message(
116 'save_success_count',
117 array('count' => count($newBindings))
118 );
119 $bindings = $newBindings;
120 }
121 }
122 }
123
124 foreach (array(
125 'bar_title' => $form->get_fd_message('bar_title'),
126 'bar_subtitle' => $form->get_fd_message('bar_subtitle'),
127 'bar_icon' => 'bi-database-gear',
128 'bar_actions' => '',
129 'bar_class' => 'dbx-module-bar',
130 'bar_title_class' => 'dbx-module-bar-titleblock',
131 'bar_title_pre' => '',
132 'bar_title_heading_attrs' => '',
133 'bar_middle' => '',
134 'bar_extra' => '',
135 'bar_actions_class' => 'dbx-module-bar-actions',
136 ) as $name => $value) {
137 $form->add_rep($name, $value);
138 }
139 $form->add_rep('save_label', $form->get_fd_message('save_label'));
140 $form->add_rep('binding_count', (string)count($bindings));
141 $form->add_rep(
142 'binding_count_label',
143 $form->get_fd_message('binding_count_label')
144 );
145 $form->add_rep('dd_count', (string)count($catalog));
146 $form->add_rep('dd_count_label', $form->get_fd_message('dd_count_label'));
147
148 return $form->run();
149 }
150}
dbxForm-Oberflaeche fuer installationsbezogene Serverbindungen pro DD.
if($failed !==array()) $installer
set_local_config_section(string $modul, string $section, array $value)
Ersetzt genau einen lokalen Konfigurationsbereich.
Definition dbxApi.php:896
if($resolved !==$expectedBase . 'files/test/') $config
DBX schema administration.