From: Chuck Scott WARNING: This process may take a very long time!
+ {$genError}
'.$err['message'];
+ $failure = true;
+
+ }
+}
+
+// Determine if the members schema exists
+if (!$failure) {
+ $sql = "
+ SELECT EXISTS
+ (
+ SELECT 1
+ FROM information_schema.schemata AS exists
+ WHERE schema_name = 'members'
+ ) AS isMembers
+ ;";
+ $res = pg_query($db, $sql);
+ if (pg_fetch_result($res, 0, 'isMembers') == 'f') {
+ $templateData['genError'] = 'The "members" schema was not found! Is this the right database?';
+ $failure = true;
+ }
+}
+
+/*
+ * Load data from source database
+ */
+trigger_error('Memory before: '.memory_get_usage(), E_USER_NOTICE);
+// Attempt to get member base data
+if (!$failure) {
+ $sql = "
+ SELECT click, detail, edate, member_id
+ FROM members.exposure
+ ;";
+ $res = pg_query($db, $sql);
+ $rows = pg_num_rows($res);
+
+ // Check if there were no results
+ if ($rows == 0) {
+
+ $templateData['genError'] = 'There does not appear to be any Clicks and Views data listed in this database!';
+ $failure = true;
+
+ } else {
+
+ $rrows = 0;
+
+ // Get each row and process it.
+ while ($row = pg_fetch_array($res, null, PGSQL_ASSOC)) {
+
+ // Get new member ID
+ $memb = $Members->getEntry($row['member_id'], 'old_member_id');
+
+ // If we have a good member record
+ if ($memb) {
+
+ $memberId = $memb['id'];
+
+ // Set the date, first date of week, and first date of this month for this entry
+ $time = strtotime($row['edate']);
+ $today = date('Y-m-d', $time);
+ $thisWeek = date('Y-m-d', strtotime($row['edate'].' -'.date('w', $time).' days'));
+ $thisMonth = date('Y-m-d', strtotime($row['edate'].' -'.(date('j', $time)-1).' days'));
+
+ // If there's click through counts to store
+ if ($row['click'] > 0) {
+
+ // Create or update click entries as needed using a Transaction
+ $this->wpdb->query('BEGIN');
+
+ // Day count - stat_type = 1
+ $this->wpdb->query("
+ INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."clickthrough_stats
+ (member, stat_type, stat_date, clicks)
+ VALUES
+ ($memberId, 1, '$today', ".$row['click'].")
+ ON DUPLICATE KEY
+ UPDATE clicks = clicks + ".$row['click'].";
+ ");
+
+ // Week count - stat_type = 2
+ $this->wpdb->query("
+ INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."clickthrough_stats
+ (member, stat_type, stat_date, clicks)
+ VALUES
+ ($memberId, 2, '$thisWeek', ".$row['click'].")
+ ON DUPLICATE KEY
+ UPDATE clicks = clicks + ".$row['click'].";
+ ");
+
+ // Month count - stat_type = 3
+ $this->wpdb->query("
+ INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."clickthrough_stats
+ (member, stat_type, stat_date, clicks)
+ VALUES
+ ($memberId, 3, '$thisMonth', ".$row['click'].")
+ ON DUPLICATE KEY
+ UPDATE clicks = clicks + ".$row['click'].";
+ ");
+
+ $this->wpdb->query('COMMIT');
+
+ }
+
+ // If there's detail view counts to store
+ if ($row['detail'] > 0) {
+
+ // Create or update click entries as needed using a Transaction
+ $this->wpdb->query('BEGIN');
+
+ // Day count - stat_type = 1
+ $this->wpdb->query("
+ INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_detail_stats
+ (member, stat_type, stat_date, clicks)
+ VALUES
+ ($memberId, 1, '$today', ".$row['detail'].")
+ ON DUPLICATE KEY
+ UPDATE clicks = clicks + ".$row['detail'].";
+ ");
+
+ // Week count - stat_type = 2
+ $this->wpdb->query("
+ INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_detail_stats
+ (member, stat_type, stat_date, clicks)
+ VALUES
+ ($memberId, 2, '$thisWeek', ".$row['detail'].")
+ ON DUPLICATE KEY
+ UPDATE clicks = clicks + ".$row['detail'].";
+ ");
+
+ // Week count - stat_type = 3
+ $this->wpdb->query("
+ INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_detail_stats
+ (member, stat_type, stat_date, clicks)
+ VALUES
+ ($memberId, 3, '$thisMonth', ".$row['detail'].")
+ ON DUPLICATE KEY
+ UPDATE clicks = clicks + ".$row['detail'].";
+ ");
+
+ $this->wpdb->query('COMMIT');
+
+ }
+
+ }
+
+ $rrows++;
+ }
+
+
+ }
+
+ if ($rrows != $rows) {
+ $templateData['genError'] = 'There was a problem retrieving all expected Clicks and Views data! (only '.$rrows.' of '.$rows.')';
+ $failure = true;
+ }
+
+ $templateData['rows'] = $rows;
+
+}
+
+if ($failure) {
+ $requestedView = 'import.html';
+} else {
+ $requestedView = 'import/memberClicksViews.html';
+}
diff --git a/views/admin/management/import.html b/views/admin/management/import.html
index 14b69b44..8d28b74f 100644
--- a/views/admin/management/import.html
+++ b/views/admin/management/import.html
@@ -17,6 +17,7 @@
Import member data
@@ -94,7 +95,7 @@
-
+
@@ -103,10 +104,15 @@
Import old member IDs only
+ Import member Clicks and Views
List old/new member IDs
Do not interrupt or re-submit this page.Please Wait!
+ Clicks and Views Import Results
+
+{if isset($genError)}
+ Oops!
+
{$thisDate} - URL Click-Through Counts for Past Month + URL Click-Through Counts for Past Month by Day
{$thisDate} - URL Click-Through Counts for Past 2 Years + URL Click-Through Counts for Past 2 Years by Month
{$thisDate} - Detail Page Views for Past Month -
{$thisDate} - Detail Page Views for Past 2 Years -