Author: sevein
Date: Tue Aug 21 17:43:56 2012
New Revision: 12154
Log:
Some changes in order to allow preselecting a parent for the import feature,
still work to do. See issue 1993.
Modified:
trunk/apps/qubit/modules/informationobject/templates/_contextMenu.php
trunk/apps/qubit/modules/object/actions/importAction.class.php
trunk/apps/qubit/modules/object/actions/importSelectAction.class.php
trunk/apps/qubit/modules/object/templates/importSelectSuccess.php
trunk/lib/QubitCsvImport.class.php
trunk/lib/QubitXmlImport.class.php
Modified: trunk/apps/qubit/modules/informationobject/templates/_contextMenu.php
==============================================================================
--- trunk/apps/qubit/modules/informationobject/templates/_contextMenu.php
Tue Aug 21 16:14:01 2012 (r12153)
+++ trunk/apps/qubit/modules/informationobject/templates/_contextMenu.php
Tue Aug 21 17:43:56 2012 (r12154)
@@ -19,6 +19,21 @@
</div>
</div>
+<div class="section">
+
+ <h2><?php echo __('Import') ?></h2>
+
+ <div class="content">
+ <ul class="clearfix">
+
+ <li><?php echo link_to(__('XML'), array($resource, 'module' => 'object',
'action' => 'importSelect', 'type' => 'xml')) ?></li>
+ <li><?php echo link_to(__('CSV'), array($resource, 'module' => 'object',
'action' => 'importSelect', 'type' => 'csv')) ?></li>
+
+ </ul>
+ </div>
+
+</div>
+
<?php echo get_partial('informationobject/format', array('resource' =>
$resource)) ?>
<?php if (check_field_visibility('app_element_visibility_physical_storage')):
?>
Modified: trunk/apps/qubit/modules/object/actions/importAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/object/actions/importAction.class.php Tue Aug
21 16:14:01 2012 (r12153)
+++ trunk/apps/qubit/modules/object/actions/importAction.class.php Tue Aug
21 17:43:56 2012 (r12154)
@@ -33,10 +33,23 @@
$this->timer = new QubitTimer;
$file = $request->getFiles('file');
+ // Import type, CSV or XML?
+ $importType = $request->getParameter('importType', 'xml');
+
+ // We will use this later to redirect users back to the importSelect page
+ if (isset($this->getRoute()->resource))
+ {
+ $importSelectRoute = array($this->getRoute()->resource, 'module' =>
'object', 'action' => 'importSelect', 'type' => $importType);
+ }
+ else
+ {
+ $importSelectRoute = array('module' => 'object', 'action' =>
'importSelect', 'type' => $importType);
+ }
+
// if we got here without a file upload, go to file selection
if (!isset($file))
{
- $this->redirect(array('module' => 'object', 'action' => 'importSelect'));
+ $this->redirect();
}
// set indexing preference
@@ -56,7 +69,7 @@
if (!class_exists('ZipArchive'))
{
$this->context->user->setFlash('error', $this->context->i18n->__('PHP
Zip extension could not be found.'));
- $this->redirect(array('module' => 'object', 'action' =>
'importSelect'));
+ $this->redirect($importSelectRoute);
}
// Create temporary directory
@@ -85,12 +98,14 @@
{
case 'csv':
$importer = new QubitCsvImport;
+ if (isset($this->getRoute()->resource))
$importer->setParent($this->getRoute()->resource;
$importer->import($importFile);
break;
case 'xml':
$importer = new QubitXmlImport;
+ if (isset($this->getRoute()->resource))
$importer->setParent($this->getRoute()->resource;
$importer->import($importFile, array('strictXmlParsing' => false));
break;
@@ -99,9 +114,6 @@
}
else
{
- // Import type, CSV or XML?
- $importType = $request->getParameter('importType', 'xml');
-
try
{
// Choose import type based on importType parameter
@@ -111,19 +123,21 @@
{
case 'csv':
$importer = new QubitCsvImport;
+ if (isset($this->getRoute()->resource))
$importer->setParent($this->getRoute()->resource;
$importer->import($file['tmp_name'], $request->csvObjectType);
break;
case 'xml':
$importer = new QubitXmlImport;
+ if (isset($this->getRoute()->resource))
$importer->setParent($this->getRoute()->resource;
$importer->import($file['tmp_name'], array('strictXmlParsing' =>
false));
break;
default:
$this->context->user->setFlash('error',
$this->context->i18n->__('Unable to import selected file: unknown file
extension.'));
- $this->redirect(array('module' => 'object', 'action' =>
'importSelect', 'type' => $importType));
+ $this->redirect($importSelectRoute);
break;
}
@@ -131,7 +145,7 @@
catch (sfException $e)
{
$this->context->user->setFlash('error', $e->getMessage());
- $this->redirect(array('module' => 'object', 'action' =>
'importSelect', 'type' => $importType));
+ $this->redirect($importSelectRoute);
}
// Optimize index if enabled
Modified: trunk/apps/qubit/modules/object/actions/importSelectAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/object/actions/importSelectAction.class.php
Tue Aug 21 16:14:01 2012 (r12153)
+++ trunk/apps/qubit/modules/object/actions/importSelectAction.class.php
Tue Aug 21 17:43:56 2012 (r12154)
@@ -23,6 +23,15 @@
{
$this->form = new sfForm;
+ if (isset($this->getRoute()->resource))
+ {
+ $this->resource = $this->getRoute()->resource;
+
+ $this->form->setDefault('parent',
$this->context->routing->generate(null, array($this->resource)));
+ $this->form->setValidator('parent', new sfValidatorString);
+ $this->form->setWidget('parent', new sfWidgetFormInputHidden);
+ }
+
// Check parameter
if (isset($request->type))
{
Modified: trunk/apps/qubit/modules/object/templates/importSelectSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/object/templates/importSelectSuccess.php Tue Aug
21 16:14:01 2012 (r12153)
+++ trunk/apps/qubit/modules/object/templates/importSelectSuccess.php Tue Aug
21 17:43:56 2012 (r12154)
@@ -1,5 +1,12 @@
<h1><?php echo $title ?></h1>
+<?php if (isset($resource)): ?>
+ <h1 class="label"><?php echo render_title($resource) ?></h1>
+ <?php echo $form->renderFormTag(url_for(array($resource, 'module' =>
'object', 'action' => 'import')), array('enctype' => 'multipart/form-data')) ?>
+<?php else: ?>
+ <?php echo $form->renderFormTag(url_for(array('module' => 'object', 'action'
=> 'import')), array('enctype' => 'multipart/form-data')) ?>
+<?php endif; ?>
+
<?php if ($sf_user->hasFlash('error')): ?>
<div class="messages error">
<h3><?php echo __('Error encountered') ?></h3>
@@ -7,7 +14,7 @@
</div>
<?php endif; ?>
-<?php echo $form->renderFormTag(url_for(array('module' => 'object', 'action'
=> 'import')), array('enctype' => 'multipart/form-data')) ?>
+ <?php echo $form->renderHiddenFields() ?>
<fieldset>
Modified: trunk/lib/QubitCsvImport.class.php
==============================================================================
--- trunk/lib/QubitCsvImport.class.php Tue Aug 21 16:14:01 2012 (r12153)
+++ trunk/lib/QubitCsvImport.class.php Tue Aug 21 17:43:56 2012 (r12154)
@@ -30,9 +30,10 @@
{
protected
$errors = null,
- $rootObject = null;
+ $rootObject = null,
+ $parent = null;
- public function import($csvFile, $type = null, $sourceName = null)
+ public function import($csvFile, $type = null)
{
// Find the proper task
switch ($type)
@@ -60,13 +61,13 @@
}
// Build command string
- if (isset($sourceName))
+ if (isset($this->parent))
{
// Example: php symfony csv:import --source-name="$sourceName"
/tmp/foobar
$command = sprintf('php %s %s --source-name=%s %s',
escapeshellarg(sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'symfony'),
escapeshellarg($taskClassName),
- escapeshellarg($sourceName),
+ escapeshellarg($parent->slug),
escapeshellarg($csvFile));
}
else
@@ -131,4 +132,14 @@
{
return $this->rootObject;
}
+
+ /**
+ * Get the root object for the import
+ *
+ * @return mixed the root object (object type depends on import type)
+ */
+ public function setParent($parent)
+ {
+ return $this->parent = $parent;
+ }
}
Modified: trunk/lib/QubitXmlImport.class.php
==============================================================================
--- trunk/lib/QubitXmlImport.class.php Tue Aug 21 16:14:01 2012 (r12153)
+++ trunk/lib/QubitXmlImport.class.php Tue Aug 21 17:43:56 2012 (r12154)
@@ -30,7 +30,8 @@
{
protected
$errors = null,
- $rootObject = null;
+ $rootObject = null,
+ $parent = null;
public function import($xmlFile, $options = array())
{
@@ -572,4 +573,14 @@
{
return $this->rootObject;
}
+
+ /**
+ * Get the root object for the import
+ *
+ * @return mixed the root object (object type depends on import type)
+ */
+ public function setParent($parent)
+ {
+ return $this->parent = $parent;
+ }
}
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.