<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[4727] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Add a custom table containing a subset of plugin meta used for api.wordpress.org/plugins/update-check/.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/4727">4727</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/4727","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-01-19 04:33:23 +0000 (Thu, 19 Jan 2017)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Plugin Directory: Add a custom table containing a subset of plugin meta used for api.wordpress.org/plugins/update-check/.

See <a href="http://meta.trac.wordpress.org/ticket/2112">#2112</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassimportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjobsclassmanagerphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryzipclassbuilderphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjobsclassapiupdateupdaterphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-api-update-updater.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorycliclassimportphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php    2017-01-19 00:45:23 UTC (rev 4726)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php      2017-01-19 04:33:23 UTC (rev 4727)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3,6 +3,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Plugin_Directory;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Readme\Parser;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Template;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Plugin_Directory\Jobs\API_Update_Updater;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Tools;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Tools\SVN;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -193,6 +194,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Finally, set the new version live.
</span><span class="cx" style="display: block; padding: 0 10px">                update_post_meta( $plugin->ID, 'stable_tag', $stable_tag );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                // Ensure that the API gets the updated data
+               API_Update_Updater::update_single_plugin( $plugin->post_name );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 return true;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjobsclassapiupdateupdaterphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-api-update-updater.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-api-update-updater.php                               (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-api-update-updater.php 2017-01-19 04:33:23 UTC (rev 4727)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,117 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Jobs;
+use WordPressdotorg\Plugin_Directory\Plugin_Directory;
+
+/**
+ * Handles interfacing with the api.WordPress.org/plugin/update-check/ API.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Jobs
+ */
+class API_Update_Updater {
+
+       /**
+        * The cron job to ensure all plugins in the `update_source` table are up-to-date.
+        * This cron is a backup in the event that the import doesn't trigger it correctly.
+        */
+       public static function cron_trigger() {
+               global $wpdb;
+
+               $out_of_date_plugins = $wpdb->get_col(
+                       "SELECT p.post_name
+                       FROM {$wpdb->posts} p
+                               LEFT JOIN {$wpdb->prefix}update_source u ON p.ID = u.plugin_id
+                       WHERE
+                               p.post_type = 'plugin'
+                               AND (
+                                       p.post_status IN( 'publish', 'approved', 'disabled', 'closed' ) OR
+                                       u.plugin_id IS NOT NULL
+                               )
+                               AND (
+                                       u.plugin_id IS NULL OR
+                                       u.last_updated != p.post_modified OR
+                                       ( u.available = 1 AND (p.post_status != 'publish' AND p.post_status != 'disabled' ) ) OR
+                                       ( u.available = 0 AND (p.post_status = 'publish' OR p.post_status = 'disabled' ) )
+                               )"
+               );
+
+               if ( ! $out_of_date_plugins ) {
+                       return;
+               }
+
+               foreach ( $out_of_date_plugins as $plugin_slug ) {
+                       if ( ! self::update_single_plugin( $plugin_slug ) ) {
+                               // If the update failed, but yet we know the DB data differs, clear cached data and try again.
+                               $post = Plugin_Directory::get_plugin_post( $plugin_slug );
+                               clean_post_cache( $post->ID );
+                               self::update_single_plugin( $plugin_slug );
+                       }
+               }
+       }
+
+       /**
+        * Updates a single plugins `update_source` data.
+        */
+       public static function update_single_plugin( $plugin_slug, $self_loop = false ) {
+               global $wpdb;
+               $post = Plugin_Directory::get_plugin_post( $plugin_slug );
+
+               if ( ! $post ) {
+                       $wpdb->delete(  $wpdb->prefix . 'update_source', compact( 'plugin_slug' ) );
+                       return true;
+               }
+
+               $data = array(
+                       'plugin_id'       => $post->ID,
+                       'plugin_slug'     => $post->post_name,
+                       'available'       => 'publish' === $post->post_status || 'disabled' === $post->post_status,
+                       'version'         => get_post_meta( $post->ID, 'version', true ),
+                       'stable_tag'      => get_post_meta( $post->ID, 'stable_tag', true ),
+                       'plugin_name'     => get_post_meta( $post->ID, 'header_name', true ),
+                       'plugin_name_san' => sanitize_title_with_dashes( get_post_meta( $post->ID, 'header_name', true ) ),
+                       'tested'          => get_post_meta( $post->ID, 'tested', true ),
+                       'requires'        => get_post_meta( $post->ID, 'requires', true ),
+                       'upgrade_notice'  => '',
+                       'last_updated'    => $post->post_modified,
+               );
+               $upgrade_notice = get_post_meta( $post->ID, 'upgrade_notice', true );
+               if ( isset( $upgrade_notice[ $data['version'] ] ) ) {
+                       $data['upgrade_notice'] = $upgrade_notice[ $data['version'] ];
+               }
+
+               if (
+                       $wpdb->update( $wpdb->prefix . 'update_source', $data, array( 'plugin_slug' => $post->post_name ) ) &&
+                       ! $wpdb->get_var( $wpdb->prepare( "SELECT `plugin_slug` FROM `{$wpdb->prefix}update_source` WHERE `plugin_slug` = %s", $post->post_name ) )
+               ) {
+                       if ( ! $wpdb->insert( $wpdb->prefix . 'update_source', $data ) ) {
+                               return false;
+                       }
+               }
+
+               // ~34char prefix, Memcache limit of 255char per key.
+               $plugin_details_cache_key = 'plugin_details:' . ( strlen( $plugin_slug ) > 200 ? 'md5:' . md5( $plugin_slug ) : $plugin_slug );
+               wp_cache_delete( $plugin_details_cache_key, 'update-check-3' );
+
+               return true;
+       }
+
+}
+
+/*
+CREATE TABLE `{$prefix}_update_source` (
+  `plugin_id` bigint(20) unsigned NOT NULL,
+  `plugin_slug` varchar(255) NOT NULL DEFAULT '',
+  `available` tinyint(4) NOT NULL,
+  `version` varchar(128) NOT NULL DEFAULT '0.0',
+  `stable_tag` varchar(128) NOT NULL DEFAULT 'trunk',
+  `plugin_name` varchar(255) NOT NULL DEFAULT '',
+  `plugin_name_san` varchar(255) NOT NULL DEFAULT '',
+  `tested` varchar(128) NOT NULL DEFAULT '',
+  `requires` varchar(128) NOT NULL DEFAULT '',
+  `upgrade_notice` text,
+  `last_updated` datetime NOT NULL,
+  PRIMARY KEY (`plugin_id`),
+  UNIQUE KEY `plugin_slug` (`plugin_slug`),
+  KEY `plugin_name` (`plugin_name`),
+  KEY `plugin_name_san` (`plugin_name_san`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+*/
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-api-update-updater.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjobsclassmanagerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php  2017-01-19 00:45:23 UTC (rev 4726)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php    2017-01-19 04:33:23 UTC (rev 4727)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -18,9 +18,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'cron_schedules', array( $this, 'register_schedules' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // The actual cron hooks.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_action( 'plugin_directory_meta_sync', array( __NAMESPACE__ . '\Meta_Sync', 'cron_trigger' ) );
-               add_action( 'plugin_directory_svn_sync',  array( __NAMESPACE__ . '\SVN_Watcher', 'cron_trigger' ) );
-               
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         add_action( 'plugin_directory_meta_sync',        array( __NAMESPACE__ . '\Meta_Sync', 'cron_trigger' ) );
+               add_action( 'plugin_directory_svn_sync',         array( __NAMESPACE__ . '\SVN_Watcher', 'cron_trigger' ) );
+               add_action( 'plugin_directory_update_api_check', array( __NAMESPACE__ . '\API_Update_Updater', 'cron_trigger' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Register the wildcard cron hook tasks.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -133,6 +133,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! wp_next_scheduled ( 'plugin_directory_svn_sync' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        wp_schedule_event( time(), 'every_30s', 'plugin_directory_svn_sync' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                if ( ! wp_next_scheduled ( 'plugin_directory_update_api_check' ) ) {
+                       wp_schedule_event( time(), 'hourly', 'plugin_directory_update_api_check' );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryzipclassbuilderphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php   2017-01-19 00:45:23 UTC (rev 4726)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php     2017-01-19 04:33:23 UTC (rev 4727)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -201,8 +201,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        protected function move_into_place() {
</span><span class="cx" style="display: block; padding: 0 10px">                $this->exec( sprintf(
</span><span class="cx" style="display: block; padding: 0 10px">                        'mv -f %s %s',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $this->tmp_build_file,
-                       $this->zip_file
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 escapeshellarg( $this->tmp_build_file ),
+                       escapeshellarg( $this->zip_file )
</ins><span class="cx" style="display: block; padding: 0 10px">                 ), $output, $return_value );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $return_value ) {
</span></span></pre>
</div>
</div>

</body>
</html>