Вход Регистрация
Файл: adultscript-2.0.3-pro/files/install/migrate-mediaxxxscript.php
Строк: 765
<?php
define
('_VALID'true);
define('_INSTALL'true);
require 
realpath('../libraries/bootstrap.php');

define('INSTALL_URL'BASE_URL.'/install');

error_reporting(E_ALL);
ini_set('display_errors'1);

restore_error_handler();
restore_exception_handler();

while(
ob_get_level()) {
    
ob_end_flush();
}

// we dont need a session opened here
session_write_close();

$dt_method        'copy';

$errors            = array();
$test              VF::factory('test');
$required         $test->get_required_results();
$optional        $test->get_optional_results();
$recommended    $test->get_recommended_results();

$config            = array(
    
'm_path'        => '',
    
'm_db_host'        => '',
    
'm_db_username'    => '',
    
'm_db_password'    => '',
    
'm_db_name'        => '',
    
'base_url'        => BASE_URL,
    
'relative_url'    => RELATIVE_URL,
);

$secret            VText::random();

function 
show($value)
{
    if (
$value == '2') {
        return 
'no';
    }
    
    return (
$value == '0') ? 'all' 'friends';
}

function 
update_progress($data)
{
    
file_put_contents(TMP_DIR.'/logs/migration_progress.log'$data."n");
}

