Skip to content

Commit

Permalink
[mms] Store CSV and TSV data in storage object, instead of temporary …
Browse files Browse the repository at this point in the history
…file, to ensure import can work across a PHP cluster.
  • Loading branch information
slusarz committed May 9, 2014
1 parent 7750151 commit 0bafddd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
3 changes: 0 additions & 3 deletions framework/Data/lib/Horde/Data/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,6 @@ public function nextStep($action, array $param = array())
*/
public function cleanup()
{
if ($filename = $this->storage->get('file_name')) {
@unlink($filename);
}
$this->storage->clear();

if ($this->_cleanupCallback) {
Expand Down
13 changes: 8 additions & 5 deletions framework/Data/lib/Horde/Data/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ public function nextStep($action, array $param = array())

/* Move uploaded file so that we can read it again in the next
step after the user gave some format details. */
$file_name = Horde_Util::getTempFile('import', false);
if (!move_uploaded_file($_FILES['import_file']['tmp_name'], $file_name)) {
$file_name = $_FILES['import_file']['tmp_name'];
if (($file_data = file_get_contents($file_name)) === false) {
throw new Horde_Data_Exception(Horde_Data_Translation::t("The uploaded file could not be saved."));
}

/* Do charset checking now, if requested. */
if (isset($param['check_charset'])) {
$file_data = file_get_contents($file_name);
$charset = isset($this->_vars->charset)
? Horde_String::lower($this->_vars->charset)
: 'utf-8';
Expand All @@ -231,7 +230,7 @@ public function nextStep($action, array $param = array())
}

$this->storage->set('charset', $this->_vars->charset);
$this->storage->set('file_name', $file_name);
$this->storage->set('file_data', $file_data);

/* Read the file's first two lines to show them to the user. */
$first_lines = '';
Expand Down Expand Up @@ -265,8 +264,12 @@ public function nextStep($action, array $param = array())
if (isset($param['import_mapping'])) {
$import_mapping = $param['import_mapping'];
}

$file_name = Horde_Util::getTempFile('import');
file_put_contents($file_name, $this->storage->get('file_data'));

$this->storage->set('data', $this->importFile(
$this->storage->get('file_name'),
$file_name,
$this->_vars->header,
$this->_vars->sep,
$this->_vars->quote,
Expand Down
16 changes: 10 additions & 6 deletions framework/Data/lib/Horde/Data/Tsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,19 @@ public function nextStep($action, array $param = array())
return $this->nextStep(Horde_Data::IMPORT_DATA, $param);
}

/* Move uploaded file so that we can read it again in the next step
after the user gave some format details. */
/* Store uploaded file data so that we can read it again in the
* next step after the user gives some format details. */
try {
$this->_browser->wasFileUploaded('import_file', Horde_Data_Translation::t("TSV file"));
} catch (Horde_Browser_Exception $e) {
throw new Horde_Data_Exception($e);
}
$file_name = Horde_Util::getTempFile('import', false);
if (!move_uploaded_file($_FILES['import_file']['tmp_name'], $file_name)) {

$file_name = $_FILES['import_file']['tmp_name'];
if (($file_data = file_get_contents($file_name)) === false) {
throw new Horde_Data_Exception(Horde_Data_Translation::t("The uploaded file could not be saved."));
}
$this->storage->set('file_name', $file_name);
$this->storage->set('file_data', $file_data);

/* Read the file's first two lines to show them to the user. */
$first_lines = '';
Expand All @@ -237,8 +238,11 @@ public function nextStep($action, array $param = array())
return Horde_Data::IMPORT_TSV;

case Horde_Data::IMPORT_TSV:
$file_name = Horde_Util::getTempFile('import');
file_put_contents($file_name, $this->storage->get('file_data'));

$this->storage->set('header', $this->_vars->header);
$this->storage->set('data', $this->importFile($this->storage->get('file_name'), $this->storage->get('header')));
$this->storage->set('data', $this->importFile($file_name, $this->storage->get('header')));
$this->storage->set('map');
return Horde_Data::IMPORT_MAPPED;
}
Expand Down
4 changes: 2 additions & 2 deletions framework/Data/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Store CSV and TSV data in storage object, instead of temporary file, to ensure import can work across a PHP cluster.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -945,7 +945,7 @@ Converted to package.xml 2.0 for pear.horde.org
<date>2013-05-28</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Store CSV and TSV data in storage object, instead of temporary file, to ensure import can work across a PHP cluster.
</notes>
</release>
</changelog>
Expand Down

0 comments on commit 0bafddd

Please sign in to comment.