OSDN Git Service

continue searching after finding an index.php that doesn't contain the path to wp...
authorscribu <mail@scribu.net>
Fri, 31 Jan 2014 00:36:20 +0000 (02:36 +0200)
committerscribu <mail@scribu.net>
Fri, 31 Jan 2014 00:36:20 +0000 (02:36 +0200)
features/config.feature
php/WP_CLI/Runner.php

index f3021ec..b103ef7 100644 (file)
@@ -76,6 +76,7 @@ Feature: Have a config file
     Then STDOUT should be empty
 
     When I run `mkdir -p other/subdir`
+    And I run `echo '<?php // Silence is golden' > other/subdir/index.php`
     And I run `wp core is-installed` from 'other/subdir'
     Then STDOUT should be empty
 
index 6abb09a..d43b2c7 100644 (file)
@@ -77,9 +77,6 @@ class Runner {
         * Attempts to find the path to the WP install inside index.php
         */
        private static function extract_subdir_path( $index_path ) {
-               if ( !file_exists( $index_path ) )
-                       return false;
-
                $index_code = file_get_contents( $index_path );
 
                if ( !preg_match( '|^\s*require\s*\(?\s*(.+?)/wp-blog-header\.php([\'"])|m', $index_code, $matches ) ) {
@@ -115,11 +112,24 @@ class Runner {
                        return getcwd();
                }
 
-               if ( $wp_load_path = Utils\find_file_upward( 'wp-load.php' ) ) {
-                       return dirname( $wp_load_path );
-               }
+               $dir = getcwd();
+
+               while ( is_readable( $dir ) ) {
+                       if ( file_exists( "$dir/wp-load.php" ) ) {
+                               return $dir;
+                       }
 
-               return self::extract_subdir_path( Utils\find_file_upward( 'index.php' ) );
+                       if ( file_exists( "$dir/index.php" ) ) {
+                               if ( $path = self::extract_subdir_path( "$dir/index.php" ) )
+                                       return $path;
+                       }
+
+                       $parent_dir = dirname( $dir );
+                       if ( empty($parent_dir) || $parent_dir === $dir ) {
+                               break;
+                       }
+                       $dir = $parent_dir;
+               }
        }
 
        private static function set_wp_root( $path ) {