Опубликовано: 20 апреля 201213 г Скрип, написанный "на коленке", конвертирует все теги из мода LastDragon для IP.Board 3.1.x в обыкновенные системные теги линейки 3.3.х. Когда IPBSkins будет обновляться - пригодится :) Запускать строго один раз, лучше всего через консоль - очень много SQL-запросов.<?php class db { private $conn, $res; function __construct($info) { if (! $this->conn = mysql_connect($info['sql_host'], $info['sql_user'], $info['sql_pass'])) die('Нет коннекта к БД'); if (! mysql_select_db($info['sql_database'], $this->conn)) die('Нет базы данных'); } function query($sql) { $this->res = mysql_query($sql); if(!$this->res) echo("<pre>Ошибка БД: ".mysql_error()."\n\n{$sql}"); return $this->res; } function fetch($res = '') { if(!empty($res)) $this->res = $res; return mysql_fetch_array($this->res, MYSQL_ASSOC); } function safe($string) { return mysql_real_escape_string($string, $this->conn); } function insert_id() { return mysql_insert_id($this->conn); } function query_count($sql, $cname = 'CNT') { $row = $this->fetch($this->query($sql)); return !empty($row[$cname]) ? $row[$cname] : 0; } } function getRawTagsByMeta( $meta ) { global $db, $p; $tags = array(); $res = $db->query("SELECT * FROM {$p}core_tags WHERE tag_aai_lookup = '{$meta}' ORDER BY tag_id"); while( $row = $db->fetch($res) ) { $tags[ $row['tag_id'] ] = $row; } return $tags; } include("conf_global.php"); $db = new db($INFO); $p = !empty($INFO['sql_tbl_prefix']) ? $INFO['sql_tbl_prefix'] : ''; $res = $db->query("SELECT tt.*, t.* FROM {$p}tagscloud_topic_tags tt LEFT JOIN {$p}tagscloud_tags t ON t.id = tt.tag_id"); echo "Converting tags...\n"; while($row = $db->fetch($res)) { $data = array( 'tag_aai_lookup' => md5( 'forums;topics;'.$row['topic_id'] ), 'tag_aap_lookup' => md5( 'forums:topics:'.$row['forum_id'] ), 'tag_meta_app' => 'forums', 'tag_meta_area' => 'topics', 'tag_meta_id' => $row['topic_id'], 'tag_meta_parent_id' => $row['forum_id'], 'tag_member_id' => 1, 'tag_added' => time(), 'tag_prefix' => 0, 'tag_text' => $row['text'] ); $db->query("INSERT INTO {$p}core_tags (".implode(",",array_keys($data)).") VALUES ('".implode("','",$data)."')"); $db->query("INSERT INTO {$p}core_tags_perms (tag_perm_aai_lookup, tag_perm_aap_lookup, tag_perm_text, tag_perm_visible) VALUES ('{$data['tag_aai_lookup']}', '{$data['tag_aap_lookup']}', '*', '1')"); $tags = getRawTagsByMeta( $data['tag_aai_lookup'] ); $text = array( 'tags' => array(), 'prefix' => '' ); foreach( $tags as $id => $tag ) { $text['tags'][] = $tag['tag_text']; if ( $tag['tag_prefix'] ) { $text['prefix'] = $tag['tag_text']; } } $update = array( 'tag_cache_key' => $data['tag_aai_lookup'], 'tag_cache_text' => serialize( $text ), 'tag_cache_date' => time() ); $db->query( "REPLACE INTO {$p}core_tags_cache (".implode(",",array_keys($update)).") VALUES ('".implode("','",$update)."')"); } echo "done!\n";
Скрип, написанный "на коленке", конвертирует все теги из мода LastDragon для IP.Board 3.1.x в обыкновенные системные теги линейки 3.3.х.
Когда IPBSkins будет обновляться - пригодится :)
Запускать строго один раз, лучше всего через консоль - очень много SQL-запросов.
<?php class db { private $conn, $res; function __construct($info) { if (! $this->conn = mysql_connect($info['sql_host'], $info['sql_user'], $info['sql_pass'])) die('Нет коннекта к БД'); if (! mysql_select_db($info['sql_database'], $this->conn)) die('Нет базы данных'); } function query($sql) { $this->res = mysql_query($sql); if(!$this->res) echo("<pre>Ошибка БД: ".mysql_error()."\n\n{$sql}"); return $this->res; } function fetch($res = '') { if(!empty($res)) $this->res = $res; return mysql_fetch_array($this->res, MYSQL_ASSOC); } function safe($string) { return mysql_real_escape_string($string, $this->conn); } function insert_id() { return mysql_insert_id($this->conn); } function query_count($sql, $cname = 'CNT') { $row = $this->fetch($this->query($sql)); return !empty($row[$cname]) ? $row[$cname] : 0; } } function getRawTagsByMeta( $meta ) { global $db, $p; $tags = array(); $res = $db->query("SELECT * FROM {$p}core_tags WHERE tag_aai_lookup = '{$meta}' ORDER BY tag_id"); while( $row = $db->fetch($res) ) { $tags[ $row['tag_id'] ] = $row; } return $tags; } include("conf_global.php"); $db = new db($INFO); $p = !empty($INFO['sql_tbl_prefix']) ? $INFO['sql_tbl_prefix'] : ''; $res = $db->query("SELECT tt.*, t.* FROM {$p}tagscloud_topic_tags tt LEFT JOIN {$p}tagscloud_tags t ON t.id = tt.tag_id"); echo "Converting tags...\n"; while($row = $db->fetch($res)) { $data = array( 'tag_aai_lookup' => md5( 'forums;topics;'.$row['topic_id'] ), 'tag_aap_lookup' => md5( 'forums:topics:'.$row['forum_id'] ), 'tag_meta_app' => 'forums', 'tag_meta_area' => 'topics', 'tag_meta_id' => $row['topic_id'], 'tag_meta_parent_id' => $row['forum_id'], 'tag_member_id' => 1, 'tag_added' => time(), 'tag_prefix' => 0, 'tag_text' => $row['text'] ); $db->query("INSERT INTO {$p}core_tags (".implode(",",array_keys($data)).") VALUES ('".implode("','",$data)."')"); $db->query("INSERT INTO {$p}core_tags_perms (tag_perm_aai_lookup, tag_perm_aap_lookup, tag_perm_text, tag_perm_visible) VALUES ('{$data['tag_aai_lookup']}', '{$data['tag_aap_lookup']}', '*', '1')"); $tags = getRawTagsByMeta( $data['tag_aai_lookup'] ); $text = array( 'tags' => array(), 'prefix' => '' ); foreach( $tags as $id => $tag ) { $text['tags'][] = $tag['tag_text']; if ( $tag['tag_prefix'] ) { $text['prefix'] = $tag['tag_text']; } } $update = array( 'tag_cache_key' => $data['tag_aai_lookup'], 'tag_cache_text' => serialize( $text ), 'tag_cache_date' => time() ); $db->query( "REPLACE INTO {$p}core_tags_cache (".implode(",",array_keys($update)).") VALUES ('".implode("','",$update)."')"); } echo "done!\n";