예제 #1
0
파일: update.php 프로젝트: HugoLS/Variation
function gmedia_do_update()
{
    global $wpdb, $gmDB, $gmCore, $gmGallery;
    // 10 minutes execution time
    @set_time_limit(10 * 60);
    if (ob_get_level() == 0) {
        ob_start();
    }
    // upgrade function changed in WordPress 2.3
    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    // add charset & collate like wp core
    $charset_collate = '';
    if ($wpdb->has_cap('collation')) {
        if (!empty($wpdb->charset)) {
            $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
        }
        if (!empty($wpdb->collate)) {
            $charset_collate .= " COLLATE {$wpdb->collate}";
        }
    }
    $gmedia = $wpdb->prefix . 'gmedia';
    $gmedia_term = $wpdb->prefix . 'gmedia_term';
    $gmedia_term_relationships = $wpdb->prefix . 'gmedia_term_relationships';
    $sql = "\n\tCREATE TABLE {$gmedia} (\n\t\tID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\tauthor BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\tdate DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\tdescription LONGTEXT NOT NULL,\n\t\ttitle TEXT NOT NULL,\n\t\tgmuid VARCHAR(255) NOT NULL DEFAULT '',\n\t\tlink VARCHAR(255) NOT NULL DEFAULT '',\n\t\tmodified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\tmime_type VARCHAR(100) NOT NULL DEFAULT '',\n\t\tstatus VARCHAR(20) NOT NULL DEFAULT 'public',\n\t\tPRIMARY KEY  (ID),\n\t\tKEY gmuid (gmuid),\n\t\tKEY type_status_date (mime_type,status,date,ID),\n\t\tKEY author (author)\n\t) {$charset_collate};\n\tCREATE TABLE {$gmedia_term} (\n\t\tterm_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\tname VARCHAR(200) NOT NULL DEFAULT '',\n\t\ttaxonomy VARCHAR(32) NOT NULL DEFAULT '',\n\t\tdescription LONGTEXT NOT NULL,\n\t\tglobal BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\tcount BIGINT(20) NOT NULL DEFAULT '0',\n\t\tstatus VARCHAR(20) NOT NULL DEFAULT 'public',\n\t\tPRIMARY KEY  (term_id),\n\t\tKEY taxonomy (taxonomy),\n\t\tKEY name (name)\n\t) {$charset_collate};\n\tCREATE TABLE {$gmedia_term_relationships} (\n\t\tgmedia_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\tgmedia_term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\tterm_order INT(11) NOT NULL DEFAULT '0',\n\t\tgmedia_order INT(11) NOT NULL DEFAULT '0',\n\t\tPRIMARY KEY  (gmedia_id,gmedia_term_id),\n\t\tKEY gmedia_term_id (gmedia_term_id)\n\t) {$charset_collate}\n\t";
    dbDelta($sql);
    echo '<p>' . __('Gmedia database tables updated...', 'gmLang') . '</p><br>';
    echo '<script type="text/javascript">
var scroll_down = true;
function ScrollDown() {
	if(scroll_down){
		window.scrollTo(0,document.body.scrollHeight);
		scrolldelay = setTimeout(function(){ ScrollDown(); },100);
	}
}
ScrollDown();
window.onload = function() {
	ScrollDown();
  scroll_down = false;
}
</script>';
    echo '<p>' . __('Start update images...', 'gmLang') . '</p>';
    wp_ob_end_flush_all();
    $old_options = get_option('gmediaOptions');
    require_once dirname(__FILE__) . '/setup.php';
    $options = gmedia_default_options();
    if (isset($old_options['product_name'])) {
        $options['license_name'] = $old_options['product_name'];
        $options['license_key'] = $old_options['gmedia_key'];
        $options['license_key2'] = $old_options['gmedia_key2'];
    }
    update_option('gmediaOptions', $options);
    $gmGallery->options = $options;
    $fix_files = glob($gmCore->upload['path'] . '/?*.?*', GLOB_NOSORT);
    if (!empty($fix_files)) {
        foreach ($fix_files as $ff) {
            @rename($ff, $gmCore->upload['path'] . '/image/' . basename($ff));
        }
    }
    $gmedias = $gmDB->get_gmedias(array('mime_type' => 'image/*', 'cache_results' => false));
    $files = array();
    foreach ($gmedias as $gmedia) {
        $files[] = array('id' => $gmedia->ID, 'file' => $gmCore->upload['path'] . '/image/' . $gmedia->gmuid);
    }
    if (!empty($files)) {
        gmedia_images_update($files);
    }
    $gmCore->delete_folder($gmCore->upload['path'] . '/link');
    // try to make gallery dirs if not exists
    foreach ($gmGallery->options['folder'] as $folder) {
        wp_mkdir_p($gmCore->upload['path'] . '/' . $folder);
    }
    $wpdb->update($wpdb->prefix . 'gmedia_term', array('taxonomy' => 'gmedia_album'), array('taxonomy' => 'gmedia_category'));
    $wpdb->update($wpdb->prefix . 'gmedia_term', array('taxonomy' => 'gmedia_gallery'), array('taxonomy' => 'gmedia_module'));
    $gmedias = $gmDB->get_gmedias(array('no_found_rows' => true, 'meta_key' => 'link', 'cache_results' => false));
    foreach ($gmedias as $gmedia) {
        $link = $gmDB->get_metadata('gmedia', $gmedia->ID, 'link', true);
        if ($link) {
            $wpdb->update($wpdb->prefix . 'gmedia', array('link' => $link), array('ID' => $gmedia->ID));
        }
    }
    $wpdb->delete($wpdb->prefix . 'gmedia_meta', array('meta_key' => 'link'));
    //$gmDB->delete_metadata('gmedia', 0, 'link', false, true);
    $wpdb->update($wpdb->prefix . 'gmedia_meta', array('meta_key' => 'cover'), array('meta_key' => 'preview'));
    echo '<p>' . __('Gmedia database data updated...', 'gmLang') . '</p>';
    wp_ob_end_flush_all();
    $galleries = $gmDB->get_terms('gmedia_gallery');
    if ($galleries) {
        foreach ($galleries as $gallery) {
            $old_meta = $gmDB->get_metadata('gmedia_term', $gallery->term_id);
            if (!empty($old_meta)) {
                $old_meta = array_map('reset', $old_meta);
                $old_meta = array_map('maybe_unserialize', $old_meta);
                if (!isset($old_meta['gMediaQuery'])) {
                    continue;
                }
                /*
                $old_meta_keys = array_keys($old_meta);
                foreach($old_meta_keys as $key){
                	$wpdb->delete($wpdb->prefix.'gmedia_term_meta', array('gmedia_term_id' => $gallery->term_id, 'meta_key' => $key));
                	//$gmDB->delete_metadata('gmedia_term', $gallery->term_id, $key);
                }
                */
                $gmedia_category = $gmedia_tag = array();
                foreach ($old_meta['gMediaQuery'] as $tab) {
                    if (isset($tab['cat']) && !empty($tab['cat'])) {
                        $gmedia_category[] = $tab['cat'];
                    }
                    if (isset($tab['tag__in']) && !empty($tab['tag__in'])) {
                        $gmedia_tag = array_merge($gmedia_tag, $tab['tag__in']);
                    }
                }
                $query = array();
                if (!empty($gmedia_category)) {
                    $query = array('gmedia_album' => $gmedia_category);
                } elseif (!empty($gmedia_tag)) {
                    $query = array('gmedia_tag' => $gmedia_tag);
                }
                $gallery_meta = array('edited' => $old_meta['last_edited'], 'module' => $old_meta['module_name'], 'query' => $query);
                foreach ($gallery_meta as $key => $value) {
                    $gmDB->update_metadata('gmedia_term', $gallery->term_id, $key, $value);
                }
            }
        }
    }
    echo '<p>' . __('Gmedia Galleries updated...', 'gmLang') . '</p><br><br>';
    wp_ob_end_flush_all();
    update_option("gmediaDbVersion", GMEDIA_DBVERSION);
    echo '<p>' . __('GmediaGallery plugin update complete.', 'gmLang') . '</p>';
}
예제 #2
0
function gmedia_db_update__0_9_6()
{
    global $wpdb, $gmDB, $gmCore, $gmGallery;
    $info = get_transient('gmediaHeavyJob');
    $info['096_1'] = __('Start update images...', 'grand-media');
    set_transient('gmediaHeavyJob', $info);
    set_transient('gmediaUpgrade', time());
    $old_options = get_option('gmediaOptions');
    require_once dirname(__FILE__) . '/setup.php';
    $options = gmedia_default_options();
    if (isset($old_options['product_name'])) {
        $options['license_name'] = $old_options['product_name'];
        $options['license_key'] = $old_options['gmedia_key'];
        $options['license_key2'] = $old_options['gmedia_key2'];
    }
    update_option('gmediaOptions', $options);
    $gmGallery->options = $options;
    $fix_files = glob($gmCore->upload['path'] . '/?*.?*', GLOB_NOSORT);
    if (!empty($fix_files)) {
        foreach ($fix_files as $ff) {
            @rename($ff, $gmCore->upload['path'] . '/image/' . basename($ff));
        }
    }
    $gmedias = $gmDB->get_gmedias(array('mime_type' => 'image/*', 'cache_results' => false));
    $files = array();
    foreach ($gmedias as $gmedia) {
        $files[] = array('id' => $gmedia->ID, 'file' => $gmCore->upload['path'] . '/image/' . $gmedia->gmuid);
    }
    if (!empty($files)) {
        gmedia_images_update($files);
    }
    $gmCore->delete_folder($gmCore->upload['path'] . '/link');
    // try to make gallery dirs if not exists
    foreach ($gmGallery->options['folder'] as $folder) {
        wp_mkdir_p($gmCore->upload['path'] . '/' . $folder);
    }
    $wpdb->update($wpdb->prefix . 'gmedia_term', array('taxonomy' => 'gmedia_album'), array('taxonomy' => 'gmedia_category'));
    $wpdb->update($wpdb->prefix . 'gmedia_term', array('taxonomy' => 'gmedia_gallery'), array('taxonomy' => 'gmedia_module'));
    $gmedias = $gmDB->get_gmedias(array('no_found_rows' => true, 'meta_key' => 'link', 'cache_results' => false));
    foreach ($gmedias as $gmedia) {
        $link = $gmDB->get_metadata('gmedia', $gmedia->ID, 'link', true);
        if ($link) {
            $wpdb->update($wpdb->prefix . 'gmedia', array('link' => $link), array('ID' => $gmedia->ID));
        }
    }
    $wpdb->delete($wpdb->prefix . 'gmedia_meta', array('meta_key' => 'link'));
    $wpdb->update($wpdb->prefix . 'gmedia_meta', array('meta_key' => '_cover'), array('meta_key' => 'preview'));
    $info['096_2'] = __('Gmedia database data updated...', 'grand-media');
    set_transient('gmediaHeavyJob', $info);
    set_transient('gmediaUpgrade', time());
    $galleries = $gmDB->get_terms('gmedia_gallery');
    if ($galleries) {
        foreach ($galleries as $gallery) {
            $old_meta = $gmDB->get_metadata('gmedia_term', $gallery->term_id);
            if (!empty($old_meta)) {
                $old_meta = array_map('reset', $old_meta);
                if (!isset($old_meta['gMediaQuery'])) {
                    continue;
                }
                $gmedia_category = $gmedia_tag = array();
                foreach ($old_meta['gMediaQuery'] as $tab) {
                    if (isset($tab['cat']) && !empty($tab['cat'])) {
                        $gmedia_category[] = $tab['cat'];
                    }
                    if (isset($tab['tag__in']) && !empty($tab['tag__in'])) {
                        $gmedia_tag = array_merge($gmedia_tag, $tab['tag__in']);
                    }
                }
                $query = array();
                if (!empty($gmedia_category)) {
                    $query = array('gmedia_album' => $gmedia_category);
                } elseif (!empty($gmedia_tag)) {
                    $query = array('gmedia_tag' => $gmedia_tag);
                }
                $gallery_meta = array('_edited' => $old_meta['last_edited'], '_module' => $old_meta['module_name'], '_query' => $query);
                foreach ($gallery_meta as $key => $value) {
                    $gmDB->update_metadata('gmedia_term', $gallery->term_id, $key, $value);
                }
            }
        }
    }
    update_option("gmediaDbVersion", '0.9.6');
    $info['096_3'] = __('Gmedia Galleries updated...', 'grand-media');
    set_transient('gmediaHeavyJob', $info);
    set_transient('gmediaUpgrade', time());
    //wp_schedule_single_event(time() + 2, 'gmedia_db_update');
    gmedia_db_update();
}