if (isset(
$_POST['submitted'])) {
    
$filter            VF::factory('filter');
    
$m_path            VFolder::safe($filter->get('m_path'));
    
$m_db_host        $filter->get('m_db_host');
    
$m_db_username    $filter->get('m_db_username');
    
$m_db_password    $filter->get('m_db_password');
    
$m_db_name        $filter->get('m_db_name');
    
    if (
$m_path == '') {
        
$errors[] = 'You need to enter the Media XXX Script Installation path to continue!';
    } else {
        
$dirs    = array(
            
$m_path,
            
$m_path.'/images/albums',
            
$m_path.'/images/membersprofilepic',
            
$m_path.'/images/picturethumbs',
            
$m_path.'/images/videothumbs',
            
$m_path.'/pdata',
            
$m_path.'/vdata'
        
);
        
        foreach (
$dirs as $dir) {
            if (!
file_exists($dir) OR !is_dir($dir) OR !is_readable($dir)) {
                
$errors[] = 'Invalid Media XXX Script installation (folder: '.$dir.' not found)!';
            }
        }
    }
    
    if (
$m_db_host == '' OR $m_db_username == '' OR
        
$m_db_password == '' OR $m_db_name == '') {
        
$errors[] = 'You need to enter the Media XXX Script database host, username, password and name to continue!';
    } else {
        require 
'db.php';
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        if (
$mdb->is_error()) {
            
$errors[] = $mdb->get_error();
        }
    }
    
    if (!
$errors) {
        
update_progress('1^Migrating users....');
        
        
$db VF::factory('database');
        
$db->query("SHOW COLUMNS FROM #__user LIKE 'old_user_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__user ADD `old_user_id` int(11) NOT NULL default '0'");
        }
        
        
$mdb->query("SELECT * FROM members ORDER BY USERID ASC");
        
$users $mdb->fetch_rows();
        
        foreach (
$users as $user) {
            if (
$user['username'] == 'anonymous') {
                
$db->query("UPDATE #__user
                            SET old_user_id = "
.(int) $user['USERID']."
                            WHERE username = 'anonymous'
                            LIMIT 1"
);
                continue;
            }

            if (
$user['username'] == 'admin') {
                
$db->query("UPDATE #__user
                            SET old_user_id = "
.(int) $user['USERID']."
                            WHERE username = 'admin'
                            LIMIT 1"
);
                continue;
            }
            
            
$gender        = ($user['gender'] == '0') ? 'female' 'male';
            
$relation    'hidden';
            if (
$user['relation'] != '') {
                if (
$user['relation'] == '1') {
                    
$relation 'single';
                } elseif (
$user['relation'] == '2') {
                    
$relation 'taken';
                } else {
                    
$relation 'open';
                }
            }
            
            
$interested  'hidden';
            if (
$user['interested'] != '') {
                if (
$user['interested'] == '1') {
                    
$interested 'single';
                } elseif (
$user['interested'] == '2') {
                    
$interested 'taken';
                } else {
                    
$interested 'open';
                }
            }
            
            
$rating 0;
            if (
$user['rating'] != '') {
                
$rating floor((float) $user['rating']);
                
$rating round($rating/21);
            }
                        
            
$db->query("INSERT INTO #__user
                        SET group_id = 5,
                              old_user_id = "
.(int) $user['USERID'].",
                            username = '"
.$db->escape(str_replace(' ''-'$user['username']))."',
                            password = '"
.$db->escape($user['password'])."',
                            email = '"
.$db->escape($user['email'])."',
                            name = '"
.$db->escape($user['firstname']).' '.$db->escape($user['lastname'])."',
                            gender = '"
.$db->escape($gender)."',
                            relation = '"
.$db->escape($relation)."',
                            interested = '"
.$db->escape($interested)."',
                            birth_date = '"
.$db->escape($user['birthday'])."',
                            city = '"
.$db->escape($user['city'])."',
                            country = '"
.$db->escape($user['country'])."',
                            join_date = '"
.$db->escape(date('Y-m-d h:i:s'$user['addtime']))."',
                            login_date = '"
.$db->escape(date('Y-m-d h:i:s'$user['lastlogin']))."',
                            popularity = "
.(int) $user['activity'].",
                            rating = "
.$rating.",
                            rated_by = "
.(int) $user['ratingcount'].",
                            verified = '"
.$user['verified']."',
                            status = '"
.$user['status']."'");
            if (
$db->affected_rows()) {
                
$user_id = (int) $db->get_last_insert_id('#__user');
                
$db->query("INSERT INTO #__user_activity
                            SET user_id = "
.$user_id.",
                                total_video_views = "
.(int) $user['yourvideosviewed'].",
                                total_viewed_videos = "
.(int) $user['videosyouviewed'].",
                                total_profile_views = "
.(int) $user['profileviews']);
                
$db->query("INSERT INTO #__user_profile
                            SET user_id = "
.$user_id.",
                                about = '"
.$db->escape($user['about'])."',
                                website = '"
.$db->escape($user['url'])."',
                                hobbies = '"
.$db->escape($user['hobby'])."',
                                school = '"
.$db->escape($user['school'])."',
                                occupation = '"
.$db->escape($user['job'])."',
                                turn_on = '"
.$db->escape($user['turnon'])."',
                                turn_off = '"
.$db->escape($user['turnoff'])."'");
                
                
$allow_friends             = ($user['fr_auto'] == '1') ? 'auto' 'approve';
                
$profile_comments        = ($user['wall_public'] == '1') ? 'all' 'friends';
                
$db->query("INSERT INTO #__user_preferences
                            SET user_id = "
.$user_id.",
                                show_videos = 'all',
                                show_video_favorites = '"
.show($user['show_favorites'])."',
                                show_friends = '"
.show($user['show_friends'])."',
                                show_subscribers = '"
.show($user['show_subscribers'])."',
                                show_subscriptions = '"
.show($user['show_subscriptions'])."',
                                allow_friends = '"
.$allow_friends."',
                                profile_comments = '"
.$profile_comments."'");
                
$db->query("INSERT INTO #__user_notifications
                            SET user_id = "
.$user_id.",
                                video_approve = '"
.$user['video_approve']."',
                                video_comment = '"
.$user['video_comment']."',
                                subscription = '"
.$user['video_subscribe']."',
                                friend_request = '"
.$user['friend_request']."',
                                profile_comment = '"
.$user['wall_write']."',
                                new_message = '"
.$user['send_message']."'");
                
                if (
$user['profilepicture'] != '') {
                    
$avatar $m_path.'/images/membersprofilepic/thumbs/'.$user['USERID'].'.jpg';
                    if (
file_exists($avatar) && is_file($avatar)) {
                        
$ext VFile::ext($user['profilepicture']);
                        
$dt_method($avatarMEDIA_DIR.'/users/'.$user_id.'.'.$ext);
                        
$db->query("UPDATE #__user SET avatar = '".$db->escape($ext)."' WHERE user_id = ".$user_id." LIMIT 1");
                    }
                }
            } else {
                die(
'Failed to add user!');
            }
        }
        
        
// progress 5%, lets initiate our database connections again
        
update_progress('5^Migrating user comments...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');
        
        
$mdb->query("SELECT * FROM members_comments");
        
$comments $mdb->fetch_rows();
        foreach (
$comments as $comment) {
            
$user_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $comment['PROFILEID']." LIMIT 1"'user_id');
            
$poster_id    = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $comment['USERID']." LIMIT 1"'user_id');
            
            if (
$user_id !== && $poster_id !== 0) {
                
$db->query("INSERT INTO #__user_comments
                              SET user_id = "
.$user_id.",
                                  poster_id = "
.$poster_id.",
                                  comment = '"
.$db->escape($comment['details'])."',
                                  add_date = '"
.date('Y-m-d h:i:s'$comment['time_added'])."'");
            }
        }
        
        
// progress 7%, lets initiate our database connections again :-)
        
update_progress('7^Migrating user blocks...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');
        
        
$mdb->query("SELECT BPID, BUID FROM members_blocks");
        
$blocks $mdb->fetch_rows();
        foreach (
$blocks as $block) {
            
$user_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $block['BPID']." LIMIT 1"'user_id');
            
$blocked_id = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $block['BUID']." LIMIT 1"'user_id');
            
            if (
$user_id !== && $blocked_id !== 0) {
                
$db->query("INSERT INTO #__user_blocks
                              SET user_id = "
.$user_id.",
                                  blocked_id = "
.$blocked_id);
            }
        }
        
        
