Example #1
0
 /**
  * sets record related properties
  * 
  * @param string _name of property
  * @param mixed _value of property
  * @throws Tinebase_Exception_InvalidArgument
  */
 public function __set($_name, $_value)
 {
     switch ($_name) {
         case 'application_id':
             $_value = Tinebase_Model_Application::convertApplicationIdToInt($_value);
     }
     parent::__set($_name, $_value);
 }
 /**
  * sets record related properties
  * 
  * @param string _name of property
  * @param mixed _value of property
  * @throws Tinebase_Exception_InvalidArgument
  */
 public function __set($_name, $_value)
 {
     switch ($_name) {
         case 'application_id':
             $_value = Tinebase_Model_Application::convertApplicationIdToInt($_value);
     }
     /**
      * @TODO
      * - ask model for datatype
      * - cope with record/recordSet
      */
     if (is_string($_value) && strlen($_value) == 19 && preg_match('/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$/', $_value)) {
         $_value = new Tinebase_DateTime($_value);
     }
     parent::__set($_name, $_value);
 }
Example #3
0
 /**
  * returns one config value identified by config name and application id
  * -> value in config.inc.php overwrites value in db if $_fromFile is TRUE
  * 
  * @deprecated
  * @param   string      $_name config name/key
  * @param   string      $_applicationId application id [optional]
  * @param   mixed       $_default the default value [optional]
  * @param   boolean     $_fromFile get from config.inc.php [optional]
  * @return  Tinebase_Model_Config  the config record
  * @throws  Tinebase_Exception_NotFound
  */
 public function getConfig($_name, $_applicationId = NULL, $_default = NULL, $_fromFile = TRUE)
 {
     $applicationId = $_applicationId !== NULL ? Tinebase_Model_Application::convertApplicationIdToInt($_applicationId) : Tinebase_Application::getInstance()->getApplicationByName('Tinebase')->getId();
     $result = $this->_loadConfig($_name, $applicationId);
     if (!$result) {
         $result = new Tinebase_Model_Config(array('application_id' => $applicationId, 'name' => $_name, 'value' => $_default), TRUE);
     }
     // check config.inc.php and get value from there
     $configFileData = $this->_getConfigFileData();
     if ($_fromFile && array_key_exists($_name, $configFileData)) {
         Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Overwriting config setting "' . $_name . '" with value from config.inc.php.');
         $result->value = $configFileData[$_name];
     }
     return $result;
 }
Example #4
0
 /**
  * load a config record from database
  * 
  * @param  string                   $_name
  * @param  mixed                    $_application
  * @return Tinebase_Model_Config
  */
 protected function _loadConfig($_name, $_application = null)
 {
     $applicationId = Tinebase_Model_Application::convertApplicationIdToInt($_application ? $_application : $this->_appName);
     $cache = Tinebase_Core::getCache();
     $cacheId = '_loadConfig_' . sha1($applicationId . $_name);
     if ($cache && $cache->test($cacheId)) {
         $result = $cache->load($cacheId);
         if (is_object($result)) {
             return $result;
         }
     }
     $filter = new Tinebase_Model_ConfigFilter(array(array('field' => 'application_id', 'operator' => 'equals', 'value' => $applicationId), array('field' => 'name', 'operator' => 'equals', 'value' => $_name)));
     $result = $this->_getBackend()->search($filter)->getFirstRecord();
     if ($cache) {
         $cache->save($result, $cacheId, array('config'), 60);
     }
     return $result;
 }
 /**
  * add table to tine registry
  *
  * @param Tinebase_Model_Application
  * @param string name of table
  * @param int version of table
  * @return int
  */
 public function addApplicationTable($_applicationId, $_name, $_version)
 {
     $applicationId = Tinebase_Model_Application::convertApplicationIdToInt($_applicationId);
     $applicationData = array('application_id' => $applicationId, 'name' => $_name, 'version' => $_version);
     $this->_getDb()->insert(SQL_TABLE_PREFIX . 'application_tables', $applicationData);
 }
 /**
  * fill class cache with all config records for this app
  */
 protected function _loadAllAppConfigsInCache()
 {
     if (empty($this->_appName)) {
         if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' appName not set');
         }
         $this->_cachedApplicationConfig = array();
     }
     if (!Tinebase_Application::getInstance()->getInstance()->isInstalled('Tinebase')) {
         $this->_cachedApplicationConfig = array();
         return;
     }
     $cache = Tinebase_Core::getCache();
     if (!is_object($cache)) {
         Tinebase_Core::setupCache();
         $cache = Tinebase_Core::getCache();
     }
     if (Tinebase_Core::get(Tinebase_Core::SHAREDCACHE)) {
         if ($cachedApplicationConfig = $cache->load('cachedAppConfig_' . $this->_appName)) {
             $this->_cachedApplicationConfig = $cachedApplicationConfig;
             return;
         }
     }
     try {
         $applicationId = Tinebase_Model_Application::convertApplicationIdToInt($this->_appName);
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Loading all configs for app ' . $this->_appName);
         }
         $filter = new Tinebase_Model_ConfigFilter(array(array('field' => 'application_id', 'operator' => 'equals', 'value' => $applicationId)));
         $allConfigs = $this->_getBackend()->search($filter);
     } catch (Zend_Db_Exception $zdae) {
         // DB might not exist or tables are not created, yet
         Tinebase_Exception::log($zdae);
         $this->_cachedApplicationConfig = array();
         return;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Found ' . count($allConfigs) . ' configs.');
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($allConfigs->toArray(), TRUE));
     }
     foreach ($allConfigs as $config) {
         $this->_cachedApplicationConfig[$config->name] = $config;
     }
     if (Tinebase_Core::get(Tinebase_Core::SHAREDCACHE)) {
         $cache->save($this->_cachedApplicationConfig, 'cachedAppConfig_' . $this->_appName);
     }
 }
