public static function migrateGame($v2UserId, $v2Key = false, $v1GameId = false, $sift = false) { set_time_limit(0); /*Huge hack to allow for either v1 style access or v2 access*/ if (!$v2Key) { $data = file_get_contents("php://input"); $glob = json_decode($data); $v2UserId = $glob->auth->user_id; $v2Key = $glob->auth->key; $v1GameId = $glob->game_id; $sift = isset($glob->sift) && $glob->sift; } /*End huge hack*/ //check permission by getting available v1 games $retGames = migration::v1GamesForV2User($v2UserId, $v2Key); if ($retGames->returnCode != 0) { return new migration_return_package(1, NULL, $retGames->returnCodeDescription); } $owned_v1_games = $retGames->data; $authorized = false; for ($i = 0; $i < count($owned_v1_games); $i++) { if ($owned_v1_games[$i]->game_id == $v1GameId) { $authorized = true; } } if (!$authorized) { return new migration_return_package(1, NULL, "Your attached v1 account does not have ownership of that game"); } $Editors = new Editors(); $Games = new Games(); $v2Auth = new stdClass(); $v2Auth->user_id = $v2UserId; $v2Auth->key = $v2Key; $v2Auth->permission = "read_write"; $oldGame = $Games->getGame($v1GameId)->data; //conform old terminology to new $oldGame->published = $oldGame->ready_for_public; $oldGame->type = $oldGame->is_locational ? "LOCATION" : "ANYWHERE"; $oldGame->notebook_allow_comments = $oldGame->allow_note_comments; $oldGame->notebook_allow_likes = $oldGame->allow_note_likes; $oldGame->notebook_allow_player_tags = $oldGame->allow_player_tags; $oldGame->map_show_player = $oldGame->show_player_location; $oldGame->map_offsite_mode = $oldGame->full_quick_travel; $oldGame->is_siftr = $sift ? 1 : 0; $oldGame->auth = $v2Auth; $v2GameId = bridgeService("v2", "games", "createGame", "", $oldGame)->data->game_id; $maps = new stdClass(); $maps->media = migration::migrateMedia($v1GameId, $v2GameId); //update game media refrences $v2Game = migration_dbconnection::queryObject("SELECT * FROM games WHERE game_id = '{$v2GameId}'", "v2"); migration_dbconnection::query("UPDATE games SET media_id = '{$maps->media[$v2Game->media_id]}', icon_media_id = '{$maps->media[$v2Game->icon_media_id]}' WHERE game_id = '{$v2GameId}'", "v2"); $v2Game = migration_dbconnection::queryObject("SELECT * FROM games WHERE game_id = '{$v2GameId}'", "v2"); //get updated game data $maps->plaques = migration::migratePlaques($v1GameId, $v2GameId, $maps); $maps->items = migration::migrateItems($v1GameId, $v2GameId, $maps); $maps->webpages = migration::migrateWebpages($v1GameId, $v2GameId, $maps); $characterMaps = migration::migrateDialogs($v1GameId, $v2GameId, $maps); $maps->dialogs = $characterMaps->dialogsMap; $maps->scripts = $characterMaps->scriptsMap; $maps->options = $characterMaps->optionsMap; $maps->item_tags = migration::migrateItemTags($v1GameId, $v2GameId, $maps); $maps->note_tags = migration::migrateNoteTags($v1GameId, $v2GameId, $maps); $maps->webhooks = migration::migrateWebhooks($v1GameId, $v2GameId, $maps); $maps->quests = migration::migrateQuests($v1GameId, $v2GameId, $maps); $maps->events = migration::migrateEvents($v1GameId, $v2GameId, $maps); $maps->factories = migration::migrateFactories($v1GameId, $v2GameId, $maps); if ($sift) { $maps->notes = migration::migrateNotes($v1GameId, $v2GameId, $maps); } $scene = migration_dbconnection::queryObject("SELECT * FROM scenes WHERE game_id = '{$v2GameId}';", "v2"); if ($scene) { $sceneId = $scene->scene_id; } else { $sceneId = migration_dbconnection::queryInsert("INSERT INTO scenes (game_id, name, created) VALUES ('{$v2GameId}', 'Main Scene', CURRENT_TIMESTAMP)", "v2"); } migration_dbconnection::query("UPDATE games SET intro_scene_id = '{$sceneId}' WHERE game_id = '{$v2GameId}';", "v2"); $triggerMaps = migration::migrateTriggers($v1GameId, $v2GameId, $sceneId, $maps); //both of these maps have v1 location_id as key, v2 trigger as value $maps->locTriggers = $triggerMaps->locationTriggerMap; $maps->qrTriggers = $triggerMaps->qrTriggerMap; $maps->tabs = migration::migrateTabs($v1GameId, $v2GameId, $maps); migration::updateDialogOptionLinks($v1GameId, $v2GameId, $maps); //now that tabs/objects (link targets) are updated with ids, we can make sense of them //maps generated from migrateRequirementPackage inserted directly. $maps->skipped_requirement_atoms = array(); migration::migrateRequirements($v1GameId, $v2GameId, $maps); migration_dbconnection::queryInsert("INSERT INTO game_migrations (v2_game_id, v1_game_id, v2_user_id) VALUES ('{$v2GameId}','{$v1GameId}','{$v2UserId}')"); $v2Game->migration_maps = $maps; return new migration_return_package(0, $v2Game); }