Support » Plugin: WP Statistics » Duplicate entry ‘…’ for key ‘unique_date’

  • Hi,

    In my WP logs (multi-wordpress), I have the following recurrent lines:

    `
    [host wiki.fr.dracca.com] AH10039: FastCGI: server “/homez.2081/…/wordpress/wp-cron.php” stderr: PHP message: Erreur de la base de donn\xc3\xa9es WordPress Duplicate entry ‘2018-10-29’ for key ‘unique_date’ pour la requ\xc3\xaate INSERT INTO wor8628_4_statistics_visit (last_visit, last_counter, visit) VALUES ( ”, ‘2018-10-29’, 0) faite par do_action_ref_array, WP_Hook->do_action, WP_Hook->apply_filters, WP_Statistics_Schedule::add_visit_event, referer: https://wiki.fr.dracca.com/wp-cron.php?doing_wp_cron=1540742958.5284719467163085937500 on Dracca (x1)
    `

    Looking at the Git repository, I found that code line:

    $sqlstring = $wpdb->prepare( ‘INSERT INTO ‘ . $wpdb->prefix . ‘statistics_visit (last_visit, last_counter, visit) VALUES ( %s, %s, %d)’, $WP_Statistics->Current_Date(null, ‘+1’), $WP_Statistics->Current_date(‘Y-m-d’, ‘+1’), 0 );

    https://github.com/wp-plugins/wp-statistics/blob/7c56e2448fdaee50c6e07db2746a3c767527e3f8/schedule.php#L119

    More precisely, bug seems to come from $WP_Statistics->Current_Date(null, '+1') because the signature of the method Current_Date is:

    public function Current_Date($format = ‘Y-m-d H:i:s’, $strtotime = null, $relative = null) {

    https://github.com/wp-plugins/wp-statistics/blob/7c56e2448fdaee50c6e07db2746a3c767527e3f8/includes/classes/statistics.class.php#L361

    And a php -r "echo date(null);" returns an empty string. Hence the duplication.

    I think the code should be fixed to $WP_Statistics->Current_Date("Y-m-d", '+1') or so.

    Can you please check?

    WordPress 4.9.8
    WP Stats Version 12.4.3
    PHP 7.1 MySQL 5.7 but I doubt it changes anything

    PS: I hope formatting will be OK as I see no “preview” area

  • The topic ‘Duplicate entry ‘…’ for key ‘unique_date’’ is closed to new replies.