Ejemplo n.º 1
0
 /**
  * get export object for given filter and format
  * 
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param string|array $_options format (as string) or export definition id (array)
  * @param Tinebase_Controller_Record_Interface $_controller (optional)
  * @param array $_additionalOptions (optional)
  * @return Tinebase_Export_Abstract
  * @throws Tinebase_Exception_NotFound
  */
 public static function factory($_filter, $_options, $_controller = NULL, $_additionalOptions = array())
 {
     if (!is_array($_options)) {
         $_options = array('format' => $_options);
     }
     if (array_key_exists('definitionId', $_options)) {
         $definition = Tinebase_ImportExportDefinition::getInstance()->get($_options['definitionId']);
         $exportClass = $definition->plugin;
         // export plugin needs the definition id
         $_additionalOptions = array_merge($_additionalOptions, $_options);
     } else {
         if (array_key_exists('format', $_options) && !empty($_options['format'])) {
             $appName = $_filter->getApplicationName();
             $model = $_filter->getModelName();
             $exportClass = $appName . '_Export_' . ucfirst(strtolower($_options['format']));
             if (!@class_exists($exportClass)) {
                 // check for model specific export class
                 list($a, $b, $modelPart) = explode('_', $model);
                 $exportClass = $exportClass . '_' . $modelPart;
                 if (!@class_exists($exportClass)) {
                     throw new Tinebase_Exception_NotFound('No ' . $_options['format'] . ' export class found for ' . $appName . ' / ' . $model);
                 }
             }
         } else {
             throw new Tinebase_Exception_InvalidArgument('Export definition ID or format required in options');
         }
     }
     if (preg_match('/pdf/i', $exportClass)) {
         // legacy
         $result = new $exportClass($_additionalOptions);
     } else {
         $result = new $exportClass($_filter, $_controller, $_additionalOptions);
     }
     return $result;
 }
 /**
  * update to 6.1
  * - remove fritzbox export
  * 
  * @see 0006948: Export a contact as adb_fritzbox
  */
 public function update_0()
 {
     try {
         $fritzex = Tinebase_ImportExportDefinition::getInstance()->getByName('adb_fritzbox');
         Tinebase_ImportExportDefinition::getInstance()->delete($fritzex->getId());
     } catch (Tinebase_Exception_NotFound $tenf) {
         // does not exist
     }
     $this->setApplicationVersion('Addressbook', '6.1');
 }
Ejemplo n.º 3
0
 /**
  * try to export Timesheets (as ods) with definition id
  */
 public function testExportTimesheetsOdsWithDefId()
 {
     $definitions = Tinebase_ImportExportDefinition::getInstance()->getExportDefinitionsForApplication(Tinebase_Application::getInstance()->getApplicationByName('Timetracker'));
     $defId = '';
     foreach ($definitions as $definition) {
         if ($definition->plugin == 'Timetracker_Export_Ods_Timesheet') {
             $defId = $definition->getId();
         }
     }
     $this->_exportTsOds($defId);
 }
 public function testExportLetter()
 {
     // make sure definition is imported
     $definitionFile = __DIR__ . '/../../../../tine20/Addressbook/Export/definitions/adb_default_doc.xml';
     $app = Tinebase_Application::getInstance()->getApplicationByName('Addressbook');
     Tinebase_ImportExportDefinition::getInstance()->updateOrCreateFromFilename($definitionFile, $app);
     $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'n_given', 'operator' => 'equals', 'value' => 'James')));
     $doc = new Addressbook_Export_Doc($filter);
     $doc->generate();
     $tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.docx';
     $doc->save($tempfile);
     $this->assertGreaterThan(0, filesize($tempfile));
 }
