documentutil.inc.php.tmp

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· TMP 代码 · 共 1,528 行 · 第 1/4 页

TMP
1,528
字号
        $oSubscriptionEvent = new SubscriptionEvent();        $oFolder = Folder::get($oDocument->getFolderID());        $oSubscriptionEvent->AddDocument($oDocument, $oFolder);        $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();        $aTriggers = $oKTTriggerRegistry->getTriggers('add', 'postValidate');        foreach ($aTriggers as $aTrigger) {            $sTrigger = $aTrigger[0];            $oTrigger = new $sTrigger;            $aInfo = array(                'document' => $oDocument,                'aOptions' => $aOrigOptions,            );            $oTrigger->setInfo($aInfo);            $ret = $oTrigger->postValidate();        }        KTDocumentUtil::updateSearchableText($oDocument, true);        DBUtil::commit();        $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Checking permissions...')));        // Check if there are any dynamic conditions / permissions that need to be updated on the document        // If there are dynamic conditions then update the permissions on the document        // The dynamic condition test fails unless the document exists in the DB therefore update permissions after committing the transaction.        include_once(KT_LIB_DIR.'/permissions/permissiondynamiccondition.inc.php');        $iPermissionObjectId = $oFolder->getPermissionObjectID();        $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId);        if(!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)){            $res = KTPermissionUtil::updatePermissionLookup($oDocument);        }        $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('All done...')));        return $oDocument;    }    // }}}	function generateNewDocumentFilename($sDocFilename){		if(preg_match("/\([0-9]+\)(\.[^\.]+){1,}$/", $sDocFilename)){		  preg_match("/\([0-9]+\)\./", $sDocFilename, $matches);		  $new_one = substr($matches[0], 1);		  $new_two = explode(')', $new_one);		  $new = $new_two[0]+1;		  $pattern[0] = '/\([0-9]+\)\./';		  $replacement[0] = ' ('.$new.').';		  $sFilename = preg_replace($pattern, $replacement, $sDocFilename);		}else{		  $matches = explode('.', $sDocFilename);		  $prefix = $matches[0].' (2)';		  for($i = 1; $i < count($matches); $i++ ){		    $suffix .= '.'.$matches[$i];		  }		  $sFilename = $prefix.$suffix;		}		return $sFilename;	}	function generateNewDocumentName($sDocName){		if(preg_match("/\([0-9]+\)$/", $sDocName)){		  preg_match("/\([0-9]+\)$/", $sDocName, $matches);		  $new_one = substr($matches[0], 1);		  $new_two = explode(')', $new_one);		  $new = $new_two[0]+1;		  $pattern[0] = '/\([0-9]+\)$/';		  $replacement[0] = '('.$new.')';		  $sName = preg_replace($pattern, $replacement, $sDocName);		}else{		  $sName =  $sDocName.' (2)';		}		return $sName;	}    // {{{ fileExists    function fileExists($oFolder, $sFilename) {        return Document::fileExists($sFilename, $oFolder->getID());    }    // }}}    // {{{ nameExists    function nameExists($oFolder, $sName) {        return Document::nameExists($sName, $oFolder->getID());    }    // }}}    // {{{ storeContents    /**     * Stores contents (filelike) from source into the document storage     */    function storeContents(&$oDocument, $oContents = null, $aOptions = null) {        if (is_null($aOptions)) {            $aOptions = array();        }        if (PEAR::isError($oDocument)) {            return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $oDocument->getMessage()));        }        $bCanMove = KTUtil::arrayGet($aOptions, 'move');        $oStorage =& KTStorageManagerUtil::getSingleton();        $oKTConfig =& KTConfig::getSingleton();        $sBasedir = $oKTConfig->get('urls/tmpDirectory');        $sFilename = (isset($aOptions['temp_file'])) ? $aOptions['temp_file'] : '';//        $oOutputFile = new KTFSFileLike($sFilename);//        $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile);//        if (($res === false)) {//            return PEAR::raiseError(_kt("Couldn't store contents, and no reason given."));//        } else if (PEAR::isError($res)) {//            return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage()));//        }        if(empty($sFilename)){            return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), _kt('The uploaded file does not exist.')));        }        $md5hash = md5_file($sFilename);        $content = $oDocument->_oDocumentContentVersion;        $content->setStorageHash($md5hash);        $content->update();        if (empty($aOptions)) $aOptions = array();        $aOptions['md5hash'] = $md5hash;        $sType = KTMime::getMimeTypeFromFile($sFilename);        $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName());        $oDocument->setMimeTypeId($iMimeTypeId);        $res = $oStorage->upload($oDocument, $sFilename, $aOptions);        if ($res === false) {            return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), _kt('No reason given')));        }        if (PEAR::isError($res)) {            return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage()));        }        KTDocumentUtil::setComplete($oDocument, 'contents');        if ($aOptions['cleanup_initial_file'] && file_exists($sFilename)) {            @unlink($sFilename);        }        return true;    }    // }}}    // {{{ updateTransactionText    function updateTransactionText($oDocument) {        // NEW SEARCH        return;        $iDocumentId = KTUtil::getId($oDocument);        $aTransactions = DocumentTransaction::getByDocument($iDocumentId);        foreach ($aTransactions as $oTransaction) {            $aComments[] = $oTransaction->getComment();        }        $sAllComments = join("\n\n", $aComments);        $sTable = KTUtil::getTableName('document_transaction_text');        $aQuery = array("DELETE FROM $sTable WHERE document_id = ?", array($iDocumentId));        $res = DBUtil::runQuery($aQuery);        if (PEAR::isError($res)) {            return $res;        }        $aInsert = array(            'document_id' => $iDocumentId,            'document_text' => $sAllComments,        );        return DBUtil::autoInsert($sTable, $aInsert, array('noid' => true));    }    // }}}    // {{{ updateSearchableText    function updateSearchableText($oDocument, $bOverride = false) {        // NEW SEARCH        return;        if (isset($GLOBALS['_IN_ADD']) && empty($bOverride)) {            return;        }        $sMetadata = KTUtil::arrayGet( $_REQUEST, 'metadata_2');        $oDocument = KTUtil::getObject('Document', $oDocument);        $iDocumentId = $oDocument->getId();        $sTable = KTUtil::getTableName('document_transaction_text');        $aQuery = array("SELECT document_text FROM $sTable WHERE                document_id = ?", array($iDocumentId));        $sAllComments = DBUtil::getOneResultKey($aQuery, 'document_text');        $sTable = KTUtil::getTableName('document_text');        $aQuery = array("SELECT document_text FROM $sTable WHERE                document_id = ?", array($iDocumentId));        $sAllDocumentText = DBUtil::getOneResultKey($aQuery, 'document_text');        $aFieldLinks = DocumentFieldLink::getByDocument($iDocumentId);        $aFieldValues = array();        foreach ($aFieldLinks as $oFieldLink) {            $aFieldValues[] = $oFieldLink->getValue();        }        $sAllFieldText = join(' ', $aFieldValues);        $sDocumentFilename = $oDocument->getFilename();        $sDocumentTitle = $oDocument->getName();        $sSearchableText = $sAllDocumentText . ' ' . $sAllFieldText . ' ' . $sAllComments . ' ' . $sDocumentFilename . ' ' . $sDocumentTitle . ' ' . $sMetadata;        $sTable = KTUtil::getTableName('document_searchable_text');        $aDelete = array(            'document_id' => $iDocumentId,        );        DBUtil::whereDelete($sTable, $aDelete);        $aInsert = array(            'document_id' => $iDocumentId,            'document_text' => $sSearchableText,        );        return DBUtil::autoInsert($sTable, $aInsert, array('noid' => true));    }    // }}}    // {{{ delete    function delete($oDocument, $sReason, $iDestFolderId = null) {    	// use the deleteSymbolicLink function is this is a symlink        if ($oDocument->isSymbolicLink())        {            return KTDocumentUtil::deleteSymbolicLink($oDocument);        }    	   	        $oDocument =& KTUtil::getObject('Document', $oDocument);        if (is_null($iDestFolderId)) {            $iDestFolderId = $oDocument->getFolderID();        }        $oStorageManager =& KTStorageManagerUtil::getSingleton();        global $default;        if (count(trim($sReason)) == 0) {            return PEAR::raiseError(_kt('Deletion requires a reason'));        }        if (PEAR::isError($oDocument) || ($oDocument == false)) {            return PEAR::raiseError(_kt('Invalid document object.'));        }        if ($oDocument->getIsCheckedOut() == true) {            return PEAR::raiseError(sprintf(_kt('The document is checked out and cannot be deleted: %s'), $oDocument->getName()));        }        // IF we're deleted ...        if ($oDocument->getStatusID() == DELETED) {            return true;        }        $oOrigFolder = Folder::get($oDocument->getFolderId());        DBUtil::startTransaction();        // flip the status id        $oDocument->setStatusID(DELETED);        // $iDestFolderId is DEPRECATED.        $oDocument->setFolderID(null);        $oDocument->setRestoreFolderId($oOrigFolder->getId());        $oDocument->setRestoreFolderPath(Folder::generateFolderIDs($oOrigFolder->getId()));        $res = $oDocument->update();        if (PEAR::isError($res) || ($res == false)) {            DBUtil::rollback();            return PEAR::raiseError(_kt('There was a problem deleting the document from the database.'));        }        // now move the document to the delete folder        $res = $oStorageManager->delete($oDocument);        if (PEAR::isError($res) || ($res == false)) {            //could not delete the document from the file system            $default->log->error('Deletion: Filesystem error deleting document ' .                $oDocument->getFileName() . ' from folder ' .                Folder::getFolderPath($oDocument->getFolderID()) .                ' id=' . $oDocument->getFolderID());            // we use a _real_ transaction here ...            DBUtil::rollback();            /*            //reverse the document deletion            $oDocument->setStatusID(LIVE);            $oDocument->update();            */            return PEAR::raiseError(_kt('There was a problem deleting the document from storage.'));        }        //delete all shortcuts linking to this document        $aSymlinks = $oDocument->getSymbolicLinks();        foreach($aSymlinks as $aSymlink){        	$oShortcutDocument = Document::get($aSymlink['id']);        	$oOwnerUser = User::get($oShortcutDocument->getOwnerID());        	        	KTDocumentUtil::deleteSymbolicLink($aSymlink['id']);        	        	//send an email to the owner of the shortcut        	if($oOwnerUser->getEmail()!=null && $oOwnerUser->getEmailNotification() == true){        		$emailTemplate = new EmailTemplate("kt3/notifications/notification.SymbolicLinkDeleted",array('user_name'=>$this->oUser->getName(),        			'url'=>KTUtil::ktLink(KTBrowseUtil::getUrlForDocument($oShortcutDocument)),        			'title' =>$oShortcutDocument->getName()));        		$email = new EmailAlert($oOwnerUser->getEmail(),_kt("KnowledgeTree Notification"),$emailTemplate->getBody());        		$email->send();        	}        }                $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document deleted: ') . $sReason, 'ktcore.transactions.delete');        $oDocumentTransaction->create();        $oDocument->setFolderID(1);        DBUtil::commit();	// we weren't doing notifications on this one        $oSubscriptionEvent = new SubscriptionEvent();        $oSubscriptionEvent->RemoveDocument($oDocument, $oOrigFolder);        // document is now deleted:  triggers are best-effort.        $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();        $aTriggers = $oKTTriggerRegistry->getTriggers('delete', 'postValidate');        foreach ($aTriggers as $aTrigger) {            $sTrigger = $aTrigger[0];            $oTrigger = new $sTrigger;            $aInfo = array(                'document' => $oDocument,            );            $oTrigger->setInfo($aInfo);            $ret = $oTrigger->postValidate();            if (PEAR::isError($ret)) {                $oDocument->delete();          // FIXME nbm: review that on-fail => delete is correct ?!                return $ret;            }        }    }    // }}}    function reindexDocument($oDocument) {        // NEW SEARCH        Indexer::index($oDocument);        return;        /*        $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();        $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform');        foreach ($aTriggers as $aTrigger) {            $sTrigger = $aTrigger[0];            if ($aTrigger[1]) {                require_once($aTrigger[1]);            }            $oTrigger = new $sTrigger;            $oTrigger->setDocument($oDocument);            $oTrigger->transform();        }        KTDocumentUtil::updateSearchableText($oDocument);*/    }    function canBeMoved($oDocument) {        if ($oDocument->getIsCheckedOut()) {            return false;        }        if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.move')) {            return false;        }        return true;    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?