@@ -55,12 +55,24 @@ function createOrUpdatePost( name, title, content, fn ) {
55
55
}
56
56
57
57
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
+ } ) ;
59
65
} else {
60
66
db . query ( "UPDATE `" + postsTable + "` " +
61
67
"SET `post_content` = ? " +
62
68
"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
+ } ) ;
64
76
}
65
77
} ) ;
66
78
}
@@ -250,8 +262,14 @@ var wordpress = module.exports = {
250
262
251
263
setVersions : auto ( function ( plugin , versions , latest , fn ) {
252
264
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 ) {
255
273
if ( error ) {
256
274
return fn ( error ) ;
257
275
}
@@ -260,14 +278,30 @@ var wordpress = module.exports = {
260
278
return fn ( new Error ( "No post for " + postName ) ) ;
261
279
}
262
280
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
+ } ,
267
284
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
+ ) ;
271
305
} ) ,
272
306
273
307
updateMeta : auto ( function ( plugin , meta , fn ) {
0 commit comments