Ejemplo n.º 1
0
 /**
  * @param \OC\Files\Storage\Storage|string $storage
  * @throws \RuntimeException
  */
 public function __construct($storage)
 {
     if ($storage instanceof \OC\Files\Storage\Storage) {
         $this->storageId = $storage->getId();
     } else {
         $this->storageId = $storage;
     }
     $this->storageId = self::adjustStorageId($this->storageId);
     $sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?';
     $result = \OC_DB::executeAudited($sql, array($this->storageId));
     if ($row = $result->fetchRow()) {
         $this->numericId = $row['numeric_id'];
     } else {
         $connection = \OC_DB::getConnection();
         if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId])) {
             $this->numericId = \OC_DB::insertid('*PREFIX*storages');
         } else {
             $result = \OC_DB::executeAudited($sql, array($this->storageId));
             if ($row = $result->fetchRow()) {
                 $this->numericId = $row['numeric_id'];
             } else {
                 throw new \RuntimeException('Storage could neither be inserted nor be selected from the database');
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Function that is called after a user is added to a group.
  * TODO what does it do?
  * @param array $arguments
  */
 public static function post_addToGroup($arguments)
 {
     // Find the group shares and check if the user needs a unique target
     $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?');
     $result = $query->execute(array(self::SHARE_TYPE_GROUP, $arguments['gid']));
     $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`,' . ' `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`,' . ' `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
     while ($item = $result->fetchRow()) {
         $sourceExists = \OC\Share\Share::getItemSharedWithBySource($item['item_type'], $item['item_source'], self::FORMAT_NONE, null, true, $arguments['uid']);
         if ($sourceExists) {
             $fileTarget = $sourceExists['file_target'];
             $itemTarget = $sourceExists['item_target'];
         } else {
             $itemTarget = Helper::generateTarget($item['item_type'], $item['item_source'], self::SHARE_TYPE_USER, $arguments['uid'], $item['owner'], null, $item['parent']);
             // do we also need a file target
             if ($item['item_type'] === 'file' || $item['item_type'] === 'folder') {
                 $fileTarget = Helper::generateTarget('file', $item['file_target'], self::SHARE_TYPE_USER, $arguments['uid'], $item['owner'], null, $item['parent']);
             } else {
                 $fileTarget = null;
             }
         }
         // Insert an extra row for the group share if the item or file target is unique for this user
         if ($itemTarget != $item['item_target'] || $fileTarget != $item['file_target']) {
             $query->execute(array($item['item_type'], $item['item_source'], $itemTarget, $item['id'], self::$shareTypeGroupUserUnique, $arguments['uid'], $item['uid_owner'], $item['permissions'], $item['stime'], $item['file_source'], $fileTarget));
             \OC_DB::insertid('*PREFIX*share');
         }
     }
 }
 /**
  * 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');
 }
Ejemplo n.º 4
0
    public function add($callback, $topic)
    {
        $queryParts = array('timestamp', 'topic', 'callback');
        $params = array(time(), $topic, $callback);
        $sql = 'INSERT INTO `*PREFIX*hub_subscriptions`
					(`' . implode('`, `', $queryParts) . '`)
				VALUES (?,?,?)';
        \OC_DB::executeAudited($sql, $params);
        return \OC_DB::insertid('*PREFIX*hub_subscriptions');
    }
Ejemplo n.º 5
0
 /**
  * @param \OC\Files\Storage\Storage|string $storage
  */
 public function __construct($storage)
 {
     if ($storage instanceof \OC\Files\Storage\Storage) {
         $this->storageId = $storage->getId();
     } else {
         $this->storageId = $storage;
     }
     $this->storageId = self::adjustStorageId($this->storageId);
     $sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?';
     $result = \OC_DB::executeAudited($sql, array($this->storageId));
     if ($row = $result->fetchRow()) {
         $this->numericId = $row['numeric_id'];
     } else {
         $sql = 'INSERT INTO `*PREFIX*storages` (`id`) VALUES(?)';
         \OC_DB::executeAudited($sql, array($this->storageId));
         $this->numericId = \OC_DB::insertid('*PREFIX*storages');
     }
 }
Ejemplo n.º 6
0
 public function checkLastIndexId()
 {
     $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (' . ' `item_type`, `item_source`, `item_target`, `share_type`,' . ' `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,' . ' `file_target`, `token`, `parent`, `expiration`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)');
     $query->bindValue(1, 'file');
     $query->bindValue(2, 949);
     $query->bindValue(3, '/949');
     $query->bindValue(4, 0);
     $query->bindValue(5, 'migrate-test-user');
     $query->bindValue(6, 'migrate-test-owner');
     $query->bindValue(7, 23);
     $query->bindValue(8, 1402493312);
     $query->bindValue(9, 0);
     $query->bindValue(10, '/migration.txt');
     $query->bindValue(11, null);
     $query->bindValue(12, null);
     $query->bindValue(13, null);
     $this->assertEquals(1, $query->execute());
     $this->assertNotEquals('0', \OC_DB::insertid('*PREFIX*share'));
     // cleanup
     $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_target` = ?');
     $query->bindValue(1, '/migration.txt');
     $this->assertEquals(1, $query->execute());
 }
Ejemplo n.º 7
0
 /**
  * @param \OC\Files\Storage\Storage|string $storage
  * @param bool $isAvailable
  * @throws \RuntimeException
  */
 public function __construct($storage, $isAvailable = true)
 {
     if ($storage instanceof \OC\Files\Storage\Storage) {
         $this->storageId = $storage->getId();
     } else {
         $this->storageId = $storage;
     }
     $this->storageId = self::adjustStorageId($this->storageId);
     if ($row = self::getStorageById($this->storageId)) {
         $this->numericId = $row['numeric_id'];
     } else {
         $connection = \OC_DB::getConnection();
         if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $isAvailable])) {
             $this->numericId = \OC_DB::insertid('*PREFIX*storages');
         } else {
             if ($row = self::getStorageById($this->storageId)) {
                 $this->numericId = $row['numeric_id'];
             } else {
                 throw new \RuntimeException('Storage could neither be inserted nor be selected from the database');
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Put shared item into the database
  * @param string $itemType Item type
  * @param string $itemSource Item source
  * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  * @param string $shareWith User or group the item is being shared with
  * @param string $uidOwner User that is the owner of shared item
  * @param int $permissions CRUDS permissions
  * @param boolean|array $parentFolder Parent folder target (optional)
  * @param string $token (optional)
  * @param string $itemSourceName name of the source item (optional)
  * @param \DateTime $expirationDate (optional)
  * @throws \Exception
  * @return mixed id of the new share or false
  */
 private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null, $token = null, $itemSourceName = null, \DateTime $expirationDate = null)
 {
     $queriesToExecute = array();
     $suggestedItemTarget = null;
     $groupFileTarget = $fileTarget = $suggestedFileTarget = $filePath = '';
     $groupItemTarget = $itemTarget = $fileSource = $parent = 0;
     $result = self::checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate);
     if (!empty($result)) {
         $parent = $result['parent'];
         $itemSource = $result['itemSource'];
         $fileSource = $result['fileSource'];
         $suggestedItemTarget = $result['suggestedItemTarget'];
         $suggestedFileTarget = $result['suggestedFileTarget'];
         $filePath = $result['filePath'];
     }
     $isGroupShare = false;
     if ($shareType == self::SHARE_TYPE_GROUP) {
         $isGroupShare = true;
         if (isset($shareWith['users'])) {
             $users = $shareWith['users'];
         } else {
             $users = \OC_Group::usersInGroup($shareWith['group']);
         }
         // remove current user from list
         if (in_array(\OCP\User::getUser(), $users)) {
             unset($users[array_search(\OCP\User::getUser(), $users)]);
         }
         $groupItemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $suggestedItemTarget);
         $groupFileTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $filePath);
         // add group share to table and remember the id as parent
         $queriesToExecute['groupShare'] = array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $groupItemTarget, 'shareType' => $shareType, 'shareWith' => $shareWith['group'], 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $groupFileTarget, 'token' => $token, 'parent' => $parent, 'expiration' => $expirationDate);
     } else {
         $users = array($shareWith);
         $itemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedItemTarget);
     }
     $run = true;
     $error = '';
     $preHookData = array('itemType' => $itemType, 'itemSource' => $itemSource, 'shareType' => $shareType, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, 'expiration' => $expirationDate, 'token' => $token, 'run' => &$run, 'error' => &$error);
     $preHookData['itemTarget'] = $isGroupShare ? $groupItemTarget : $itemTarget;
     $preHookData['shareWith'] = $isGroupShare ? $shareWith['group'] : $shareWith;
     \OC_Hook::emit('OCP\\Share', 'pre_shared', $preHookData);
     if ($run === false) {
         throw new \Exception($error);
     }
     foreach ($users as $user) {
         $sourceId = $itemType === 'file' || $itemType === 'folder' ? $fileSource : $itemSource;
         $sourceExists = self::getItemSharedWithBySource($itemType, $sourceId, self::FORMAT_NONE, null, true, $user);
         $userShareType = $isGroupShare ? self::$shareTypeGroupUserUnique : $shareType;
         if ($sourceExists && $sourceExists['item_source'] === $itemSource) {
             $fileTarget = $sourceExists['file_target'];
             $itemTarget = $sourceExists['item_target'];
             // for group shares we don't need a additional entry if the target is the same
             if ($isGroupShare && $groupItemTarget === $itemTarget) {
                 continue;
             }
         } elseif (!$sourceExists && !$isGroupShare) {
             $itemTarget = Helper::generateTarget($itemType, $itemSource, $userShareType, $user, $uidOwner, $suggestedItemTarget, $parent);
             if (isset($fileSource)) {
                 if ($parentFolder) {
                     if ($parentFolder === true) {
                         $fileTarget = Helper::generateTarget('file', $filePath, $userShareType, $user, $uidOwner, $suggestedFileTarget, $parent);
                         if ($fileTarget != $groupFileTarget) {
                             $parentFolders[$user]['folder'] = $fileTarget;
                         }
                     } else {
                         if (isset($parentFolder[$user])) {
                             $fileTarget = $parentFolder[$user]['folder'] . $itemSource;
                             $parent = $parentFolder[$user]['id'];
                         }
                     }
                 } else {
                     $fileTarget = Helper::generateTarget('file', $filePath, $userShareType, $user, $uidOwner, $suggestedFileTarget, $parent);
                 }
             } else {
                 $fileTarget = null;
             }
         } else {
             // group share which doesn't exists until now, check if we need a unique target for this user
             $itemTarget = Helper::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $user, $uidOwner, $suggestedItemTarget, $parent);
             // do we also need a file target
             if (isset($fileSource)) {
                 $fileTarget = Helper::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $user, $uidOwner, $suggestedFileTarget, $parent);
             } else {
                 $fileTarget = null;
             }
             if ($itemTarget === $groupItemTarget && (!isset($fileSource) || $fileTarget === $groupFileTarget)) {
                 continue;
             }
         }
         $queriesToExecute[] = array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $itemTarget, 'shareType' => $userShareType, 'shareWith' => $user, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $fileTarget, 'token' => $token, 'parent' => $parent, 'expiration' => $expirationDate);
     }
     $id = false;
     if ($isGroupShare) {
         $id = self::insertShare($queriesToExecute['groupShare']);
         // Save this id, any extra rows for this group share will need to reference it
         $parent = \OC_DB::insertid('*PREFIX*share');
         unset($queriesToExecute['groupShare']);
     }
     foreach ($queriesToExecute as $shareQuery) {
         $shareQuery['parent'] = $parent;
         $id = self::insertShare($shareQuery);
     }
     $postHookData = array('itemType' => $itemType, 'itemSource' => $itemSource, 'parent' => $parent, 'shareType' => $shareType, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, 'id' => $parent, 'token' => $token, 'expirationDate' => $expirationDate);
     $postHookData['shareWith'] = $isGroupShare ? $shareWith['group'] : $shareWith;
     $postHookData['itemTarget'] = $isGroupShare ? $groupItemTarget : $itemTarget;
     $postHookData['fileTarget'] = $isGroupShare ? $groupFileTarget : $fileTarget;
     \OC_Hook::emit('OCP\\Share', 'post_shared', $postHookData);
     return $id ? $id : false;
 }
