OSDN Git Service

Make wp rewrite (flush|structure) generate .htaccess files properly for apache.
authorEugene Ware <eugene@noblesamurai.com>
Wed, 26 Jun 2013 06:37:16 +0000 (16:37 +1000)
committerEugene Ware <eugene@noblesamurai.com>
Wed, 26 Jun 2013 06:37:16 +0000 (16:37 +1000)
php/commands/rewrite.php
php/config-spec.php

index 7f464ae..3453496 100644 (file)
@@ -10,16 +10,18 @@ class Rewrite_Command extends WP_CLI_Command {
        /**
         * Flush rewrite rules.
         *
-        * @synopsis [--soft]
+        * @synopsis [--hard]
         */
        public function flush( $args, $assoc_args ) {
-               flush_rewrite_rules( isset( $assoc_args['soft'] ) );
+               // make sure we detect mod_rewrite if configured in apache_modules in config
+               self::apache_modules();
+               flush_rewrite_rules( isset( $assoc_args['hard'] ) );
        }
 
        /**
         * Update the permalink structure.
         *
-        * @synopsis <permastruct> [--category-base=<base>] [--tag-base=<base>]
+        * @synopsis <permastruct> [--category-base=<base>] [--tag-base=<base>] [--hard]
         */
        public function structure( $args, $assoc_args ) {
                global $wp_rewrite;
@@ -62,7 +64,9 @@ class Rewrite_Command extends WP_CLI_Command {
                        $wp_rewrite->set_tag_base( $tag_base );
                }
 
-               flush_rewrite_rules( $hard );
+               // make sure we detect mod_rewrite if configured in apache_modules in config
+               self::apache_modules();
+               flush_rewrite_rules( isset( $assoc_args['hard'] ) );
        }
 
        /**
@@ -86,6 +90,22 @@ class Rewrite_Command extends WP_CLI_Command {
                }
 
        }
+
+       /**
+        * Expose apache modules if present in config
+        */
+       public static function apache_modules() {
+               $mods = WP_CLI::get_config('apache_modules');
+               if ( count($mods) > 0 && !function_exists( 'apache_get_modules') ) {
+                       global $is_apache;
+                       $is_apache = true;
+
+                       function apache_get_modules() {
+                               return WP_CLI::get_config('apache_modules');
+                       }
+               }
+       }
+
 }
 
 WP_CLI:: add_command( 'rewrite', 'Rewrite_Command' );
index 61aaf46..1ec7556 100644 (file)
@@ -63,5 +63,12 @@ return array(
                'default' => false,
                'desc' => 'Suppress informational messages',
        ),
+
+       'apache_modules' => array(
+               'file' => '<bool>',
+               'desc' => 'List of Apache Modules that are to be reported as loaded',
+               'multiple' => true,
+               'default' => array(),
+       ),
 );