PDA

View Full Version : Explanation of the touserarray in table PMTEXT


FredrikSE
08-03-2008, 09:04 AM
Hi!

I am currently working on several scripts that later on will migrate my current forum to vBulletin 3.7. So far I'm doing alright. Most of the information such as users, threads and posts are importing correctly into vBulletin which is good news. Now I'm trying to work out a script that will migrate all the PM's from my custom forum database.

The tables that the PM function is made up of is pm, pmtext, pmreceipt, in the vBulletin database. It's easy to understand what the information is doing in in most of tables. There is on field though, called touserarray, in table pmtext, that I need som help to parse, exactly what elements it's made up of!

touserarray:
a:1:{s:2:"cc";a:1:{i:10;s:5:"LeonL";}}

The user element is easy do decode from the string. But how about the rest?

Regards,

Fredrik

Marco van Herwaarden
08-03-2008, 09:43 AM
You can use explode() on that string and it will return an array with all the values.

PS Why not use the DataManagers, would make things a lot easier and you do not need to know which tables store which information.

PPS To write an importer, you could use ImpEx as an example and write a new module based on existing ones.

FredrikSE
08-03-2008, 10:53 AM
Thanks for you reply!

I assume the DataManager can be used when the forum from which you are importing is well known and supported by vBulletin, right?

In my case I'm importing from my very own custom forum and I feel ImpEx won't do the job for me. I gave it a try but I soon realized that it was not going to handle all my information the way I wanted.

This leaves me with the option to hard code scripts myself for the various categories I want to migrate. So far everything is working out very good.

One of the last thing is to get the PM's in place. You say I can use explode() on that string. It would be very helpful if you could give me a code example.

Marco van Herwaarden
08-03-2008, 11:06 AM
DataManagers are used to manipulate the data in the vBulletin database. They have no connection with the system you are using to get the data. They are basically an API that will provide an interface to edit/insert/delete data without having to access the tables directly. You can find more information in our Articles section.

Sorry made a typo in my previous post, you should be using unserialize() on the string to get an array.

Example:
<?php
$string = 'a:1:{s:2:"cc";a:1:{i:10;s:5:"LeonL";}}';
$array = unserialize($string);
echo "<br />Var string: " . $string;
echo "<br />Array array: <pre>";print_r($array);echo "</pre>";
?>
Would result in:
Var string: a:1:{s:2:"cc";a:1:{i:10;s:5:"LeonL";}}
Array array:
Array( [cc] => Array ( [10] => LeonL ))

FredrikSE
08-03-2008, 05:21 PM
When you say DataManagers I assume you refer to functions and classes within the various php-files that vBulletin is made up of? First you have to be some what of a detective and look those up in a specific file I guess?

Thanks for your example. The only information of value really that comes out of the array when you run unserialize is the userID and username. Do you now what those other numbers are for in that string?

I sent three test PM from my admin account to the three users to see how/if the touserarray values other than userID/username changes.

This is the result taken from the database:

a:1:{s:2:"cc";a:1:{i:185;s:4:"Adam";}}
a:1:{s:2:"cc";a:1:{i:245;s:10:"cjsundberg";}}
a:1:{s:2:"cc";a:1:{i:309;s:6:"19-555";}}

The only value that changes is the value before the username. In the first string it's 4, then 10 and finally 6. Do you know what that value is for? When I run unserialize it doesn't show up!

I need to know this when I import so that I can anticipate the correct value.

nexialys
08-03-2008, 05:31 PM
You can use explode() on that string and it will return an array with all the values.

Hum, sorry to interveine, but it's a serialized entry... unserialize() is needed!

Opserty
08-03-2008, 09:39 PM
Hum, sorry to interveine, but it's a serialized entry... unserialize() is needed!
2nd paragraph of post #4 my dear. :D

Marco van Herwaarden
08-04-2008, 07:24 AM
Thanks for your example. The only information of value really that comes out of the array when you run unserialize is the userID and username. Do you now what those other numbers are for in that string?

I sent three test PM from my admin account to the three users to see how/if the touserarray values other than userID/username changes.

This is the result taken from the database:

a:1:{s:2:"cc";a:1:{i:185;s:4:"Adam";}}
a:1:{s:2:"cc";a:1:{i:245;s:10:"cjsundberg";}}
a:1:{s:2:"cc";a:1:{i:309;s:6:"19-555";}}

The only value that changes is the value before the username. In the first string it's 4, then 10 and finally 6. Do you know what that value is for? When I run unserialize it doesn't show up!

I need to know this when I import so that I can anticipate the correct value.
There is no real need to know what the numbers in that string mean. You should just populate an array, and then use $string = serialize($array) to get this string.

But if you want to know: ;)

a:1:{s:2:"cc";a:1:{i:185;s:4:"Adam";}}

a:1:{..} - Array with 1 entry
s:2:"cc"; - String, 2 positions, value "cc"
a:1:{....} - Array with 1 entry
i:185; - Integer, value 185 (probably userid on this example)
s:4:"Adam"; - String, 4 positions, value "Adam"

FredrikSE
08-04-2008, 07:39 PM
So it wasn't more complicated than that after all?! :) The way you describe it, it seems like a straight forward process to populate the array and the store the whole PM-post into the database.

Thanks for your explanation. This means I will have a good night sleep not having to think about this array! ;)

FredrikSE
08-05-2008, 08:55 PM
How would I populate this array?

Like this before I serialize it?!

$touserarray = array("185", "Adam");

Dismounted
08-06-2008, 05:58 AM
You create an array like you normally would, then use serialize().

FredrikSE
08-06-2008, 07:10 PM
After I've serialized my string with this code:

$touserarray = array($array['toID'], $array['toID']);
$touserarray = serialize($touserarray);

The resul is thist:

a:2:{i:0;s:2:"16";i:1;s:2:"16";}

It's no way near the way the strings look like in the database.

What am I doing wrong?

MoT3rror
08-07-2008, 01:19 AM
array(
'cc',
array(
$userid,
$username
)
);

FredrikSE
08-07-2008, 06:43 PM
It still doesn't look quite right:

a:2:{i:0;s:2:"cc";i:1;a:2:{i:0;s:2:"16";i:1;s:12:"John-Fredrik";}}

The string seems to be too long after it has been serialized...

Opserty
08-07-2008, 08:31 PM
$touserarray = array(
'cc' => array
(
$userid => $username
)
);


Or... why don't you just get a string from the database, run unserialize(); on it and then use var_dump(); if you follow the formatting that is outputted it shows some indication of the structure of the array.