From 8509994c2a7f3cdddbb48b8a1f6a952b437a315c Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Sat, 23 Nov 2013 19:47:45 -0500 Subject: [PATCH 1/7] fix update to remove shares where file doesn't exist on postgres Without patch, breaks with: Failed to upgrade "files_sharing". Exception="SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "5,179"" See: https://github.com/owncloud/core/issues/5758 --- apps/files_sharing/appinfo/update.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index 0d827da28eab..721b53ee3d45 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -71,18 +71,7 @@ // clean up oc_share table from files which are no longer exists if (version_compare($installedVersion, '0.3.5', '<')) { - - // get all shares where the original file no longer exists - $findShares = \OC_DB::prepare('SELECT `file_source` 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)) { - $delArray = array(); - foreach ($sharesFound as $share) { - $delArray[] = $share['file_source']; - } - $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (?)'); - $result = $removeShares->execute(array(implode(',', $delArray))); - } + // delete all shares where the original file no longer exists + $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (SELECT `file_source` 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\'))'); + $result = $removeShares->execute(array(implode(',', $delArray))); } From dec10be8c8207fecd3b79055d8329d6b8d852762 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Sat, 23 Nov 2013 20:06:57 -0500 Subject: [PATCH 2/7] removing unnecessary cruft - no parameter is set, none to pass. https://github.com/owncloud/core/issues/5758 --- apps/files_sharing/appinfo/update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index 721b53ee3d45..53138d7f4ba3 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -73,5 +73,5 @@ if (version_compare($installedVersion, '0.3.5', '<')) { // delete all shares where the original file no longer exists $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (SELECT `file_source` 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\'))'); - $result = $removeShares->execute(array(implode(',', $delArray))); + $result = $removeShares->execute(); } From 06c11f2603c1d1c2e0afeb0a5fb42ff1ae0b32f7 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Fri, 29 Nov 2013 12:35:22 -0500 Subject: [PATCH 3/7] removing subquery, making more readable See: https://github.com/owncloud/core/pull/6016#issuecomment-29510979 --- apps/files_sharing/appinfo/update.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index 53138d7f4ba3..742802a59902 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -72,6 +72,16 @@ // clean up oc_share table from files which are no longer exists if (version_compare($installedVersion, '0.3.5', '<')) { // delete all shares where the original file no longer exists - $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (SELECT `file_source` 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\'))'); - $result = $removeShares->execute(); + $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($share['id']); + } + } } From 40a348ace9ee6d916e172720a8a7a3e07388b8fb Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Thu, 19 Dec 2013 09:42:50 -0500 Subject: [PATCH 4/7] parameters to sql calls should be arrays https://github.com/owncloud/core/pull/6016 --- apps/files_sharing/appinfo/update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index 742802a59902..848fbec73286 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -81,7 +81,7 @@ if (is_array($sharesFound) && !empty($sharesFound)) { $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` = ? )'); foreach ($sharesFound as $share) { - $result = $removeShares->execute($share['id']); + $result = $removeShares->execute(array($share['id'])); } } } From f4025d29b253051fc9fbd96998ca072cac5c6c8c Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Thu, 19 Dec 2013 09:44:14 -0500 Subject: [PATCH 5/7] boosting version to ensure fix gets executed --- apps/files_sharing/appinfo/update.php | 2 +- apps/files_sharing/appinfo/version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index 848fbec73286..c930a16bd9c5 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -70,7 +70,7 @@ } // clean up oc_share table from files which are no longer exists -if (version_compare($installedVersion, '0.3.5', '<')) { +if (version_compare($installedVersion, '0.3.5.6', '<')) { // 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` ' . diff --git a/apps/files_sharing/appinfo/version b/apps/files_sharing/appinfo/version index 09e9157034c2..8f91d33378ed 100644 --- a/apps/files_sharing/appinfo/version +++ b/apps/files_sharing/appinfo/version @@ -1 +1 @@ -0.3.5 \ No newline at end of file +0.3.5.6 From a9d04f342760780f3c3cef90486aca8fb48560eb Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Thu, 19 Dec 2013 09:45:48 -0500 Subject: [PATCH 6/7] properly escaping the sql select statement --- apps/files_sharing/appinfo/update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index c930a16bd9c5..ee556e0cfc02 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -72,7 +72,7 @@ // clean up oc_share table from files which are no longer exists if (version_compare($installedVersion, '0.3.5.6', '<')) { // delete all shares where the original file no longer exists - $findShares = \OC_DB::prepare('SELECT `*PREFIX*share.id` ' . + $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(); From a7898b77c98cae0861b3d773a71cbd827dca6e0c Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Thu, 19 Dec 2013 09:46:53 -0500 Subject: [PATCH 7/7] removing extraneous closing paren. --- apps/files_sharing/appinfo/update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php index ee556e0cfc02..85ef24902253 100644 --- a/apps/files_sharing/appinfo/update.php +++ b/apps/files_sharing/appinfo/update.php @@ -79,7 +79,7 @@ // delete those shares from the oc_share table if (is_array($sharesFound) && !empty($sharesFound)) { - $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` = ? )'); + $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` = ? '); foreach ($sharesFound as $share) { $result = $removeShares->execute(array($share['id'])); }