/**
  * resolve node container and path
  * 
  * (1) add path to records 
  * (2) replace name with container record, if node name is a container id 
  *     / path is toplevel (shared/personal with useraccount
  * (3) add account grants of acl container to node
  * 
  * @param Tinebase_Record_RecordSet|Tinebase_Model_Tree_Node $_records
  * @param Tinebase_Model_Tree_Node_Path $_path
  * @param Tinebase_Model_Container $_container
  */
 public function resolveContainerAndAddPath($_records, Tinebase_Model_Tree_Node_Path $_path, Tinebase_Model_Container $_container = NULL)
 {
     $records = $_records instanceof Tinebase_Model_Tree_Node ? new Tinebase_Record_RecordSet('Tinebase_Model_Tree_Node', array($_records)) : $_records;
     if (!$_path->container) {
         // fetch top level container nodes
         if ($_container === NULL) {
             $containerIds = $_records->name;
             $containers = Tinebase_Container::getInstance()->getMultiple($containerIds);
         } else {
             $containers = new Tinebase_Record_RecordSet('Tinebase_Model_Container', array($_container));
         }
     }
     $app = Tinebase_Application::getInstance()->getApplicationByName($this->_applicationName);
     $flatpathWithoutBasepath = Tinebase_Model_Tree_Node_Path::removeAppIdFromPath($_path->flatpath, $app);
     if ($records) {
         foreach ($records as $record) {
             $record->path = $flatpathWithoutBasepath . '/' . $record->name;
             $aclContainer = NULL;
             if (!$_path->container) {
                 // resolve container
                 if (!$record->name instanceof Tinebase_Model_Container) {
                     $idx = $containers->getIndexById($record->name);
                     if ($idx !== FALSE) {
                         $aclContainer = $containers[$idx];
                         $record->name = $aclContainer;
                         $record->path = $flatpathWithoutBasepath . '/' . $record->name->name;
                     }
                 }
             } else {
                 $aclContainer = $_path->container;
             }
             if ($aclContainer) {
                 $record->account_grants = Tinebase_Container::getInstance()->getGrantsOfAccount(Tinebase_Core::getUser(), $aclContainer)->toArray();
                 $aclContainer->account_grants = $record->account_grants;
                 // needed for sorting
                 $record->container_name = $aclContainer->name;
             }
         }
     }
 }
 /**
  * updates installed applications. does nothing if no applications are installed
  *
  * @param Tinebase_Record_RecordSet $_applications
  * @return  array   messages
  */
 public function updateApplications(Tinebase_Record_RecordSet $_applications)
 {
     $this->_updatedApplications = 0;
     $smallestMajorVersion = NULL;
     $biggestMajorVersion = NULL;
     //find smallest major version
     foreach ($_applications as $application) {
         if ($smallestMajorVersion === NULL || $application->getMajorVersion() < $smallestMajorVersion) {
             $smallestMajorVersion = $application->getMajorVersion();
         }
         if ($biggestMajorVersion === NULL || $application->getMajorVersion() > $biggestMajorVersion) {
             $biggestMajorVersion = $application->getMajorVersion();
         }
     }
     $messages = array();
     // update tinebase first (to biggest major version)
     $tinebase = $_applications->filter('name', 'Tinebase')->getFirstRecord();
     if (!empty($tinebase)) {
         unset($_applications[$_applications->getIndexById($tinebase->getId())]);
         list($major, $minor) = explode('.', $this->getSetupXml('Tinebase')->version[0]);
         Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updating Tinebase to version ' . $major . '.' . $minor);
         for ($majorVersion = $tinebase->getMajorVersion(); $majorVersion <= $major; $majorVersion++) {
             $messages += $this->updateApplication($tinebase, $majorVersion);
         }
     }
     // update the rest
     for ($majorVersion = $smallestMajorVersion; $majorVersion <= $biggestMajorVersion; $majorVersion++) {
         foreach ($_applications as $application) {
             if ($application->getMajorVersion() <= $majorVersion) {
                 $messages += $this->updateApplication($application, $majorVersion);
             }
         }
     }
     return array('messages' => $messages, 'updated' => $this->_updatedApplications);
 }
 public function testGetIndexById()
 {
     $idx = $this->object->getIndexById(1);
     $this->assertEquals(2, $idx);
 }
 /**
  * set customfield value in record
  * 
  * @param Tinebase_Record_Abstract $record
  * @param Tinebase_Model_CustomField_Value $customField
  * @param Tinebase_Record_RecordSet $configs
  */
 protected function _setCfValueInRecord(Tinebase_Record_Abstract $record, Tinebase_Model_CustomField_Value $customField, Tinebase_Record_RecordSet $configs)
 {
     $recordCfs = $record->customfields;
     $idx = $configs->getIndexById($customField->customfield_id);
     if ($idx !== FALSE) {
         $config = $configs[$idx];
         if (strtolower($config->definition['type']) == 'record') {
             $value = $this->_getRecordTypeCfValue($config, $customField->value);
         } else {
             $value = $customField->value;
         }
         $recordCfs[$config->name] = $value;
     }
     // sort customfields by key
     if (is_array($recordCfs)) {
         ksort($recordCfs);
     }
     $record->customfields = $recordCfs;
 }
 /**
  * resolved app records and fills the related_record property with the corresponding record
  * 
  * NOTE: With this, READ ACL is implicitly checked as non readable records won't get retuned!
  * 
  * @param  Tinebase_Record_RecordSet $_relations of Tinebase_Model_Relation
  * @param  boolean $_ignoreACL 
  * @return void
  * 
  * @todo    make getApplicationInstance work for tinebase record (Tinebase_Model_User for example)
  */
 protected function resolveAppRecords($_relations, $_ignoreACL = FALSE)
 {
     // separate relations by model
     $modelMap = array();
     foreach ($_relations as $relation) {
         if (!(isset($modelMap[$relation->related_model]) || array_key_exists($relation->related_model, $modelMap))) {
             $modelMap[$relation->related_model] = new Tinebase_Record_RecordSet('Tinebase_Model_Relation');
         }
         $modelMap[$relation->related_model]->addRecord($relation);
     }
     // fill related_record
     foreach ($modelMap as $modelName => $relations) {
         // check right
         $split = explode('_Model_', $modelName);
         $rightClass = $split[0] . '_Acl_Rights';
         $rightName = 'manage_' . strtolower($split[1]) . 's';
         if (class_exists($rightClass)) {
             $ref = new ReflectionClass($rightClass);
             $u = Tinebase_Core::getUser();
             // if a manage right is defined and the user has no manage_record or admin right, remove relations having this record class as related model
             if (is_object($u) && $ref->hasConstant(strtoupper($rightName)) && !$u->hasRight($split[0], $rightName) && !$u->hasRight($split[0], Tinebase_Acl_Rights::ADMIN)) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     $_relations->removeRecords($relations);
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Skipping relation due to no manage right: ' . $modelName);
                 }
                 continue;
             }
         }
         $getMultipleMethod = 'getMultiple';
         if ($modelName === 'Tinebase_Model_User') {
             // @todo add related backend here
             //$appController = Tinebase_User::factory($relations->related_backend);
             $appController = Tinebase_User::factory(Tinebase_User::getConfiguredBackend());
             $records = $appController->{$getMultipleMethod}($relations->related_id);
         } else {
             try {
                 $appController = Tinebase_Core::getApplicationInstance($modelName);
                 if (method_exists($appController, $getMultipleMethod)) {
                     $records = $appController->{$getMultipleMethod}($relations->related_id, $_ignoreACL);
                     // resolve record alarms
                     if (count($records) > 0 && $records->getFirstRecord()->has('alarms')) {
                         $appController->getAlarms($records);
                     }
                 } else {
                     throw new Tinebase_Exception_AccessDenied('Controller ' . get_class($appController) . ' has no method ' . $getMultipleMethod);
                 }
             } catch (Tinebase_Exception_AccessDenied $tea) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Removing relations from result. Got exception: ' . $tea->getMessage());
                 }
                 $_relations->removeRecords($relations);
                 continue;
             }
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Resolving " . count($relations) . " relations");
         }
         foreach ($relations as $relation) {
             $recordIndex = $records->getIndexById($relation->related_id);
             $relationIndex = $_relations->getIndexById($relation->getId());
             if ($recordIndex !== false) {
                 $_relations[$relationIndex]->related_record = $records[$recordIndex];
             } else {
                 // delete relation from set, as READ ACL is obviously not granted
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " removing {$relation->related_model} {$relation->related_backend} {$relation->related_id} (ACL)");
                 }
                 unset($_relations[$relationIndex]);
             }
         }
     }
 }
