echo"❌ Failed to parse a valid Course ID from the API response."
echo"Full API Response:"
echo"$COURSE_RESPONSE" | jq .
exit 1
fi
echo"✅ Successfully created course '$COURSE_SHORTNAME' with ID: $NEW_COURSE_ID"
# --- END OF ROBUST ERROR CHECK ---
# --- Step 5: Enroll Admin User into the New Course ---
echo"🧑🏫 Step 5: Enrolling you as a teacher in the new course..."
# First, get the User ID for your admin user
ADMIN_USER_ID=$(docker exec"$DB_CONTAINER_NAME" mysql -u root -p"$DB_ROOT_PASSWORD""$DB_NAME"-se"SELECT id FROM mdl_user WHERE username='$MOODLE_ADMIN_USER';")
# The roleid for a Teacher is typically 3 (editingteacher) or 4 (teacher). We'll use 3.
TEACHER_ROLE_ID=3
# Add the enrol_manual_enrol_users function to our service
docker exec-i"$DB_CONTAINER_NAME" mysql -u root -p"$DB_ROOT_PASSWORD""$DB_NAME"-e"INSERT IGNORE INTO mdl_external_services_functions (externalserviceid, functionname) VALUES ((SELECT id FROM mdl_external_services WHERE shortname = '$CUSTOM_SERVICE_NAME'), 'enrol_manual_enrol_users');"