// progress 8%, lets initiate our database connections again :-)
        
update_progress('8^Migrating user subscribers...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');
        
        
$mdb->query("SELECT subscriber, subscribee FROM members_subscribers");
        
$subscribes $mdb->fetch_rows();
        foreach (
$subscribes as $subscribe) {
            
$user_id         = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $subscribe['subscriber']." LIMIT 1"'user_id');
            
$subscriber_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $subscribe['subscribee']." LIMIT 1"'user_id');
            
            if (
$user_id !== && $subscriber_id !== 0) {
                
$db->query("INSERT INTO #__user_subscriptions
                            SET user_id = "
.$user_id.",
                                subscriber_id = "
.$subscriber_id);
            }
        }
        
        
// progress 9%, lets initiate our database connections again :-)
        
update_progress('9^Migrating user friends...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');
        
        
$mdb->query("SELECT USERID, FRIENDID, time_added FROM friends");
        
$friends $mdb->fetch_rows();
        foreach (
$friends as $friend) {
            
$user_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $friend['USERID']." LIMIT 1"'user_id');
            
$friend_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $friend['FRIENDID']." LIMIT 1"'user_id');
            
            if (
$user_id !== && $friend_id !== 0) {
                
$db->query("INSERT INTO #__user_friends
                            SET user_id = "
.$user_id.",
                                friend_id = "
.$friend_id.",
                                add_date = '"
.date('Y-m-d h:i:s'$friend['time_added'])."',
                                status = 'approved'"
);
                
$db->query("INSERT INTO #__user_friends
                            SET user_id = "
.$friend_id.",
                                friend_id = "
.$user_id.",
                                add_date = '"
.date('Y-m-d h:i:s'$friend['time_added'])."',
                                status = 'approved'"
);
                
$db->query("UPDATE #__user_activity
                            SET total_friends = total_friends
                            WHERE user_id IN ("
.$user_id.",".$friend_id.")");
            }
        }

        
// progress 10%, lets initiate our database connections again :-)
        
update_progress('10^Migrating photo categories...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');

        
$db->query("SHOW COLUMNS FROM #__photo_categories LIKE 'old_cat_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__photo_categories ADD `old_cat_id` int(11) NOT NULL default '0'");
        }
        
        
$mdb->query("SELECT CATID, name FROM categories ORDER BY name ASC");
        
$categories $mdb->fetch_rows();
        foreach (
$categories as $category) {
            
$db->query("INSERT INTO #__photo_categories
                        SET old_cat_id = "
.(int) $category['CATID'].",
                            name = '"
.$db->escape($category['name'])."',
                            slug = '"
.$db->escape(prepare_string($category['name'], TRUE))."'");
            if (!
$db->affected_rows()) {
                die(
'Failed to add photo category!');
            }
        }
        
        
// progress 11%, lets initiate our database connections again :-)
        
update_progress('11^Migrating photo albums...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');

        
$db->query("SHOW COLUMNS FROM #__photo_albums LIKE 'old_album_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__photo_albums ADD `old_album_id` int(11) NOT NULL default '0'");
        }
        
        
$mdb->query("SELECT * FROM albums");
        
$albums $mdb->fetch_rows();
        foreach (
$albums as $album) {
            
$rating 0;
            if (
$album['rate'] != '') {
                
$rating floor((float) $album['rate']);
                
$rating round($rating/21);
            }
            
            
$type        = ($album['public'] == '1') ? 'public' 'private';
            
$user_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $album['USERID']." LIMIT 1"'user_id');
            
            
$db->query("INSERT INTO #__photo_albums
                        SET user_id = "
.$user_id.",
                            old_album_id = "
.(int) $album['AID'].",
                            title = '"
.$db->escape($album['aname'])."',
                            slug = '"
.$db->escape(prepare_string($album['aname'], TRUE))."',
                            type = '"
.$db->escape($type)."',
                            rating = "
.$rating.",
                            rated_by = "
.$album['ratings'].",
                            total_views = "
.$album['viewcount'].",
                            add_time = "
.$album['time_added'].",
                            add_date = "
.$album['date_added'].",
                            status = '2'"
);
            if (
$db->affected_rows()) {
                
$album_id    $db->get_last_insert_id('#__photo_albums');
                
$cat_id     = (int) $db->get_field("SELECT cat_id FROM #__photo_categories WHERE old_cat_id = ".(int) $album['categories']." LIMIT 1"'cat_id');
                
                
$db->query("INSERT INTO #__photo_category
                            SET album_id = "
.$album_id.",
                                cat_id = "
.$cat_id);
                
                
$tag_string str_replace(','''prepare_tags($album['tags']));
                
$tag_array  explode(' '$tag_string);
                
$tags        = array();
                foreach (
$tag_array as $tag) {
                    if (
strlen($tag) >= 3) {
                        
$tags[] = $tag;
                    }
                }
                
                foreach (
$tags as $tag) {
                    
$db->query("INSERT INTO #__photo_tags
                                SET album_id = "
.$album_id.",
                                    name = '"
.$db->escape($tag)."'");
                }
                
                
$cover $m_path.'/images/albums/'.$album['AID'].'.jpg';
                if (
file_exists($cover) && is_file($cover)) {
                    
$dt_method($coverMEDIA_DIR.'/photos/covers/'.$album_id.'.jpg');
                }
            }
        }
        
        
