/**
  * Override method because admin app requires special rights
  * @see tine20/Setup/Setup_Initialize#_createInitialRights($_application)
  * 
  * @todo make hard coded role name ('admin role') configurable
  */
 protected function _createInitialRights(Tinebase_Model_Application $_application)
 {
     //do not call parent::_createInitialRights(); because this app is fopr admins only
     $roles = Tinebase_Acl_Roles::getInstance();
     $adminRole = $roles->getRoleByName('admin role');
     $allRights = Tinebase_Application::getInstance()->getAllRights($_application->getId());
     foreach ($allRights as $right) {
         $roles->addSingleRight($adminRole->getId(), $_application->getId(), $right);
     }
 }
 /**
  * get shared container
  * 
  * @return Tinebase_Model_Container
  */
 protected function _getSharedContainer()
 {
     if (!$this->_sharedContainer) {
         $search = Tinebase_Container::getInstance()->search(new Tinebase_Model_ContainerFilter(array('application_id' => $this->_application->getId(), 'name' => 'shared', 'type' => Tinebase_Model_Container::TYPE_SHARED)));
         $this->_sharedContainer = count($search) > 0 ? $search->getFirstRecord() : Tinebase_Container::getInstance()->addContainer(new Tinebase_Model_Container(array('name' => 'shared', 'type' => Tinebase_Model_Container::TYPE_SHARED, 'backend' => 'sql', 'application_id' => $this->_application->getId())));
     }
     return $this->_sharedContainer;
 }
