public static function install($data, &$fail, &$errno, &$error) { $serverFiles = Installation::GibServerDateien(); $installComponentDefsResult['components'] = array(); foreach ($serverFiles as $sf) { $sf = pathinfo($sf)['filename']; $tempData = Einstellungen::ladeEinstellungenDirekt($sf, $data); if ($tempData === null) { $fail = true; $error = Language::Get('generateComponents', 'noAccess'); return; } $componentList = Zugang::Ermitteln('actionInstallComponentDefs', 'KomponentenErstellen::installiereKomponentenDefinitionen', $tempData, $fail, $errno, $error); if (isset($componentList['components'])) { $installComponentDefsResult['components'] = array_merge($installComponentDefsResult['components'], $componentList['components']); } } // Komponenten erzeugen $comList = array(); $setDBNames = array(); $ComponentList = array(); // zunächst die Komponentenliste nach Namen sortieren $ComponentListInput = array(); foreach ($installComponentDefsResult['components'] as $key => $input) { if (!isset($input['name'])) { continue; } if (!isset($ComponentListInput[$input['name']])) { $ComponentListInput[$input['name']] = array(); } $ComponentListInput[$input['name']][$key] = $input; } for ($zz = 0; $zz < 2; $zz++) { $tempList = array(); foreach ($ComponentListInput as $key2 => $ComNames) { foreach ($ComNames as $key => $input) { if (!isset($input['name'])) { continue; } if (!isset($input['type']) || $input['type'] == 'normal') { // normale Komponente if (!isset($input['registered'])) { $comList[] = "('{$input['name']}', '{$input['urlExtern']}/{$input['path']}', '" . (isset($input['option']) ? $input['option'] : '') . "', '" . implode(';', isset($input['def']) ? $input['def'] : array()) . "')"; // Verknüpfungen erstellen $setDBNames[] = " SET @{$key}_{$input['name']} = (select CO_id from Component where CO_address='{$input['urlExtern']}/{$input['path']}' limit 1); "; $input['dbName'] = $key . '_' . $input['name']; $input['registered'] = '1'; } if (!isset($tempList[$key2])) { $tempList[$key2] = array(); } $tempList[$key2][] = $input; } elseif (isset($input['type']) && $input['type'] == 'clone') { // Komponente basiert auf einer bestehenden if (!isset($input['base'])) { continue; } if (!isset($input['baseURI'])) { $input['baseURI'] = ''; } if (isset($ComponentListInput[$input['base']])) { foreach ($ComponentListInput[$input['base']] as $key3 => $input2) { if (!isset($input2['name'])) { continue; } // pruefe, dass die Eintraege nicht doppelt erstellt werden $found = false; if (isset($ComponentListInput[$input['name']])) { foreach ($ComponentListInput[$input['name']] as $input3) { if ((!isset($input3['type']) || $input3['type'] == 'normal') && $input['name'] == $input3['name'] && "{$input3['urlExtern']}/{$input3['path']}" == "{$input2['urlExtern']}/{$input2['path']}{$input['baseURI']}") { $found = true; break; } } } if ($found) { continue; } if (isset($tempList[$input['name']])) { foreach ($tempList[$input['name']] as $input3) { if ($input['name'] == $input3['name'] && "{$input3['urlExtern']}/{$input3['path']}" == "{$input2['urlExtern']}/{$input2['path']}{$input['baseURI']}") { $found = true; break; } } } if ($found) { continue; } $input2['path'] = "{$input2['path']}{$input['baseURI']}"; $input2['def'] = array_merge($input2['def'], $input['def']); $input2['links'] = array_merge(isset($input2['links']) ? $input2['links'] : array(), isset($input['links']) ? $input['links'] : array()); $input2['connector'] = array_merge(isset($input2['connector']) ? $input2['connector'] : array(), isset($input['connector']) ? $input['connector'] : array()); if (isset($input['option'])) { $input2['option'] = $input['option']; } $input2['name'] = $input['name']; $input2['registered'] = null; if (!isset($tempList[$key2])) { $tempList[$key2] = array(); } $tempList[$key2][] = $input2; } } } } } $ComponentListInput = $tempList; } $sql = "START TRANSACTION;SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;TRUNCATE TABLE `ComponentLinkage`;SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;COMMIT;"; //TRUNCATE TABLE `Component`; DBRequest::request2($sql, false, $data, true); $sql = "UPDATE `Component` SET `CO_status` = '0';"; DBRequest::request2($sql, false, $data, true); $sql = "START TRANSACTION;SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;INSERT INTO `Component` (`CO_name`, `CO_address`, `CO_option`, `CO_def`) VALUES "; $installComponentDefsResult['componentsCount'] = count($comList); $sql .= implode(',', $comList); unset($comList); $sql .= " ON DUPLICATE KEY UPDATE CO_status='1', CO_address=VALUES(CO_address), CO_option=VALUES(CO_option), CO_def=VALUES(CO_def);SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;COMMIT;"; //echo $sql; DBRequest::request2($sql, false, $data, true); //echo $sql; $sql = "START TRANSACTION;SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;"; $sql .= implode('', $setDBNames); unset($setDBNames); $links = array(); foreach ($ComponentListInput as $key2 => $ComNames) { foreach ($ComNames as $key => $input) { if (isset($input['type']) && $input['type'] != 'normal') { continue; } if (isset($input['dbName'])) { // prüfe nun alle Verknüpfungen dieser Komponente und erstelle diese if (isset($input['links'])) { foreach ($input['links'] as $link) { if (!isset($link['target'])) { $link['target'] = ''; } if (!is_array($link['target'])) { $link['target'] = array($link['target']); } foreach ($link['target'] as $tar) { // $tar -> der Name der Zielkomponente if (!isset($ComponentListInput[$tar])) { continue; } foreach ($ComponentListInput[$tar] as $target) { // $target -> das Objekt der Zielkomponente if (!isset($target['dbName'])) { continue; } if (!isset($input['link_type']) || $input['link_type'] == 'local' || $input['link_type'] == '') { if ($input['urlExtern'] == $target['urlExtern']) { $priority = isset($input['priority']) ? ", CL_priority = {$input['priority']}" : ''; $relevanz = isset($input['relevanz']) ? $input['relevanz'] : ''; $sql .= " INSERT INTO `ComponentLinkage` SET CO_id_owner = @{$input['dbName']}, CL_name = '{$link['name']}', CL_relevanz = '{$relevanz}', CO_id_target = @{$target['dbName']} {$priority};"; $links[] = 1; } } elseif ($input['link_type'] == 'full') { if ($input['urlExtern'] == $target['urlExtern'] || isset($target['link_availability']) && $target['link_availability'] == 'full') { $priority = isset($input['priority']) ? ", CL_priority = {$input['priority']}" : ''; $relevanz = isset($input['relevanz']) ? $input['relevanz'] : ''; $sql .= " INSERT INTO `ComponentLinkage` SET CO_id_owner = @{$input['dbName']}, CL_name = '{$link['name']}', CL_relevanz = '{$relevanz}', CO_id_target = @{$target['dbName']} {$priority};"; $links[] = 1; } } } } } } if (isset($input['connector'])) { foreach ($input['connector'] as $link) { if (!isset($link['target'])) { $link['target'] = ''; } if (!is_array($link['target'])) { $link['target'] = array($link['target']); } if (!isset($link['links'])) { $link['links'] = array('a' => null); } foreach ($link['links'] as $callKey => $call) { foreach ($link['target'] as $tar) { // $tar -> der Name der Zielkomponente if (!isset($ComponentListInput[$tar])) { continue; } foreach ($ComponentListInput[$tar] as $target) { // $target -> das Objekt der Zielkomponente if (!isset($target['dbName'])) { continue; } if (!isset($input['link_type']) || $input['link_type'] == 'local' || $input['link_type'] == '') { if ($input['urlExtern'] == $target['urlExtern']) { $priority = isset($link['priority']) ? ", CL_priority = {$link['priority']}" : ''; $method = isset($call['method']) ? $call['method'] : 'GET'; $path = isset($call['path']) ? ", CL_path = '{$method} {$call['path']}'" : ''; $relevanz = isset($link['relevanz']) ? $link['relevanz'] : ''; $sql .= " INSERT INTO `ComponentLinkage` SET CO_id_owner = @{$target['dbName']}, CL_name = '{$link['name']}', CL_relevanz = '{$relevanz}', CO_id_target = @{$input['dbName']} {$priority} {$path};"; $links[] = 1; } } elseif ($input['link_type'] == 'full') { if ($input['urlExtern'] == $target['urlExtern'] || isset($input['link_availability']) && $input['link_availability'] == 'full') { $priority = isset($link['priority']) ? ", CL_priority = {$link['priority']}" : ''; $method = isset($call['method']) ? $call['method'] : 'GET'; $path = isset($call['path']) ? ", CL_path = '{$method} {$call['path']}'" : ''; $relevanz = isset($link['relevanz']) ? $link['relevanz'] : ''; $sql .= " INSERT INTO `ComponentLinkage` SET CO_id_owner = @{$target['dbName']}, CL_name = '{$link['name']}', CL_relevanz = '{$relevanz}', CO_id_target = @{$input['dbName']} {$priority} {$path};"; $links[] = 1; } } } } } } } } } } $installComponentDefsResult['linksCount'] = count($links); $sql .= " SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;COMMIT;"; DBRequest::request2($sql, false, $data, true); $installComponentDefsResult['components'] = $ComponentListInput; return $installComponentDefsResult; }