Example #7
0
 /**
  * delete custom fields for an application
  *
  * @param string|Tinebase_Model_Application $_applicationId
  * @return integer numer of deleted custom fields
  */
 public function deleteCustomFieldsForApplication($_applicationId)
 {
     $this->_clearCache();
     $applicationId = Tinebase_Model_Application::convertApplicationIdToInt($_applicationId);
     $filterValues = array(array('field' => 'application_id', 'operator' => 'equals', 'value' => $applicationId));
     $filter = new Tinebase_Model_CustomField_ConfigFilter($filterValues);
     $filter->customfieldACLChecks(FALSE);
     $customFields = $this->_backendConfig->search($filter);
     $deletedCount = 0;
     foreach ($customFields as $customField) {
         $this->deleteCustomField($customField);
         $deletedCount++;
     }
     return $deletedCount;
 }
Example #8
0
 /**
  * check if one of the roles the user is in has a given right for a given application
  * - admin right includes all other rights
  *
  * @param   string|Tinebase_Model_Application $_application the application (one of: app name, id or record)
  * @param   int $_accountId the numeric id of a user account
  * @param   int $_right the right to check for
  * @return  bool
  * @throws  Tinebase_Exception_AccessDenied
  */
 public function hasRight($_application, $_accountId, $_right)
 {
     try {
         $appId = Tinebase_Model_Application::convertApplicationIdToInt($_application);
     } catch (Tinebase_Exception_NotFound $tenf) {
         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Application ' . $_application . ' is not installed.');
         return false;
     }
     $application = Tinebase_Application::getInstance()->getApplicationById($appId);
     if ($application->status != 'enabled') {
         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Application ' . $_application . ' is disabled.');
         return false;
     }
     $roleMemberships = $this->getRoleMemberships($_accountId);
     if (empty($roleMemberships)) {
         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' ' . $_accountId . ' has no role memberships.');
         return false;
     }
     $select = $this->_roleRightsTable->select();
     $select->where($this->_db->quoteInto($this->_db->quoteIdentifier('role_id') . ' IN (?)', $roleMemberships))->where('(' . $this->_db->quoteInto($this->_db->quoteIdentifier('right') . ' = ?', $_right) . ' OR ' . $this->_db->quoteInto($this->_db->quoteIdentifier('right') . ' = ?', Tinebase_Acl_Rights::ADMIN) . ')')->where($this->_db->quoteInto($this->_db->quoteIdentifier('application_id') . ' = ?', $application->getId()));
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $select->__toString());
     if (!($row = $this->_roleRightsTable->fetchRow($select))) {
         $result = false;
     } else {
         $result = true;
     }
     return $result;
 }