Ejemplo n.º 5
0
 /**
  * test import data
  */
 public function testImport()
 {
     $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('adb_import_vcard');
     $this->_instance = Addressbook_Import_VCard::createFromDefinition($definition, array('dryrun' => TRUE));
     $result = $this->_instance->importFile($this->_filename);
     //print_r($result['results']->getFirstRecord()->toArray());
     $this->assertEquals(2, $result['totalcount'], 'Didn\'t import anything.');
     $this->assertEquals('spass, alex', $result['results']->getFirstRecord()->n_fileas, 'file as not found');
     $this->assertEquals('+49732121258035', $result['results']->getFirstRecord()->tel_home, 'n_fileas not found');
     $this->assertEquals('mitbewohner', $result['results']->getFirstRecord()->note, 'note not found');
     $this->assertEquals('Eisenhüttenstraße 723', $result['results']->getFirstRecord()->adr_one_street, 'street not found');
     $this->assertEquals('http://www.vcard.de', $result['results']->getFirstRecord()->url, 'url not found');
 }
 /**
  * get default definition
  *
  * @param Tinebase_Record_RecordSet $_importDefinitions
  * @return Tinebase_Model_ImportExportDefinition
  *
  * @todo generalize this
  */
 protected function _getDefaultImportDefinition($_importDefinitions)
 {
     try {
         $defaultDefinition = Tinebase_ImportExportDefinition::getInstance()->getByName('inv_tine_import_csv');
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (count($_importDefinitions) > 0) {
             $defaultDefinition = $_importDefinitions->getFirstRecord();
         } else {
             $defaultDefinition = NULL;
         }
     }
     return $defaultDefinition;
 }
 /**
  * get export object for given filter and format
  * 
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param string|array $_options format (as string) or export definition id (array)
  * @param Tinebase_Controller_Record_Interface $_controller (optional)
  * @param array $_additionalOptions (optional)
  * @return Tinebase_Export_Abstract
  * @throws Tinebase_Exception_NotFound
  */
 public static function factory($_filter, $_options, $_controller = NULL, $_additionalOptions = array())
 {
     if (!is_array($_options)) {
         $_options = array('format' => $_options);
     }
     // always merge options? this needs to be refactored!
     $_additionalOptions = array_merge($_additionalOptions, $_options);
     if (isset($_options['definitionId']) || array_key_exists('definitionId', $_options)) {
         $definition = Tinebase_ImportExportDefinition::getInstance()->get($_options['definitionId']);
         $exportClass = $definition->plugin;
     } else {
         if ((isset($_options['format']) || array_key_exists('format', $_options)) && !empty($_options['format'])) {
             $appName = $_filter->getApplicationName();
             $model = $_filter->getModelName();
             $exportClass = $appName . '_Export_' . ucfirst(strtolower($_options['format']));
             // start output buffering to catch errors, append them to log and exception
             ob_start();
             if (!class_exists($exportClass)) {
                 $ob = ob_get_length() > 0 ? ob_get_clean() : '';
                 // check for model specific export class
                 list($a, $b, $modelPart) = explode('_', $model);
                 $exportClass2 = $exportClass . '_' . $modelPart;
                 if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                     Tinebase_Core::getLogger()->log(__METHOD__ . '::' . __LINE__ . ' Could not find class ' . $exportClass . ' trying ' . $exportClass2 . '. Output Buffer: ' . PHP_EOL . $ob, Zend_Log::NOTICE);
                 }
                 if (!class_exists($exportClass2)) {
                     $ob = ob_get_length() > 0 ? ob_get_clean() : NULL;
                     ob_end_flush();
                     throw new Tinebase_Exception_NotFound('No ' . $_options['format'] . ' export class found for ' . $appName . ' / ' . $model . '. ClassName: ' . $exportClass2 . ($ob ? 'Output: ' . $ob : ''));
                 } else {
                     $exportClass = $exportClass2;
                 }
             }
             ob_end_flush();
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Export options: ' . print_r($_options, TRUE));
             }
             throw new Tinebase_Exception_InvalidArgument('Export definition ID or format required in options');
         }
     }
     if (preg_match('/pdf/i', $exportClass)) {
         // legacy
         $result = new $exportClass($_additionalOptions);
     } else {
         $result = new $exportClass($_filter, $_controller, $_additionalOptions);
     }
     return $result;
 }
 /**
  * import helper
  *
  * @param array $_options
  * @param string|Tinebase_Model_ImportExportDefinition $_definition
  * @param Tinebase_Model_Filter_FilterGroup $_exportFilter
  * @throws Tinebase_Exception_NotFound
  * @return array
  */
 protected function _doImport(array $_options, $_definition, Tinebase_Model_Filter_FilterGroup $_exportFilter = NULL)
 {
     if (!$this->_importerClassName || !$this->_modelName) {
         throw new Tinebase_Exception_NotFound('No import class or model name given');
     }
     $definition = $_definition instanceof Tinebase_Model_ImportExportDefinition ? $_definition : Tinebase_ImportExportDefinition::getInstance()->getByName($_definition);
     $this->_instance = call_user_func_array($this->_importerClassName . '::createFromDefinition', array($definition, $_options));
     // export first
     if ($_exportFilter !== NULL && $this->_exporterClassName) {
         $exporter = new $this->_exporterClassName($_exportFilter, Tinebase_Core::getApplicationInstance($this->_modelName));
         $this->_filename = $exporter->generate();
     }
     // then import
     $result = $this->_instance->importFile($this->_filename);
     return $result;
 }
 public function testExportSimpleDocSheet()
 {
     // skip tests for php7
     // ERROR: PHP Fatal error:  Cannot use PhpOffice\PhpWord\Shared\String as String because 'String' is a special
     //  class name in /usr/local/share/tine20.git/tine20/vendor/phpoffice/phpword/src/PhpWord/TemplateProcessor.php
     //  on line 23
     if (PHP_VERSION_ID >= 70000) {
         $this->markTestSkipped('FIXME 0011730: fix doc export for php7');
     }
     // make sure definition is imported
     $definitionFile = __DIR__ . '/../../../../tine20/Calendar/Export/definitions/cal_default_doc_sheet.xml';
     $calendarApp = Tinebase_Application::getInstance()->getApplicationByName('Calendar');
     Tinebase_ImportExportDefinition::getInstance()->updateOrCreateFromFilename($definitionFile, $calendarApp, 'cal_default_doc_sheet');
     //        Tinebase_TransactionManager::getInstance()->commitTransaction($this->_transactionId);
     // @TODO have some demodata to export here
     $filter = new Calendar_Model_EventFilter(array());
     $doc = new Calendar_Export_DocSheet($filter);
     $doc->generate();
     $tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.docx';
     $doc->save($tempfile);
     $this->assertGreaterThan(0, filesize($tempfile));
     //        `open $tempfile`;
 }
 /**
  * returns import definition from file
  * 
  * @param string $filename
  * @return Tinebase_Model_ImportExportDefinition
  */
 protected function _getDefinitionFromFile($filename, $path = null)
 {
     $filename = ($path ? $path : dirname(__FILE__) . '/files/') . $filename;
     $applicationId = Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId();
     $definition = Tinebase_ImportExportDefinition::getInstance()->getFromFile($filename, $applicationId);
     return $definition;
 }
