Merge branch 'pu/2013.10-icsimport'
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 11 Sep 2014 10:07:54 +0000 (12:07 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 11 Sep 2014 10:07:54 +0000 (12:07 +0200)
tine20/Calendar/js/ImportDialog.js
tine20/Tinebase/Controller/ScheduledImport.php
tine20/Tinebase/Model/Import.php

index 3f472e5..2fa565d 100644 (file)
@@ -103,6 +103,14 @@ Tine.Calendar.ImportDialog = Ext.extend(Tine.widgets.dialog.ImportDialog, {
                 title: that.app.i18n._('Import Definition Success!'),
                 msg: that.app.i18n._('The Ical Import definition has been created successfully! Please wait some minutes to get the events synced.')
             });
+            
+            var wp = this.app.mainScreen.getWestPanel(),
+                tp = wp.getContainerTreePanel(),
+                state = wp.getState();
+                
+            tp.getLoader().load(tp.getRootNode());
+            wp.applyState(state);
+            
         } else {
             Tine.Tinebase.ExceptionHandler.handleRequestException(response, callback, that);
         }
@@ -223,7 +231,7 @@ Tine.Calendar.ImportDialog = Ext.extend(Tine.widgets.dialog.ImportDialog, {
                     id: this.app.appName + 'ContainerName',
                     xtype: 'textfield',
                     ref: '../../../containerField',
-                    disabled: true,
+                    disabled: false,
                     enableKeyEvents: true,
                     listeners: {
                         scope: this,
index a9eb77b..26825ea 100644 (file)
@@ -58,11 +58,13 @@ class Tinebase_Controller_ScheduledImport extends Tinebase_Controller_Record_Abs
     
     /**
      * Search and executed the next scheduled import
+     * 
+     * @return null|array
      */
     public function runNextScheduledImport()
     {
         if ($record = $this->_getNextScheduledImport()) {
-            return $this->_doScheduledImport($record);
+            return $this->_doScheduledImport($record)->toArray();
         }
         
         return NULL;
@@ -94,7 +96,7 @@ class Tinebase_Controller_ScheduledImport extends Tinebase_Controller_Record_Abs
         
         $filter0 = new Tinebase_Model_ImportFilter(array(
                 array('field' => 'interval', 'operator' => 'equals', 'value' => Tinebase_Model_Import::INTERVAL_ONCE),
-                array('field' => 'timestamp', 'operator' => 'before', 'value' => $now),
+                array('field' => 'timestamp', 'operator' => 'isnull', 'value' => null),
         ), 'AND');
         
         $filter1 = new Tinebase_Model_ImportFilter(array(
@@ -141,8 +143,13 @@ class Tinebase_Controller_ScheduledImport extends Tinebase_Controller_Record_Abs
      * @param Tinebase_Model_Import $record
      * @return Tinebase_Model_Import
      */
-    protected function _doScheduledImport(Tinebase_Model_Import $record = NULL)
+    protected function _doScheduledImport(Tinebase_Model_Import $record)
     {
+        $currentUser = Tinebase_Core::getUser();
+        // set user who created the import job
+        $importUser = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $record->user_id, 'Tinebase_Model_FullUser');
+        Tinebase_Core::set(Tinebase_Core::USER, $importUser);
+        
         $importer = $record->getOption('plugin');
         
         $options = array(
@@ -157,7 +164,6 @@ class Tinebase_Controller_ScheduledImport extends Tinebase_Controller_Record_Abs
         } else {
             $toImport = file_get_contents($record->source);
         }
-
         
         $importer = new $importer($options);
         
@@ -190,6 +196,8 @@ class Tinebase_Controller_ScheduledImport extends Tinebase_Controller_Record_Abs
             }
         }
         
+        Tinebase_Core::set(Tinebase_Core::USER, $currentUser);
+        
         return $record;
     }
     
index 3961338..f64c2db 100644 (file)
@@ -75,7 +75,7 @@ class Tinebase_Model_Import extends Tinebase_Record_Abstract
      */
     protected $_validators = array(
         'id'                    => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => NULL),
-        'timestamp'          => array('allowEmpty' => false),
+        'timestamp'          => array('allowEmpty' => true),
         'user_id'            => array('presence' => 'required'),
         'model'              => array('presence' => 'required'),
         'application_id'     => array('presence' => 'required'),
@@ -147,30 +147,29 @@ class Tinebase_Model_Import extends Tinebase_Record_Abstract
      *
      * @param array $_data            the new data to set
      * @throws Tinebase_Exception_Record_Validation when content contains invalid or missing data
-     *
-     * @todo remove custom fields handling (use Tinebase_Record_RecordSet for them)
      */
     public function setFromArray(array $_data)
     {
         parent::setFromArray($_data);
-        $now = Tinebase_DateTime::now();
+        $timestamp = Tinebase_DateTime::now();
         
         // set timestamp according to interval, if it is not set
         if (! isset($_data['timestamp'])) {
             switch ($_data['interval']) {
                 case Tinebase_Model_Import::INTERVAL_DAILY:
-                    $now->subDay(1)->subSecond(1);
+                    $timestamp->subDay(1)->subSecond(1);
                     break;
                 case Tinebase_Model_Import::INTERVAL_WEEKLY:
-                    $now->subWeek(1)->subSecond(1);
+                    $timestamp->subWeek(1)->subSecond(1);
                     break;
                 case Tinebase_Model_Import::INTERVAL_HOURLY:
-                    $now->subHour(1)->subSecond(1);
+                    $timestamp->subHour(1)->subSecond(1);
                     break;
                 default:
+                    $timestamp = null;
             }
             
-            $this->timestamp = $now;
+            $this->timestamp = $timestamp;
         }
     }
 }