|
From: OryNider <ory...@us...> - 2007-08-09 13:21:07
|
Update of /cvsroot/mxbb/mx_smartor In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv15539 Added Files: hierarchy_db_migrate.php Log Message: I add this file just in case we will upgrade the personal gallery system, not to be released in the package. --- NEW FILE: hierarchy_db_migrate.php --- <?php /** * * @package mxBB Portal Module - mx_smartor * @version $Id: hierarchy_db_migrate.php,v 1.6 2007/08/09 13:21:03 orynider Exp $ * @copyright (c) 2002-2006 [Smartor, Volodymyr (CLowN) Skoryk, IdleVoid, Jon Ohlsson] mxBB Project Team * @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2 * */ define( 'IN_PORTAL', true ); $album_root_path = '../modules/mx_smartor/album_mod/'; // Table names define( 'ALBUM_TABLE', $mx_table_prefix . 'smartor_album' ); define( 'ALBUM_CAT_TABLE', $mx_table_prefix . 'smartor_album_cat' ); define( 'ALBUM_CONFIG_TABLE', $mx_table_prefix . 'smartor_album_config' ); define( 'ALBUM_COMMENT_TABLE', $mx_table_prefix . 'smartor_album_comment' ); define( 'ALBUM_RATE_TABLE', $mx_table_prefix . 'smartor_album_rate' ); define( 'ALBUM_SP_CONFIG_TABLE', $mx_table_prefix . 'smartor_album_sp_config' ); if ( !$userdata['session_logged_in'] ) { die( 'no valid admin' ); } if ( $userdata['user_level'] != ADMIN ) { mx_message_die( GENERAL_MESSAGE, 'You are not authorised to access this page' ); } $page_title = 'Converting/Migrating the database for IdleVoid\'s Album Category Hierarchy Mod 1.2.0'; // include($phpbb_root_path . 'includes/page_header.'.$phpEx); echo '<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">'; echo '<th>This will convert/migrate all the personal galleries into the data model used in the Album Category Hierarchy 1.1.0 mod.</th>'; echo '<tr><td align="center"><table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">'; echo '<tr><th>Updating the database</th></tr><tr><td><span class="genmed"><ul type="circle">'; $personal_gallery_info = array(); $sql = "SELECT DISTINCT p.pic_user_id, p.pic_username FROM " . ALBUM_TABLE . " AS p WHERE p.pic_cat_id = 0 ORDER BY pic_user_id"; if ( !$result = $db->sql_query( $sql ) ) { mx_message_die( GENERAL_ERROR, 'Could not query personal gallery information', '', __LINE__, __FILE__, $sql ); } if ( $db->sql_numrows( $result ) == 0 ) { // mx_message_die(GENERAL_ERROR, 'There aren\'t any \'old\' personal galleries. Script is ending.'); echo '<li><font color="#0000FF"><b>NOTICE:</b></font> There aren\'t any \'old\' personal galleries to migrate. Script is ending.</li><br />'; } else { while ( $row = $db->sql_fetchrow( $result ) ) { $personal_gallery_info[] = $row; } reset( $personal_gallery_info ); $sql = ""; for( $i = 0; $i < count( $personal_gallery_info ); $i++ ) { // check wheter the personal gallery root id already exists...it shouldn't tho'. $sql = "SELECT cat_id FROM " . ALBUM_CAT_TABLE . " WHERE cat_user_id = " . $personal_gallery_info[$i]['pic_user_id'] . " AND cat_parent = 0 LIMIT 1"; if ( !$result = $db->sql_query ( $sql ) ) { $error = $db->sql_error(); echo '<li>' . $sql . '<br /><font color="#FF0000"><b>ERROR:</b></font> ' . $error['message'] . '</li><br />'; // try the next personal gallery continue; } if ( $db->sql_numrows( $result ) == 0 ) { $root_cat_name = sprintf( $lang['Personal_Gallery_Of_User'], $personal_gallery_info[$i]['pic_username'] ); $sql = "INSERT INTO " . ALBUM_CAT_TABLE . " (cat_title, cat_desc, cat_order, cat_view_level, cat_upload_level, cat_rate_level, cat_comment_level, cat_edit_level, cat_delete_level, cat_approval, cat_parent, cat_user_id) VALUES ('" . $root_cat_name . "', '" . $root_cat_name . "', '0', '" . $album_config['personal_gallery_view'] . "', '" . ALBUM_PRIVATE . "', '0', '0', '" . ALBUM_PRIVATE . "', '" . ALBUM_PRIVATE . "', '0', '0', '" . $personal_gallery_info[$i]['pic_user_id'] . "')"; if ( !$result = $db->sql_query ( $sql ) ) { $error = $db->sql_error(); echo '<li>' . $sql . '<br /><font color="#FF0000"><b>ERROR:</b></font> ' . $error['message'] . '</li><br />'; echo ' Personal gallery was <b>NOT</b> created for user : \'' . $personal_gallery_info[$i]['pic_username'] . '\'<br />'; echo ' Please inform IdleVoid (the Author) about this, including the user name<br />'; // try the next personal gallery and by that skip the updating of this users personal gallery continue; } // get the newly created personal gallery root id. $sql = "SELECT cat_id FROM " . ALBUM_CAT_TABLE . " WHERE cat_user_id = " . $personal_gallery_info[$i]['pic_user_id'] . " AND cat_parent = 0 LIMIT 1"; if ( !$result = $db->sql_query ( $sql ) ) { $error = $db->sql_error(); echo '<li>' . $sql . '<br /><font color="#FF0000"><b>ERROR:</b></font> ' . $error['message'] . '</li><br />'; continue; } $row = $db->sql_fetchrow( $result ); $root_cat_id = $row['cat_id']; // move the pictures of this user into the $sql = "UPDATE " . ALBUM_TABLE . " SET pic_cat_id = $root_cat_id WHERE pic_cat_id = 0 AND pic_user_id = " . $personal_gallery_info[$i]['pic_user_id']; if ( !$result = $db->sql_query ( $sql ) ) { $error = $db->sql_error(); echo '<li>' . $sql . '<br /><font color="#FF0000"><b>ERROR:</b></font> ' . $error['message'] . '</li><br />'; } else { echo '<li>' . $sql . '<br /><font color="#00AA00"><b>SUCCESSFULL</b></font></li><br />'; } } } } echo '</ul></span></td></tr>'; echo '<tr><th>Finish</th></tr><tr><td><span class="genmed"><center><br />Installation is now finished.<br /></center></span></td></tr></table></td></tr></table>'; // include($phpbb_root_path . 'includes/page_tail.'.$phpEx); ?> |