Exemple #6
0
 /**
  * resolved app records and filles the related_record property with the corresponding record
  * 
  * NOTE: With this, READ ACL is implicitly checked as non readable records won't get retuned!
  * 
  * @param  Tinebase_Record_RecordSet $_relations of Tinebase_Model_Relation
  * @param  boolean $_ignoreACL 
  * @return void
  * 
  * @todo    make getApplicationInstance work for tinebase record (Tinebase_Model_User for example)
  */
 protected function resolveAppRecords($_relations, $_ignoreACL = FALSE)
 {
     // seperate relations by model
     $modelMap = array();
     foreach ($_relations as $relation) {
         if (!array_key_exists($relation->related_model, $modelMap)) {
             $modelMap[$relation->related_model] = new Tinebase_Record_RecordSet('Tinebase_Model_Relation');
         }
         $modelMap[$relation->related_model]->addRecord($relation);
     }
     // fill related_record
     foreach ($modelMap as $modelName => $relations) {
         $getMultipleMethod = 'getMultiple';
         if ($modelName === 'Tinebase_Model_User') {
             // @todo add related backend here
             //$appController = Tinebase_User::factory($relations->related_backend);
             $appController = Tinebase_User::factory(Tinebase_User::getConfiguredBackend());
             $records = $appController->{$getMultipleMethod}($relations->related_id);
         } else {
             try {
                 $appController = Tinebase_Core::getApplicationInstance($modelName);
                 $records = $appController->{$getMultipleMethod}($relations->related_id, $_ignoreACL);
             } catch (Tinebase_Exception_AccessDenied $tea) {
                 // remove relations, user has no permission
                 $_relations->removeRecords($relations);
                 continue;
             }
         }
         foreach ($relations as $relation) {
             $recordIndex = $records->getIndexById($relation->related_id);
             $relationIndex = $_relations->getIndexById($relation->getId());
             if ($recordIndex !== false) {
                 $_relations[$relationIndex]->related_record = $records[$recordIndex];
             } else {
                 // delete relation from set, as READ ACL is obviously not granted
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " removing {$relation->related_model} {$relation->related_backend} {$relation->related_id} (ACL)");
                 }
                 unset($_relations[$relationIndex]);
             }
         }
     }
 }