Ejemplo n.º 11
0
 /**
  * import course members
  *
  * @param string $tempFileId
  * @param string $groupId
  * @param string $courseName
  * 
  * @todo write test!!
  */
 public function importMembers($tempFileId, $groupId, $courseId)
 {
     $tempFile = Tinebase_TempFile::getInstance()->getTempFile($tempFileId);
     $course = $this->_controller->get($courseId);
     $schoolName = strtolower(Tinebase_Department::getInstance()->get($course->type)->name);
     // get definition and start import with admin user import csv plugin
     $definitionName = $this->_config->get('import_definition', 'admin_user_import_csv');
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Using import definition: ' . $definitionName);
     }
     $definition = Tinebase_ImportExportDefinition::getInstance()->getByName($definitionName);
     $importer = Admin_Import_Csv::createFromDefinition($definition, array('group_id' => $groupId, 'accountEmailDomain' => isset($this->_config->domain) ? $this->_config->domain : '', 'accountHomeDirectoryPrefix' => isset($this->_config->basehomedir) ? $this->_config->basehomedir . $schoolName . '/' . $course->name . '/' : '', 'password' => strtolower($course->name), 'course' => $course, 'samba' => isset($this->_config->samba) ? array('homePath' => $this->_config->samba->basehomepath, 'homeDrive' => $this->_config->samba->homedrive, 'logonScript' => $course->name . $this->_config->samba->logonscript_postfix_member, 'profilePath' => $this->_config->samba->baseprofilepath . $schoolName . '\\' . $course->name . '\\', 'pwdCanChange' => new Tinebase_DateTime('@1'), 'pwdMustChange' => new Tinebase_DateTime('@1')) : array()));
     $importer->importFile($tempFile->path);
     // return members to update members grid and add to student group
     $members = $this->_getCourseMembers($groupId);
     // add to student group if available
     if (isset($this->_config->students_group) && !empty($this->_config->students_group)) {
         $groupController = Admin_Controller_Group::getInstance();
         foreach ($members as $member) {
             $groupController->addGroupMember($this->_config->students_group, $member['id']);
         }
     }
     return array('results' => $members, 'status' => 'success');
 }
 /**
  * repair a table
  * 
  * @param Zend_Console_Getopt $opts
  * 
  * @todo add more tables
  */
 public function repairTable($opts)
 {
     if (!$this->_checkAdminRight()) {
         return FALSE;
     }
     $this->_addOutputLogWriter();
     $data = $this->_parseArgs($opts, array('table'));
     switch ($data['table']) {
         case 'importexport_definition':
             Tinebase_ImportExportDefinition::getInstance()->repairTable();
             $result = 0;
             break;
         default:
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' No repair script found for ' . $data['table']);
             }
             $result = 1;
     }
     exit($result);
 }
 /**
  * get default definition
  *
  * @param Tinebase_Record_RecordSet $_importDefinitions
  * @return Tinebase_Model_ImportExportDefinition
  */
 protected function _getDefaultImportDefinition($_importDefinitions)
 {
     try {
         $defaultName = $this->_defaultImportDefinitionName ? $this->_defaultImportDefinitionName : strtolower($this->_applicationName . '_tine_import_csv');
         $defaultDefinition = Tinebase_ImportExportDefinition::getInstance()->getByName($defaultName);
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (count($_importDefinitions) > 0) {
             $defaultDefinition = $_importDefinitions->getFirstRecord();
         } else {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' No import definitions found for ' . $this->_applicationName);
             $defaultDefinition = NULL;
         }
     }
     return $defaultDefinition;
 }