예제 #3
0
 /**
  * testSetContainerInPathRecord
  * 
  * @todo move this to Tinebase?
  */
 public function testSetContainerInPathRecord()
 {
     $flatpath = Filemanager_Controller_Node::getInstance()->addBasePath('/' . Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/' . $this->_personalContainer->name);
     $path = Tinebase_Model_Tree_Node_Path::createFromPath($flatpath);
     $path->setContainer($this->_sharedContainer);
     $this->assertEquals('/' . $this->_application->getId() . '/folders/shared/' . $this->_sharedContainer->getId(), $path->statpath);
     // move it back
     $path->setContainer($this->_personalContainer);
     $this->assertEquals('/' . $this->_application->getId() . '/folders/personal/' . Tinebase_Core::getUser()->getId() . '/' . $this->_personalContainer->getId(), $path->statpath, 'wrong statpath: ' . print_r($path->toArray(), TRUE));
 }
예제 #4
0
 /**
  * create inital rights
  * 
  * @todo make hard coded role names ('user role' and 'admin role') configurable
  * 
  * @param Tinebase_Application $application
  * @return void
  */
 protected function _createInitialRights(Tinebase_Model_Application $_application)
 {
     $roleRights = array('user role' => $this->_userRoleRights, 'admin role' => Tinebase_Application::getInstance()->getAllRights($_application->getId()));
     foreach ($roleRights as $roleName => $rights) {
         try {
             $role = Tinebase_Acl_Roles::getInstance()->getRoleByName($roleName);
         } catch (Tinebase_Exception_NotFound $tenf) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $tenf->getMessage());
             continue;
         }
         foreach ($rights as $right) {
             try {
                 Tinebase_Acl_Roles::getInstance()->addSingleRight($role->getId(), $_application->getId(), $right);
             } catch (Exception $e) {
                 Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Cannot add right: ' . $right . ' for application: ' . $_application->name . ' - ' . $roleName . ' - ' . print_r($e->getMessage(), true));
             }
         }
     }
 }
 /**
  * create inital rights
  * 
  * @todo make hard coded role names ('user role' and 'admin role') configurable
  * 
  * @param Tinebase_Application $application
  * @return void
  */
 public static function createInitialRights(Tinebase_Model_Application $_application)
 {
     Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Creating initial rights for application ' . $_application->name);
     $allRights = Tinebase_Application::getInstance()->getAllRights($_application->getId());
     $userRights = static::$_userRoleRights;
     if (in_array(Tinebase_Acl_Rights::USE_PERSONAL_TAGS, $allRights)) {
         $userRights[] = Tinebase_Acl_Rights::USE_PERSONAL_TAGS;
     }
     $roleRights = array('user role' => $userRights, 'admin role' => $allRights);
     foreach ($roleRights as $roleName => $rights) {
         try {
             $role = Tinebase_Acl_Roles::getInstance()->getRoleByName($roleName);
         } catch (Tinebase_Exception_NotFound $tenf) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $tenf->getMessage());
             continue;
         }
         foreach ($rights as $right) {
             try {
                 Tinebase_Acl_Roles::getInstance()->addSingleRight($role->getId(), $_application->getId(), $right);
             } catch (Exception $e) {
                 Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Cannot add right: ' . $right . ' for application: ' . $_application->name . ' - ' . $roleName . ' - ' . print_r($e->getMessage(), true));
             }
         }
     }
 }
 /**
  * get registry data from application frontend json class
  *
  * @param Tinebase_Model_Application $application
  * @return array
  * @throws Tinebase_Exception_InvalidArgument
  */
 protected function _getCustomAppRegistry(Tinebase_Model_Application $application)
 {
     $jsonAppName = $application->name . '_Frontend_Json';
     if (!class_exists($jsonAppName)) {
         return array();
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Getting registry data for app ' . $application->name);
     }
     try {
         $applicationJson = new $jsonAppName();
         $registryData = $applicationJson->getRegistryData();
     } catch (Exception $e) {
         Tinebase_Exception::log($e);
         if (!$e instanceof Tinebase_Exception_AccessDenied && !in_array($application->name, array('Tinebase', 'Addressbook', 'Admin'))) {
             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Disabling ' . $application->name . ': ' . $e);
             Tinebase_Application::getInstance()->setApplicationState(array($application->getId()), Tinebase_Application::DISABLED);
         }
         return array();
     }
     // TODO get this from app controller / modelconfig
     foreach ($applicationJson->getRelatableModels() as $relModel) {
         $registryData[$relModel['ownApp']]['relatableModels'][] = $relModel;
     }
     $registryData['models'] = $applicationJson->getModelsConfiguration();
     $registryData['defaultModel'] = $applicationJson->getDefaultModel();
     return $registryData;
 }
 /**
  * delete containers, configs and other data of an application
  * 
  * NOTE: if a table with foreign key constraints to applications is added, we need to make sure that the data is deleted here 
  * 
  * @param Tinebase_Model_Application $_applicationName
  * @return void
  */
 public function removeApplicationData(Tinebase_Model_Application $_application)
 {
     $dataToDelete = array('container' => array('tablename' => ''), 'config' => array('tablename' => ''), 'customfield' => array('tablename' => ''), 'rights' => array('tablename' => 'role_rights'), 'definitions' => array('tablename' => 'importexport_definition'), 'filter' => array('tablename' => 'filter'), 'modlog' => array('tablename' => 'timemachine_modlog'), 'import' => array('tablename' => 'import'));
     $countMessage = ' Deleted';
     $where = array($this->_getDb()->quoteInto($this->_getDb()->quoteIdentifier('application_id') . '= ?', $_application->getId()));
     foreach ($dataToDelete as $dataType => $info) {
         switch ($dataType) {
             case 'container':
                 $count = Tinebase_Container::getInstance()->deleteContainerByApplicationId($_application->getId());
                 break;
             case 'config':
                 $count = Tinebase_Config::getInstance()->deleteConfigByApplicationId($_application->getId());
                 break;
             case 'customfield':
                 $count = Tinebase_CustomField::getInstance()->deleteCustomFieldsForApplication($_application->getId());
                 break;
             default:
                 if ((isset($info['tablename']) || array_key_exists('tablename', $info)) && !empty($info['tablename'])) {
                     try {
                         $count = $this->_getDb()->delete(SQL_TABLE_PREFIX . $info['tablename'], $where);
                     } catch (Zend_Db_Statement_Exception $zdse) {
                         Tinebase_Exception::log($zdse);
                         $count = 0;
                     }
                 } else {
                     Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' No tablename defined for ' . $dataType);
                     $count = 0;
                 }
         }
         $countMessage .= ' ' . $count . ' ' . $dataType . '(s) /';
     }
     $countMessage .= ' for application ' . $_application->name;
     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . $countMessage);
 }
