If you requested access to your source code after the release of the Member CSV Export feature but before the v2.3 release, you may notice that this feature has stopped working. Although we make every effort to keep our APIs stable, we very rarely must make small changes. Don't worry, though, there's an easy fix which we'll describe here!
To make this fix all you'll need to do is to replace the contents of some functions. If you've made any changes to these functions you'll also need to either merge the changes or reimplement them.
/**
* Serves up the memberdata that has been previously exported
* @see Index_BulkController::action_exportMemberData()
*/
public function action_downloadMemberData() {
if (! XG_SecurityHelper::userIsAdmin()) {
throw new Exception("Permission denied.");
}
$this->_widget->includeFileOnce('/lib/helpers/Index_MembershipHelper.php');
$file = Index_MembershipHelper::memberDataExportFile();
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="' . basename($file).'"');
@readfile($file);
}
/**
* For exporting member profile information to .csv file
* should only be called via xn_out=json and an admin
*/
public function action_exportMemberData() {
if (! XG_SecurityHelper::userIsAdmin()) {
throw new Exception("Permission denied.");
}
try {
/*
* Requests must be a POST operation by an administrator
*/
if ($_SERVER['REQUEST_METHOD'] != 'POST') { throw new Exception("Only POST requests permitted"); }
$usersPerRequest = 50;
// What is the starting and ending offset of this page?
$start = $_POST['counter'] * $usersPerRequest;
$end = $start + $usersPerRequest;
$this->_widget->includeFileOnce('/lib/helpers/Index_MembershipHelper.php');
if ($_POST["counter"]== 0) {
$csv = @fopen(Index_MembershipHelper::memberDataExportFile(),'w');
} else {
$csv = @fopen(Index_MembershipHelper::memberDataExportFile(),'a');
}
if ($csv === false) {
throw new Exception("Can't open member data export file");
}
$profilesWidget = W_Cache::getWidget('profiles');
$profilesWidget->includeFileOnce('/lib/helpers/Profiles_ProfileQuestionHelper.php');
$questions = Profiles_ProfileQuestionHelper::getQuestions($profilesWidget);
if ($_POST['counter'] == 0) {
$csvoutput = "\xEF\xBB\xBF" . 'Name' . "," . 'Profile Address' . "," . 'Email';
foreach ($questions as $question) {
$quest = str_replace(','," ",$question);
$csvoutput .= "," . $quest;
}
fwrite($csv,"$csvoutput\r\n");
}
$filters = array();
$members = User::find($filters, $start, $end,
'createdDate', 'desc', TRUE);
foreach ($members as $user) {
// Would be more correct to use xg_username here, as it falls back to the profile fullName
// if the User fullName is not set. However, xg_username does a couple of queries per user
// (unless we preload the users with XG_Cache::profiles). Anyway, just use my->fullName
// for simplicity and performance. [Jon Aquino 2007-10-30]
if ($user->my->fullName) { // [skip-Syntax7Test]
$fullname = $user->my->fullName; // [skip-Syntax7Test]
} else {
$fullname = $user->title;
}
$csvoutput = $fullname . ",http://" . $_SERVER['SERVER_NAME'] . User::quickProfileUrl($user->contributorName) . "," . XN_Profile::load($user->contributorName)->email;
foreach ($questions as $question) {
$attributeName = 'xg_profiles_answer_q' . $question;
$answer = unserialize($user->my->$attributeName);
if (!$answer) {
$answer = $user->my->$attributeName;
}
if (is_array($answer)) {
$answer = implode(',',$answer);
}
$answer = preg_replace("/[\n\r]/u","",$answer);
$csvoutput .= "," . str_replace(",",' ', $answer);
}
$changed++;
fwrite($csv,"$csvoutput\r\n");
}
// Don't let $remaining get below 0
$remaining = max(0, ($members - $end));
$this->contentChanged = $changed;
$this->contentRemaining = $remaining;
fclose($csv);
} catch (Exception $e) {
$this->errorMessage = $e->getMessage();
}
}
/**
* To what file is member data exported?
* @return string
*/
public static function memberDataExportFile() {
return $_SERVER['SERVER_NAME'] . '/xn_private/memberdata.csv';
}
_successMessage="<%= xg_html('CLICK_TO_SEE_MEMBER_DATA', 'href=\'/xn_private/memberdata.csv\' target=\'_new\'') %>"
to
_successMessage="<%= xg_html('CLICK_TO_SEE_MEMBER_DATA', "href='{$this->_widget->buildUrl('membership','downloadMemberData')}' target='_new'") %>"
'CLICK_TO_SEE_MEMBER_DATA' => 'Your Member Data has been exported. Right click this link and choose \'Save As\' in order to save it to your desktop.',to
'CLICK_TO_SEE_MEMBER_DATA' => 'Your Member Data has been exported. Click this link in order to save it to your desktop.',
You're all done. That was easy, wasn't it? Your member export feature should now operate correctly on your network running its own source code. If you have any questions or issues be sure to let us know!
Last updated by Devin Jul 8.
© 2008 Created by Ning Developer Admin