mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
8dd644d25d
Namespace all templates Move difflib and BBCodeParser2 to thirdparty Remove deprecated API marked for removal in 4.0
65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Security;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
|
use SilverStripe\Dev\CsvBulkLoader;
|
|
|
|
|
|
/**
|
|
* @todo Migrate Permission->Arg and Permission->Type values
|
|
*/
|
|
class GroupCsvBulkLoader extends CsvBulkLoader {
|
|
|
|
public $duplicateChecks = array(
|
|
'Code' => 'Code',
|
|
);
|
|
|
|
public function __construct($objectClass = null) {
|
|
if(!$objectClass) $objectClass = 'SilverStripe\\Security\\Group';
|
|
|
|
parent::__construct($objectClass);
|
|
}
|
|
|
|
public function processRecord($record, $columnMap, &$results, $preview = false) {
|
|
// We match by 'Code', the ID property is confusing the importer
|
|
if(isset($record['ID'])) unset($record['ID']);
|
|
|
|
$objID = parent::processRecord($record, $columnMap, $results, $preview);
|
|
|
|
/** @var Group $group */
|
|
$group = DataObject::get_by_id($this->objectClass, $objID);
|
|
// set group hierarchies - we need to do this after all records
|
|
// are imported to avoid missing "early" references to parents
|
|
// which are imported later on in the CSV file.
|
|
if(isset($record['ParentCode']) && $record['ParentCode']) {
|
|
$parentGroup = DataObject::get_one('SilverStripe\\Security\\Group', array(
|
|
'"Group"."Code"' => $record['ParentCode']
|
|
));
|
|
if($parentGroup) {
|
|
$group->ParentID = $parentGroup->ID;
|
|
$group->write();
|
|
}
|
|
}
|
|
|
|
// set permission codes - these are all additive, meaning
|
|
// existing permissions arent cleared.
|
|
if(isset($record['PermissionCodes']) && $record['PermissionCodes']) {
|
|
foreach(explode(',', $record['PermissionCodes']) as $code) {
|
|
$p = DataObject::get_one('SilverStripe\\Security\\Permission', array(
|
|
'"Permission"."Code"' => $code,
|
|
'"Permission"."GroupID"' => $group->ID
|
|
));
|
|
if(!$p) {
|
|
$p = new Permission(array('Code' => $code));
|
|
$p->write();
|
|
}
|
|
$group->Permissions()->add($p);
|
|
}
|
|
}
|
|
|
|
return $objID;
|
|
}
|
|
|
|
}
|