Skip to content

Commit ff290a9

Browse files
committed
Create update page in WordPress during setup.
1 parent 35991a2 commit ff290a9

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ From http://plugins.jquery.com.dev/wp-admin/
8080

8181
3. `npm install`
8282

83-
4. `cp src/config-sample.json src/config.json`
83+
4. `cp config-sample.json config.json`
8484

85-
5. Edit src/config.json
85+
5. Edit config.json
8686
* Set `dbName` to your WordPress MySQL database name
8787
* Set `dbUser` to your WordPress MySQL database user
8888
* Set `dbPassword` to your WordPress MySQL database password
File renamed without changes.

src/config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var path = require( "path" ),
2+
config = require( "../config" );
3+
4+
function resolvePath( key, _default ) {
5+
config[ key ] = path.resolve( __dirname, "..", config[ key ] || _default );
6+
}
7+
8+
resolvePath( "repoDir", "/tmp/plugin-repos" );
9+
resolvePath( "pluginsDb", "plugins.db" );
10+
11+
module.exports = config;

src/wordpress.js

+46-5
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function setTerms( postId, terms, fn ) {
285285

286286
/** util **/
287287

288-
function flush ( fn ) {
288+
function flush( fn ) {
289289
db.query( "DELETE FROM `" + optionsTable + "` WHERE `option_name` = 'rewrite_rules'", fn );
290290
}
291291

@@ -424,15 +424,56 @@ var wordpress = module.exports = {
424424
},
425425

426426
_reset: auto(function( fn ) {
427+
var path = require( "path" );
428+
427429
Step(
430+
// remove existing content
428431
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() );
432443
});
433-
wordpress.flush( parallel() );
434444
},
435445

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
436477
function( error ) {
437478
wordpress.end();
438479
fn( error );

0 commit comments

Comments
 (0)