|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Security; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use SilverStripe\ORM\DataObject; |
|
7
|
|
|
use CsvBulkLoader; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @todo Migrate Permission->Arg and Permission->Type values |
|
11
|
|
|
* |
|
12
|
|
|
* @package framework |
|
13
|
|
|
* @subpackage security |
|
14
|
|
|
*/ |
|
15
|
|
|
class GroupCsvBulkLoader extends CsvBulkLoader { |
|
16
|
|
|
|
|
17
|
|
|
public $duplicateChecks = array( |
|
18
|
|
|
'Code' => 'Code', |
|
19
|
|
|
); |
|
20
|
|
|
|
|
21
|
|
|
public function __construct($objectClass = null) { |
|
22
|
|
|
if(!$objectClass) $objectClass = 'SilverStripe\\Security\\Group'; |
|
23
|
|
|
|
|
24
|
|
|
parent::__construct($objectClass); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function processRecord($record, $columnMap, &$results, $preview = false) { |
|
28
|
|
|
// We match by 'Code', the ID property is confusing the importer |
|
29
|
|
|
if(isset($record['ID'])) unset($record['ID']); |
|
30
|
|
|
|
|
31
|
|
|
$objID = parent::processRecord($record, $columnMap, $results, $preview); |
|
32
|
|
|
|
|
33
|
|
|
$group = DataObject::get_by_id($this->objectClass, $objID); |
|
34
|
|
|
// set group hierarchies - we need to do this after all records |
|
35
|
|
|
// are imported to avoid missing "early" references to parents |
|
36
|
|
|
// which are imported later on in the CSV file. |
|
37
|
|
|
if(isset($record['ParentCode']) && $record['ParentCode']) { |
|
38
|
|
|
$parentGroup = DataObject::get_one('SilverStripe\\Security\\Group', array( |
|
39
|
|
|
'"Group"."Code"' => $record['ParentCode'] |
|
40
|
|
|
)); |
|
41
|
|
|
if($parentGroup) { |
|
42
|
|
|
$group->ParentID = $parentGroup->ID; |
|
|
|
|
|
|
43
|
|
|
$group->write(); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
// set permission codes - these are all additive, meaning |
|
48
|
|
|
// existing permissions arent cleared. |
|
49
|
|
|
if(isset($record['PermissionCodes']) && $record['PermissionCodes']) { |
|
50
|
|
|
foreach(explode(',', $record['PermissionCodes']) as $code) { |
|
51
|
|
|
$p = DataObject::get_one('SilverStripe\\Security\\Permission', array( |
|
52
|
|
|
'"Permission"."Code"' => $code, |
|
53
|
|
|
'"Permission"."GroupID"' => $group->ID |
|
54
|
|
|
)); |
|
55
|
|
|
if(!$p) { |
|
56
|
|
|
$p = new Permission(array('Code' => $code)); |
|
57
|
|
|
$p->write(); |
|
58
|
|
|
} |
|
59
|
|
|
$group->Permissions()->add($p); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $objID; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.