8000 Set keywords on versionless post. · sequoiar/plugins.jquery.com@523c2d9 · GitHub
Skip to content

Commit 523c2d9

Browse files
committed
Set keywords on versionless post.
1 parent 1295d6f commit 523c2d9

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

src/wordpress.js

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,24 @@ function createOrUpdatePost( name, title, content, fn ) {
5555
}
5656

5757
if ( !id ) {
58-
createPost( name, title, content, fn );
58+
createPost( name, title, content, function( error, info ) {
59+
if ( error ) {
60+
return fn( error );
61+
}
62+
63+
fn( null, info.insertId );
64+
});
5965
} else {
6066
db.query( "UPDATE `" + postsTable + "` " +
6167
"SET `post_content` = ? " +
6268
"WHERE `ID` = ?",
63-
[ content, id ], fn );
69+
[ content, id ], function( error ) {
70+
if ( error ) {
71+
return fn( error );
72+
}
73+
74+
fn( null, id );
75+
});
6476
}
6577
});
6678
}
@@ -250,8 +262,14 @@ var wordpress = module.exports = {
250262

251263
setVersions: auto(function( plugin, versions, latest, fn ) {
252264
var postName = plugin + "/" + latest;
253-
db.query( "SELECT `post_title`, `post_content` FROM `" + postsTable + "` WHERE `post_name` = ?",
254-
[ postName ], function( error, rows ) {
265+
Step(
266+
function() {
267+
db.query( "SELECT `ID`, `post_title`, `post_content` " +
268+
"FROM `" + postsTable + "` WHERE `post_name` = ?",
269+
[ postName ], this );
270+
},
271+
272+
function( error, rows ) {
255273
if ( error ) {
256274
return fn( error );
257275
}
@@ -260,14 +278,30 @@ var wordpress = module.exports = {
260278
return fn( new Error( "No post for " + postName ) );
261279
}
262280

263-
createOrUpdatePost( plugin, rows[ 0 ].post_title, rows[ 0 ].post_content, function( error ) {
264-
if ( error ) {
265-
return fn( error );
266-
}
281+
createOrUpdatePost( plugin, rows[ 0 ].post_title, rows[ 0 ].post_content, this.parallel() );
282+
this.parallel()( null, rows[ 0 ].ID );
283+
},
267284

268-
setMeta( plugin, "versions", JSON.stringify( versions ), fn );
269-
});
270-
});
285+
function( error, mainId, versionedId ) {
286+
if ( error ) {
287+
return fn( error );
288+
}
289+
290+
setMeta( plugin, "versions", JSON.stringify( versions ), this.parallel() );
291+
db.query( "INSERT INTO `" + termRelationshipsTable + "` (`object_id`, `term_taxonomy_id`) " +
292+
"(SELECT ?, `term_taxonomy_id` FROM `" + termRelationshipsTable + "` " +
293+
"WHERE `object_id` = ?)",
294+
[ mainId, versionedId ], this.parallel() );
295+
},
296+
297+
function( error ) {
298+
if ( error ) {
299+
return fn( error );
300+
}
301+
302+
fn( null );
303+
}
304+
);
271305
}),
272306

273307
updateMeta: auto(function( plugin, meta, fn ) {

0 commit comments

Comments
 (0)