From 42413373b5b4c6a622b33d20032989f5114ad189 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 16 Feb 2015 15:15:54 +0000 Subject: [PATCH] fix migrate_db2fs to only fetch 5 files per query, as we dont want to require enough memory to hold all file in memory --- api/src/Vfs/Sqlfs/StreamWrapper.php | 2 +- api/src/Vfs/Sqlfs/Utils.php | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/api/src/Vfs/Sqlfs/StreamWrapper.php b/api/src/Vfs/Sqlfs/StreamWrapper.php index f9976d73d6..739f4c6f34 100644 --- a/api/src/Vfs/Sqlfs/StreamWrapper.php +++ b/api/src/Vfs/Sqlfs/StreamWrapper.php @@ -678,7 +678,7 @@ class StreamWrapper implements Vfs\StreamWrapperIface /** * due to problems with recursive directory creation, we have our own here */ - private static function mkdir_recursive($pathname, $mode, $depth=0) + protected static function mkdir_recursive($pathname, $mode, $depth=0) { $maxdepth=10; $depth2propagate = (int)$depth + 1; diff --git a/api/src/Vfs/Sqlfs/Utils.php b/api/src/Vfs/Sqlfs/Utils.php index b7e842f6aa..d3f1eb48a3 100644 --- a/api/src/Vfs/Sqlfs/Utils.php +++ b/api/src/Vfs/Sqlfs/Utils.php @@ -37,18 +37,21 @@ class Utils extends StreamWrapper self::_pdo(); } $query = 'SELECT fs_id,fs_name,fs_size,fs_content'. - ' FROM '.self::TABLE.' WHERE fs_content IS NOT NULL'; + $query = 'SELECT fs_id,fs_name,fs_size,fs_content'. + ' FROM '.self::TABLE.' WHERE fs_content IS NOT NULL'. + ' ORDER BY fs_id LIMIT 5 OFFSET :offset'; $fs_id = $fs_name = $fs_size = $fs_content = null; + $n = 0; $stmt = self::$pdo->prepare($query); $stmt->bindColumn(1,$fs_id); $stmt->bindColumn(2,$fs_name); $stmt->bindColumn(3,$fs_size); - $stmt->bindColumn(4,$fs_content,\PDO::PARAM_LOB); + $stmt->bindColumn(4,$fs_content,PDO::PARAM_LOB); + $stmt->bindValue(':offset', $n, PDO::PARAM_INT); - if ($stmt->execute()) + while ($stmt->execute()) { - $n = 0; foreach($stmt as $row) { // hack to work around a current php bug (http://bugs.php.net/bug.php?id=40913) @@ -86,16 +89,17 @@ class Utils extends StreamWrapper fclose($content); unset($content); ++$n; - unset($row); // not used, as we access bound variables } - unset($stmt); + if (!$n) break; // just in case nothing is found, statement will execute just fine + } + unset($row); // not used, as we access bound variables + unset($stmt); - if ($n) // delete all content in DB, if there was some AND no error (exception thrown!) - { - $query = 'UPDATE '.self::TABLE.' SET fs_content=NULL WHERE fs_content IS NOT NULL'; - $stmt = self::$pdo->prepare($query); - $stmt->execute(); - } + if ($n) // delete all content in DB, if there was some AND no error (exception thrown!) + { + $query = 'UPDATE '.self::TABLE.' SET fs_content=NULL WHERE fs_content IS NOT NULL'; + $stmt = self::$pdo->prepare($query); + $stmt->execute(); } return $n; }