159 lines
3.9 KiB
PHP
159 lines
3.9 KiB
PHP
<?php
|
|
define(ROOT, "../../");
|
|
require_once(ROOT."include/db.inc.php");
|
|
require_once(ROOT."include/array.inc.php");
|
|
define(DB_OLD, "usr_web7_1");
|
|
define(DB_NEW, "flexicon2");
|
|
|
|
// === SQL FUNCTIONS =========================================================================== //
|
|
|
|
# selects a database
|
|
function select($db){
|
|
//mysql_select_db($db);
|
|
}
|
|
|
|
# executes an insert query
|
|
function insert($query){
|
|
mysql_query($query);
|
|
return mysql_insert_id();
|
|
}
|
|
|
|
# executes an update query
|
|
function update($query){
|
|
mysql_query($query);
|
|
}
|
|
|
|
# returns the result set
|
|
function getAll($query){
|
|
return mysql_query($query);
|
|
}
|
|
|
|
# returns one result line
|
|
function getOne($query){
|
|
$r = mysql_query($query);
|
|
return mysqli_fetch_array($r, MYSQLI_ASSOC);
|
|
}
|
|
|
|
|
|
// === IMPORT FUNCTIONS ========================================================================= //
|
|
|
|
|
|
# imports the headings
|
|
function importHeadings(){
|
|
|
|
select(DB_NEW);
|
|
$query = sprintf("SELECT id,name,classId FROM bruckmuehle_index WHERE class = 'PersonPage'");
|
|
$result = getAll($query);
|
|
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
|
|
importPersonPage($line['id'], $line['name'], $line['classId']);
|
|
}
|
|
echo "<hr>";
|
|
|
|
select(DB_NEW);
|
|
$query = sprintf("SELECT id,name,classId FROM bruckmuehle_index WHERE class = 'TicketPage'");
|
|
$result = getAll($query);
|
|
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
|
|
importTicketPage($line['id'], $line['name'], $line['classId']);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
# imports the headings for a person page
|
|
function importPersonPage($id, $name, $classId){
|
|
|
|
select(DB_OLD);
|
|
$line = getOne(sprintf("SELECT * FROM flexicon_personpage WHERE name = %s", sqlstring($name)));
|
|
|
|
if(!empty($line)){
|
|
echo "import personpage $line[name] » $name<br>\n";
|
|
}
|
|
else{
|
|
echo "!!! personpage not found: $name<br>\n";
|
|
return;
|
|
}
|
|
|
|
select(DB_NEW);
|
|
$line2 = getOne(sprintf("SELECT buildingBlocks FROM bruckmuehle_stdpage WHERE id = %d", $classId));
|
|
|
|
$ids = explode("\t", $line['childElements']);
|
|
$types = explode("\t", $line['childTypes']);
|
|
$blocks = explode("\t", $line2['buildingBlocks']);
|
|
|
|
foreach($ids as $i=>$id){
|
|
if(strtolower($types[$i]) == "headerelement"){
|
|
$blocks = array_insert($blocks, $i, importHeadingBlock($id));
|
|
}
|
|
}
|
|
|
|
select(DB_NEW);
|
|
$query = sprintf("UPDATE bruckmuehle_stdpage SET buildingBlocks = %s WHERE id = %d",
|
|
sqlstring(implode("\t", $blocks)),
|
|
$classId);
|
|
update($query);
|
|
}
|
|
|
|
|
|
# imports the headings for a ticket page
|
|
function importTicketPage($id, $name, $classId){
|
|
|
|
select(DB_OLD);
|
|
$line = getOne(sprintf("SELECT * FROM flexicon_stdpage WHERE name = %s", sqlstring($name)));
|
|
|
|
if(!empty($line)){
|
|
echo "import ticketpage $line[name] » $name<br>\n";
|
|
}
|
|
else{
|
|
echo "!!! ticketpage not found: $name<br>\n";
|
|
return;
|
|
}
|
|
|
|
select(DB_NEW);
|
|
$line2 = getOne(sprintf("SELECT buildingBlocks FROM bruckmuehle_stdpage WHERE id = %d", $classId));
|
|
|
|
$ids = explode("\t", $line['childElements']);
|
|
$types = explode("\t", $line['childTypes']);
|
|
$blocks = explode("\t", $line2['buildingBlocks']);
|
|
|
|
foreach($ids as $i=>$id){
|
|
if(strtolower($types[$i]) == "headerelement"){
|
|
$blocks = array_insert($blocks, $i, importHeadingBlock($id));
|
|
}
|
|
}
|
|
|
|
select(DB_NEW);
|
|
$query = sprintf("UPDATE bruckmuehle_stdpage SET buildingBlocks = %s WHERE id = %d",
|
|
sqlstring(implode("\t", $blocks)),
|
|
$classId);
|
|
update($query);
|
|
}
|
|
|
|
|
|
# imports a heading block
|
|
# returns id
|
|
function importHeadingBlock($id){
|
|
|
|
select(DB_OLD);
|
|
$line = getOne(sprintf("SELECT * FROM flexicon_headerelement WHERE id = %d", $id));
|
|
|
|
select(DB_NEW);
|
|
$query = sprintf("INSERT INTO bruckmuehle_headingblock (content, level) VALUES (%s, %d)",
|
|
sqlstring($line['content']),
|
|
$line['level']);
|
|
$blockId = insert($query);
|
|
return "headingblock,$blockId";
|
|
}
|
|
|
|
|
|
// === MAIN ===================================================================================== //
|
|
|
|
mysql_connect(DBHOST, DBUSER, DBPWD);
|
|
mysql_select_db(DB_OLD);
|
|
importHeadings();
|
|
mysql_close();
|
|
echo "<b>import complete</b>";
|
|
|
|
|
|
|
|
|
|
?>
|