예제 #8
0
 /**
  * update existing definition or create new from file
  * - use backend functions (create/update) directly because we do not want any default controller handling here
  * - calling function needs to make sure that user has admin right!
  *
  * @param string $_filename
  * @param Tinebase_Model_Application $_application
  * @param string $_name
  * @return Tinebase_Model_ImportExportDefinition
  */
 public function updateOrCreateFromFilename($_filename, $_application, $_name = NULL)
 {
     $definition = $this->getFromFile($_filename, $_application->getId(), $_name);
     // try to get definition and update if it exists
     try {
         $existing = $this->getByName($definition->name);
         Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updating definition: ' . $definition->name);
         $copyFields = array('filename', 'plugin_options', 'description');
         foreach ($copyFields as $field) {
             $existing->{$field} = $definition->{$field};
         }
         $result = $this->_backend->update($existing);
     } catch (Tinebase_Exception_NotFound $tenf) {
         // does not exist
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Creating import/export definion from file: ' . $_filename);
         $result = $this->_backend->create($definition);
     }
     return $result;
 }
예제 #9
0
 /**
  * add TMA to "in class" cache and to Zend Cache
  * 
  * @param  Tinebase_Model_Application  $_application
  */
 protected function _addToClassCache(Tinebase_Model_Application $_application)
 {
     $this->_applicationCache[$_application->getId()] = $_application;
     $this->_applicationCache[$_application->name] = $_application;
 }
 /**
  * removes modlog entries for that application
  *
  * @param Tinebase_Model_Application $applicationName
  *
  * @return void
  */
 public function removeApplication(Tinebase_Model_Application $_application)
 {
     $this->_backend->deleteByProperty($_application->getId(), 'application_id');
 }
 /**
  * update installed application
  *
  * @param   Tinebase_Model_Application    $_application
  * @param   string    $_majorVersion
  * @return  array   messages
  * @throws  Setup_Exception if current app version is too high
  */
 public function updateApplication(Tinebase_Model_Application $_application, $_majorVersion)
 {
     $setupXml = $this->getSetupXml($_application->name);
     $messages = array();
     switch (version_compare($_application->version, $setupXml->version)) {
         case -1:
             $message = "Executing updates for " . $_application->name . " (starting at " . $_application->version . ")";
             $messages[] = $message;
             Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' ' . $message);
             list($fromMajorVersion, $fromMinorVersion) = explode('.', $_application->version);
             $minor = $fromMinorVersion;
             $className = ucfirst($_application->name) . '_Setup_Update_Release' . $_majorVersion;
             if (!class_exists($className)) {
                 Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " update class {$className} does not exists, skipping release {$_majorVersion} for app {$_application->name}");
             } else {
                 $update = new $className($this->_backend);
                 $classMethods = get_class_methods($update);
                 // we must do at least one update
                 do {
                     $functionName = 'update_' . $minor;
                     try {
                         $db = Setup_Core::getDb();
                         $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction($db);
                         Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updating ' . $_application->name . ' - ' . $functionName);
                         $update->{$functionName}();
                         Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
                     } catch (Exception $e) {
                         Tinebase_TransactionManager::getInstance()->rollBack();
                         Setup_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage());
                         Setup_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
                         throw $e;
                     }
                     $minor++;
                 } while (array_search('update_' . $minor, $classMethods) !== false);
             }
             $messages[] = "<strong> Updated " . $_application->name . " successfully to " . $_majorVersion . '.' . $minor . "</strong>";
             // update app version
             $updatedApp = Tinebase_Application::getInstance()->getApplicationById($_application->getId());
             $_application->version = $updatedApp->version;
             Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Updated ' . $_application->name . " successfully to " . $_application->version);
             $this->_updatedApplications++;
             break;
         case 0:
             Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' No update needed for ' . $_application->name);
             break;
         case 1:
             throw new Setup_Exception('Current application version is higher than version from setup.xml: ' . $_application->version . ' > ' . $setupXml->version);
             break;
     }
     Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Clearing cache after update ...');
     $this->_enableCaching();
     Tinebase_Core::getCache()->clean(Zend_Cache::CLEANING_MODE_ALL);
     return $messages;
 }
예제 #12
0
 /**
  * removes app id (and /folders namespace) from a path
  * 
  * @param string $_flatpath
  * @param Tinebase_Model_Application $_application
  * @return string
  */
 public static function removeAppIdFromPath($_flatpath, $_application)
 {
     $appId = $_application->getId();
     return preg_replace('@^/' . $appId . '/folders@', '', $_flatpath);
 }