Ejemplo n.º 9
0
	public function testLastInsertId() {
		$query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)');
		$result1 = OC_DB::executeAudited($query, array('insertid 1','uri_1'));
		$id1 = OC_DB::insertid('*PREFIX*'.$this->table2);
		
		// we don't know the id we should expect, so insert another row
		$result2 = OC_DB::executeAudited($query, array('insertid 2','uri_2'));
		$id2 = OC_DB::insertid('*PREFIX*'.$this->table2);
		// now we can check if the two ids are in correct order
		$this->assertGreaterThan($id1, $id2);
	}
Ejemplo n.º 10
0
 /**
  * store meta data for a file or folder
  *
  * @param string $file
  * @param array $data
  *
  * @return int file id
  */
 public function put($file, array $data)
 {
     if (($id = $this->getId($file)) > -1) {
         $this->update($id, $data);
         return $id;
     } else {
         // normalize file
         $file = $this->normalize($file);
         if (isset($this->partial[$file])) {
             //add any saved partial data
             $data = array_merge($this->partial[$file], $data);
             unset($this->partial[$file]);
         }
         $requiredFields = array('size', 'mtime', 'mimetype');
         foreach ($requiredFields as $field) {
             if (!isset($data[$field])) {
                 //data not complete save as partial and return
                 $this->partial[$file] = $data;
                 return -1;
             }
         }
         $data['path'] = $file;
         $data['parent'] = $this->getParentId($file);
         $data['name'] = \OC_Util::basename($file);
         list($queryParts, $params) = $this->buildParts($data);
         $queryParts[] = '`storage`';
         $params[] = $this->getNumericStorageId();
         $valuesPlaceholder = array_fill(0, count($queryParts), '?');
         $sql = 'INSERT INTO `*PREFIX*filecache` (' . implode(', ', $queryParts) . ')' . ' VALUES (' . implode(', ', $valuesPlaceholder) . ')';
         \OC_DB::executeAudited($sql, $params);
         return (int) \OC_DB::insertid('*PREFIX*filecache');
     }
 }
 /**
  * Add an song to the database
  * @param string name
  * @param string path
  * @param integer artist
  * @param integer album
  * @return integer the song_id of the added artist
  */
 public static function addSong($name, $path, $artist, $album, $length, $track, $size)
 {
     $name = trim($name);
     $path = trim($path);
     if ($name == '' or $path == '') {
         return 0;
     }
     $uid = OC_User::getUser();
     //check if the song is already in the database
     $songId = self::getSongId($name, $artist, $album);
     if ($songId != 0) {
         $songInfo = self::getSong($songId);
         self::moveSong($songInfo['song_path'], $path);
         return $songId;
     } else {
         if (!isset(self::$queries['addsong'])) {
             $query = OC_DB::prepare("INSERT INTO  `*PREFIX*media_songs` (`song_name` ,`song_artist` ,`song_album` ,`song_path` ,`song_user`,`song_length`,`song_track`,`song_size`,`song_playcount`,`song_lastplayed`)\n\t\t\t\tVALUES (?, ?, ?, ?,?,?,?,?,0,0)");
             self::$queries['addsong'] = $query;
         } else {
             $query = self::$queries['addsong'];
         }
         $query->execute(array($name, $artist, $album, $path, $uid, $length, $track, $size));
         $songId = OC_DB::insertid();
         // 			self::setLastUpdated();
         return self::getSongId($name, $artist, $album);
     }
 }
