Skip to content

Instantly share code, notes, and snippets.

@gautiermichelin
Last active June 10, 2016 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gautiermichelin/61ed0a6f058bd535cb0ccd43afd4f50c to your computer and use it in GitHub Desktop.
Save gautiermichelin/61ed0a6f058bd535cb0ccd43afd4f50c to your computer and use it in GitHub Desktop.
Import users from a CSV file into CollectiveAccess, creating here a bunch of SQL inserts to run into a CA database
<?php
// Import users from a CSV file into CollectiveAccess, creating here a bunch of SQL inserts to run into a CA database
// 06/2016, Gautier Michelin
ini_set('auto_detect_line_endings', TRUE);
$ca_install_prefix = "saintmaurtest_";
$rows = array_map('str_getcsv', file('adherents_artotheque_view.csv'));
$header = array_shift($rows);
$csv = array();
foreach ($rows as $row) {
// Mapping each column to the equivalent user var
// "id","titre","prenom","nom","reabonnement","nbabo","part","pro","eco","adresse","cp","ville","telephone","portbureau"
$temp = array_combine($header, $row);
$result=[];
$result["user_profile_organization"] = "";
$result["user_profile_address1"] = $temp["adresse"];
$result["user_profile_address2"] = "";
$result["user_profile_city"] = $temp["ville"];
$result["user_profile_state"]= "";
$result["user_profile_country"]= "France";
$result["user_profile_postalcode"] = $temp["cp"];
$result["user_profile_phone"] = $temp["telephone"];
$result_array =
array(
$ca_install_prefix.'password_reset_expiration' => 0,
$ca_install_prefix.'password_reset_mails_sent' => 0,
$ca_install_prefix.'password_resets_failed' => 0,
'_user_preferences'=>$result
);
if($temp["nom"]) {
print "replace into ca_users (user_name, userclass, fname, lname, email, sms_number, vars, active)"
."values (\"".$temp["prenom"]."_".$temp["nom"]."\", 1, \"".$temp["prenom"]."\", \"".$temp["nom"]."\", \"\", \"".$temp["portbureau"]."\", \"".base64_encode(serialize($result_array))."\", 1);\n";
}
}
@gautiermichelin
Copy link
Author

Simple stuff with base64 encode and serialize vars for fast ca_users import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment