/**
  * 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 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()
 {
     // 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');
 }
 /**
  * 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))));
 }
示例#6
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
  */
 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
  */
 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
  */
 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))));
 }
 /**
  * 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))));
 }
 /**
  * add one record
  *
  * @param   Tinebase_Record_Interface $_record
  * @return  Tinebase_Record_Interface
  * @throws  Tinebase_Exception_AccessDenied
  * @throws  Tinebase_Exception_Record_Validation
  */
 public function create(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}");
     }
     $createdRecord = $this->_configBackend->create($_record);
     return $this->get($createdRecord->getId());
 }
示例#12
0
 /**
  * create new job
  * 
  * @param string $_name
  * @param integer $_maxSeq
  * @param int $timeout
  * @return Tinebase_Model_AsyncJob
  */
 protected function _createNewJob($_name, $_maxSeq, $_timeout)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Creating new Job ' . $_name);
     }
     $date = new Tinebase_DateTime();
     $date->addSecond($_timeout);
     $job = new Tinebase_Model_AsyncJob(array('name' => $_name, 'start_time' => new Tinebase_DateTime(), 'end_time' => $date, 'status' => Tinebase_Model_AsyncJob::STATUS_RUNNING, 'seq' => $_maxSeq + 1));
     return $this->_backend->create($job);
 }
