public static function migrateNotes($v1GameId, $v2GameId, $maps) { $noteIdMap = array(); $noteIdMap[0] = 0; $commentIdMap = array(); $commentIdMap[0] = 0; $userIdMap = array(); $userIdMap[0] = 0; $notes = migration_dbconnection::queryArray("SELECT * FROM notes WHERE game_id = '{$v1GameId}'", "v1"); $properNotes = array(); $commentNotes = array(); for ($i = 0; $i < count($notes); $i++) { if (!$userIdMap[$notes[$i]->owner_id]) { $userIdMap[$notes[$i]->owner_id] = migration::forceMigratePlayer($notes[$i]->owner_id); } if ($notes[$i]->parent_note_id) { $commentNotes[] = $notes[$i]; } else { $properNotes[] = $notes[$i]; } } for ($i = 0; $i < count($properNotes); $i++) { $noteIdMap[$properNotes[$i]->note_id] = 0; //set it to 0 in case of failure if ($properNotes[$i]->incomplete) { continue; } $newNoteId = migration_dbconnection::queryInsert("INSERT INTO notes (game_id, user_id, name, description, media_id, created) VALUES ('{$v2GameId}','{$userIdMap[$properNotes[$i]->owner_id]}','" . addslashes($properNotes[$i]->title) . "','" . addslashes($properNotes[$i]->title) . "','0','{$properNotes[$i]->created}');", "v2"); $notetags = migration_dbconnection::queryArray("SELECT * FROM note_tags WHERE note_id = '{$properNotes[$i]->note_id}';", "v1"); for ($j = 0; $j < count($notetags); $j++) { migration_dbconnection::queryInsert("INSERT INTO object_tags (game_id, object_type, object_id, tag_id, created) VALUES ('{$v2GameId}','NOTE','{$newNoteId}','{$maps->note_tags[$notetags[$j]->tag_id]}',CURRENT_TIMESTAMP);", "v2"); } $noteIdMap[$properNotes[$i]->note_id] = $newNoteId; } for ($i = 0; $i < count($commentNotes); $i++) { $commentIdMap[$commentNotes[$i]->note_id] = 0; //set it to 0 in case of failure $newCommentId = migration_dbconnection::queryInsert("INSERT INTO note_comments (game_id, note_id, user_id, name, description, created) VALUES ('{$v2GameId}','{$noteIdMap[$commentNotes[$i]->parent_note_id]}','{$userIdMap[$commentNotes[$i]->owner_id]}','" . addslashes($commentNotes[$i]->title) . "','" . addslashes($commentNotes[$i]->title) . "',CURRENT_TIMESTAMP)", "v2"); $commentIdMap[$commentNotes[$i]->note_id] = $newCommentId; } $content = migration_dbconnection::queryArray("SELECT * FROM note_content WHERE game_id = '{$v1GameId}'", "v1"); for ($i = 0; $i < count($content); $i++) { if ($noteId = $noteIdMap[$content[$i]->note_id]) { if ($content[$i]->type == 'TEXT') { //content belongs to note migration_dbconnection::query("UPDATE notes SET description = '{$content[$i]->text}' WHERE note_id = '{$noteId}'", "v2"); } else { //assume some type of media migration_dbconnection::query("UPDATE notes SET media_id = '{$maps->media[$content[$i]->media_id]}' WHERE note_id = '{$noteId}'", "v2"); } } else { if ($commentId = $commentIdMap[$content[$i]->note_id]) { if ($content[$i]->type == 'TEXT') { //content belongs to comment migration_dbconnection::query("UPDATE note_comments SET description = '{$content[$i]->text}' WHERE note_comment_id = '{$commentId}'", "v2"); } } else { continue; } } //orphan } return $noteIdMap; }