diff --git a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-projects.php b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-projects.php index ab46bdc..57b03b2 100644 --- a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-projects.php +++ b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/partials/sync-projects.php @@ -14,9 +14,7 @@ die; } -$projects_url = 'https://landscape.cncf.io/api/items?project=hosted'; -$items_url = 'https://landscape.cncf.io/data/items.json'; -$logos_url = 'https://landscape.cncf.io/'; +$projects_url = 'https://landscape.cncf.io/api/projects/all.json'; $args = array( 'timeout' => 100, @@ -27,27 +25,106 @@ if ( is_wp_error( $data ) || ( wp_remote_retrieve_response_code( $data ) != 200 ) ) { return; } + $projects = json_decode( wp_remote_retrieve_body( $data ) ); -$data = wp_remote_get( $items_url, $args ); -if ( is_wp_error( $data ) || ( wp_remote_retrieve_response_code( $data ) != 200 ) ) { - return; -} -$items = json_decode( wp_remote_retrieve_body( $data ) ); -$id_column = array_column( $items, 'id' ); - -foreach ( $projects as $level ) { - foreach ( $level->items as $project ) { - $key = array_search( $project->id, $id_column ); - if ( false === $key ) { - continue; - } +foreach ( $projects as $p ) { + + // skip projects in the sub-landscapes. + if ( 'Wasm' == $p->category || 'Serverless' == $p->category || 'CNAI' == $p->category ) { + continue; + } - $p = $items[ $key ]; + $params = array( + 'post_type' => 'lf_project', + 'post_title' => $p->name, + 'post_status' => 'publish', + 'meta_input' => array( + 'lf_project_external_url' => $p->homepage_url, + 'lf_project_twitter' => $p->twitter_url ?? '', + 'lf_project_logo' => $p->logo_url ?? '', + 'lf_project_category' => $p->subcategory ?? '', + ), + ); - // adds term to taxonomy if it doesn't exist. - if ( ! term_exists( $p->name, 'lf-project' ) ) { - wp_insert_term( $p->name, 'lf-project' ); + if ( property_exists( $p, 'repositories' ) ) { + $repo_url = null; + foreach ( $p->repositories as $repo ) { + if ( property_exists( $repo, 'primary' ) && $repo->primary ) { + $repo_url = $repo->url; + break; + } } + + if ( $repo_url ) { + $params['meta_input']['lf_project_github'] = $repo_url; + } + } + + if ( property_exists( $p, 'description' ) ) { + $params['meta_input']['lf_project_description'] = $p->description; + } + if ( property_exists( $p, 'devstats_url' ) ) { + $params['meta_input']['lf_project_devstats'] = $p->devstats_url; + } + if ( property_exists( $p, 'artwork_url' ) ) { + $params['meta_input']['lf_project_logos'] = $p->artwork_url; + } + if ( property_exists( $p, 'stack_overflow_url' ) ) { + $params['meta_input']['lf_project_stack_overflow'] = $p->stack_overflow_url; + } + if ( property_exists( $p, 'accepted_at' ) ) { + $params['meta_input']['lf_project_date_accepted'] = $p->accepted_at; + } + if ( property_exists( $p, 'incubating_at' ) ) { + $params['meta_input']['lf_project_date_incubating'] = $p->incubating_at; + } + if ( property_exists( $p, 'graduated_at' ) ) { + $params['meta_input']['lf_project_date_graduated'] = $p->graduated_at; + } + if ( property_exists( $p, 'archived_at' ) ) { + $params['meta_input']['lf_project_date_archived'] = $p->archived_at; + } + if ( property_exists( $p, 'blog_url' ) ) { + $params['meta_input']['lf_project_blog'] = $p->blog_url; + } + if ( property_exists( $p, 'mailing_list_url' ) ) { + $params['meta_input']['lf_project_mail'] = $p->mailing_list_url; + } + if ( property_exists( $p, 'slack_url' ) ) { + $params['meta_input']['lf_project_slack'] = $p->slack_url; + } + if ( property_exists( $p, 'youtube_url' ) ) { + $params['meta_input']['lf_project_youtube'] = $p->youtube_url; + } + if ( property_exists( $p, 'gitter_url' ) ) { + $params['meta_input']['lf_project_gitter'] = $p->gitter_url; + } + + $pp = get_posts( + array( + 'post_type' => 'lf_project', + 'title' => $p->name, + 'post_status' => 'all', + 'numberposts' => 1, + 'update_post_term_cache' => false, + 'update_post_meta_cache' => false, + 'orderby' => 'post_date ID', + 'order' => 'ASC', + ) + ); + if ( ! empty( $pp ) ) { + $params['ID'] = $pp[0]->ID; + } + + // adds term to taxonomy if it doesn't exist. + if ( ! term_exists( $p->name, 'lf-project' ) ) { + wp_insert_term( $p->name, 'lf-project' ); + } + + $newid = wp_insert_post( $params ); // will insert or update the post as needed. + + if ( $newid ) { + wp_set_object_terms( $newid, $p->maturity, 'lf-project-stage', false ); } }