Ejemplo n.º 12
0
 /**
  * Gets last value of autoincrement
  * @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix
  * @return int
  *
  * MDB2 lastInsertID()
  *
  * Call this method right after the insert command or other functions may
  * cause trouble!
  */
 public static function insertid($table = null)
 {
     return \OC_DB::insertid($table);
 }
*/
//no apps or filesystem
$RUNTIME_NOSETUPFS = true;
require_once '../../../lib/base.php';
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('bookmarks');
$CONFIG_DBTYPE = OC_Config::getValue("dbtype", "sqlite");
if ($CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3') {
    $_ut = "strftime('%s','now')";
} else {
    $_ut = "UNIX_TIMESTAMP()";
}
//FIXME: Detect when user adds a known URL
$query = OC_DB::prepare("\n\tINSERT INTO *PREFIX*bookmarks\n\t(url, title, user_id, public, added, lastmodified)\n\tVALUES (?, ?, ?, 0, {$_ut}, {$_ut})\n\t");
$params = array(htmlspecialchars_decode($_GET["url"]), htmlspecialchars_decode($_GET["title"]), OC_User::getUser());
$query->execute($params);
$b_id = OC_DB::insertid();
if ($b_id !== false) {
    $query = OC_DB::prepare("\n\t\tINSERT INTO *PREFIX*bookmarks_tags\n\t\t(bookmark_id, tag)\n\t\tVALUES (?, ?)\n\t\t");
    $tags = explode(' ', urldecode($_GET["tags"]));
    foreach ($tags as $tag) {
        if (empty($tag)) {
            //avoid saving blankspaces
            continue;
        }
        $params = array($b_id, trim($tag));
        $query->execute($params);
    }
    OC_JSON::success(array('data' => $b_id));
}
Ejemplo n.º 14
0
 /**
  * Put shared item into the database
  * @param string $itemType Item type
  * @param string $itemSource Item source
  * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  * @param string $shareWith User or group the item is being shared with
  * @param string $uidOwner User that is the owner of shared item
  * @param int $permissions CRUDS permissions
  * @param boolean|array $parentFolder Parent folder target (optional)
  * @param string $token (optional)
  * @param string $itemSourceName name of the source item (optional)
  * @param \DateTime $expirationDate (optional)
  * @throws \Exception
  * @return boolean Returns true on success or false on failure
  */
 private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null, $token = null, $itemSourceName = null, \DateTime $expirationDate = null)
 {
     $backend = self::getBackend($itemType);
     $l = \OC_L10N::get('lib');
     // Check if this is a reshare
     if ($checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true)) {
         // Check if attempting to share back to owner
         if ($checkReshare['uid_owner'] == $shareWith && $shareType == self::SHARE_TYPE_USER) {
             $message = 'Sharing %s failed, because the user %s is the original sharer';
             $message_t = $l->t('Sharing %s failed, because the user %s is the original sharer', array($itemSourceName, $shareWith));
             \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $shareWith), \OC_Log::ERROR);
             throw new \Exception($message_t);
         }
         // Check if share permissions is granted
         if (self::isResharingAllowed() && (int) $checkReshare['permissions'] & \OCP\PERMISSION_SHARE) {
             if (~(int) $checkReshare['permissions'] & $permissions) {
                 $message = 'Sharing %s failed, because the permissions exceed permissions granted to %s';
                 $message_t = $l->t('Sharing %s failed, because the permissions exceed permissions granted to %s', array($itemSourceName, $uidOwner));
                 \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName, $uidOwner), \OC_Log::ERROR);
                 throw new \Exception($message_t);
             } else {
                 // TODO Don't check if inside folder
                 $parent = $checkReshare['id'];
                 $itemSource = $checkReshare['item_source'];
                 $fileSource = $checkReshare['file_source'];
                 $suggestedItemTarget = $checkReshare['item_target'];
                 $suggestedFileTarget = $checkReshare['file_target'];
                 $filePath = $checkReshare['file_target'];
                 $expirationDate = min($expirationDate, $checkReshare['expiration']);
             }
         } else {
             $message = 'Sharing %s failed, because resharing is not allowed';
             $message_t = $l->t('Sharing %s failed, because resharing is not allowed', array($itemSourceName));
             \OC_Log::write('OCP\\Share', sprintf($message, $itemSourceName), \OC_Log::ERROR);
             throw new \Exception($message_t);
         }
     } else {
         $parent = null;
         $suggestedItemTarget = null;
         $suggestedFileTarget = null;
         if (!$backend->isValidSource($itemSource, $uidOwner)) {
             $message = 'Sharing %s failed, because the sharing backend for ' . '%s could not find its source';
             $message_t = $l->t('Sharing %s failed, because the sharing backend for %s could not find its source', array($itemSource, $itemType));
             \OC_Log::write('OCP\\Share', sprintf($message, $itemSource, $itemType), \OC_Log::ERROR);
             throw new \Exception($message_t);
         }
         if ($backend instanceof \OCP\Share_Backend_File_Dependent) {
             $filePath = $backend->getFilePath($itemSource, $uidOwner);
             if ($itemType == 'file' || $itemType == 'folder') {
                 $fileSource = $itemSource;
             } else {
                 $meta = \OC\Files\Filesystem::getFileInfo($filePath);
                 $fileSource = $meta['fileid'];
             }
             if ($fileSource == -1) {
                 $message = 'Sharing %s failed, because the file could not be found in the file cache';
                 $message_t = $l->t('Sharing %s failed, because the file could not be found in the file cache', array($itemSource));
                 \OC_Log::write('OCP\\Share', sprintf($message, $itemSource), \OC_Log::ERROR);
                 throw new \Exception($message_t);
             }
         } else {
             $filePath = null;
             $fileSource = null;
         }
     }
     // Share with a group
     if ($shareType == self::SHARE_TYPE_GROUP) {
         $groupItemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $suggestedItemTarget);
         $run = true;
         $error = '';
         \OC_Hook::emit('OCP\\Share', 'pre_shared', array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $groupItemTarget, 'shareType' => $shareType, 'shareWith' => $shareWith['group'], 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, 'expiration' => $expirationDate, 'token' => $token, 'run' => &$run, 'error' => &$error));
         if ($run === false) {
             throw new \Exception($error);
         }
         if (isset($fileSource)) {
             if ($parentFolder) {
                 if ($parentFolder === true) {
                     $groupFileTarget = Helper::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner, $suggestedFileTarget);
                     // Set group default file target for future use
                     $parentFolders[0]['folder'] = $groupFileTarget;
                 } else {
                     // Get group default file target
                     $groupFileTarget = $parentFolder[0]['folder'] . $itemSource;
                     $parent = $parentFolder[0]['id'];
                 }
             } else {
                 $groupFileTarget = Helper::generateTarget('file', $filePath, $shareType, $shareWith['group'], $uidOwner, $suggestedFileTarget);
             }
         } else {
             $groupFileTarget = null;
         }
         $queriesToExecute = array();
         $queriesToExecute['groupShare'] = array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $groupItemTarget, 'shareType' => $shareType, 'shareWith' => $shareWith['group'], 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $groupFileTarget, 'token' => $token, 'parent' => $parent, 'expiration' => $expirationDate);
         // Loop through all users of this group in case we need to add an extra row
         foreach ($shareWith['users'] as $uid) {
             $itemTarget = Helper::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $uid, $uidOwner, $suggestedItemTarget, $parent);
             if (isset($fileSource)) {
                 if ($parentFolder) {
                     if ($parentFolder === true) {
                         $fileTarget = Helper::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner, $suggestedFileTarget, $parent);
                         if ($fileTarget != $groupFileTarget) {
                             $parentFolders[$uid]['folder'] = $fileTarget;
                         }
                     } else {
                         if (isset($parentFolder[$uid])) {
                             $fileTarget = $parentFolder[$uid]['folder'] . $itemSource;
                             $parent = $parentFolder[$uid]['id'];
                         }
                     }
                 } else {
                     $fileTarget = Helper::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $uid, $uidOwner, $suggestedFileTarget, $parent);
                 }
             } else {
                 $fileTarget = null;
             }
             // Insert an extra row for the group share if the item or file target is unique for this user
             if ($itemTarget != $groupItemTarget || isset($fileSource) && $fileTarget != $groupFileTarget) {
                 $queriesToExecute[] = array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $itemTarget, 'shareType' => self::$shareTypeGroupUserUnique, 'shareWith' => $uid, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $fileTarget, 'token' => $token, 'expiration' => $expirationDate);
             }
         }
         self::insertShare($queriesToExecute['groupShare']);
         // Save this id, any extra rows for this group share will need to reference it
         $parent = \OC_DB::insertid('*PREFIX*share');
         unset($queriesToExecute['groupShare']);
         foreach ($queriesToExecute as $shareQuery) {
             $shareQuery['parent'] = $parent;
             self::insertShare($shareQuery);
         }
         \OC_Hook::emit('OCP\\Share', 'post_shared', array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $groupItemTarget, 'parent' => $parent, 'shareType' => $shareType, 'shareWith' => $shareWith['group'], 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, 'fileTarget' => $groupFileTarget, 'id' => $parent, 'token' => $token, 'expirationDate' => $expirationDate));
         if ($parentFolder === true) {
             // Return parent folders to preserve file target paths for potential children
             return $parentFolders;
         }
     } else {
         $itemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedItemTarget);
         $run = true;
         $error = '';
         \OC_Hook::emit('OCP\\Share', 'pre_shared', array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $itemTarget, 'shareType' => $shareType, 'shareWith' => $shareWith, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, 'token' => $token, 'expirationDate' => $expirationDate, 'run' => &$run, 'error' => &$error));
         if ($run === false) {
             throw new \Exception($error);
         }
         if (isset($fileSource)) {
             if ($parentFolder) {
                 if ($parentFolder === true) {
                     $fileTarget = Helper::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner, $suggestedFileTarget);
                     $parentFolders['folder'] = $fileTarget;
                 } else {
                     $fileTarget = $parentFolder['folder'] . $itemSource;
                     $parent = $parentFolder['id'];
                 }
             } else {
                 $fileTarget = Helper::generateTarget('file', $filePath, $shareType, $shareWith, $uidOwner, $suggestedFileTarget);
             }
         } else {
             $fileTarget = null;
         }
         self::insertShare(array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $itemTarget, 'shareType' => $shareType, 'shareWith' => $shareWith, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $fileTarget, 'token' => $token, 'parent' => $parent, 'expiration' => $expirationDate));
         $id = \OC_DB::insertid('*PREFIX*share');
         \OC_Hook::emit('OCP\\Share', 'post_shared', array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $itemTarget, 'parent' => $parent, 'shareType' => $shareType, 'shareWith' => $shareWith, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, 'fileTarget' => $fileTarget, 'id' => $id, 'token' => $token, 'expirationDate' => $expirationDate));
         if ($parentFolder === true) {
             $parentFolders['id'] = $id;
             // Return parent folder to preserve file target paths for potential children
             return $parentFolders;
         }
     }
     return true;
 }
 /**
  * @brief Creates a new address book from the data sabredav provides
  * @param string $principaluri
  * @param string $uri
  * @param string $name
  * @param string $description
  * @return insertid
  */
 public static function addFromDAVData($principaluri, $uri, $name, $description)
 {
     $userid = self::extractUserID($principaluri);
     $stmt = OC_DB::prepare('INSERT INTO *PREFIX*contacts_addressbooks (userid,displayname,uri,description,ctag) VALUES(?,?,?,?,?)');
     $result = $stmt->execute(array($userid, $name, $uri, $description, 1));
     return OC_DB::insertid();
 }
