From 2982dc73f8875c99a35abf3ddd846ec4cfc484a2 Mon Sep 17 00:00:00 2001
From: Florian Kaiser <florian.kaiser@mpcdf.mpg.de>
Date: Wed, 21 Mar 2018 09:14:01 +0100
Subject: [PATCH] version 2.0.0: ownCloud 10 compatibility now uses oc_accounts
 table, no longer compatible or at least tested with ownCloud < 10.0

---
 README.md        |  2 ++
 appinfo/info.xml |  4 ++--
 db/usagedao.php  | 19 +++++++++----------
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md
index ed106ee..39233a6 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,8 @@ This app is only meant for admins, so best restrict it to the admin group in the
 
 Otherwise normal users will see it in their navigation but get an error when they try to access it.
 
+Requires ownCloud 10 or later.
+
 # Disclaimer
 This app basically does SUMs over the oc_filecache table.
 
diff --git a/appinfo/info.xml b/appinfo/info.xml
index c732a41..5f4342c 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -5,10 +5,10 @@
     <description>Displays used space for all users</description>
     <licence>AGPL</licence>
     <author>Florian Kaiser</author>
-    <version>0.0.1</version>
+    <version>2.0.0</version>
     <namespace>StorageUsage</namespace>
     <category>other</category>
     <dependencies>
-        <owncloud min-version="8.1" />
+        <owncloud min-version="10.0" max-version="11.0" />
     </dependencies>
 </info>
diff --git a/db/usagedao.php b/db/usagedao.php
index a9e00b8..e4fe586 100644
--- a/db/usagedao.php
+++ b/db/usagedao.php
@@ -13,16 +13,15 @@ class UsageDAO {
 
     public function getUsage() {
 	$dbPlatform = $this->db->getDatabasePlatform();
-	$join_storage_expr = $dbPlatform->getConcatExpression('"home::"', '*PREFIX*preferences.userid');
-
-        $sql = 'SELECT *PREFIX*preferences.userid AS username, *PREFIX*preferences.configvalue as quotastring, *PREFIX*filecache.size as bytes, sub.num as objects
-		FROM *PREFIX*preferences
-		LEFT JOIN *PREFIX*storages ON (*PREFIX*storages.id=' . $join_storage_expr . ')
-		LEFT JOIN *PREFIX*filecache ON (*PREFIX*storages.numeric_id=*PREFIX*filecache.storage)
-		LEFT JOIN (SELECT storage, COUNT(*) as num FROM *PREFIX*filecache GROUP BY storage) sub ON (sub.storage=*PREFIX*storages.numeric_id)
-		WHERE *PREFIX*preferences.appid="files" and *PREFIX*preferences.configkey="quota"
-		AND *PREFIX*filecache.path="files"
-		ORDER BY *PREFIX*filecache.size DESC;';
+	$join_storage_expr = $dbPlatform->getConcatExpression('"home::"', '*PREFIX*accounts.user_id');
+
+        $sql = 'SELECT *PREFIX*accounts.user_id AS username, *PREFIX*accounts.quota as quotastring, *PREFIX*filecache.size as bytes, sub.num as objects
+                FROM *PREFIX*accounts
+                LEFT JOIN *PREFIX*storages ON (*PREFIX*storages.id=' . $join_storage_expr . ')
+                LEFT JOIN *PREFIX*filecache ON (*PREFIX*storages.numeric_id=*PREFIX*filecache.storage)
+                LEFT JOIN (SELECT storage, COUNT(*) as num FROM *PREFIX*filecache GROUP BY storage) sub ON (sub.storage=*PREFIX*storages.numeric_id)
+                WHERE *PREFIX*filecache.path="files"
+                ORDER BY *PREFIX*filecache.size DESC;';
 
         $stmt = $this->db->prepare($sql);
         $stmt->execute();
-- 
GitLab