Hallo, Gast! (Registrieren)

Letzte Ankündigung: MyBB 1.8.37 veröffentlicht (04.11.23)


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste
2 Foren zusammenfügen mit URL-Erhaltung
#1
Hallo,

ich möchte gerne Forum2 in Forum1 hineinmergen. Beide sind MyBB. Beide haben verschiedene URLs. Soweit würde das problemlos mit dem Merge-System funktionieren.

Nun möchte ich aber, dass externe Links auf Forum2 erhalten bleiben. Dazu will ich die Domain von Forum2 beibehalten und z.B. Aufrufe von forum2.de/viewpost.php?id=42 auf den entsprechend gemergten Beitrag auf forum1.de als Permanent Redirect weiterleiten.

Die Idee dabei war die Primärschlüssel von allem aus Forum2 um z.B. 100000 zu erhöhen, und bei der Weiterleitung dann einfach die ID dementsprechend erhöht an Forum1 weiterzuleiten. Nun möchte ich aber schon das Merge-System verwenden um nicht alles manuell und höchstwahrscheinlich fehlerbehaftet händisch zu machen.

Wie kann ich sowas am besten mit dem Merge-System umsetzen?

Danke im Voraus!
Zitieren
#2
Es gibt einen Ansatz:
Das Merge-System speichert während des Imports die alten Ids (z.B. import_tid). Diese werden zwar normalerweise am Ende gelöscht (resources/functions.php), aber dies lässt sich leicht ändern:
PHP-Code:
    $drop_list = array(
        
"users" => array('import_uid''import_usergroup''import_additionalgroups''import_displaygroup'),
        
"forums" => array('import_fid''import_pid'),
        
"threads" => array('import_tid''import_uid''import_poll''import_firstpost'),
        
"posts" => array('import_pid''import_uid'),
        
"polls" => array('import_pid''import_tid'),
        
"usergroups" => array('import_gid'),
        
"attachments" => array('import_aid'),
    ); 
Mit diesen alten Ids sind mit einem kleinen Script entsprechende Weiterleitungen möglich.
[Bild: banner.png]

Bitte die Foren-Regeln beachten und im Profil die verwendete MyBB-Version angeben.
Zitieren
#3
Das hat wunderbar funktioniert, danke!

Für's Archiv die von mir angepasste delete_import_fields() in functions.php, welche mir für jede tabelle eine textdatei mit assoziationen "neu:alt" im merge/ ordner unter dem namen "tabelle_id_changes.txt" anlegt
PHP-Code:
function delete_import_fields($text=true)
{
    global 
$db$output$lang;

    if(
$text == true)
    {
        
$output->construct_progress_bar();
    }

    if(
$text == true)
    {
        
$output->update_progress_bar(0$lang->sprintf($lang->removing_tableTABLE_PREFIX."trackers"));
    }
    
$db->drop_table("trackers");

    
$drop_list = array(
        
"users" => array('import_uid''import_usergroup''import_additionalgroups''import_displaygroup'),
        
"forums" => array('import_fid''import_pid'),
        
"threads" => array('import_tid''import_uid''import_poll''import_firstpost'),
        
"posts" => array('import_pid''import_uid'),
        
"polls" => array('import_pid''import_tid'),
        
"usergroups" => array('import_gid'),
        
"attachments" => array('import_aid'),
    );

    
$increment 200/(count($drop_listCOUNT_RECURSIVE)-count($drop_list));
    
$progress 0;
    
$data = [];
    foreach(
$drop_list as $table => $columns)
    {
        
        
$data[$table] = [];
        
        
$columns_list implode(', '$columns);
        
$columns2 = [explode("_"$columns[0])[1], $columns[0]];
        
        if(
$db->field_exists($columns2[1], $table)) {
            
$query $db->simple_select($tableimplode(', '$columns2), $columns[0]." != 0");
            while(
$stuff $db->fetch_array($query)) {
                
$data[$table] .= $stuff[$columns2[1]].':'.$stuff[$columns2[0]]."\n";
            }
        }
        
        
$comma "";
        
$columns_sql "";
        foreach(
$columns as $column)
        {
            if(
$db->field_exists($column$table))
            {
                
$columns_sql .= "{$comma} DROP ".$column;
                
$comma ",";
            }
        }

        if(
$text == true)
        {
            
$output->update_progress_bar($progress$lang->sprintf($lang->removing_columns$columns_listTABLE_PREFIX.$table));
            
$progress += $increment;
        }

        
$db->write_query("ALTER TABLE ".TABLE_PREFIX.$table."{$columns_sql}");
    }

    foreach (
$data as $t => $s) {
        
file_put_contents($t."_id_changes.txt"$s);
    }
    
    
$db->delete_query("datacache""title='import_cache'");

Zitieren