Ejemplo n.º 16
0
 /**
  * store meta data for a file or folder
  *
  * @param string $file
  * @param array $data
  *
  * @return int file id
  */
 public function put($file, array $data)
 {
     if (($id = $this->getId($file)) > -1) {
         $this->update($id, $data);
         return $id;
     } else {
         if (isset($this->partial[$file])) {
             //add any saved partial data
             $data = array_merge($this->partial[$file], $data);
             unset($this->partial[$file]);
         }
         $requiredFields = array('size', 'mtime', 'mimetype');
         foreach ($requiredFields as $field) {
             if (!isset($data[$field])) {
                 //data not complete save as partial and return
                 $this->partial[$file] = $data;
                 return -1;
             }
         }
         $data['path'] = $file;
         $data['parent'] = $this->getParentId($file);
         $data['name'] = basename($file);
         $data['encrypted'] = isset($data['encrypted']) ? (int) $data['encrypted'] : 0;
         list($queryParts, $params) = $this->buildParts($data);
         $queryParts[] = '`storage`';
         $params[] = $this->numericId;
         $valuesPlaceholder = array_fill(0, count($queryParts), '?');
         $query = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache`(' . implode(', ', $queryParts) . ')' . ' VALUES(' . implode(', ', $valuesPlaceholder) . ')');
         $result = $query->execute($params);
         if (\OC_DB::isError($result)) {
             \OCP\Util::writeLog('cache', 'Insert to cache failed: ' . $result->getMessage(), \OCP\Util::ERROR);
         }
         return (int) \OC_DB::insertid('*PREFIX*filecache');
     }
 }
Ejemplo n.º 17
0
	/**
	 * store meta data for a file or folder
	 *
	 * @param string $file
	 * @param array $data
	 *
	 * @return int file id
	 */
	public function put($file, array $data) {
		if (($id = $this->getId($file)) > -1) {
			$this->update($id, $data);
			return $id;
		} else {
			// normalize file
			$file = $this->normalize($file);

			if (isset($this->partial[$file])) { //add any saved partial data
				$data = array_merge($this->partial[$file], $data);
				unset($this->partial[$file]);
			}

			$requiredFields = array('size', 'mtime', 'mimetype');
			foreach ($requiredFields as $field) {
				if (!isset($data[$field])) { //data not complete save as partial and return
					$this->partial[$file] = $data;
					return -1;
				}
			}

			$data['path'] = $file;
			$data['parent'] = $this->getParentId($file);
			$data['name'] = \OC_Util::basename($file);

			list($queryParts, $params) = $this->buildParts($data);
			$queryParts[] = '`storage`';
			$params[] = $this->getNumericStorageId();

			$params = array_map(function($item) {
				return trim($item, "`");
			}, $params);
			$queryParts = array_map(function($item) {
				return trim($item, "`");
			}, $queryParts);
			$values = array_combine($queryParts, $params);
			if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values)) {
				return (int)\OC_DB::insertid('*PREFIX*filecache');
			}

			return $this->getId($file);
		}
	}
 /**
  * @brief Adds an object with the data provided by sabredav
  * @param integer $id Calendar id
  * @param string $uri   the uri the card will have
  * @param string $data  object
  * @return insertid
  */
 public static function addFromDAVData($id, $uri, $data)
 {
     $object = self::parse($data);
     list($type, $startdate, $enddate, $summary, $repeating, $uid) = self::extractData($object);
     $stmt = OC_DB::prepare('INSERT INTO *PREFIX*calendar_objects (calendarid,objecttype,startdate,enddate,repeating,summary,calendardata,uri,lastmodified) VALUES(?,?,?,?,?,?,?,?,?)');
     $result = $stmt->execute(array($id, $type, $startdate, $enddate, $repeating, $summary, $data, $uri, time()));
     OC_Calendar_Calendar::touchCalendar($id);
     return OC_DB::insertid();
 }
