Plugin Directory

Changeset 1214050


Ignore:
Timestamp:
08/06/2015 12:47:34 PM (11 years ago)
Author:
samface
Message:

fixed file permissions and site visibility repair issues

Location:
angry-creative-logger/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • angry-creative-logger/trunk/classes/wp_cli.php

    r1189487 r1214050  
    2828        $all_routines = ACI_Routine_Handler::get_inspection_routines();
    2929        $all_routine_slugs = array();
     30        $routine_repair_methods = array();
    3031        $force_inspect = true;
    3132
     
    9394                }
    9495
    95         if ( AC_Inspector::$error_count ) {
     96                if ( AC_Inspector::$error_count ) {
    9697                    AC_Inspector::$error_count = 0;
    9798                    continue;
     
    100101                $routine_log_count = AC_Inspector::$log_count - $total_log_count;
    101102
    102             WP_CLI::success( "Inspected $routine with $routine_log_count remark(s).\n" );
     103                WP_CLI::success( "Inspected $routine with $routine_log_count remark(s).\n" );
    103104
    104105                if ( $routine_log_count > 0 ) {
    105106
    106107                    $repair_method = ACI_Routine_Handler::get_repair_method( $all_routines[$routine_key], $routine_options );
     108
    107109                    if ( !empty( $repair_method ) ) {
    108 
    109                         WP_CLI::confirm( "Routine $routine has a repair method that may or may not fix the problem for you.\n" .
    110                                          "Have you made a backup of your website's entire source code, uploaded files and database\n" .
    111                                          "and want me to try and run the repair method with the risk of me messing everything up?" );
    112 
    113                         $total_log_count = AC_Inspector::$log_count;
    114                         $total_error_count = AC_Inspector::$error_count;
    115                         $total_success_count = AC_Inspector::$success_count;
    116 
    117                         call_user_func( $repair_method );
    118 
    119                         $routine_log_count = AC_Inspector::$log_count - $total_log_count;
    120                         $routine_error_count = AC_Inspector::$error_count - $total_error_count;
    121                         $routine_success_count = AC_Inspector::$success_count - $total_success_count;
    122 
    123                         if ( $routine_error_count > 0 ) {
    124                             WP_CLI::error( "Repair method for routine '$routine' yielded $routine_error_count error(s).\n" );
    125                         } else if ( $routine_success_count > 0 || $routine_log_count > 0 ) {
    126                             WP_CLI::success( "Successfully performed repair method for routine '$routine' with no errors.\n" );
    127                         } else {
    128                             WP_CLI::success( "Nothing seems broken. If it ain't broke, don't fix it.\n" );
    129                         }
    130 
     110                        $routine_repair_methods[$routine] = $repair_method;
    131111                    }
    132112
     
    138118
    139119            }
     120
     121        }
     122
     123        if ( count( $routine_repair_methods ) > 0 ) {
     124
     125            WP_CLI::confirm( "One or more of your inspection routines has a repair method that may or may not fix the problem(s) for you.\n" .
     126                             "Have you made a backup of your website's entire source code, uploaded files and database and want me to\n" .
     127                             "try and repair with the risk of me messing everything up?" );
     128
     129            foreach( $routine_repair_methods as $routine => $repair_method ) {
     130
     131                $total_log_count = AC_Inspector::$log_count;
     132                $total_error_count = AC_Inspector::$error_count;
     133                $total_success_count = AC_Inspector::$success_count;
     134
     135                call_user_func( $repair_method );
     136
     137                $routine_log_count = AC_Inspector::$log_count - $total_log_count;
     138                $routine_error_count = AC_Inspector::$error_count - $total_error_count;
     139                $routine_success_count = AC_Inspector::$success_count - $total_success_count;
     140
     141                if ( $routine_error_count > 0 ) {
     142                    WP_CLI::error( "Repair method for routine '$routine' yielded $routine_error_count error(s).\n" );
     143                } else if ( $routine_success_count > 0 || $routine_log_count > 0 ) {
     144                    WP_CLI::success( "Successfully performed repair method for routine '$routine' with no errors.\n" );
     145                } else {
     146                    WP_CLI::success( "Nothing seems broken. If it ain't broke, don't fix it.\n" );
     147                }
     148
     149            }
    140150
    141151        }
  • angry-creative-logger/trunk/plugin.php

    r1189487 r1214050  
    44Plugin URI: http://angrycreative.se
    55Description: Inspects and logs possible issues with your Wordpress installation.
    6 Version: 0.8
     6Version: 0.8.1
    77Author: Robin Björklund, Sammy Nordström, Angry Creative AB
    88*/
    99
    10 define( 'ACI_PLUGIN_VERSION', '0.8' );
     10define( 'ACI_PLUGIN_VERSION', '0.8.1' );
    1111
    1212define( 'ACI_PLUGIN_DIR', dirname( __FILE__ ) );
  • angry-creative-logger/trunk/readme.txt

    r1189487 r1214050  
    44Requires at least: 4.0
    55Tested up to: 4.2.2
    6 Stable tag: 0.8
     6Stable tag: 0.8.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3030* Added the abilitiy to define SITE_RELEASE_TIER (local/development/test/integration/stage/production) in wp-config.php
    3131* Added repair method to site visibility routine using SITE_RELEASE_TIER for making the site public or private
     32* Added the abiltity to define HIDDEN_SITES to prevent specific sites from being made public by the site visibility repair method
    3233
    3334= 0.7.x =
  • angry-creative-logger/trunk/routines/file_permissions.php

    r1189487 r1214050  
    177177                if ( "/*" == $folder && in_array( "/*", self::$_options['allowed_dirs'] ) ) {
    178178                    $allowed_dir = true;
    179                 } else if ( !empty( $folder_base ) && false !== strpos( $file_path, $folder_base ) ) {
    180                     $allowed_dir = true;
     179                } else if ( !empty( $folder_base ) ) {
     180                    foreach( self::$_options['allowed_dirs'] as $dir ) {
     181                        if ( preg_match("|".str_replace('/*', '/.*', $dir)."|", $file_path ) ) {
     182                            $allowed_dir = true;
     183                            break;
     184                        }
     185                    }
    181186                }
    182187            } else if ( in_array( $folder, self::$_options['allowed_dirs'] ) ) {
  • angry-creative-logger/trunk/routines/site_visibility.php

    r1189487 r1214050  
    2121    }
    2222
     23    public static function is_visible( $site_id = 1 ) {
     24
     25        if ( is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) {
     26
     27            if ( intval( $site_id ) == 0 || !get_blog_details( $site_id ) ) {
     28                $site_id = 1;
     29            }
     30
     31            $visible = get_blog_details( $site_id )->public;
     32
     33        } else {
     34
     35            $visible = get_option('blog_public');
     36
     37        }
     38
     39        return $visible ? true : false;
     40
     41    }
     42
     43    public static function should_be_visible( $site_id = 1 ) {
     44
     45        if ( !aci_release_tier_aware() ) {
     46            return null;
     47        }
     48
     49        $release_tier = aci_get_release_tier();
     50
     51        if ( $release_tier != 'production' ) {
     52            return false;
     53        }
     54
     55        if ( defined( 'HIDDEN_SITES' ) ) {
     56
     57            $hidden_sites = explode( ',', HIDDEN_SITES );
     58
     59            foreach ($hidden_sites as $hidden_site_id) {
     60
     61                $hidden_site_id = intval( trim( $hidden_site_id ) );
     62
     63                if ( $hidden_site_id > 0 && $hidden_site_id == $site_id ) {
     64                    return false;
     65                }
     66            }
     67        }
     68
     69        return true;
     70
     71    }
     72
    2373    public static function inspect() {
    2474
     
    2676
    2777            global $wpdb;
    28             $site_blog_ids = $wpdb->get_col("SELECT blog_id FROM ".$wpdb->prefix."blogs");
     78            $site_ids = $wpdb->get_col("SELECT blog_id FROM ".$wpdb->prefix."blogs");
    2979
    30             if (is_array($site_blog_ids)) {
    31                 foreach( $site_blog_ids AS $site_blog_id ) {
     80            if (is_array($site_ids)) {
     81                foreach( $site_ids AS $site_id ) {
    3282
    33                     if (intval($site_blog_id) > 0) {
     83                    if ( null === self::should_be_visible( $site_id ) ) {
     84                        if ( self::is_visible( $site_id ) ) {
     85                            AC_Inspector::log( 'Site '.$site_id.' is visible to search enginges, which may be correct as well as incorrect. Please define SITE_RELEASE_TIER in your wp-config.php to help me determine this.', __CLASS__ );
     86                        } else {
     87                            AC_Inspector::log( 'Site '.$site_id.' is not visible to search enginges, which may be correct as well as incorrect. Please define SITE_RELEASE_TIER in your wp-config.php to help me determine this.', __CLASS__ );
     88                        }
     89                    }
    3490
    35                         $visible = get_blog_details( $site_blog_id )->public;
    36 
    37                         if ( !$visible ) {
    38 
    39                             AC_Inspector::log( 'Site '.$site_blog_id.' is not visible to search engines.', __CLASS__, array( 'site_id' => $site_blog_id ) );
    40 
    41                         }
    42 
     91                    if ( !self::is_visible( $site_id ) && true === self::should_be_visible( $site_id ) ) {
     92                        AC_Inspector::log( 'Site '.$site_id.' should be visible to search engines, please check your site visibility settings.', __CLASS__, array( 'site_id' => $site_id ) );
     93                    } else if ( self::is_visible( $site_id ) && false === self::should_be_visible( $site_id ) ) {
     94                        AC_Inspector::log( 'Site '.$site_id.' should not be visible to search engines, please check your site visibility settings.', __CLASS__, array( 'site_id' => $site_id ) );
    4395                    }
    4496
     
    48100        } else {
    49101
    50             $visible = get_option('blog_public');
     102            if ( null === self::should_be_visible() ) {
     103                if ( self::is_visible() ) {
     104                    AC_Inspector::log( 'The site is visible to search enginges, which may be correct as well as incorrect. Please define SITE_RELEASE_TIER in your wp-config.php to help me determine this.', __CLASS__ );
     105                } else {
     106                    AC_Inspector::log( 'The site is not visible to search enginges, which may be correct as well as incorrect. Please define SITE_RELEASE_TIER in your wp-config.php to help me determine this.', __CLASS__ );
     107                }
     108            }
    51109
    52             if ( !$visible ) {
    53 
    54                 AC_Inspector::log( 'The site is not visible to search engines.', __CLASS__ );
    55 
     110            if ( !self::is_visible() && true === self::should_be_visible() ) {
     111                AC_Inspector::log( 'The site should be visible to search engines, please check your site visibility settings.', __CLASS__, array( 'site_id' => $site_id ) );
     112            } else if ( self::is_visible( $site_id ) && false === self::should_be_visible( $site_id ) ) {
     113                AC_Inspector::log( 'The site should not be visible to search engines, please check your site visibility settings.', __CLASS__, array( 'site_id' => $site_id ) );
    56114            }
    57115
     
    67125        }
    68126
    69         $release_tier = aci_get_release_tier();
    70 
    71127        if ( is_multisite() && is_plugin_active_for_network( ACI_PLUGIN_BASENAME ) ) {
    72128
    73129            global $wpdb;
    74             $site_blog_ids = $wpdb->get_col("SELECT blog_id FROM ".$wpdb->prefix."blogs");
     130            $site_ids = $wpdb->get_col("SELECT blog_id FROM ".$wpdb->prefix."blogs");
    75131
    76             if (is_array($site_blog_ids)) {
    77                 foreach( $site_blog_ids AS $site_blog_id ) {
     132            if (is_array($site_ids)) {
     133                foreach( $site_ids AS $site_id ) {
    78134
    79                     if (intval($site_blog_id) > 0) {
     135                    if (intval($site_id) > 0) {
    80136
    81                         $visible = get_blog_details( $site_blog_id )->public;
     137                        $visible = self::is_visible( $site_id );
    82138
    83                         if ( ( !$visible && $release_tier == 'production' ) || ( $visible && $release_tier != 'production' ) ) {
     139                        if ( ( !$visible && true === self::should_be_visible( $site_id ) ) || ( $visible && false === self::should_be_visible( $site_id ) ) ) {
    84140
    85141                            $visible = $visible ? 0 : 1;
    86142
    87                             switch_to_blog( $site_blog_id );
     143                            switch_to_blog( $site_id );
    88144                            update_option( 'blog_public', $visible );
    89145                            restore_current_blog();
    90146
    91                             AC_Inspector::log( 'The site visibility setting for ' . get_blog_details( $site_blog_id, true )->blogname .' is now ' . ( ( $visible ) ? ' public' : ' private' )  . '.', __CLASS__, array( 'success' => true ) );
     147                            AC_Inspector::log( 'The site visibility setting for ' . get_blog_details( $site_id, true )->blogname .' is now ' . ( ( $visible ) ? ' public' : ' private' )  . '.', __CLASS__, array( 'success' => true ) );
    92148
    93149                        } else {
    94150
    95                             AC_Inspector::log( 'The site visibility setting for ' . get_blog_details( $site_blog_id, true )->blogname .' seems correct, no action taken.', __CLASS__, array( 'log_level' => 'notice' ) );
     151                            AC_Inspector::log( 'The site visibility setting for ' . get_blog_details( $site_id, true )->blogname .' seems correct, no action taken.', __CLASS__, array( 'log_level' => 'notice' ) );
    96152
    97153                        }
     
    103159        } else {
    104160
    105             $visible = get_option('blog_public');
     161            $visible = self::is_visible();
    106162
    107             if ( ( !$visible && $release_tier == 'production' ) || ( $visible && $release_tier != 'production' ) ) {
     163            if ( ( !$visible && true === self::should_be_visible() ) || ( $visible && false === self::should_be_visible() ) ) {
    108164
    109165                $visible = $visible ? 0 : 1;
Note: See TracChangeset for help on using the changeset viewer.