// progress 13%, lets initiate our database connections again :-)
        
update_progress('13^Migrating photos...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');

        
$db->query("SHOW COLUMNS FROM #__photo LIKE 'old_photo_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__photo ADD `old_photo_id` int(11) NOT NULL default '0'");
        }
        
        
$pcfg    VF::cfg('module.photo');
        
$image     VF::factory('image');
        
        
$mdb->query("SELECT * FROM pictures");
        
$photos $mdb->fetch_rows();
        foreach (
$photos as $photo) {
            
$rating 0;
            if (
$photo['rating'] != '') {
                
$rating floor((float) $photo['rating']);
                
$rating round($rating/21);
            }
            
            
$ext      str_replace('.'''$photo['ext']);
            
$album_id = (int) $db->get_field("SELECT album_id FROM #__photo_albums WHERE old_album_id = ".(int) $photo['AID']." LIMIT 1"'album_id');
            
$db->query("INSERT INTO #__photo
                        SET album_id = "
.$album_id.",
                            old_photo_id = "
.(int) $photo['PID'].",
                            caption = '"
.$db->escape($photo['caption'])."',
                            add_date = '"
.$db->escape($photo['date_added'])."',
                            rating = "
.$rating.",
                            rated_by = "
.$photo['ratingcount'].",
                            total_views = "
.$photo['viewcount'].",
                            ext = '"
.$db->escape($ext)."'");
            if (
$db->affected_rows()) {
                
$photo_id        $db->get_last_insert_id('#__photo');
                
$src             $m_path.'/pdata/'.$photo['PID'].'.'.$ext;
                
$dst            MEDIA_DIR.'/photos/'.$photo_id.'.'.$ext;
                
$dst_orig        MEDIA_DIR.'/photos/orig/'.$photo_id.'.'.$ext;
                
$dst_thumb        MEDIA_DIR.'/photos/thumbs/'.$photo_id.'.jpg';
                
$dst_thumb_tmp    TMP_DIR.'/images/'.$photo_id.'.thumb.jpg';
                if (
file_exists($src) && is_file($src)) {
                    
$dt_method($src$dst_orig);
                    if (!
$image->load($dst_orig)) {
                        
$db->query("UPDATE #__photo SET status = '0' WHERE photo_id = ".$photo_id." LIMIT 1");
                        continue;
                    }
                    
                    if (
$image->src['width'] < $pcfg['photo_width']) {
                        
$dt_method($dst_orig$dst);
                    } else {
                        if (!
$image->resize($pcfg['photo_width'], $pcfg['photo_height'], 'MAX_WIDTH'$dst)) {
                            
$db->query("UPDATE #__photo SET status = '0' WHERE photo_id = ".$photo_id." LIMIT 1");
                            continue;
                        }
                    }
                    
                    
$thumb_width    $pcfg['thumb_width']+30;
                    
$thumb_height   $pcfg['thumb_height']+100;
                    
$image->set_option('jpeg_quality'100);
                    if (!
$image->resize($thumb_width$thumb_height'MAX_HEIGHT'$dst_thumb_tmp)) {
                          continue;
                    }

                    
$image->clear();
                    
$image->load($dst_thumb_tmp);

                    if (!
$image->crop_from_center($pcfg['thumb_width'], $pcfg['thumb_height'], $dst_thumb)) {
                          continue;
                    }

                    
$db->query("UPDATE #__photo_albums
                                SET total_photos = total_photos+1,
                                    status = '1'
                                WHERE album_id = "
.$album_id."
                                LIMIT 1"
);
                    
                    
VFile::delete($dst_thumb_tmp);
                }
            }
        }
        
        
// progress 15%, lets initiate our database connections again :-)
        
update_progress('15^Migrating photo comments...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');
        
        
$mdb->query("SELECT * FROM pictures_comments");
        
$comments $mdb->fetch_rows();
        foreach (
$comments as $comment) {
            
$db->query("SELECT album_id, photo_id FROM #__photo WHERE old_photo_id = ".(int) $comment['PID']." LIMIT 1"'photo_id');
            
$photo_id     = (int) $db->fetch_field('photo_id');
            
$album_id    = (int) $db->fetch_field('album_id');
            
$user_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $comment['USERID']." LIMIT 1"'user_id');

            if (
$user_id !== && $photo_id !== 0) {
                
$db->query("INSERT INTO #__photo_comments
                              SET photo_id = "
.$photo_id.",
                                  user_id = "
.$user_id.",
                                  comment = '"
.$db->escape($comment['details'])."',
                                  add_date = '"
.date('Y-m-d h:i:s'$comment['time_added'])."'");
                
$db->query("UPDATE #__photo
                            SET total_comments = total_comments+1
                            WHERE photo_id = "
.$photo_id."
                            LIMIT 1"
);
            }
        }
        
        
