Plugin Directory

Changeset 2377524


Ignore:
Timestamp:
09/08/2020 11:21:41 PM (5 years ago)
Author:
devoutpro
Message:

urgent bug fix, db upgrade problem broke callers list v1.15

Location:
nomore404-404-redirection-and-firewall
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • nomore404-404-redirection-and-firewall/tags/1.15/includes/nomore404-activation.php

    r2376893 r2377524  
    2929    $obj_settings = new NoMore404_Settings(); // this creates default options via constructor or creates missing options
    3030}
     31
     32function nomore404_update_db_check() {
     33    $obj_settings = new NoMore404_Settings();
     34    //NoMore404_Model_Static_Class::good_error_log('settings:', $obj_settings);
     35    if(NOMORE404DBVERSION != $obj_settings->options['dbversion']) nomore404_activation();
     36}
     37
     38add_action( 'plugins_loaded', 'nomore404_update_db_check' );
    3139
    3240function nomore404_create_tables($prefix) {
     
    7987            //NoMore404_Model_Static_Class::good_error_log('Table 1 update 2 result:', $result);
    8088        }
    81         if($obj_settings->options['dbversion'] < '1.13'){ // alter table here if before v 1.13
     89        if(False == NoMore404_Model_Static_Class::check_table_column_exists($table_name1, 'uploaded')){
    8290            $update_query1 = "ALTER TABLE $table_name1
    8391                                ADD uploaded TINYINT(1) NOT NULL DEFAULT '0'";
     
    128136            $result = $wpdb->query($update_query2);
    129137        }
    130         if($obj_settings->options['dbversion'] < '1.13'){ // alter table here if before v 1.13
     138        if(False == NoMore404_Model_Static_Class::check_table_column_exists($table_name2, 'uploaded')){
    131139            $update_query2 = "ALTER TABLE $table_name2
    132140                                ADD uploaded TINYINT(1) NOT NULL DEFAULT '0'";
     
    164172            $result = $wpdb->query($update_query3);
    165173        }
    166         if($obj_settings->options['dbversion'] < '1.13'){ // alter table here if before v 1.13
     174        if(False == NoMore404_Model_Static_Class::check_table_column_exists($table_name3, 'uploaded')){
    167175            $update_query3 = "ALTER TABLE $table_name3
    168176                                ADD uploaded TINYINT(1) NOT NULL DEFAULT '0'";
  • nomore404-404-redirection-and-firewall/tags/1.15/includes/nomore404-model.php

    r2376893 r2377524  
    3232    }
    3333   
     34    /**
     35     * Returns true if a database table column exists. Otherwise returns false.
     36     *
     37     * @param string $table_name Name of table we will check for column existence.
     38     * @param string $column_name Name of column we are checking for.
     39     *
     40     * @return boolean True if column exists. Else returns false.
     41     */
     42    public static function check_table_column_exists($table_name, $column_name) {
     43
     44        global $wpdb;
     45
     46        $column = $wpdb->get_results($wpdb->prepare(
     47                        "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ", DB_NAME, $table_name, $column_name
     48                ));
     49
     50        if (!empty($column)) {
     51            return true;
     52        }
     53
     54        return false;
     55    }
     56
    3457    public static function delete_col(&$array, $key)
    3558    {
     
    155178             $output = $wpdb->insert_id;
    156179         } catch (Exception $ex) {
    157             //self::good_error_log('Caught URICaller insert error:',$ex->getMessage());
    158180            return False; // if insert did not work - return false
    159181         }
     
    168190                            array('uri_id' => $uri_id, 'caller_id' => $caller_id));
    169191         } catch (Exception $ex) {
    170             //self::good_error_log('Caught URICaller update error:',$ex->getMessage());
    171192            return False; // if insert did not work - return false
    172193         }
     
    199220             $output = $wpdb->insert_id;
    200221         } catch (Exception $ex) {
    201             //self::good_error_log('Caught Caller insert error:',$ex->getMessage());
    202222            return False; // if insert did not work - return false
    203223         }
     
    212232            $output = $wpdb->update(self::$caller_table_name, $caller_data, array('caller_id' => $caller_id));
    213233         } catch (Exception $ex) {
    214             //self::good_error_log('Caught Caller update error:',$ex->getMessage());
    215234            return False; // if update did not work - return false
    216235         }
     
    236255            );
    237256         } catch (Exception $ex) {
    238             //self::good_error_log('Caught Caller delete error:',$ex->getMessage());
    239257            return False; // if update did not work - return false
    240258         }
     
    245263    public static  function countCallers($search = '', $filteruriid = ''){
    246264        global $wpdb;
    247        
    248         //self::good_error_log('Counting callers by URIid:', $filteruriid);
    249265       
    250266        if('' == $filteruriid ){ // if not filtered  then normal sort and search applies       
     
    279295           
    280296        }
    281         //self::good_error_log('Running query:', $cleanedsql);
    282297        $num = (int) $wpdb->get_var($cleanedsql);
    283         //self::good_error_log('Number of records:', $num);
    284298        return $num;
    285299    }
     
    311325            // prepare list of fields
    312326            $listOfFieldsToGet = 'c.caller_id, c.caller_ip, c.comment, c.hostname, c.date_created, c.date_last_used,
    313                                     c.counter, c.suspicious, c.malicious, c.whitelist, c.uploaded';
     327                                    c.counter, c.suspicious, c.malicious, c.whitelist, c.uploaded, c.caller_ip_str';
    314328                   
    315329            // form query
     
    334348        }
    335349        $output = $wpdb->get_results($cleanedsql, ARRAY_A);
    336         //NoMore404_Model_Static_Class::good_error_log('SQL  in model class:', $cleanedsql);
    337         //NoMore404_Model_Static_Class::good_error_log('Callers in model class:', $output);
    338350        return $output;
    339351    }
     
    357369            );
    358370         } catch (Exception $ex) {
    359             //self::good_error_log('Caught URI delete error:',$ex->getMessage());
    360371            return False; // if update did not work - return false
    361372         }
     
    396407            }             
    397408        }
    398         //self::var_error_log('Number of URIs:', $num);
    399409        $num = (int) $wpdb->get_var($cleanedsql);
    400410        return $num;
     
    476486             $output = $wpdb->insert_id;
    477487         } catch (Exception $ex) {
    478             //self::good_error_log('Caught insert error:',$ex->getMessage());
    479488            return False; // if insert did not work - return false
    480489         }
     
    489498            $output = $wpdb->update(self::$uri_table_name, $uri_data, array('uri_id' => $uri_id));
    490499         } catch (Exception $ex) {
    491             //self::good_error_log('Caught update error:',$ex->getMessage());
    492500            return $output; // if insert did not work - return false
    493501         }
  • nomore404-404-redirection-and-firewall/tags/1.15/nomore404.php

    r2376893 r2377524  
    3232defined('ABSPATH') or exit;
    3333
    34 define("NOMORE404VERSION", "1.14");
    35 define("NOMORE404DBVERSION", "1.14");
     34define("NOMORE404VERSION", "1.15");
     35define("NOMORE404DBVERSION", "1.15");
    3636
    3737// plugin activation and uninstallation
  • nomore404-404-redirection-and-firewall/tags/1.15/readme.txt

    r2376893 r2377524  
    66Tested up to: 5.5
    77Requires PHP: 5.3
    8 Stable tag: 1.14   
     8Stable tag: 1.15   
    99License: GPLv2
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3030
    3131== Changelog ==
     321.15 Bug fix of plugin update process and new bug in Callers list, callers list
     33     was empty when filtered by URI
    32341.14 Manual upload of data to the backend system for analysis is done
    33351.13 Fixed activation and db upgrade errors.
  • nomore404-404-redirection-and-firewall/trunk/includes/nomore404-activation.php

    r2376893 r2377524  
    2929    $obj_settings = new NoMore404_Settings(); // this creates default options via constructor or creates missing options
    3030}
     31
     32function nomore404_update_db_check() {
     33    $obj_settings = new NoMore404_Settings();
     34    //NoMore404_Model_Static_Class::good_error_log('settings:', $obj_settings);
     35    if(NOMORE404DBVERSION != $obj_settings->options['dbversion']) nomore404_activation();
     36}
     37
     38add_action( 'plugins_loaded', 'nomore404_update_db_check' );
    3139
    3240function nomore404_create_tables($prefix) {
     
    7987            //NoMore404_Model_Static_Class::good_error_log('Table 1 update 2 result:', $result);
    8088        }
    81         if($obj_settings->options['dbversion'] < '1.13'){ // alter table here if before v 1.13
     89        if(False == NoMore404_Model_Static_Class::check_table_column_exists($table_name1, 'uploaded')){
    8290            $update_query1 = "ALTER TABLE $table_name1
    8391                                ADD uploaded TINYINT(1) NOT NULL DEFAULT '0'";
     
    128136            $result = $wpdb->query($update_query2);
    129137        }
    130         if($obj_settings->options['dbversion'] < '1.13'){ // alter table here if before v 1.13
     138        if(False == NoMore404_Model_Static_Class::check_table_column_exists($table_name2, 'uploaded')){
    131139            $update_query2 = "ALTER TABLE $table_name2
    132140                                ADD uploaded TINYINT(1) NOT NULL DEFAULT '0'";
     
    164172            $result = $wpdb->query($update_query3);
    165173        }
    166         if($obj_settings->options['dbversion'] < '1.13'){ // alter table here if before v 1.13
     174        if(False == NoMore404_Model_Static_Class::check_table_column_exists($table_name3, 'uploaded')){
    167175            $update_query3 = "ALTER TABLE $table_name3
    168176                                ADD uploaded TINYINT(1) NOT NULL DEFAULT '0'";
  • nomore404-404-redirection-and-firewall/trunk/includes/nomore404-model.php

    r2376893 r2377524  
    3232    }
    3333   
     34    /**
     35     * Returns true if a database table column exists. Otherwise returns false.
     36     *
     37     * @param string $table_name Name of table we will check for column existence.
     38     * @param string $column_name Name of column we are checking for.
     39     *
     40     * @return boolean True if column exists. Else returns false.
     41     */
     42    public static function check_table_column_exists($table_name, $column_name) {
     43
     44        global $wpdb;
     45
     46        $column = $wpdb->get_results($wpdb->prepare(
     47                        "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ", DB_NAME, $table_name, $column_name
     48                ));
     49
     50        if (!empty($column)) {
     51            return true;
     52        }
     53
     54        return false;
     55    }
     56
    3457    public static function delete_col(&$array, $key)
    3558    {
     
    155178             $output = $wpdb->insert_id;
    156179         } catch (Exception $ex) {
    157             //self::good_error_log('Caught URICaller insert error:',$ex->getMessage());
    158180            return False; // if insert did not work - return false
    159181         }
     
    168190                            array('uri_id' => $uri_id, 'caller_id' => $caller_id));
    169191         } catch (Exception $ex) {
    170             //self::good_error_log('Caught URICaller update error:',$ex->getMessage());
    171192            return False; // if insert did not work - return false
    172193         }
     
    199220             $output = $wpdb->insert_id;
    200221         } catch (Exception $ex) {
    201             //self::good_error_log('Caught Caller insert error:',$ex->getMessage());
    202222            return False; // if insert did not work - return false
    203223         }
     
    212232            $output = $wpdb->update(self::$caller_table_name, $caller_data, array('caller_id' => $caller_id));
    213233         } catch (Exception $ex) {
    214             //self::good_error_log('Caught Caller update error:',$ex->getMessage());
    215234            return False; // if update did not work - return false
    216235         }
     
    236255            );
    237256         } catch (Exception $ex) {
    238             //self::good_error_log('Caught Caller delete error:',$ex->getMessage());
    239257            return False; // if update did not work - return false
    240258         }
     
    245263    public static  function countCallers($search = '', $filteruriid = ''){
    246264        global $wpdb;
    247        
    248         //self::good_error_log('Counting callers by URIid:', $filteruriid);
    249265       
    250266        if('' == $filteruriid ){ // if not filtered  then normal sort and search applies       
     
    279295           
    280296        }
    281         //self::good_error_log('Running query:', $cleanedsql);
    282297        $num = (int) $wpdb->get_var($cleanedsql);
    283         //self::good_error_log('Number of records:', $num);
    284298        return $num;
    285299    }
     
    311325            // prepare list of fields
    312326            $listOfFieldsToGet = 'c.caller_id, c.caller_ip, c.comment, c.hostname, c.date_created, c.date_last_used,
    313                                     c.counter, c.suspicious, c.malicious, c.whitelist, c.uploaded';
     327                                    c.counter, c.suspicious, c.malicious, c.whitelist, c.uploaded, c.caller_ip_str';
    314328                   
    315329            // form query
     
    334348        }
    335349        $output = $wpdb->get_results($cleanedsql, ARRAY_A);
    336         //NoMore404_Model_Static_Class::good_error_log('SQL  in model class:', $cleanedsql);
    337         //NoMore404_Model_Static_Class::good_error_log('Callers in model class:', $output);
    338350        return $output;
    339351    }
     
    357369            );
    358370         } catch (Exception $ex) {
    359             //self::good_error_log('Caught URI delete error:',$ex->getMessage());
    360371            return False; // if update did not work - return false
    361372         }
     
    396407            }             
    397408        }
    398         //self::var_error_log('Number of URIs:', $num);
    399409        $num = (int) $wpdb->get_var($cleanedsql);
    400410        return $num;
     
    476486             $output = $wpdb->insert_id;
    477487         } catch (Exception $ex) {
    478             //self::good_error_log('Caught insert error:',$ex->getMessage());
    479488            return False; // if insert did not work - return false
    480489         }
     
    489498            $output = $wpdb->update(self::$uri_table_name, $uri_data, array('uri_id' => $uri_id));
    490499         } catch (Exception $ex) {
    491             //self::good_error_log('Caught update error:',$ex->getMessage());
    492500            return $output; // if insert did not work - return false
    493501         }
  • nomore404-404-redirection-and-firewall/trunk/nomore404.php

    r2376893 r2377524  
    3232defined('ABSPATH') or exit;
    3333
    34 define("NOMORE404VERSION", "1.14");
    35 define("NOMORE404DBVERSION", "1.14");
     34define("NOMORE404VERSION", "1.15");
     35define("NOMORE404DBVERSION", "1.15");
    3636
    3737// plugin activation and uninstallation
  • nomore404-404-redirection-and-firewall/trunk/readme.txt

    r2376938 r2377524  
    66Tested up to: 5.5
    77Requires PHP: 5.3
    8 Stable tag: 1.13   
     8Stable tag: 1.15   
    99License: GPLv2
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3030
    3131== Changelog ==
     321.15 Bug fix of plugin update process and new bug in Callers list, callers list
     33     was empty when filtered by URI
    32341.14 Manual upload of data to the backend system for analysis is done
    33351.13 Fixed activation and db upgrade errors.
Note: See TracChangeset for help on using the changeset viewer.