mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
2e577ddb1d
The bundle is generated by running “webpack” directly - gulp is no longer needed as an intermediary. The resulting config is a lot shorter, although more configuration is pushed into lib.js. Modules are shared between javascript files as global variables. Although this global state pollution is a bit messy, I don’t think it’s practically any worse than the previous state, and it highlights the heavy coupling between the different packages we have in place. Reducing the width of the coupling between the core javascript and add-on modules would probably be a better way of dealing with this than replacing global variables with some other kind of global state. The web pack execution seems roughly twice as fast - if I clear out my framework/client/dist/js folder, it takes 13.3s to rebuild. However, it’s not rebuilding other files inside dist, only the bundle files. CSS files are now included from javascript and incorporated into bundle.css by the webpack. Although the style-loader is helpful in some dev workflows (it allows live reload), it introduces a flash of unstyled content which makes it inappropriate for production. Instead ExtractTextPlugin is used to write all the aggregated CSS into a single bundle.css file. A style-loader-based configuration could be introduced for dev environments, if we make use of the webpack live reloader in the future. Note that the following features have been removed as they don't appear to be necessary when using Webpack: - UMD module generation - thirdparty dist file copying LeftAndMain.js deps: Without it, ssui.core.js gets loaded too late, which leads e.g. to buttons being initialised without this added behaviour.
126 lines
3.7 KiB
PHP
126 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Admin;
|
|
|
|
use SilverStripe\Security\Group;
|
|
use SilverStripe\Security\MemberCsvBulkLoader;
|
|
use SilverStripe\Forms\LiteralField;
|
|
use SilverStripe\Forms\FileField;
|
|
use SilverStripe\Forms\FieldList;
|
|
use SilverStripe\Forms\FormAction;
|
|
use SilverStripe\Forms\RequiredFields;
|
|
use SilverStripe\Forms\Form;
|
|
use SilverStripe\View\Requirements;
|
|
|
|
/**
|
|
* Imports {@link Member} records by CSV upload, as defined in
|
|
* {@link MemberCsvBulkLoader}.
|
|
*/
|
|
class MemberImportForm extends Form {
|
|
|
|
/**
|
|
* @var Group Optional group relation
|
|
*/
|
|
protected $group;
|
|
|
|
public function __construct($controller, $name, $fields = null, $actions = null, $validator = null) {
|
|
if(!$fields) {
|
|
$helpHtml = _t(
|
|
'MemberImportForm.Help1',
|
|
'<p>Import users in <em>CSV format</em> (comma-separated values).'
|
|
. ' <small><a href="#" class="toggle-advanced">Show advanced usage</a></small></p>'
|
|
);
|
|
$helpHtml .= _t(
|
|
'MemberImportForm.Help2',
|
|
'<div class="advanced">'
|
|
. '<h4>Advanced usage</h4>'
|
|
. '<ul>'
|
|
. '<li>Allowed columns: <em>%s</em></li>'
|
|
. '<li>Existing users are matched by their unique <em>Code</em> property, and updated with any new values from '
|
|
. 'the imported file.</li>'
|
|
. '<li>Groups can be assigned by the <em>Groups</em> column. Groups are identified by their <em>Code</em> property, '
|
|
. 'multiple groups can be separated by comma. Existing group memberships are not cleared.</li>'
|
|
. '</ul>'
|
|
. '</div>'
|
|
);
|
|
|
|
$importer = new MemberCsvBulkLoader();
|
|
$importSpec = $importer->getImportSpec();
|
|
$helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
|
|
|
|
$fields = new FieldList(
|
|
new LiteralField('Help', $helpHtml),
|
|
$fileField = new FileField(
|
|
'CsvFile',
|
|
_t(
|
|
'SecurityAdmin_MemberImportForm.FileFieldLabel',
|
|
'CSV File <small>(Allowed extensions: *.csv)</small>'
|
|
)
|
|
)
|
|
);
|
|
$fileField->getValidator()->setAllowedExtensions(array('csv'));
|
|
}
|
|
|
|
if(!$actions) {
|
|
$action = new FormAction('doImport', _t('SecurityAdmin_MemberImportForm.BtnImport', 'Import from CSV'));
|
|
$action->addExtraClass('btn btn-secondary-outline ss-ui-button');
|
|
$actions = new FieldList($action);
|
|
}
|
|
|
|
if(!$validator) $validator = new RequiredFields('CsvFile');
|
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator);
|
|
|
|
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js');
|
|
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js');
|
|
Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/style/bundle.css');
|
|
|
|
$this->addExtraClass('cms');
|
|
$this->addExtraClass('import-form');
|
|
}
|
|
|
|
public function doImport($data, $form) {
|
|
$loader = new MemberCsvBulkLoader();
|
|
|
|
// optionally set group relation
|
|
if($this->group) $loader->setGroups(array($this->group));
|
|
|
|
// load file
|
|
$result = $loader->load($data['CsvFile']['tmp_name']);
|
|
|
|
// result message
|
|
$msgArr = array();
|
|
if($result->CreatedCount()) $msgArr[] = _t(
|
|
'MemberImportForm.ResultCreated', 'Created {count} members',
|
|
array('count' => $result->CreatedCount())
|
|
);
|
|
if($result->UpdatedCount()) $msgArr[] = _t(
|
|
'MemberImportForm.ResultUpdated', 'Updated {count} members',
|
|
array('count' => $result->UpdatedCount())
|
|
);
|
|
if($result->DeletedCount()) $msgArr[] = _t(
|
|
'MemberImportForm.ResultDeleted', 'Deleted %d members',
|
|
array('count' => $result->DeletedCount())
|
|
);
|
|
$msg = ($msgArr) ? implode(',', $msgArr) : _t('MemberImportForm.ResultNone', 'No changes');
|
|
|
|
$this->sessionMessage($msg, 'good');
|
|
|
|
$this->controller->redirectBack();
|
|
}
|
|
|
|
/**
|
|
* @param $group Group
|
|
*/
|
|
public function setGroup($group) {
|
|
$this->group = $group;
|
|
}
|
|
|
|
/**
|
|
* @return Group
|
|
*/
|
|
public function getGroup($group) {
|
|
return $this->group;
|
|
}
|
|
}
|