Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbPress to Activity import


  • Sergio De Falco
    Participant

    @sgr33n

    Hi people,

    Does exist a script that import all bbPress into activity because I don’t know how the importer just imported a few activities into my stream.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

  • Paul Wong-Gibbs
    Keymaster

    @djpaul

    It sounds like you’ve run the importer that comes with bbPress 2. If BuddyPress and Activity were set up and working prior to you running that data import/migration, I would expect the Activity stream to be populated. If this isn’t the case, perhaps it is a bug. Might be worth a quick look on bbpress.org’s forums to see if the question has been asked before.

    I’m not aware of any scripts or plugins that backfill the data for you.


    Sergio De Falco
    Participant

    @sgr33n

    Thanks Paul, I made it :), it’s something really rough, but if somebody needs it here it is:

    <?php
    
    // parametri del database
    $db_host = "localhost";         //Your database host
    $db_user = "database";          //Your database username
    $db_password = "password";      //Your database password
    $db_name = "database_01";       //Your database name
    
    $db = mysql_connect($db_host, $db_user, $db_password);
    set_time_limit(0);
    
    if ($db == FALSE)
    die ("Connection Error.");
    
    mysql_select_db($db_name, $db)
    or die ("Database Error.");
    
    $n = 0;
    $query = "SELECT * FROM <code>wp_posts</code> WHERE post_type = 'topic' OR post_type = 'reply' ORDER BY post_date ASC";
    
    $result = mysql_query($query, $db);
    
    while ($row = mysql_fetch_array($result))
    
    	{
    		unset($user_id);
    		unset($reg);
    		unset($guid);
    		unset($id);
    		unset($post_parent);
    		unset($post_date);
    		unset($nicename);
    		unset($displayname);
    		unset($title);
    		unset($forum);
    		unset($forumurl);
    		unset($post_type);
    		unset($forum_id);
    		unset($acttype);
    	
    		$user_id = $row['post_author'];
    		$guid = $row['guid'];
    		$reg = $row['user_registered'];
    		$id = $row['ID'];
    		$post_parent = $row['post_parent'];
    		$post_date = $row['post_date'];
    		$title = $row['post_title'];
    		$content = $row['post_content'];
    		$post_type = $row['post_type'];
    		$forum_id = $post_parent;
    		
    		$q1 = "SELECT * FROM <code>wp_users</code> WHERE ID = '$user_id'";
    		$r1 = mysql_query($q1, $db);
    		$e1 = mysql_fetch_array($r1);
    		
    		$nicename = $e1['user_nicename'];
    		$displayname = $e1['display_name'];
    		
    		if ( $post_type == 'reply' ) {
    			$q1 = "SELECT * FROM <code>wp_posts</code> WHERE ID = '$post_parent'";
    			$r1 = mysql_query($q1, $db);
    			$e1 = mysql_fetch_array($r1);
    			
    			$post_parent = $e1['post_parent'];
    			$title = $e1['post_title'];
    			$guid = $e1['guid'];
    		}
    		
    		$q1 = "SELECT * FROM <code>wp_posts</code> WHERE ID = '$forum_id'";
    		$r1 = mysql_query($q1, $db);
    		$e1 = mysql_fetch_array($r1);
    		
    		$forum = $e1['post_title'];
    		$forumurl = $e1['guid'];
    
    		if ( $post_type == 'topic' ) {
    			$action = mysql_real_escape_string('<a href="http://www.yoursite.com/users/' . $nicename . '/" rel="nofollow">' . $displayname . '</a> ha iniziato la discussione <a href="' . $guid . '">' . $title . '</a> nel forum <a href="' . $forumurl . '">' . $forum . '</a>');
    			$acttype = 'bbp_topic_create';
    		} else {
    			$action = mysql_real_escape_string('<a href="http://www.yoursite.com/users/' . $nicename . '/" rel="nofollow">' . $displayname . '</a> ha risposto alla discussione <a href="' . $guid . '">' . $title . '</a> nel forum <a href="' . $forumurl . '">' . $forum . '</a>');
    			$acttype = 'bbp_reply_create';
    		}
    		
    		$content = mysql_real_escape_string( $content );
    
    		if ( $user_id > 0 ) {
    			$q1 = "SELECT COUNT(umeta_id) AS conto FROM <code>wp_usermeta</code> WHERE user_id = '$user_id' AND meta_key = 'last_activity'";
    			$r1 = mysql_query($q1, $db);
    			$e1 = mysql_fetch_array($r1);
    			
    			if ( $e1['conto'] > 0 ) {
    				$q = "UPDATE wp_usermeta SET meta_value = '$post_date' WHERE user_id = '$user_id' AND meta_key = 'last_activity'";
    				mysql_query($q, $db);
    			} else {
    				$q = "INSERT INTO <code>wp_usermeta</code> (<code>umeta_id</code>, <code>user_id</code>, <code>meta_key</code>, <code>meta_value</code> ) VALUES ( NULL, '$user_id', 'last_activity', '$post_date' );";
    				mysql_query($q, $db);
    			}
    		}
    		
    		$q = "INSERT INTO <code>wp_bp_activity</code> (<code>id</code>, <code>user_id</code>, <code>component</code>, <code>type</code>, <code>action</code>, <code>content</code>, <code>primary_link</code>, <code>item_id</code>, <code>secondary_item_id</code>, <code>date_recorded</code>, <code>hide_sitewide</code>, <code>mptt_left</code>, <code>mptt_right</code>, <code>is_spam</code> ) VALUES ";
    		$q .= "(NULL, '$user_id', 'bbpress', '$acttype', '$action', '$content', '$guid', '$id', '$post_parent', '$post_date', '0', '0', '0', '0')";
    		mysql_query($q, $db);
    
                    $n++;
    	}
    
    mysql_close($db);
    
    echo "Done! inserted $n activity entries";
    ?>
    

    The action is in italian, you can modify as you want


    Sergio De Falco
    Participant

    @sgr33n

    replace code with `

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘bbPress to Activity import’ is closed to new replies.
Skip to toolbar