Source of file ListBulkLoader.php
Size: 1,484 Bytes - Last Modified: 2021-12-24T05:16:49+00:00
/var/www/docs.ssmods.com/process/src/src/BulkLoader/ListBulkLoader.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | <?php namespace ilateral\SilverStripe\ImportExport\BulkLoader; use SilverStripe\ORM\DataList; /** * Peforms bulk loading, but works with a given DataList. */ class ListBulkLoader extends BetterBulkLoader { /** * The list to insert new DataObjects into. * @var DataList */ protected $list; public function __construct(DataList $list) { $this->list = $list; //TODO: user error if list is null parent::__construct($this->list->dataClass()); } public function setList(DataList $list) { $this->list = $list; return $this; } /** * Get the DataList of objects this loader applies to. * @return DataList */ public function getDataList() { return $this->list; } /** * Add records to the list. */ protected function processAll($filepath, $preview = false) { $iterator = $this->getSource()->getIterator(); $results = new BetterBulkLoader_Result(); foreach ($iterator as $record) { if ($id = $this->processRecord($record, $this->columnMap, $results, $preview)) { $this->list->add($id); } } return $results; } /** * Override the default deleteExistingRecords method. */ public function deleteExistingRecords() { foreach ($this->list as $item) { $item->delete(); $item->destroy(); } } } |