// progress 17%, lets initiate our database connections again :-)
        
update_progress('17^Migrating photo favorites...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');
        
        
$mdb->query("SELECT USERID, PID FROM pictures_favorited");
        
$favorites $mdb->fetch_rows();
        foreach (
$favorites as $favorite) {
            
$photo_id     = (int) $db->get_field("SELECT photo_id FROM #__photo WHERE old_photo_id = ".(int) $favorite['PID']." LIMIT 1"'photo_id');
            
$user_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $favorite['USERID']." LIMIT 1"'user_id');
            
            if (
$photo_id !== && $user_id !== 0) {
                
$db->query("INSERT INTO #__photo_favorites
                            SET photo_id = "
.$photo_id.",
                                user_id = "
.$user_id);
                
$db->query("UPDATE #__photo SET total_favorites = total_favorites+1
                            WHERE photo_id = "
.$photo_id." LIMIT 1");
            }
        }
        
        
// progress 19%, lets initiate our database connections again :-)
        
update_progress('19^Migrating video categories...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');
        
        
$db->query("SHOW COLUMNS FROM #__video_categories LIKE 'old_cat_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__video_categories ADD `old_cat_id` int(11) NOT NULL default '0'");
        }
        
        
$mdb->query("SELECT CATID, name FROM categories ORDER BY name ASC");
        
$categories $mdb->fetch_rows();
        foreach (
$categories as $category) {
            
$db->query("INSERT INTO #__video_categories
                        SET old_cat_id = "
.(int) $category['CATID'].",
                            name = '"
.$db->escape($category['name'])."',
                            slug = '"
.$db->escape(prepare_string($category['name'], TRUE))."'");
            if (!
$db->affected_rows()) {
                die(
'Failed to add video category!');
            }
        }
        
        
// progress 20%, lets initiate our database connections again :-)
        
update_progress('20^Migrating video servers...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');
        
        
// this is to write the required data for the video migration
        // for each server
        
$files    = array();
        
        
$db->query("SHOW COLUMNS FROM #__server LIKE 'old_server_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__server ADD `old_server_id` int(11) NOT NULL default '0'");
        }
        
        
$mdb->query("SELECT * FROM servers");
        
$servers $mdb->fetch_rows();
        foreach (
$servers as $server) {
            if (
$server['host'] == 'localhost') {
                
$files[$server['SID']] = array();
                continue;
            }
        
            
$db->query("INSERT INTO #__server
                        SET server_name = '"
.$db->escape($server['name'])."',
                            ftp_host = '"
.$db->escape($server['host'])."',
                            ftp_username = '"
.$db->escape($server['login'])."',
                            ftp_password = '"
.$db->escape($server['pass'])."',
                            ftp_root = '"
.$db->escape($server['path'])."',
                            streaming_method = 'progressive',
                            url = '"
.$db->escape($server['url'])."',
                            old_server_id = "
.(int) $server['SID']);
            
            
$files[$server['SID']] = array();
        }
        
        
// this will only move the database and thumbs...to move the videos use migrate-mediaxxxscript-videos.php
        // from a ssh console
        //
        // progress 21%, lets initiate our database connections again :-)
        
update_progress('21^Migrating videos...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');

        
$db->query("SHOW COLUMNS FROM #__video LIKE 'old_video_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__video ADD `old_video_id` int(11) NOT NULL default '0'");
        }
        
        
$mdb->query("SELECT * FROM videos");
        
$videos $mdb->fetch_rows();
        
        
$percent     75;
        
$count         count($videos);
        
$incr        round($percent/round($count/500), 2);
        
$progress     21;
        
        
$index        0;
        foreach (
$videos as $video) {
            
$rating 0;
            if (
$video['rating'] != '') {
                
$rating floor((float) $video['rating']);
                
$rating round($rating/21);
            }
            
            
$user_id    = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $video['USERID']." LIMIT 1"'user_id');
            
