aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/updater.php
diff options
context:
space:
mode:
authorMorris Jobke <morris.jobke@gmail.com>2014-02-20 15:21:53 +0100
committerMorris Jobke <morris.jobke@gmail.com>2014-03-13 13:09:32 +0100
commitec54bc77093265b2b9f03eecc1507cb266683624 (patch)
treed8492d1bf4edba95aa48bd859e788c4313cb4ee3 /apps/files_sharing/lib/updater.php
parentd58fda7ff3e8f67e7699123eb4cca8248484c9ea (diff)
downloadnextcloud-server-ec54bc77093265b2b9f03eecc1507cb266683624.tar.gz
nextcloud-server-ec54bc77093265b2b9f03eecc1507cb266683624.zip
Refactor update script to class and add unit test
Diffstat (limited to 'apps/files_sharing/lib/updater.php')
-rw-r--r--apps/files_sharing/lib/updater.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/updater.php b/apps/files_sharing/lib/updater.php
index 23ebc9fb811..950575ec26b 100644
--- a/apps/files_sharing/lib/updater.php
+++ b/apps/files_sharing/lib/updater.php
@@ -135,4 +135,26 @@ class Shared_Updater {
}
}
+ /**
+ * clean up oc_share table from files which are no longer exists
+ *
+ * This fixes issues from updates from files_sharing < 0.3.5.6 (ownCloud 4.5)
+ * It will just be called during the update of the app
+ */
+ static public function fixBrokenSharesOnAppUpdate() {
+ // delete all shares where the original file no longer exists
+ $findShares = \OC_DB::prepare('SELECT `*PREFIX*share`.`id` ' .
+ 'FROM `*PREFIX*share` LEFT JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` ' .
+ 'WHERE `*PREFIX*filecache`.`fileid` IS NULL AND `*PREFIX*share`.`item_type` IN (\'file\', \'folder\')');
+ $sharesFound = $findShares->execute(array())->fetchAll();
+
+ // delete those shares from the oc_share table
+ if (is_array($sharesFound) && !empty($sharesFound)) {
+ $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` = ? ');
+ foreach ($sharesFound as $share) {
+ $result = $removeShares->execute(array($share['id']));
+ }
+ }
+ }
+
}