<%@ Page Language="C#" AutoEventWireup="true" Inherits="Sitecore.sitecore.admin.AdminPage" %>
<%@ Import Namespace="Sitecore" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="Sitecore.Install.Framework" %>
<%@ Import Namespace="Sitecore.SecurityModel" %>
<%@ Import Namespace="Sitecore.Workflows" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Migrate Lists</title>

    <script runat="server" language="c#">
        private const string AnalyticsWorkflowId = "{689E2994-4656-4C58-9112-7826CB46EE69}";
        private const string DraftStateId = "{39156DC0-21C6-4F64-B641-31E85C8F5DFE}";

        protected void Page_Load(object sender, EventArgs e)
        {
            CheckSecurity(true);

            Database db = Sitecore.Configuration.Factory.GetDatabase("master");

            using (new SecurityDisabler())
            {
                // Run the List Manager migration post-step
                var listPostStep = new Sitecore.ListManagement.Client.PostSteps.MigrationPostStep();
                listPostStep.Run(new NullOutput(), new NameValueCollection());

                // Ensure the Lists are deployed
                Item listsFolderItem = db.GetItem("{3C94F086-453B-48FC-9F1B-2B00BC0A55C7}");
                IWorkflow analyticsWorkflow = db.WorkflowProvider.GetWorkflow(AnalyticsWorkflowId);
                WorkflowCommand deployCommand = analyticsWorkflow.GetCommands(DraftStateId).First();

                foreach (Item item in listsFolderItem.Children)
                {
                    using (new EditContext(item))
                    {
                        // Set to Draft workflow state
                        item[FieldIDs.WorkflowState] = DraftStateId;
                    }

                    // Run "Deploy" command which also sets item back to "Deployed" workflow state
                    analyticsWorkflow.Execute(deployCommand.CommandID, item, string.Empty, false);
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            DONE
        </div>
    </form>
</body>
</html>