#!/usr/bin/php 'mysql', 'database_name' => 'gutachten', 'server' => '116.203.228.129', 'username' => 'root', 'password' => 'salam', ]); // NEW DATA $DB_NEW = new Medoo([ 'database_type' => 'mysql', 'database_name' => 'gutachten_t3', 'server' => '127.0.0.1', 'username' => 'root', 'password' => 'Salam0815!', 'charset' => 'utf8', ]); function fixUtf8($string) { return Encoding::toUTF8($string, Encoding::ICONV_TRANSLIT); } $IMPORT = ''; $_jobs = ['', 'all', 'allgemein', 'auftraggeber', 'gutachter', 'download', 'freigabe', 'help', 'orientierung', 'projekte', 'platzhalter', 'basis', 'generell']; foreach ($_jobs as $key => $value) { if (in_array($value, $argv)) { $IMPORT = $value; } } if ('' == $IMPORT or 'This Info' == $IMPORT) { echo "\n\nOPTIONEN"; echo "\n----------------------------------------\n"; foreach ($_jobs as $key => $value) { if ($key > 0) { echo "var: $key\t:\t$value\n"; } } echo "----------------------------------------\n\n"; exit; } echo "\n----------------------------------------\n"; echo 'IMPORT: '.$IMPORT."\n"; echo "----------------------------------------\n\n"; $usermap = []; $usermap['Hermann Telser'] = 1; $usermap['Marie Rezac'] = 2; $usermap['Marie Rezac (Kopie)'] = 2; $usermap['Christoph Aschaber'] = 3; $usermap['Christoph Aschaber (Kopie)'] = 3; $usermap['Claudia'] = 4; $usermap['Claudia (Kopie)'] = 4; $usermap['Elisabeth Mair am Tinkhof'] = 5; $usermap['Elisabeth Mair am Tinkhof (Kopie)'] = 5; $usermap['Hanno Vogl-Fernheim'] = 6; $usermap['Hanno Vogl-Fernheim (Kopie)'] = 6; $usermap['laszlo'] = 7; $usermap['laszlo (Kopie)'] = 7; $usermap['falkner'] = 8; $usermap['Oliver Hosp'] = 9; $usermap['Evelyne Gerber'] = 10; $usermap['Evelyne Gerber (Kopie)'] = 10; /************************************************************ Table von Hand kopiert: tx_gutachten_standards tx_gutachten_textart tx_gutachten_raumart ************************************************************/ // Gutachten Allgemein $table_old = 'tt_allgemein'; $table_new = 'tx_gutachten_allgemein'; if ('all' == $IMPORT or 'allgemein' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['tt_allgemein_id']; $insert_array['timestamp'] = $value['timestamp']; $insert_array['pid'] = $value['pid']; $insert_array['uid'] = $usermap[$value['ersteller']]; $insert_array['geschoss'] = fixUtf8($value['geschoss']); $insert_array['typ'] = fixUtf8($value['typ']); $insert_array['qm'] = $value['qm']; $DB_NEW->insert($table_new, $insert_array); if (0 == $key % 100) { echo '*'; } // debug_new(__line__); } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Auftraggeber $table_old = 'auftraggeber'; $table_new = 'tx_gutachten_auftraggeber'; if ('all' == $IMPORT or 'auftraggeber' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['auftraggeber_id']; $insert_array['kennung'] = fixUtf8($value['kennung']); $insert_array['kopf'] = fixUtf8($value['kopf']); $insert_array['txt'] = fixUtf8($value['txt']); $insert_array['kontaktperson'] = fixUtf8($value['kontaktperson']); $insert_array['email'] = fixUtf8($value['email']); $insert_array['telefon'] = fixUtf8($value['telefon']); $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); echo '*'; } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Download Log $table_old = 'downloadlog'; $table_new = 'tx_gutachten_downloadlog'; if ('all' == $IMPORT or 'download' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['id']; $insert_array['pid'] = $value['pid']; $insert_array['uid'] = $value['user_id']; $insert_array['art'] = fixUtf8($value['art']); $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); if (0 == $key % 100) { echo '*'; } } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Freigaben // $_user_map = []; // $_user_map[2] = 1; // $_user_map[4] = 2; // $_user_map[5] = 2; // $_user_map[6] = 3; // $_user_map[7] = 3; // $_user_map[8] = 2; // $_user_map[9] = 9; // $_user_map[10] = 2; // $_user_map[11] = 2; // $_user_map[13] = 6; // $_user_map[15] = 5; // $_user_map[16] = 10; // // $table_old = 'freigabe'; // $table_new = 'tx_gutachten_freigabe'; // if ('all' == $IMPORT or 'freigabe' == $IMPORT) { // $arr = $DB_OLD->select($table_old, '*'); // debug_old(__LINE__); // $DB_NEW->query("truncate $table_new"); // debug_new(__LINE__); // foreach ($arr as $key => $value) { // $insert_array = []; // $insert_array['id'] = $value['id']; // $insert_array['pid'] = $value['pid']; // $insert_array['uid'] = $_user_map[$value['uid']]; // $insert_array['onoff'] = $value['onoff']; // $insert_array['status'] = $value['status']; // $DB_NEW->insert($table_new, $insert_array); // if (0 == $key % 100) { // echo '*'; // } // } // ++$key; // note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); // } // Freigabe new if ('all' == $IMPORT or 'freigabe' == $IMPORT) { $arr = $DB_OLD->select('freigabe', '*'); debug_old(__LINE__); echo PHP_EOL.PHP_EOL; foreach ($arr as $key => $value) { $DB_NEW->update('tx_gutachten_projekte', ['status' => $value['status']], ['id' => $value['pid']]); // debug_new(__LINE__); if (0 == $key % 100) { echo '*'; } } echo PHP_EOL.PHP_EOL.PHP_EOL; } // Gutachter $table_old = 'gutachter'; $table_new = 'tx_gutachten_gutachter'; if ('all' == $IMPORT or 'gutachter' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['gutachter_id']; $insert_array['kennung'] = fixUtf8($value['kennung']); $insert_array['kopf'] = fixUtf8($value['kopf']); $insert_array['txt'] = fixUtf8($value['txt']); $insert_array['kontaktperson'] = fixUtf8($value['kontaktperson']); $insert_array['email'] = fixUtf8($value['email']); $insert_array['telefon'] = fixUtf8($value['telefon']); $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); // debug_new(__LINE__); echo '*'; } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Help $table_old = 'tt_help'; $table_new = 'tx_gutachten_help'; if ('all' == $IMPORT or 'help' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['tt_help_id']; $insert_array['pid'] = $value['pid']; $insert_array['uid'] = $usermap[$value['ersteller']]; $insert_array['colid'] = $value['colid']; $insert_array['coltitel'] = fixUtf8($value['coltitel']); $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); if (0 == $key % 100) { echo '*'; } } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Table info missing -> obsolet // Orientierung $table_old = 'tt_orientierung'; $table_new = 'tx_gutachten_orientierung'; if ('all' == $IMPORT or 'orientierung' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['tt_orientierung_id']; $insert_array['orientierung'] = fixUtf8($value['orientierung']); $insert_array['sortierung'] = $value['sortierung']; $DB_NEW->insert($table_new, $insert_array); echo '*'; } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Übersicht Projekte $table_old = 'uebersicht'; $table_new = 'tx_gutachten_projekte'; if ('all' == $IMPORT or 'projekte' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['uebersicht_id']; $insert_array['uid'] = $usermap[$value['ersteller']] ?? 0; $insert_array['auftraggeber_id'] = $value['auftraggeber_id']; $insert_array['gutachter_id'] = $value['gutachter_id']; $insert_array['intname'] = fixUtf8($value['intname']); $insert_array['name'] = fixUtf8($value['name']); $insert_array['beschreibung'] = fixUtf8($value['beschreibung']); $insert_array['erstellung'] = fixUtf8($value['erstellung']); $insert_array['erstelldatum'] = fixUtf8($value['erstelldatum']); $insert_array['onoff'] = $value['onoff']; $insert_array['upload'] = $value['upload']; $insert_array['allgemeinupload'] = $value['allgemeinupload']; $insert_array['recalculate'] = $value['recalculate']; $insert_array['zuabTitel'] = fixUtf8($value['zuabTitel']); $insert_array['nwbTitel'] = fixUtf8($value['nwbTitel']); $insert_array['zustTitel'] = fixUtf8($value['zustTitel']); $insert_array['allgemTitel'] = fixUtf8($value['allgemTitel']); $insert_array['loggia_title'] = fixUtf8($value['loggia_title']); $insert_array['nwbStartSeite'] = $value['nwbStartSeite']; $insert_array['m1pP'] = $value['m1pP']; $insert_array['m5pP'] = $value['m5pP']; $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); echo '*'; } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Platzhalter $table_old = 'projekteplatzhalter'; $table_new = 'tx_gutachten_projekteplatzhalter'; if ('all' == $IMPORT or 'platzhalter' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['projekteplatzhalter_id']; $insert_array['pid'] = $value['pid']; $insert_array['uid'] = $usermap[$value['ersteller']] ?? 0; $insert_array['code'] = fixUtf8($value['code']); $insert_array['txt'] = fixUtf8($value['txt']); $insert_array['vorkommen'] = fixUtf8($value['vorkommen']); $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); if (0 == $key % 100) { echo '*'; } } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Standards $table_old = 'projektestandards'; $table_new = 'tx_gutachten_projektestandards'; if ('all' == $IMPORT or 'platzhalter' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['projektestandards_id']; $insert_array['pid'] = $value['pid']; $insert_array['pos'] = $value['pos']; $insert_array['uid'] = $usermap[$value['ersteller']] ?? 0; $insert_array['textart_id'] = $value['textart_id']; $insert_array['spalten'] = $value['spalten']; $insert_array['fontsize'] = $value['fontsize']; $insert_array['neueseite'] = $value['neueseite']; $insert_array['kennung'] = fixUtf8($value['kennung']); $insert_array['titel'] = fixUtf8($value['titel']); $insert_array['txt'] = fixUtf8($value['txt']); $insert_array['platzhalter'] = fixUtf8($value['platzhalter']); $insert_array['checksumm'] = $value['checksumm']; $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); if (0 == $key % 100) { echo '*'; } } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Räume All $table_old = 'tt_raume_all'; $table_new = 'tx_gutachten_raume_all'; if ('all' == $IMPORT or 'alle' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['tt_raume_all_id']; $insert_array['tt_raume_basis_id'] = $value['tt_raume_basis_id']; $insert_array['tt_raumart_id'] = $value['tt_raumart_id']; $insert_array['pid'] = $value['pid']; $insert_array['geschoss'] = fixUtf8($value['geschoss']); $insert_array['raum'] = fixUtf8($value['raum']); $insert_array['factor'] = $value['factor']; $insert_array['qm'] = $value['qm']; $insert_array['NW'] = $value['NW']; $insert_array['NWungerundet'] = $value['NWungerundet']; $insert_array['NWm2'] = $value['NWm2']; $insert_array['uid'] = $usermap[$value['ersteller']] ?? 0; $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); if (0 == $key % 1000) { echo '*'; } } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Räume Basis $table_old = 'tt_raume_basis'; $table_new = 'tx_gutachten_raume_basis'; if ('all' == $IMPORT or 'basis' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['tt_raume_basis_id']; $insert_array['pid'] = $value['pid']; $insert_array['topNr'] = fixUtf8($value['topNr']); $insert_array['typ'] = fixUtf8($value['typ']); $insert_array['tt_orientierung_id'] = $value['tt_orientierung_id']; $insert_array['noDispInOrientierung'] = $value['noDispInOrientierung']; $insert_array['factor'] = $value['factor']; $insert_array['GNO'] = $value['GNO']; $insert_array['qmM1'] = $value['qmM1']; $insert_array['qmM1uM2bis'] = $value['qmM1uM2bis']; $insert_array['qmM1uM2'] = $value['qmM1uM2']; $insert_array['NWM1uM2'] = $value['NWM1uM2']; $insert_array['a'] = $value['a']; $insert_array['b'] = $value['b']; $insert_array['c'] = $value['c']; $insert_array['d'] = $value['d']; $insert_array['e'] = $value['e']; $insert_array['f'] = $value['f']; $insert_array['g'] = $value['g']; $insert_array['h'] = $value['h']; $insert_array['i'] = $value['i']; $insert_array['j'] = $value['j']; $insert_array['k'] = $value['k']; $insert_array['l'] = $value['l']; $insert_array['m'] = $value['m']; $insert_array['n'] = $value['n']; $insert_array['o'] = $value['o']; $insert_array['p'] = $value['p']; $insert_array['q'] = $value['q']; $insert_array['r'] = $value['r']; $insert_array['s'] = $value['s']; $insert_array['t'] = $value['t']; $insert_array['u'] = $value['u']; $insert_array['summe_az'] = $value['summe_az']; $insert_array['bewertung'] = $value['bewertung']; $insert_array['uid'] = $usermap[$value['ersteller']] ?? 0; $insert_array['notizen'] = fixUtf8($value['notizen']); $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); if (0 == $key % 100) { echo '*'; } } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Platzhalter $table_old = 'tt_raume_generell'; $table_new = 'tx_gutachten_raume_generell'; if ('all' == $IMPORT or 'generell' == $IMPORT) { $arr = $DB_OLD->select($table_old, '*'); debug_old(__LINE__); $DB_NEW->query("truncate $table_new"); debug_new(__LINE__); foreach ($arr as $key => $value) { $insert_array = []; $insert_array['id'] = $value['tt_raume_generell_id']; $insert_array['tt_raumart_id'] = $value['tt_raumart_id']; $insert_array['pid'] = $value['pid']; $insert_array['raum'] = fixUtf8($value['raum']); $insert_array['factor'] = $value['factor']; $insert_array['zunutzwert'] = $value['zunutzwert']; $insert_array['uid'] = $usermap[$value['ersteller']] ?? 0; $insert_array['timestamp'] = $value['timestamp']; $DB_NEW->insert($table_new, $insert_array); if (0 == $key % 100) { echo '*'; } } ++$key; note("IMPORT from $table_old INTO $table_new".PHP_EOL."$key Rows"); } // Functions function note($txt) { echo PHP_EOL.'---------------------------------------------------------------------'.PHP_EOL; echo $txt; echo PHP_EOL.'---------------------------------------------------------------------'.PHP_EOL; } function debug_old($line) { global $DB_OLD; echo PHP_EOL.$line.': '.str_replace('"', '', $DB_OLD->last()); } function debug_new($line) { global $DB_NEW; echo PHP_EOL.$line.': '.str_replace('"', '', $DB_NEW->last()).PHP_EOL; }