diff options
| author | Christian Fowler <spider@viovio.com> | 2009-05-30 17:21:15 +0000 |
|---|---|---|
| committer | Christian Fowler <spider@viovio.com> | 2009-05-30 17:21:15 +0000 |
| commit | 49973fae69bb1f05c6454b33fdde28e58ca50da9 (patch) | |
| tree | 990fb5d600f4b734ddb53d88d078e024e6035351 /admin | |
| parent | 1562103290223833e27d020bc693ba599be3e0ad (diff) | |
| download | boards-49973fae69bb1f05c6454b33fdde28e58ca50da9.tar.gz boards-49973fae69bb1f05c6454b33fdde28e58ca50da9.tar.bz2 boards-49973fae69bb1f05c6454b33fdde28e58ca50da9.zip | |
add board upgrade code from wjames5
Diffstat (limited to 'admin')
| -rw-r--r-- | admin/upgrades/1.0.1.php | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/admin/upgrades/1.0.1.php b/admin/upgrades/1.0.1.php index 54ba667..11c0577 100644 --- a/admin/upgrades/1.0.1.php +++ b/admin/upgrades/1.0.1.php @@ -1,6 +1,6 @@ <?php /** - * @version $Header: /cvsroot/bitweaver/_bit_boards/admin/upgrades/1.0.1.php,v 1.1 2009/05/29 16:03:49 spiderr Exp $ + * @version $Header: /cvsroot/bitweaver/_bit_boards/admin/upgrades/1.0.1.php,v 1.2 2009/05/30 17:21:15 spiderr Exp $ */ global $gBitInstaller; @@ -33,5 +33,61 @@ array( 'DATADICT' => array( )), )), +array( 'PHP' => ' +// Is package installed and enabled +$gBitSystem->verifyPackage( "boards" ); + +require_once( BOARDS_PKG_PATH."BitBoardTopic.php"); + +$oTopic = new BitBoardTopic(); + +// get a list of all the bad records +$list_query = "SELECT bt.* + FROM `".BIT_DB_PREFIX."boards_topics` bt + INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id`= bt.`parent_id` ) + WHERE lc.content_type_guid != ?"; + +$bind_vars = array( "bitcomment" ); + +$max_records = 99999; + +$map_errors = $oTopic->mDb->query( $list_query, $bind_vars, $max_records ); + +// fix everything +// transaction will save us if something goes bad +$oTopic->mDb->StartTrans(); + +// expunge all the bad records we just got a list of +$expunge_query = "DELETE FROM `".BIT_DB_PREFIX."boards_topics` + WHERE `parent_id` IN + ( SELECT bt.`parent_id` + FROM `".BIT_DB_PREFIX."boards_topics` bt + INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( lc.`content_id`= bt.`parent_id` ) + WHERE lc.content_type_guid != ? )"; +$oTopic->mDb->query( $expunge_query, $bind_vars ); + +// repopulate the records with the proper parent_id value +while( $topic = $map_errors->fetchRow() ) { + $store_hash = $topic; + $comment_query = "SELECT lcom.`content_id` FROM `".BIT_DB_PREFIX."liberty_comments` lcom WHERE lcom.`comment_id` = ?"; + // if the mapping isnt totally screwed up the parent id should work as a comment_id + if( $comment_content_id = $oTopic->mDb->getOne( $comment_query, array( $topic["parent_id"] ) ) ){ + // just to be doublely safe, make sure the record doesnt already exist in the table + if( !$oTopic->mDb->getOne( "SELECT parent_id FROM boards_topics WHERE parent_id = ?", $comment_content_id ) ){ + $store_hash["parent_id"] = $comment_content_id; + // reinsert the topic + if( $result = $oTopic->mDb->associateInsert( "boards_topics", $store_hash ) ){ + echo "Table boards_topic mapping repaired for topic/comment content id:" . $comment_content_id . "<br />"; + } + }else{ + echo "Duplicate record for topic/comment content id:" . $comment_content_id . ", insertion ignored <br />"; + } + } +} + +$oTopic->mDb->CompleteTrans(); +' ), + + )); ?> |
