]> git.mxchange.org Git - mailer.git/commitdiff
Continued with ext-wernis:
authorRoland Haeder <roland@mxchange.org>
Sun, 6 Apr 2014 21:25:19 +0000 (23:25 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 6 Apr 2014 21:25:19 +0000 (23:25 +0200)
- Added wernis_refid column which will hold the referral id from WDS66. This
  can be used to link a registered (through ext-wernis, not ext-register)
  account with this.
- Added registration provider to mappedData array
- Some rewrites
- Added convertEmptyToNull() (generic)

Signed-off-by: Roland Häder <roland@mxchange.org>
inc/extensions/ext-wernis.php
inc/functions.php
inc/libs/wernis_functions.php

index 8e4f120424bac7c98ca58ff531d1409d252543c6..0fbf56ee834765eefef0830452d8e600696a1756 100644 (file)
@@ -71,7 +71,8 @@ INDEX (`userid`)",
                addConfigAddSql('wernis_api_url', "VARCHAR(255) NOT NULL DEFAULT 'http://www.wds66.com/api/'");
 
                // User data
-               addExtensionAddTableColumnSql('user_data', 'wernis_userid', "VARCHAR(6) NOT NULL DEFAULT ''");
+               addExtensionAddTableColumnSql('user_data', 'wernis_userid', "VARCHAR(6) NULL DEFAULT NULL");
+               addExtensionAddTableColumnSql('user_data', 'wernis_refid', "VARCHAR(6) NULL DEFAULT NULL");
 
                // Admin menu
                addAdminMenuSql('wernis', NULL, 'Wernis-Management', 'Konfiguration zur WDS66-API einstellen, Auszahlungen auflisten usw..', 15);
index 3ee3d3b1ae1cb86fc6b745d4c96b40b5460094dd..4f37ac1a92079a5d9ae6a39ed39301fc4d8391a9 100644 (file)
@@ -2192,6 +2192,18 @@ function convertZeroToNull ($number) {
        return $number;
 }
 
+// Converts an empty string to NULL, else leaves it untouched
+function convertEmptyToNull ($str) {
+       // Is the string empty?
+       if (strlen($str) == 0) {
+               // Is really empty
+               $str = NULL;
+       } // END - if
+
+       // Return it
+       return $str;
+}
+
 // Converts a NULL|empty string|< 1 to zero
 function convertNullToZero ($number) {
        // Is it a valid username?
index 50f39751be16d9225486c209725ed1029fc77f10..67d20182b2d45c1b70c71ca3d875e5f4de9af805 100644 (file)
@@ -551,12 +551,11 @@ function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status
                         * update it and ignore result from function because the update
                         * will always run.
                         */
-                       updateWernisRegistrationStatusByKey('api_redirect_challenge', $challenge, 'ACCEPTED');
+                       updateWernisRegistrationDataByKey('api_auth_status', 'api_redirect_challenge', $challenge, 'ACCEPTED');
                } // END - if
 
                // Now call "get.php"
-               // @TODO Hard-coded value (anrede, etc.)
-               $response = executeWernisApiGet($rows[0], 'data', 'anrede|vorname|name|strasse|plz|ort|birth_day|birth_month|birth_year|email');
+               $response = executeWernisApiGet($rows[0], 'data', 'anrede|vorname|name|strasse|plz|ort|birth_day|birth_month|birth_year|email|werber');
 
                // Was the status okay?
                if (isHttpResponseStatusOkay($response)) {
@@ -571,15 +570,53 @@ function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status
 
                        /*
                         * Do some checks on the decoded string, it should be a
-                        * serialized array with 10 entries (see above
+                        * serialized array with 11 entries (see above
                         * executeWernisApiGet() call).
                         */
-                       assert(substr($decodedData, 0, 6) == 'a:10:{');
+                       assert(substr($decodedData, 0, 6) == 'a:11:{');
                        assert(substr($decodedData, -1, 1) == '}');
 
                        // The array seems to be fine, unserialize it
                        $userData = unserialize($decodedData);
-                       die(__FUNCTION__.'<pre>'.print_r($userData, TRUE).'</pre>');
+
+                       // All mappings WDS66->mailer
+                       $mappings = array(
+                               'anrede'      => 'gender',
+                               'vorname'     => 'surname',
+                               'name'        => 'family',
+                               'strasse'     => 'street_nr',
+                               'plz'         => 'zip',
+                               'ort'         => 'city',
+                               'email'       => 'email',
+                               'birth_day'   => 'birth_day',
+                               'birth_month' => 'birth_month',
+                               'birth_year'  => 'birth_year',
+                               'werber'      => 'wernis_refid'
+                       );
+
+                       // Array for mapped data
+                       $mappedData = array();
+
+                       // Map all WDS66 entries into mailer entries
+                       foreach ($mappings as $from => $to) {
+                               // All must exist
+                               if (!isset($userData[$from])) {
+                                       // Element $from does not exist
+                                       reportBug(__FUNCTION__, __LINE__, 'Cannot map from=' . $from . ' -> to=' . $to . ': element does not exist.');
+                               } // END - if
+
+                               // "Map" all
+                               $mappedData[$to] = convertEmptyToNull($userData[$from]);
+                       } // END - foreach
+
+                       // Both arrays must have same size
+                       assert(count($userData) == count($mappedData));
+
+                       // Now add userid and registration provider from WDS66
+                       $mappedData['wernis_userid']         = bigintval($rows[0]['wernis_userid']);
+                       $mappedData['registration_provider'] = 'wernis';
+
+                       die(__FUNCTION__ . '<pre>'.print_r($mappedData, TRUE).'</pre>');
                } else {
                        // Something bad happened
                        displayMessage($response['message']);
@@ -591,21 +628,22 @@ function doWernisFinishUserRegistration ($challenge, $challengeResponse, $status
 }
 
 // Updates auth status by given key/value pair
-function updateWernisRegistrationStatusByKey ($key, $value, $newStatus) {
+function updateWernisRegistrationDataByKey ($updatedColumn, $key, $oldValue, $newValue) {
        // Run the update
        sqlQueryEscaped("UPDATE
        `{?_MYSQL_PREFIX?}_wernis_regs`
 SET
-       `api_auth_status`='%s'
+       `%s`='%s'
 WHERE
        `%s`='%s' AND
-       `api_auth_status` != '%s'
+       `%s` != '%s'
 LIMIT 1",
                array(
-                       $newStatus,
+                       $updatedColumn,
+                       $newValue,
                        $key,
-                       $value,
-                       $newStatus
+                       $updatedColumn,
+                       $oldValue
                ), __FUNCTION__, __LINE__
        );
 
@@ -692,9 +730,6 @@ function doWernisAuthPending ($args) {
                                $challenge
                        ), __FUNCTION__, __LINE__
                );
-
-               // Should be inserted
-               assert(sqlAffectedRows() == 1);
        } else {
                // Update challenge
                sqlQueryEscaped("UPDATE
@@ -712,11 +747,11 @@ LIMIT 1",
                                bigintval($args['wernis_userid'])
                        ), __FUNCTION__, __LINE__
                );
-
-               // Should always be updated
-               assert(sqlAffectedRows() == 1);
        }
 
+       // Should always update/insert
+       assert(sqlAffectedRows() == 1);
+
        // Redirect to WDS66 module=auth ...
        redirectToUrl(getWernisBaseUrl() . '/modules.php?module=auth&amp;auth_key=' . $args['auth_key'] . '&amp;params=' . urlencode(base64_encode('&module=' . getModule() . '&what=' . getWhat())) . '&amp;challenge=' . $challenge);
 }
@@ -729,7 +764,6 @@ function doWernisAuthAccepted ($args) {
        // auth_key and wernis_userid must be set
        assert(isset($args['auth_key']));
        assert(isset($args['wernis_userid']));
-
        die(__FUNCTION__ . '<pre>'.print_r($args, TRUE).'</pre>');
 }