Author: benj
Date: Tue May 10 11:41:11 2016
New Revision: 1668

URL: http://svn.gna.org/viewcvs/gdtc?rev=1668&view=rev
Log:
Add new function to ensure renewal is consistent upon deletion (#19477)

Modified:
    trunk/gdtc/include/membership.php

Modified: trunk/gdtc/include/membership.php
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/include/membership.php?rev=1668&r1=1667&r2=1668&view=diff
==============================================================================
--- trunk/gdtc/include/membership.php   (original)
+++ trunk/gdtc/include/membership.php   Tue May 10 11:41:11 2016
@@ -234,4 +234,35 @@
 
 
 
+function membership_fix_renewal ( $membership_id )
+{
+    $subscriptions = simple_query ( sprintf
+                                   ( "SELECT * " .
+                                     "  FROM subscription " .
+                                     " WHERE subscription.membership_id = 
'%s';",
+                                     $membership_id ) );
+
+    /* Do not change the date in case of no matches, like the last
+     * subscription was removed. */
+    if ( $subscriptions )
+    {
+       $max = '1970-00-00';
+       foreach ( $subscriptions as $subscription )
+       {
+           if ( strcmp ( $max, $subscription [ 'end_date' ] ) < 0 )
+           {
+               $max = $subscription [ 'end_date' ];
+               printf ( "New max is %s, $max<br/>\n", $max );
+           }
+       }
+       if ( strcmp ( $max, '1970-00-00' ) )
+       {
+           $commit = Array ( 'renewal_date' => $max );
+           commit ( 'membership', 'membership_id', $membership_id, $commit,
+                    'Ajustement automatique de la date de renouvellement');
+       }
+    }
+}
+
+
 ?>


_______________________________________________
Gdtc-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gdtc-commits

Reply via email to