Created tijdstip van users synchroniseren met content
Merk op dat ik de tips vooral post bij wijze van backup voor mezelf :-)
Al is het natuurlijk leuk om te horen als iemand er iets moest aan hebben!
We zaten met het probleem dat we users en content geïmporteerd hadden, en de user accounts waren nieuwer dan de content. Dus de 'Lid sinds X jaar, Y weken' vermelding op de profielpagina vermeldde dat de gebruiker deze week was aangemaakt, terwijl sommigen al jaren op de site zaten.
Dit kwam doordat het oude systeem deze informatie niet opsloeg in de tabellen -- er was geen kolom waaruit we dit konden kopiëren.
De volgende PHP code lost dit op in Drupal, door op zoek te gaan naar het tijdstip van de allereerste comment of node van de users. Als die timestamp recenter is dan de user, dan wordt de 'created' kolom van die user aangepast.
Enkel nuttig dus voor zij die oude content importeren in Drupal.
Update aanmeldingsdatum
(PHP code wordt uitgevoerd...)
<?php
// run a query to fetch userid, created timestamp, and first comment timestamp
$timestamps = db_query("SELECT {users}.uid, {users}.created, {users}.name, MIN({comments}.timestamp) AS first_comment_timestamp FROM {users} LEFT JOIN {comments} ON {users}.uid = {comments}.uid WHERE {users}.uid > 0 GROUP BY {users}.uid ORDER BY first_comment_timestamp DESC;");
while ($t = db_fetch_object($timestamps))
{
// update the created timestamp for users
// where created timestamp is older than their
// first comment timestamp
if($t->first_comment_timestamp && $t->first_comment_timestamp < $t->created)
{
// check for presence of first comment timestamp separately
// because not all users will have a comment
echo 'Updating created timestamp for user (from comment): ' . $t->name . '.
';
db_query("UPDATE {users} SET created = %d WHERE uid = %d;", $t->first_comment_timestamp, $t->uid);
}
}
// do exact same thing, but now with node timestamp instead of comment timestamp
$timestamps = db_query("SELECT {users}.uid, {users}.created, {users}.name, MIN({node}.created) AS first_node_timestamp FROM {users} LEFT JOIN {node} ON {users}.uid = {node}.uid WHERE {users}.uid > 0 GROUP BY {users}.uid ORDER BY first_node_timestamp DESC;");
while ($t = db_fetch_object($timestamps))
{
// update the created timestamp for users
// where created timestamp is older than their
// first comment timestamp
if($t->first_node_timestamp && $t->first_node_timestamp < $t->created)
{
// check for presence of first comment timestamp separately
// because not all users will have a comment
echo 'Updating created timestamp for user (from node): ' . $t->name . '.
';
db_query("UPDATE {users} SET created = %d WHERE uid = %d;", $t->first_node_timestamp, $t->uid);
}
}
?>
Merk op dat beide SQL SELECT queries zeer lang duren; ik vermoed dat ze nog zwaar geoptimaliseerd kunnen worden.
Actuele inhoud
12 feb 2012
- , Tekst bij foto's , (Forumonderwerp) , Harrie
- , Kleuren , (Forumonderwerp) , Harrie
- , Er worden escape characters toegevoegd , (Forumonderwerp) , baltusf
- , Rekenhulp maken , (Forumonderwerp) , ebosch
- , Edit tabs invoegen in template , (Forumonderwerp) , Mindhunter
11 feb 2012
- , Artikel alleen lezen voor geregistreerden , (Forumonderwerp) , Hilde Jansen
10 feb 2012
- , Nieuwe module toevoegen , (Forumonderwerp) , snake , Reacties: 1
09 feb 2012
- , CKeditor zelf HTML en CSS toepassen in de code view , (Forumonderwerp) , DGNY
- , Parse error: syntax error , (Forumonderwerp) , ballooning4u , Reacties: 1
- , Views, inhoud van een cell , (Forumonderwerp) , LLMM
- , Webform Rules anoniem , (Forumonderwerp) , Juzzuu , Reacties: 1
- , Database moeten in stukken, hoe moet ik dit voor elkaar krijgen? , (Forumonderwerp) , GioV , Reacties: 7
- , youtube film in website , (Forumonderwerp) , annemie , Reacties: 4
- , userpoints vraagje , (Forumonderwerp) , jeroenenwendy
08 feb 2012
- , Vacature Webdeveloper , (Forumonderwerp) , JoHo Processen ...
florisla
30 maart, 2008 - 19:25
Permalink
htmlspecialchars() vergeten
Voor de volledigheid: bij het echo'en van
$t->namewas ik functie htmlspecialchars() vergeten.