Ejemplo n.º 14
0
 /**
  * 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');
 }
 /**
  * import course members
  *
  * @param string $tempFileId
  * @param string $courseId
  * @return array
  */
 public function importMembers($tempFileId, $courseId)
 {
     $this->checkRight(Courses_Acl_Rights::ADD_NEW_USER);
     $tempFile = Tinebase_TempFile::getInstance()->getTempFile($tempFileId);
     // get definition and start import with admin user import csv plugin
     $definitionName = $this->_config->get(Courses_Config::STUDENTS_IMPORT_DEFINITION, 'admin_user_import_csv');
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Using import definition: ' . $definitionName);
     }
     $definition = Tinebase_ImportExportDefinition::getInstance()->getByName($definitionName);
     $course = $this->get($courseId);
     // check if group exists, too
     $group = $this->_groupController->get($course->group_id);
     $importer = Admin_Import_User_Csv::createFromDefinition($definition, $this->_getNewUserConfig($course));
     $result = $importer->importFile($tempFile->path);
     $groupMembers = $this->_groupController->getGroupMembers($course->group_id);
     $this->_manageAccessGroups($groupMembers, $course);
     $this->_addToStudentGroup($groupMembers);
     $this->_addToUserDefaultGroup($groupMembers);
     return $result;
 }
 /**
  * get special options
  *
  * @param string $_value
  * @return array
  */
 protected function _getSpecialOptions($_value)
 {
     $translate = Tinebase_Translation::getTranslation($this->_application);
     $result = array();
     switch ($_value) {
         case self::TSODSEXPORTCONFIG:
             // get names from import export definitions
             $filter = new Tinebase_Model_ImportExportDefinitionFilter(array(array('field' => 'plugin', 'operator' => 'equals', 'value' => 'Timetracker_Export_Ods_Timesheet')));
             $configs = Tinebase_ImportExportDefinition::getInstance()->search($filter);
             if (!empty($configs)) {
                 foreach ($configs as $tsConfig) {
                     $result[] = array($tsConfig->name, $tsConfig->name);
                 }
             } else {
                 $result[] = array('default', $translate->_('default'));
             }
             break;
         case self::QUICKTAG:
             // Get all shared tags
             $tagController = Tinebase_Tags::getInstance();
             $filter = new Tinebase_Model_TagFilter(array('type' => Tinebase_Model_Tag::TYPE_SHARED));
             $tags = $tagController->searchTags($filter);
             $availableTags = array();
             /* @var $tag Tinebase_Model_Tag */
             foreach ($tags as $tag) {
                 $availableTags[] = array($tag->id, $tag->name);
             }
             return $availableTags;
             break;
         default:
             $result = parent::_getSpecialOptions($_value);
     }
     return $result;
 }
 /**
  * returns course import definition
  * 
  * @param string $encoding
  * @return Tinebase_Model_ImportExportDefinition
  */
 protected function _getCourseImportDefinition3($encoding = 'UTF-8')
 {
     try {
         $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('course_user_import_csv');
     } catch (Tinebase_Exception_NotFound $e) {
         $definition = Tinebase_ImportExportDefinition::getInstance()->create(new Tinebase_Model_ImportExportDefinition(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Admin')->getId(), 'name' => 'course_user_import_csv', 'type' => 'import', 'model' => 'Tinebase_Model_FullUser', 'plugin' => 'Admin_Import_User_Csv', 'plugin_options' => '<?xml version="1.0" encoding="UTF-8"?>
         <config>
             <headline>1</headline>
             <use_headline>0</use_headline>
             <dryrun>0</dryrun>
             <encoding>' . $encoding . '</encoding>
             <delimiter>;</delimiter>
             <mapping>
                 <field>
                     <source>Name</source>
                     <destination>accountLastName</destination>
                 </field>
                 <field>
                     <source>Vorname</source>
                     <destination>accountFirstName</destination>
                 </field>
             </mapping>
         </config>')));
     }
     return $definition;
 }
Ejemplo n.º 18
0
 /**
  * get export config
  *
  * @param array $_additionalOptions additional options
  * @return Zend_Config_Xml
  * @throws Tinebase_Exception_NotFound
  */
 protected function _getExportConfig($_additionalOptions = array())
 {
     if (array_key_exists('definitionFilename', $_additionalOptions)) {
         // get definition from file
         $definition = Tinebase_ImportExportDefinition::getInstance()->getFromFile($_additionalOptions['definitionFilename'], Tinebase_Application::getInstance()->getApplicationByName($this->_applicationName)->getId());
     } else {
         if (array_key_exists('definitionId', $_additionalOptions)) {
             $definition = Tinebase_ImportExportDefinition::getInstance()->get($_additionalOptions['definitionId']);
         } else {
             // get preference from db and set export definition name
             $exportName = $this->_defaultExportname;
             if ($this->_prefKey !== NULL) {
                 $exportName = Tinebase_Core::getPreference($this->_applicationName)->getValue($this->_prefKey, $exportName);
             }
             // get export definition by name / model
             $filter = new Tinebase_Model_ImportExportDefinitionFilter(array(array('field' => 'model', 'operator' => 'equals', 'value' => $this->_modelName), array('field' => 'name', 'operator' => 'equals', 'value' => $exportName)));
             $definitions = Tinebase_ImportExportDefinition::getInstance()->search($filter);
             if (count($definitions) == 0) {
                 throw new Tinebase_Exception_NotFound('Export definition for model ' . $this->_modelName . ' not found.');
             }
             $definition = $definitions->getFirstRecord();
             if (!empty($definition->filename)) {
                 // check if file with plugin options exists and use that
                 $completeFilename = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . $this->_applicationName . DIRECTORY_SEPARATOR . 'Export' . DIRECTORY_SEPARATOR . 'definitions' . DIRECTORY_SEPARATOR . $definition->filename;
                 try {
                     $fileDefinition = Tinebase_ImportExportDefinition::getInstance()->getFromFile($completeFilename, Tinebase_Application::getInstance()->getApplicationByName($this->_applicationName)->getId());
                     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Using definition from file ' . $definition->filename);
                     $definition->plugin_options = $fileDefinition->plugin_options;
                 } catch (Tinebase_Exception_NotFound $tenf) {
                     Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $tenf->getMessage());
                 }
             }
         }
     }
     return Tinebase_ImportExportDefinition::getInstance()->getOptionsAsZendConfigXml($definition, $_additionalOptions);
 }
 /**
  * get special options
  *
  * @param string $_value
  * @return array
  */
 protected function _getSpecialOptions($_value)
 {
     $translate = Tinebase_Translation::getTranslation($this->_application);
     $result = array();
     switch ($_value) {
         case self::TSODSEXPORTCONFIG:
             // get names from import export definitions
             $filter = new Tinebase_Model_ImportExportDefinitionFilter(array(array('field' => 'plugin', 'operator' => 'equals', 'value' => 'Timetracker_Export_Ods_Timesheet')));
             $configs = Tinebase_ImportExportDefinition::getInstance()->search($filter);
             if (!empty($configs)) {
                 foreach ($configs as $tsConfig) {
                     $result[] = array($tsConfig->name, $tsConfig->name);
                 }
             } else {
                 $result[] = array('default', $translate->_('default'));
             }
             break;
         default:
             $result = parent::_getSpecialOptions($_value);
     }
     return $result;
 }
Ejemplo n.º 20
0
 /**
  * Returns registry data of addressbook.
  * @see Tinebase_Application_Json_Abstract
  * 
  * @return mixed array 'variable name' => 'data'
  */
 public function getRegistryData()
 {
     $filter = new Tinebase_Model_ImportExportDefinitionFilter(array(array('field' => 'plugin', 'operator' => 'equals', 'value' => 'Billing_Import_BankCsv')));
     $importDefinitions = Tinebase_ImportExportDefinition::getInstance()->search($filter);
     //print_r($importDefinitions);
     try {
         $defaultDefinitionArray = Tinebase_ImportExportDefinition::getInstance()->getByName('bank_import_csv')->toArray();
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (count($importDefinitions) > 0) {
             $defaultDefinitionArray = $importDefinitions->getFirstRecord()->toArray();
         } else {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' No import definitions found for Banks');
             $defaultDefinitionArray = array();
         }
     }
     $registryData = array('Order' => Billing_Controller_Order::getInstance()->getRegistryData(), 'StockLocation' => Billing_Controller_StockLocation::getInstance()->getRegistryData(), 'PaymentMethods' => $this->getPaymentMethodsAsSimpleArray(), 'Context' => $this->getContextsAsSimpleArray(), 'ArticleGroups' => Billing_Controller_ArticleGroup::getInstance()->getArticleGroupsAsSimpleArray(), 'DebitorGroups' => Billing_Controller_DebitorGroup::getInstance()->getDebitorGroupsAsSimpleArray(), 'ArticleSeriess' => Billing_Controller_ArticleSeries::getInstance()->getArticleSeriessAsSimpleArray(), 'AccountSystems' => Billing_Controller_AccountSystem::getInstance()->getAccountSystemsAsSimpleArray(), 'AccountClasss' => Billing_Controller_AccountClass::getInstance()->getAccountClasssAsSimpleArray(), 'defaultBankImportDefinition' => $defaultDefinitionArray, 'importDefinitions' => array('results' => $importDefinitions->toArray(), 'totalcount' => count($importDefinitions)));
     return $registryData;
 }
 /**
  * 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;
 }
 /**
  * import users
  *
  * @param string $_config xml config
  * 
  * @see 0008300: Import User via CLI don't import all fields
  */
 protected function _importUsers($_config, $_filename, $_definition)
 {
     // create definition / check if exists
     try {
         $definition = Tinebase_ImportExportDefinition::getInstance()->getByName($_definition);
         $definition->plugin_options = $_config;
     } catch (Tinebase_Exception_NotFound $e) {
         $definition = Tinebase_ImportExportDefinition::getInstance()->create(new Tinebase_Model_ImportExportDefinition(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Admin')->getId(), 'name' => $_definition, 'type' => 'import', 'model' => 'Tinebase_Model_FullUser', 'plugin' => 'Admin_Import_User_Csv', 'plugin_options' => $_config)));
     }
     $tempFilename = TestServer::replaceEmailDomainInFile($_filename);
     $opts = new Zend_Console_Getopt('abp:');
     $opts->setArguments(array($tempFilename, 'definition=' . $_definition));
     // start import (dry run)
     ob_start();
     $this->_cli->importUser($opts);
     $out = ob_get_clean();
     return $out;
 }
 /**
  * import records
  *
  * @param Zend_Console_Getopt   $_opts
  * @return array import result
  */
 protected function _import($_opts)
 {
     $args = $this->_parseArgs($_opts, array(), 'filename');
     if ($_opts->d) {
         $args['dryrun'] = 1;
         if ($_opts->v) {
             echo "Doing dry run.\n";
         }
     }
     if (isset($args['definition']) || array_key_exists('definition', $args)) {
         if (preg_match("/\\.xml/", $args['definition'])) {
             $definition = Tinebase_ImportExportDefinition::getInstance()->getFromFile($args['definition'], Tinebase_Application::getInstance()->getApplicationByName($this->_applicationName)->getId());
         } else {
             $definition = Tinebase_ImportExportDefinition::getInstance()->getByName($args['definition']);
         }
         // If old Admin Import plugin is given use the new one!
         if ($definition->plugin == 'Admin_Import_Csv') {
             $definition->plugin = 'Admin_Import_User_Csv';
         }
         $importer = call_user_func($definition->plugin . '::createFromDefinition', $definition, $args);
     } else {
         if (isset($args['plugin']) || array_key_exists('plugin', $args)) {
             $importer = new $args['plugin']($args);
         } else {
             echo "You need to define a plugin OR a definition at least! \n";
             exit;
         }
     }
     // loop files in argv
     $result = array();
     foreach ((array) $args['filename'] as $filename) {
         // read file
         if ($_opts->v) {
             echo "reading file {$filename} ...";
         }
         try {
             $result[$filename] = $importer->importFile($filename);
             if ($_opts->v) {
                 echo "done.\n";
             }
         } catch (Exception $e) {
             if ($_opts->v) {
                 echo "failed (" . $e->getMessage() . ").\n";
             } else {
                 echo $e->getMessage() . "\n";
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage());
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
             }
             continue;
         }
         echo "Imported " . $result[$filename]['totalcount'] . " records. Import failed for " . $result[$filename]['failcount'] . " records. \n";
         if (isset($result[$filename]['duplicatecount']) && !empty($result[$filename]['duplicatecount'])) {
             echo "Found " . $result[$filename]['duplicatecount'] . " duplicates.\n";
         }
         // import (check if dry run)
         if ($_opts->d && $_opts->v) {
             print_r($result[$filename]['results']->toArray());
             if ($result[$filename]['failcount'] > 0) {
                 print_r($result[$filename]['exceptions']->toArray());
             }
         }
     }
     return $result;
 }
Ejemplo n.º 24
0
 /**
  * import records
  *
  * @param string $_tempFileId to import
  * @param string $_importDefinitionId
  * @param array $_options additional import options
  * @param array $_clientRecordData
  * @return array
  * @throws Tinebase_Exception_NotFound
  */
 protected function _import($_tempFileId, $_importDefinitionId, $_options = array(), $_clientRecordData = array())
 {
     $definition = Tinebase_ImportExportDefinition::getInstance()->get($_importDefinitionId);
     $importer = call_user_func($definition->plugin . '::createFromDefinition', $definition, $_options);
     if (!is_object($importer)) {
         throw new Tinebase_Exception_NotFound('No importer found for ' . $definition->name);
     }
     // extend execution time to 30 minutes
     $oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(1800);
     $file = Tinebase_TempFile::getInstance()->getTempFile($_tempFileId);
     $importResult = $importer->importFile($file->path, $_clientRecordData);
     $importResult['results'] = $importResult['results']->toArray();
     $importResult['exceptions'] = $importResult['exceptions']->toArray();
     $importResult['status'] = 'success';
     // reset max execution time to old value
     Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime);
     return $importResult;
 }
