Recent Topics

1 Jul 19, 2012 18:19    

Is this possible ?

I dont want to switch to Wordpress since i like b2, but i am thinking of duplicating my install and running a WP copy under different domain.Since both will be the same site, i dont want to enter posts twice.

Widget, theme or user integration is not as important.(user integration would be nice though)

Only post update is essential for me.Would it be possible to bridge the two so they use the same db ? Or do sth that would update the other db when the other is changed ?

2 Jul 19, 2012 19:49

I believe it's a lot easier to replicate changes from one app to another.
Just hack the DB class of either app, create hooks for INSERT and UPDATE operations and duplicate the queries for another app.

Of course you will need to sync the apps initially.

// note to myself
Add plugin hooks to DB class in b2evo v5

3 Jul 19, 2012 20:35

sam2kb wrote:

I believe it's a lot easier to replicate changes from one app to another.
Just hack the DB class of either app, create hooks for INSERT and UPDATE operations and duplicate the queries for another app.

Of course you will need to sync the apps initially.

// note to myself
Add plugin hooks to DB class in b2evo v5

could you explain it further if it's a rather simple task ? or could you please pm me an offer for the job..
ps: no hurry

4 Jul 19, 2012 21:52

Well, we don't even need to add new hooks. There's a way in b2evo to log all DB queries. So you initiate logging, and on script shutdown you analyze queries, and reproduce data altering queries like (insert, update, replace, delete) to the other app.

To be honest, I just realized that this is the wrong (very hard) way. Analyzing and parsing each query is not easy.

Instead, you should use these new hooks from b2evo v5 AfterObjectInsert, AfterObjectUpdate, AfterObjectDelete. This is simpler than working with raw queries. Here's the example

/**
 * Event handler: called at the end of {@link DataObject::dbinsert() inserting an object in the database}.
 *
 * @param array Associative array of parameters
 *   - 'Object': the related Object (by reference)
 *   - 'type': class name of deleted Object (Chapter, File, Blog, Link, Comment, Slug etc.) (by reference)
 */
function AfterObjectInsert( & $params )
{
	// use XML-RPC to do the changes in WP
	load_funcs('xmlrpc/model/_xmlrpc.funcs.php');
	$client = new xmlrpc_client('/xmlrpc.php', 'my-wp-host.com', 80);

	if( $params['type'] == 'Item' )
	{	// New post added in b2evo
		$Item = & $params['Object'];
		
		$title = $Item->get('title');
		$content = $Item->get('title');
		
		$client->[CONSTRUCT XML-RPC REQUEST WITH VALUES RECEIVED FROM THE OBJECT]
		$client->[SEND XML-RPC REQUEST TO INSERT NEW POST]
	}
}


Form is loading...