本文整理汇总了PHP中OCP\IDBConnection::insertIfNotExist方法的典型用法代码示例。如果您正苦于以下问题:PHP IDBConnection::insertIfNotExist方法的具体用法?PHP IDBConnection::insertIfNotExist怎么用?PHP IDBConnection::insertIfNotExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\IDBConnection
的用法示例。
在下文中一共展示了IDBConnection::insertIfNotExist方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addShare
/**
* add new server-to-server share
*
* @param string $remote
* @param string $token
* @param string $password
* @param string $name
* @param string $owner
* @param boolean $accepted
* @param string $user
* @param int $remoteId
* @return Mount|null
*/
public function addShare($remote, $token, $password, $name, $owner, $accepted = false, $user = null, $remoteId = -1)
{
$user = $user ? $user : $this->uid;
$accepted = $accepted ? 1 : 0;
$name = Filesystem::normalizePath('/' . $name);
if (!$accepted) {
// To avoid conflicts with the mount point generation later,
// we only use a temporary mount point name here. The real
// mount point name will be generated when accepting the share,
// using the original share item name.
$tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}';
$mountPoint = $tmpMountPointName;
$hash = md5($tmpMountPointName);
$data = ['remote' => $remote, 'share_token' => $token, 'password' => $password, 'name' => $name, 'owner' => $owner, 'user' => $user, 'mountpoint' => $mountPoint, 'mountpoint_hash' => $hash, 'accepted' => $accepted, 'remote_id' => $remoteId];
$i = 1;
while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) {
// The external share already exists for the user
$data['mountpoint'] = $tmpMountPointName . '-' . $i;
$data['mountpoint_hash'] = md5($data['mountpoint']);
$i++;
}
return null;
}
$mountPoint = Files::buildNotExistingFileName('/', $name);
$mountPoint = Filesystem::normalizePath('/' . $mountPoint);
$hash = md5($mountPoint);
$query = $this->connection->prepare('
INSERT INTO `*PREFIX*share_external`
(`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
');
$query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId));
$options = array('remote' => $remote, 'token' => $token, 'password' => $password, 'mountpoint' => $mountPoint, 'owner' => $owner);
return $this->mountShare($options);
}
示例2: createGroup
/**
* Try to create a new group
* @param string $gid The name of the group to create
* @return bool
*
* Tries to create a new group. If the group name already exists, false will
* be returned.
*/
public function createGroup($gid)
{
$this->fixDI();
// Add group
$result = $this->dbConn->insertIfNotExist('*PREFIX*groups', ['gid' => $gid]);
// Add to cache
$this->groupCache[$gid] = $gid;
return $result === 1;
}
示例3: createCacheEntry
private function createCacheEntry($internalPath, $storageId)
{
$this->connection->insertIfNotExist('*PREFIX*filecache', ['storage' => $storageId, 'path' => $internalPath, 'path_hash' => md5($internalPath), 'parent' => -1, 'name' => basename($internalPath), 'mimetype' => 0, 'mimepart' => 0, 'size' => 0, 'storage_mtime' => 0, 'encrypted' => 0, 'unencrypted_size' => 0, 'etag' => '', 'permissions' => 31], ['storage', 'path_hash']);
$id = (int) $this->connection->lastInsertId('*PREFIX*filecache');
$this->fileIds[] = $id;
return $id;
}
示例4: setValue
/**
* Sets a value. If the key did not exist before it will be created.
*
* @param string $app app
* @param string $key key
* @param string|float|int $value value
* @return bool True if the value was inserted or updated, false if the value was the same
*/
public function setValue($app, $key, $value)
{
if (!$this->hasKey($app, $key)) {
$inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', ['appid' => $app, 'configkey' => $key, 'configvalue' => $value], ['appid', 'configkey']);
if ($inserted) {
if (!isset($this->cache[$app])) {
$this->cache[$app] = [];
}
$this->cache[$app][$key] = $value;
return true;
}
}
$sql = $this->conn->getQueryBuilder();
$sql->update('appconfig')->set('configvalue', $sql->createParameter('configvalue'))->where($sql->expr()->eq('appid', $sql->createParameter('app')))->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))->setParameter('configvalue', $value)->setParameter('app', $app)->setParameter('configkey', $key);
/*
* Only limit to the existing value for non-Oracle DBs:
* http://docs.oracle.com/cd/E11882_01/server.112/e26088/conditions002.htm#i1033286
* > Large objects (LOBs) are not supported in comparison conditions.
*/
if (!$this->conn instanceof \OC\DB\OracleConnection) {
// Only update the value when it is not the same
$sql->andWhere($sql->expr()->neq('configvalue', $sql->createParameter('configvalue')))->setParameter('configvalue', $value);
}
$changedRow = (bool) $sql->execute();
$this->cache[$app][$key] = $value;
return $changedRow;
}
示例5: addToCache
private function addToCache(ICachedMountInfo $mount)
{
if ($mount->getStorageId() !== -1) {
$this->connection->insertIfNotExist('*PREFIX*mounts', ['storage_id' => $mount->getStorageId(), 'root_id' => $mount->getRootId(), 'user_id' => $mount->getUser()->getUID(), 'mount_point' => $mount->getMountPoint()], ['root_id', 'user_id']);
} else {
$this->logger->error('Error getting storage info for mount at ' . $mount->getMountPoint());
}
}
示例6: map
/**
* attempts to map the given entry
* @param string $fdn fully distinguished name (from LDAP)
* @param string $name
* @param string $uuid a unique identifier as used in LDAP
* @return bool
*/
public function map($fdn, $name, $uuid)
{
$row = array('ldap_dn' => $fdn, 'owncloud_name' => $name, 'directory_uuid' => $uuid);
try {
$result = $this->dbc->insertIfNotExist($this->getTableName(), $row);
// insertIfNotExist returns values as int
return (bool) $result;
} catch (\Exception $e) {
return false;
}
}
示例7: setValue
/**
* Sets a value. If the key did not exist before it will be created.
*
* @param string $app app
* @param string $key key
* @param string $value value
* @return bool True if the value was inserted or updated, false if the value was the same
*/
public function setValue($app, $key, $value)
{
if (!$this->hasKey($app, $key)) {
$inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', ['appid' => $app, 'configkey' => $key, 'configvalue' => $value], ['appid', 'configkey']);
if ($inserted) {
if (!isset($this->cache[$app])) {
$this->cache[$app] = [];
}
$this->cache[$app][$key] = $value;
return true;
}
}
$sql = $this->conn->getQueryBuilder();
$sql->update('appconfig')->set('configvalue', $sql->createParameter('configvalue'))->where($sql->expr()->eq('appid', $sql->createParameter('app')))->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))->andWhere($sql->expr()->neq('configvalue', $sql->createParameter('configvalue')))->setParameter('configvalue', $value)->setParameter('app', $app)->setParameter('configkey', $key)->setParameter('configvalue', $value);
$changedRow = (bool) $sql->execute();
$this->cache[$app][$key] = $value;
return $changedRow;
}
示例8: setUserValue
/**
* Set a user defined value
*
* @param string $userId the userId of the user that we want to store the value under
* @param string $appName the appName that we want to store the value under
* @param string $key the key under which the value is being stored
* @param string $value the value that you want to store
* @param string $preCondition only update if the config value was previously the value passed as $preCondition
* @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
*/
public function setUserValue($userId, $appName, $key, $value, $preCondition = null)
{
// TODO - FIXME
$this->fixDIInit();
// Check if the key does exist
$sql = 'SELECT `configvalue` FROM `*PREFIX*preferences` ' . 'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?';
$result = $this->connection->executeQuery($sql, array($userId, $appName, $key));
$oldValue = $result->fetchColumn();
$result->closeCursor();
$exists = $oldValue !== false;
if ($oldValue === strval($value)) {
// no changes
return;
}
$affectedRows = 0;
if (!$exists && $preCondition === null) {
$this->connection->insertIfNotExist('*PREFIX*preferences', ['configvalue' => $value, 'userid' => $userId, 'appid' => $appName, 'configkey' => $key], ['configkey', 'userid', 'appid']);
$affectedRows = 1;
} elseif ($exists) {
$data = array($value, $userId, $appName, $key);
$sql = 'UPDATE `*PREFIX*preferences` SET `configvalue` = ? ' . 'WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? ';
if ($preCondition !== null) {
if ($this->getSystemValue('dbtype', 'sqlite') === 'oci') {
//oracle hack: need to explicitly cast CLOB to CHAR for comparison
$sql .= 'AND to_char(`configvalue`) = ?';
} else {
$sql .= 'AND `configvalue` = ?';
}
$data[] = $preCondition;
}
$affectedRows = $this->connection->executeUpdate($sql, $data);
}
// only add to the cache if we already loaded data for the user
if ($affectedRows > 0 && isset($this->userCache[$userId])) {
if (!isset($this->userCache[$userId][$appName])) {
$this->userCache[$userId][$appName] = array();
}
$this->userCache[$userId][$appName][$key] = $value;
}
if ($preCondition !== null && $affectedRows === 0) {
throw new PreConditionNotMetException();
}
}
示例9: initLockField
/**
* Insert a file locking row if it does not exists.
*
* @param string $path
* @param int $lock
* @return int number of inserted rows
*/
protected function initLockField($path, $lock = 0) {
$expire = $this->getExpireTime();
return $this->connection->insertIfNotExist('*PREFIX*file_locks', ['key' => $path, 'lock' => $lock, 'ttl' => $expire], ['key']);
}
示例10: initLockField
protected function initLockField($path)
{
$this->connection->insertIfNotExist('*PREFIX*file_locks', ['key' => $path, 'lock' => 0, 'ttl' => 0], ['key']);
}
示例11: addApplicable
public function addApplicable($mountId, $type, $value)
{
$this->connection->insertIfNotExist('*PREFIX*external_applicable', ['mount_id' => $mountId, 'type' => $type, 'value' => $value], ['mount_id', 'type', 'value']);
}
示例12: addToCache
private function addToCache(ICachedMountInfo $mount)
{
$this->connection->insertIfNotExist('*PREFIX*mounts', ['storage_id' => $mount->getStorageId(), 'root_id' => $mount->getRootId(), 'user_id' => $mount->getUser()->getUID(), 'mount_point' => $mount->getMountPoint()], ['root_id', 'user_id']);
}
示例13: insertIfNotExist
/**
* Insert a row if the matching row does not exists.
*
* @param string $table The table name (will replace *PREFIX* with the actual prefix)
* @param array $input data that should be inserted into the table (column name => value)
* @param array|null $compare List of values that should be checked for "if not exists"
* If this is null or an empty array, all keys of $input will be compared
* Please note: text fields (clob) must not be used in the compare array
* @return int number of inserted rows
* @throws \Doctrine\DBAL\DBALException
*/
public function insertIfNotExist($table, $input, array $compare = null)
{
return $this->connection->insertIfNotExist($table, $input, $compare);
}