Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daranzolin/7879449c97cf36d8c26ea1a3f9f7eef3 to your computer and use it in GitHub Desktop.
Save daranzolin/7879449c97cf36d8c26ea1a3f9f7eef3 to your computer and use it in GitHub Desktop.
library(tidyverse)
source("utils.R")
decrement_section <- function(section_code) {
old_section_num <- readr::parse_number(section_code) - 1
section_code <- stringr::str_extract(section_code, "^(\\w+)")
paste(section_code, old_section_num)
}
create_content_migration <- function(migration_type = "course_copy_importer", course_id = NULL, source_course_id = NULL) {
url <- paste0(canvas_url(),
paste("courses", course_id, "content_migrations", sep="/"))
args <- sc(list(migration_type = migration_type,
source_course_id = source_course_id))
names(args)[2] <- "settings[source_course_id]"
invisible(canvas_query(url, args, "POST"))
}
courses <- rcanvas::get_course_list()
section_shell_ids <- courses %>%
filter(!grepl("Test", name),
workflow_state == "unpublished") %>%
rowwise() %>%
mutate(offering_code = stringr::str_extract(name, "^(\\w+)"),
source_section_code = decrement_section(name)) %>%
select(offering_code, shell_name = name, source_section_code, shell_id = id)
source_section_ids <- courses %>%
filter(name %in% section_shell_ids$source_section_code) %>%
select(source_section_code = name, source_section_id = id)
all_sections <- left_join(section_shell_ids, source_section_ids, by = "source_section_code")
id_list <- list(migration_type = "course_copy_importer",
course_id = all_sections$shell_id,
source_course_id = all_sections$source_section_id)
pmap(id_list, create_content_migration)
# create_content_migration(migration_type = "course_copy_importer", course_id = 1320656, source_course_id = 1320594)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment