本文整理汇总了PHP中DBUtil::runQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP DBUtil::runQuery方法的具体用法?PHP DBUtil::runQuery怎么用?PHP DBUtil::runQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBUtil
的用法示例。
在下文中一共展示了DBUtil::runQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: do_update
function do_update()
{
$sTable = KTUtil::getTableName('plugins');
$aIds = (array) KTUtil::arrayGet($_REQUEST, 'pluginids');
// Update disabled plugins
$sIds = implode(',', $aIds);
$sQuery = "UPDATE {$sTable} SET disabled = 1 WHERE id NOT IN ({$sIds})";
DBUtil::runQuery(array($sQuery));
// Select disabled plugins that have been enabled
$sQuery = "SELECT * FROM {$sTable} WHERE disabled = 1 AND id IN ({$sIds})";
$res = DBUtil::getResultArray($sQuery);
if (!PEAR::isError($res)) {
// Enable the disabled plugins
$sQuery = "UPDATE {$sTable} SET disabled = 0 WHERE id IN ({$sIds})";
DBUtil::runQuery(array($sQuery));
// run setup for each plugin
$aEnabled = array();
if (!empty($res)) {
foreach ($res as $item) {
$aEnabled[] = $item['id'];
}
$sEnabled = implode(',', $aEnabled);
$sQuery = "SELECT h.classname, h.pathname FROM {$sTable} p\n INNER JOIN plugin_helper h ON (p.namespace = h.plugin)\n WHERE classtype = 'plugin' AND p.id IN ({$sEnabled})";
$res = DBUtil::getResultArray($sQuery);
if (!PEAR::isError($res)) {
foreach ($res as $item) {
$classname = $item['classname'];
$path = $item['pathname'];
if (!empty($path)) {
require_once $path;
}
$oPlugin = new $classname($path);
$oPlugin->setup();
}
}
}
}
KTPluginEntity::clearAllCaches();
// FIXME!!! Plugin manager needs to be updated to deal with this situation. This code should be in the plugin.
//enabling or disabling Tag fieldset depending on whether tag cloud plugin is enabled or disabled.
//Get tag cloud object
$oTagClouPlugin = KTPluginEntity::getByNamespace('ktcore.tagcloud.plugin');
if (!PEAR::isError($oTagClouPlugin) && !is_a($oTagClouPlugin, 'KTEntityNoObjects') && !is_null($oTagClouPlugin)) {
if ($oTagClouPlugin->getDisabled() == '1') {
//disable tag fieldset
$aFV = array('disabled' => true);
$aWFV = array('namespace' => 'tagcloud');
$res = DBUtil::whereUpdate('fieldsets', $aFV, $aWFV);
} else {
//enable tag fieldset
$aFV = array('disabled' => false);
$aWFV = array('namespace' => 'tagcloud');
$res = DBUtil::whereUpdate('fieldsets', $aFV, $aWFV);
}
}
// we reregister the plugins to ensure they are in the correct order
KTPluginUtil::registerPlugins();
$this->successRedirectToMain(_kt('Plugins updated'));
}
示例2: postValidate
function postValidate()
{
global $default;
$document =& $this->aInfo["document"];
$documentid = $document->getId();
$sql = "SELECT document_id FROM search_saved_events WHERE document_id={$documentid}";
$rs = DBUtil::getResultArray($sql);
if (count($rs) == 0) {
$sql = "INSERT INTO search_saved_events (document_id) VALUES ({$documentid})";
DBUtil::runQuery($sql);
}
}
示例3: setup
/**
* Setup the plugin: add the processor, viewlet action and template location
*
*/
function setup()
{
$plugin_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$dir = $plugin_dir . 'thumbnails.php';
$this->registerProcessor('thumbnailGenerator', 'thumbnails.generator.processor', $dir);
$this->registerAction('documentviewlet', 'ThumbnailViewlet', 'thumbnail.viewlets', $dir);
require_once KT_LIB_DIR . '/templating/templating.inc.php';
$oTemplating =& KTTemplating::getSingleton();
$oTemplating->addLocation('thumbnails', $plugin_dir . 'templates', 'thumbnails.generator.processor.plugin');
// check for existing config settings entry and only add if not already present
$sql = 'SELECT id FROM `config_settings` WHERE group_name = "externalBinary" AND item = "convertPath"';
$result = DBUtil::getOneResult($sql);
if (PEAR::isError($result) || empty($result)) {
DBUtil::runQuery('INSERT INTO `config_settings` (group_name, display_name, description, item, value, default_value, type, options, can_edit) ' . 'VALUES ("externalBinary", "convert", "The path to the ImageMagick \\"convert\\" binary", "convertPath", "default", "convert", ' . '"string", NULL, 1);');
}
}
示例4: saveTransitionSources
function saveTransitionSources($oTransition, $aStateIds)
{
$sTable = KTUtil::getTableName('workflow_state_transitions');
$aQuery = array("DELETE FROM {$sTable} WHERE transition_id = ?", array($oTransition->getId()));
$res = DBUtil::runQuery($aQuery);
if (PEAR::isError($res)) {
return $res;
}
$aOptions = array('noid' => true);
if (empty($aStateIds)) {
return;
// don't fail if there are no transitions.
}
foreach ($aStateIds as $iStateId) {
$res = DBUtil::autoInsert($sTable, array('state_id' => $iStateId, 'transition_id' => $oTransition->getId()), $aOptions);
if (PEAR::isError($res)) {
return $res;
}
}
return;
}
示例5: replaceState
function replaceState($oState, $oReplacement)
{
$state_id = KTUtil::getId($oState);
$replacement_id = KTUtil::getId($oReplacement);
// we need to convert:
// - documents
// - transitions
// before we do a delete.
$doc = KTUtil::getTableName('document_metadata_version');
$aDocQuery = array("UPDATE {$doc} SET workflow_state_id = ? WHERE workflow_state_id = ?", array($replacement_id, $state_id));
$res = DBUtil::runQuery($aDocQuery);
if (PEAR::isError($res)) {
return $res;
}
$wf = KTUtil::getTableName('workflow_transitions');
$aTransitionQuery = array("UPDATE {$wf} SET target_state_id = ? WHERE target_state_id = ?", array($replacement_id, $state_id));
$res = DBUtil::runQuery($aTransitionQuery);
if (PEAR::isError($res)) {
return $res;
}
$wf = KTUtil::getTableName('workflow_state_transitions');
$aTransitionQuery = array("DELETE FROM {$wf} WHERE state_id = ?", array($state_id));
$res = DBUtil::runQuery($aTransitionQuery);
if (PEAR::isError($res)) {
return $res;
}
Document::clearAllCaches();
}
示例6: postValidate
/**
* postValidate method for trigger
*
* @return unknown
*/
function postValidate()
{
global $default;
$oDocument =& $this->aInfo['document'];
$aMeta =& $this->aInfo['aOptions'];
// get document id
$iDocId = $oDocument->getID();
// get all tags that are linked to the document
$sQuery = 'SELECT tw.id FROM tag_words AS tw, document_tags AS dt, documents AS d ' . 'WHERE dt.tag_id = tw.id ' . 'AND dt.document_id = d.id ' . 'AND d.id = ?';
$aParams = array($iDocId);
$aTagId = DBUtil::getResultArray(array($sQuery, $aParams));
if (PEAR::isError($aTagId)) {
// XXX: log error
return false;
}
// if there are any related tags proceed
if ($aTagId) {
// delete all entries from document_tags table for the document
$sQuery = 'DELETE FROM document_tags ' . 'WHERE document_id = ?';
$aParams = array($iDocId);
$removed = DBUtil::runQuery(array($sQuery, $aParams));
if (PEAR::isError($removed)) {
// XXX: log error
return false;
}
}
// proceed to add the tags as per normal
$sQuery = 'SELECT df.id AS id FROM document_fields AS df ' . 'WHERE df.name = \'Tag\'';
$sTags = DBUtil::getOneResultKey(array($sQuery), 'id');
if (PEAR::isError($sTags)) {
// XXX: log error
return false;
}
$tagString = '';
if ($sTags) {
// it is actually correct using $aMeta. It is different to the add trigger above...
if (count($aMeta) > 0) {
foreach ($aMeta as $aMetaData) {
$oProxy = $aMetaData[0];
if ($oProxy->iId == $sTags) {
$tagString = $aMetaData[1];
break;
}
}
}
if ($tagString != '') {
$words_table = KTUtil::getTableName('tag_words');
$tagString = str_replace(' ', ' ', $tagString);
$tags = explode(',', $tagString);
$aTagIds = array();
foreach ($tags as $sTag) {
$sTag = trim($sTag);
if (mb_detect_encoding($sTag) == 'ASCII') {
$sTag = strtolower($sTag);
}
$res = DBUtil::getOneResult(array("SELECT id FROM {$words_table} WHERE tag = ?", array($sTag)));
if (PEAR::isError($res)) {
return $res;
}
if (is_null($res)) {
$id =& DBUtil::autoInsert($words_table, array('tag' => $sTag));
$aTagIds[$sTag] = $id;
} else {
$aTagIds[$sTag] = $res['id'];
}
}
$doc_tags = KTUtil::getTableName('document_tags');
foreach ($aTagIds as $sTag => $tagid) {
DBUtil::autoInsert($doc_tags, array('document_id' => $iDocId, 'tag_id' => $tagid), array('noid' => true));
}
}
}
}
示例7: performPostUpgradeActions
function performPostUpgradeActions()
{
// This is just to test and needs to be updated to a more sane and error resistent architrcture if it works.
// It should idealy work the same as the upgrades.
global $default;
// Ensure all plugins are re-registered.
$sql = "TRUNCATE plugin_helper";
$res = DBUtil::runQuery($sql);
// Clear out all caches and proxies - they need to be regenerated with the new code
$proxyDir = $default->proxyCacheDirectory;
KTUtil::deleteDirectory($proxyDir);
$oKTCache = new KTCache();
$oKTCache->deleteAllCaches();
// Clear the configuration cache, it'll regenerate on next load
$oKTConfig = new KTConfig();
$oKTConfig->clearCache();
// Unlock the scheduler
$lockFile = $default->cacheDirectory . DIRECTORY_SEPARATOR . 'scheduler.lock';
if (file_exists($lockFile)) {
@unlink($lockFile);
}
return true;
}
示例8: unqueueDocFromProcessing
/**
* Remove the document from the processing queue. This is normally called when it has been processed.
*
* @param int $docid
*/
public static function unqueueDocFromProcessing($docid, $reason = false, $level = 'debug')
{
$sql = "DELETE FROM process_queue WHERE document_id={$docid}";
$result = DBUtil::runQuery($sql);
if ($reason !== false) {
global $default;
$default->log->{$level}("Processor queue: removing document {$docid} from the queue - {$reason}");
}
}
示例9: mergeWithLastMetadataVersion
/**
* Merge new metadata with previous metadata version
*
* @author KnowledgeTree Team
* @access public
* @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
*/
function mergeWithLastMetadataVersion()
{
// keep latest metadata version
$metadata_version = $this->document->getMetadataVersion();
if ($metadata_version == 0) {
// this could theoretically happen in the case we are updating metadata and sysdata, but no metadata fields are specified.
return;
}
$metadata_id = $this->document->getMetadataVersionId();
// get previous version
$sql = "SELECT id, metadata_version FROM document_metadata_version WHERE id<{$metadata_id} AND document_id={$this->documentid} order by id desc";
$old = DBUtil::getResultArray($sql);
if (is_null($old) || PEAR::isError($old)) {
return new PEAR_Error('Previous version could not be resolved');
}
// only interested in the first one
$old = $old[0];
$old_metadata_id = $old['id'];
$old_metadata_version = $old['metadata_version'];
DBUtil::startTransaction();
// delete previous metadata version
$sql = "DELETE FROM document_metadata_version WHERE id={$old_metadata_id}";
$rs = DBUtil::runQuery($sql);
if (PEAR::isError($rs)) {
DBUtil::rollback();
return $rs;
}
// make latest equal to previous
$sql = "UPDATE document_metadata_version SET metadata_version={$old_metadata_version} WHERE id={$metadata_id}";
$rs = DBUtil::runQuery($sql);
if (PEAR::isError($rs)) {
DBUtil::rollback();
return $rs;
}
$sql = "UPDATE documents SET metadata_version={$old_metadata_version} WHERE id={$this->documentid}";
$rs = DBUtil::runQuery($sql);
if (PEAR::isError($rs)) {
DBUtil::rollback();
return $rs;
}
DBUtil::commit();
$this->clearCache();
}
示例10: applySQL
/**
* applies queries to the database
* @return
* @param $filename Object
*/
function applySQL($filename)
{
global $default;
DBUtil::setupAdminDatabase();
$db = $default->_admindb;
$content = file_get_contents($filename);
$aQueries = SQLFile::splitSQL($content);
DBUtil::startTransaction();
foreach ($aQueries as $sQuery) {
$res = DBUtil::runQuery($sQuery, $db);
if (PEAR::isError($res)) {
continue;
}
}
DBUtil::commit();
}
示例11: deleteSymbolicLink
/**
* Deletes a symbolic link folder
*
* @param Folder $folder tthe symbolic link folder to delete
* @param User $user the current user
* @return unknown
*/
static function deleteSymbolicLink($folder, $user = null)
{
//validate input
if (is_numeric($folder)) {
$folder = Folder::get($folder);
}
if (!$folder instanceof Folder) {
return PEAR::raiseError(_kt('Folder not specified'));
}
if (!$folder->isSymbolicLink()) {
return PEAR::raiseError(_kt('Folder must be a symbolic link entity'));
}
if (is_null($user)) {
$user = $_SESSION['userID'];
}
if (is_numeric($user)) {
$user = User::get($user);
}
//check if the user has sufficient permissions
$oPerm = KTPermission::getByName('ktcore.permissions.delete');
if (!KTBrowseUtil::inAdminMode($user, $folder)) {
if (!KTPermissionUtil::userHasPermissionOnItem($user, $oPerm, $folder)) {
return PEAR::raiseError(_kt('You\'re not authorized to delete shortcuts'));
}
}
// we only need to delete the folder entry for the link
$sql = "DELETE FROM folders WHERE id=?";
DBUtil::runQuery(array($sql, array($folder->getId())));
}
示例12: doPluginRegistration
/**
* 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();
}
示例13: do_delete
function do_delete()
{
if (is_null($this->savedSearchId)) {
$this->errorRedirectTo('manage', _kt('The saved search id was not passed correctly.'));
}
$sql = "DELETE FROM search_saved WHERE type='S' AND id={$this->savedSearchId}";
if (!$this->sysAdmin) {
$sql .= " AND user_id={$this->curUserId} ";
}
$res = DBUtil::runQuery($sql);
if (DBUtil::affectedRows() == 0) {
$message = '';
// in case of database error, supply actual error as message
if (PEAR::isError($res)) {
$message = $res->getMessage();
}
if (!$this->sysAdmin) {
if ($message == '') {
$message = 'You do not have permission to delete this search.';
}
} else {
if ($message == '') {
$message = 'The saved search could not be deleted.';
}
}
$this->errorRedirectTo('manage', _kt($message));
}
$this->successRedirectTo('manage', _kt('The saved search was deleted successfully.'));
}
示例14: deleteSavedSearch
/**
* This method deletes the saved search based on the saved search id
*
* @author KnowledgeTree Team
* @access public
* @static
* @param integer $searchID The id of the saved search
* @return void
*/
public static function deleteSavedSearch($searchID)
{
$sysAdmin = Permission::userIsSystemAdministrator();
$sql = "DELETE FROM search_saved WHERE type='S' AND id={$searchID}";
if (!$sysAdmin) {
$sql .= " AND user_id='" . $_SESSION['userID'] . "'";
}
DBUtil::runQuery($sql);
}
示例15: renameFolder
function renameFolder($oFolder, $sNewName)
{
$table = "document_content_version";
$sQuery = "UPDATE {$table} SET storage_path = CONCAT(?, SUBSTRING(storage_path FROM ?)) WHERE storage_path LIKE ?";
if ($oFolder->getId() == 1) {
$sSrcFolderPath = $oFolder->getName();
$sDestFolderPath = $sNewName;
} else {
$sSrcFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $oFolder->getName());
$sDestFolderPath = sprintf("%s/%s", $oFolder->getFullPath(), $sNewName);
}
$aParams = array($sDestFolderPath, strlen($sSrcFolderPath) + 1, sprintf("%s%%", $sSrcFolderPath));
$res = DBUtil::runQuery(array($sQuery, $aParams));
if (PEAR::isError($res)) {
return $res;
}
$oConfig =& KTConfig::getSingleton();
$sSrc = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $sSrcFolderPath);
$sDst = sprintf("%s/%s", $oConfig->get('urls/documentRoot'), $sDestFolderPath);
$res = @rename($sSrc, $sDst);
if (PEAR::isError($res) || $res == false) {
print '<br /> -- unable to move ' . $sSrc . ' to ' . $sDst . ' ';
return false;
// return PEAR::raiseError('unable to move directory to ' . $sDst);
}
return true;
}