Not all data exporting

sam_bolton - August 22, 2007 - 02:35
Project:Profile CSV
Version:5.x-1.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

When I run the profile csv, not all of the data necessarily transfers across. For example in in a particular field, some of the information exports, but not all. This does not affect every field, only about 2 or 3.

I have installed a patch which improved things (http://drupal.org/node/83310), and changed the profile field from hidden to private, which also improved things but did not completely correct it (and I need to keep some fields hidden).

This is slightly different to previously reported problems in that the column is not entirely blank - some of the info is there, but not all.

Does anyone have any suggestions as to how to get all of the data to export? Thanks in advance for your help.

#1

brenk28 - December 6, 2007 - 19:45
Version:4.7.x-1.x-dev» 5.x-1.x-dev

This happens for me in 5.x-1.x-dev as well.

I think the problem is in the "_profile_csv_get_profile" function. Specifically, it first checks the visibility of the profile field, and if it is 4, it checks the data that is has from the user table and if not, queries the profile_values table. My profile fields were set to "Public field, content shown on profile page but not used on member list pages", returning a visibility of 2. However, my data was in stored in user.data and not in profile_values, so the function was not returning any data.

I don't know why my data was stored in user.data as opposed to the profile_values table, but it seems to me that first checking if ($profile_field ['visibility'] == 4) should be removed; just check first if you have the data, and if not, then do the query. So this is the modified version of the function that works for me:

function _profile_csv_get_profile($uid=0,$user_data=NULL) {
  $profile_fields = _profile_csv_get_profile_fields();
  $profile_result = array();
  foreach($profile_fields  as $profile_field) {
    $value = "";
    //$value = try to get it from the $user_data
    $value = $user_data[$profile_field['name']];
    if (!($value)) {
      $value = db_result(db_query("SELECT pv.value FROM {profile_fields} pf, {profile_values} pv ".
                                  "WHERE pv.fid = pf.fid ".
                                  "AND pf.name = '%s' ".
                                  "AND pv.uid = %d", $profile_field['name'], $uid));
   }

    if ($profile_field['type'] == 'date') {
      if ($value !== 0) {
        $value = unserialize($value);
        $value = $value['year'] .'-'. $value['month'] .'-'. $value['day'];
      }
    }
    $profile_result[] = $value;
  }
return $profile_result;
}

#2

ask - September 23, 2008 - 19:49

To fix the problem I made this dirty change:

svn diff
Index: profile_csv.module
===================================================================
--- profile_csv.module (revision 93)
+++ profile_csv.module (working copy)
@@ -239,7 +239,7 @@
$profile_fields = _profile_csv_get_profile_fields();
$profile_result = array();
foreach($profile_fields as $profile_field) {
- if ($profile_field ['visibility'] == 4) {
+ if ($profile_field ['visibility'] == 4 && !empty($user_data[$profile_field['name']])) {
//$value = try to get it from the $user_data
$value = $user_data[$profile_field['name']];
}

============
Not sure, but I feel that the problem is connected with usage of user_save() function somewhere in the middle of execution, which lean to storage of the profile in two tables: users.data and profile_values.value.

#3

jchin1968 - November 11, 2008 - 16:31

Check your profile_values table for duplicate records with the same profile_values.fid and profile_values.uid. That was causing my profile export file to contain blank field values.

For some reason, most likely during user data import, I ended up with over a thousand cases where two records had the same fid and uid values but with different profile_values.value. Fortunately, the erroneous record contained a blank value while the correct record contained some value so it was relatively easy to delete the duplicate record. This is the SQL statement I used to get rid of the duplicate records. It's not the most elegant code but it works.

CREATE TEMPORARY TABLE tmptable
SELECT * FROM profile_values pv1
WHERE pv1.value='' AND 2=(SELECT COUNT(*) FROM profile_values pv2 WHERE pv2.fid=pv1.fid AND pv2.uid=pv1.uid);

DELETE profile_values FROM profile_values
INNER JOIN tmptable
ON profile_values.fid = tmptable.fid AND profile_values.uid = tmptable.uid
WHERE profile_values.value='';

 
 

Drupal is a registered trademark of Dries Buytaert.