Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author SpeakOut!

    (@123host)

    Thomas, this may be a bug. Did you have it to confirm signatures and then change it?

    I am travelling until early next week and have contracted Covid while in Europe, so things are a bit delayed at the moment.

    Thread Starter Thomas Huber

    (@hubsi)

    Yes, confirmed signatures are counted.

    Plugin Author SpeakOut!

    (@123host)

    Ok. As I said, there nothing I can do right now. A temporary fix, since you seem to know SQL would be to do a backup and then delete line 838

    I’ll check this out next week.

    Plugin Author SpeakOut!

    (@123host)

    Hi Thomas,

    Yes this is a bug that is only triggered if a petition was set to “confirm” at some point and then changed to “not confirm”.

    In a regular petition. a signature has a NULL value for the confirmed flag. However, if a petition is set to confirm, then the signature’s confirmed flag is 0 until it is confirmed, then it changes to 1. So far so good.

    If the petition is then switched to not confirm, the flag for confirmed signatures is still 1 and unconfirmed signatures is still 0. Now we get to the SQL statement and line 838; AND ( $db_signatures.is_confirmed != '0' ). I think you can see what is happening. There is a conflict between a petition not wanting confirmation, but some signature already having the flag set to 0.

    The solution might be to clear all the confirmed flags (with a warning) if confirmation is disabled . But I can imagine that will cause upset if someone disables and changes their mind, all confirmations will be lost.

    I am going to think about an elegant way around it.

    Thread Starter Thomas Huber

    (@hubsi)

    Hi.
    Topic resolved? Sorry, I can’t see a solution yet.
    I hope you are doing better and your recovering of covid symptoms will be fast.

    How about this hint? => Conditional statements, related to the setting / option if requires_confirmation is turned off.
    But but have too less deep knowledge about this plugin, if that would work and bring no other side-effects.
    Greetings, Thomas

    Plugin Author SpeakOut!

    (@123host)

    Thomas, how long ago (roughly) did you first install SpeakOut!

    It looks this is a legacy bug that is fixed if installed recently, but has never taken old installs into account.

    As I suspected, I think the only solution might be to clear all the confirmed flags (with a warning) if confirmation is disabled .

    • This reply was modified 2 years, 5 months ago by SpeakOut!.
    Plugin Author SpeakOut!

    (@123host)

    OK. I have a fix for this. If you need it urgently, edit /wp-content/plugins/speakout/includes/class.petition.php

    At line 828 find a function retrieve() with the following code ( you may have removed line 838 as a workaround )

    public function retrieve( $id )
    {
        if( !is_numeric( $id )){ return; }
        global $wpdb, $db_petitions, $db_signatures;
    
        $sql = "
            SELECT $db_petitions.*, COUNT( $db_signatures.id ) AS 'signatures'
            FROM $db_petitions
            LEFT JOIN $db_signatures
                ON $db_petitions.id = $db_signatures.petitions_id
                AND ( $db_signatures.is_confirmed != '0' )
            WHERE $db_petitions.id = $id
            GROUP BY $db_petitions.id
        ";
        $petition = $wpdb->get_row( $sql );
        $rowcount = $wpdb->get_var( $sql );    
           
        if (  $rowcount > 0 ) {
            $this->_populate_from_query( $petition );
            return true;
        }
        else {
            return false;
        }
    }
    
    // get all Active Campaign lists for Add New View dropdown

    We are adding a conditional statement that is called only if confirmations are disabled, in this case, it counts all signatures.

    public function retrieve( $id )
    {
        if( !is_numeric( $id )){ return; }
        global $wpdb, $db_petitions, $db_signatures;
    
        $sql = "
            SELECT $db_petitions.*, COUNT( $db_signatures.id ) AS 'signatures'
            FROM $db_petitions
            LEFT JOIN $db_signatures
                ON $db_petitions.id = $db_signatures.petitions_id
                AND ( $db_signatures.is_confirmed != '0' )
            WHERE $db_petitions.id = $id
            GROUP BY $db_petitions.id
        ";
        $petition = $wpdb->get_row( $sql );
        $rowcount = $wpdb->get_var( $sql );    
        
    
        // this is a workaround to fix signature count for early installs that have confirmed enabled, then later disabled confirmations
        if($petition->requires_confirmation == 0){
          $sql = "
                SELECT COUNT( $db_signatures.id ) AS 'signatures'
                FROM $db_petitions
                LEFT JOIN $db_signatures
                    ON $db_petitions.id = $db_signatures.petitions_id
                WHERE $db_petitions.id = $id
                GROUP BY $db_petitions.id
                ";  
            
            $rowcount = $wpdb->get_var( $sql );
            $petition->signatures = $rowcount;
        }
        
        if (  $rowcount > 0 ) {
            $this->_populate_from_query( $petition );
            return true;
        }
        else {
            return false;
        }
    }
    
    // get all Active Campaign lists for Add New View dropdown

    Thinking the fix for this (which apparently was added to the plugin in version 2.15.2) may be catching more cases than it should. I have a site with signature confirmation enabled that suddenly is counting unconfirmed signatures. After looking into it, I wonder if line 837 in class.petition.php should be using === instead of just ==. That change did get my use case to work as expected, but it may also miss the one it was supposed to catch. Let me know if you need more information about my settings.

    Plugin Author SpeakOut!

    (@123host)

    Thanks @jboyette36 – I am about to release version 3.0.0 in which I have changed the logic of that function so it uses != instead of == (or ===).

    The new version should be out within the next day or two. Final touches and testing being done right now.

    @123host The new version is working as expected on the site. Thanks for responding and for your work on this plugin!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Signature count incorrect’ is closed to new replies.