Exemple #1
0
 /**
  * convert plugin_options to array
  * 
  * @param Tinebase_Model_ImportExportDefinition $_definition
  */
 protected function _convertOptions(Tinebase_Model_ImportExportDefinition $_definition)
 {
     $options = empty($_definition->plugin_options) ? array() : Tinebase_ImportExportDefinition::getOptionsAsZendConfigXml($_definition)->toArray();
     if (isset($options['autotags'])) {
         $options['autotags'] = $this->_handleAutotags($options['autotags']);
     }
     if (isset($options['container_id'])) {
         $options['container_id'] = Tinebase_Container::getInstance()->getContainerById($options['container_id'])->toArray();
     }
     $_definition->plugin_options = $options;
 }
 /**
  * import helper
  *
  * @param array $additionalOptions
  * @param array $clientRecords
  * @param string $filename
  * @return array
  */
 protected function _importHelper($additionalOptions = array('dryrun' => 1), $clientRecords = array(), $filename = NULL)
 {
     $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('adb_tine_import_csv');
     $definitionOptions = Tinebase_ImportExportDefinition::getOptionsAsZendConfigXml($definition);
     $tempFileBackend = new Tinebase_TempFile();
     $importFile = $filename ? $filename : dirname(dirname(dirname(dirname(__FILE__)))) . '/tine20/' . $definitionOptions->example;
     $tempFile = $tempFileBackend->createTempFile($importFile);
     $options = array_merge($additionalOptions, array('container_id' => $this->container->getId()));
     $result = $this->_uit->importContacts($tempFile->getId(), $definition->getId(), $options, $clientRecords);
     if (isset($additionalOptions['dryrun']) && $additionalOptions['dryrun'] === 0) {
         foreach ($result['results'] as $contact) {
             $this->_contactIdsToDelete[] = $contact['id'];
         }
     }
     return $result;
 }
 /**
  * returns config from definition
  * 
  * @param Tinebase_Model_ImportExportDefinition $_definition
  * @param array                                 $_options
  * @return array
  */
 public static function getOptionsArrayFromDefinition($_definition, $_options)
 {
     $options = Tinebase_ImportExportDefinition::getOptionsAsZendConfigXml($_definition, $_options);
     $optionsArray = $options->toArray();
     if (!isset($optionsArray['model'])) {
         $optionsArray['model'] = $_definition->model;
     }
     return $optionsArray;
 }
 /**
  * testImportWithTags
  */
 public function testImportWithTags()
 {
     $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('adb_tine_import_csv');
     $definitionOptions = Tinebase_ImportExportDefinition::getOptionsAsZendConfigXml($definition);
     $options = array('dryrun' => 0, 'autotags' => array(array('name' => 'Importliste (19.10.2011)', 'description' => 'Kontakte der Importliste vom 19.10.2011 um 20.00 Uhr. Bearbeiter: UNITTEST', 'contexts' => array('Addressbook' => ''), 'type' => Tinebase_Model_Tag::TYPE_SHARED)));
     $result = $this->_importHelper($options);
     $fritz = $result['results'][1];
     $this->assertEquals(2, count($result['results']), 'should import 2');
     $this->assertEquals(1, count($result['results'][0]['tags']), 'no tag added');
     $this->assertEquals('Importliste (19.10.2011)', $result['results'][0]['tags'][0]['name']);
     $fritz['tags'] = array(array('name' => 'supi', 'type' => Tinebase_Model_Tag::TYPE_PERSONAL));
     $fritz = $this->_instance->saveContact($fritz);
     //print_r($fritz);
     // once again for duplicates (check if client record has tag)
     $result = $this->_importHelper($options);
     //print_r($result);
     $this->assertEquals(2, count($result['exceptions']), 'should have 2 duplicates');
     $this->assertEquals(1, count($result['exceptions'][0]['exception']['clientRecord']['tags']), 'no tag added');
     $this->assertEquals('Importliste (19.10.2011)', $result['exceptions'][0]['exception']['clientRecord']['tags'][0]['name']);
     $fritzClient = $result['exceptions'][1]['exception']['duplicates'][0];
     // emulate client merge behaviour
     $fritzClient['tags'][] = $result['exceptions'][1]['exception']['clientRecord']['tags'][0];
     $fritzClient['adr_one_locality'] = '';
     $clientRecords = array(array('recordData' => $fritzClient, 'resolveStrategy' => 'mergeMine', 'index' => 1));
     //print_r($clientRecords);
     $result = $this->_importHelper(array('dryrun' => 0), $clientRecords);
     $this->assertEquals(1, $result['totalcount'], 'Should merge fritz: ' . print_r($result['exceptions'], TRUE));
     $this->assertEquals(2, count($result['results'][0]['tags']), 'Should merge tags');
     $this->assertEquals(NULL, $result['results'][0]['adr_one_locality'], 'Should remove locality');
 }