/**
 * @package iMegaTeleport
 * @version 1.6.14
 * 
 * Copyright 2013 iMega ltd (email: info@imega.ru)
 *
 * This program is free software you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
set@baseurl='{$baseurl}';set@imgpath='{$imgpath}';set session group_concat_max_len=1000000;update {$table_prefix}options set option_value=55 where option_name='imegateleport_progress';delete from {$table_prefix}options where option_name like'imegateleport_stat%';insert {$table_prefix}options(option_name,option_value)value('imegateleport_stat_date',UNIX_TIMESTAMP(CURRENT_TIMESTAMP));drop table if exists {$table_prefix}imegaBuffer,{$table_prefix}imegaAttrs,{$table_prefix}compareGroups,{$table_prefix}compareGroupsUpdate,{$table_prefix}compareGroupsUnique,{$table_prefix}groupsUpdate;create table {$table_prefix}compareGroups select pt.id,pt.guid,pt.title,pt.slug,pt.parent from {$table_prefix}imega_groups pt left join {$table_prefix}imegateleport p on p.guid=pt.guid where p.guid is null;insert {$table_prefix}options(option_name,option_value)select'imegateleport_stat_groups',count(id)from {$table_prefix}compareGroups;create table {$table_prefix}compareGroupsUpdate select pt.id,pt.guid,p.title,p.slug,p.parent from {$table_prefix}imegateleport pt join {$table_prefix}imega_groups p on p.guid=pt.guid group by guid;insert {$table_prefix}options(option_name,option_value)select'imegateleport_stat_groups_replace',count(id)from {$table_prefix}compareGroupsUpdate;create table {$table_prefix}compareGroupsUnique select u.id,u.guid,u.title,u.slug,u.parent from(select cg.id,cg.guid,cg.title,cg.slug,cg.parent from {$table_prefix}compareGroups cg left join {$table_prefix}terms t on t.slug=cg.slug where t.slug is null)u group by u.slug;insert {$table_prefix}terms(name,slug)select title,slug from {$table_prefix}compareGroupsUnique;insert {$table_prefix}imegateleport(object_id,name,guid)select t.term_id,'terms',cgu.guid from {$table_prefix}compareGroupsUnique cgu left join {$table_prefix}terms t on t.slug=cgu.slug;set@maxID=(select CAST(ifnull(max(term_id),1)as char)from {$table_prefix}terms);insert {$table_prefix}terms(name,slug)select cg.title,concat(cg.slug,(cg.id+@maxID))slug from {$table_prefix}compareGroups cg left join {$table_prefix}compareGroupsUnique cu on cu.guid=cg.guid where cu.guid is null;insert {$table_prefix}imegateleport(object_id,name,guid)select t.term_id,'terms',cg.guid from {$table_prefix}compareGroups cg left join {$table_prefix}compareGroupsUnique cu on cu.guid=cg.guid left join {$table_prefix}terms t on t.slug=concat(cg.slug,(cg.id+@maxID))where cu.guid is null;insert {$table_prefix}term_taxonomy(term_id,taxonomy,description,parent)select t.term_id,'department','',ifnull(parent.term_id,0)parent from {$table_prefix}compareGroups cg left join {$table_prefix}compareGroupsUnique cu on cu.guid=cg.guid left join {$table_prefix}terms t on cg.slug=t.slug left join {$table_prefix}compareGroups cuparent on cg.parent=cuparent.guid left join {$table_prefix}terms parent on cuparent.slug=parent.slug where cu.guid is not null union select t.term_id,'department','',ifnull(parent.term_id,0)parent from {$table_prefix}compareGroups cg left join {$table_prefix}compareGroupsUnique cu on cu.guid=cg.guid left join {$table_prefix}terms t on concat(cg.slug,(cg.id+@maxID))=t.slug left join {$table_prefix}compareGroups cuparent on cg.parent=cuparent.guid left join {$table_prefix}terms parent on cuparent.slug=parent.slug where cu.guid is null;insert {$table_prefix}imegateleport(object_id,name,guid)select tt.term_taxonomy_id,'term_taxonomy',cg.guid from {$table_prefix}compareGroups cg left join {$table_prefix}compareGroupsUnique cu on cu.guid=cg.guid left join {$table_prefix}terms t on cg.slug=t.slug left join {$table_prefix}term_taxonomy tt on tt.term_id=t.term_id where cu.guid is not null union select tt.term_taxonomy_id,'term_taxonomy',cg.guid from {$table_prefix}compareGroups cg left join {$table_prefix}compareGroupsUnique cu on cu.guid=cg.guid left join {$table_prefix}terms t on concat(cg.slug,(cg.id+@maxID))=t.slug left join {$table_prefix}term_taxonomy tt on tt.term_id=t.term_id where cu.guid is null;update {$table_prefix}options set option_value=60 where option_name='imegateleport_progress';create table {$table_prefix}groupsUpdate select tt.term_id,cgu.title,nullif(cgu.slug,t.slug)slug,tt.term_taxonomy_id,tt.taxonomy,parent_tt.term_id parent from {$table_prefix}compareGroupsUpdate cgu left join {$table_prefix}imegateleport tp on tp.guid=cgu.guid left join {$table_prefix}term_taxonomy tt on tt.term_taxonomy_id=tp.object_id left join {$table_prefix}terms t on t.term_id=tt.term_id and t.slug=cgu.slug left join {$table_prefix}imegateleport parent_tp on parent_tp.guid=cgu.parent left join {$table_prefix}term_taxonomy parent_tt on parent_tt.term_taxonomy_id=parent_tp.object_id and parent_tt.term_id<>tt.parent where t.slug is null or parent_tt.term_taxonomy_id is not null;replace {$table_prefix}terms(term_id,name,slug)select term_id,title,slug from {$table_prefix}groupsUpdate where parent is null;replace {$table_prefix}term_taxonomy(term_taxonomy_id,term_id,taxonomy,parent)select term_taxonomy_id,term_id,taxonomy,parent from {$table_prefix}groupsUpdate where slug is null;drop table if exists {$table_prefix}compareGroups,{$table_prefix}compareGroupsUpdate,{$table_prefix}compareGroupsUnique,{$table_prefix}groupsUpdate;update {$table_prefix}options set option_value=65 where option_name='imegateleport_progress';drop table if exists {$table_prefix}compareGoods,{$table_prefix}compareGoodsUnique;create table {$table_prefix}compareGoods select c.id,c.guid,c.post_title,c.post_content,c.post_name,c.catalogGuid,c.img,c.img_prop,c.action,m.label from(select pr.id,pr.guid,title post_title,descr post_content,pr.slug post_name,catalog_guid catalogGuid,pr.img,pr.img_prop,'insert'action from {$table_prefix}imega_prod pr left join {$table_prefix}imegateleport p on p.guid=pr.guid where p.guid is null union select pr.id,pr.guid,title post_title,descr post_content,pr.slug post_name,catalog_guid catalogGuid,pr.img,pr.img_prop,'update'action from {$table_prefix}imegateleport p join {$table_prefix}imega_prod pr on p.guid=pr.guid)c left join {$table_prefix}imega_misc m on m.guid=c.guid where m.type='group';insert {$table_prefix}options(option_name,option_value)select'imegateleport_stat_goods',count(id)from {$table_prefix}compareGoods where action='insert';insert {$table_prefix}options(option_name,option_value)select'imegateleport_stat_goods_replace',count(id)from {$table_prefix}compareGoods where action='update';create table {$table_prefix}compareGoodsUnique select cg.id,cg.guid,cg.post_title,cg.post_content,cg.post_name,cg.catalogGuid,cg.img,cg.img_prop,cg.action,cg.label from(select*from {$table_prefix}compareGoods group by post_name)cg left join {$table_prefix}posts p on p.post_name=cg.post_name where p.post_name is null;insert {$table_prefix}posts(post_date,post_date_gmt,post_content,post_title,post_name,post_type,post_excerpt,to_ping,pinged,post_content_filtered)select CURRENT_TIMESTAMP,UTC_TIMESTAMP,post_content,post_title,post_name,'products','','','',''from {$table_prefix}compareGoodsUnique where action='insert';replace {$table_prefix}posts(id,post_content,post_title,post_name,post_modified,post_modified_gmt,post_type,post_excerpt,to_ping,pinged,post_content_filtered)select p.object_id,post_content,post_title,post_name,CURRENT_TIMESTAMP,UTC_TIMESTAMP,'products','','','',''from {$table_prefix}compareGoodsUnique cgu left join {$table_prefix}imegateleport p on p.guid=cgu.guid where action='update';delete from {$table_prefix}postmeta where post_id in(select p.object_id from {$table_prefix}compareGoodsUnique cgu left join {$table_prefix}imegateleport p on p.guid=cgu.guid where action='update');delete from {$table_prefix}term_relationships where object_id in(select p.object_id from {$table_prefix}compareGoodsUnique cgu left join {$table_prefix}imegateleport p on p.guid=cgu.guid where action='update');delete from {$table_prefix}posts where post_parent in(select p.object_id from {$table_prefix}compareGoodsUnique cgu left join {$table_prefix}imegateleport p on p.guid=cgu.guid where action='update');insert {$table_prefix}posts(post_date,post_date_gmt,post_status,post_parent,guid,post_type,post_mime_type,post_excerpt,to_ping,pinged,post_content_filtered)select CURRENT_TIMESTAMP,UTC_TIMESTAMP,'inherit',p.id,concat(@baseurl,@imgpath,pr.img),'attachment','image/jpeg','','','',''from {$table_prefix}compareGoodsUnique cu left join {$table_prefix}imega_prod pr on pr.guid=cu.guid left join {$table_prefix}posts p on p.post_name=cu.post_name where pr.img is not null and pr.img<>'';insert {$table_prefix}imegateleport(object_id,name,guid)select p.id object_id,'posts'name,cu.guid guid from {$table_prefix}compareGoodsUnique cu left join {$table_prefix}posts p on p.post_name=cu.post_name where cu.action='insert';insert {$table_prefix}postmeta(post_id,meta_key,meta_value)select img.id,'_{$table_prefix}attached_file',concat(@imgpath,cgu.img)from {$table_prefix}posts p left join {$table_prefix}compareGoodsUnique cgu on cgu.post_name=p.post_name left join {$table_prefix}posts img on img.guid=concat(@baseurl,@imgpath,cgu.img)where p.post_type<>'attachment'and cgu.img<>''union select img.id,'_{$table_prefix}attachment_metadata',cgu.img_prop from {$table_prefix}posts p left join {$table_prefix}compareGoodsUnique cgu on cgu.post_name=p.post_name left join {$table_prefix}posts img on img.guid=concat(@baseurl,@imgpath,cgu.img)where p.post_type<>'attachment'and cgu.img_prop<>''union select p.id,'_thumbnail_id',img.id from {$table_prefix}posts p left join {$table_prefix}compareGoodsUnique cgu on cgu.post_name=p.post_name left join {$table_prefix}posts img on img.guid=concat(@baseurl,@imgpath,cgu.img)where p.post_type<>'attachment'and cgu.img_prop<>'';insert {$table_prefix}term_relationships(object_id,term_taxonomy_id)select p.id,tp.object_id from {$table_prefix}posts p left join {$table_prefix}compareGoodsUnique cu on cu.post_name=p.post_name left join {$table_prefix}imegateleport tp on tp.guid=cu.label where p.post_type<>'attachment'and tp.name='term_taxonomy'and tp.object_id is not null;delete from {$table_prefix}compareGoods where guid in(select guid from {$table_prefix}compareGoodsUnique);drop table if exists {$table_prefix}compareGoodsUnique;set@maxID=(select CAST(ifnull(max(id),1)as char)from {$table_prefix}posts);update {$table_prefix}options set option_value=70 where option_name='imegateleport_progress';replace {$table_prefix}posts(id,post_content,post_title,post_name,post_modified,post_modified_gmt,post_type,post_excerpt,to_ping,pinged,post_content_filtered)select tp.object_id,cg.post_content,cg.post_title,concat(cg.post_name,(cg.id+@maxID)),CURRENT_TIMESTAMP,UTC_TIMESTAMP,'products','','','',''from {$table_prefix}compareGoods cg left join {$table_prefix}imegateleport tp on tp.guid=cg.guid left join {$table_prefix}posts p on p.id=tp.object_id and p.post_name=cg.post_name where cg.action='update'and p.post_name is null;delete from {$table_prefix}postmeta where post_id in(select p.object_id from {$table_prefix}compareGoods cg left join {$table_prefix}imegateleport p on p.guid=cg.guid where action='update');delete from {$table_prefix}term_relationships where object_id in(select p.object_id from {$table_prefix}compareGoods cg left join {$table_prefix}imegateleport p on p.guid=cg.guid where action='update');delete from {$table_prefix}posts where post_parent in(select p.object_id from {$table_prefix}compareGoods cg left join {$table_prefix}imegateleport p on p.guid=cg.guid where action='update');insert {$table_prefix}posts(post_date,post_date_gmt,post_content,post_title,post_name,post_type,post_excerpt,to_ping,pinged,post_content_filtered)select CURRENT_TIMESTAMP,UTC_TIMESTAMP,post_content,post_title,concat(post_name,(id+@maxID)),'products','','','',''from {$table_prefix}compareGoods where action='insert';insert {$table_prefix}posts(post_date,post_date_gmt,post_status,post_parent,guid,post_type,post_mime_type,post_excerpt,to_ping,pinged,post_content_filtered)select CURRENT_TIMESTAMP,UTC_TIMESTAMP,'inherit',p.id,concat(@baseurl,@imgpath,pr.img),'attachment','image/jpeg','','','',''from {$table_prefix}compareGoods cg left join {$table_prefix}imega_prod pr on pr.guid=cg.guid left join {$table_prefix}posts p on p.post_name=concat(cg.post_name,(cg.id+@maxID))where pr.img is not null and pr.img<>'';insert {$table_prefix}postmeta(post_id,meta_key,meta_value)select p.id,'_{$table_prefix}attached_file',concat(@imgpath,cg.img)from {$table_prefix}posts p left join {$table_prefix}compareGoods cg on concat(cg.post_name,(cg.id+@maxID))=p.post_name left join {$table_prefix}posts img on img.guid=concat(@baseurl,@imgpath,cg.img)where p.post_type<>'attachment'and cg.img<>''union select p.id,'_{$table_prefix}attachment_metadata',cg.img_prop from {$table_prefix}posts p left join {$table_prefix}compareGoods cg on concat(cg.post_name,(cg.id+@maxID))=p.post_name left join {$table_prefix}posts img on img.guid=concat(@baseurl,@imgpath,cg.img)where p.post_type<>'attachment'and cg.img_prop<>''union select p.id,'_thumbnail_id',img.id from {$table_prefix}posts p left join {$table_prefix}compareGoods cg on concat(cg.post_name,(cg.id+@maxID))=p.post_name left join {$table_prefix}posts img on img.guid=concat(@baseurl,@imgpath,cg.img)where p.post_type<>'attachment'and cg.img_prop<>'';insert {$table_prefix}term_relationships(object_id,term_taxonomy_id)select p.id,tp.object_id from {$table_prefix}posts p left join {$table_prefix}compareGoods cg on concat(cg.post_name,(cg.id+@maxID))=p.post_name left join {$table_prefix}imegateleport tp on tp.guid=cg.label where tp.object_id is not null and tp.name='term_taxonomy';insert {$table_prefix}term_relationships(object_id,term_taxonomy_id)select tp.object_id,tpg.object_id from {$table_prefix}compareGoods cg left join {$table_prefix}imegateleport tp on tp.guid=cg.guid left join {$table_prefix}posts p on p.id=tp.object_id and p.post_name=cg.post_name left join {$table_prefix}imegateleport tpg on tpg.guid=cg.label where cg.action='update'and tpg.object_id is not null and tpg.name='term_taxonomy';insert {$table_prefix}imegateleport(object_id,name,guid)select p.id,'posts',cg.guid from {$table_prefix}compareGoods cg left join {$table_prefix}posts p on p.post_name=concat(cg.post_name,(cg.id+@maxID))where cg.action='insert';drop table if exists {$table_prefix}compareGoods,{$table_prefix}imegaBuffer,{$table_prefix}imegaAttrs;create table {$table_prefix}imegaBuffer(id int,guid varchar(38),name varchar(200),val varchar(200),uni char(6),attr varchar(200),key guid(guid),key val(val),key uni(uni));insert {$table_prefix}imegaBuffer(guid,name,val,uni,attr)select m.guid,m.val,m.valSlug,'unique',m.labelSlug from {$table_prefix}imega_misc m left join {$table_prefix}terms t on t.slug=m.valSlug where type='attr'and t.slug is null and m.label<>'ОписаниеФайла'group by m.valSlug;set@maxID=(select CAST(ifnull(max(term_id),1)as char)from {$table_prefix}terms);insert {$table_prefix}imegaBuffer(id,guid,name,val,uni,attr)select m.id,m.guid,m.val,concat(m.valSlug,(m.id+@maxID))slug,'',m.labelSlug from {$table_prefix}imega_misc m left join {$table_prefix}terms t on t.slug=m.valSlug left join {$table_prefix}imegaBuffer b on b.val=m.valSlug and b.attr=m.labelSlug left join {$table_prefix}term_taxonomy tt on tt.taxonomy=concat('pa_',m.labelSlug)where type='attr'and b.val is null and m.label<>'ОписаниеФайла'and tt.term_taxonomy_id is null group by m.valSlug;insert {$table_prefix}terms(name,slug)select name,val from {$table_prefix}imegaBuffer;insert {$table_prefix}imegateleport(object_id,name)select term_id,('terms')from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val;insert {$table_prefix}term_taxonomy(term_id,taxonomy,description)select t.term_id,concat('pa_',b.attr),''from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val;insert {$table_prefix}imegateleport(object_id,name)select tt.term_taxonomy_id,('term_taxonomy')from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}term_taxonomy tt on tt.term_id=t.term_id;insert ignore {$table_prefix}term_relationships(object_id,term_taxonomy_id)select tp.object_id,tt.term_taxonomy_id from {$table_prefix}imega_misc m left join {$table_prefix}imegateleport tp on tp.guid=m.guid left join {$table_prefix}term_taxonomy tt on tt.taxonomy=concat('pa_',m.labelSlug)left join {$table_prefix}terms t on t.term_id=tt.term_id where type='attr'and t.name=m.val and m.label<>'ОписаниеФайла'and tp.object_id is not null;truncate table {$table_prefix}imegaBuffer;set@maxID=(select CAST(ifnull(max(term_id),1)as char)from {$table_prefix}terms);insert {$table_prefix}imegaBuffer(guid,name,val,uni)select p.guid,p.title,p.slug,'unique'from {$table_prefix}imega_prop p left join {$table_prefix}terms t on t.slug=p.slug where t.slug is null and p.val_type is null group by p.slug;insert {$table_prefix}imegaBuffer(guid,name,val)select p.guid,p.title,concat(p.slug,(@maxID+p.id))from {$table_prefix}imega_prop p left join {$table_prefix}terms t on t.slug=p.slug left join {$table_prefix}imegateleport tp on tp.guid=p.guid left join {$table_prefix}imegaBuffer b on b.guid=p.guid where p.val_type is null and b.guid is null;insert {$table_prefix}terms(name,slug)select name,val from {$table_prefix}imegaBuffer;insert {$table_prefix}imegateleport(object_id,name,guid)select t.term_id,'terms',b.guid from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}imega_prop p on p.guid=b.guid;insert {$table_prefix}term_taxonomy(term_id,taxonomy,description)select t.term_id,concat('pa_',pp.slug),''from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}imega_prop p on p.guid=b.guid left join {$table_prefix}imega_prop pp on p.parent_guid=pp.guid;insert {$table_prefix}imegateleport(object_id,name)select tt.term_taxonomy_id,'term_taxonomy'from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}term_taxonomy tt on tt.term_id=t.term_id;insert {$table_prefix}term_relationships(object_id,term_taxonomy_id)select tp.object_id,tt.term_taxonomy_id from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}term_taxonomy tt on tt.term_id=t.term_id left join {$table_prefix}imega_misc m on m.val=b.guid left join {$table_prefix}imegateleport tp on tp.guid=m.guid where tp.object_id is not null;truncate table {$table_prefix}imegaBuffer;insert {$table_prefix}imegaBuffer(id,name,val,uni)select m.id,m.val,m.valSlug,'unique'from {$table_prefix}imega_prop p left join {$table_prefix}imega_misc m on m.label=p.guid left join {$table_prefix}terms t on t.slug=m.valSlug where t.slug is null and p.val_type='text'group by m.valSlug;set@maxID=(select CAST(ifnull(max(term_id),1)as char)from {$table_prefix}terms);insert {$table_prefix}imegaBuffer(id,name,val)select m.id,m.val,concat(m.valSlug,@maxID+m.id)from {$table_prefix}imega_prop p left join {$table_prefix}imega_misc m on m.label=p.guid left join {$table_prefix}terms t on t.slug=m.valSlug where t.slug is not null and p.val_type='text';insert {$table_prefix}terms(name,slug)select name,val from {$table_prefix}imegaBuffer;insert {$table_prefix}imegateleport(object_id,name)select t.term_id,'terms'from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val;insert {$table_prefix}term_taxonomy(term_id,taxonomy,description)select t.term_id,concat('pa_',p.slug),''from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}imega_misc m on m.id=b.id left join {$table_prefix}imega_prop p on p.guid=m.label;insert {$table_prefix}imegateleport(object_id,name)select term_taxonomy_id,'term_taxonomy'from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}term_taxonomy tt on tt.term_id=t.term_id;create table {$table_prefix}imegaAttrs(post int,taxonomy int,json varchar(250));update {$table_prefix}options set option_value=75 where option_name='imegateleport_progress';insert {$table_prefix}postmeta(post_id,meta_key,meta_value)select p.id,'_product_info_product_price',op.price from {$table_prefix}imega_offers_prices op left join {$table_prefix}posts p on p.post_name=op.offer_guid where p.id is not null union select p.id,'_product_info_product_price',op.price from {$table_prefix}imega_offers_prices op left join {$table_prefix}imegateleport t on t.guid=op.offer_guid left join {$table_prefix}posts p on p.id=t.object_id where p.id is not null;update {$table_prefix}options set option_value=80 where option_name='imegateleport_progress';truncate table {$table_prefix}imegaBuffer;insert {$table_prefix}imegaBuffer(id,name,val,uni,attr)select of.id,of.val,of.valSlug,'unique',of.titleSlug from {$table_prefix}imega_offers_features of left join {$table_prefix}terms t on t.slug=of.valSlug where t.slug is null group by of.valSlug;set@maxID=(select CAST(ifnull(max(term_id),1)as char)from {$table_prefix}terms);insert {$table_prefix}imegaBuffer(id,name,val,attr)select of.id,of.val,concat(of.valSlug,(@maxID+of.id)),of.titleSlug from {$table_prefix}imega_offers_features of left join {$table_prefix}terms t on t.slug=of.valSlug left join {$table_prefix}imegaBuffer b on b.val=of.valSlug and b.attr=of.titleSlug where b.id is null group by of.valSlug,titleSlug;insert {$table_prefix}terms(name,slug)select name,val from {$table_prefix}imegaBuffer;update {$table_prefix}options set option_value=85 where option_name='imegateleport_progress';insert {$table_prefix}term_taxonomy(term_id,taxonomy,description)select t.term_id,concat('pa_',of.titleSlug),''from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}imega_offers_features of on of.id=b.id;insert {$table_prefix}imegateleport(object_id,name)select t.term_id,'terms'from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val union select term_taxonomy_id,'term_taxonomy'from {$table_prefix}imegaBuffer b left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}term_taxonomy tt on tt.term_id=t.term_id;insert {$table_prefix}term_relationships(object_id,term_taxonomy_id)select tp.object_id,tt.term_taxonomy_id from {$table_prefix}imega_prod p left join {$table_prefix}imegateleport tp on tp.guid=p.guid left join {$table_prefix}imega_offers_features of on of.prodGuid=p.guid left join {$table_prefix}imegaBuffer b on of.titleSlug=b.attr and of.val=b.name left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}term_taxonomy tt on tt.term_id=t.term_id where of.id is not null group by tp.object_id,tt.term_taxonomy_id;update {$table_prefix}options set option_value=90 where option_name='imegateleport_progress';insert {$table_prefix}postmeta(post_id,meta_key,meta_value)select post,'_product_attributes',concat('a:',count(post),':{',group_concat(json separator''),'}')from {$table_prefix}imegaAttrs group by post;insert {$table_prefix}postmeta(post_id,meta_key,meta_value)select po.id,concat('attribute_',tt.taxonomy),t.slug from {$table_prefix}imega_prod p left join {$table_prefix}imegateleport tp on tp.guid=p.guid left join {$table_prefix}imega_offers_features of on of.prodGuid=p.guid left join {$table_prefix}posts po on po.post_name=of.offer_guid left join {$table_prefix}imegaBuffer b on of.titleSlug=b.attr and of.val=b.name left join {$table_prefix}terms t on t.slug=b.val left join {$table_prefix}term_taxonomy tt on tt.term_id=t.term_id where of.id is not null;update {$table_prefix}options set option_value=95 where option_name='imegateleport_progress';drop table if exists {$table_prefix}imegaBuffer,{$table_prefix}imegaAttrs,{$table_prefix}imega_groups,{$table_prefix}imega_misc,{$table_prefix}imega_offers,{$table_prefix}imega_prop,{$table_prefix}imega_offers_features,{$table_prefix}imega_offers_prices,{$table_prefix}imega_prod;update {$table_prefix}options set option_value=100 where option_name='imegateleport_progress';