示例#13
0
 /**
  * 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);
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
         }
     }
 }
示例#18
0
 /**
  * set grants for custom field
  *
  * @param   string|Tinebase_Model_CustomField_Config $_customfieldId
  * @param   array $_grants list of grants to add
  * @param   string $_accountType
  * @param   int $_accountId
  * @return  void
  */
 public function setGrants($_customfieldId, $_grants = array(), $_accountType = NULL, $_accountId = NULL)
 {
     $cfId = $_customfieldId instanceof Tinebase_Model_CustomField_Config ? $_customfieldId->getId() : $_customfieldId;
     try {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting grants for custom field ' . $cfId . ' -> ' . print_r($_grants, TRUE));
         }
         $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
         $this->_backendACL->deleteByProperty($cfId, 'customfield_id');
         foreach ($_grants as $grant) {
             if (in_array($grant, Tinebase_Model_CustomField_Grant::getAllGrants())) {
                 $newGrant = new Tinebase_Model_CustomField_Grant(array('customfield_id' => $cfId, 'account_type' => $_accountType !== NULL ? $_accountType : Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE, 'account_id' => $_accountId !== NULL ? $_accountId : 0, 'account_grant' => $grant));
                 $this->_backendACL->create($newGrant);
             }
         }
         Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
         $this->_clearCache();
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw new Tinebase_Exception_Backend($e->getMessage());
     }
 }
 /**
  * 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 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');
 }
 /**
  * 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);
 }
 /**
  * init key fields
  */
 protected function _initializeKeyFields()
 {
     $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)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'name' => Addressbook_Config::CONTACT_SALUTATION, 'value' => json_encode($keyfieldConfig))));
 }
 /**
  * generates path for the record
  *
  * @param Tinebase_Record_Abstract $record
  * @param boolean $rebuildRecursively
  * @return Tinebase_Record_RecordSet
  *
  * TODO what about acl? the account who creates the path probably does not see all relations ...
  */
 public function generatePathForRecord(Tinebase_Record_Abstract $record, $rebuildRecursively = false)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Generate path for ' . get_class($record) . ' record with id ' . $record->getId());
     }
     $recordController = Tinebase_Core::getApplicationInstance(get_class($record));
     // if we rebuild recursively, dont do any tree operation, just rebuild the paths for the record and be done with it
     if (false === $rebuildRecursively) {
         // fetch full record + check acl
         $record = $recordController->get($record->getId());
         $currentPaths = Tinebase_Record_Path::getInstance()->getPathsForRecords($record);
     }
     $newPaths = new Tinebase_Record_RecordSet('Tinebase_Model_Path');
     // fetch all parent -> child relations and add to path
     $newPaths->merge($this->_getPathsOfRecord($record, $rebuildRecursively));
     if (method_exists($recordController, 'generatePathForRecord')) {
         $newPaths->merge($recordController->generatePathForRecord($record));
     }
     // if we rebuild recursively, dont do any tree operation, just rebuild the paths for the record and be done with it
     if (false === $rebuildRecursively) {
         //compare currentPaths with newPaths to find out if we need to make subtree updates
         //we should do this before the new paths of the current record have been persisted to DB!
         $currentShadowPathOffset = array();
         foreach ($currentPaths as $offset => $path) {
             $currentShadowPathOffset[$path->shadow_path] = $offset;
         }
         $newShadowPathOffset = array();
         foreach ($newPaths as $offset => $path) {
             $newShadowPathOffset[$path->shadow_path] = $offset;
         }
         $toDelete = array();
         $anyOldOffset = null;
         foreach ($currentShadowPathOffset as $shadowPath => $offset) {
             $anyOldOffset = $offset;
             // parent path has been deleted!
             if (false === isset($newShadowPathOffset[$shadowPath])) {
                 $toDelete[] = $shadowPath;
                 continue;
             }
             $currentPath = $currentPaths[$offset];
             $newPath = $newPaths[$newShadowPathOffset[$shadowPath]];
             // path changed (a title was updated or similar)
             if ($currentPath->path !== $newPath->path) {
                 // update ... set path = REPLACE(path, $currentPath->path, $newPath->path) where shadow_path LIKE '$shadowPath/%'
                 $this->_backend->replacePathForShadowPathTree($shadowPath, $currentPath->path, $newPath->path);
             }
             unset($newShadowPathOffset[$shadowPath]);
         }
         // new parents
         if (count($newShadowPathOffset) > 0 && null !== $anyOldOffset) {
             $anyPath = $currentPaths[$anyOldOffset];
             $newParents = array_values($newShadowPathOffset);
             foreach ($newParents as $newParentOffset) {
                 $newParent = $newPaths[$newParentOffset];
                 // insert into ... select
                 // REPLACE(path, $anyPath->path, $newParent->path) as path,
                 // REPLACE(shadow_path, $anyPath->shadow_path, $newParent->shadow_path) as shadow_path
                 // from ... where shadow_path LIKE '$anyPath->shadow_path/%'
                 $this->_backend->copyTreeByShadowPath($anyPath->shadow_path, $newParent->path, $anyPath->path, $newParent->shadow_path, $anyPath->shadow_path);
             }
         }
         //execute deletes only now, important to make 100% sure "new parents" just above still has data to work on!
         foreach ($toDelete as $delete) {
             // delete where shadow_path LIKE '$delete/%'
             $this->_backend->deleteForShadowPathTree($delete);
         }
     }
     // delete current paths of this record
     $this->deletePathsForRecord($record);
     // recreate new paths of this record
     foreach ($newPaths as $path) {
         $this->_backend->create($path);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Created ' . count($newPaths) . ' paths.');
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r($newPaths->toArray(), true));
     }
     return $newPaths;
 }
 /**
  * create INTERNET_ACCESS keyfield
  */
 public static function createInternetAccessKeyfield()
 {
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $keyfieldConfig = array('name' => Courses_Config::INTERNET_ACCESS, 'records' => array(array('id' => 'ON', 'value' => 'On', 'image' => 'images/oxygen/16x16/actions/dialog-apply.png', 'system' => true), array('id' => 'OFF', 'value' => 'Off', 'image' => 'images/oxygen/16x16/actions/dialog-cancel.png', 'system' => true), array('id' => 'FILTERED', 'value' => 'Filtered', 'image' => 'images/oxygen/16x16/actions/view-choose.png', 'system' => true)));
     $cb->create(new Tinebase_Model_Config(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Courses')->getId(), 'name' => Courses_Config::INTERNET_ACCESS, 'value' => json_encode($keyfieldConfig))));
 }
 /**
  * - create sales product table
  * - copy products from metacrm_products to new table
  * 
  */
 public function update_1()
 {
     $tableDefinition = '
         <table>
         <name>sales_products</name>
         <version>1</version>
         <declaration>
             <field>
                 <name>id</name>
                 <type>text</type>
                 <length>40</length>
                 <notnull>true</notnull>
             </field>
             <field>
                 <name>name</name>
                 <type>text</type>
                 <length>255</length>
                 <notnull>true</notnull>
             </field>
             <field>
                 <name>description</name>
                 <type>text</type>
                 <notnull>false</notnull>
             </field>
             <field>
                 <name>price</name>
                 <type>float</type>
                 <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>                
             <index>
                 <name>id</name>
                 <primary>true</primary>
                 <field>
                     <name>id</name>
                 </field>
             </index>
         </declaration>
     </table>
     ';
     $table = Setup_Backend_Schema_Table_Factory::factory('Xml', $tableDefinition);
     $this->_backend->createTable($table);
     Tinebase_Application::getInstance()->addApplicationTable(Tinebase_Application::getInstance()->getApplicationByName('Sales'), 'sales_products', 1);
     // check if crm is installed first
     if (Setup_Controller::getInstance()->isInstalled('Crm')) {
         // add products from crm
         $select = $this->_db->select()->from(SQL_TABLE_PREFIX . 'metacrm_products');
         $stmt = $this->_db->query($select);
         $queryResult = $stmt->fetchAll();
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . print_r($queryResult, TRUE));
         }
         // insert values into products table
         $productsBackend = new Tinebase_Backend_Sql(array('modelName' => 'Sales_Model_Product', 'tableName' => 'sales_products'));
         foreach ($queryResult as $row) {
             $products = new Sales_Model_Product(array('id' => $row['id'], 'name' => $row['productsource'], 'price' => $row['price']));
             $productsBackend->create($products);
         }
     }
     $this->setApplicationVersion('Sales', '2.2');
 }
 /**
  * update from 0.5 to 2.0
  * - copy entries from timetracker_timesheet_custom to customfield table
  * - drop timetracker_timesheet_custom table
  */
 public function update_5()
 {
     // get all timetracker/timesheet custom fields
     $customfields = Tinebase_CustomField::getInstance()->getCustomFieldsForApplication(Tinebase_Application::getInstance()->getApplicationByName('Timetracker'), 'Timetracker_Model_Timesheet');
     if (count($customfields) > 0) {
         $customfields->addIndices(array('name'));
         // get all custom field values
         $select = $this->_db->select()->from(SQL_TABLE_PREFIX . 'timetracker_timesheet_custom')->order('name ASC');
         $stmt = $this->_db->query($select);
         $queryResult = $stmt->fetchAll();
         //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . print_r($queryResult, TRUE));
         // insert values into customfield table
         $cfValueBackend = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_CustomField_Value', 'tableName' => 'customfield'));
         foreach ($queryResult as $row) {
             if (!isset($customfield) || $customfield->name != $row['name']) {
                 $customfield = $customfields->filter('name', $row['name'])->getFirstRecord();
             }
             $cfValue = new Tinebase_Model_CustomField_Value(array('record_id' => $row['record_id'], 'customfield_id' => $customfield->getId(), 'value' => $row['value']));
             $cfValueBackend->create($cfValue);
         }
     }
     // drop obsolete table
     $this->dropTable('timetracker_timesheet_custom');
     $this->setApplicationVersion('Timetracker', '2.0');
 }
 /**
  * update to 8.28
  *
  *  - add columns
  */
 public function update_27()
 {
     $this->validateTableVersion('sales_products', 5);
     // create keyfield config
     $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))));
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>number</name>
             <type>text</type>
             <length>64</length>
             <notnull>true</notnull>
         </field>
     ');
     $this->_backend->addCol('sales_products', $declaration);
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>gtin</name>
             <type>text</type>
             <length>64</length>
             <notnull>false</notnull>
         </field>
     ');
     $this->_backend->addCol('sales_products', $declaration);
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>purchaseprice</name>
             <type>float</type>
             <notnull>false</notnull>
         </field>
     ');
     $this->_backend->addCol('sales_products', $declaration);
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>salesprice</name>
             <type>float</type>
             <notnull>false</notnull>
         </field>
     ');
     $this->_backend->alterCol('sales_products', $declaration, 'price');
     $this->setTableVersion('sales_products', 6);
     $this->setApplicationVersion('Sales', '8.28');
 }
