Ticket #268: maia-postgres-1.0.0.patch

File maia-postgres-1.0.0.patch, 2.3 kB (added by erik@…, 3 years ago)

patch send...digests.pl to check for Pg DSN, and DtRT in that case.

  • scripts/send-quarantine-digests.pl

    diff -ru maia-1.0.0-prepatch/scripts/send-quarantine-digests.pl maia-1.0.0/scripts/send-quarantine-digests.pl
    old new  
    121121# anything below this point.                                           # 
    122122######################################################################## 
    123123 
     124# The organization of this file makes this a bit obtuse 
     125my $isPg = 0; 
     126 
    124127    # Retrieve the string value associated with a key in the database.cfg file. 
    125128    sub get_string_key($$) 
    126129    { 
     
    182185      my $unique_string = phrase_generate(); 
    183186 
    184187      my $insert = "INSERT INTO maia_tokens (token_system, token, data, expires) " . 
    185                    "VALUES ('digest',?,?, DATE_ADD(NOW(), INTERVAL ? DAY))"; 
     188                   "VALUES ('digest',?,?, " . 
     189                       ($isPg ? "NOW() + INTERVAL ? DAY" 
     190                              : "DATE_ADD(NOW(), INTERVAL ? DAY)") . 
     191                           ")"; 
    186192      my $sth = $dbh->prepare($insert); 
    187193      $sth->execute($unique_string, $maia_user_id,$days) or die (sprintf("Maia: [send-quarantine-reminders] Couldn't execute query: %s", $dbh->errstr));; 
    188194 
     
    201207 
    202208    # Connect to the database 
    203209    my $dsn = get_string_key($db_cfg, "dsn"); 
     210    # The organization of this file makes this a bit obtuse 
     211    $isPg = $dsn =~ /^dbi:Pg/; 
    204212    my $username = get_string_key($db_cfg, "username"); 
    205213    my $password = get_string_key($db_cfg, "password"); 
    206214    my $dbh = DBI->connect($dsn, $username, $password) 
     
    240248              "WHERE maia_users.primary_email_id = users.id " . 
    241249              "AND maia_users.quarantine_digest_interval > 0 " . 
    242250              "AND (maia_users.quarantine_digest_interval <= " . 
    243                    "((UNIX_TIMESTAMP() - UNIX_TIMESTAMP(maia_users.last_digest_sent)) / 60) " . 
     251              ($isPg ? "(( ROUND(DATE_PART('epoch', NOW())) - ROUND(DATE_PART('epoch', maia_users.last_digest_sent))) / 60)" 
     252                     : "((UNIX_TIMESTAMP() - UNIX_TIMESTAMP(maia_users.last_digest_sent)) / 60) ") . 
    244253                   "OR maia_users.last_digest_sent IS NULL) " . 
    245254              "ORDER BY maia_users.id ASC"; 
    246255    my $sth3 = $dbh->prepare($select)