/** * 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) { 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(); // call update of backend direct to save overhead of $this->update() return $this->_backend->update($loginRecord); }
/** * 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; } }
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()); } }
/** * update one record * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface * @throws Tinebase_Exception_AccessDenied * @throws Tinebase_Exception_Record_Validation */ public function update(Tinebase_Record_Interface $_record) { $app = Tinebase_Application::getInstance()->getApplicationById($_record->application_id); if (!Tinebase_Core::getUser()->hasRight($app->name, 'admin')) { throw new Tinebase_Exception_AccessDenied("You do not have admin rights for {$app->name}"); } $this->_configBackend->update($_record); return $this->get($_record->getId()); }
/** * 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'); }
/** * 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; }
/** * save state data * * @param JSONstring $_stateData */ public function saveStateInfo($_stateData) { if (!Tinebase_Core::getUser()->hasRight('Tinebase', Tinebase_Acl_Rights::MANAGE_OWN_STATE)) { throw new Tinebase_Exception_AccessDenied("You don't have the right to manage your client state"); } $userId = Tinebase_Core::getUser()->getId(); try { $stateRecord = $this->_backend->getByProperty($userId, 'user_id'); } catch (Tinebase_Exception_NotFound $tenf) { $stateRecord = new Tinebase_Model_State(array('user_id' => $userId, 'data' => Zend_Json::encode($_stateData))); $this->_backend->create($stateRecord); } $stateRecord->data = Zend_Json::encode($_stateData); $this->_backend->update($stateRecord); }
/** * 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'); }
/** * saves a single state entry * * @param string $_name * @param string $_value * @return void */ public function setState($_name, $_value) { if (!Tinebase_Core::getUser()->hasRight('Tinebase', Tinebase_Acl_Rights::MANAGE_OWN_STATE)) { throw new Tinebase_Exception_AccessDenied("You don't have the right to manage your client state"); } $userId = Tinebase_Core::getUser()->getId(); $results = $this->_backend->search($this->_getFilter($_name, $userId)); if ($results->count() == 0) { $record = new Tinebase_Model_State(array('user_id' => $userId, 'state_id' => $_name, 'data' => $_value)); $this->_backend->create($record); } else { $record = $results->getFirstRecord(); $record->data = $_value; $this->_backend->update($record); } }
/** * save custom fields of record in its custom fields table * * @param Tinebase_Record_Interface $_record */ public function saveRecordCustomFields(Tinebase_Record_Interface $_record) { $applicationId = Tinebase_Application::getInstance()->getApplicationByName($_record->getApplication())->getId(); $appCustomFields = $this->getCustomFieldsForApplication($applicationId, get_class($_record), Tinebase_Model_CustomField_Grant::GRANT_WRITE); $this->resolveConfigGrants($appCustomFields); $existingCustomFields = $this->_getCustomFields($_record->getId()); $existingCustomFields->addIndices(array('customfield_id')); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updating custom fields for record of class ' . get_class($_record)); } //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . print_r($_record->customfields, TRUE)); //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . print_r($appCustomFields->toArray(), TRUE)); foreach ($appCustomFields as $customField) { if (is_array($_record->customfields) && array_key_exists($customField->name, $_record->customfields)) { $value = $_record->customfields[$customField->name]; $filtered = $existingCustomFields->filter('customfield_id', $customField->id); switch (count($filtered)) { case 1: $cf = $filtered->getFirstRecord(); if ($customField->valueIsEmpty($value)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Deleting cf value for ' . $customField->name); } $this->_backendValue->delete($cf); } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updateing value for ' . $customField->name . ' to ' . $value); } $cf->value = $value; $this->_backendValue->update($cf); } break; case 0: if (!$customField->valueIsEmpty($value)) { $cf = new Tinebase_Model_CustomField_Value(array('record_id' => $_record->getId(), 'customfield_id' => $customField->getId(), 'value' => $value)); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating value for ' . $customField->name . ' -> ' . $value); } $this->_backendValue->create($cf); } break; default: throw new Tinebase_Exception_UnexpectedValue('Oops, there should be only one custom field value here!'); } } } }
/** * persist vacation data in db */ protected function _saveVacation() { if (empty($this->_vacation)) { return; } $vacationRecord = new Expressomail_Model_Sieve_Vacation(); $vacationRecord->setFromFSV($this->_vacation); $vacationRecord->account_id = $this->_accountId; $vacationRecord->setId($this->_accountId); $vacationRecord->addresses = Zend_Json::encode($vacationRecord->addresses); try { $oldVac = $this->_vacationBackend->get($vacationRecord->getId()); $this->_vacationBackend->update($vacationRecord); } catch (Tinebase_Exception_NotFound $tenf) { $this->_vacationBackend->create($vacationRecord); } }
/** * 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; }
/** * persist vacation data in db */ protected function _saveVacation() { if (empty($this->_vacation)) { return; } $vacationRecord = new Felamimail_Model_Sieve_Vacation(); $vacationRecord->setFromFSV($this->_vacation); $vacationRecord->account_id = $this->_accountId; $vacationRecord->setId($this->_accountId); $vacationRecord->addresses = Zend_Json::encode($vacationRecord->addresses); if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Saving vacation in DB: ' . print_r($vacationRecord->toArray(), TRUE)); } try { $oldVac = $this->_vacationBackend->get($vacationRecord->getId()); $this->_vacationBackend->update($vacationRecord); } catch (Tinebase_Exception_NotFound $tenf) { $this->_vacationBackend->create($vacationRecord); } }
/** * 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); } } }
/** * 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'); }
/** * testAdoptAlarmTimeOfYearlyEvent * * @see 0009320: Wrong notification on first occurrence exceptions */ public function testAdoptAlarmTimeOfYearlyEvent() { $event = $this->_getEvent(); $event->dtstart = new Tinebase_DateTime('2012-10-26 22:00:00'); $event->dtend = new Tinebase_DateTime('2012-10-27 21:59:00'); $event->is_all_day_event = 1; $event->rrule = 'FREQ=YEARLY;BYMONTH=10;BYMONTHDAY=27;INTERVAL=1'; $event->alarms = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm', array(new Tinebase_Model_Alarm(array('minutes_before' => 2880), TRUE))); $persistentEvent = $this->_controller->create($event); $alarm = $persistentEvent->alarms->getFirstRecord(); $this->_controller->adoptAlarmTime($persistentEvent, $alarm); $now = Tinebase_DateTime::now(); $year = $now->get('Y'); if ($now->isLater(new Tinebase_DateTime($year . '-10-27'))) { $year++; } // might be at 22:00 or 23.00 (daylight saving ...) // TODO verify that (@see 0011404: fix failing testAdoptAlarmTimeOfYearlyEvent) $expectedAlarmTimes = array($year . '-10-24 22:00:00', $year . '-10-24 23:00:00'); $this->assertTrue(in_array($alarm->alarm_time->toString(), $expectedAlarmTimes), 'alarm time mismatch:' . print_r($alarm->toArray(), true) . ' expected: ' . print_r($expectedAlarmTimes, true)); if ($now->isLater(new Tinebase_DateTime($year . '-10-24'))) { // FIXME test fails if current date is between 10-24 and 10-27 // @see 0011404: fix failing testAdoptAlarmTimeOfYearlyEvent return; } // mock send alarm and check next occurrence $alarm->sent_status = Tinebase_Model_Alarm::STATUS_PENDING; $alarm->sent_time = new Tinebase_DateTime('2012-10-24 22:01:03'); $alarm->alarm_time = new Tinebase_DateTime('2013-10-24 22:00:00'); $alarm->options = '{"custom":false,"minutes_before":2880,"recurid":"' . $persistentEvent->uid . '-2013-10-26 22:00:00"}'; $alarmBackend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Alarm', 'tableName' => 'alarm')); $updatedAlarm = $alarmBackend->update($alarm); $updatedAlarm->sent_time = Tinebase_DateTime::now(); $updatedAlarm->sent_status = Tinebase_Model_Alarm::STATUS_SUCCESS; $updatedAlarm->minutes_before = 2880; $this->_controller->adoptAlarmTime($persistentEvent, $updatedAlarm, 'instance'); $this->assertTrue(in_array($updatedAlarm->alarm_time->toString(), $expectedAlarmTimes), 'alarm time mismatch:' . print_r($updatedAlarm->toArray(), true) . ' expected: ' . print_r($expectedAlarmTimes, true)); }
/** * update application * * @param Tinebase_Model_Application $_application * @return Tinebase_Model_Application */ public function updateApplication(Tinebase_Model_Application $_application) { $backend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Application', 'tableName' => 'applications')); $result = $backend->update($_application); $this->_cleanCache($result); return $result; }
/** * delete notes * * @param Tinebase_Record_RecordSet $notes */ public function deleteNotes(Tinebase_Record_RecordSet $notes) { $sqlBackend = new Tinebase_Backend_Sql(array('tableName' => $this->getTableName(), 'modelName' => 'Tinebase_Model_Note'), $this->getAdapter()); foreach ($notes as $note) { Tinebase_Timemachine_ModificationLog::setRecordMetaData($note, 'delete', $note); $sqlBackend->update($note); } }
/** * save custom fields of record in its custom fields table * * @param Tinebase_Record_Interface $_record */ public function saveRecordCustomFields(Tinebase_Record_Interface $_record) { $applicationId = Tinebase_Application::getInstance()->getApplicationByName($_record->getApplication())->getId(); $appCustomFields = $this->getCustomFieldsForApplication($applicationId, get_class($_record), Tinebase_Model_CustomField_Grant::GRANT_WRITE); $this->resolveConfigGrants($appCustomFields); $existingCustomFields = $this->_getCustomFields($_record->getId()); $existingCustomFields->addIndices(array('customfield_id')); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updating custom fields for record of class ' . get_class($_record)); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Record cf values: ' . print_r($_record->customfields, TRUE)); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' App cf names: ' . print_r($appCustomFields->name, TRUE)); } foreach ($appCustomFields as $customField) { if (is_array($_record->customfields) && (isset($_record->customfields[$customField->name]) || array_key_exists($customField->name, $_record->customfields))) { $value = $_record->customfields[$customField->name]; $filtered = $existingCustomFields->filter('customfield_id', $customField->id); // we need to resolve the modelName and the record value if array is given (e.g. on updating customfield) if (strtolower($customField->definition['type']) == 'record') { $modelParts = explode('.', $customField->definition['recordConfig']['value']['records']); // get model parts from saved record class e.g. Tine.Admin.Model.Group $modelName = $modelParts[1] . '_Model_' . $modelParts[3]; if (is_array($value)) { $model = new $modelName(array(), TRUE); $value = $value[$model->getIdProperty()]; } // check if customfield value is the record itself if (get_class($_record) == $modelName && $_record->getId() == $value) { throw new Tinebase_Exception_Record_Validation('It is not allowed to add the same record as customfield record!'); } } switch (count($filtered)) { case 1: $cf = $filtered->getFirstRecord(); if ($customField->valueIsEmpty($value)) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Deleting cf value for ' . $customField->name); } $this->_backendValue->delete($cf); } else { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Updating value for ' . $customField->name . ' to ' . $value); } $cf->value = $value; $this->_backendValue->update($cf); } break; case 0: if (!$customField->valueIsEmpty($value)) { $cf = new Tinebase_Model_CustomField_Value(array('record_id' => $_record->getId(), 'customfield_id' => $customField->getId(), 'value' => $value)); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating value for ' . $customField->name . ' -> ' . $value); } $this->_backendValue->create($cf); } break; default: throw new Tinebase_Exception_UnexpectedValue('Oops, there should be only one custom field value here!'); } } } }
/** * update 7.8 -> 7.9 * * - add account module with the corresponding tables */ public function update_8() { $tableDeclaration = new Setup_Backend_Schema_Table_Xml(' <table> <name>humanresources_account</name> <version>1</version> <declaration> <field> <name>id</name> <type>text</type> <length>40</length> <notnull>true</notnull> </field> <field> <name>employee_id</name> <type>text</type> <length>40</length> <notnull>true</notnull> </field> <field> <name>year</name> <type>integer</type> <notnull>true</notnull> <length>4</length> </field> <field> <name>created_by</name> <type>text</type> <length>40</length> </field> <field> <name>creation_time</name> <type>datetime</type> </field> <field> <name>last_modified_by</name> <type>text</type> <length>40</length> </field> <field> <name>last_modified_time</name> <type>datetime</type> </field> <field> <name>is_deleted</name> <type>boolean</type> <default>false</default> </field> <field> <name>deleted_by</name> <type>text</type> <length>40</length> </field> <field> <name>deleted_time</name> <type>datetime</type> </field> <field> <name>seq</name> <type>integer</type> <notnull>true</notnull> <default>0</default> </field> <index> <name>id</name> <primary>true</primary> <field> <name>id</name> </field> </index> <index> <name>account::employee_id--employee::id</name> <field> <name>employee_id</name> </field> <foreign>true</foreign> <reference> <table>humanresources_employee</table> <field>id</field> </reference> </index> </declaration> </table> '); $this->_backend->createTable($tableDeclaration, 'HumanResources'); $tableDeclaration = new Setup_Backend_Schema_Table_Xml(' <table> <name>humanresources_extrafreetime</name> <version>1</version> <declaration> <field> <name>id</name> <type>text</type> <length>40</length> <notnull>true</notnull> </field> <field> <name>account_id</name> <type>text</type> <length>40</length> <notnull>true</notnull> </field> <field> <name>days</name> <type>integer</type> <notnull>true</notnull> <length>4</length> </field> <field> <name>type</name> <type>text</type> <length>64</length> <default>vacation</default> </field> <field> <name>description</name> <type>text</type> <length>255</length> <notnull>false</notnull> </field> <field> <name>created_by</name> <type>text</type> <length>40</length> </field> <field> <name>creation_time</name> <type>datetime</type> </field> <field> <name>last_modified_by</name> <type>text</type> <length>40</length> </field> <field> <name>last_modified_time</name> <type>datetime</type> </field> <field> <name>is_deleted</name> <type>boolean</type> <default>false</default> </field> <field> <name>deleted_by</name> <type>text</type> <length>40</length> </field> <field> <name>deleted_time</name> <type>datetime</type> </field> <field> <name>seq</name> <type>integer</type> <notnull>true</notnull> <default>0</default> </field> <index> <name>id</name> <primary>true</primary> <field> <name>id</name> </field> </index> <index> <name>exfreetime::account_id--account::id</name> <field> <name>account_id</name> </field> <foreign>true</foreign> <reference> <table>humanresources_account</table> <field>id</field> </reference> </index> </declaration> </table> '); $this->_backend->createTable($tableDeclaration, 'HumanResources'); // 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))); // create type config $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config')); $appId = Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId(); $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => HumanResources_Config::EXTRA_FREETIME_TYPE, 'value' => json_encode($freeTimeTypeConfig)))); // remove unused stati $filter = new Tinebase_Model_ConfigFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => HumanResources_Config::FREETIME_TYPE))); $record = $cb->search($filter)->getFirstRecord(); $result = json_decode($record->value); $newResult = array('name' => HumanResources_Config::FREETIME_TYPE); foreach ($result->records as $field) { if ($field->id == 'VACATION_EXTRA' || $field->id == 'VACATION_REMAINING') { continue; } $newResult['records'][] = $field; } $record->value = json_encode($newResult); $cb->update($record); $this->setApplicationVersion('HumanResources', '7.9'); }
/** * 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); } }
/** * testAdoptAlarmTimeOfYearlyEvent * * @see 0009320: Wrong notification on first occurrence exceptions */ public function testAdoptAlarmTimeOfYearlyEvent() { $event = $this->_getEvent(); $event->dtstart = new Tinebase_DateTime('2012-10-26 22:00:00'); $event->dtend = new Tinebase_DateTime('2012-10-27 21:59:00'); $event->is_all_day_event = 1; $event->rrule = 'FREQ=YEARLY;BYMONTH=10;BYMONTHDAY=27;INTERVAL=1'; $event->alarms = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm', array(new Tinebase_Model_Alarm(array('minutes_before' => 2880), TRUE))); $persistentEvent = $this->_controller->create($event); $alarm = $persistentEvent->alarms->getFirstRecord(); $this->_controller->adoptAlarmTime($persistentEvent, $alarm); $now = Tinebase_DateTime::now(); $year = $now->get('Y'); if ($now->isLater(new Tinebase_DateTime($year . '-10-24'))) { $year++; } $this->assertEquals($year . '-10-24 23:00:00', $alarm->alarm_time->toString(), print_r($alarm->toArray(), true)); // mock send alarm and check next occurrence $alarm->sent_status = Tinebase_Model_Alarm::STATUS_PENDING; $alarm->sent_time = new Tinebase_DateTime('2012-10-24 22:01:03'); $alarm->alarm_time = new Tinebase_DateTime('2013-10-24 22:00:00'); $alarm->options = '{"custom":false,"minutes_before":2880,"recurid":"' . $persistentEvent->uid . '-2013-10-26 22:00:00"}'; $alarmBackend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Alarm', 'tableName' => 'alarm')); $updatedAlarm = $alarmBackend->update($alarm); $updatedAlarm->sent_time = Tinebase_DateTime::now(); $updatedAlarm->sent_status = Tinebase_Model_Alarm::STATUS_SUCCESS; $updatedAlarm->minutes_before = 2880; $this->_controller->adoptAlarmTime($persistentEvent, $updatedAlarm, 'instance'); $this->assertEquals($year . '-10-24 23:00:00', $updatedAlarm->alarm_time->toString(), print_r($updatedAlarm->toArray(), true)); }
/** * update to 7.4 * * - save each state_id in an own field */ public function update_3() { // add a default value of "false", as PGSQL does allow notnull columns with default value null $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>state_id</name> <type>text</type> <length>128</length> <notnull>true</notnull> <default>false</default> </field> '); $this->_backend->addCol('state', $declaration); $this->_backend->dropIndex('state', 'user_id'); $declaration = new Setup_Backend_Schema_Index_Xml(' <index> <name>user_id--state_id</name> <unique>true</unique> <field> <name>user_id</name> </field> <field> <name>state_id</name> </field> </index> '); $this->_backend->addIndex('state', $declaration); $be = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_State', 'tableName' => 'state')); $allStates = $be->getAll(); foreach ($allStates as $oldState) { $oldData = Zend_Json::decode($oldState->data); foreach ($oldData as $stateId => $data) { $filter = new Tinebase_Model_StateFilter(array(array('field' => 'state_id', 'operator' => 'equals', 'value' => $stateId), array('field' => 'user_id', 'operator' => 'equals', 'value' => $oldState->user_id))); $result = $be->search($filter); try { if ($result->count()) { $record = $result->getFirstRecord(); $record->data = $data; $be->update($record); } else { $record = new Tinebase_Model_State(array('user_id' => $oldState->user_id, 'state_id' => $stateId, 'data' => $data)); $be->create($record); } } catch (Exception $e) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . 'Could not transfer old state: ' . $stateId . ': ' . print_r($data, 1)); Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . 'Exception Message: ' . $e->getMessage()); } } } $be->delete($oldState->getId()); } // remove the default value "false" again $declaration = new Setup_Backend_Schema_Field_Xml(' <field> <name>state_id</name> <type>text</type> <length>128</length> <notnull>true</notnull> </field> '); $this->_backend->alterCol('state', $declaration); $this->setApplicationVersion('Tinebase', '7.4'); $this->setTableVersion('state', 2); }
/** * update to 6.7 * * - remove costcenter from contract, create costcenter-employee-mm table */ public function update_6() { $table = new Setup_Backend_Schema_Table_Xml('<table> <name>humanresources_costcenter</name> <version>1</version> <declaration> <field> <name>id</name> <type>text</type> <length>40</length> <notnull>true</notnull> </field> <field> <name>start_date</name> <type>datetime</type> <notnull>false</notnull> </field> <field> <name>employee_id</name> <type>text</type> <length>40</length> <notnull>true</notnull> </field> <field> <name>cost_center_id</name> <type>text</type> <length>40</length> <notnull>true</notnull> </field> <field> <name>created_by</name> <type>text</type> <length>40</length> </field> <field> <name>creation_time</name> <type>datetime</type> </field> <field> <name>last_modified_by</name> <type>text</type> <length>40</length> </field> <field> <name>last_modified_time</name> <type>datetime</type> </field> <field> <name>is_deleted</name> <type>boolean</type> <default>false</default> </field> <field> <name>deleted_by</name> <type>text</type> <length>40</length> </field> <field> <name>deleted_time</name> <type>datetime</type> </field> <index> <name>id</name> <primary>true</primary> <field> <name>id</name> </field> </index> </declaration> </table>'); $this->_backend->createTable($table, 'HumanResources'); // find all contracts $select = $this->_db->select()->from(SQL_TABLE_PREFIX . 'humanresources_contract')->where('is_deleted=0'); $stmt = $select->query(); $contracts = $stmt->fetchAll(); $now = new Tinebase_DateTime(); $be = HumanResources_Controller_CostCenter::getInstance(); foreach ($contracts as $contract) { if ($contract['cost_center_id']) { $costcenter = new HumanResources_Model_CostCenter(array('employee_id' => $contract['employee_id'], 'cost_center_id' => $contract['cost_center_id'], 'start_date' => $contract['start_date'] ? $contract['start_date'] : (string) $now)); $be->create($costcenter); } } // remove costcenter property from contract try { $this->_backend->dropCol('humanresources_contract', 'cost_center_id'); } catch (Exception $e) { } // create type config $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config')); $appId = Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId(); // update vacation status config $kfc = $cb->getByProperty('freetimeStatus'); $kfc->name = HumanResources_Config::VACATION_STATUS; $cb->update($kfc); // 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)))); // update sickness records, set status = excused $filter = new HumanResources_Model_FreeTimeFilter(array(array('field' => 'type', 'operator' => 'equals', 'value' => 'SICKNESS'))); $ftb = new HumanResources_Backend_FreeTime(); $records = $ftb->search($filter); $ftb->updateMultiple($records->id, array('status' => 'EXCUSED')); // create persistenfilters $pfe = Tinebase_PersistentFilter::getInstance(); $commonValues = array('account_id' => NULL, 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId(), 'model' => 'HumanResources_Model_EmployeeFilter'); $pfe->createDuringSetup(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array('name' => "Currently employed", 'description' => "Employees which are currently employed", 'filters' => array(array('field' => 'is_employed', 'operator' => 'equals', 'value' => 1)))))); // add workingtime json $field = '<field> <name>workingtime_json</name> <type>text</type> <length>1024</length> <notnull>true</notnull> </field>'; $declaration = new Setup_Backend_Schema_Field_Xml($field); $this->_backend->addCol('humanresources_contract', $declaration); $this->setTableVersion('humanresources_contract', '4'); // change freetime type field length $field = '<field> <name>type</name> <type>text</type> <length>64</length> <default>vacation</default> </field>'; $declaration = new Setup_Backend_Schema_Field_Xml($field); $this->_backend->alterCol('humanresources_freetime', $declaration); $this->setTableVersion('humanresources_freetime', '3'); // add vacation types $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config', 'modlogActive' => FALSE)); $appId = Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId(); $filter = new Tinebase_Model_ConfigFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => HumanResources_Config::FREETIME_TYPE))); $ftt = $cb->search($filter)->getFirstRecord(); $val = json_decode($ftt->value); $existing = $val->records; $existing[] = array('id' => 'VACATION_REMAINING', 'value' => 'Remaining Vacation', 'icon' => 'images/oxygen/16x16/actions/book2.png', 'system' => TRUE); $existing[] = array('id' => 'VACATION_EXTRA', 'value' => 'Extra Vacation', 'icon' => 'images/oxygen/16x16/actions/book2.png', 'system' => TRUE); $freeTimeTypeConfig = array('name' => HumanResources_Config::FREETIME_TYPE, 'records' => $existing); $ftt->value = json_encode($freeTimeTypeConfig); $cb->update($ftt); // update json of workingtime models if they still exist $controller = HumanResources_Controller_WorkingTime::getInstance(); $controller->modlogActive(FALSE); $filter = new HumanResources_Model_WorkingTimeFilter(array()); //array('field' => 'working_hours', 'operator' => 'equals', 'value' => '40'))); $allWT = $controller->search($filter); $wt40 = $allWT->filter('working_hours', "40"); foreach ($wt40 as $wt) { $wt->json = '{"days":[8,8,8,8,8,0,0]}'; $controller->update($wt); } $wt37 = $allWT->filter('working_hours', "37.5"); foreach ($wt37 as $wt) { $wt->json = '{"days":[8,8,8,8,5.5,0,0]}'; $controller->update($wt); } $wt20 = $allWT->filter('working_hours', "20"); foreach ($wt20 as $wt) { $wt->json = '{"days":[4,4,4,4,4,0,0]}'; $controller->update($wt); } $this->setApplicationVersion('HumanResources', '6.7'); }