@@ -27,7 +27,8 @@ class Runner
2727 protected $ pdoclass ;
2828 protected $ db ;
2929 protected $ workers = [];
30- protected $ wp_path ;
30+ protected $ wp_base_path ;
31+ protected $ wpconfig_path ;
3132 protected $ table_prefix ;
3233 protected $ table ;
3334 protected $ state ;
@@ -40,6 +41,7 @@ public function __construct(
4041 $ pdoclass ,
4142 $ max_workers ,
4243 $ wpcli_path ,
44+ $ wpconfig_path ,
4345 $ cleanup_interval ,
4446 $ cleanup_delay ,
4547 $ wp_base_path ,
@@ -49,9 +51,10 @@ public function __construct(
4951 $ this ->pdoclass = $ pdoclass ;
5052 $ this ->max_workers = $ max_workers ;
5153 $ this ->wpcli_path = $ wpcli_path ;
54+ $ this ->wpconfig_path = $ wpconfig_path ;
5255 $ this ->cleanup_interval = $ cleanup_interval ;
5356 $ this ->cleanup_delay = $ cleanup_delay ;
54- $ this ->wp_path = realpath ( $ wp_base_path) ;
57+ $ this ->wp_base_path = $ wp_base_path ;
5558 $ this ->max_log_size = $ max_log_size ;
5659 $ this ->state_path = $ state_path ;
5760 $ this ->hooks = new Hooks ();
@@ -68,6 +71,7 @@ public static function instance(
6871 $ pdoclass ,
6972 $ max_workers ,
7073 $ wpcli_path ,
74+ $ wpconfig_path ,
7175 $ cleanup_interval ,
7276 $ cleanup_delay ,
7377 $ wp_base_path ,
@@ -80,6 +84,7 @@ public static function instance(
8084 $ pdoclass ,
8185 $ max_workers ,
8286 $ wpcli_path ,
87+ $ wpconfig_path ,
8388 $ cleanup_interval ,
8489 $ cleanup_delay ,
8590 $ wp_base_path ,
@@ -126,15 +131,8 @@ public function bootstrap()
126131 {
127132 $ this ->load_state ();
128133
129- $ config_path = $ this ->wp_path . '/wp-config.php ' ;
130- if (!file_exists ($ config_path )) {
131- $ config_path = realpath ($ this ->wp_path . '/../wp-config.php ' );
132- if (!file_exists ($ config_path )) {
133- throw new Exception (sprintf (
134- 'Could not find config file at %s ' ,
135- $ this ->wp_path . '/wp-config.php or next level up. '
136- ));
137- }
134+ if (!file_exists ($ this ->wpconfig_path )) {
135+ throw new Exception ('Could not find config file at ' . $ this ->wpconfig_path );
138136 }
139137
140138 // Load configuration ONLY
@@ -143,7 +141,7 @@ public function bootstrap()
143141 $ _SERVER ['HTTP_HOST ' ] = 'cavalcade.example ' ;
144142 }
145143
146- include $ config_path ;
144+ include $ this -> wpconfig_path ;
147145 $ this ->table_prefix = isset ($ table_prefix ) ? $ table_prefix : 'wp_ ' ;
148146 $ this ->table = $ this ->table_prefix . 'cavalcade_jobs ' ;
149147 $ charset = defined ('DB_CHARSET ' ) ? DB_CHARSET : 'utf8mb4 ' ;
@@ -528,11 +526,6 @@ protected function terminate($type)
528526 unset($ this ->db );
529527 }
530528
531- public function get_wp_path ()
532- {
533- return $ this ->wp_path ;
534- }
535-
536529 protected function get_next_job ()
537530 {
538531 // $this->log->debug('trying to get next job');
@@ -592,7 +585,15 @@ protected function run_job($job)
592585 1 => ['pipe ' , 'w ' ], // stdout
593586 2 => ['pipe ' , 'w ' ], // stderr
594587 ];
595- $ process = proc_open ($ command , $ spec , $ pipes , $ this ->wp_path );
588+
589+ // Resolve path every time to support atomic deployment.
590+ $ wp_path = realpath ($ this ->wp_base_path );
591+ if ($ wp_path === false ) {
592+ $ this ->log ->error ('failed to resolve path: ' . $ this ->wp_base_path );
593+ throw new Exception ('failed to resolve path ' );
594+ }
595+
596+ $ process = proc_open ($ command , $ spec , $ pipes , $ wp_path );
596597
597598 if ($ process === false ) {
598599 throw new Exception ('unable to proc_open() ' );
0 commit comments