Ejemplo n.º 25
0
 /**
  * get default definition
  * 
  * @param Tinebase_Record_RecordSet $_importDefinitions
  * @return Tinebase_Model_ImportExportDefinition
  * 
  * @todo generalize this
  */
 protected function _getDefaultImportDefinition($_importDefinitions)
 {
     try {
         $defaultDefinition = Tinebase_ImportExportDefinition::getInstance()->getByName('adb_tine_import_csv');
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (count($_importDefinitions) > 0) {
             $defaultDefinition = $_importDefinitions->getFirstRecord();
         } else {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' No import definitions found for Addressbook');
             $defaultDefinition = NULL;
         }
     }
     return $defaultDefinition;
 }
 /**
  * import helper
  *
  * @param array $_options
  * @param string|Tinebase_Model_ImportExportDefinition $_definition
  * @param Inventory_Model_InventoryItemFilter $_exportFilter
  * @return array
  */
 protected function _doImport(array $_options, $_definition, Inventory_Model_InventoryItemFilter $_exportFilter = NULL)
 {
     $definition = $_definition instanceof Tinebase_Model_ImportExportDefinition ? $_definition : Tinebase_ImportExportDefinition::getInstance()->getByName($_definition);
     $this->_instance = Inventory_Import_Csv::createFromDefinition($definition, $_options);
     // export first
     if ($_exportFilter !== NULL) {
         $exporter = new Inventory_Export_Csv($_exportFilter, Inventory_Controller_InventoryItem::getInstance());
         $this->_filename = $exporter->generate();
     }
     // then import
     $result = $this->_instance->importFile($this->_filename);
     return $result;
 }
 /**
  * Returns registry data of all applications current user has access to
  * @see Tinebase_Application_Json_Abstract
  *
  * @return mixed array 'variable name' => 'data'
  */
 public function getAllRegistryData()
 {
     $registryData = array();
     if (Tinebase_Core::getUser()) {
         $userApplications = Tinebase_Core::getUser()->getApplications(TRUE);
         $clientConfig = Tinebase_Config::getInstance()->getClientRegistryConfig();
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             /** @noinspection PhpUndefinedFieldInspection */
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' User applications to fetch registry for: ' . print_r($userApplications->name, TRUE));
         }
         /** @noinspection PhpUndefinedFieldInspection */
         if (!in_array('Tinebase', $userApplications->name)) {
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' User has no permissions to run Tinebase.');
             $this->logout();
             throw new Tinebase_Exception_AccessDenied('User has no permissions to run Tinebase');
         }
         foreach ($userApplications as $application) {
             $jsonAppName = $application->name . '_Frontend_Json';
             if (class_exists($jsonAppName)) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Getting registry data for app ' . $application->name);
                 }
                 try {
                     $applicationJson = new $jsonAppName();
                     $registryData[$application->name] = isset($registryData[$application->name]) || array_key_exists($application->name, $registryData) ? array_merge_recursive($registryData[$application->name], $applicationJson->getRegistryData()) : $applicationJson->getRegistryData();
                 } catch (Exception $e) {
                     Tinebase_Exception::log($e);
                     if (!$e instanceof Tinebase_Exception_AccessDenied && !in_array($application->name, array('Tinebase', 'Addressbook', 'Admin'))) {
                         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Disabling ' . $application->name . ': ' . $e);
                         Tinebase_Application::getInstance()->setApplicationState(array($application->getId()), Tinebase_Application::DISABLED);
                     }
                     unset($registryData[$application->name]);
                     continue;
                 }
                 $registryData[$application->name]['rights'] = Tinebase_Core::getUser()->getRights($application->name);
                 $registryData[$application->name]['config'] = isset($clientConfig[$application->name]) ? $clientConfig[$application->name]->toArray() : array();
                 $registryData[$application->name]['models'] = $applicationJson->getModelsConfiguration();
                 $registryData[$application->name]['defaultModel'] = $applicationJson->getDefaultModel();
                 foreach ($applicationJson->getRelatableModels() as $relModel) {
                     $registryData[$relModel['ownApp']]['relatableModels'][] = $relModel;
                 }
                 // @todo do we need this for all apps?
                 $exportDefinitions = Tinebase_ImportExportDefinition::getInstance()->getExportDefinitionsForApplication($application);
                 $registryData[$application->name]['exportDefinitions'] = array('results' => $exportDefinitions->toArray(), 'totalcount' => count($exportDefinitions));
                 $customfields = Tinebase_CustomField::getInstance()->getCustomFieldsForApplication($application);
                 Tinebase_CustomField::getInstance()->resolveConfigGrants($customfields);
                 $registryData[$application->name]['customfields'] = $customfields->toArray();
                 // add preferences for app
                 $appPrefs = Tinebase_Core::getPreference($application->name);
                 if ($appPrefs !== NULL) {
                     $allPrefs = $appPrefs->getAllApplicationPreferences();
                     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($allPrefs, TRUE));
                     }
                     foreach ($allPrefs as $pref) {
                         try {
                             $registryData[$application->name]['preferences'][$pref] = $appPrefs->{$pref};
                         } catch (Exception $e) {
                             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not get ' . $pref . '  preference: ' . $e);
                         }
                     }
                 }
             }
         }
     } else {
         $registryData['Tinebase'] = $this->getRegistryData();
     }
     return $registryData;
 }
 /**
  * Returns registry data of all applications current user has access to
  * @see Tinebase_Application_Json_Abstract
  *
  * @return mixed array 'variable name' => 'data'
  */
 public function getAllRegistryData()
 {
     $registryData = array();
     if (Tinebase_Core::getUser()) {
         $userApplications = Tinebase_Core::getUser()->getApplications(TRUE);
         $clientConfig = Tinebase_Config::getInstance()->getClientRegistryConfig();
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             /** @noinspection PhpUndefinedFieldInspection */
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' User applications to fetch registry for: ' . print_r($userApplications->name, TRUE));
         }
         /** @noinspection PhpUndefinedFieldInspection */
         if (!in_array('Tinebase', $userApplications->name)) {
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' User has no permissions to run Tinebase.');
             $this->logout();
             throw new Tinebase_Exception_AccessDenied('User has no permissions to run Tinebase');
         }
         foreach ($userApplications as $application) {
             $appRegistry = array();
             $appRegistry['rights'] = Tinebase_Core::getUser()->getRights($application->name);
             $appRegistry['config'] = isset($clientConfig[$application->name]) ? $clientConfig[$application->name]->toArray() : array();
             // @todo do we need this for all apps?
             $exportDefinitions = Tinebase_ImportExportDefinition::getInstance()->getExportDefinitionsForApplication($application);
             $appRegistry['exportDefinitions'] = array('results' => $exportDefinitions->toArray(), 'totalcount' => count($exportDefinitions));
             $customfields = Tinebase_CustomField::getInstance()->getCustomFieldsForApplication($application);
             Tinebase_CustomField::getInstance()->resolveConfigGrants($customfields);
             $appRegistry['customfields'] = $customfields->toArray();
             // add preferences for app
             try {
                 $prefRegistry = $this->_getAppPreferencesForRegistry($application);
                 $appRegistry = array_merge_recursive($appRegistry, $prefRegistry);
             } catch (Tinebase_Exception_AccessDenied $tead) {
                 // do not add prefs if user has no run right
             }
             $customAppRegistry = $this->_getCustomAppRegistry($application);
             if (empty($customAppRegistry)) {
                 // TODO always get this from app controller (and remove from _getCustomAppRegistry)
                 $appController = Tinebase_Core::getApplicationInstance($application->name);
                 $models = $appController->getModels();
                 $appRegistry['models'] = Tinebase_ModelConfiguration::getFrontendConfigForModels($models);
                 $appRegistry['defaultModel'] = $appController->getDefaultModel();
             } else {
                 $appRegistry = array_merge_recursive($appRegistry, $customAppRegistry);
             }
             $registryData[$application->name] = $appRegistry;
         }
     } else {
         $registryData['Tinebase'] = $this->getRegistryData();
     }
     return $registryData;
 }
