silverstripe-framework/security/MemberCsvBulkLoader.php
Damian Mooyman d8e9af8af8 API New Database abstraction layer. Ticket #7429
Database abstraction broken up into controller, connector, query builder, and schema manager, each independently configurable via YAML / Injector
Creation of new DBQueryGenerator for database specific generation of SQL
Support for parameterised queries, move of code base to use these over escaped conditions
Refactor of SQLQuery into separate query classes for each of INSERT UPDATE DELETE and SELECT
Support for PDO
Installation process upgraded to use new ORM
SS_DatabaseException created to handle database errors, maintaining details of raw sql and parameter details for user code designed interested in that data.
Renamed DB static methods to conform correctly to naming conventions (e.g. DB::getConn -> DB::get_conn)
3.2 upgrade docs
Performance Optimisation and simplification of code to use more concise API
API Ability for database adapters to register extensions to ConfigureFromEnv.php
2014-07-09 18:04:05 +12:00

77 lines
1.8 KiB
PHP

<?php
/**
* Imports member records, and checks/updates duplicates based on their
* 'Email' property.
*
* @package framework
* @subpackage security
*/
class MemberCsvBulkLoader extends CsvBulkLoader {
/**
* @var array Array of {@link Group} records. Import into a specific group.
* Is overruled by any "Groups" columns in the import.
*/
protected $groups = array();
public function __construct($objectClass = null) {
if(!$objectClass) $objectClass = 'Member';
parent::__construct($objectClass);
}
public $duplicateChecks = array(
'Email' => 'Email',
);
public function processRecord($record, $columnMap, &$results, $preview = false) {
$objID = parent::processRecord($record, $columnMap, $results, $preview);
$_cache_groupByCode = array();
// Add to predefined groups
$member = DataObject::get_by_id($this->objectClass, $objID);
foreach($this->groups as $group) {
// TODO This isnt the most memory effective way to add members to a group
$member->Groups()->add($group);
}
// Add to groups defined in CSV
if(isset($record['Groups']) && $record['Groups']) {
$groupCodes = explode(',', $record['Groups']);
foreach($groupCodes as $groupCode) {
if(!isset($_cache_groupByCode[$groupCode])) {
$group = Group::get()->filter('Code', $groupCode)->first();
if(!$group) {
$group = new Group();
$group->Code = $groupCode;
$group->Title = $groupCode;
$group->write();
}
$member->Groups()->add($group);
}
$_cache_groupByCode[$groupCode] = $group;
}
}
$member->destroy();
unset($member);
return $objID;
}
/**
* @param Array $groups
*/
public function setGroups($groups) {
$this->groups = $groups;
}
/**
* @return Array
*/
public function getGroups() {
return $this->groups;
}
}