/**
  * init key fields
  */
 protected function _initializeKeyFields()
 {
     // create status config
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $typeConfig = array('name' => Inventory_Config::INVENTORY_STATUS, 'records' => array(array('id' => 'ORDERED', 'value' => 'ordered'), array('id' => 'AVAILABLE', 'value' => 'available'), array('id' => 'DEFECT', 'value' => 'defect'), array('id' => 'MISSING', 'value' => 'missing'), array('id' => 'REMOVED', 'value' => 'removed'), array('id' => 'UNKNOWN', 'value' => 'unknown')), 'default' => 'AVAILABLE');
     $cb->create(new Tinebase_Model_Config(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Inventory')->getId(), 'name' => Inventory_Config::INVENTORY_STATUS, 'value' => json_encode($typeConfig))));
 }
 /**
  * init key fields
  */
 protected function _initializeKeyFields()
 {
     // create status config
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $statusConfig = array('name' => ExampleApplication_Config::EXAMPLE_STATUS, 'records' => array(array('id' => 'COMPLETED', 'value' => 'Completed', 'is_open' => 0, 'icon' => 'images/oxygen/16x16/actions/ok.png', 'system' => true), array('id' => 'CANCELLED', 'value' => 'Cancelled', 'is_open' => 0, 'icon' => 'images/oxygen/16x16/actions/dialog-cancel.png', 'system' => true), array('id' => 'IN-PROCESS', 'value' => 'In process', 'is_open' => 1, 'icon' => 'images/oxygen/16x16/actions/view-refresh.png', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('ExampleApplication')->getId(), 'name' => ExampleApplication_Config::EXAMPLE_STATUS, 'value' => json_encode($statusConfig))));
 }
 protected function _updateLeadConfig()
 {
     // get all configs for crm from DB
     $crmApp = Tinebase_Application::getInstance()->getApplicationByName('Crm');
     // either put default to DB or delete form DB
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $configRecords = $cb->search(new Tinebase_Model_ConfigFilter(array(array('field' => 'application_id', 'operator' => 'equals', 'value' => $crmApp->getId()))));
     $appDefaults = $configRecords->filter('name', 'appdefaults')->getFirstRecord();
     foreach (array('leadstate', 'leadtype', 'leadsource') as $oldValueName) {
         $keyFieldName = $oldValueName . 's';
         $DBconfig = $configRecords->filter('name', $keyFieldName)->getFirstRecord();
         // only update if custom config is found and if it is still in old format
         if ($DBconfig && strpos($DBconfig->value, $oldValueName) !== false) {
             $decodedConfig = json_decode($DBconfig->value, true);
             foreach ($decodedConfig as $key => $oldRecord) {
                 $decodedConfig[$key]['value'] = $oldRecord[$oldValueName];
                 unset($decodedConfig[$key][$oldValueName]);
             }
             // if no app defaults: use the first record as default
             $default = isset($appDefaults[$keyFieldName]) ? $appDefaults[$keyFieldName] : $decodedConfig[0]['id'];
             $DBconfig->value = json_encode(array('records' => $decodedConfig, 'default' => $default));
             $cb->update($DBconfig);
         }
     }
     if ($appDefaults) {
         $cb->delete($appDefaults->getId());
     }
 }
 /**
  * init favorites
  */
 protected function _initializeKeyFields()
 {
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $attendeeRolesConfig = array('name' => Calendar_Config::ATTENDEE_ROLES, 'records' => array(array('id' => 'REQ', 'value' => 'Required', 'system' => true), array('id' => 'OPT', 'value' => 'Optional', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'name' => Calendar_Config::ATTENDEE_ROLES, 'value' => json_encode($attendeeRolesConfig))));
     $attendeeStatusConfig = array('name' => Calendar_Config::ATTENDEE_STATUS, 'records' => array(array('id' => 'NEEDS-ACTION', 'value' => 'No response', 'icon' => 'images/oxygen/16x16/actions/mail-mark-unread-new.png', 'system' => true), array('id' => 'ACCEPTED', 'value' => 'Accepted', 'icon' => 'images/oxygen/16x16/actions/ok.png', 'system' => true), array('id' => 'DECLINED', 'value' => 'Declined', 'icon' => 'images/oxygen/16x16/actions/dialog-cancel.png', 'system' => true), array('id' => 'TENTATIVE', 'value' => 'Tentative', 'icon' => 'images/calendar-response-tentative.png', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'name' => Calendar_Config::ATTENDEE_STATUS, 'value' => json_encode($attendeeStatusConfig))));
 }
 /**
  * init key fields
  */
 protected function _initializeKeyFields()
 {
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $tasksStatusConfig = array('name' => Tasks_Config::TASK_STATUS, 'records' => array(array('id' => 'NEEDS-ACTION', 'value' => 'No response', 'is_open' => 1, 'icon' => 'images/oxygen/16x16/actions/mail-mark-unread-new.png', 'system' => true), array('id' => 'COMPLETED', 'value' => 'Completed', 'is_open' => 0, 'icon' => 'images/oxygen/16x16/actions/ok.png', 'system' => true), array('id' => 'CANCELLED', 'value' => 'Cancelled', 'is_open' => 0, 'icon' => 'images/oxygen/16x16/actions/dialog-cancel.png', 'system' => true), array('id' => 'IN-PROCESS', 'value' => 'In process', 'is_open' => 1, 'icon' => 'images/oxygen/16x16/actions/view-refresh.png', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Tasks')->getId(), 'name' => Tasks_Config::TASK_STATUS, 'value' => json_encode($tasksStatusConfig))));
     $tasksPriorityConfig = array('name' => Tasks_Config::TASK_PRIORITY, 'records' => array(array('id' => 'LOW', 'value' => 'low', 'icon' => 'images/oxygen/16x16/actions/go-down.png', 'system' => true), array('id' => 'NORMAL', 'value' => 'normal', 'icon' => 'images/oxygen/16x16/actions/go-next.png', 'system' => true), array('id' => 'HIGH', 'value' => 'high', 'icon' => 'images/oxygen/16x16/actions/go-up.png', 'system' => true), array('id' => 'URGENT', 'value' => 'urgent', 'icon' => 'images/oxygen/16x16/emblems/emblem-important.png', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Tasks')->getId(), 'name' => Tasks_Config::TASK_PRIORITY, 'value' => json_encode($tasksPriorityConfig))));
 }
 /**
  * init key fields
  */
 protected function _initializeKeyFields()
 {
     // create status config
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $appId = Tinebase_Application::getInstance()->getApplicationByName('Projects')->getId();
     $projectsStatusConfig = array('name' => Projects_Config::PROJECT_STATUS, 'records' => array(array('id' => 'NEEDS-ACTION', 'value' => 'On hold', 'is_open' => 1, 'icon' => 'images/oxygen/16x16/actions/mail-mark-unread-new.png', 'system' => true), array('id' => 'COMPLETED', 'value' => 'Completed', 'is_open' => 0, 'icon' => 'images/oxygen/16x16/actions/ok.png', 'system' => true), array('id' => 'CANCELLED', 'value' => 'Cancelled', 'is_open' => 0, 'icon' => 'images/oxygen/16x16/actions/dialog-cancel.png', 'system' => true), array('id' => 'IN-PROCESS', 'value' => 'In process', 'is_open' => 1, 'icon' => 'images/oxygen/16x16/actions/view-refresh.png', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Projects_Config::PROJECT_STATUS, 'value' => json_encode($projectsStatusConfig))));
     $projectsAttendeeRoleConfig = array('name' => Projects_Config::PROJECT_ATTENDEE_ROLE, 'records' => array(array('id' => 'COWORKER', 'value' => 'Coworker', 'icon' => 'images/oxygen/16x16/apps/system-users.png', 'system' => true), array('id' => 'RESPONSIBLE', 'value' => 'Responsible', 'icon' => 'images/oxygen/16x16/apps/preferences-desktop-user.png', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Projects_Config::PROJECT_ATTENDEE_ROLE, 'value' => json_encode($projectsAttendeeRoleConfig))));
 }
 public function update_3()
 {
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $appId = Tinebase_Application::getInstance()->getApplicationByName('Sipgate')->getId();
     $c = array('name' => Sipgate_Config::ACCOUNT_ACCOUNT_TYPE, 'records' => array(array('id' => 'plus', 'value' => 'basic/plus', 'icon' => "../../images/oxygen/16x16/places/user-identity.png", 'system' => true), array('id' => 'team', 'value' => 'team', 'icon' => "../../images/oxygen/16x16/apps/system-users.png", 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sipgate_Config::ACCOUNT_ACCOUNT_TYPE, 'value' => json_encode($c))));
     // create tos config
     $c = array('name' => Sipgate_Config::ACCOUNT_TYPE, 'records' => array(array('id' => 'private', 'value' => 'private', 'icon' => "../../images/oxygen/16x16/places/user-identity.png", 'system' => true), array('id' => 'shared', 'value' => 'shared', 'icon' => "../../images/oxygen/16x16/apps/system-users.png", 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sipgate_Config::ACCOUNT_TYPE, 'value' => json_encode($c))));
     $this->setApplicationVersion('Sipgate', '1.4');
 }
 /**
  * update to 7.2
  * - add uid field
  */
 public function update_1()
 {
     $this->validateTableVersion('tasks', 6);
     // first add with notnull == false ...
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>uid</name>
             <type>text</type>
             <length>255</length>
             <notnull>false</notnull>
         </field>
     ');
     try {
         $this->_backend->addCol('tasks', $declaration);
     } catch (Exception $e) {
         Tinebase_Exception::log($e);
     }
     $tasksBackend = new Tinebase_Backend_Sql(array('modelName' => 'Tasks_Model_Task', 'tableName' => 'tasks'));
     $allTasks = $tasksBackend->getAll();
     // add uid to all tasks
     foreach ($allTasks as $task) {
         $task->uid = $task->id;
         if (empty($task->status)) {
             $task->status = 'UNKNOWN';
         }
         $tasksBackend->update($task);
     }
     // ... now set notnull to true
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>uid</name>
             <type>text</type>
             <length>255</length>
             <notnull>true</notnull>
         </field>
     ');
     $this->_backend->alterCol('tasks', $declaration);
     $declaration = new Setup_Backend_Schema_Index_Xml('
         <index>
             <name>uid--id</name>
             <field>
                 <name>uid</name>
             </field>
             <field>
                 <name>id</name>
             </field>
         </index>
     ');
     $this->_backend->addIndex('tasks', $declaration);
     $this->setTableVersion('tasks', 7);
     $this->setApplicationVersion('Tasks', '7.2');
 }
Ejemplo n.º 9
0
 /**
  * add logout entry to the access log
  *
  * @param string $_sessionId the session id
  * @param string $_ipAddress the ip address the user connects from
  * @return void|Tinebase_Model_AccessLog
  */
 public function setLogout($_sessionId, $_ipAddress = NULL)
 {
     try {
         $loginRecord = $this->_backend->getByProperty($_sessionId, 'sessionid');
     } catch (Tinebase_Exception_NotFound $tenf) {
         Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not find access log login record for session id ' . $_sessionId);
         return;
     }
     $loginRecord->lo = Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG);
     if ($_ipAddress !== NULL) {
         $loginRecord->ip = $_ipAddress;
     }
     return $this->update($loginRecord);
 }
 /**
  * update to 6.2
  * 
  * @see 0008196: Preferences values contains translated value
  */
 public function update_1()
 {
     $prefBackend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Preference', 'tableName' => 'preferences'));
     $alarmPrefs = $prefBackend->search(new Tinebase_Model_PreferenceFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => Calendar_Preference::DEFAULTALARM_MINUTESBEFORE))));
     foreach ($alarmPrefs as $pref) {
         if (preg_match("/\\((\\d+)\\)/", $pref->value, $matches)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updating DEFAULTALARM_MINUTESBEFORE from ' . $pref->value . ' to ' . $matches[1]);
             }
             $pref->value = $matches[1];
             $prefBackend->update($pref);
         }
     }
     $this->setApplicationVersion('Calendar', '6.2');
 }
Ejemplo n.º 11
0
 /**
  * set alarms of record
  *
  * @param Tinebase_Record_Abstract $_record
  * @param string $_alarmsProperty
  * @return void
  */
 public function setAlarmsOfRecord(Tinebase_Record_Abstract $_record, $_alarmsProperty = 'alarms')
 {
     $model = get_class($_record);
     $alarms = $_record->{$_alarmsProperty};
     $currentAlarms = $this->getAlarmsOfRecord($model, $_record);
     $diff = $currentAlarms->getMigration($alarms->getArrayOfIds());
     $this->_backend->delete($diff['toDeleteIds']);
     if (count($alarms) > 1) {
         Tinebase_Core::getLogger()->NOTICE(__METHOD__ . '::' . __LINE__ . "only the first alarm could is saved: " . print_r($alarms->toArray(), TRUE));
     }
     // create / update alarms
     foreach ($alarms as $alarm) {
         $id = $alarm->getId();
         if ($id) {
             $alarm = $this->_backend->update($alarm);
         } else {
             $alarm->record_id = $_record->getId();
             if (!$alarm->model) {
                 $alarm->model = $model;
             }
             $alarm = $this->_backend->create($alarm);
         }
         break;
     }
 }
 /**
  * init key fields
  */
 function _initializeKeyfields()
 {
     // create status config
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $appId = Tinebase_Application::getInstance()->getApplicationByName('Sipgate')->getId();
     $connectionStatusConfig = array('name' => Sipgate_Config::CONNECTION_STATUS, 'records' => array(array('id' => 'accepted', 'value' => 'accepted', 'icon' => "../../images/../Sipgate/res/call_accepted.png", 'system' => true), array('id' => 'outgoing', 'value' => 'outgoing', 'icon' => "../../images/../Sipgate/res/call_outgoing.png", 'system' => true), array('id' => 'missed', 'value' => 'missed', 'icon' => "../../images/../Sipgate/res/call_missed.png", 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sipgate_Config::CONNECTION_STATUS, 'value' => json_encode($connectionStatusConfig))));
     // create tos config
     $connectionTos = array('name' => Sipgate_Config::CONNECTION_TOS, 'records' => array(array('id' => 'voice', 'value' => 'Telephone Call', 'icon' => "../../images/oxygen/16x16/apps/kcall.png", 'system' => true), array('id' => 'fax', 'value' => 'Facsimile', 'icon' => "../../images/../Sipgate/res/16x16/kfax.png", 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sipgate_Config::CONNECTION_TOS, 'value' => json_encode($connectionTos))));
     $c = array('name' => Sipgate_Config::ACCOUNT_ACCOUNT_TYPE, 'records' => array(array('id' => 'plus', 'value' => 'basic/plus', 'icon' => "../../images/oxygen/16x16/places/user-identity.png", 'system' => true), array('id' => 'team', 'value' => 'team', 'icon' => "../../images/oxygen/16x16/apps/system-users.png", 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sipgate_Config::ACCOUNT_ACCOUNT_TYPE, 'value' => json_encode($c))));
     // create tos config
     $c = array('name' => Sipgate_Config::ACCOUNT_TYPE, 'records' => array(array('id' => 'private', 'value' => 'private', 'icon' => "../../images/oxygen/16x16/places/user-identity.png", 'system' => true), array('id' => 'shared', 'value' => 'shared', 'icon' => "../../images/oxygen/16x16/apps/system-users.png", 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sipgate_Config::ACCOUNT_TYPE, 'value' => json_encode($c))));
 }
 /**
  * init key fields
  */
 function _initializeKeyfields()
 {
     // create type config
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $appId = Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId();
     $freeTimeTypeConfig = array('name' => HumanResources_Config::FREETIME_TYPE, 'records' => array(array('id' => 'SICKNESS', 'value' => 'Sickness', 'icon' => 'images/oxygen/16x16/actions/book.png', 'system' => TRUE), array('id' => 'VACATION', 'value' => 'Vacation', 'icon' => 'images/oxygen/16x16/actions/book2.png', 'system' => TRUE)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => HumanResources_Config::FREETIME_TYPE, 'value' => json_encode($freeTimeTypeConfig))));
     // extra free time type
     $freeTimeTypeConfig = array('name' => HumanResources_Config::EXTRA_FREETIME_TYPE, 'records' => array(array('id' => 'PAYED', 'value' => 'Payed', 'icon' => NULL, 'system' => TRUE), array('id' => 'NOT_PAYED', 'value' => 'Not payed', 'icon' => NULL, 'system' => TRUE)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => HumanResources_Config::EXTRA_FREETIME_TYPE, 'value' => json_encode($freeTimeTypeConfig))));
     // create vacation status config
     $vacationStatusConfig = array('name' => HumanResources_Config::VACATION_STATUS, 'records' => array(array('id' => 'REQUESTED', 'value' => 'Requested', 'icon' => 'images/oxygen/16x16/actions/mail-mark-unread-new.png', 'system' => TRUE), array('id' => 'IN-PROCESS', 'value' => 'In process', 'icon' => 'images/oxygen/16x16/actions/view-refresh.png', 'system' => TRUE), array('id' => 'ACCEPTED', 'value' => 'Accepted', 'icon' => 'images/oxygen/16x16/actions/ok.png', 'system' => TRUE), array('id' => 'DECLINED', 'value' => 'Declined', 'icon' => 'images/oxygen/16x16/actions/dialog-cancel.png', 'system' => TRUE)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => HumanResources_Config::VACATION_STATUS, 'value' => json_encode($vacationStatusConfig))));
     // create sickness status config
     $sicknessStatusConfig = array('name' => HumanResources_Config::SICKNESS_STATUS, 'records' => array(array('id' => 'EXCUSED', 'value' => 'Excused', 'icon' => 'images/oxygen/16x16/actions/smiley.png', 'system' => TRUE), array('id' => 'UNEXCUSED', 'value' => 'Unexcused', 'icon' => 'images/oxygen/16x16/actions/tools-report-bug.png', 'system' => TRUE)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => HumanResources_Config::SICKNESS_STATUS, 'value' => json_encode($sicknessStatusConfig))));
 }
 /**
  * init key fields
  */
 protected function _initializeKeyFields()
 {
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $appId = Tinebase_Application::getInstance()->getApplicationByName('Sales')->getId();
     // create product categories
     $tc = array('name' => Sales_Config::PRODUCT_CATEGORY, 'records' => array(array('id' => 'DEFAULT', 'value' => 'Default', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sales_Config::PRODUCT_CATEGORY, 'value' => json_encode($tc))));
     // create type config
     $tc = array('name' => Sales_Config::INVOICE_TYPE, 'records' => array(array('id' => 'INVOICE', 'value' => 'Invoice', 'system' => true), array('id' => 'REVERSAL', 'value' => 'Reversal', 'system' => true), array('id' => 'CREDIT', 'value' => 'Credit', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sales_Config::INVOICE_TYPE, 'value' => json_encode($tc))));
     // create cleared state keyfields
     $tc = array('name' => Sales_Config::INVOICE_CLEARED, 'records' => array(array('id' => 'TO_CLEAR', 'value' => 'to clear', 'system' => true), array('id' => 'CLEARED', 'value' => 'cleared', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sales_Config::INVOICE_CLEARED, 'value' => json_encode($tc))));
     // create payment types config
     $tc = array('name' => Sales_Config::PAYMENT_METHODS, 'records' => array(array('id' => 'BANK TRANSFER', 'value' => 'Bank transfer', 'system' => true), array('id' => 'DIRECT DEBIT', 'value' => 'Direct debit', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sales_Config::PAYMENT_METHODS, 'value' => json_encode($tc))));
 }
 /**
  * Sets up the fixture.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     parent::setUp();
     $fe = new Tinebase_Frontend_Cli();
     $opts = new Zend_Console_Getopt('abp:');
     $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/tine20/tine20/HumanResources/Export/definitions/hr_default_ods.xml';
     $opts->setArguments(array($path));
     ob_start();
     $fe->updateImportExportDefinition($opts);
     $output = ob_get_clean();
     $this->assertContains('hr_default_ods.xml successfully.', $output);
     $filter = new Tinebase_Model_ImportExportDefinitionFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => 'hr_default_ods')));
     $backend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_ImportExportDefinition', 'tableName' => 'importexport_definition'), NULL);
     $this->_importDefinition = $backend->search($filter)->getFirstRecord();
     $filter = new HumanResources_Model_EmployeeFilter(array());
     $options = array('definitionId' => $this->_importDefinition->getId());
     $this->_instance = Tinebase_Export::factory($filter, $options);
 }
 /**
  * load state data
  *
  * @return array
  */
 public function loadStateInfo()
 {
     $result = array();
     if (Tinebase_Core::getUser()) {
         $userId = Tinebase_Core::getUser()->getId();
         $states = $this->_backend->search(new Tinebase_Model_StateFilter(array(array('field' => 'user_id', 'operator' => 'equals', 'value' => $userId))));
         foreach ($states as $stateRecord) {
             $result[$stateRecord->state_id] = $stateRecord->data;
         }
     }
     return $result;
 }
 /**
  * delete all sieve data associated with account
  */
 public function delete()
 {
     try {
         $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
         $this->_rulesBackend->deleteByProperty($this->_accountId, 'account_id');
         $this->_vacationBackend->deleteByProperty($this->_accountId, 'account_id');
         Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw Exception;
     }
 }
 /**
  * undo modlog records defined by filter
  * 
  * @param Tinebase_Model_ModificationLogFilter $filter
  * @param boolean $overwrite should changes made after the detected change be overwritten?
  * @param boolean $dryrun
  * @return integer count of reverted changes
  * 
  * @todo use iterator?
  * @todo return updated records/exceptions?
  * @todo create result model / should be used in Tinebase_Controller_Record_Abstract::updateMultiple, too
  * @todo use transaction with rollback for dryrun?
  * @todo allow to undo tags/customfields/...
  */
 public function undo(Tinebase_Model_ModificationLogFilter $filter, $overwrite = FALSE, $dryrun = FALSE)
 {
     $notUndoableFields = array('tags', 'customfields', 'relations');
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Filter: ' . print_r($filter->toArray(), TRUE));
     }
     $modlogRecords = $this->_backend->search($filter, new Tinebase_Model_Pagination(array('sort' => array('record_type', 'modification_time'))));
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . count($modlogRecords) . ' modlog records matching the filter.');
     }
     $updateCount = 0;
     $failCount = 0;
     $undoneModlogs = new Tinebase_Record_RecordSet('Tinebase_Model_ModificationLog');
     $currentRecordType = NULL;
     foreach ($modlogRecords as $modlog) {
         if ($currentRecordType !== $modlog->record_type || !isset($controller)) {
             $currentRecordType = $modlog->record_type;
             $controller = Tinebase_Core::getApplicationInstance($modlog->record_type);
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Modlog: ' . print_r($modlog->toArray(), TRUE));
         }
         try {
             $record = $controller->get($modlog->record_id);
             if (!in_array($modlog->modified_attribute, $notUndoableFields) && ($overwrite || $record->seq === $modlog->seq)) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Reverting change id ' . $modlog->getId());
                 }
                 $record->{$modlog->modified_attribute} = $modlog->old_value;
                 if (!$dryrun) {
                     $controller->update($record);
                 }
                 $updateCount++;
                 $undoneModlogs->addRecord($modlog);
             } else {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Not reverting change of ' . $modlog->modified_attribute . ' of record ' . $modlog->record_id);
                 }
             }
         } catch (Exception $e) {
             if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                 Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $e);
             }
             $failCount++;
         }
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Reverted ' . $updateCount . ' modlog changes.');
     }
     return array('totalcount' => $updateCount, 'failcount' => $failCount, 'undoneModlogs' => $undoneModlogs);
 }
 /**
  * finish job
  *
  * @param Tinebase_Model_AsyncJob $_asyncJob
  * @param string $_status
  * @param string $_message
  * @return Tinebase_Model_AsyncJob
  */
 public function finishJob(Tinebase_Model_AsyncJob $_asyncJob, $_status = Tinebase_Model_AsyncJob::STATUS_SUCCESS, $_message = NULL)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Finishing job ' . $_asyncJob->name . ' with status ' . $_status);
     }
     $this->_purgeOldJobs($_asyncJob);
     $_asyncJob->end_time = Tinebase_DateTime::now();
     $_asyncJob->status = $_status;
     if ($_message !== NULL) {
         $_asyncJob->message = $_message;
     }
     $result = $this->_backend->update($_asyncJob);
     return $result;
 }
 /**
  * clear access log table
  * - if $date param is omitted, the last 60 days of access log are kept, the rest will be removed
  * 
  * @param Tinebase_DateTime $date
  * @return integer deleted rows
  * 
  * @todo use $this->deleteByFilter($_filter)? might be slow for huge access_logs
  */
 public function clearTable($date = NULL)
 {
     $date = $date instanceof Tinebase_DateTime ? $date : Tinebase_DateTime::now()->subDay(60);
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Removing all access log entries before ' . $date->toString());
     }
     $db = $this->_backend->getAdapter();
     $where = array($db->quoteInto($db->quoteIdentifier('li') . ' < ?', $date->toString()));
     $deletedRows = $db->delete($this->_backend->getTablePrefix() . $this->_backend->getTableName(), $where);
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Removed ' . $deletedRows . ' rows.');
     }
     return $deletedRows;
 }
