<!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>[3164] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory: Plugin Directory: Imports: Many fixes to the import processes, optimizations, bugfixes, etc.</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/3164">3164</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/3164","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-05-18 02:12:47 +0000 (Wed, 18 May 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: Imports: Many fixes to the import processes, optimizations, bugfixes, etc.
See <a href="http://meta.trac.wordpress.org/ticket/1584">#1584</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorybinimportpluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin.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>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectorybinimportpluginphp"></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/bin/import-plugin.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/import-plugin.php 2016-05-18 02:08:28 UTC (rev 3163)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/import-plugin.php 2016-05-18 02:12:47 UTC (rev 3164)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -6,6 +6,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> die();
</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">+ob_start();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $opts = getopt( '', array( 'url:', 'abspath:', 'plugin:' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Guess the default parameters:
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -49,10 +51,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> echo "Processing Import for $plugin_slug... ";
</span><span class="cx" style="display: block; padding: 0 10px"> try {
</span><span class="cx" style="display: block; padding: 0 10px"> $importer = new CLI\Import;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $importer->import( $plugin_slug );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $importer->import_from_svn( $plugin_slug );
</ins><span class="cx" style="display: block; padding: 0 10px"> echo "OK\n";
</span><span class="cx" style="display: block; padding: 0 10px"> } catch( \Exception $e ) {
</span><span class="cx" style="display: block; padding: 0 10px"> echo "Failed.\n";
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- fwrite( STDERR, "Plugin Import Failed: " . $e->getMessage() . "\n" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ fwrite( STDERR, "[{$plugin_slug}] Plugin Import Failed: " . $e->getMessage() . "\n" );
</ins><span class="cx" style="display: block; padding: 0 10px"> exit(1);
</span><span class="cx" style="display: block; padding: 0 10px"> }
</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-05-18 02:08:28 UTC (rev 3163)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php 2016-05-18 02:12:47 UTC (rev 3164)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -6,6 +6,7 @@
</span><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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use Exception;
</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"> * The functionality required to process a plugin import into the Directory.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,59 +47,107 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $plugin_slug The slug of the plugin to import.
</span><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 import( $plugin_slug ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function import_from_svn( $plugin_slug ) {
+ global $wpdb;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $plugin = Plugin_Directory::get_plugin_post( $plugin_slug );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $plugin ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-// TODO throw new \Exception( "Unknown Plugin" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// TODO throw new Exception( "Unknown Plugin" );
</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"> $data = $this->export_and_parse_plugin( $plugin_slug );
</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 ( ! $plugin ) {
- global $wpdb;
- // TODO: During development while the bbPress variant is still running, we'll pull details from it and allow importing of any plugin.
- $author = $wpdb->get_var( $wpdb->prepare( 'SELECT topic_poster FROM ' . PLUGINS_TABLE_PREFIX . 'topics WHERE topic_slug = %s', $plugin_slug ) );
- if ( ! $author ) {
- throw new \Exception( "Unknown Plugin" );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // TODO: During development while the bbPress variant is still running, we'll pull details from it and allow importing of any plugin.
+ $topic = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . PLUGINS_TABLE_PREFIX . 'topics WHERE topic_slug = %s', $plugin_slug ) );
+
+ if ( ! $plugin && ! $topic ) {
+ throw new Exception( "Unknown Plugin" );
+ }
+
+ // TODO: During development we're just going to import status from bbPress.
+ $status = 'publish';
+ if ( 2 == $topic->topic_open ) {
+ $status = 'approved';
+ } elseif ( 2 == $topic->forum_id ) {
+ $status = 'pending';
+ } elseif ( 4 == $topic->forum_id || 'rejected-' == substr( $topic->topic_slug, 0, 9 ) ) {
+ $status = 'rejected';
+ } elseif ( 1 == $topic->forum_id && 0 == $topic->topic_open ) {
+ $status = 'closed';
+ } elseif ( 3 == $topic->topic_open ) {
+ $status = 'disabled';
+ }
+
+ if ( ! $plugin ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $plugin = Plugin_Directory::create_plugin_post( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'slug' => $plugin_slug,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'status' => 'publish', // If we're importing it on the CLI, and it didn't exist, assume it's published
- 'author' => $author
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'status' => $status,
+ 'author' => $topic->topic_poster,
+ 'post_date_gmt' => $topic->topic_start_time,
+ 'post_date' => $topic->topic_start_time,
+ 'post_modified' => $topic->topic_time,
+ 'post_modified_gmt' => $topic->topic_time,
</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 class="cx" style="display: block; padding: 0 10px"> $readme = $data['readme'];
</span><span class="cx" style="display: block; padding: 0 10px"> $assets = $data['assets'];
</span><span class="cx" style="display: block; padding: 0 10px"> $headers = $data['plugin_headers'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $stable_tag = $data['stable_tag'];
</ins><span class="cx" style="display: block; padding: 0 10px"> $tagged_versions = $data['tagged_versions'];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $content = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $readme->sections as $section => $section_content ) {
- $content .= "\n\n<!--section={$section}-->\n{$section_content}";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $readme->sections ) {
+ foreach ( $readme->sections as $section => $section_content ) {
+ $content .= "\n\n<!--section={$section}-->\n{$section_content}";
+ }
+ } elseif ( !empty( $headers->Description ) ) {
+ $content = "<!--section=description-->\n{$headers->Description}";
</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"> // Fallback to the plugin title if the readme didn't contain it.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin->post_title = trim( $readme->name ) ?: strip_tags( $headers->Name );
- $plugin->post_content = trim( $content );
- $plugin->post_excerpt = trim( $readme->short_description );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $plugin->post_title = trim( $readme->name ) ?: strip_tags( $headers->Name ) ?: $plugin->post_title;
+ $plugin->post_content = trim( $content ) ?: $plugin->post_content;
+ $plugin->post_excerpt = trim( $readme->short_description ) ?: $headers->Description ?: $plugin->post_excerpt;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $plugin->post_date = $topic->topic_start_time;
+ $plugin->post_date_gmt = $topic->topic_start_time;
+ $plugin->override_modified_date = true;
+ $plugin->post_modified = $topic->topic_time;
+ $plugin->post_modified_gmt = $topic->topic_time;
+
+ $plugin->post_status = $status;
+ if ( ! $plugin->post_title ) {
+ $plugin->post_title = $topic->topic_title;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Bump last updated if the version has changed.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $headers->Version != get_post_meta( $plugin->ID, 'version', true ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( !isset( $headers->Version ) || $headers->Version != get_post_meta( $plugin->ID, 'version', true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $plugin->post_modified = $plugin->post_modified_gmt = current_time( 'mysql' );
</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">+ add_filter( 'wp_insert_post_data', array( $this, 'filter_wp_insert_post_data' ), 10, 2 );
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_update_post( $plugin );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ remove_filter( 'wp_insert_post_data', array( $this, 'filter_wp_insert_post_data' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $this->readme_fields as $readme_field ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Don't change the tested version if a newer version was specified through wp-admin
</span><span class="cx" style="display: block; padding: 0 10px"> if ( 'tested' == $readme_field && version_compare( get_post_meta( $plugin->ID, 'tested', true ), $readme->$readme_field, '>' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- update_post_meta( $plugin->ID, $readme_field, wp_slash( $readme->$readme_field ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( 'stable_tag' == $readme_field ) {
+ // The stable_tag needs to come from the trunk readme at all times.
+ $value = $stable_tag;
+ } else {
+ $value = $readme->$readme_field;
+ }
+
+ update_post_meta( $plugin->ID, $readme_field, wp_slash( $value ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $this->plugin_headers as $plugin_header => $meta_field ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- update_post_meta( $plugin->ID, $meta_field, wp_slash( $headers->$plugin_header ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ update_post_meta( $plugin->ID, $meta_field, ( isset( $headers->$plugin_header ) ? wp_slash( $headers->$plugin_header ) : '' ) );
</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_post_meta( $plugin->ID, 'tagged_versions', wp_slash( $tagged_versions ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -140,48 +189,80 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $plugin_slug The slug of the plugin to parse.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * 'readme', 'trunk_readme', 'tmp_dir', 'plugin_headers', 'assets'
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * 'readme', 'stable_tag', 'plugin_headers', 'assets', 'tagged_versions'
</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"> protected function export_and_parse_plugin( $plugin_slug ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $tmp_dir = Filesystem::temp_directory( "process-{$plugin_slug}" );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $svn_export = SVN::export( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk", $tmp_dir . '/trunk', array( 'ignore-externals' ) );
- if ( ! $svn_export['result'] || empty( $svn_export['revision'] ) ) {
- throw new \Exception( "Could not create SVN export." . implode( ' ', reset( $svn_export['errors'] ) ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Find the trunk readme file, list remotely to avoid checking out the entire directory.
+ $trunk_files = SVN::ls( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk" );
+ if ( ! $trunk_files ) {
+ throw new Exception( 'Plugin has no files in trunk.' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $trunk_revision = $svn_export['revision'];
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $trunk_readme = $this->find_readme_file( $tmp_dir . '/trunk' );
- if ( ! $trunk_readme ) {
- throw new \Exception( "Could not locate a trunk readme" );
- }
- $trunk_readme = new Readme_Parser( $trunk_readme );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // A plugin historically doesn't have to have a readme.
+ $trunk_readme_files = preg_grep( '!^readme.(txt|md)$!i', $trunk_files );
+ if ( $trunk_readme_files ) {
+ $trunk_readme_file = reset( $trunk_readme_files );
+ foreach ( $trunk_readme_files as $f ) {
+ if ( '.txt' == strtolower( substr( $f, -4 ) ) ) {
+ $trunk_readme_file = $f;
+ break;
+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $trunk_readme->stable_tag == 'trunk' || empty( $trunk_readme->stable_tag ) ) {
- $readme = $trunk_readme;
- $stable = 'trunk';
- $stable_revision = $trunk_revision;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $trunk_readme_file = self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk/{$trunk_readme_file}";
+ $trunk_readme = new Readme_Parser( $trunk_readme_file );
+
+ $stable_tag = $trunk_readme->stable_tag;
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // There's a chance that the stable_tag will not actually exist, we have to fallback to trunk in those cases and avoid exiting here.
- $stable_tag = preg_replace( '![^a-z0-9-_.]!i', '', $trunk_readme->stable_tag );
- $svn_export = SVN::export( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$stable_tag}", $tmp_dir . '/stable', array( 'ignore-externals' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $stable_tag = 'trunk';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $stable_readme = $svn_export['result'] ? $this->find_readme_file( $tmp_dir . '/stable' ) : false;
- if ( $stable_readme ) {
- $readme = $stable_readme = new Readme_Parser( $stable_readme );
- $stable = 'stable';
- $stable_revision = $svn_export['revision'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $exported = false;
+ if ( $stable_tag && 'trunk' != $stable_tag ) {
+ $svn_export = SVN::export(
+ self::PLUGIN_SVN_BASE . "/{$plugin_slug}/tags/{$stable_tag}",
+ $tmp_dir . '/export',
+ array(
+ 'ignore-externals',
+ 'depth' => 'files'
+ )
+ );
+ if ( $svn_export['result'] && false !== $this->find_readme_file( $tmp_dir . '/export' ) ) {
+ $exported = true;
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Trunk is stable!
- $readme = $trunk_readme;
- $stable = 'trunk';
- $stable_revision = $trunk_revision;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Clear out any files that exist in the export.
+ Filesystem::rmdir( $tmp_dir . '/export' );
</ins><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">+ if ( ! $exported ) {
+ $stable_tag = 'trunk';
+ // Either stable_tag = trunk, or the stable_tag tag didn't exist.
+ $svn_export = SVN::export(
+ self::PLUGIN_SVN_BASE . "/{$plugin_slug}/trunk",
+ $tmp_dir . '/export',
+ array(
+ 'ignore-externals',
+ 'depth' => 'files' // Only export the root files, we don't need the rest to read the plugin headers/screenshots
+ )
+ );
+ if ( ! $svn_export['result'] || empty( $svn_export['revision'] ) ) {
+ throw new Exception( 'Could not create SVN export: ' . implode( ' ', reset( $svn_export['errors'] ) ) );
+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $plugin_headers = $this->find_plugin_headers( "$tmp_dir/$stable" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // The readme may not actually exist, but that's okay.
+ $readme = $this->find_readme_file( $tmp_dir . '/export' );
+ $readme = new Readme_Parser( $readme );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // There must be valid plugin headers though.
+ $plugin_headers = $this->find_plugin_headers( "$tmp_dir/export" );
+ if ( ! $plugin_headers ) {
+ throw new Exception( 'Could not find the plugin headers.' );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Now we look in the /assets/ folder for banners, screenshots, and icons.
</span><span class="cx" style="display: block; padding: 0 10px"> $assets = array( 'screenshot' => array(), 'banner' => array(), 'icon' => array() );
</span><span class="cx" style="display: block; padding: 0 10px"> $svn_assets_folder = SVN::ls( self::PLUGIN_SVN_BASE . "/{$plugin_slug}/assets/", true /* verbose */ );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -200,13 +281,13 @@
</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">- $tagged_versions = SVN::ls( "https://plugins.svn.wordpress.org/{$plugin_slug}/tags/" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $tagged_versions = SVN::ls( "https://plugins.svn.wordpress.org/{$plugin_slug}/tags/" ) ?: array();
</ins><span class="cx" style="display: block; padding: 0 10px"> $tagged_versions = array_map( function( $item ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return rtrim( $item, '/' );
</span><span class="cx" style="display: block; padding: 0 10px"> }, $tagged_versions );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Find screenshots in the stable plugin folder (but don't overwrite /assets/)
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( Filesystem::list_files( "$tmp_dir/$stable/", false /* non-recursive */, '!^screenshot-\d+\.(jpeg|jpg|png|gif)$!' ) as $plugin_screenshot ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( Filesystem::list_files( "$tmp_dir/export/", false /* non-recursive */, '!^screenshot-\d+\.(jpeg|jpg|png|gif)$!' ) as $plugin_screenshot ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $filename = basename( $plugin_screenshot );
</span><span class="cx" style="display: block; padding: 0 10px"> $screenshot_id = substr( $filename, strpos( $filename, '-' ) + 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> $screenshot_id = substr( $screenshot_id, 0, strpos( $screenshot_id, '.' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -218,16 +299,32 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $assets['screenshot'][ $filename ] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'filename' => $filename,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'revision' => $stable_revision,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'revision' => $svn_export['revision'],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'resolution' => $screenshot_id,
</span><span class="cx" style="display: block; padding: 0 10px"> 'location' => 'plugin',
</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">- return compact( 'readme', 'trunk_readme', 'tmp_dir', 'plugin_headers', 'assets', 'tagged_versions' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return compact( 'readme', 'stable_tag', 'tmp_dir', 'plugin_headers', 'assets', 'tagged_versions' );
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Filters `wp_insert_post()` to allow a custom modified date to be specified.
+ *
+ * @param array $data The data to be inserted into the database.
+ * @param array $postarr The raw data passed to `wp_insert_post()`.
+ *
+ * @return array The data to insert into the database.
+ */
+ public function filter_wp_insert_post_data( $data, $postarr ) {
+ if ( !empty( $postarr['override_modified_date'] ) ) {
+ $data['post_modified'] = $postarr['post_modified'];
+ $data['post_modified_gmt'] = $postarr['post_modified_gmt'];
+ }
+ return $data;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Find the plugin readme file.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Looks for either a readme.txt or readme.md file, prioritizing readme.txt.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -259,13 +356,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> protected function find_plugin_headers( $directory ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $files = Filesystem::list_files( $directory, false, '!\.php$!i' );
</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 ( ! function_exists( 'get_plugin_data' ) ) {
+ require ABSPATH . 'wp-admin/includes/plugin.php';
+ }
+
+ /*
+ * Sometimes plugins have multiple files which we detect as a plugin based on the headers.
+ * We'll return immediately if the file has a `Plugin Name:` header, otherwise
+ * simply return the last set of headers we come across.
+ */
+ $possible_headers = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $files as $file ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data = get_plugin_data( $file, false, false );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( array_filter( $data ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return (object) $data;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $data['Name'] ) {
+ return (object) $data;
+ } else {
+ $possible_headers = (object) $data;
+ }
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $possible_headers ) {
+ return $possible_headers;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>