Ejemplo n.º 29
0
 /**
  * Returns registry data of all applications current user has access to
  * @see Tinebase_Application_Json_Abstract
  *
  * @return mixed array 'variable name' => 'data'
  */
 public function getAllRegistryData()
 {
     $registryData = array();
     if (Tinebase_Core::getUser()) {
         $userApplications = Tinebase_Core::getUser()->getApplications(TRUE);
         $clientConfig = Tinebase_Config::getInstance()->getClientRegistryConfig();
         foreach ($userApplications as $application) {
             $jsonAppName = $application->name . '_Frontend_Json';
             if (class_exists($jsonAppName)) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Getting registry data for app ' . $application->name);
                 }
                 $applicationJson = new $jsonAppName();
                 $registryData[$application->name] = $applicationJson->getRegistryData();
                 $registryData[$application->name]['rights'] = Tinebase_Core::getUser()->getRights($application->name);
                 $registryData[$application->name]['config'] = isset($clientConfig[$application->name]) ? $clientConfig[$application->name]->toArray() : array();
                 // @todo do we need this for all apps?
                 $exportDefinitions = Tinebase_ImportExportDefinition::getInstance()->getExportDefinitionsForApplication($application);
                 $registryData[$application->name]['exportDefinitions'] = array('results' => $exportDefinitions->toArray(), 'totalcount' => count($exportDefinitions));
                 $customfields = Tinebase_CustomField::getInstance()->getCustomFieldsForApplication($application);
                 Tinebase_CustomField::getInstance()->resolveConfigGrants($customfields);
                 $registryData[$application->name]['customfields'] = $customfields->toArray();
                 // add preferences for app
                 $appPrefs = Tinebase_Core::getPreference($application->name);
                 if ($appPrefs !== NULL) {
                     $allPrefs = $appPrefs->getAllApplicationPreferences();
                     foreach ($allPrefs as $pref) {
                         $registryData[$application->name]['preferences'][$pref] = $appPrefs->{$pref};
                     }
                 }
             }
         }
         if (!array_key_exists('Tinebase', $registryData)) {
             Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' User has no permissions to run Tinebase or unable to get Tinebase preferences. Aborting ...');
             $this->logout();
         }
     } else {
         $registryData['Tinebase'] = $this->getRegistryData();
     }
     return $registryData;
 }
 /**
  * look for import definitions and put them into the db
  *
  * @param Tinebase_Model_Application $_application
  */
 public function createImportExportDefinitions($_application)
 {
     foreach (array('Import', 'Export') as $type) {
         $path = $this->_baseDir . $_application->name . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . 'definitions';
         if (file_exists($path)) {
             foreach (new DirectoryIterator($path) as $item) {
                 $filename = $path . DIRECTORY_SEPARATOR . $item->getFileName();
                 if (preg_match("/\\.xml/", $filename)) {
                     try {
                         Tinebase_ImportExportDefinition::getInstance()->updateOrCreateFromFilename($filename, $_application);
                     } catch (Exception $e) {
                         Setup_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Not installing import/export definion from file: ' . $filename . ' / Error message: ' . $e->getMessage());
                     }
                 }
             }
         }
     }
 }