/** * Clears the cached data on the document and refreshes the document object. * * @author KnowledgeTree Team * @access public */ function clearCache() { // TODO: we should only clear the cache for the document we are working on // this is a quick fix but not optimal!! $metadataid = $this->document->getMetadataVersionId(); $contentid = $this->document->getContentVersionId(); $cache = KTCache::getSingleton(); $cache->remove('KTDocumentMetadataVersion/id', $metadataid); $cache->remove('KTDocumentContentVersion/id', $contentid); $cache->remove('KTDocumentCore/id', $this->documentid); $cache->remove('Document/id', $this->documentid); unset($GLOBALS['_OBJECTCACHE']['KTDocumentMetadataVersion'][$metadataid]); unset($GLOBALS['_OBJECTCACHE']['KTDocumentContentVersion'][$contentid]); unset($GLOBALS['_OBJECTCACHE']['KTDocumentCore'][$this->documentid]); $this->document =& Document::get($this->documentid); }
/** * Read the plugins directory and register all plugins in the database. */ function doPluginRegistration() { global $default; KTPluginUtil::_deleteSmartyFiles(); require_once KT_LIB_DIR . '/cache/cache.inc.php'; $oCache =& KTCache::getSingleton(); $oCache->deleteAllCaches(); // Remove all entries from the plugin_helper table and refresh it. $query = "DELETE FROM plugin_helper"; $res = DBUtil::runQuery($query); $files = array(); $plugins = array(); KTPluginUtil::_walk(KT_DIR . '/plugins', $files); foreach ($files as $sFile) { $plugin_ending = "Plugin.php"; if (substr($sFile, -strlen($plugin_ending)) === $plugin_ending) { /* Set default priority */ $plugins[$sFile] = KTPluginUtil::getPluginPriority($sFile); } } /* Sort the plugins by priority */ asort($plugins); /* Add a check to indicate that plugin registration is occuring. This check has been put in place to prevent the plugin being registered on every page load. */ $_SESSION['plugins_registerplugins'] = true; foreach ($plugins as $sFile => $priority) { require_once $sFile; } $_SESSION['plugins_registerplugins'] = false; $oRegistry =& KTPluginRegistry::getSingleton(); $aRegistryList = $oRegistry->getPlugins(); foreach ($aRegistryList as $oPlugin) { $res = $oPlugin->register(); if (PEAR::isError($res)) { //var_dump($res); $default->log->debug('Register of plugin failed: ' . $res->getMessage()); } } $aPluginList = KTPluginEntity::getList(); foreach ($aPluginList as $oPluginEntity) { $sPath = $oPluginEntity->getPath(); if (!KTUtil::isAbsolutePath($sPath)) { $sPath = sprintf("%s/%s", KT_DIR, $sPath); } if (!file_exists($sPath)) { $oPluginEntity->setUnavailable(true); $oPluginEntity->setDisabled(true); $res = $oPluginEntity->update(); } } KTPluginEntity::clearAllCaches(); KTPluginUtil::_deleteSmartyFiles(); require_once KT_LIB_DIR . '/cache/cache.inc.php'; $oCache =& KTCache::getSingleton(); $oCache->deleteAllCaches(); //KTPluginUtil::removePluginCache(); }
/** * Updates permission lookups for all objects of a certain * permission object. * * It may be that you don't have or want to have the root item for a * permission object that you do have and have updates - then use * this. */ function updatePermissionLookupForPO($oPO) { $sWhere = 'permission_object_id = ?'; $aParams = array($oPO->getID()); $aFolders =& Folder::getList(array($sWhere, $aParams)); // init once time those var for speeding up updates $oChannel =& KTPermissionChannel::getSingleton(); $aPermAssigns = KTPermissionAssignment::getByObjectMulti($oPO); $aMapPermAllowed = array(); foreach ($aPermAssigns as $oPermAssign) { $oPermDescriptor = KTPermissionDescriptor::get($oPermAssign->getPermissionDescriptorID()); $aGroupIDs = $oPermDescriptor->getGroups(); $aUserIDs = array(); $aRoleIDs = $oPermDescriptor->getRoles(); $aAllowed = array('group' => $aGroupIDs, 'user' => $aUserIDs, 'role' => $aRoleIDs); $aMapPermAllowed[$oPermAssign->getPermissionID()] = $aAllowed; } $aMapPermDesc = array(); foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) { $oLookupPD = KTPermissionUtil::getOrCreateDescriptor($aAllowed); $aMapPermDesc[$iPermissionId] = $oLookupPD->getID(); } $oPermLookup = KTPermissionLookupAssignment::findOrCreateLookupByPermissionDescriptorMap($aMapPermDesc); $aOptions = array('channel' => $oChannel, 'map_allowed' => $aMapPermAllowed, 'perm_lookup' => $oPermLookup); if (!PEAR::isError($aFolders)) { foreach ($aFolders as $oFolder) { KTPermissionUtil::updatePermissionLookup($oFolder, $aOptions); } } $aIds = DBUtil::getResultArrayKey(array("SELECT id FROM documents WHERE permission_object_id=?", $aParams), 'id'); if (!PEAR::isError($aIds)) { $cache = KTCache::getSingleton(); foreach ($aIds as $iId) { $oDocument =& Document::get($iId); KTPermissionUtil::updatePermissionLookup($oDocument, $aOptions); $metadataid = $oDocument->getMetadataVersionId(); $contentid = $oDocument->getContentVersionId(); $cache->remove('KTDocumentMetadataVersion/id', $metadataid); $cache->remove('KTDocumentContentVersion/id', $contentid); $cache->remove('KTDocumentCore/id', $iId); $cache->remove('Document/id', $iId); unset($GLOBALS['_OBJECTCACHE']['KTDocumentMetadataVersion'][$metadataid]); unset($GLOBALS['_OBJECTCACHE']['KTDocumentContentVersion'][$contentid]); unset($GLOBALS['_OBJECTCACHE']['KTDocumentCore'][$iId]); unset($oDocument); } } /* $aDocuments =& Document::getList(array($sWhere, $aParams)); if (!PEAR::isError($aDocuments)) { foreach ($aDocuments as $oDocument) { KTPermissionUtil::updatePermissionLookup($oDocument, $aOptions); } }*/ }
function clearGroupCacheForUser($oUser) { $oCache =& KTCache::getSingleton(); if (PEAR::isError($oUser)) { return $oUser; } $group = "groupidsforuser"; $iUserId = KTUtil::getId($oUser); $oCache->remove($group, $iUserId); }
function _performUpgrade() { $this->_deleteSmartyFiles(); $this->_deleteProxyFiles(); require_once KT_LIB_DIR . '/cache/cache.inc.php'; $oCache =& KTCache::getSingleton(); $oCache->deleteAllCaches(); require_once KT_LIB_DIR . '/permissions/permissionutil.inc.php'; $po =& new KTRebuildPermissionObserver($this); $po->start(); $oChannel =& KTPermissionChannel::getSingleton(); $oChannel->addObserver($po); set_time_limit(0); ignore_user_abort(true); KTPermissionUtil::rebuildPermissionLookups(true); $po->end(); $versionFile = KT_DIR . '/docs/VERSION-NAME.txt'; $fp = fopen($versionFile, 'rt'); $systemVersion = fread($fp, filesize($versionFile)); fclose($fp); $query = "UPDATE system_settings SET value = ? WHERE name = ?"; $aParams = array($systemVersion, "knowledgetreeVersion"); DBUtil::runQuery(array($query, $aParams)); $query = "UPDATE system_settings SET value = ? WHERE name = ?"; $aParams = array($this->version, "databaseVersion"); return DBUtil::runQuery(array($query, $aParams)); }
function _getStrings($_format) { $oCache = KTCache::getSingleton(); list($bCached, $stuff) = $oCache->get("i18nstrings", $this->sFilename); if (empty($bCached)) { require_once 'File/Gettext.php'; $this->oLang = File_Gettext::factory($_format, $this->sFilename); $bLoaded = $this->oLang->load(); $stuff = $this->oLang->toArray(); $oCache->set("i18nstrings", $this->sFilename, $stuff); } $this->aMeta = $stuff['meta']; $this->aStrings = $stuff['strings']; }
/** * This adds a document to the current folder. * * <code> * $kt = new KTAPI(); * $kt->start_session("admin", "admin"); * $folder = $kt->get_folder_by_name("My New folder"); * $res = $folder->add_document("Test Document", "test.txt", "Default", $tmpfname); * </code> * * @author KnowledgeTree Team * @access public * @param string $title This is the title for the file in the repository. * @param string $filename This is the filename in the system for the file. * @param string $documenttype This is the name or id of the document type. It first looks by name, then by id. * @param string $tempfilename This is a reference to the file that is accessible locally on the file system. * @return KTAPI_Document */ function add_document($title, $filename, $documenttype, $tempfilename) { if (!is_file($tempfilename)) { return new PEAR_Error('File does not exist.'); } $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } //KTS-4016: removed the replacing of special characters from the title as they should be allowed there //$title = KTUtil::replaceInvalidCharacters($title); $filename = basename($filename); $filename = KTUtil::replaceInvalidCharacters($filename); $documenttypeid = KTAPI::get_documenttypeid($documenttype); if (PEAR::isError($documenttypeid)) { $config = KTCache::getSingleton(); $defaultToDefaultDocType = $config->get('webservice/useDefaultDocumentTypeIfInvalid', true); if ($defaultToDefaultDocType) { $documenttypeid = KTAPI::get_documenttypeid('Default'); } else { return new KTAPI_DocumentTypeError('The document type could not be resolved or is disabled: ' . $documenttype); } } $options = array('contents' => new KTFSFileLike($tempfilename), 'temp_file' => $tempfilename, 'novalidate' => true, 'documenttype' => DocumentType::get($documenttypeid), 'description' => $title, 'metadata' => array(), 'cleanup_initial_file' => true); DBUtil::startTransaction(); $document =& KTDocumentUtil::add($this->folder, $filename, $user, $options); if (PEAR::isError($document)) { DBUtil::rollback(); return new PEAR_Error(KTAPI_ERROR_INTERNAL_ERROR . ' : ' . $document->getMessage()); } DBUtil::commit(); KTUploadManager::temporary_file_imported($tempfilename); return new KTAPI_Document($this->ktapi, $this, $document); }
private function clearCache() { $metadataid = $this->doc->getMetadataVersionId(); $contentid = $this->doc->getContentVersionId(); $iId = $this->doc->getId(); $cache = KTCache::getSingleton(); $cache->remove('KTDocumentMetadataVersion/id', $metadataid); $cache->remove('KTDocumentContentVersion/id', $contentid); $cache->remove('KTDocumentCore/id', $iId); $cache->remove('Document/id', $iId); unset($GLOBALS['_OBJECTCACHE']['KTDocumentMetadataVersion'][$metadataid]); unset($GLOBALS['_OBJECTCACHE']['KTDocumentContentVersion'][$contentid]); unset($GLOBALS['_OBJECTCACHE']['KTDocumentCore'][$iId]); unset($this->doc); }