Skip to content

Commit 1295d6f

Browse files
committed
Store keywords for versioned posts.
1 parent 9d08c05 commit 1295d6f

File tree

2 files changed

+87
-14
lines changed

2 files changed

+87
-14
lines changed

src/wordpress.js

Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ var mysql = require( "mysql" ),
44

55
var db,
66
postIds = {},
7-
postsTable = table( "posts" );
7+
optionsTable = table( "options" ),
88
postmetaTable = table( "postmeta" ),
9-
optionsTable = table( "options" );
9+
postsTable = table( "posts" ),
10+
termsTable = table( "terms" ),
11+
termRelationshipsTable = table( "term_relationships" ),
12+
termTaxonomyTable = table( "term_taxonomy" );
1013

1114
function table( name ) {
1215
return "wp_" + (config.siteId ? config.siteId + "_" : "") + name;
@@ -152,13 +155,27 @@ function auto( fn ) {
152155
var wordpress = module.exports = {
153156
addVersionedPlugin: auto(function( version, package, content, fn ) {
154157
var postName = package.name + "/" + package.version;
155-
createPost( postName, package.title, content, function( error ) {
156-
if ( error ) {
157-
return fn( error );
158-
}
158+
Step(
159+
function() {
160+
createPost( postName, package.title, content, this );
161+
},
159162

160-
setMeta( postName, "package_json", JSON.stringify( package ), fn );
161-
});
163+
function( error ) {
164+
var parallel = this.parallel;
165+
setMeta( postName, "package_json", JSON.stringify( package ), parallel() );
166+
(package.keywords || []).forEach(function( keyword ) {
167+
wordpress.setTerm( postName, keyword, parallel() );
168+
});
169+
},
170+
171+
function( error ) {
172+
if ( error ) {
173+
return fn( error );
174+
}
175+
176+
fn( null );
177+
}
178+
);
162179
}),
163180

164181
getPendingVersions: auto(function( plugin, fn ) {
@@ -273,6 +290,62 @@ var wordpress = module.exports = {
273290
);
274291
}),
275292

293+
createTerm: auto(function( term, fn ) {
294+
Step(
295+
function() {
296+
db.query( "INSERT INTO `" + termsTable + "` SET `name` = ?, `slug` = ? " +
297+
"ON DUPLICATE KEY UPDATE `term_id` = LAST_INSERT_ID(`term_id`)",
298+
[ term, term ], this );
299+
},
300+
301+
function( error, info ) {
302+
if ( error ) {
303+
return fn( error );
304+
}
305+
306+
db.query( "INSERT INTO `" + termTaxonomyTable + "` " +
307+
"SET `term_id` = ?, `taxonomy` = 'post_tag' " +
308+
"ON DUPLICATE KEY UPDATE `term_taxonomy_id` = LAST_INSERT_ID(`term_taxonomy_id`)",
309+
[ info.insertId ], this );
310+
},
311+
312+
function( error, info ) {
313+
if ( error ) {
314+
return fn( error );
315+
}
316+
317+
fn( null, info.insertId );
318+
}
319+
);
320+
}),
321+
322+
setTerm: auto(function( post, term, fn ) {
323+
Step(
324+
function() {
325+
getPostId( post, this.parallel() );
326+
wordpress.createTerm( term, this.parallel() );
327+
},
328+
329+
function( error, postId, termId ) {
330+
if ( error ) {
331+
return fn( error );
332+
}
333+
334+
db.query( "INSERT INTO `" + termRelationshipsTable + "` " +
335+
"SET `object_id` = ?, `term_taxonomy_id` = ?",
336+
[ postId, termId ], this );
337+
},
338+
339+
function( error, termId ) {
340+
if ( error ) {
341+
return fn( error );
342+
}
343+
344+
fn( null );
345+
}
346+
);
347+
}),
348+
276349
flush: auto(function( fn ) {
277350
db.query( "DELETE FROM `" + optionsTable + "` WHERE `option_name` = 'rewrite_rules'", fn );
278351
}),
@@ -287,9 +360,11 @@ var wordpress = module.exports = {
287360
_reset: auto(function( fn ) {
288361
Step(
289362
function() {
290-
db.query( "TRUNCATE TABLE `" + postsTable + "`", this.parallel() );
291-
db.query( "TRUNCATE TABLE `" + postmetaTable + "`", this.parallel() );
292-
wordpress.flush( this.parallel() );
363+
var parallel = this.parallel;
364+
[ postmetaTable, postsTable, termsTable, termRelationshipsTable, termTaxonomyTable ].forEach(function( table ) {
365+
db.query( "TRUNCATE TABLE `" + table + "`", parallel() );
366+
});
367+
wordpress.flush( parallel() );
293368
},
294369

295370
function( error ) {

template/page

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858
</div>
5959
<div class="block">
6060
<h2>Tags</h2>
61-
<ul>
62-
<li>?</li>
63-
</ul>
61+
[jq_plugin_keywords]
6462
</div>
6563
</div>

0 commit comments

Comments
 (0)