<!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>[4520] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Shift SVN Watching, Plugin Imports, and Plugin i18n imports to Jobs.</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/4520">4520</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/4520","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>2016-12-13 09:44:54 +0000 (Tue, 13 Dec 2016)</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: Shift SVN Watching, Plugin Imports, and Plugin i18n imports to Jobs.
See <a href="http://meta.trac.wordpress.org/ticket/2330">#2330</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassplugindirectoryphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php</a></li>
<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_htmlwpcontentpluginsplugindirectorycliclasssvnwatcherphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-svn-watcher.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<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_htmlwpcontentpluginsplugindirectoryjobsclassplugini18nimportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-plugin-i18n-import.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjobsclasspluginimportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-plugin-import.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjobsclasssvnwatcherphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-svn-watcher.php</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorybinsvnwatcherphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/svn-watcher.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorybinsvnwatcherphp"></a>
<div class="delfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Deleted: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/svn-watcher.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/bin/svn-watcher.php 2016-12-13 04:46:39 UTC (rev 4519)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/svn-watcher.php 2016-12-13 09:44:54 UTC (rev 4520)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,20 +0,0 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
-namespace WordPressdotorg\Plugin_Directory;
-/**
- * This is a stand alone script which is regularly run to import plugins into the WordPress Plugin Directory after svn commits.
- */
-
-// This script should only be called in a CLI environment.
-if ( 'cli' != php_sapi_name() ) {
- die();
-}
-
-$_SERVER['HTTPS'] = 'on';
-$_SERVER['HTTP_HOST'] = 'wordpress.org';
-$_SERVER['REQUEST_URI'] = '/plugins/';
-
-// Assume a standard WordPress wp-content/plugins file structure.
-include dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) . '/wp-load.php';
-
-$watcher = new CLI\SVN_Watcher();
-$watcher->watch();
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryclassplugindirectoryphp"></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/class-plugin-directory.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/class-plugin-directory.php 2016-12-13 04:46:39 UTC (rev 4519)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php 2016-12-13 09:44:54 UTC (rev 4520)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -42,8 +42,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'the_content', array( $this, 'filter_rel_nofollow' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Cron tasks.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_action( 'admin_init', array( $this, 'register_cron_tasks' ) );
- add_action( 'plugin_directory_meta_sync', array( __NAMESPACE__ . '\Jobs\Meta_Sync', 'cron_trigger' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ new Jobs\Manager();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // oEmbed whitlisting.
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'embed_oembed_discover', '__return_false' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -466,19 +465,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require_once( __DIR__ . '/libs/site-search/jetpack-search.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> \Jetpack_Search::instance();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Queue all of our cron tasks.
- */
- function register_cron_tasks() {
- if ( ! wp_next_scheduled ( 'plugin_directory_meta_sync' ) ) {
- wp_schedule_event( time(), 'hourly', 'plugin_directory_meta_sync' );
- }
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * Register the Shortcodes used within the content.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function register_shortcodes() {
</span></span></pre></div>
<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 2016-12-13 04:46:39 UTC (rev 4519)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php 2016-12-13 09:44:54 UTC (rev 4520)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -159,7 +159,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Update all readme meta
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $this->readme_fields as $readme_field ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $value = ( 'tested' == $readme_field ) ? $tested : $readme->field;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $value = ( 'tested' == $readme_field ) ? $tested : $readme->$readme_field;
</ins><span class="cx" style="display: block; padding: 0 10px"> update_post_meta( $plugin->ID, $readme_field, wp_slash( $value ) );
</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_htmlwpcontentpluginsplugindirectorycliclasssvnwatcherphp"></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-svn-watcher.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-svn-watcher.php 2016-12-13 04:46:39 UTC (rev 4519)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-svn-watcher.php 2016-12-13 09:44:54 UTC (rev 4520)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,6 +1,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory\CLI;
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Plugin_Directory;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use WordPressdotorg\Plugin_Directory\Jobs;
</ins><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Tools\SVN;
</span><span class="cx" style="display: block; padding: 0 10px"> use Exception;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -13,17 +14,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> const SVN_URL = 'https://plugins.svn.wordpress.org/';
</span><span class="cx" style="display: block; padding: 0 10px"> const PHP = '/usr/local/bin/php';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- const PROCESS_I18N = true;
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function __construct() {
- $this->watch();
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * This method is responsible for running a loop over all SVN revisions to fetch updated details.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function watch() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $svn_rev_option_name = 'svn_rev_' . php_uname( 'n' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $svn_rev_option_name = 'svn_rev_last_processed';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $last_rev_processed = $this->get_option( $svn_rev_option_name );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $last_rev_processed ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -36,11 +32,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $head_rev = $last_rev_processed + 100;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $last_rev_processed == $head_rev ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $last_rev_processed >= $head_rev ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // Nothing to do!
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // We don't want to re-process the last rev processed, so bump past it
+ $last_rev_processed++;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> echo "Processing changes from $last_rev_processed to $head_rev..\n";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $plugins_to_process = $this->get_plugin_changes_between( $last_rev_processed, $head_rev );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -50,41 +49,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $plugin_data['tags_touched'][] = 'trunk';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $esc_plugin_slug = escapeshellarg( $plugin_slug );
- $esc_changed_tags = escapeshellarg( implode( ',', $plugin_data['tags_touched'] ) );
- $esc_revision = escapeshellarg( $plugin_data['revision'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ Jobs\Plugin_Import::queue( $plugin_slug, $plugin_data );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $cmd = self::PHP . ' ' . dirname( __DIR__ ) . "/bin/import-plugin.php --plugin {$esc_plugin_slug} --changed-tags {$esc_changed_tags} --revision {$esc_revision}";
-
- echo "\$$cmd\n";
- echo shell_exec( $cmd ) . "\n";
-
- if ( self::PROCESS_I18N && 'nothing-much' === $plugin_slug ) {
- $plugin = Plugin_Directory::get_plugin_post( $plugin_slug );
- $stable_tag = $plugin->stable_tag;
-
- $i18n_processes = [];
- if ( in_array( 'trunk', $plugin_data['tags_touched'] ) ) {
- if ( $plugin_data['code_touched'] ) {
- $i18n_processes[] = 'trunk|code';
- }
- if ( $plugin_data['readme_touched'] ) {
- $i18n_processes[] = 'trunk|readme';
- }
- }
- if ( in_array( $stable_tag, $plugin_data['tags_touched'] ) ) {
- if ( $plugin_data['code_touched'] ) {
- $i18n_processes[] = "{$stable_tag}|code";
- }
- if ( $plugin_data['readme_touched'] ) {
- $i18n_processes[] = "{$stable_tag}|readme";
- }
- }
-
- $this->process_i18n_for_plugin( $plugin_slug, $i18n_processes );
- }
-
- $this->update_option( $svn_rev_option_name, $plugin_data['revision'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->update_option( $svn_rev_option_name, min( $plugin_data['revisions'] ) );
</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"> // Update it to HEAD again. We do this as $plugin_data['revision'] may be set to PREVHEAD in the event the latest 2 (or more) commits are to a single plugin.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -92,27 +59,6 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Processes i18n import tasks.
- *
- * @param string $plugin_slug
- * @param array $i18n_processes
- */
- protected function process_i18n_for_plugin( $plugin_slug, $i18n_processes ) {
- foreach ( $i18n_processes as $process ) {
- list( $tag, $type ) = explode( '|', $process );
-
- $esc_plugin_slug = escapeshellarg( $plugin_slug );
- $esc_tag = escapeshellarg( $tag );
- $esc_type = escapeshellarg( $type );
-
- $cmd = self::PHP . ' ' . dirname( __DIR__ ) . "/bin/import-plugin-to-glotpress.php --plugin {$esc_plugin_slug} --tag {$esc_tag} --type {$esc_type}";
-
- echo "\n\$$cmd\n";
- echo shell_exec( $cmd ) . "\n";
- }
- }
-
- /**
</del><span class="cx" style="display: block; padding: 0 10px"> * Determines what plugin changes have happened between two revisions.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $rev The revision to search from.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -122,12 +68,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> protected function get_plugin_changes_between( $rev, $head_rev = 'HEAD' ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $logs = SVN::log( self::SVN_URL, array( $rev, $head_rev ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $logs['error'] ) {
- throw new Exception( "Could not fetch plugins.svn logs: " . implode( ', ', $logs['error'] ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $logs['errors'] ) {
+ throw new Exception( "Could not fetch plugins.svn logs: " . implode( ', ', $logs['errors'] ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // If no changes (either no log entries, or HEAD was the same as $rev)
- if ( ! count( $logs['log'] ) || ( 1 == count( $logs['log'] ) && $rev == array_keys( $logs['log'] )[0] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // nothing new to report
+ if ( ! $logs['log'] ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return array();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -143,13 +89,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'readme_touched' => false, // minor optimization, only parse readme i18n on readme-related commits
</span><span class="cx" style="display: block; padding: 0 10px"> 'code_touched' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'assets_touched' => false,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'revision' => PHP_INT_MAX,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'revisions' => array(),
</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"> $plugin =& $plugins[ $plugin_slug ];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Keep track of the lowest revision number we've seen for this plugin
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin['revision'] = min( $plugin['revision'], $log['revision'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $plugin['revisions'][] = $log['revision'];
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $log['paths'] as $path ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $path_parts = explode('/', trim( $path, '/' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -182,11 +128,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Sort plugins by minimum revision, it should already be in this order, but double check.
</span><span class="cx" style="display: block; padding: 0 10px"> uasort( $plugins, function( $a, $b ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $a['revision'] == $b['revision'] ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( min( $a['revisions'] ) == min( $b['revisions'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return 0;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return ( $a['revision'] < $b['revision'] ) ? -1 : 1;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return ( min( $a['revisions'] ) < min( $b['revisions'] ) ) ? -1 : 1;
</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"> return $plugins;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -206,7 +152,7 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * An implementation of `get_option()~ which doesn't utilise the cache.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * An implementation of `get_option()` which doesn't utilise the cache.
</ins><span class="cx" style="display: block; padding: 0 10px"> * As this is a long-running script, we don't want to hit an alloptions race condition bug.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $option_name The Option to retrieve.
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryjobsclassmanagerphp"></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-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 (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php 2016-12-13 09:44:54 UTC (rev 4520)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,170 @@
</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;
+
+/**
+ * Manager to wrap up all the logic for Cron tasks.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Jobs
+ */
+class Manager {
+
+ /**
+ * A static method for the cron trigger to fire.
+ */
+ public function __construct() {
+ // Register all the cron task handlers.
+ add_action( 'admin_init', array( $this, 'register_cron_tasks' ) );
+ add_filter( 'cron_schedules', array( $this, 'register_schedules' ) );
+
+ // The actual cron hooks.
+ add_action( 'plugin_directory_meta_sync', array( __NAMESPACE__ . '\Meta_Sync', 'cron_trigger' ) );
+ add_action( 'plugin_directory_svn_sync', array( __NAMESPACE__ . '\SVN_Watcher', 'cron_trigger' ) );
+
+
+ // Register the wildcard cron hook tasks.
+ if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
+ add_action( 'pre_option_cron', array( $this, 'register_colon_based_hook_handlers' ), 100 );
+ }
+
+ }
+
+ /**
+ * Register any cron schedules needed.
+ */
+ public function register_schedules( $schedules ) {
+ $schedules['every_30s'] = array( 'interval' => 30, 'display' => 'Every 30 seconds' );
+
+ return $schedules;
+ }
+
+ /**
+ * Returns the latest time that the scheduled hook will run
+ *
+ * @param string $hook The hook to look for.
+ * @param string $when 'last' or 'next' for when the hook runs.
+ * @return bool|int False on failure, The timestamp on success.
+ */
+ public static function get_scheduled_time( $hook, $when = 'last' ) {
+ $crons = _get_cron_array();
+ if ( empty( $crons ) ) {
+ return false;
+ }
+
+ $timestamps = array();
+
+ foreach ( $crons as $timestamp => $cron ) {
+ if ( isset( $cron[ $hook ] ) ) {
+ foreach ( $cron[ $hook ] as $key => $cron_item ) {
+ if ( 'waiting' === $cron_item['_job']->status ) {
+ $timestamps[] = $timestamp;
+ break;
+ }
+ }
+ }
+ }
+
+ if ( empty( $timestamps ) ) {
+ return false;
+ }
+
+ if ( 'last' == $when ) {
+ return max( $timestamps );
+ } else {
+ return min( $timestamps );
+ }
+ }
+
+ /**
+ * Reschedules a cavalcade job.
+ * This requires the usage of Cavalcade, and will fail without it.
+ *
+ * @param string $hook The Hook to reschedule.
+ * @param int $new_timestamp The time to reschedule it to.
+ * @param int $old_timestamp The specific job to schedule. Optional, will affect first job otherwise.
+ */
+ public static function reschedule_event( $hook, $new_timestamp = false, $old_timestamp = false ) {
+ $new_timestatmp = $new_timestamp ?: time();
+
+ $crons = _get_cron_array();
+ foreach ( $crons as $timestamp => $cron ) {
+ if ( $old_timestamp && $old_timestamp != $timestamp ) {
+ continue;
+ }
+
+ if ( isset( $cron[ $hook ] ) ) {
+ foreach ( $cron[ $hook ] as $key => $event ) {
+ // Cavalcade should present this field,if not, bail.
+ if ( empty( $event['_job'] ) ) {
+ return false;
+ }
+
+ if ( 'waiting' !== $event['_job']->status ) {
+ return false;
+ }
+
+ $event['_job']->nextrun = $new_timestamp;
+ $event['_job']->save();
+
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+
+ /**
+ * Queue all of our cron tasks.
+ */
+ function register_cron_tasks() {
+ if ( ! wp_next_scheduled ( 'plugin_directory_meta_sync' ) ) {
+ wp_schedule_event( time(), 'hourly', 'plugin_directory_meta_sync' );
+ }
+ if ( ! wp_next_scheduled ( 'plugin_directory_svn_sync' ) ) {
+ wp_schedule_event( time(), 'every_30s', 'plugin_directory_svn_sync' );
+ }
+ }
+
+ /**
+ * The WordPress Cron implementation isn't great at determining if a job is already enqueued,
+ * as a result, we use a "fake" hook to encode the plugin slug into the job name to allow us to
+ * detect if a cron task for that plugin has already been registered.
+ *
+ * These cron tasks are in the form of 'import_plugin:$slug', this maps them to their expected handlers.
+ *
+ * @param array $cron_array The Cron array.
+ * @return array The Cron array passed, unchanged.
+ */
+ function register_colon_based_hook_handlers( $cron_array ) {
+ $wildcard_cron_tasks = array(
+ 'import_plugin' => array( __NAMESPACE__ . '\Plugin_Import', 'cron_trigger' ),
+ 'import_plugin_i18n' => array( __NAMESPACE__ . '\Plugin_i18n_Import', 'cron_trigger' ),
+ );
+
+ foreach ( $cron_array as $timestamp => $handlers ) {
+ if ( ! is_numeric( $timestamp ) ) {
+ continue;
+ }
+ foreach ( $handlers as $hook => $jobs ) {
+ $pos = strpos( $hook, ':' );
+ if ( ! $pos ) {
+ continue;
+ }
+
+ $partial_hook = substr( $hook, 0, $pos );
+
+ if ( isset( $wildcard_cron_tasks[ $partial_hook ] ) ) {
+ add_action( $hook, $wildcard_cron_tasks[ $partial_hook ], 10, PHP_INT_MAX );
+ }
+ }
+ }
+
+ return $cron_array;
+ }
+
+
+}
+
</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-manager.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_htmlwpcontentpluginsplugindirectoryjobsclassplugini18nimportphp"></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-plugin-i18n-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/jobs/class-plugin-i18n-import.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-plugin-i18n-import.php 2016-12-13 09:44:54 UTC (rev 4520)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,89 @@
</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;
+use WordPressdotorg\Plugin_Directory\CLI;
+use Exception;
+
+/**
+ * Import plugin string changes into WordPress.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Jobs
+ */
+class Plugin_i18n_Import {
+
+ /**
+ * Queue the job
+ */
+ public static function queue( $plugin_slug, $plugin_data ) {
+ if ( 'nothing-much' != $plugin_slug ) {
+ return;
+ }
+
+ // To avoid a situation where two imports run concurrently, if one is already scheduled, run it 1hr later (We'll trigger it after the current one finishes).
+ $when_to_run = time() + 15*MINUTE_IN_SECONDS;
+ if ( $next_scheuled = Manager::get_scheduled_time( "import_plugin_i18n:{$plugin_slug}", 'last' ) ) {
+ $when_to_run = $next_scheuled + HOUR_IN_SECONDS;
+ }
+
+ wp_schedule_single_event(
+ $when_to_run,
+ "import_plugin_i18n:{$plugin_slug}",
+ array(
+ array_merge( array( 'plugin' => $plugin_slug ), $plugin_data )
+ )
+ );
+
+ }
+
+ /**
+ * The cron trigger for the import job.
+ */
+ public static function cron_trigger( $plugin_data ) {
+ $plugin_slug = $args['plugin'];
+
+ $plugin = Plugin_Directory::get_plugin_post( $plugin_slug );
+ $stable_tag = $plugin->stable_tag;
+
+ $i18n_processes = [];
+ if ( in_array( 'trunk', $plugin_data['tags_touched'] ) ) {
+ if ( $plugin_data['code_touched'] ) {
+ $i18n_processes[] = 'trunk|code';
+ }
+ if ( $plugin_data['readme_touched'] ) {
+ $i18n_processes[] = 'trunk|readme';
+ }
+ }
+ if ( in_array( $stable_tag, $plugin_data['tags_touched'] ) ) {
+ if ( $plugin_data['code_touched'] ) {
+ $i18n_processes[] = "{$stable_tag}|code";
+ }
+ if ( $plugin_data['readme_touched'] ) {
+ $i18n_processes[] = "{$stable_tag}|readme";
+ }
+ }
+
+ self::process_i18n_for_plugin( $plugin_slug, $i18n_processes );
+ }
+
+ /**
+ * Processes i18n import tasks.
+ *
+ * @param string $plugin_slug
+ * @param array $i18n_processes
+ */
+ public static function process_i18n_for_plugin( $plugin_slug, $i18n_processes ) {
+ foreach ( $i18n_processes as $process ) {
+ list( $tag, $type ) = explode( '|', $process );
+
+ $esc_plugin_slug = escapeshellarg( $plugin_slug );
+ $esc_tag = escapeshellarg( $tag );
+ $esc_type = escapeshellarg( $type );
+
+ $cmd = self::PHP . ' ' . dirname( __DIR__ ) . "/bin/import-plugin-to-glotpress.php --plugin {$esc_plugin_slug} --tag {$esc_tag} --type {$esc_type}";
+
+ echo "\n\$$cmd\n";
+ echo shell_exec( $cmd ) . "\n";
+ }
+ }
+
+}
</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-plugin-i18n-import.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_htmlwpcontentpluginsplugindirectoryjobsclasspluginimportphp"></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-plugin-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/jobs/class-plugin-import.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-plugin-import.php 2016-12-13 09:44:54 UTC (rev 4520)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,54 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Jobs;
+use WordPressdotorg\Plugin_Directory\CLI;
+use Exception;
+
+/**
+ * Import plugin changes into WordPress.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Jobs
+ */
+class Plugin_Import {
+
+ public static function queue( $plugin_slug, $plugin_data ) {
+ // To avoid a situation where two imports run concurrently, if one is already scheduled, run it 1hr later (We'll trigger it after the current one finishes).
+ $when_to_run = time();
+ if ( $next_scheuled = Manager::get_scheduled_time( "import_plugin:{$plugin_slug}", 'last' ) ) {
+ $when_to_run = $next_scheuled + HOUR_IN_SECONDS;
+ }
+
+ wp_schedule_single_event(
+ $when_to_run,
+ "import_plugin:{$plugin_slug}",
+ array(
+ array_merge( array( 'plugin' => $plugin_slug ), $plugin_data )
+ )
+ );
+ }
+
+ /**
+ * The cron trigger for the import job.
+ */
+ public static function cron_trigger( $args ) {
+ $plugin_slug = $args['plugin'];
+ $changed_tags = $args['tags_touched'];
+
+ try {
+ $importer = new CLI\Import;
+ $importer->import_from_svn( $plugin_slug, $changed_tags );
+ } catch( Exception $e ) {
+ fwrite( STDERR, "[{$plugin_slug}] Plugin Import Failed: " . $e->getMessage() . "\n" );
+ }
+
+ // Re-schedule any other jobs for this plugin to NOW()
+ $hook = current_filter();
+ if ( $next_timestamp = Manager::get_scheduled_time( $hook, 'next' ) ) {
+ Manager::reschedule_event(
+ $hook,
+ time() + HOUR_IN_SECONDS,
+ $next_timestamp
+ );
+ }
+ }
+
+}
</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-plugin-import.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_htmlwpcontentpluginsplugindirectoryjobsclasssvnwatcherphp"></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-svn-watcher.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-svn-watcher.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-svn-watcher.php 2016-12-13 09:44:54 UTC (rev 4520)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,21 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+namespace WordPressdotorg\Plugin_Directory\Jobs;
+use WordPressdotorg\Plugin_Directory\CLI;
+use Exception;
+
+/**
+ * Watch SVN changesets and queue up jobs to import the changed plugins.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Jobs
+ */
+class SVN_Watcher {
+
+ /**
+ * The cron trigger for the svn import job.
+ */
+ public static function cron_trigger() {
+ $watcher = new CLI\SVN_Watcher();
+ $watcher->watch();
+ }
+
+}
</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-svn-watcher.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></div>
</body>
</html>