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()); } }
/** * get last job of this name * * @param string $name * @return Tinebase_Model_AsyncJob */ public function getLastJob($name) { $filter = new Tinebase_Model_AsyncJobFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => $name))); $pagination = new Tinebase_Model_Pagination(array('sort' => 'start_time', 'dir' => 'DESC', 'limit' => 1)); $jobs = $this->_backend->search($filter, $pagination); $lastJob = $jobs->getFirstRecord(); return $lastJob; }
/** * only keep the last 60 jobs and purge all other * * @param Tinebase_Model_AsyncJob $job */ protected function _purgeOldJobs(Tinebase_Model_AsyncJob $job) { $deleteBefore = $job->seq - 60; if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Purging old Jobs before sequence: ' . $deleteBefore); } // avoid overloading by deleting old jobs in batches only $idsToDelete = $this->_backend->search(new Tinebase_Model_AsyncJobFilter(array(array('field' => 'seq', 'operator' => 'less', 'value' => $deleteBefore))), new Tinebase_Model_Pagination(array('limit' => 10000)), true); $this->_backend->delete($idsToDelete); }
/** * 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; }
/** * 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); }
/** * get list of records * * @param Tinebase_Model_Filter_FilterGroup|optional $_filter * @param Tinebase_Model_Pagination|optional $_pagination * @param boolean|array $_getRelations * @param boolean $_onlyIds * @param string $_action for right/acl check * @return Tinebase_Record_RecordSet|array */ public function search(Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Record_Interface $_pagination = NULL, $_getRelations = FALSE, $_onlyIds = FALSE, $_action = 'get') { //@TODO support more appfilter combinations when needed $appFilter = $_filter->getFilter('application_id'); $app = Tinebase_Application::getInstance()->getApplicationById($appFilter->getValue()); $appname = $app->name; if (!Tinebase_Core::getUser()->hasRight($appname, 'admin')) { throw new Tinebase_Exception_AccessDenied("You do not have admin rights for {$appname}"); } $configRecords = new Tinebase_Record_RecordSet('Tinebase_Model_Config'); $appConfigObject = Tinebase_Config::getAppConfig($appname); $appConfigDefinitions = $appConfigObject->getProperties(); $appDBConfig = $this->_configBackend->search($_filter); foreach ($appConfigDefinitions as $name => $definition) { if (array_key_exists('setByAdminModule', $definition) && $definition['setByAdminModule']) { $configFromFile = $appConfigObject->getConfigFileSection($name); $configFromDb = $appDBConfig->filter('name', $name)->getFirstRecord(); if ($configFromDb && !$configFromFile) { $configRecord = $this->_mergeDefinition($configFromDb, $definition); $configRecord->source = Tinebase_Model_Config::SOURCE_DB; } else { $definition['id'] = 'virtual-' . $name; $definition['application_id'] = $app->getId(); $definition['name'] = $name; $definition['value'] = json_encode($configFromFile); $definition['source'] = is_null($configFromFile) ? Tinebase_Model_Config::SOURCE_DEFAULT : Tinebase_Model_Config::SOURCE_FILE; $configRecord = new Tinebase_Model_Config($definition); } // exclude config's which the admin can't set if ($configRecord->source != Tinebase_Model_Config::SOURCE_FILE) { $configRecords->addRecord($configRecord); } } } return $configRecords; }
/** * 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'); }
/** * 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); }
/** * get all alarms of given record(s) / adds record_id index to result set * * @param string $_model model to get alarms for * @param string|array|Tinebase_Record_Interface|Tinebase_Record_RecordSet $_recordId record id(s) to get alarms for * @param boolean $_onlyIds * @return Tinebase_Record_RecordSet|array of ids */ public function getAlarmsOfRecord($_model, $_recordId, $_onlyIds = FALSE) { if ($_recordId instanceof Tinebase_Record_RecordSet) { $recordId = $_recordId->getArrayOfIds(); } else { if ($_recordId instanceof Tinebase_Record_Interface) { $recordId = $_recordId->getId(); } else { $recordId = $_recordId; } } //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " model: '$_model' id:" . print_r((array)$recordId, true)); $filter = new Tinebase_Model_AlarmFilter(array(array('field' => 'model', 'operator' => 'equals', 'value' => $_model), array('field' => 'record_id', 'operator' => 'in', 'value' => (array) $recordId))); $result = $this->_backend->search($filter, NULL, $_onlyIds); // NOTE: Adding indices to empty recordsets breaks empty tests if (count($result) > 0 && $result instanceof Tinebase_Record_RecordSet) { $result->addIndices(array('record_id')); } return $result; }
/** * fetch all user ids from accounts table: updating from an old version fails if the modlog fields don't exist * * @return array */ public function getAllUserIdsFromSqlBackend() { $sqlbackend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_FullUser', 'tableName' => $this->_tableName)); $userIds = $sqlbackend->search(null, null, Tinebase_Backend_Sql_Abstract::IDCOL); return $userIds; }
/** * 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); }
/** * get list of custom field values * * @param Tinebase_Model_Filter_FilterGroup|optional $_filter * @param Tinebase_Model_Pagination|optional $_pagination * @param bool $_getRelations (unused) * @param boolean $_onlyIds (unused) * @return Tinebase_Record_RecordSet */ public function search(Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Record_Interface $_pagination = NULL, $_getRelations = FALSE, $_onlyIds = FALSE) { $result = $this->_backendValue->search($_filter, $_pagination); return $result; }
/** * Search for records matching given filter * * @param Tinebase_Model_Filter_FilterGroup $_filter * @param Tinebase_Model_Pagination $_pagination * @param boolean $_onlyIds * @return Tinebase_Record_RecordSet|array */ public function search(Tinebase_Model_Filter_FilterGroup $_filter = NULL, Tinebase_Model_Pagination $_pagination = NULL, $_onlyIds = FALSE) { $backend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Relation', 'tableName' => 'relations')); $_filter->addFilter(new Tinebase_Model_Filter_Bool('is_deleted', 'equals', (int) FALSE)); return $backend->search($_filter, $_pagination, $_onlyIds); }
/** * 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'); }
/** * 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'); }
/** * update payment methods */ public function update_31() { $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config')); $appId = Tinebase_Application::getInstance()->getApplicationByName('Sales')->getId(); $idToDelete = $cb->search(new Tinebase_Model_ConfigFilter(array(array('field' => 'application_id', 'operator' => 'equals', 'value' => $appId), array('field' => 'name', 'operator' => 'equals', 'value' => Sales_Config::PAYMENT_METHODS)), 'AND'), null, true); if (isset($idToDelete[0])) { $cb->delete($idToDelete[0]); } // 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), array('id' => 'CANCELLATION', 'value' => 'Cancellation', 'system' => true), array('id' => 'CREDIT', 'value' => 'Credit', 'system' => true), array('id' => 'CREDIT CARD', 'value' => 'Credit card', 'system' => true), array('id' => 'PAYPAL', 'value' => 'Paypal', 'system' => true))); $cb->create(new Tinebase_Model_Config(array('application_id' => $appId, 'name' => Sales_Config::PAYMENT_METHODS, 'value' => json_encode($tc)))); $this->setApplicationVersion('Sales', '8.32'); }