Beispiel #1
0
 /**
  * @medium
  */
 function testRemoveBrokenFileShares()
 {
     $this->prepareFileCache();
     // check if there are just 4 shares (see setUp - precondition: empty table)
     $countAllShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share`');
     $result = $countAllShares->execute()->fetchOne();
     $this->assertEquals(4, $result);
     // check if there are just 3 file shares (see setUp - precondition: empty table)
     $countFileShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\')');
     $result = $countFileShares->execute()->fetchOne();
     $this->assertEquals(3, $result);
     // check if there are just 2 items (see setUp - precondition: empty table)
     $countItems = \OC_DB::prepare('SELECT COUNT(`fileid`) FROM `*PREFIX*filecache`');
     $result = $countItems->execute()->fetchOne();
     $this->assertEquals(2, $result);
     // execute actual code which should be tested
     \OC\Files\Cache\Shared_Updater::fixBrokenSharesOnAppUpdate();
     // check if there are just 2 shares (one gets killed by the code as there is no filecache entry for this)
     $result = $countFileShares->execute()->fetchOne();
     $this->assertEquals(2, $result);
     // check if the share of file '200' is removed as there is no entry for this in filecache table
     $countFileShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share` WHERE `file_source` = 200');
     $result = $countFileShares->execute()->fetchOne();
     $this->assertEquals(0, $result);
     // check if there are just 2 items
     $countItems = \OC_DB::prepare('SELECT COUNT(`fileid`) FROM `*PREFIX*filecache`');
     $result = $countItems->execute()->fetchOne();
     $this->assertEquals(2, $result);
     // the calendar share survived
     $countOtherShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share` WHERE `item_source` = \'999\'');
     $result = $countOtherShares->execute()->fetchOne();
     $this->assertEquals(1, $result);
 }
Beispiel #2
0
<?php

$installedVersion = OCP\Config::getAppValue('files_sharing', 'installed_version');
if (version_compare($installedVersion, '0.5', '<')) {
    updateFilePermissions();
}
if (version_compare($installedVersion, '0.4', '<')) {
    removeSharedFolder();
}
// clean up oc_share table from files which are no longer exists
if (version_compare($installedVersion, '0.3.5.6', '<')) {
    \OC\Files\Cache\Shared_Updater::fixBrokenSharesOnAppUpdate();
}
/**
 * it is no longer possible to share single files with delete permissions. User
 * should only be able to unshare single files but never to delete them.
 */
function updateFilePermissions($chunkSize = 99)
{
    $query = OCP\DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `item_type` = ?');
    $result = $query->execute(array('file'));
    $updatedRows = array();
    while ($row = $result->fetchRow()) {
        if ($row['permissions'] & \OCP\PERMISSION_DELETE) {
            $updatedRows[$row['id']] = (int) $row['permissions'] & ~\OCP\PERMISSION_DELETE;
        }
    }
    $connection = \OC_DB::getConnection();
    $chunkedPermissionList = array_chunk($updatedRows, $chunkSize, true);
    foreach ($chunkedPermissionList as $subList) {
        $statement = "UPDATE `*PREFIX*share` SET `permissions` = CASE `id` ";