mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
API CHANGE Removing unfinished deprecated BulkLoader functionality
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@54119 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
6d6b43b21d
commit
52a96217e9
@ -14,7 +14,6 @@ Director::addRules(50, array(
|
||||
'admin/assets/$Action/$ID' => 'AssetAdmin',
|
||||
'admin/comments/$Action' => 'CommentAdmin',
|
||||
'admin/ReportField/$Action/$ID/$Type/$OtherID' => 'ReportField_Controller',
|
||||
'admin/bulkload/$Action/$ID/$OtherID' => 'BulkLoaderAdmin',
|
||||
'admin/ImageEditor/$Action' => 'ImageEditor',
|
||||
'admin/$Action/$ID/$OtherID' => 'CMSMain',
|
||||
'unsubscribe/$Email/$MailingList' => 'Unsubscribe_Controller',
|
||||
|
@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package cms
|
||||
* @subpackage bulkloading
|
||||
*/
|
||||
|
||||
/**
|
||||
* An abstract base for bulk loaders of content into the SilverStripe database.
|
||||
* Bulk loaders give SilverStripe authors the ability to do large-scale CSV uploads into their Sapphire databases.
|
||||
* @package cms
|
||||
* @subpackage bulkloading
|
||||
*/
|
||||
abstract class BulkLoader extends ViewableData {
|
||||
/**
|
||||
* Override this on subclasses to give the specific functions names
|
||||
*/
|
||||
static $title = null;
|
||||
|
||||
/**
|
||||
* Return a human-readable name for this object.
|
||||
* It defaults to the class name can be overridden by setting the static variable $title
|
||||
*/
|
||||
function Title() {
|
||||
if($title = $this->stat('title')) return $title;
|
||||
else return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process every record in the file
|
||||
* @param filename The name of the CSV file to process
|
||||
* @param preview If true, we'll just output a summary of changes but not actually do anything
|
||||
*
|
||||
* @returns A DataObjectSet containing a list of all the reuslst
|
||||
*/
|
||||
function processAll($filename, $preview = false) {
|
||||
// TODO
|
||||
// Get the first record out of the CSV and store it as headers
|
||||
// Get each record out of the CSV
|
||||
// Remap the record so that it's keyed by headers
|
||||
// Pass it to $this->processRecord, and get the results
|
||||
// Put the results inside an ArrayData and push that onto a DataObjectSet for returning
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------------------
|
||||
* Next, we have some abstract functions that let subclasses say what kind of batch operation they're
|
||||
* going to do
|
||||
*----------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Return a FieldSet containing all the options for this form; this
|
||||
* doesn't include the actual upload field itself
|
||||
*/
|
||||
abstract function getOptionFields();
|
||||
|
||||
/**
|
||||
* Process a single record from the CSV file.
|
||||
* @param record An map of the CSV data, keyed by the header field
|
||||
* @param preview
|
||||
*
|
||||
* @returns A 2 value array.
|
||||
* - The first element should be "add", "edit" or "", depending on the operation performed in response to this record
|
||||
* - The second element is a free-text string that can optionally provide some more information about what changes have
|
||||
* been made
|
||||
*/
|
||||
abstract function processRecord($record, $preview = false);
|
||||
|
||||
/*----------------------------------------------------------------------------------------
|
||||
* Next, we have a library of helper functions (Brian to build as necessary)
|
||||
*----------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,135 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package cms
|
||||
* @subpackage bulkloading
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to provide batch-update facilities to CMS users.
|
||||
* The BulkLoaderAdmin class provides an interface for accessing all of the subclasses of BulkLoader,
|
||||
* each of which defines a particular bulk loading operation.
|
||||
*
|
||||
* @package cms
|
||||
* @subpackage bulkloading
|
||||
* @deprecated This class has never been used in production; if we're going to continue to support it we should increase its usefulness.
|
||||
*/
|
||||
class BulkLoaderAdmin extends LeftAndMain {
|
||||
|
||||
static $allowed_actions = array(
|
||||
'preview' => 'ADMIN',
|
||||
'process' => 'ADMIN',
|
||||
);
|
||||
|
||||
/**
|
||||
* Initialisation method called before accessing any functionality that BulkLoaderAdmin has to offer
|
||||
*/
|
||||
public function init() {
|
||||
Requirements::javascript('cms/javascript/BulkLoaderAdmin.js');
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Link function to tell us how to get back to this controller.
|
||||
*/
|
||||
public function Link($action = null) {
|
||||
return "admin/bulkload/$action";
|
||||
}
|
||||
|
||||
public function BulkLoaders() {
|
||||
$items = ClassInfo::subclassesFor("BulkLoader");
|
||||
array_shift($items);
|
||||
|
||||
foreach($items as $item) {
|
||||
$itemObjects[] = new $item();
|
||||
}
|
||||
|
||||
return new DataObjectSet($itemObjects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the form shown when we first click on a loader on the left.
|
||||
* Provides all the options, a file upload, and an option to proceed
|
||||
*/
|
||||
public function getEditForm($className = null) {
|
||||
if(is_subclass_of($className, 'BulkLoader')) {
|
||||
$loader = new $className();
|
||||
|
||||
$fields = $loader->getOptionFields();
|
||||
if(!$fields) $fields = new FieldSet();
|
||||
|
||||
$fields->push(new FileField("File", _t('BulkLoaderAdmin.CSVFILE','CSV File')));
|
||||
$fields->push(new HiddenField('LoaderClass', '', $loader->class));
|
||||
|
||||
return new Form($this, "EditForm",
|
||||
$fields,
|
||||
new FieldSet(
|
||||
new FormAction('preview', _t('BulkLoaderAdmin.PREVIEW',"Preview"))
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function preview() {
|
||||
$className = $_REQUEST['LoaderClass'];
|
||||
if(is_subclass_of($className, 'BulkLoader')) {
|
||||
$loader = new $className();
|
||||
|
||||
$results = $loader->processAll($_FILES['File']['tmp_name'], false);
|
||||
|
||||
return $this->customise(array(
|
||||
"Message" => _t('BulkLoaderAdmin.PRESSCNT','Press continue to load this data in'),
|
||||
"Results" => $results,
|
||||
"ConfirmForm" => $this->getConfirmFormFor($loader, $file),
|
||||
))->renderWith("BulkLoaderAdmin_preview");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a confirmation form for the given file/class
|
||||
* Will copy the file to a suitable temporary location
|
||||
* @param loader A BulkLoader object
|
||||
* @param file The name of the temp file
|
||||
*/
|
||||
public function getConfirmFormFor($loader, $file) {
|
||||
$tmpFile = tempnam(TEMP_FOLDER,'batch-upload-');
|
||||
copy($file,$tmpFile);
|
||||
|
||||
return new Form($this, "ConfirmForm", new FieldSet(
|
||||
new HiddenField("File", "", $tmpFile),
|
||||
new HiddenField("LoaderClass", "", $loader->class)
|
||||
), new FieldSet(
|
||||
new FormAction('process', _t('BulkLoaderAdmin.CONFIRMBULK','Confirm bulk load'))
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Stub to return the form back after pressing the button.
|
||||
*/
|
||||
public function ConfirmForm() {
|
||||
$className = $_REQUEST['LoaderClass'];
|
||||
return $this->getConfirmFormFor(new $className(), $_REQUEST['File']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the data and display the final "finished" message
|
||||
*/
|
||||
public function process() {
|
||||
$className = $_REQUEST['LoaderClass'];
|
||||
if(is_subclass_of($className, 'BulkLoader')) {
|
||||
$loader = new $className();
|
||||
|
||||
$results = $loader->processAll($_REQUEST['Filename'], true);
|
||||
|
||||
return $this->customise(array(
|
||||
"Message" => _t('BulkLoaderAdmin.DATALOADED', 'This data has been loaded in'),
|
||||
"Results" => $results,
|
||||
"ConfirmForm" => " ",
|
||||
))->renderWith("BulkLoaderAdmin_preview");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Configuration for the left hand tree
|
||||
*/
|
||||
if(typeof SiteTreeHandlers == 'undefined') SiteTreeHandlers = {};
|
||||
SiteTreeHandlers.loadPage_url = 'admin/bulkload/getitem';
|
||||
SiteTreeHandlers.showRecord_url = 'admin/bulkload/show/';;
|
||||
|
||||
Behaviour.register({
|
||||
'#Form_EditForm' : {
|
||||
getPageFromServer: function (className) {
|
||||
$('BulkLoaderIframe').src = 'admin/bulkload/iframe/' + className;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
@ -1 +0,0 @@
|
||||
$EditForm
|
@ -1,10 +0,0 @@
|
||||
<p>$Message
|
||||
|
||||
<% _t('RES','Results') %>
|
||||
|
||||
|
||||
<% control Results %>
|
||||
list changes here
|
||||
<% end_control %>
|
||||
|
||||
$ConfirmForm
|
@ -1,20 +0,0 @@
|
||||
<div class="title"><div><% _t('FUNCTIONS','Functions') %></div></div>
|
||||
|
||||
<div id="treepanes">
|
||||
<div id="sitetree_holder" style="overflow:auto">
|
||||
<% if BulkLoaders %>
|
||||
<ul id="sitetree" class="tree unformatted">
|
||||
<li id="$ID" class="root Root"><a><% _t('BATCHEF','Batch entry functions')</a>
|
||||
|
||||
<ul>
|
||||
<% control BulkLoaders %>
|
||||
<li id="record-$class">
|
||||
<a href="admin/bulkload/show/$class">$Title</a>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
@ -1,5 +0,0 @@
|
||||
<form id="Form_EditForm" action="admin/bulkload?executeForm=EditForm" method="post" enctype="multipart/form-data">
|
||||
<iframe style="width: 100%; height: 100%" src="admin/bulkload/iframe/$Class"></iframe>
|
||||
</form>
|
||||
|
||||
<p id="statusMessage" style="visibility:hidden"></p>
|
Loading…
Reference in New Issue
Block a user