@@ -285,7 +285,7 @@ function setTerms( postId, terms, fn ) {
285
285
286
286
/** util **/
287
287
288
- function flush ( fn ) {
288
+ function flush ( fn ) {
289
289
db . query ( "DELETE FROM `" + optionsTable + "` WHERE `option_name` = 'rewrite_rules'" , fn ) ;
290
290
}
291
291
@@ -424,15 +424,56 @@ var wordpress = module.exports = {
424
424
} ,
425
425
426
426
_reset : auto ( function ( fn ) {
427
+ var path = require ( "path" ) ;
428
+
427
429
Step (
430
+ // remove existing content
428
431
function ( ) {
429
- var parallel = this . parallel ;
430
- [ postmetaTable , postsTable , termsTable , termRelationshipsTable , termTaxonomyTable ] . forEach ( function ( table ) {
431
- db . query ( "TRUNCATE TABLE `" + table + "`" , parallel ( ) ) ;
432
+ var group = this . group ( ) ;
433
+
434
+ // remove existing content
435
+ [
436
+ postmetaTable ,
437
+ postsTable ,
438
+ termsTable ,
439
+ termRelationshipsTable ,
440
+ termTaxonomyTable
441
+ ] . forEach ( function ( table ) {
442
+ db . query ( "TRUNCATE TABLE `" + table + "`" , group ( ) ) ;
432
443
} ) ;
433
- wordpress . flush ( parallel ( ) ) ;
434
444
} ,
435
445
446
+ // create update page
447
+ function ( error ) {
448
+ if ( error ) {
449
+ throw error ;
450
+ }
451
+
452
+ db . query ( "INSERT INTO `" + postsTable + "` " +
453
+ "SET `post_type` = 'page', `post_name` = 'update', `post_title` = 'update', " +
454
+ "`post_status` = 'publish', `post_content_filtered` = ?" ,
455
+ [ path . resolve ( __dirname , "update.js" ) ] , this ) ;
456
+ } ,
457
+
458
+ // set page template for update page
459
+ function ( error , info ) {
460
+ if ( error ) {
461
+ throw error ;
462
+ }
463
+
464
+ setMeta ( info . insertId , "_wp_page_template" , "post-receive.php" , this ) ;
465
+ } ,
466
+
467
+ // clear rewrite rules
468
+ function ( error ) {
469
+ if ( error ) {
470
+ throw error ;
471
+ }
472
+
473
+ wordpress . flush ( this ) ;
474
+ } ,
475
+
476
+ // close database connection
436
477
function ( error ) {
437
478
wordpress . end ( ) ;
438
479
fn ( error ) ;
0 commit comments