本文整理汇总了PHP中OC_DB类的典型用法代码示例。如果您正苦于以下问题:PHP OC_DB类的具体用法?PHP OC_DB怎么用?PHP OC_DB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OC_DB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cleanDB
function cleanDB()
{
$query1 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks');
$query1->execute();
$query2 = OC_DB::prepare('DELETE FROM *PREFIX*bookmarks_tags');
$query2->execute();
}
示例2: runStep
/**
* Send an email to {$limit} users
*
* @param int $limit Number of users we want to send an email to
* @return int Number of users we sent an email to
*/
protected function runStep($limit)
{
// Get all users which should receive an email
$affectedUsers = $this->mqHandler->getAffectedUsers($limit);
if (empty($affectedUsers)) {
// No users found to notify, mission abort
return 0;
}
$preferences = new \OC\Preferences(\OC_DB::getConnection());
$userLanguages = $preferences->getValueForUsers('core', 'lang', $affectedUsers);
$userEmails = $preferences->getValueForUsers('settings', 'email', $affectedUsers);
// Get all items for these users
// We don't use time() but "time() - 1" here, so we don't run into
// runtime issues and delete emails later, which were created in the
// same second, but were not collected for the emails.
$sendTime = time() - 1;
$mailData = $this->mqHandler->getItemsForUsers($affectedUsers, $sendTime);
// Send Email
$default_lang = \OC_Config::getValue('default_language', 'en');
foreach ($mailData as $user => $data) {
if (!isset($userEmails[$user])) {
// The user did not setup an email address
// So we will not send an email :(
continue;
}
$language = isset($userLanguages[$user]) ? $userLanguages[$user] : $default_lang;
$this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $data);
}
// Delete all entries we dealt with
$this->mqHandler->deleteSentItems($affectedUsers, $sendTime);
return sizeof($affectedUsers);
}
示例3: calculateFolderSize
/**
* get the size of a folder and set it in the cache
*
* @param string $path
* @param array $entry (optional) meta data of the folder
* @return int
*/
public function calculateFolderSize($path, $entry = null)
{
if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {
return parent::calculateFolderSize($path, $entry);
} elseif ($path === '' or $path === '/') {
// since the size of / isn't used (the size of /files is used instead) there is no use in calculating it
return 0;
}
$totalSize = 0;
if (is_null($entry)) {
$entry = $this->get($path);
}
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
$id = $entry['fileid'];
$sql = 'SELECT SUM(`size`) AS f1, ' . 'SUM(`unencrypted_size`) AS f2 FROM `*PREFIX*filecache` ' . 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
list($sum, $unencryptedSum) = array_values($row);
$totalSize = 0 + $sum;
$unencryptedSize = 0 + $unencryptedSum;
$entry['size'] += 0;
$entry['unencrypted_size'] += 0;
if ($entry['size'] !== $totalSize) {
$this->update($id, array('size' => $totalSize));
}
if ($entry['unencrypted_size'] !== $unencryptedSize) {
$this->update($id, array('unencrypted_size' => $unencryptedSize));
}
}
}
return $totalSize;
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->validateInput($input, $output);
$this->readPassword($input, $output);
$fromDB = \OC_DB::getConnection();
$toDB = $this->getToDBConnection($input, $output);
if ($input->getOption('clear-schema')) {
$this->clearSchema($toDB, $input, $output);
}
$this->createSchema($toDB, $input, $output);
$toTables = $this->getTables($toDB);
$fromTables = $this->getTables($fromDB);
// warn/fail if there are more tables in 'from' database
$extraFromTables = array_diff($fromTables, $toTables);
if (!empty($extraFromTables)) {
$output->writeln('<comment>The following tables will not be converted:</comment>');
$output->writeln($extraFromTables);
if (!$input->getOption('all-apps')) {
$output->writeln('<comment>Please note that tables belonging to available but currently not installed apps</comment>');
$output->writeln('<comment>can be included by specifying the --all-apps option.</comment>');
}
/** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
$dialog = $this->getHelperSet()->get('dialog');
if (!$dialog->askConfirmation($output, '<question>Continue with the conversion (y/n)? [n] </question>', false)) {
return;
}
}
$intersectingTables = array_intersect($toTables, $fromTables);
$this->convertDB($fromDB, $toDB, $intersectingTables, $input, $output);
}
示例5: getPathAndUser
/**
* lookup file path and owner by fetching it from the fscache
* needed becaus OC_FileCache::getPath($id, $user) already requires the user
* @param int $id
* @return array
*/
function getPathAndUser($id)
{
$query = \OC_DB::prepare('SELECT `user`, `path` FROM `*PREFIX*fscache` WHERE `id` = ?');
$result = $query->execute(array($id));
$row = $result->fetchRow();
return $row;
}
示例6: testShareMountLoseParentFolder
/**
* test if the mount point moves up if the parent folder no longer exists
*/
function testShareMountLoseParentFolder()
{
// share to user
$fileinfo = $this->view->getFileInfo($this->folder);
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
$statement = "UPDATE `*PREFIX*share` SET `file_target` = ? where `share_with` = ?";
$query = \OC_DB::prepare($statement);
$arguments = array('/foo/bar' . $this->folder, self::TEST_FILES_SHARING_API_USER2);
$query->execute($arguments);
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $query->execute();
$shares = $result->fetchAll();
$this->assertSame(1, count($shares));
$share = reset($shares);
$this->assertSame('/foo/bar' . $this->folder, $share['file_target']);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
// share should have moved up
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`');
$result = $query->execute();
$shares = $result->fetchAll();
$this->assertSame(1, count($shares));
$share = reset($shares);
$this->assertSame($this->folder, $share['file_target']);
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$this->view->unlink($this->folder);
}
示例7: scan
public static function scan($id, $path, $storage)
{
$file = $storage->getLocalFile($path);
$result = OC_Files_Antivirus::clamav_scan($file);
switch ($result) {
case CLAMAV_SCANRESULT_UNCHECKED:
\OCP\Util::writeLog('files_antivirus', 'File "' . $path . '" from user "' . $user . '": is not checked', \OCP\Util::ERROR);
break;
case CLAMAV_SCANRESULT_INFECTED:
$infected_action = \OCP\Config::getAppValue('files_antivirus', 'infected_action', 'only_log');
if ($infected_action == 'delete') {
\OCP\Util::writeLog('files_antivirus', 'File "' . $path . '" from user "' . $user . '": is infected, file deleted', \OCP\Util::ERROR);
unlink($file);
} else {
\OCP\Util::writeLog('files_antivirus', 'File "' . $path . '" from user "' . $user . '": is infected', \OCP\Util::ERROR);
}
break;
case CLAMAV_SCANRESULT_CLEAN:
$stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*files_antivirus` (`fileid`, `check_time`) VALUES (?, ?)');
try {
$result = $stmt->execute(array($id, time()));
if (\OC_DB::isError($result)) {
\OC_Log::write('files_antivirus', __METHOD__ . ', DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
return;
}
} catch (\Exception $e) {
\OCP\Util::writeLog('files_antivirus', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
}
break;
}
}
示例8: getChildren
public function getChildren($itemSource)
{
$children = array();
$parents = array($itemSource);
$query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
$result = $query->execute(array('httpd/unix-directory'));
if ($row = $result->fetchRow()) {
$mimetype = $row['id'];
} else {
$mimetype = -1;
}
while (!empty($parents)) {
$parents = "'" . implode("','", $parents) . "'";
$query = OC_DB::prepare('SELECT `fileid`, `name`, `mimetype` FROM `*PREFIX*filecache`' . ' WHERE `parent` IN (' . $parents . ')');
$result = $query->execute();
$parents = array();
while ($file = $result->fetchRow()) {
$children[] = array('source' => $file['fileid'], 'file_path' => $file['name']);
// If a child folder is found look inside it
if ($file['mimetype'] == $mimetype) {
$parents[] = $file['fileid'];
}
}
}
return $children;
}
示例9: calculateFolderSize
/**
* get the size of a folder and set it in the cache
*
* @param string $path
* @return int
*/
public function calculateFolderSize($path)
{
if ($path !== '/' and $path !== '' and $path !== 'files') {
return parent::calculateFolderSize($path);
}
$totalSize = 0;
$entry = $this->get($path);
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
$id = $entry['fileid'];
$sql = 'SELECT SUM(`size`) AS f1, ' . 'SUM(`unencrypted_size`) AS f2 FROM `*PREFIX*filecache` ' . 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
list($sum, $unencryptedSum) = array_values($row);
$totalSize = (int) $sum;
$unencryptedSize = (int) $unencryptedSum;
if ($entry['size'] !== $totalSize) {
$this->update($id, array('size' => $totalSize));
}
if ($entry['unencrypted_size'] !== $unencryptedSize) {
$this->update($id, array('unencrypted_size' => $unencryptedSize));
}
}
}
return $totalSize;
}
示例10: createStorage
/**
* Create a storage entry
*
* @param string $storageId
*/
private function createStorage($storageId)
{
$sql = 'INSERT INTO `*PREFIX*storages` (`id`)' . ' VALUES (?)';
$storageId = \OC\Files\Cache\Storage::adjustStorageId($storageId);
$numRows = $this->connection->executeUpdate($sql, array($storageId));
$this->assertEquals(1, $numRows);
return \OC_DB::insertid('*PREFIX*storages');
}
示例11: getMimeTypeIdFromDB
/**
* Returns the id of a given mime type or null
* if it does not exist.
*/
private function getMimeTypeIdFromDB($mimeType) {
$sql = 'SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?';
$results = \OC_DB::executeAudited($sql, [$mimeType]);
$result = $results->fetchOne();
if ($result) {
return $result['id'];
}
return null;
}
示例12: setUp
public function setUp()
{
$this->connection = \OC_DB::getConnection();
if ($this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\OCI8\Driver) {
$this->markTestSkipped('DB migration tests arent supported on OCI');
}
$this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
$this->tableName = 'test_' . uniqid();
}
示例13: setUp
public function setUp()
{
$this->connection = \OC_DB::getConnection();
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
$this->markTestSkipped("Test only relevant on MySql");
}
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
$this->tableName = uniqid($dbPrefix . "_enum_bit_test");
$this->connection->exec("CREATE TABLE {$this->tableName}(b BIT, e ENUM('1','2','3','4'))");
}
示例14: findUserForIdentity
/**
* find the user that can be authenticated with an openid identity
*/
public static function findUserForIdentity($identity)
{
$query = OC_DB::prepare('SELECT userid FROM *PREFIX*preferences WHERE appid=? AND configkey=? AND configvalue=?');
$result = $query->execute(array('user_openid', 'identity', $identity))->fetchAll();
if (count($result) > 0) {
return $result[0]['userid'];
} else {
return false;
}
}
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:13,代码来源:owncloud_apps_user_openid_user_openid.php
示例15: setUp
public function setUp()
{
$this->connection = \OC_DB::getConnection();
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
$this->markTestSkipped("Test only relevant on Sqlite");
}
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
$this->tableName = uniqid($dbPrefix . "_enum_bit_test");
$this->connection->exec("CREATE TABLE {$this->tableName}(t0 tinyint unsigned, t1 tinyint)");
}