$type        = ($video['public'] == '1') ? 'public' 'private';
        
            
$db->query("INSERT INTO #__video
                        SET user_id = "
.$user_id.",
                            title = '"
.$db->escape($video['title'])."',
                            slug = '"
.$db->escape(prepare_string($video['title'], TRUE))."',
                            description = '"
.$db->escape($video['details'])."',
                            rating = "
.$rating.",
                            rated_by = "
.$video['ratingcount'].",
                            duration = "
.$video['runtime'].",
                            thumb = 1,
                            embed_code = '"
.$db->escape($video['embedcode'])."',
                            total_views = "
.$video['viewcount'].",
                            add_time = "
.$video['time_added'].",
                            add_date = '"
.$db->escape($video['date_added'])."',
                            status = 0,
                            old_video_id = "
.$video['VIDEOID']);
            if (
$db->affected_rows()) {
                
$video_id     $db->get_last_insert_id('#__video');
                
                
$tags     str_replace(','''prepare_tags($video['tags']));
                
$tags      explode(' '$tags);
                foreach (
$tags as $tag) {
                    if (
strlen($tag) >= 3) {
                        
$db->query("INSERT INTO #__video_tags SET video_id = ".$video_id.", name = '".$db->escape($tag)."'");
                    }
                }
                
                
$db->query("SELECT cat_id FROM #__video_categories WHERE old_cat_id = ".(int) $video['categories']." LIMIT 1");
                
$cat_id 1;
                if (
$db->affected_rows()) {
                    
$cat_id = (int) $db->fetch_field('cat_id');
                }
                
                
$db->query("INSERT INTO #__video_category
                            SET video_id = "
.$video_id.",
                                cat_id = "
.$cat_id);
                
                
$thumbs     0;
//                $thumb_dir    = MEDIA_DIR.'/videos/tmb/'.$video_id;
                
$thumb_dir MEDIA_DIR.'/videos/tmb/'.path($video_id);
                
                
VFolder::create($thumb_dir);
                for (
$i=1$i<=20$i++) {
                    
$src $m_path.'/images/videothumbs/'.$video['VIDEOID'].'-'.$i.'.jpg';
                    
$dst $thumb_dir.'/'.$i.'.jpg';
                    
file_put_contents('/tmp/thumb_debug'$src.' - '.$dst."n"FILE_APPEND);
                    if (
file_exists($src) && is_file($src)) {
                        
$dt_method($src$dst);
                        ++
$thumbs;
                    }
                }
                
                
$ext    = ($video['HD'] == 'mp4') ? 'mp4' 'flv';
                
$server    0;
                if (
$video['MSID'] >= 2) {
                    
$db->query("SELECT server_id FROM #__server WHERE old_server_id = ".(int) $video['MSID']." LIMIT 1");
                    if (
$db->affected_rows()) {
                        
$server = (int) $db->fetch_field('server_id');
                        
$db->query("UPDATE #__server SET total_videos = total_videos+1 WHERE server_id = ".$server." LIMIT 1");
                    }
                }
                
                
$db->query("UPDATE #__user_activity SET total_videos = total_videos+1 WHERE user_id = ".$user_id." LIMIT 1");
                
$db->query("UPDATE #__video
                            SET thumbs = "
.$thumbs.",
                                ext = '"
.$db->escape($ext)."',
                                server = "
.$server.",
                                status = 1"
);

                
// the code to get the videos should go here...but it will go in a separate file instead
                
$video_old    $video['VIDEOID'].'.'.$ext;
                
$video_new    $video_id.'.'.$ext;
                
                
$files[$video['MSID']][$video_old] = $video_new;
            }
            
            
// doing the progress stuff here...not very accurate...enough for my eye
            
++$index;
            if (
$index === 50) {
                
$index      0;
                
$progress = ($progress 96) ? 96 : ($progress $incr);
                
update_progress(floor($progress).'^Migrating videos...');
            }
        }
        
        
// progress 97%, lets initiate our database connections again :-)
        
update_progress('97^Migrating video comments...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');

        
$mdb->query("SELECT * FROM videos_comments");
        
$comments $mdb->fetch_rows();
        foreach (
$comments as $comment) {
            
$db->query("SELECT video_id FROM #__video WHERE old_video_id = ".(int) $comment['VIDEOID']." LIMIT 1"'video_id');
            
$video_id    = (int) $db->fetch_field('video');
            
$user_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $comment['USERID']." LIMIT 1"'user_id');

            if (
$user_id !== && $video_id !== 0) {
                
$db->query("INSERT INTO #__video_comments
                              SET video_id = "
.$video_id.",
                                  user_id = "
.$user_id.",
                                  comment = '"
.$db->escape($comment['details'])."',
                                  add_date = '"
.date('Y-m-d h:i:s'$comment['time_added'])."'");
                
$db->query("UPDATE #__video
                            SET total_comments = total_comments+1
                            WHERE video_id = "
.$video_id."
                            LIMIT 1"
);
            }
        }

        
// progress 99%, lets initiate our database connections again :-)
        
update_progress('99^Migrating video favorites...');
        
$mdb->close();
        
$mdb = new VInstall_db($m_db_host$m_db_name$m_db_username$m_db_password'');
        
$db VF::factory_remove('database');
        
$db VF::factory('database');
        
        
$mdb->query("SELECT USERID, VIDEOID FROM videos_favorited");
        
