2012-07-13 13:17:36 +00:00
< ? php
2012-09-09 22:29:47 +00:00
$installedVersion = OCP\Config :: getAppValue ( 'files_sharing' , 'installed_version' );
2012-09-11 01:57:05 +00:00
if ( version_compare ( $installedVersion , '0.3' , '<' )) {
2012-09-21 21:25:57 +00:00
$update_error = false ;
2012-09-09 22:29:47 +00:00
$query = OCP\DB :: prepare ( 'SELECT * FROM `*PREFIX*sharing`' );
$result = $query -> execute ();
$groupShares = array ();
2012-09-25 09:47:45 +00:00
//we need to set up user backends, otherwise creating the shares will fail with "because user does not exist"
OC_User :: useBackend ( new OC_User_Database ());
OC_Group :: useBackend ( new OC_Group_Database ());
OC_App :: loadApps ( array ( 'authentication' ));
2012-10-27 12:25:15 +00:00
$rootView = new \OC\Files\View ( '' );
2012-09-09 22:29:47 +00:00
while ( $row = $result -> fetchRow ()) {
2012-10-27 12:25:15 +00:00
$meta = $rootView -> getFileInfo ( $$row [ 'source' ]);
$itemSource = $meta [ 'fileid' ];
2012-09-09 22:29:47 +00:00
if ( $itemSource != - 1 ) {
2012-10-27 12:25:15 +00:00
$file = $meta ;
2012-09-09 22:29:47 +00:00
if ( $file [ 'mimetype' ] == 'httpd/unix-directory' ) {
$itemType = 'folder' ;
} else {
$itemType = 'file' ;
2012-08-29 06:42:49 +00:00
}
2012-09-09 22:29:47 +00:00
if ( $row [ 'permissions' ] == 0 ) {
2012-11-11 18:58:54 +00:00
$permissions = OCP\PERMISSION_READ | OCP\PERMISSION_SHARE ;
2012-09-09 22:29:47 +00:00
} else {
2012-11-11 18:58:54 +00:00
$permissions = OCP\PERMISSION_READ | OCP\PERMISSION_UPDATE | OCP\PERMISSION_SHARE ;
2012-09-09 22:29:47 +00:00
if ( $itemType == 'folder' ) {
2012-11-11 18:58:54 +00:00
$permissions |= OCP\PERMISSION_CREATE ;
2012-09-09 22:29:47 +00:00
}
}
$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' ]);
2012-09-25 09:47:45 +00:00
//we need to setup the filesystem for the user, otherwise OC_FileSystem::getRoot will fail and break
OC_Util :: setupFS ( $row [ 'uid_owner' ]);
2012-09-21 21:25:57 +00:00
try {
OCP\Share :: shareItem ( $itemType , $itemSource , $shareType , $shareWith , $permissions );
}
catch ( Exception $e ) {
$update_error = true ;
2012-09-26 10:27:34 +00:00
OCP\Util :: writeLog ( 'files_sharing' , 'Upgrade Routine: Skipping sharing "' . $row [ 'source' ] . '" to "' . $shareWith . '" (error is "' . $e -> getMessage () . '")' , OCP\Util :: WARN );
2012-09-21 21:25:57 +00:00
}
2012-09-25 09:47:45 +00:00
OC_Util :: tearDownFS ();
2012-08-29 06:42:49 +00:00
}
2012-07-13 13:17:36 +00:00
}
2012-10-18 16:44:03 +00:00
OC_User :: setUserId ( null );
2012-09-21 21:25:57 +00:00
if ( $update_error ) {
2012-09-26 10:27:34 +00:00
OCP\Util :: writeLog ( 'files_sharing' , 'There were some problems upgrading the sharing of files' , OCP\Util :: ERROR );
2012-09-21 21:25:57 +00:00
}
2012-09-09 22:29:47 +00:00
// NOTE: Let's drop the table after more testing
// $query = OCP\DB::prepare('DROP TABLE `*PREFIX*sharing`');
// $query->execute();
2012-09-21 21:25:57 +00:00
}
2012-10-07 21:34:21 +00:00
if ( version_compare ( $installedVersion , '0.3.3' , '<' )) {
OC_User :: useBackend ( new OC_User_Database ());
OC_App :: loadApps ( array ( 'authentication' ));
$users = OC_User :: getUsers ();
foreach ( $users as $user ) {
2012-10-27 12:25:15 +00:00
// OC_FileCache::delete('Shared', '/'.$user.'/files/');
2012-10-07 21:34:21 +00:00
}
2012-10-26 21:05:02 +00:00
}