0010850: Calendar application gets disabled continuously
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 27 Feb 2015 12:02:03 +0000 (13:02 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 25 Mar 2015 19:04:14 +0000 (20:04 +0100)
* catches import definition read exceptions to prevent app deactivation
* removes temp file handling, just use xml string when transforming
options to Zend_Config_Xml

https://forge.tine20.org/view.php?id=10850

Change-Id: I478301a4fbb16401141bc08d76595f54cc5c2c7c
Reviewed-on: https://gerrit.tine20.org/tine20/3059
Tested-by: jenkins user
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Calendar/Frontend/Json.php
tine20/Tinebase/ImportExportDefinition.php

index 8badcda..26bc770 100644 (file)
@@ -117,17 +117,12 @@ class Calendar_Frontend_Json extends Tinebase_Frontend_Json_Abstract
             $defaultCalendarArray = array();
         }
         
-        $definitionConverter = new Tinebase_Convert_ImportExportDefinition_Json();
         $importDefinitions = $this->_getImportDefinitions();
-        $defaultDefinition = $this->_getDefaultImportDefinition($importDefinitions);
         
         $registryData = array(
             'defaultContainer'          => $defaultCalendarArray,
-            'defaultImportDefinition'   => ($defaultDefinition) ? $definitionConverter->fromTine20Model($defaultDefinition) : array(),
-            'importDefinitions'         => array(
-                'results'               => $definitionConverter->fromTine20RecordSet($importDefinitions),
-                'totalcount'            => count($importDefinitions),
-            ),
+            'defaultImportDefinition'   => $importDefinitions['default'],
+            'importDefinitions'         => $importDefinitions
         );
         
         return $registryData;
@@ -212,7 +207,7 @@ class Calendar_Frontend_Json extends Tinebase_Frontend_Json_Abstract
     /**
      * get addressbook import definitions
      * 
-     * @return Tinebase_Record_RecordSet
+     * @return array
      * 
      * @todo generalize this
      */
@@ -223,9 +218,28 @@ class Calendar_Frontend_Json extends Tinebase_Frontend_Json_Abstract
             array('field' => 'type',            'operator' => 'equals', 'value' => 'import'),
         ));
         
-        $importDefinitions = Tinebase_ImportExportDefinition::getInstance()->search($filter);
+        $definitionConverter = new Tinebase_Convert_ImportExportDefinition_Json();
+        
+        try {
+            $importDefinitions = Tinebase_ImportExportDefinition::getInstance()->search($filter);
+            $defaultDefinition = $this->_getDefaultImportDefinition($importDefinitions);
+            $result = array(
+                'results'               => $definitionConverter->fromTine20RecordSet($importDefinitions),
+                'totalcount'            => count($importDefinitions),
+                'default'               => ($defaultDefinition) ? $definitionConverter->fromTine20Model($defaultDefinition) : array(),
+            );
+        } catch (Exception $e) {
+            Tinebase_Exception::log($zce);
+            $result = array(
+                array(
+                    'results'               => array(),
+                    'totalcount'            => 0,
+                    'default'               => array(),
+                )
+            );
+        }
         
-        return $importDefinitions;
+        return $result;
     }
     
     /**
index d844174..68f7927 100644 (file)
@@ -144,20 +144,8 @@ class Tinebase_ImportExportDefinition extends Tinebase_Controller_Record_Abstrac
         if (! $cache->test($cacheId)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ 
                 . ' Generate new Zend_Config_Xml object' . $cacheId);
-            $tmpfname = tempnam(Tinebase_Core::getTempDir(), "tine_tempfile_");
-            
-            if (! $tmpfname) {
-                throw new Tinebase_Exception_AccessDenied('Could not create temporary file.');
-            }
-            
-            $handle = fopen($tmpfname, "w");
-            fwrite($handle, $_definition->plugin_options);
-            fclose($handle);
-            
-            // read file with Zend_Config_Xml
-            $config = new Zend_Config_Xml($tmpfname, null, true);
-            unlink($tmpfname);
             
+            $config = new Zend_Config_Xml($_definition->plugin_options, /* section = */ null, /* runtime mods allowed = */ true);
             $cache->save($config, $cacheId);
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__