$favorites $mdb->fetch_rows();
        foreach (
$favorites as $favorite) {
            
$video_id     = (int) $db->get_field("SELECT video_id FROM #__video WHERE old_video_id = ".(int) $favorite['VIDEOID']." LIMIT 1"'video_id');
            
$user_id     = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $favorite['USERID']." LIMIT 1"'user_id');
            
            if (
$video_id !== && $user_id !== 0) {
                
$db->query("INSERT INTO #__video_favorites
                            SET video_id = "
.$video_id.",
                                user_id = "
.$user_id);
                
$db->query("UPDATE #__video SET total_favorites = total_favorites+1
                            WHERE video_id = "
.$video_id." LIMIT 1");
            }
        }
        
        foreach (
$files as $key => $values) {
            
$output     = array();
            
$output[]    = '<?php return array(';
            foreach (
$values as $old => $new) {
                
$output[]    = "'".$old."' => '".$new."',";
            }
            
$output[]     = '); ?>';
            
            
file_put_contents(BASE_DIR.'/install/data/videos_server_'.$key.'.php'implode("n"$output));
        }
        
        
$finished TRUE;
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
    <title>Adult Script Pro Migration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="<?php echo INSTALL_URL ?>/css/style.css?v1" type="text/css" media="all" />
    <script type="text/javascript">var base_url = "<?php echo BASE_URL?>";</script>
</head>
<script type="text/javascript" src="<?php echo INSTALL_URL?>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function update_migration_progress()
{
    $.ajax({
          url: base_url + '/install/ajax.php',
        cache: false,
        type: "POST",
        dataType: "json",
        data: {},
          success: function(response){
              $(".progress_msg").html('');
            $(".bar").css('width', response.progress + '%');
            $(".progress_msg").html(response.msg);
            setTimeout("update_migration_progress()", 1200);
        }
    });
}

