Magento 1.5 "Invalid entity model" error on export

Article ID #1091
Revision: 1.7
Last update: 2011-10-16

 

Symptoms

On attempt to run export profile in Magento 1.5 the following error message is througn:

"Invalid entity model"

 

Cause

The reason is that in Magento 1.5 version it is changed how Magento handles temporary directories on export, it is trying to use /tmp directory on host ultimately and it is not allowed in most shared environments.

 

Solution

To make Magento use correct temporary directory defined for your installation the following patches can be applied:

  • app/code/core/Mage/Core/functions.php file:
@@ -354,23 +354,26 @@
     // article/creating-zip-tar-archives-dynamically-php/2/

-    function sys_get_temp_dir()
+  function sys_get_temp_dir() {
+      if( $temp=getenv('TMP') )        return $temp;
+      if( $temp=getenv('TEMP') )        return $temp;
+      if( $temp=getenv('TMPDIR') )    return $temp;
+      $temp=tempnam(__FILE__,'');
+      if (file_exists($temp)) {
+          unlink($temp);
+          return dirname($temp);
+      }
+      return FALSE;
+  }
+}
+if ( !function_exists('virt_sys_get_temp_dir') ) {
+    function virt_sys_get_temp_dir()
     {
-        // Try to get from environment variable
-        if ( !empty($_ENV['TMP']) ) {
-            return realpath( $_ENV['TMP'] );
-        } else if ( !empty($_ENV['TMPDIR']) ) {
-            return realpath( $_ENV['TMPDIR'] );
-        } else if ( !empty($_ENV['TEMP']) ) {
-            return realpath( $_ENV['TEMP'] );
-        } else {
-            // Try to use system's temporary directory
-            // as random name shouldn't exist
-            $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
-            if ( $temp_file ) {
-                $temp_dir = realpath( dirname($temp_file) );
-                unlink( $temp_file );
-                return $temp_dir;
-            } else {
-                return FALSE;
-            }
-        }
+      if( $temp=getenv('TMP') )        return $temp;
+      if( $temp=getenv('TEMP') )        return $temp;
+      if( $temp=getenv('TMPDIR') )    return $temp;
+      $temp=tempnam(__FILE__,'');
+      if (file_exists($temp)) {
+          unlink($temp);
+          return dirname($temp);
+      }
+      return FALSE;
     }



  • app/code/core/Mage/ImportExport/Model/Export/Adapter/Abstract.php file:
@@ -59,3 +59,3 @@
         if (!$destination) {
-            $destination = tempnam(sys_get_temp_dir(), 'importexport_');
+            $destination = tempnam(virt_sys_get_temp_dir(), 'importexport_');
         }

 

 

Such patch has been applied already on new Magenting installations.

 

To apply the patch on your installation you need to edit these files adding lines marked with "+" sign and remove lines marked with "-" sign. Or you can replace the files with patched version:

Did this article help you solve your issue?


Average rating: 3.65 (23 votes)

completely useless 1 2 3 4 5 most valuable

Tags: