From fa0b2ace725b15f55fc21cece09902fdcba93b2a Mon Sep 17 00:00:00 2001 From: ren <18050944+renintw@users.noreply.github.com> Date: Mon, 29 Jan 2024 05:27:03 +0900 Subject: [PATCH] Try: retrieve last commit date and update it --- .../wporg-markdown/inc/class-importer.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/wordpress.org/public_html/wp-content/plugins/wporg-markdown/inc/class-importer.php b/wordpress.org/public_html/wp-content/plugins/wporg-markdown/inc/class-importer.php index 2a5885c789..de96472219 100644 --- a/wordpress.org/public_html/wp-content/plugins/wporg-markdown/inc/class-importer.php +++ b/wordpress.org/public_html/wp-content/plugins/wporg-markdown/inc/class-importer.php @@ -99,6 +99,18 @@ protected function get_existing_for_post( WP_Post $post ) { return array( $key, $data ); } + + /** + * Get the latest commit date for a given repo. + * + * @param string $url URL to the manifest. + * @return string Date of latest commit. + */ + public function get_latest_commit_date( $url ) { + // Fetch information using the GitHub API + $latest_commit = wp_remote_get( $url ); + } + /** * Import the manifest. * @@ -130,6 +142,9 @@ public function import_manifest() { return new WP_Error( 'invalid-manifest', 'Manifest did not unfurl properly.' ); } + $latest_commit_date = $this->get_latest_commit_date($this->get_manifest_url()); + $last_update_date = get_option('last_update_date'); + // A numeric key suggests the manifest did not explicitly specify keys for each item, so define one. // Note: not explicitly specifying a key means the slugs defined must be unique. $keys = array_keys( $manifest ); @@ -186,6 +201,10 @@ public function import_manifest() { if ( $this->process_manifest_doc( $doc, $manifest ) ) { $created++; } + + if ( $latest_commit_date > $last_update_date && $updated > 0 ) { + update_option( 'last_update_date', $latest_commit_date ); + } } if ( class_exists( 'WP_CLI' ) ) { if ( 0 === $created && 0 === $updated ) {