Ejemplo n.º 21
0
 /**
  * load state data
  *
  * @return array
  */
 public function loadStateInfo()
 {
     $result = array();
     if (Tinebase_Core::getUser()) {
         $userId = Tinebase_Core::getUser()->getId();
         try {
             $state = $this->_backend->getByProperty($userId, 'user_id');
             $result = Zend_Json::decode($state->data);
         } catch (Tinebase_Exception_NotFound $tenf) {
             // no state found
         }
     }
     return $result;
 }
Ejemplo n.º 22
0
 /**
  * finish job
  *
  * @param Tinebase_Model_AsyncJob $_asyncJob
  * @param string $_status
  * @param string $_message
  * @return Tinebase_Model_AsyncJob
  */
 public function finishJob(Tinebase_Model_AsyncJob $_asyncJob, $_status = Tinebase_Model_AsyncJob::STATUS_SUCCESS, $_message = NULL)
 {
     try {
         $db = $this->_backend->getAdapter();
         $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($db);
         $_asyncJob->end_time = Tinebase_DateTime::now();
         $_asyncJob->status = $_status;
         if ($_message !== NULL) {
             $_asyncJob->message = $_message;
         }
         $result = $this->_backend->update($_asyncJob);
         Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
     return $result;
 }
 /**
  * set alarms of record
  *
  * @param Tinebase_Record_Abstract $_record
  * @param string $_alarmsProperty
  * @return void
  */
 public function setAlarmsOfRecord(Tinebase_Record_Abstract $_record, $_alarmsProperty = 'alarms')
 {
     $model = get_class($_record);
     $alarms = $_record->{$_alarmsProperty};
     $currentAlarms = $this->getAlarmsOfRecord($model, $_record);
     $diff = $currentAlarms->getMigration($alarms->getArrayOfIds());
     $this->_backend->delete($diff['toDeleteIds']);
     // create / update alarms
     foreach ($alarms as $alarm) {
         $id = $alarm->getId();
         if ($id) {
             $alarm = $this->_backend->update($alarm);
         } else {
             $alarm->record_id = $_record->getId();
             if (!$alarm->model) {
                 $alarm->model = $model;
             }
             $alarm = $this->_backend->create($alarm);
         }
     }
 }
 /**
  * delete all record paths
  *
  * @param $record
  * @return int
  *
  * TODO add acl check?
  */
 public function deletePathsForRecord($record)
 {
     return $this->_backend->deleteByProperty($record->getId(), 'record_id');
 }
 /**
  * Deletes a set of records.
  *
  * If one of the records could not be deleted, no record is deleted
  *
  * @param   array array of record identifiers
  * @return  Tinebase_Record_RecordSet
  */
 public function delete($_ids)
 {
     $this->_configBackend->delete($_ids);
 }
Ejemplo n.º 26
0
 /**
  * add a calendar for each resource
  */
 public function update_8()
 {
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>container_id</name>
             <type>integer</type>
         </field>');
     $this->_backend->addCol('cal_resources', $declaration, 1);
     $declaration = new Setup_Backend_Schema_Index_Xml('
         <index>
             <name>cal_resources::container_id--container::id</name>
             <field>
                 <name>container_id</name>
             </field>
             <foreign>true</foreign>
             <reference>
                 <table>container</table>
                 <field>id</field>
             </reference>
         </index>');
     $this->_backend->addForeignKey('cal_resources', $declaration);
     $this->setTableVersion('cal_resources', 2);
     $this->setApplicationVersion('Calendar', '3.9');
     // give existing resources a container
     $rb = new Tinebase_Backend_Sql(array('modelName' => 'Calendar_Model_Resource', 'tableName' => 'cal_resources'));
     $resources = $rb->getAll();
     foreach ($resources as $resource) {
         $container = Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => $resource->name, 'type' => Tinebase_Model_Container::TYPE_SHARED, 'owner_id' => $resource->getId(), 'backend' => 'Sql', 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId())), NULL, TRUE);
         // remove default admin
         $grants = Tinebase_Container::getInstance()->setGrants($container->getId(), new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(array('account_id' => '0', 'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE, Tinebase_Model_Grants::GRANT_FREEBUSY => true))), TRUE, FALSE);
         $resource->container_id = $container->getId();
         $rb->update($resource);
     }
 }
 /**
  * returns active users
  *
  * @return int
  */
 public function getActiveUserCount()
 {
     $backend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_User', 'tableName' => 'accounts'));
     // TODO allow to set this as param
     $afterDate = Tinebase_DateTime::now()->subMonth(1);
     $filter = new Tinebase_Model_FullUserFilter(array(array('field' => 'last_login', 'operator' => 'after', 'value' => $afterDate), array('field' => 'status', 'operator' => 'equals', 'value' => Tinebase_Model_User::ACCOUNT_STATUS_ENABLED)));
     return $backend->searchCount($filter);
 }
 /**
  * update to 8.3
  * - normalize all rrules
  */
 public function update_2()
 {
     // find all events with rrule
     $eventIds = $this->_db->query("SELECT " . $this->_db->quoteIdentifier('id') . " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_events") . " WHERE " . $this->_db->quoteIdentifier("rrule") . " IS NOT NULL")->fetchAll(Zend_Db::FETCH_ASSOC);
     // NOTE: we need a generic sql BE to circumvent calendar specific acl issues
     $eventBE = new Tinebase_Backend_Sql(array('modelName' => 'Calendar_Model_Event', 'tableName' => 'cal_events', 'modlogActive' => false));
     foreach ($eventIds as $eventId) {
         $event = $eventBE->get($eventId['id']);
         $oldRruleString = (string) $event->rrule;
         $rrule = Calendar_Model_Rrule::getRruleFromString($oldRruleString);
         $rrule->normalize($event);
         if ($oldRruleString != (string) $rrule) {
             $event->rrule = (string) $rrule;
             try {
                 $eventBE->update($event);
             } catch (Tinebase_Exception_Record_Validation $terv) {
                 Tinebase_Exception::log($terv, null, $event->toArray());
             } catch (Tinebase_Exception_UnexpectedValue $teuv) {
                 Tinebase_Exception::log($teuv, null, $event->toArray());
             }
         }
     }
     $this->setApplicationVersion('Calendar', '8.3');
 }
 /**
  * update from 5.4 -> 5.5
  * - set cleared to text
  * - change default values for cleared, status 
  * 
  * @return void
  */
 public function update_4()
 {
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>cleared</name>
             <type>text</type>
             <length>64</length>
             <default>not yet cleared</default>
         </field>');
     $this->_backend->alterCol('sales_contracts', $declaration);
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>status</name>
             <type>text</type>
             <length>64</length>
             <default>open</default>
         </field>');
     $this->_backend->alterCol('sales_contracts', $declaration);
     $this->setTableVersion('sales_contracts', 4);
     // transfer cleared value
     $be = new Sales_Backend_Contract();
     $filter = new Sales_Model_ContractFilter(array(), 'AND');
     $filter->addFilter(new Tinebase_Model_Filter_Text('cleared', 'equals', '0'));
     $results = $be->search($filter, null, false, true);
     $be->updateMultiple($results, array('cleared' => 'NOTCLEARED'));
     $filter = new Sales_Model_ContractFilter(array(), 'AND');
     $filter->addFilter(new Tinebase_Model_Filter_Text('cleared', 'equals', '1'));
     $results = $be->search($filter, null, false, true);
     $be->updateMultiple($results, array('cleared' => 'CLEARED'));
     // keyfieldconfigs
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $appId = Tinebase_Application::getInstance()->getApplicationByName('Sales')->getId();
     $salesStatusConfig = array('name' => Sales_Config::CONTRACT_STATUS, 'records' => array(array('id' => 'OPEN', 'value' => 'open', 'icon' => 'images/oxygen/16x16/places/folder-green.png', 'system' => true), array('id' => 'CLOSED', 'value' => 'closed', 'icon' => 'images/oxygen/16x16/places/folder-red.png', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sales_Config::CONTRACT_STATUS, 'value' => json_encode($salesStatusConfig))));
     $salesClearedConfig = array('name' => Sales_Config::CONTRACT_CLEARED, 'records' => array(array('id' => 'TOCLEAR', 'value' => 'to clear', 'icon' => 'images/oxygen/16x16/actions/dialog-warning.png', 'system' => true), array('id' => 'NOTCLEARED', 'value' => 'not yet cleared', 'icon' => 'images/oxygen/16x16/actions/edit-delete.png', 'system' => true), array('id' => 'CLEARED', 'value' => 'cleared', 'icon' => 'images/oxygen/16x16/actions/dialog-ok-apply.png', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sales_Config::CONTRACT_CLEARED, 'value' => json_encode($salesClearedConfig))));
     $this->setApplicationVersion('Sales', '5.5');
 }
 /**
  * update to 5.6
  * - convert salutations to keyfield config
  *
  * @return void
  */
 public function update_5()
 {
     $addressbookAppId = Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId();
     // get all current salutation datas and drop old salutation table
     try {
         $stmt = $this->_db->query("SELECT * FROM `" . SQL_TABLE_PREFIX . "addressbook_salutations`");
         $salutationDatas = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
         $this->_backend->dropTable('addressbook_salutations', $addressbookAppId);
     } catch (Zend_Db_Statement_Exception $zdse) {
         // already dropped
         $salutationDatas = array();
     }
     // update addressbook table
     $salutationMap = array();
     // oldId => newId
     foreach ($salutationDatas as $salutationData) {
         $salutationMap[$salutationData['id']] = $salutationData['name'];
         $this->_db->update(SQL_TABLE_PREFIX . 'addressbook', array('salutation_id' => substr(strtoupper($salutationData['name']), 0, 40)), "`salutation_id` = '{$salutationData['id']}'");
     }
     // alter salutation_id -> salutation
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>salutation</name>
             <type>text</type>
             <length>40</length>
             <notnull>false</notnull>
         </field>');
     $this->_backend->alterCol('addressbook', $declaration, 'salutation_id');
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $keyfieldConfig = array('name' => Addressbook_Config::CONTACT_SALUTATION, 'records' => array(array('id' => 'MR', 'value' => 'Mr', 'gender' => Addressbook_Model_Salutation::GENDER_MALE, 'image' => 'images/empty_photo_male.png', 'system' => true), array('id' => 'MS', 'value' => 'Ms', 'gender' => Addressbook_Model_Salutation::GENDER_FEMALE, 'image' => 'images/empty_photo_female.png', 'system' => true), array('id' => 'COMPANY', 'value' => 'Company', 'gender' => Addressbook_Model_Salutation::GENDER_OTHER, 'image' => 'images/empty_photo_company.png', 'system' => true)));
     // add non system custom salutation
     foreach ($salutationDatas as $salutationData) {
         if (!in_array(strtoupper($salutationData['name']), array('MR', 'MS', 'COMPANY'))) {
             $keyfieldConfig['records'][] = array('id' => strtoupper($salutationData['name']), 'value' => $salutationData['name'], 'gender' => $salutationData['gender'], 'image' => $salutationData['image_path']);
         }
     }
     $cb->create(new Tinebase_Model_Config(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'name' => Addressbook_Config::CONTACT_SALUTATION, 'value' => json_encode($keyfieldConfig))));
     $this->setTableVersion('addressbook', '16');
     $this->setApplicationVersion('Addressbook', '5.6');
 }