Last active
June 10, 2016 05:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple stuff with base64 encode and serialize vars for fast ca_users import.