Feature #14897 » cac-backfill-course-instructors.php
1 |
<?php
|
---|---|
2 |
|
3 |
$course_ids = get_posts( |
4 |
[
|
5 |
'post_type' => 'cac_course', |
6 |
'fields' => 'ids', |
7 |
'posts_per_page' => -1, |
8 |
]
|
9 |
);
|
10 |
|
11 |
$progress_bar = \WP_CLI\Utils\make_progress_bar( 'Backfilling instructors for courses', count( $course_ids ) ); |
12 |
|
13 |
foreach ( $course_ids as $course_id ) { |
14 |
$course = new \CAC\Courses\Course( $course_id ); |
15 |
|
16 |
$instructor_ids = $course->get_instructor_ids(); |
17 |
|
18 |
$site_ids = $course->get_site_ids(); |
19 |
if ( $site_ids ) { |
20 |
foreach ( $site_ids as $site_id ) { |
21 |
// Don't overwrite existing.
|
22 |
$saved = bp_blogs_get_blogmeta( $site_id, 'cac_instructors' ); |
23 |
if ( ! $saved ) { |
24 |
cac_set_site_instructors( $site_id, $instructor_ids ); |
25 |
WP_CLI::log( 'Setting instructors for site ' . $site_id ); |
26 |
}
|
27 |
}
|
28 |
}
|
29 |
|
30 |
$group_ids = $course->get_group_ids(); |
31 |
if ( $group_ids ) { |
32 |
foreach ( $group_ids as $group_id ) { |
33 |
// Don't overwrite existing.
|
34 |
$saved = groups_get_groupmeta( $group_id, 'cac_instructors' ); |
35 |
if ( ! $saved ) { |
36 |
groups_update_groupmeta( $group_id, 'cac_instructors', $instructor_ids ); |
37 |
WP_CLI::log( 'Setting instructors for group ' . $group_id ); |
38 |
}
|
39 |
}
|
40 |
}
|
41 |
// print_r( $instructor_ids );
|
42 |
|
43 |
$progress_bar->tick(); |
44 |
}
|
45 |
|
46 |
$progress_bar->finish(); |
- « Previous
- 1
- 2
- 3
- Next »