Skip to content

Commit

Permalink
Improve memory management of import
Browse files Browse the repository at this point in the history
 - Every file of media was kept in memory
  • Loading branch information
torinfo committed Jul 12, 2022
1 parent 74eac52 commit 4c6fb70
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions website_code/php/import/import.php
Expand Up @@ -454,23 +454,39 @@ function test_unrecognised_import($test_array, $check) {

foreach ($zip->compressedList as $x) {

foreach ($x as $y) {
if (!(strpos($y, "media/") === false)) {
$string = $zip->unzip($y, false, 0777);
$temp_array = array($y, $string, "media");
array_push($file_data, $temp_array);
}
$y = $x['file_name'];
if (!(strpos($y, "media/") === false)) {
$string = $zip->unzip($y, false, 0777);
$file_to_create = array($y, $string, "media");
if ($file_to_create[0] != "") {
$pos = strrpos($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], '/');
if ($pos > 0) {
$dir = substr($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], 0, $pos);

if ((strpos($y, ".rlt") !== false)) {
$string = $zip->unzip($y, false, 0777);
$rlt_name = $y;
$temp_array = array($y, $string, "rlt");
array_push($file_data, $temp_array);
if (!(strpos($string, "templateData=") === false)) {
$temp = substr($string, strpos($string, "templateData=\"FileLocation + '") + strlen("templateData=\"FileLocation + '"));
$temp = substr($temp, 0, strpos($temp, "'"));
$template_data_equivalent = $temp;
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
}

$fp = fopen($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], "w");

fwrite($fp, $file_to_create[1]);

fclose($fp);

chmod($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], 0777);
}
}

if ((strpos($y, ".rlt") !== false)) {
$string = $zip->unzip($y, false, 0777);
$rlt_name = $y;
$temp_array = array($y, $string, "rlt");
array_push($file_data, $temp_array);
if (!(strpos($string, "templateData=") === false)) {
$temp = substr($string, strpos($string, "templateData=\"FileLocation + '") + strlen("templateData=\"FileLocation + '"));
$temp = substr($temp, 0, strpos($temp, "'"));
$template_data_equivalent = $temp;
}
}
}
Expand All @@ -483,16 +499,15 @@ function test_unrecognised_import($test_array, $check) {
$preview_xml = '';

foreach ($zip->compressedList as $x) {
foreach ($x as $y) {
if ($y === $template_data_equivalent || $y === "template.xml") {
$data_xml = $zip->unzip($y, false, 0777);
$temp_array = array("data.xml", $data_xml, null);
array_push($file_data, $temp_array);
} else if ($y === "preview.xml") {
$preview_xml = $zip->unzip($y, false, 0777);
$temp_array = array("preview.xml", $preview_xml, null);
array_push($file_data, $temp_array);
}
$y = $x['file_name'];
if ($y === $template_data_equivalent || $y === "template.xml") {
$data_xml = $zip->unzip($y, false, 0777);
$temp_array = array("data.xml", $data_xml, null);
array_push($file_data, $temp_array);
} else if ($y === "preview.xml") {
$preview_xml = $zip->unzip($y, false, 0777);
$temp_array = array("preview.xml", $preview_xml, null);
array_push($file_data, $temp_array);
}
}

Expand Down

0 comments on commit 4c6fb70

Please sign in to comment.