forked from postlight/headless-wp-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
124 lines (105 loc) · 4.52 KB
/
RoboFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
define( 'PROJECT_DIR', dirname( __FILE__ ) );
define( 'TMP_DIR', PROJECT_DIR . '/tmp' );
define( 'WP_DIR', PROJECT_DIR . '/wordpress' );
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks {
public function wordpressSetup( $opts = [
'wp-user' => 'nedstark',
'wp-pw' => 'winteriscoming',
'wp-theme-dir' => 'postlight-headless-wp',
'wp-theme-name' => 'Postlight Headless WP Starter',
'wp-email' => 'nedstark@headlesswpstarter.dev',
'wp-db-name' => 'wp_headless',
'wp-plugins' => array(),
] ) {
$confirm = $this->io()->confirm( 'This will replace your current ' .
'WordPress install. Are you sure you want to do this?', false );
if ( ! $confirm ) {
return;
}
$this->_exec( "mysql -uroot -proot -h 0.0.0.0 -e 'create user if not exists " . $opts['wp-db-name'] . "'" );
$this->_exec( "mysql -uroot -proot -h 0.0.0.0 -e 'create database if not exists " . $opts['wp-db-name'] . "'" );
$this->_exec( 'mysql -uroot -proot -h 0.0.0.0 -e "grant all privileges on ' . $opts['wp-db-name']
. ' . * to ' . $opts['wp-db-name'] . "@localhost identified by '" . $opts['wp-db-name'] . "'\"" );
$this->_exec( "mysql -uroot -proot -h 0.0.0.0 -e 'flush privileges'" );
$this->wp( 'core download --version=4.9 --locale=en_US --force' );
$this->wp( 'core config --dbname=' . $opts['wp-db-name'] . ' --dbuser=' . $opts['wp-db-name'] . ' --dbpass=' . $opts['wp-db-name'] . ' --dbhost=0.0.0.0' );
$this->wp( 'db drop --yes' );
$this->wp( 'db create --yes' );
$install_command = implode( ' ', array(
'core install',
'--url=localhost:8080',
'--title="' . $opts['wp-theme-name'] . '"',
'--admin_user="' . $opts['wp-user'] . '"',
'--admin_password="' . $opts['wp-pw'] . '"',
'--admin_email="' . $opts['wp-email'] . '"',
'--skip-email',
) );
$this->wp( $install_command );
$this->wp( 'theme activate ' . $opts['wp-theme-dir'] );
$this->wp( 'theme delete twentyfourteen' );
$this->wp( 'theme delete twentyfifteen' );
$this->wp( 'theme delete twentysixteen' );
$this->wp( 'theme delete twentyseventeen' );
$this->wp( 'plugin delete akismet' );
$this->wp( 'plugin delete hello' );
if ( is_array( $opts['wp-plugins'] ) && sizeof( $opts['wp-plugins'] ) > 0 ) {
$installed_plugin_directories = $opts['wp-plugins'];
} else {
$installed_plugins = array_filter( glob( WP_DIR . '/wp-content/plugins/*' ), 'is_dir' );
$installed_plugin_directories = array_filter( str_replace( WP_DIR . '/wp-content/plugins/', '', $installed_plugins ) );
}
if ( sizeof( $installed_plugin_directories ) > 0 ) {
$plugins_command = 'plugin activate ' . ( implode( ' ', $installed_plugin_directories ) );
$this->wp( $plugins_command );
}
// Sync ACF
$this->wp( 'acf sync' );
// Pretty URL structure required for wp-json path to work correctly
$this->wp( 'rewrite structure "/%year%/%monthnum%/%day%/%postname%/"' );
// Set up example menu
$this->wp( 'menu create "My Menu"' );
$this->wp( 'menu item add-custom my-menu "About the Starter Kit" https://trackchanges.postlight.com/introducing-postlights-wordpress-react-starter-kit-a61e2633c48c' );
$this->wp( 'menu location assign my-menu main' );
$this->io()->success( 'Great. You can now log into WordPress at: http://localhost:8080/wp-admin (' . $opts['wp-user'] . '/' . $opts['wp-pw'] . ')' );
}
public function server() {
$this->wp( 'server' );
}
public function wordpressImport( $opts = [
'migratedb-license' => null,
'migratedb-from' => null,
] ) {
if ( isset( $opts['migratedb-license'] ) ) {
$this->wp( 'migratedb setting update license ' . $opts['migratedb-license'] );
} else {
$this->say( 'WP Migrate DB Pro: no license available. Please set migratedb-license in the robo.yml file.' );
return;
}
if ( isset( $opts['migratedb-from'] ) ) {
$command = 'WPMDB_EXCLUDE_RESIZED_MEDIA=1 wp migratedb pull ';
$command .= $opts['migratedb-from'];
$command .= ' --backup=prefix ';
$command .= ' --media=compare ';
$this->io()->success( 'About to run data migration from ' . $opts['migratedb-from'] );
$this->taskExec( $command )->run();
// Set siteurl and home
$this->wp( 'option update siteurl http://localhost:8080' );
$this->wp( 'option update home http://localhost:8080' );
} else {
$this->say( 'WP Migrate DB Pro: No source installation specified. Please set migratedb-from in the robo.yml file.' );
return;
}
}
public function wp( $arg ) {
$this->taskExec( 'wp' )
->dir( WP_DIR )
->rawArg( $arg )
->run();
}
}