示例#29
0
 /**
  * update to 5.3
  *  - move task priority to key field config
  */
 public function update_2()
 {
     $tasksAppId = Tinebase_Application::getInstance()->getApplicationByName('Tasks')->getId();
     // alter status_id -> status
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>priority</name>
             <type>text</type>
             <length>40</length>
             <default>NORMAL</default>
             <notnull>true</notnull>
         </field>');
     $this->_backend->alterCol('tasks', $declaration);
     // create status config
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $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' => $tasksAppId, 'name' => Tasks_Config::TASK_PRIORITY, 'value' => json_encode($tasksPriorityConfig))));
     // update task table
     foreach ($tasksPriorityConfig['records'] as $index => $prioData) {
         $this->_db->update(SQL_TABLE_PREFIX . 'tasks', array('priority' => $prioData['id']), "`priority` = '{$index}'");
     }
     $this->setTableVersion('tasks', '5');
     $this->setApplicationVersion('Tasks', '5.3');
 }
 /**
  * create customfield value (tr_budget) for timeaccounts starting with S-AB and moves the value from budget to tr_budget
  */
 public function moveBudget()
 {
     $filter = new Timetracker_Model_TimeaccountFilter(array(array('field' => 'budget', 'operator' => 'greater', 'value' => 0), array('field' => 'number', 'operator' => 'startswith', 'value' => 'S-AB')));
     $taController = Timetracker_Controller_Timeaccount::getInstance();
     $tas = $taController->search($filter);
     $cfi = Tinebase_CustomField::getInstance();
     $cfb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_CustomField_Value', 'tableName' => 'customfield'));
     $trBudget = $cfi->getCustomFieldByNameAndApplication('Timetracker', 'tr_budget');
     if (!$trBudget) {
         die('No CustomField tr_budget found!');
     }
     foreach ($tas as $ta) {
         echo 'Working on ' . $ta->title . PHP_EOL;
         $cf = new Tinebase_Model_CustomField_Value(array('record_id' => $ta->getId(), 'customfield_id' => $trBudget->getId(), 'value' => $ta->budget));
         $cfb->create($cf);
         $ta->budget = NULL;
         $taController->update($ta);
     }
     echo PHP_EOL;
     echo 'done!' . PHP_EOL;
 }