$(document).ready(function() {
    $("img[id^='help_']").click(function() {
        var id = $(this).attr('id').match(/help_(.*)/)[1];
        if ($("p[id='test_" + id + "']").is(':visible')) {
            $("p[id='test_" + id + "']").slideUp();
        } else {
            $("p[id='test_" + id + "']").slideDown();
        }
    });
    
    $("input[id='submit-migrate']").click(function() {
        $.ajax({
              url: base_url + '/install/ajax.php',
            cache: false,
            type: "POST",
            dataType: "json",
            data: {},
            success: function(response){
                  $("#progress-container").fadeIn();
                setTimeout("update_migration_progress()", 1200);
                $("#migrate-form").submit();
            }
        });
    });
});
</script>
<body>
<div id="container">
    <?php if ($errors): ?>
    <div class="errors">
    <?php foreach ($errors as $error): ?>
    <span><?php echo htmlspecialchars($error),'<br />'?></span>
    <?php endforeach; ?>
    </div>
    <?php endif; ?>
    <?php if (isset($finished) && $finished === TRUE): ?>
    <div style="width: 970px; padding: 2px 0; border: 1px solid #CCC;">
        Migration finished! Please run the: migrate-mediaxxxscript-videos.php from ssh (or from the browser)!
    </div>
    <?php endif; ?>
    <div id="progress-container" style="width: 970px; padding: 2px 0; border: 1px solid #CCC; display: none;">
        <div style="width: 100%; text-align: center; font-weight: bold;">Please do not close your browser and do not click any link on this page!</div>
          <div id="progress" style="width: 98%;"><div class="bar" style="width: 0;">&nbsp;</div></div>
          <div class="progress_msg"></div>
      </div>    
    <div class="left width-475">
        <h2>Testing Requirements</h2>
        <div class="box-content">
            <h3>Required Items</h3>
            <?php foreach ($required as $id => $values): if (!isset($values['system'])): ?>
            <span class="key"><?php if ($values['status'] !== true): echo '<strong>'; endif; ?><?php echo htmlspecialchars($values['message']); ?><?php if ($values['status'] !== true): echo '</strong>'; endif; ?></span>
            <span class="value">
                  <?php if ($values['status'] === true): ?>
                <img src="<?php echo INSTALL_URL?>/images/accept.png" alt="accept.png" />
                <?php else: ?>
                <img src="<?php echo INSTALL_URL?>/images/help.png" id="help_<?php echo $id?>" class="help" alt="help.png" />
                <?php if (isset($values['warning']) && $values['warning'] == '1'): ?>
                <img src="<?php echo INSTALL_URL?>/images/error.png" alt="error.png" />
                <?php else: ?>
                <img src="<?php echo INSTALL_URL?>/images/delete.png" alt="delete.png" />
                <?php endif; endif; ?>
            </span>
            <div class="clear"></div>
            <p id="test_<?php echo $id?>" style="display: none;"><?php echo htmlspecialchars($values['error']); ?></p>
            <?php endif; endforeach; ?>
            <h3>Required PHP Settings</h3>
            <?php foreach ($recommended as $id => $values): if (!isset($values['system'])): ?>
            <span class="key"><?php if ($values['status'] !== true): echo '<strong>'; endif; ?><?php echo htmlspecialchars($values['message']); ?><?php if ($values['status'] !== true): echo '</strong>'; endif; ?></span>
            <span class="value">
                  <?php if ($values['status'] === true): ?>
                <img src="<?php echo INSTALL_URL?>/images/accept.png" alt="accept.png" />
                <?php else: ?>
                <img src="<?php echo INSTALL_URL?>/images/help.png" id="help_<?php echo $id?>" class="help" alt="help.png" />
                <?php if ($values['warning'] == '1'): ?>
                <img src="<?php echo INSTALL_URL?>/images/error.png" alt="error.png" />                
                <?php else: ?>
                <img src="<?php echo INSTALL_URL?>/images/delete.png" alt="delete.png" />
                <?php endif; endif; ?>
            </span>
            <div class="clear"></div>
            <p id="test_<?php echo $id?>" style="display: none;"><?php echo htmlspecialchars($values['error']); ?></p>            
            <?php endif; endforeach; ?>
            <h3>Optional Items</h3>
            <?php foreach ($optional as $id => $values): if (!isset($values['system'])): ?>
            <span class="key"><?php if ($values['status'] !== true): echo '<strong>'; endif; ?><?php echo htmlspecialchars($values['message']); ?><?php if ($values['status'] !== true): echo '</strong>'; endif; ?></span>
            <span class="value">
                  <?php if ($values['status'] === true): ?>
                <img src="<?php echo INSTALL_URL?>/images/accept.png" alt="accept.png" />
                <?php else: ?>
                <img src="<?php echo INSTALL_URL?>/images/help.png" id="help_<?php echo $id?>" class="help" alt="help.png" />
                <img src="<?php echo INSTALL_URL?>/images/error.png" alt="error.png" />
                <?php endif; ?>
            </span>
            <div class="clear"></div>
            <p id="test_<?php echo $id?>" style="display: none;"><?php echo htmlspecialchars($values['error']); ?></p>
            <?php endif; endforeach; ?>
            <form name="test-form" method="post" action="<?php echo BASE_URL?>/install/migrate.php?a=test">
            <div class="submit">
                  <input name="submit-test" type="submit" id="submit-test" class="submit" value="Run Tests Again" />
            </div>            
            </form>
        </div>
    </div>
    <div class="right width-475">
        <h2>Migration Options</h2>
        <div class="box-content">
            <h3>Migration Help</h3>
            The below data can be gathered from the MediaXXXScript Configuration file located in <code>/WHERE/MEDIAXXXSCRIPT/IS/INSTALLED/include/config.php</code>!
            <p><strong>Path:</strong> Path where MediaXXXScript is installed on your server (<code>$config['basedir']</code> in the configuration file)!</p>
            <p><strong>Database Server:</strong> MediaXXXScript Database (MySQL) server address (<code>$DBHOST</code> in the configuration file)!</p>
            <p><strong>Database Username:</strong> MediaXXXScript Database (MySQL) username (<code>$DBUSER</code> in the configuration file)!</p>
            <p><strong>Database Password:</strong> MediaXXXScript Database (MySQL) password (<code>$DBPASSWWORD</code> in the configuration file)!</p>
            <p><strong>Database Name:</strong> MediaXXXScript Database (MySQL) Name (<code>$DBNAME</code> in the configuration file)!</p>
            <form id="migrate-form" method="post" action="<?php echo BASE_URL?>/install/migrate-mediaxxxscript.php">
            <input name="submitted" type="hidden" value="1" />
            <h3>Migration Options</h3>
            <div>
                  <label for="m_path">Path</label>
                  <input name="m_path" type="text" id="m_path" class="large" value="<?php echo $config['m_path']; ?>" />
            </div>
            <div class="clear-left">
                <label for="m_db_host">Database Server</label>
                <input name="m_db_host" type="text" id="db_host" value="<?php echo $config['m_db_host']; ?>" />
            </div>
            <div class="clear-left">
                <label for="m_db_username">Database Username</label>
                <input name="m_db_username" type="text" id="db_username" value="<?php echo $config['m_db_username']; ?>" />
            </div>
            <div class="clear-left">
                <label for="m_db_password">Database Password</label>
                <input name="m_db_password" type="password" id="db_password" value="<?php echo $config['m_db_password']; ?>" />
            </div>
            <div class="clear-left">
                <label for="m_db_name">Database Name</label>
                <input name="m_db_name" type="text" id="db_name" value="<?php echo $config['m_db_name']; ?>" />
            </div>
            <div class="submit clear-left">
                <input name="submit-migrate" type="button" id="submit-migrate" class="submit" value="Migrate >"
            </div>            
            </form>
        </div>
    </div>
    <div class="clear"></div>
</div>
</body>
</html>
Онлайн: 2
Реклама