]> source.dussan.org Git - nextcloud-server.git/commitdiff
Provide update script for files sharing
authorMichael Gapczynski <mtgap@owncloud.com>
Sun, 9 Sep 2012 22:29:47 +0000 (18:29 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Sun, 9 Sep 2012 22:29:47 +0000 (18:29 -0400)
apps/files_sharing/appinfo/update.php
apps/files_sharing/appinfo/version
apps/files_sharing/lib/share/file.php

index feafa5fb9921b2538957b83bc0f219c016ad585d..cb6af2d5f0d756f6c47018e32ef2d1f2801f87a2 100644 (file)
@@ -1,16 +1,47 @@
 <?php
-
-// touch shared directories to trigger one-time re-scan for all users
-$datadir = \OCP\Config::getSystemValue('datadirectory');
-$currentVersion=OC_Appconfig::getValue('files_sharing', 'installed_version');
-if (version_compare($currentVersion, '0.2.2', '<')) {
-       if ($handle = opendir($datadir)) {
-               while (false !== ($entry = readdir($handle))) {
-                       $sharedFolder = $datadir.'/'.$entry.'/files/Shared';
-                       if ($entry != "." && $entry != ".." && is_dir($sharedFolder)) {
-                               touch($sharedFolder);
+$installedVersion = OCP\Config::getAppValue('files_sharing', 'installed_version');
+if (version_compare($installedVersion, '0.3.2', '<')) {
+       $query = OCP\DB::prepare('SELECT * FROM `*PREFIX*sharing`');
+       $result = $query->execute();
+       $groupShares = array();
+       while ($row = $result->fetchRow()) {
+               $itemSource = OC_FileCache::getId($row['source'], '');
+               if ($itemSource != -1) {
+                       $file = OC_FileCache::get($row['source'], '');
+                       if ($file['mimetype'] == 'httpd/unix-directory') {
+                               $itemType = 'folder';
+                       } else {
+                               $itemType = 'file';
                        }
+                       if ($row['permissions'] == 0) {
+                               $permissions = OCP\Share::PERMISSION_READ;
+                       } else {
+                               $permissions = OCP\Share::PERMISSION_READ | OCP\Share::PERMISSION_UPDATE;
+                               if ($itemType == 'folder') {
+                                       $permissions |= OCP\Share::PERMISSION_CREATE;
+                               }
+                       }
+                       $pos = strrpos($row['uid_shared_with'], '@');
+                       if ($pos !== false && OC_Group::groupExists(substr($row['uid_shared_with'], $pos + 1))) {
+                               $shareType = OCP\Share::SHARE_TYPE_GROUP;
+                               $shareWith = substr($row['uid_shared_with'], 0, $pos);
+                               if (isset($groupShares[$shareWith][$itemSource])) {
+                                       continue;
+                               } else {
+                                       $groupShares[$shareWith][$itemSource] = true;
+                               }
+                       } else if ($row['uid_shared_with'] == 'public') {
+                               $shareType = OCP\Share::SHARE_TYPE_LINK;
+                               $shareWith = null;
+                       } else {
+                               $shareType = OCP\Share::SHARE_TYPE_USER;
+                               $shareWith = $row['uid_shared_with'];
+                       }
+                       OC_User::setUserId($row['uid_owner']);
+                       OCP\Share::shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions);
                }
-               closedir($handle);
        }
+       // NOTE: Let's drop the table after more testing
+//     $query = OCP\DB::prepare('DROP TABLE `*PREFIX*sharing`');
+//     $query->execute();
 }
\ No newline at end of file
index a2268e2de4458c0966915535aa599e828b6d22ae..9fc80f937fab96c3d0109624aca8028d0f3edff6 100644 (file)
@@ -1 +1 @@
-0.3.1
\ No newline at end of file
+0.3.2
\ No newline at end of file
index c8821ee0fe855d8eb3e71d54c598c2b872ab89bf..2149da1d7319d299b5903a74b58d57983afd0cee 100644 (file)
@@ -30,7 +30,7 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
 
        public function isValidSource($itemSource, $uidOwner) {
                $path = OC_FileCache::getPath($itemSource, $uidOwner);
-               if (OC_Filesystem::file_exists($path)) {
+               if ($path) {
                        $this->path = $path;
                        return true;
                }