I´m trying to export my Kunena forum posts to import them into our new wp forum server. For this I´ve created 2 files… One which contains the messages in the following format:
(`id`, `parent`, `thread`, `catid`, `name`, `userid`, `email`, `subject`, `time`, `ip`, `topic_emoticon`, `locked`, `hold`, `ordering`, `hits`, `moved`, `modified_by`, `modified_time`, `modified_reason`)
The other contains the text for the message:
(`mesid`, `message`)
From the first file I only need the “fields” id, parent, time, userid, subject and hits.
From the second i need the corresponding “field” message
Afterwards it should be formatted like this:
(`id`, `message`, `parent`, `time`, `userid`, `subject`, `hits`)
Since there are hundreds of posts and the copy & paste thing is really time consuming i thought it would be a lot easier to do this via a script… Preferably by PowerShell…
Hope you guys can help me out…
$outputFile = "C:logFile.txt"
$path = "C:kunena_messages.txt"
$path2 = "C:kunena_messages_text.txt"
get-content $path | % {$array = $_ -split ",","0"
$message = get-content $path2 | %{If($_ -match ($array[0].Trim() -replace "(","" )){
$msgArray = $_ -split ",","0"
$msgArray[1] -replace ")",""}}
$newString = $array[0].Trim()+","+$message +","+$array[1].Trim()+","+`
$array[8].Trim()+","+$array[5].Trim()+","+$array[7].Trim()+","+`
$array[14].Trim()+")"
$newString | ac $outputFile
}
You could try something like this to get the information you require:
This will give the following output in the given file (
$outputFile
).As you can see I have picked out all the parts you required apart from the message; as I’m not sure how you are linking the two. All you will need to do is use a similar method to get the correct message and put it into the variable
$message
.Going on the assumption that your ID and MesID are the same you can use something like this for the
$message
varible:$path2
being the path to your message file.So all together it should look like this: