diff options
author | raghunayyar <me@iraghu.com> | 2014-01-16 14:42:37 +0530 |
---|---|---|
committer | raghunayyar <me@iraghu.com> | 2014-01-16 14:42:37 +0530 |
commit | 775e08e0ee4125cc7b2a594771437686f6a21b56 (patch) | |
tree | 362f84449171898335dd3e8511b65c97c150e9e1 /apps/files_versions | |
parent | 4687d2dd0bde3f689eb57c90d0c4341cd00991bd (diff) | |
parent | bd643c47f32ba6d7b3ba6a18ed1591aab0b81be8 (diff) | |
download | nextcloud-server-775e08e0ee4125cc7b2a594771437686f6a21b56.tar.gz nextcloud-server-775e08e0ee4125cc7b2a594771437686f6a21b56.zip |
Merge branch 'master' into core-em-to-px
Conflicts:
apps/files_sharing/css/public.css
apps/user_ldap/css/settings.css
core/css/multiselect.css
core/css/share.css
Diffstat (limited to 'apps/files_versions')
-rw-r--r-- | apps/files_versions/ajax/preview.php | 16 | ||||
-rw-r--r-- | apps/files_versions/appinfo/app.php | 1 | ||||
-rw-r--r-- | apps/files_versions/download.php | 7 | ||||
-rw-r--r-- | apps/files_versions/js/versions.js | 25 | ||||
-rw-r--r-- | apps/files_versions/l10n/de.php | 4 | ||||
-rw-r--r-- | apps/files_versions/l10n/de_DE.php | 2 | ||||
-rw-r--r-- | apps/files_versions/l10n/el.php | 2 | ||||
-rw-r--r-- | apps/files_versions/l10n/eo.php | 3 | ||||
-rw-r--r-- | apps/files_versions/l10n/es_MX.php | 10 | ||||
-rw-r--r-- | apps/files_versions/l10n/id.php | 3 | ||||
-rw-r--r-- | apps/files_versions/l10n/ko.php | 6 | ||||
-rw-r--r-- | apps/files_versions/l10n/mk.php | 7 | ||||
-rw-r--r-- | apps/files_versions/l10n/ms_MY.php | 10 | ||||
-rw-r--r-- | apps/files_versions/l10n/sl.php | 3 | ||||
-rw-r--r-- | apps/files_versions/l10n/tr.php | 3 | ||||
-rw-r--r-- | apps/files_versions/l10n/uk.php | 3 | ||||
-rw-r--r-- | apps/files_versions/lib/hooks.php | 15 | ||||
-rw-r--r-- | apps/files_versions/lib/versions.php | 222 |
18 files changed, 204 insertions, 138 deletions
diff --git a/apps/files_versions/ajax/preview.php b/apps/files_versions/ajax/preview.php index c24134df534..31525028ef3 100644 --- a/apps/files_versions/ajax/preview.php +++ b/apps/files_versions/ajax/preview.php @@ -12,26 +12,34 @@ if(!\OC_App::isEnabled('files_versions')){ } $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; +$user = array_key_exists('user', $_GET) ? $_GET['user'] : ''; $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : 44; $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : 44; $version = array_key_exists('version', $_GET) ? $_GET['version'] : ''; $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; +if($user === '') { + \OC_Response::setStatus(400); //400 Bad Request + \OC_Log::write('versions-preview', 'No user parameter was passed', \OC_Log::DEBUG); + exit; +} + if($file === '' && $version === '') { \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); + \OC_Log::write('versions-preview', 'No file parameter was passed', \OC_Log::DEBUG); exit; } if($maxX === 0 || $maxY === 0) { \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); + \OC_Log::write('versions-preview', 'x and/or y set to 0', \OC_Log::DEBUG); exit; } try{ - $preview = new \OC\Preview(\OC_User::getUser(), 'files_versions'); - $preview->setFile($file.'.v'.$version); + $preview = new \OC\Preview($user, 'files_versions', $file.'.v'.$version); + $mimetype = \OC_Helper::getFileNameMimeType($file); + $preview->setMimetype($mimetype); $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); diff --git a/apps/files_versions/appinfo/app.php b/apps/files_versions/appinfo/app.php index 5b1e464ba6c..8f2071dd7b6 100644 --- a/apps/files_versions/appinfo/app.php +++ b/apps/files_versions/appinfo/app.php @@ -12,6 +12,7 @@ OCP\Util::addStyle('files_versions', 'versions'); OCP\Util::connectHook('OC_Filesystem', 'write', "OCA\Files_Versions\Hooks", "write_hook"); // Listen to delete and rename signals OCP\Util::connectHook('OC_Filesystem', 'post_delete', "OCA\Files_Versions\Hooks", "remove_hook"); +OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Files_Versions\Hooks", "pre_remove_hook"); OCP\Util::connectHook('OC_Filesystem', 'rename', "OCA\Files_Versions\Hooks", "rename_hook"); //Listen to delete user signal OCP\Util::connectHook('OC_User', 'pre_deleteUser', "OCA\Files_Versions\Hooks", "deleteUser_hook"); diff --git a/apps/files_versions/download.php b/apps/files_versions/download.php index 040a662e61b..2fe56d2e638 100644 --- a/apps/files_versions/download.php +++ b/apps/files_versions/download.php @@ -36,12 +36,7 @@ $view = new OC\Files\View('/'); $ftype = $view->getMimeType('/'.$uid.'/files/'.$filename); header('Content-Type:'.$ftype); -if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { - header( 'Content-Disposition: attachment; filename="' . rawurlencode( basename($filename) ) . '"' ); -} else { - header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode( basename($filename) ) - . '; filename="' . rawurlencode( basename($filename) ) . '"' ); -} +OCP\Response::setContentDispositionHeader(basename($filename), 'attachment'); OCP\Response::disableCaching(); header('Content-Length: '.$view->filesize($versionName)); diff --git a/apps/files_versions/js/versions.js b/apps/files_versions/js/versions.js index 3f56a3eb698..4adf14745de 100644 --- a/apps/files_versions/js/versions.js +++ b/apps/files_versions/js/versions.js @@ -1,5 +1,12 @@ $(document).ready(function(){ + if ($('#isPublic').val()){ + // no versions actions in public mode + // beware of https://github.com/owncloud/core/issues/4545 + // as enabling this might hang Chrome + return; + } + if (typeof FileActions !== 'undefined') { // Add versions button to 'files/index.php' FileActions.register( @@ -14,7 +21,7 @@ $(document).ready(function(){ // Action to perform when clicked if (scanFiles.scanning){return;}//workaround to prevent additional http request block scanning feedback - var file = $('#dir').val()+'/'+filename; + var file = $('#dir').val().replace(/(?!<=\/)$|\/$/, '/' + filename); var createDropDown = true; // Check if drop down is already visible for a different file if (($('#dropdown').length > 0) ) { @@ -70,6 +77,7 @@ function goToVersionPage(url){ function createVersionsDropdown(filename, files) { var start = 0; + var fileEl; var html = '<div id="dropdown" class="drop drop-versions" data-file="'+escapeHTML(files)+'">'; html += '<div id="private">'; @@ -79,8 +87,9 @@ function createVersionsDropdown(filename, files) { html += '<input type="button" value="'+ t('files_versions', 'More versions...') + '" name="show-more-versions" id="show-more-versions" style="display: none;" />'; if (filename) { - $('tr').filterAttr('data-file',filename).addClass('mouseOver'); - $(html).appendTo($('tr').filterAttr('data-file',filename).find('td.filename')); + fileEl = FileList.findFileEl(filename); + fileEl.addClass('mouseOver'); + $(html).appendTo(fileEl.find('td.filename')); } else { $(html).appendTo($('thead .share')); } @@ -131,7 +140,7 @@ function createVersionsDropdown(filename, files) { var preview = '<img class="preview" src="'+revision.preview+'"/>'; - var download ='<a href="' + path + "?file=" + files + '&revision=' + revision.version + '">'; + var download ='<a href="' + path + "?file=" + encodeURIComponent(files) + '&revision=' + revision.version + '">'; download+='<img'; download+=' src="' + OC.imagePath('core', 'actions/download') + '"'; download+=' name="downloadVersion" />'; @@ -139,8 +148,7 @@ function createVersionsDropdown(filename, files) { download+='</a>'; var revert='<span class="revertVersion"'; - revert+=' id="' + revision.version + '"'; - revert+=' value="' + files + '">'; + revert+=' id="' + revision.version + '">'; revert+='<img'; revert+=' src="' + OC.imagePath('core', 'actions/history') + '"'; revert+=' name="revertVersion"'; @@ -149,14 +157,13 @@ function createVersionsDropdown(filename, files) { var version=$('<li/>'); version.attr('value', revision.version); version.html(preview + download + revert); + // add file here for proper name escaping + version.find('span.revertVersion').attr('value', files); version.appendTo('#found_versions'); } - $('tr').filterAttr('data-file',filename).addClass('mouseOver'); $('#dropdown').show('blind'); - - } $(this).click( diff --git a/apps/files_versions/l10n/de.php b/apps/files_versions/l10n/de.php index c8b45eee500..2b5bf3e9347 100644 --- a/apps/files_versions/l10n/de.php +++ b/apps/files_versions/l10n/de.php @@ -2,8 +2,8 @@ $TRANSLATIONS = array( "Could not revert: %s" => "Konnte %s nicht zurücksetzen", "Versions" => "Versionen", -"Failed to revert {file} to revision {timestamp}." => "Konnte {file} der Revision {timestamp} nicht rückgänging machen.", -"More versions..." => "Mehrere Versionen...", +"Failed to revert {file} to revision {timestamp}." => "Konnte {file} der Revision {timestamp} nicht rückgängig machen.", +"More versions..." => "Weitere Versionen...", "No other versions available" => "Keine anderen Versionen verfügbar", "Restore" => "Wiederherstellen" ); diff --git a/apps/files_versions/l10n/de_DE.php b/apps/files_versions/l10n/de_DE.php index c8b45eee500..781774dcdd9 100644 --- a/apps/files_versions/l10n/de_DE.php +++ b/apps/files_versions/l10n/de_DE.php @@ -2,7 +2,7 @@ $TRANSLATIONS = array( "Could not revert: %s" => "Konnte %s nicht zurücksetzen", "Versions" => "Versionen", -"Failed to revert {file} to revision {timestamp}." => "Konnte {file} der Revision {timestamp} nicht rückgänging machen.", +"Failed to revert {file} to revision {timestamp}." => "Konnte {file} der Revision {timestamp} nicht rückgängig machen.", "More versions..." => "Mehrere Versionen...", "No other versions available" => "Keine anderen Versionen verfügbar", "Restore" => "Wiederherstellen" diff --git a/apps/files_versions/l10n/el.php b/apps/files_versions/l10n/el.php index af608e7c042..5337f3b5a48 100644 --- a/apps/files_versions/l10n/el.php +++ b/apps/files_versions/l10n/el.php @@ -1,6 +1,6 @@ <?php $TRANSLATIONS = array( -"Could not revert: %s" => "Αδυναμία επαναφοράς του: %s", +"Could not revert: %s" => "Αδυναμία επαναφοράς: %s", "Versions" => "Εκδόσεις", "Failed to revert {file} to revision {timestamp}." => "Αποτυχία επαναφοράς του {file} στην αναθεώρηση {timestamp}.", "More versions..." => "Περισσότερες εκδόσεις...", diff --git a/apps/files_versions/l10n/eo.php b/apps/files_versions/l10n/eo.php index c023d5fbc37..cfd8b1845cb 100644 --- a/apps/files_versions/l10n/eo.php +++ b/apps/files_versions/l10n/eo.php @@ -2,6 +2,9 @@ $TRANSLATIONS = array( "Could not revert: %s" => "Ne eblas malfari: %s", "Versions" => "Versioj", +"Failed to revert {file} to revision {timestamp}." => "Malsukcesis returnigo de {file} al la revizio {timestamp}.", +"More versions..." => "Pli da versioj...", +"No other versions available" => "Ne disponeblas aliaj versioj", "Restore" => "Restaŭri" ); $PLURAL_FORMS = "nplurals=2; plural=(n != 1);"; diff --git a/apps/files_versions/l10n/es_MX.php b/apps/files_versions/l10n/es_MX.php new file mode 100644 index 00000000000..b7acc376978 --- /dev/null +++ b/apps/files_versions/l10n/es_MX.php @@ -0,0 +1,10 @@ +<?php +$TRANSLATIONS = array( +"Could not revert: %s" => "No se puede revertir: %s", +"Versions" => "Revisiones", +"Failed to revert {file} to revision {timestamp}." => "No se ha podido revertir {archivo} a revisión {timestamp}.", +"More versions..." => "Más versiones...", +"No other versions available" => "No hay otras versiones disponibles", +"Restore" => "Recuperar" +); +$PLURAL_FORMS = "nplurals=2; plural=(n != 1);"; diff --git a/apps/files_versions/l10n/id.php b/apps/files_versions/l10n/id.php index ee7061805ba..14920cc52fd 100644 --- a/apps/files_versions/l10n/id.php +++ b/apps/files_versions/l10n/id.php @@ -2,6 +2,9 @@ $TRANSLATIONS = array( "Could not revert: %s" => "Tidak dapat mengembalikan: %s", "Versions" => "Versi", +"Failed to revert {file} to revision {timestamp}." => "Gagal mengembalikan {file} ke revisi {timestamp}.", +"More versions..." => "Versi lebih...", +"No other versions available" => "Tidak ada versi lain yang tersedia", "Restore" => "Pulihkan" ); $PLURAL_FORMS = "nplurals=1; plural=0;"; diff --git a/apps/files_versions/l10n/ko.php b/apps/files_versions/l10n/ko.php index ba951c4107a..bd56c0489bf 100644 --- a/apps/files_versions/l10n/ko.php +++ b/apps/files_versions/l10n/ko.php @@ -2,9 +2,9 @@ $TRANSLATIONS = array( "Could not revert: %s" => "되돌릴 수 없습니다: %s", "Versions" => "버전", -"Failed to revert {file} to revision {timestamp}." => "{timestamp} 판의 {file}로 돌리는데 실패했습니다.", -"More versions..." => "더 많은 버전들...", -"No other versions available" => "다른 버전을 사용할수 없습니다", +"Failed to revert {file} to revision {timestamp}." => "{file}을(를) 리비전 {timestamp}으(로) 되돌리는 데 실패하였습니다.", +"More versions..." => "더 많은 버전...", +"No other versions available" => "다른 버전을 사용할 수 없습니다", "Restore" => "복원" ); $PLURAL_FORMS = "nplurals=1; plural=0;"; diff --git a/apps/files_versions/l10n/mk.php b/apps/files_versions/l10n/mk.php index 01a98808cff..d5c883b894f 100644 --- a/apps/files_versions/l10n/mk.php +++ b/apps/files_versions/l10n/mk.php @@ -1,5 +1,10 @@ <?php $TRANSLATIONS = array( -"Versions" => "Версии" +"Could not revert: %s" => "Не можев да го вратам: %s", +"Versions" => "Версии", +"Failed to revert {file} to revision {timestamp}." => "Не успеав да го вратам {file} на ревизијата {timestamp}.", +"More versions..." => "Повеќе верзии...", +"No other versions available" => "Не постојат други верзии", +"Restore" => "Врати" ); $PLURAL_FORMS = "nplurals=2; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : 1;"; diff --git a/apps/files_versions/l10n/ms_MY.php b/apps/files_versions/l10n/ms_MY.php new file mode 100644 index 00000000000..513dff49b24 --- /dev/null +++ b/apps/files_versions/l10n/ms_MY.php @@ -0,0 +1,10 @@ +<?php +$TRANSLATIONS = array( +"Could not revert: %s" => "Tidak dapat kembalikan: %s", +"Versions" => "Versi", +"Failed to revert {file} to revision {timestamp}." => "Gagal kembalikan {file} ke semakan {timestamp}.", +"More versions..." => "Lagi versi...", +"No other versions available" => "Tiada lagi versi lain", +"Restore" => "Pulihkan" +); +$PLURAL_FORMS = "nplurals=1; plural=0;"; diff --git a/apps/files_versions/l10n/sl.php b/apps/files_versions/l10n/sl.php index 809ab34c262..08b2f03e4c1 100644 --- a/apps/files_versions/l10n/sl.php +++ b/apps/files_versions/l10n/sl.php @@ -2,6 +2,9 @@ $TRANSLATIONS = array( "Could not revert: %s" => "Ni mogoče povrniti: %s", "Versions" => "Različice", +"Failed to revert {file} to revision {timestamp}." => "Povrnitev datoteke {file} na objavo {timestamp} je spodletelo.", +"More versions..." => "Več različic", +"No other versions available" => "Ni drugih različic", "Restore" => "Obnovi" ); $PLURAL_FORMS = "nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);"; diff --git a/apps/files_versions/l10n/tr.php b/apps/files_versions/l10n/tr.php index f2bc1e6c0aa..998c61e9270 100644 --- a/apps/files_versions/l10n/tr.php +++ b/apps/files_versions/l10n/tr.php @@ -2,6 +2,9 @@ $TRANSLATIONS = array( "Could not revert: %s" => "Geri alınamıyor: %s", "Versions" => "Sürümler", +"Failed to revert {file} to revision {timestamp}." => "{file} dosyası {timestamp} gözden geçirmesine geri alınamadı.", +"More versions..." => "Daha fazla sürüm...", +"No other versions available" => "Başka sürüm mevcut değil", "Restore" => "Geri yükle" ); $PLURAL_FORMS = "nplurals=2; plural=(n > 1);"; diff --git a/apps/files_versions/l10n/uk.php b/apps/files_versions/l10n/uk.php index d75160f2864..2f87a9e703b 100644 --- a/apps/files_versions/l10n/uk.php +++ b/apps/files_versions/l10n/uk.php @@ -2,6 +2,9 @@ $TRANSLATIONS = array( "Could not revert: %s" => "Не вдалося відновити: %s", "Versions" => "Версії", +"Failed to revert {file} to revision {timestamp}." => "Не вдалося повернути {file} до ревізії {timestamp}.", +"More versions..." => "Більше версій ...", +"No other versions available" => "Інші версії недоступні", "Restore" => "Відновити" ); $PLURAL_FORMS = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);"; diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index 81ee3c8b3c6..5d3882cc3e3 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -46,6 +46,17 @@ class Hooks { } /** + * @brief mark file as "deleted" so that we can clean up the versions if the file is gone + * @param array $params + */ + public static function pre_remove_hook($params) { + $path = $params[\OC\Files\Filesystem::signal_param_path]; + if($path<>'') { + Storage::markDeletedFile($path); + } + } + + /** * @brief rename/move versions of renamed/moved files * @param array with oldpath and newpath * @@ -53,7 +64,7 @@ class Hooks { * of the stored versions along the actual file */ public static function rename_hook($params) { - + if (\OCP\App::isEnabled('files_versions')) { $oldpath = $params['oldpath']; $newpath = $params['newpath']; @@ -71,7 +82,7 @@ class Hooks { * to remove the used space for versions stored in the database */ public static function deleteUser_hook($params) { - + if (\OCP\App::isEnabled('files_versions')) { $uid = $params['uid']; Storage::deleteUser($uid); diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index fc8d0365c71..7e6cc818efb 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -19,6 +19,10 @@ class Storage { const DEFAULTENABLED=true; const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota + const VERSIONS_ROOT = 'files_versions/'; + + // files for which we can remove the versions after the delete operation was successful + private static $deletedFiles = array(); private static $max_versions_per_interval = array( //first 10sec, one version every 2sec @@ -94,7 +98,6 @@ class Storage { $files_view = new \OC\Files\View('/'.$uid .'/files'); $users_view = new \OC\Files\View('/'.$uid); - $versions_view = new \OC\Files\View('/'.$uid.'/files_versions'); // check if filename is a directory if($files_view->is_dir($filename)) { @@ -128,7 +131,10 @@ class Storage { \OC_FileProxy::$enabled = false; // store a new version of a file - $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename)); + $mtime = $users_view->filemtime('files'.$filename); + $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'. $mtime); + // call getFileInfo to enforce a file cache entry for the new version + $users_view->getFileInfo('files_versions'.$filename.'.v'.$mtime); // reset proxy state \OC_FileProxy::$enabled = $proxyStatus; @@ -141,24 +147,45 @@ class Storage { /** + * @brief mark file as deleted so that we can remove the versions if the file is gone + * @param string $path + */ + public static function markDeletedFile($path) { + list($uid, $filename) = self::getUidAndFilename($path); + self::$deletedFiles[$path] = array( + 'uid' => $uid, + 'filename' => $filename); + } + + /** * Delete versions of a file */ - public static function delete($filename) { - list($uid, $filename) = self::getUidAndFilename($filename); - $versions_fileview = new \OC\Files\View('/'.$uid .'/files_versions'); + public static function delete($path) { - $abs_path = $versions_fileview->getLocalFile($filename.'.v'); - if( ($versions = self::getVersions($uid, $filename)) ) { - $versionsSize = self::getVersionsSize($uid); - if ( $versionsSize === false || $versionsSize < 0 ) { - $versionsSize = self::calculateSize($uid); - } - foreach ($versions as $v) { - unlink($abs_path . $v['version']); - $versionsSize -= $v['size']; + $deletedFile = self::$deletedFiles[$path]; + $uid = $deletedFile['uid']; + $filename = $deletedFile['filename']; + + if (!\OC\Files\Filesystem::file_exists($path)) { + + $versions_fileview = new \OC\Files\View('/' . $uid . '/files_versions'); + + $abs_path = $versions_fileview->getLocalFile($filename . '.v'); + $versions = self::getVersions($uid, $filename); + if (!empty($versions)) { + $versionsSize = self::getVersionsSize($uid); + if ($versionsSize === false || $versionsSize < 0) { + $versionsSize = self::calculateSize($uid); + } + foreach ($versions as $v) { + unlink($abs_path . $v['version']); + \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $abs_path . $v['version'])); + $versionsSize -= $v['size']; + } + self::setVersionsSize($uid, $versionsSize); } - self::setVersionsSize($uid, $versionsSize); } + unset(self::$deletedFiles[$path]); } /** @@ -238,60 +265,39 @@ class Storage { * @param $filename file to find versions of, relative to the user files dir * @returns array */ - public static function getVersions($uid, $filename ) { - if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) { - $versions_fileview = new \OC\Files\View('/' . $uid . '/files_versions'); - $versionsName = $versions_fileview->getLocalFile($filename).'.v'; - $escapedVersionName = preg_replace('/(\*|\?|\[)/', '[$1]', $versionsName); - - $versions = array(); - // fetch for old versions - $matches = glob($escapedVersionName.'*'); - - if ( !$matches ) { - return $versions; - } - - sort( $matches ); - - $files_view = new \OC\Files\View('/'.$uid.'/files'); - $local_file = $files_view->getLocalFile($filename); - $local_file_md5 = \md5_file( $local_file ); - - foreach( $matches as $ma ) { - $parts = explode( '.v', $ma ); - $version = ( end( $parts ) ); - $key = $version.'#'.$filename; - $versions[$key]['cur'] = 0; - $versions[$key]['version'] = $version; - $versions[$key]['humanReadableTimestamp'] = self::getHumanReadableTimestamp($version); - $versions[$key]['path'] = $filename; - $versions[$key]['preview'] = \OCP\Util::linkToRoute('core_ajax_versions_preview', array('file' => $filename, 'version' => $version)); - $versions[$key]['size'] = $versions_fileview->filesize($filename.'.v'.$version); - - // if file with modified date exists, flag it in array as currently enabled version - ( \md5_file( $ma ) == $local_file_md5 ? $versions[$key]['fileMatch'] = 1 : $versions[$key]['fileMatch'] = 0 ); - - } - - // newest versions first - $versions = array_reverse( $versions ); - - foreach( $versions as $key => $value ) { - // flag the first matched file in array (which will have latest modification date) as current version - if ( $value['fileMatch'] ) { - $value['cur'] = 1; - break; + public static function getVersions($uid, $filename) { + $versions = array(); + // fetch for old versions + $view = new \OC\Files\View('/' . $uid . '/' . self::VERSIONS_ROOT); + + $pathinfo = pathinfo($filename); + + $files = $view->getDirectoryContent($pathinfo['dirname']); + + $versionedFile = $pathinfo['basename']; + + foreach ($files as $file) { + if ($file['type'] === 'file') { + $pos = strrpos($file['path'], '.v'); + $currentFile = substr($file['name'], 0, strrpos($file['name'], '.v')); + if ($currentFile === $versionedFile) { + $version = substr($file['path'], $pos + 2); + $key = $version . '#' . $filename; + $versions[$key]['cur'] = 0; + $versions[$key]['version'] = $version; + $versions[$key]['humanReadableTimestamp'] = self::getHumanReadableTimestamp($version); + $versions[$key]['preview'] = \OCP\Util::linkToRoute('core_ajax_versions_preview', array('file' => $filename, 'version' => $version, 'user' => $uid)); + $versions[$key]['path'] = $filename; + $versions[$key]['name'] = $versionedFile; + $versions[$key]['size'] = $file['size']; } } - - return( $versions ); - - } else { - // if versioning isn't enabled then return an empty array - return( array() ); } + // sort with newest version first + krsort($versions); + + return $versions; } /** @@ -338,22 +344,21 @@ class Storage { * @return size of vesions */ private static function calculateSize($uid) { - if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) { - $versions_fileview = new \OC\Files\View('/'.$uid.'/files_versions'); - $versionsRoot = $versions_fileview->getLocalFolder(''); - - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($versionsRoot), - \RecursiveIteratorIterator::CHILD_FIRST - ); + if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') { + $view = new \OC\Files\View('/' . $uid . '/files_versions'); $size = 0; - foreach ($iterator as $path) { - if ( preg_match('/^.+\.v(\d+)$/', $path, $match) ) { - $relpath = substr($path, strlen($versionsRoot)-1); - $size += $versions_fileview->filesize($relpath); + $dirContent = $view->getDirectoryContent('/'); + + while (!empty($dirContent)) { + $path = reset($dirContent); + if ($path['type'] === 'dir') { + $dirContent = array_merge($dirContent, $view->getDirectoryContent(substr($path['path'], strlen('files_versions')))); + } else { + $size += $view->filesize(substr($path['path'], strlen('files_versions'))); } + unset($dirContent[key($dirContent)]); } return $size; @@ -366,48 +371,45 @@ class Storage { * @return array with contains two arrays 'all' which contains all versions sorted by age and 'by_file' which contains all versions sorted by filename */ private static function getAllVersions($uid) { - if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) { - $versions_fileview = new \OC\Files\View('/'.$uid.'/files_versions'); - $versionsRoot = $versions_fileview->getLocalFolder(''); - - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($versionsRoot), - \RecursiveIteratorIterator::CHILD_FIRST - ); + $view = new \OC\Files\View('/' . $uid . '/'); + $dirs = array(self::VERSIONS_ROOT); - $versions = array(); + while (!empty($dirs)) { + $dir = array_pop($dirs); + $files = $view->getDirectoryContent($dir); - foreach ($iterator as $path) { - if ( preg_match('/^.+\.v(\d+)$/', $path, $match) ) { - $relpath = substr($path, strlen($versionsRoot)-1); - $versions[$match[1].'#'.$relpath] = array('path' => $relpath, 'timestamp' => $match[1]); + foreach ($files as $file) { + if ($file['type'] === 'dir') { + array_push($dirs, $file['path']); + } else { + $versionsBegin = strrpos($file['path'], '.v'); + $relPathStart = strlen(self::VERSIONS_ROOT); + $version = substr($file['path'], $versionsBegin + 2); + $relpath = substr($file['path'], $relPathStart, $versionsBegin - $relPathStart); + $key = $version . '#' . $relpath; + $versions[$key] = array('path' => $relpath, 'timestamp' => $version); } } + } - ksort($versions); - - $i = 0; - - $result = array(); + ksort($versions); - foreach( $versions as $key => $value ) { - $i++; - $size = $versions_fileview->filesize($value['path']); - $filename = substr($value['path'], 0, -strlen($value['timestamp'])-2); + $result = array(); - $result['all'][$key]['version'] = $value['timestamp']; - $result['all'][$key]['path'] = $filename; - $result['all'][$key]['size'] = $size; + foreach ($versions as $key => $value) { + $size = $view->filesize($value['path']); + $filename = $value['path']; - $filename = substr($value['path'], 0, -strlen($value['timestamp'])-2); - $result['by_file'][$filename][$key]['version'] = $value['timestamp']; - $result['by_file'][$filename][$key]['path'] = $filename; - $result['by_file'][$filename][$key]['size'] = $size; + $result['all'][$key]['version'] = $value['timestamp']; + $result['all'][$key]['path'] = $filename; + $result['all'][$key]['size'] = $size; - } - - return $result; + $result['by_file'][$filename][$key]['version'] = $value['timestamp']; + $result['by_file'][$filename][$key]['path'] = $filename; + $result['by_file'][$filename][$key]['size'] = $size; } + + return $result; } /** @@ -489,6 +491,7 @@ class Storage { while ($availableSpace < 0 && $i < $numOfVersions) { $version = current($allVersions); $versionsFileview->unlink($version['path'].'.v'.$version['version']); + \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $version['path'].'.v'.$version['version'])); $versionsSize -= $version['size']; $availableSpace += $version['size']; next($allVersions); @@ -539,6 +542,7 @@ class Storage { if ($version['version'] > $nextVersion) { //distance between two version too small, delete version $versionsFileview->unlink($version['path'] . '.v' . $version['version']); + \OC_Hook::emit('\OCP\Versions', 'delete', array('path' => $version['path'] . '.v' . $version['version'])); $size += $version['size']; unset($allVersions[$key]); // update array with all versions } else { |