Ejemplo n.º 19
0
 /**
  * @brief queues a task
  * @param $app app name
  * @param $klass class name
  * @param $method method name
  * @param $parameters all useful data as text
  * @return id of task
  */
 public static function add($app, $klass, $method, $parameters)
 {
     $stmt = OC_DB::prepare('INSERT INTO `*PREFIX*queuedtasks` (`app`, `klass`, `method`, `parameters`) VALUES(?,?,?,?)');
     $result = $stmt->execute(array($app, $klass, $method, $parameters));
     return OC_DB::insertid();
 }
 /**
  * @brief Adds a card with the data provided by sabredav
  * @param integer $id Addressbook id
  * @param string $uri   the uri the card will have
  * @param string $data  vCard file
  * @return insertid
  */
 public static function addFromDAVData($id, $uri, $data)
 {
     $fn = null;
     $card = self::parse($data);
     if (!is_null($card)) {
         foreach ($card->children as $property) {
             if ($property->name == 'FN') {
                 $fn = $property->value;
             }
         }
     }
     $stmt = OC_DB::prepare('INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)');
     $result = $stmt->execute(array($id, $fn, $data, $uri, time()));
     OC_Contacts_Addressbook::touch($id);
     return OC_DB::insertid();
 }
Ejemplo n.º 21
0
 /**
  * store meta data for a file or folder
  *
  * @param string $file
  * @param array $data
  *
  * @return int file id
  * @throws \RuntimeException
  */
 public function put($file, array $data)
 {
     if (($id = $this->getId($file)) > -1) {
         $this->update($id, $data);
         return $id;
     } else {
         // normalize file
         $file = $this->normalize($file);
         if (isset($this->partial[$file])) {
             //add any saved partial data
             $data = array_merge($this->partial[$file], $data);
             unset($this->partial[$file]);
         }
         $requiredFields = array('size', 'mtime', 'mimetype');
         foreach ($requiredFields as $field) {
             if (!isset($data[$field])) {
                 //data not complete save as partial and return
                 $this->partial[$file] = $data;
                 return -1;
             }
         }
         $data['path'] = $file;
         $data['parent'] = $this->getParentId($file);
         $data['name'] = \OC_Util::basename($file);
         list($queryParts, $params) = $this->buildParts($data);
         $queryParts[] = '`storage`';
         $params[] = $this->getNumericStorageId();
         $queryParts = array_map(function ($item) {
             return trim($item, "`");
         }, $queryParts);
         $values = array_combine($queryParts, $params);
         if (\OC::$server->getDatabaseConnection()->insertIfNotExist('*PREFIX*filecache', $values, ['storage', 'path_hash'])) {
             return (int) \OC_DB::insertid('*PREFIX*filecache');
         }
         // The file was created in the mean time
         if (($id = $this->getId($file)) > -1) {
             $this->update($id, $data);
             return $id;
         } else {
             throw new \RuntimeException('File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.');
         }
     }
 }
 /**
  * @brief Creates a new calendar from the data sabredav provides
  * @param string $principaluri
  * @param string $uri
  * @param string $name
  * @param string $components
  * @param string $timezone
  * @param integer $order
  * @param string $color
  * @return insertid
  */
 public static function addCalendarFromDAVData($principaluri, $uri, $name, $components, $timezone, $order, $color)
 {
     $userid = self::extractUserID($principaluri);
     $stmt = OC_DB::prepare('INSERT INTO *PREFIX*calendar_calendars (userid,displayname,uri,ctag,calendarorder,calendarcolor,timezone,components) VALUES(?,?,?,?,?,?,?,?)');
     $result = $stmt->execute(array($userid, $name, $uri, 1, $order, $color, $timezone, $components));
     return OC_DB::insertid();
 }