diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2013-01-18 23:31:06 -0500 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2013-01-18 23:31:06 -0500 |
commit | 9e28f924c23294a531e4fd15932abd0416d3eb84 (patch) | |
tree | 760c113cce3958558cbd8c343d6064163835f4ac /apps/files_versions | |
parent | da34e58589152f0c696f4eb802f8a4e3b900de0d (diff) | |
parent | a17ca3a69aae0dde9aaf24f23aeffdd8658829f0 (diff) | |
download | nextcloud-server-9e28f924c23294a531e4fd15932abd0416d3eb84.tar.gz nextcloud-server-9e28f924c23294a531e4fd15932abd0416d3eb84.zip |
Merge branch 'master' into move-datadirectory-checks
Diffstat (limited to 'apps/files_versions')
57 files changed, 300 insertions, 401 deletions
diff --git a/apps/files_versions/ajax/expireAll.php b/apps/files_versions/ajax/expireAll.php deleted file mode 100644 index 5c95885ffbd..00000000000 --- a/apps/files_versions/ajax/expireAll.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -/** - * ownCloud - user_migrate - * - * @author Sam Tuke - * @copyright 2012 Sam Tuke samtuke@owncloud.com - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - -// TODO: Allow admins to expire versions of any user -// TODO: Provide feedback as to how many versions were deleted - -// Check user and app status -OCP\JSON::checkLoggedIn(); -OCP\App::checkAppEnabled('files_versions'); -OCP\JSON::callCheck(); - -$versions = new OCA_Versions\Storage(); - -if( $versions->expireAll() ) { - - OCP\JSON::success(); - die(); - -} else { - - OCP\JSON::error(); - die(); - -}
\ No newline at end of file diff --git a/apps/files_versions/ajax/getVersions.php b/apps/files_versions/ajax/getVersions.php index 8476e5e8a51..600e69cf798 100644 --- a/apps/files_versions/ajax/getVersions.php +++ b/apps/files_versions/ajax/getVersions.php @@ -4,10 +4,9 @@ OCP\JSON::checkAppEnabled('files_versions'); $userDirectory = "/".OCP\USER::getUser()."/files"; $source = $_GET['source']; -if( OCA_Versions\Storage::isversioned( $source ) ) { +$count = 5; //show the newest revisions +if( ($versions = OCA_Versions\Storage::getVersions( $source, $count)) ) { - $count=5; //show the newest revisions - $versions = OCA_Versions\Storage::getVersions( $source, $count); $versionsFormatted = array(); foreach ( $versions AS $version ) { diff --git a/apps/files_versions/ajax/rollbackVersion.php b/apps/files_versions/ajax/rollbackVersion.php index f1b02eb4b92..f2c211d9c1e 100644 --- a/apps/files_versions/ajax/rollbackVersion.php +++ b/apps/files_versions/ajax/rollbackVersion.php @@ -8,10 +8,9 @@ $userDirectory = "/".OCP\USER::getUser()."/files"; $file = $_GET['file']; $revision=(int)$_GET['revision']; -if( OCA_Versions\Storage::isversioned( $file ) ) { - if(OCA_Versions\Storage::rollback( $file, $revision )) { - OCP\JSON::success(array("data" => array( "revision" => $revision, "file" => $file ))); - }else{ - OCP\JSON::error(array("data" => array( "message" => "Could not revert:" . $file ))); - } +if(OCA_Versions\Storage::rollback( $file, $revision )) { + OCP\JSON::success(array("data" => array( "revision" => $revision, "file" => $file ))); +}else{ + OCP\JSON::error(array("data" => array( "message" => "Could not revert:" . $file ))); } + diff --git a/apps/files_versions/history.php b/apps/files_versions/history.php index d4c278ebd85..6071240e583 100644 --- a/apps/files_versions/history.php +++ b/apps/files_versions/history.php @@ -28,7 +28,6 @@ $tmpl = new OCP\Template( 'files_versions', 'history', 'user' ); if ( isset( $_GET['path'] ) ) { $path = $_GET['path']; - $path = $path; $tmpl->assign( 'path', $path ); $versions = new OCA_Versions\Storage(); @@ -52,10 +51,8 @@ if ( isset( $_GET['path'] ) ) { } // show the history only if there is something to show - if( OCA_Versions\Storage::isversioned( $path ) ) { - - $count = 999; //show the newest revisions - $versions = OCA_Versions\Storage::getVersions( $path, $count); + $count = 999; //show the newest revisions + if( ($versions = OCA_Versions\Storage::getVersions( $path, $count)) ) { $tmpl->assign( 'versions', array_reverse( $versions ) ); diff --git a/apps/files_versions/js/settings-personal.js b/apps/files_versions/js/settings-personal.js deleted file mode 100644 index 1e6b036fdab..00000000000 --- a/apps/files_versions/js/settings-personal.js +++ /dev/null @@ -1,39 +0,0 @@ -// TODO: allow the button to be clicked only once - -$( document ).ready(function(){ - // - $( '#expireAllBtn' ).click( - - function( event ) { - - // Prevent page from reloading - event.preventDefault(); - - // Show loading gif - $('.expireAllLoading').show(); - - $.getJSON( - OC.filePath('files_versions','ajax','expireAll.php'), - function(result){ - if (result.status == 'success') { - $('.expireAllLoading').hide(); - $('#expireAllBtn').html('Expiration successful'); - } else { - - // Cancel loading - $('#expireAllBtn').html('Expiration failed'); - - // Show Dialog - OC.dialogs.alert( - 'Something went wrong, your files may not have been expired', - 'An error has occurred', - function(){ - $('#expireAllBtn').html(t('files_versions', 'Expire all versions')+'<img style="display: none;" class="loading" src="'+OC.filePath('core','img','loading.gif')+'" />'); - } - ); - } - } - ); - } - ); -});
\ No newline at end of file diff --git a/apps/files_versions/l10n/ar.php b/apps/files_versions/l10n/ar.php index fea7f1c7562..1f1f3100405 100644 --- a/apps/files_versions/l10n/ar.php +++ b/apps/files_versions/l10n/ar.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "إنهاء تاريخ الإنتهاء لجميع الإصدارات", "History" => "السجل الزمني", -"Versions" => "الإصدارات", -"This will delete all existing backup versions of your files" => "هذه العملية ستقوم بإلغاء جميع إصدارات النسخ الاحتياطي للملفات", "Files Versioning" => "أصدرة الملفات", "Enable" => "تفعيل" ); diff --git a/apps/files_versions/l10n/bg_BG.php b/apps/files_versions/l10n/bg_BG.php index 98b5f4113ae..6ecf12d0b00 100644 --- a/apps/files_versions/l10n/bg_BG.php +++ b/apps/files_versions/l10n/bg_BG.php @@ -1,6 +1,4 @@ <?php $TRANSLATIONS = array( "History" => "История", -"Versions" => "Версии", -"This will delete all existing backup versions of your files" => "Това действие ще изтрие всички налични архивни версии на Вашите файлове", "Enable" => "Включено" ); diff --git a/apps/files_versions/l10n/bn_BD.php b/apps/files_versions/l10n/bn_BD.php index 88349342fa9..dffa4d79a06 100644 --- a/apps/files_versions/l10n/bn_BD.php +++ b/apps/files_versions/l10n/bn_BD.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "সমস্ত ভার্সন মেয়াদোত্তীর্ণ", "History" => "ইতিহাস", -"Versions" => "ভার্সন", -"This will delete all existing backup versions of your files" => "এটি আপনার বিদ্যমান ফাইলের সমস্ত ব্যাক-আপ ভার্সন মুছে ফেলবে।", "Files Versioning" => "ফাইল ভার্সন করা", "Enable" => "সক্রিয় " ); diff --git a/apps/files_versions/l10n/ca.php b/apps/files_versions/l10n/ca.php index 0076d02992f..01e0a116873 100644 --- a/apps/files_versions/l10n/ca.php +++ b/apps/files_versions/l10n/ca.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Expira totes les versions", "History" => "Historial", -"Versions" => "Versions", -"This will delete all existing backup versions of your files" => "Això eliminarà totes les versions de còpia de seguretat dels vostres fitxers", "Files Versioning" => "Fitxers de Versions", "Enable" => "Habilita" ); diff --git a/apps/files_versions/l10n/cs_CZ.php b/apps/files_versions/l10n/cs_CZ.php index 3995334d9ee..d219c3e68da 100644 --- a/apps/files_versions/l10n/cs_CZ.php +++ b/apps/files_versions/l10n/cs_CZ.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Vypršet všechny verze", "History" => "Historie", -"Versions" => "Verze", -"This will delete all existing backup versions of your files" => "Odstraní všechny existující zálohované verze Vašich souborů", "Files Versioning" => "Verzování souborů", "Enable" => "Povolit" ); diff --git a/apps/files_versions/l10n/da.php b/apps/files_versions/l10n/da.php index bc02b47f2ad..98579747643 100644 --- a/apps/files_versions/l10n/da.php +++ b/apps/files_versions/l10n/da.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Lad alle versioner udløbe", "History" => "Historik", -"Versions" => "Versioner", -"This will delete all existing backup versions of your files" => "Dette vil slette alle eksisterende backupversioner af dine filer", "Files Versioning" => "Versionering af filer", "Enable" => "Aktiver" ); diff --git a/apps/files_versions/l10n/de.php b/apps/files_versions/l10n/de.php index 092bbfbff70..2fcb996de7b 100644 --- a/apps/files_versions/l10n/de.php +++ b/apps/files_versions/l10n/de.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Alle Versionen löschen", "History" => "Historie", -"Versions" => "Versionen", -"This will delete all existing backup versions of your files" => "Dies löscht alle vorhandenen Sicherungsversionen Deiner Dateien.", "Files Versioning" => "Dateiversionierung", "Enable" => "Aktivieren" ); diff --git a/apps/files_versions/l10n/de_DE.php b/apps/files_versions/l10n/de_DE.php index a568112d02d..2fcb996de7b 100644 --- a/apps/files_versions/l10n/de_DE.php +++ b/apps/files_versions/l10n/de_DE.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Alle Versionen löschen", "History" => "Historie", -"Versions" => "Versionen", -"This will delete all existing backup versions of your files" => "Dies löscht alle vorhandenen Sicherungsversionen Ihrer Dateien.", "Files Versioning" => "Dateiversionierung", "Enable" => "Aktivieren" ); diff --git a/apps/files_versions/l10n/el.php b/apps/files_versions/l10n/el.php index f6b9a5b2998..6b189c2cdd3 100644 --- a/apps/files_versions/l10n/el.php +++ b/apps/files_versions/l10n/el.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Λήξη όλων των εκδόσεων", "History" => "Ιστορικό", -"Versions" => "Εκδόσεις", -"This will delete all existing backup versions of your files" => "Αυτό θα διαγράψει όλες τις υπάρχουσες εκδόσεις των αντιγράφων ασφαλείας των αρχείων σας", "Files Versioning" => "Εκδόσεις Αρχείων", "Enable" => "Ενεργοποίηση" ); diff --git a/apps/files_versions/l10n/eo.php b/apps/files_versions/l10n/eo.php index 0c3835373ef..87b314655c0 100644 --- a/apps/files_versions/l10n/eo.php +++ b/apps/files_versions/l10n/eo.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Eksvalidigi ĉiujn eldonojn", "History" => "Historio", -"Versions" => "Eldonoj", -"This will delete all existing backup versions of your files" => "Ĉi tio forigos ĉiujn estantajn sekurkopiajn eldonojn de viaj dosieroj", "Files Versioning" => "Dosiereldonigo", "Enable" => "Kapabligi" ); diff --git a/apps/files_versions/l10n/es.php b/apps/files_versions/l10n/es.php index f6b63df7c2b..4a8c34e5180 100644 --- a/apps/files_versions/l10n/es.php +++ b/apps/files_versions/l10n/es.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Expirar todas las versiones", "History" => "Historial", -"Versions" => "Versiones", -"This will delete all existing backup versions of your files" => "Esto eliminará todas las versiones guardadas como copia de seguridad de tus archivos", "Files Versioning" => "Versionado de archivos", "Enable" => "Habilitar" ); diff --git a/apps/files_versions/l10n/es_AR.php b/apps/files_versions/l10n/es_AR.php index a78264de03f..74d8907fc35 100644 --- a/apps/files_versions/l10n/es_AR.php +++ b/apps/files_versions/l10n/es_AR.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Expirar todas las versiones", "History" => "Historia", -"Versions" => "Versiones", -"This will delete all existing backup versions of your files" => "Hacer estom borrará todas las versiones guardadas como copia de seguridad de tus archivos", "Files Versioning" => "Versionado de archivos", "Enable" => "Activar" ); diff --git a/apps/files_versions/l10n/et_EE.php b/apps/files_versions/l10n/et_EE.php index f1296f23fcd..ff119d5374e 100644 --- a/apps/files_versions/l10n/et_EE.php +++ b/apps/files_versions/l10n/et_EE.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Kõikide versioonide aegumine", "History" => "Ajalugu", -"Versions" => "Versioonid", -"This will delete all existing backup versions of your files" => "See kustutab kõik sinu failidest tehtud varuversiooni", "Files Versioning" => "Failide versioonihaldus", "Enable" => "Luba" ); diff --git a/apps/files_versions/l10n/eu.php b/apps/files_versions/l10n/eu.php index d84d9011707..c6b4cd7692d 100644 --- a/apps/files_versions/l10n/eu.php +++ b/apps/files_versions/l10n/eu.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Iraungi bertsio guztiak", "History" => "Historia", -"Versions" => "Bertsioak", -"This will delete all existing backup versions of your files" => "Honek zure fitxategien bertsio guztiak ezabatuko ditu", "Files Versioning" => "Fitxategien Bertsioak", "Enable" => "Gaitu" ); diff --git a/apps/files_versions/l10n/fi_FI.php b/apps/files_versions/l10n/fi_FI.php index 3cec4c04bfe..bdce8e9fe52 100644 --- a/apps/files_versions/l10n/fi_FI.php +++ b/apps/files_versions/l10n/fi_FI.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Vanhenna kaikki versiot", "History" => "Historia", -"Versions" => "Versiot", -"This will delete all existing backup versions of your files" => "Tämä poistaa kaikki tiedostojesi olemassa olevat varmuuskopioversiot", "Files Versioning" => "Tiedostojen versiointi", "Enable" => "Käytä" ); diff --git a/apps/files_versions/l10n/fr.php b/apps/files_versions/l10n/fr.php index e6dbc274456..2d26b98860a 100644 --- a/apps/files_versions/l10n/fr.php +++ b/apps/files_versions/l10n/fr.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Supprimer les versions intermédiaires", "History" => "Historique", -"Versions" => "Versions", -"This will delete all existing backup versions of your files" => "Cette opération va effacer toutes les versions intermédiaires de vos fichiers (et ne garder que la dernière version en date).", "Files Versioning" => "Versionnage des fichiers", "Enable" => "Activer" ); diff --git a/apps/files_versions/l10n/gl.php b/apps/files_versions/l10n/gl.php index f10c1e16263..7e44b8898bf 100644 --- a/apps/files_versions/l10n/gl.php +++ b/apps/files_versions/l10n/gl.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Caducan todas as versións", "History" => "Historial", -"Versions" => "Versións", -"This will delete all existing backup versions of your files" => "Isto eliminará todas as copias de seguranza que haxa dos seus ficheiros", "Files Versioning" => "Sistema de versión de ficheiros", "Enable" => "Activar" ); diff --git a/apps/files_versions/l10n/he.php b/apps/files_versions/l10n/he.php index 061e88b0dbf..9eb4df64857 100644 --- a/apps/files_versions/l10n/he.php +++ b/apps/files_versions/l10n/he.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "הפגת תוקף כל הגרסאות", "History" => "היסטוריה", -"Versions" => "גרסאות", -"This will delete all existing backup versions of your files" => "פעולה זו תמחק את כל גיבויי הגרסאות הקיימים של הקבצים שלך", "Files Versioning" => "שמירת הבדלי גרסאות של קבצים", "Enable" => "הפעלה" ); diff --git a/apps/files_versions/l10n/hu_HU.php b/apps/files_versions/l10n/hu_HU.php index 1575eda3f35..95d37ad06ed 100644 --- a/apps/files_versions/l10n/hu_HU.php +++ b/apps/files_versions/l10n/hu_HU.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Az összes korábbi változat törlése", "History" => "Korábbi változatok", -"Versions" => "Az állományok korábbi változatai", -"This will delete all existing backup versions of your files" => "Itt törölni tudja állományainak összes korábbi verzióját", "Files Versioning" => "Az állományok verzionálása", "Enable" => "engedélyezve" ); diff --git a/apps/files_versions/l10n/id.php b/apps/files_versions/l10n/id.php index d8ac66c9763..6c553327c42 100644 --- a/apps/files_versions/l10n/id.php +++ b/apps/files_versions/l10n/id.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "kadaluarsakan semua versi", "History" => "riwayat", -"Versions" => "versi", -"This will delete all existing backup versions of your files" => "ini akan menghapus semua versi backup yang ada dari file anda", "Files Versioning" => "pembuatan versi file", "Enable" => "aktifkan" ); diff --git a/apps/files_versions/l10n/is.php b/apps/files_versions/l10n/is.php index f63939d3af9..ccb8287b71e 100644 --- a/apps/files_versions/l10n/is.php +++ b/apps/files_versions/l10n/is.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Úrelda allar útgáfur", "History" => "Saga", -"Versions" => "Útgáfur", -"This will delete all existing backup versions of your files" => "Þetta mun eyða öllum afritum af skránum þínum", "Files Versioning" => "Útgáfur af skrám", "Enable" => "Virkja" ); diff --git a/apps/files_versions/l10n/it.php b/apps/files_versions/l10n/it.php index 0b1e70823d5..c57b0930111 100644 --- a/apps/files_versions/l10n/it.php +++ b/apps/files_versions/l10n/it.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Scadenza di tutte le versioni", "History" => "Cronologia", -"Versions" => "Versioni", -"This will delete all existing backup versions of your files" => "Ciò eliminerà tutte le versioni esistenti dei tuoi file", "Files Versioning" => "Controllo di versione dei file", "Enable" => "Abilita" ); diff --git a/apps/files_versions/l10n/ja_JP.php b/apps/files_versions/l10n/ja_JP.php index 367152c0743..c97ba3d00ee 100644 --- a/apps/files_versions/l10n/ja_JP.php +++ b/apps/files_versions/l10n/ja_JP.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "すべてのバージョンを削除する", "History" => "履歴", -"Versions" => "バージョン", -"This will delete all existing backup versions of your files" => "これは、あなたのファイルのすべてのバックアップバージョンを削除します", "Files Versioning" => "ファイルのバージョン管理", "Enable" => "有効化" ); diff --git a/apps/files_versions/l10n/ko.php b/apps/files_versions/l10n/ko.php index 688babb1121..f40925e1be2 100644 --- a/apps/files_versions/l10n/ko.php +++ b/apps/files_versions/l10n/ko.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "모든 버전 삭제", "History" => "역사", -"Versions" => "버전", -"This will delete all existing backup versions of your files" => "이 파일의 모든 백업 버전을 삭제합니다", "Files Versioning" => "파일 버전 관리", "Enable" => "사용함" ); diff --git a/apps/files_versions/l10n/ku_IQ.php b/apps/files_versions/l10n/ku_IQ.php index 5fa3b9080d7..db5dbad49fc 100644 --- a/apps/files_versions/l10n/ku_IQ.php +++ b/apps/files_versions/l10n/ku_IQ.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "وهشانهکان گشتیان بهسهردهچن", "History" => "مێژوو", -"Versions" => "وهشان", -"This will delete all existing backup versions of your files" => "ئهمه سهرجهم پاڵپشتی وهشانه ههبووهکانی پهڕگهکانت دهسڕینتهوه", "Files Versioning" => "وهشانی پهڕگه", "Enable" => "چالاککردن" ); diff --git a/apps/files_versions/l10n/lt_LT.php b/apps/files_versions/l10n/lt_LT.php index 3250ddc7c3c..adf4893020e 100644 --- a/apps/files_versions/l10n/lt_LT.php +++ b/apps/files_versions/l10n/lt_LT.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Panaikinti visų versijų galiojimą", "History" => "Istorija", -"Versions" => "Versijos", -"This will delete all existing backup versions of your files" => "Tai ištrins visas esamas failo versijas", "Files Versioning" => "Failų versijos", "Enable" => "Įjungti" ); diff --git a/apps/files_versions/l10n/mk.php b/apps/files_versions/l10n/mk.php index 60a06ad3384..d3ec233fe41 100644 --- a/apps/files_versions/l10n/mk.php +++ b/apps/files_versions/l10n/mk.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Истечи ги сите верзии", "History" => "Историја", -"Versions" => "Версии", -"This will delete all existing backup versions of your files" => "Ова ќе ги избрише сите постоечки резервни копии од вашите датотеки", "Files Versioning" => "Верзии на датотеки", "Enable" => "Овозможи" ); diff --git a/apps/files_versions/l10n/nb_NO.php b/apps/files_versions/l10n/nb_NO.php index b441008db01..18c72506102 100644 --- a/apps/files_versions/l10n/nb_NO.php +++ b/apps/files_versions/l10n/nb_NO.php @@ -1,7 +1,5 @@ <?php $TRANSLATIONS = array( "History" => "Historie", -"Versions" => "Versjoner", -"This will delete all existing backup versions of your files" => "Dette vil slette alle tidligere versjoner av alle filene dine", "Files Versioning" => "Fil versjonering", "Enable" => "Aktiver" ); diff --git a/apps/files_versions/l10n/nl.php b/apps/files_versions/l10n/nl.php index f9b5507621d..cd147ca693f 100644 --- a/apps/files_versions/l10n/nl.php +++ b/apps/files_versions/l10n/nl.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Alle versies laten verlopen", "History" => "Geschiedenis", -"Versions" => "Versies", -"This will delete all existing backup versions of your files" => "Dit zal alle bestaande backup versies van uw bestanden verwijderen", "Files Versioning" => "Bestand versies", "Enable" => "Activeer" ); diff --git a/apps/files_versions/l10n/pl.php b/apps/files_versions/l10n/pl.php index 46c28d4590a..a0247b8abc6 100644 --- a/apps/files_versions/l10n/pl.php +++ b/apps/files_versions/l10n/pl.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Wygasają wszystkie wersje", "History" => "Historia", -"Versions" => "Wersje", -"This will delete all existing backup versions of your files" => "Spowoduje to usunięcie wszystkich istniejących wersji kopii zapasowych plików", "Files Versioning" => "Wersjonowanie plików", "Enable" => "Włącz" ); diff --git a/apps/files_versions/l10n/pt_BR.php b/apps/files_versions/l10n/pt_BR.php index 3d39a533d65..854a30e6bee 100644 --- a/apps/files_versions/l10n/pt_BR.php +++ b/apps/files_versions/l10n/pt_BR.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Expirar todas as versões", "History" => "Histórico", -"Versions" => "Versões", -"This will delete all existing backup versions of your files" => "Isso removerá todas as versões de backup existentes dos seus arquivos", "Files Versioning" => "Versionamento de Arquivos", "Enable" => "Habilitar" ); diff --git a/apps/files_versions/l10n/pt_PT.php b/apps/files_versions/l10n/pt_PT.php index 2ddf70cc6c5..dc1bde08cad 100644 --- a/apps/files_versions/l10n/pt_PT.php +++ b/apps/files_versions/l10n/pt_PT.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Expirar todas as versões", "History" => "Histórico", -"Versions" => "Versões", -"This will delete all existing backup versions of your files" => "Isto irá apagar todas as versões de backup do seus ficheiros", "Files Versioning" => "Versionamento de Ficheiros", "Enable" => "Activar" ); diff --git a/apps/files_versions/l10n/ro.php b/apps/files_versions/l10n/ro.php index e23e771e392..7dfaee3672b 100644 --- a/apps/files_versions/l10n/ro.php +++ b/apps/files_versions/l10n/ro.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Expiră toate versiunile", "History" => "Istoric", -"Versions" => "Versiuni", -"This will delete all existing backup versions of your files" => "Această acțiune va șterge toate versiunile salvate ale fișierelor tale", "Files Versioning" => "Versionare fișiere", "Enable" => "Activare" ); diff --git a/apps/files_versions/l10n/ru.php b/apps/files_versions/l10n/ru.php index d698e90b8b8..4c7fb501091 100644 --- a/apps/files_versions/l10n/ru.php +++ b/apps/files_versions/l10n/ru.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Просрочить все версии", "History" => "История", -"Versions" => "Версии", -"This will delete all existing backup versions of your files" => "Очистить список версий ваших файлов", "Files Versioning" => "Версии файлов", "Enable" => "Включить" ); diff --git a/apps/files_versions/l10n/ru_RU.php b/apps/files_versions/l10n/ru_RU.php index 557c2f8e6d1..8656e346eb6 100644 --- a/apps/files_versions/l10n/ru_RU.php +++ b/apps/files_versions/l10n/ru_RU.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Срок действия всех версий истекает", "History" => "История", -"Versions" => "Версии", -"This will delete all existing backup versions of your files" => "Это приведет к удалению всех существующих версий резервной копии Ваших файлов", "Files Versioning" => "Файлы управления версиями", "Enable" => "Включить" ); diff --git a/apps/files_versions/l10n/si_LK.php b/apps/files_versions/l10n/si_LK.php index dbddf6dc2e9..37debf869bc 100644 --- a/apps/files_versions/l10n/si_LK.php +++ b/apps/files_versions/l10n/si_LK.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "සියලු අනුවාද අවලංගු කරන්න", "History" => "ඉතිහාසය", -"Versions" => "අනුවාද", -"This will delete all existing backup versions of your files" => "මෙයින් ඔබගේ ගොනුවේ රක්ශිත කරනු ලැබු අනුවාද සියල්ල මකා දමනු ලැබේ", "Files Versioning" => "ගොනු අනුවාදයන්", "Enable" => "සක්රිය කරන්න" ); diff --git a/apps/files_versions/l10n/sk_SK.php b/apps/files_versions/l10n/sk_SK.php index 132c6c09682..a3a3567cb4f 100644 --- a/apps/files_versions/l10n/sk_SK.php +++ b/apps/files_versions/l10n/sk_SK.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Expirovať všetky verzie", "History" => "História", -"Versions" => "Verzie", -"This will delete all existing backup versions of your files" => "Budú zmazané všetky zálohované verzie vašich súborov", "Files Versioning" => "Vytváranie verzií súborov", "Enable" => "Zapnúť" ); diff --git a/apps/files_versions/l10n/sl.php b/apps/files_versions/l10n/sl.php index 22b890a042d..7f386c9edaa 100644 --- a/apps/files_versions/l10n/sl.php +++ b/apps/files_versions/l10n/sl.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Zastaraj vse različice", "History" => "Zgodovina", -"Versions" => "Različice", -"This will delete all existing backup versions of your files" => "S tem bodo izbrisane vse obstoječe različice varnostnih kopij vaših datotek", "Files Versioning" => "Sledenje različicam", "Enable" => "Omogoči" ); diff --git a/apps/files_versions/l10n/sv.php b/apps/files_versions/l10n/sv.php index e36164e30ab..6788d1fb0f9 100644 --- a/apps/files_versions/l10n/sv.php +++ b/apps/files_versions/l10n/sv.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Upphör alla versioner", "History" => "Historik", -"Versions" => "Versioner", -"This will delete all existing backup versions of your files" => "Detta kommer att radera alla befintliga säkerhetskopior av dina filer", "Files Versioning" => "Versionshantering av filer", "Enable" => "Aktivera" ); diff --git a/apps/files_versions/l10n/ta_LK.php b/apps/files_versions/l10n/ta_LK.php index f1215b3ecc1..aca76dcc262 100644 --- a/apps/files_versions/l10n/ta_LK.php +++ b/apps/files_versions/l10n/ta_LK.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "எல்லா பதிப்புகளும் காலாவதியாகிவிட்டது", "History" => "வரலாறு", -"Versions" => "பதிப்புகள்", -"This will delete all existing backup versions of your files" => "உங்களுடைய கோப்புக்களில் ஏற்கனவே உள்ள ஆதாரநகல்களின் பதிப்புக்களை இவை அழித்துவிடும்", "Files Versioning" => "கோப்பு பதிப்புகள்", "Enable" => "இயலுமைப்படுத்துக" ); diff --git a/apps/files_versions/l10n/th_TH.php b/apps/files_versions/l10n/th_TH.php index 89b9f626911..e1e996903ae 100644 --- a/apps/files_versions/l10n/th_TH.php +++ b/apps/files_versions/l10n/th_TH.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "หมดอายุทุกรุ่น", "History" => "ประวัติ", -"Versions" => "รุ่น", -"This will delete all existing backup versions of your files" => "นี่จะเป็นลบทิ้งไฟล์รุ่นที่ทำการสำรองข้อมูลทั้งหมดที่มีอยู่ของคุณทิ้งไป", "Files Versioning" => "การกำหนดเวอร์ชั่นของไฟล์", "Enable" => "เปิดใช้งาน" ); diff --git a/apps/files_versions/l10n/tr.php b/apps/files_versions/l10n/tr.php index 73f207d5024..e9a4c4702e1 100644 --- a/apps/files_versions/l10n/tr.php +++ b/apps/files_versions/l10n/tr.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Tüm sürümleri sona erdir", "History" => "Geçmiş", -"Versions" => "Sürümler", -"This will delete all existing backup versions of your files" => "Bu dosyalarınızın tüm yedek sürümlerini silecektir", "Files Versioning" => "Dosya Sürümleri", "Enable" => "Etkinleştir" ); diff --git a/apps/files_versions/l10n/uk.php b/apps/files_versions/l10n/uk.php index 7532f755c88..49acda81079 100644 --- a/apps/files_versions/l10n/uk.php +++ b/apps/files_versions/l10n/uk.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Термін дії всіх версій", "History" => "Історія", -"Versions" => "Версії", -"This will delete all existing backup versions of your files" => "Це призведе до знищення всіх існуючих збережених версій Ваших файлів", "Files Versioning" => "Версії файлів", "Enable" => "Включити" ); diff --git a/apps/files_versions/l10n/vi.php b/apps/files_versions/l10n/vi.php index 260c3b6b39c..bb7163f6b18 100644 --- a/apps/files_versions/l10n/vi.php +++ b/apps/files_versions/l10n/vi.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "Hết hạn tất cả các phiên bản", "History" => "Lịch sử", -"Versions" => "Phiên bản", -"This will delete all existing backup versions of your files" => "Khi bạn thực hiện thao tác này sẽ xóa tất cả các phiên bản sao lưu hiện có ", "Files Versioning" => "Phiên bản tập tin", "Enable" => "Bật " ); diff --git a/apps/files_versions/l10n/zh_CN.GB2312.php b/apps/files_versions/l10n/zh_CN.GB2312.php index 107805221b8..d9e788033aa 100644 --- a/apps/files_versions/l10n/zh_CN.GB2312.php +++ b/apps/files_versions/l10n/zh_CN.GB2312.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "作废所有版本", "History" => "历史", -"Versions" => "版本", -"This will delete all existing backup versions of your files" => "这将删除所有您现有文件的备份版本", "Files Versioning" => "文件版本", "Enable" => "启用" ); diff --git a/apps/files_versions/l10n/zh_CN.php b/apps/files_versions/l10n/zh_CN.php index 48e7157c98f..14301ff0c04 100644 --- a/apps/files_versions/l10n/zh_CN.php +++ b/apps/files_versions/l10n/zh_CN.php @@ -1,8 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "过期所有版本", "History" => "历史", -"Versions" => "版本", -"This will delete all existing backup versions of your files" => "将会删除您的文件的所有备份版本", "Files Versioning" => "文件版本", "Enable" => "开启" ); diff --git a/apps/files_versions/l10n/zh_TW.php b/apps/files_versions/l10n/zh_TW.php index a21fdc85f8d..a7b496b37db 100644 --- a/apps/files_versions/l10n/zh_TW.php +++ b/apps/files_versions/l10n/zh_TW.php @@ -1,7 +1,5 @@ <?php $TRANSLATIONS = array( -"Expire all versions" => "所有逾期的版本", "History" => "歷史", -"Versions" => "版本", "Files Versioning" => "檔案版本化中...", "Enable" => "啟用" ); diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index e897a81f7af..5fb9dc3c3c5 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -39,15 +39,15 @@ class Hooks { * cleanup the versions directory if the actual file gets deleted */ public static function remove_hook($params) { - $versions_fileview = \OCP\Files::getStorage('files_versions'); - $rel_path = $params['path']; - $abs_path = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$rel_path.'.v'; - if(Storage::isversioned($rel_path)) { - $versions = Storage::getVersions($rel_path); - foreach ($versions as $v) { - unlink($abs_path . $v['version']); - } - } + if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+
+ $versions = new Storage( new \OC_FilesystemView('') );
+
+ $path = $params[\OC_Filesystem::signal_param_path];
+
+ if($path<>'') $versions->delete( $path );
+
+ }
} /** @@ -58,18 +58,16 @@ class Hooks { * of the stored versions along the actual file */ public static function rename_hook($params) { - $versions_fileview = \OCP\Files::getStorage('files_versions'); - $rel_oldpath = $params['oldpath']; - $abs_oldpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$rel_oldpath.'.v'; - $abs_newpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$params['newpath'].'.v'; - if(Storage::isversioned($rel_oldpath)) { - $info=pathinfo($abs_newpath); - if(!file_exists($info['dirname'])) mkdir($info['dirname'], 0750, true); - $versions = Storage::getVersions($rel_oldpath); - foreach ($versions as $v) { - rename($abs_oldpath.$v['version'], $abs_newpath.$v['version']); - } + if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+
+ $versions = new Storage( new \OC_FilesystemView('') );
+
+ $oldpath = $params['oldpath']; + $newpath = $params['newpath'];
+
+ if($oldpath<>'' && $newpath<>'') $versions->rename( $oldpath, $newpath );
+
} } - + } diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 0ccaaf1095d..48be5e223ac 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -1,6 +1,7 @@ <?php /** * Copyright (c) 2012 Frank Karlitschek <frank@owncloud.org> + * 2013 Bjoern Schiessle <schiessle@owncloud.com> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -16,24 +17,23 @@ namespace OCA_Versions; class Storage { - - // config.php configuration: - // - files_versions - // - files_versionsfolder - // - files_versionsblacklist - // - files_versionsmaxfilesize - // - files_versionsinterval - // - files_versionmaxversions - // - // todo: - // - finish porting to OC_FilesystemView to enable network transparency - // - add transparent compression. first test if it´s worth it. - const DEFAULTENABLED=true; - const DEFAULTBLACKLIST='avi mp3 mpg mp4 ctmp'; - const DEFAULTMAXFILESIZE=1048576; // 10MB - const DEFAULTMININTERVAL=60; // 1 min - const DEFAULTMAXVERSIONS=50; + const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota + + private static $max_versions_per_interval = array( + 1 => array('intervalEndsAfter' => 10, //first 10sec, one version every 2sec + 'step' => 2), + 2 => array('intervalEndsAfter' => 60, //next minute, one version every 10sec
+ 'step' => 10), + 3 => array('intervalEndsAfter' => 3600, //next hour, one version every minute + 'step' => 60), + 4 => array('intervalEndsAfter' => 86400, //next 24h, one version every hour + 'step' => 3600), + 5 => array('intervalEndsAfter' => 2592000, //next 30days, one version per day
+ 'step' => 86400), + 6 => array('intervalEndsAfter' => -1, //until the end one version per week
+ 'step' => 604800), + ); private static function getUidAndFilename($filename) { @@ -72,56 +72,78 @@ class Storage { return false; } - // check filetype blacklist - $blacklist=explode(' ', \OCP\Config::getSystemValue('files_versionsblacklist', Storage::DEFAULTBLACKLIST)); - foreach($blacklist as $bl) { - $parts=explode('.', $filename); - $ext=end($parts); - if(strtolower($ext)==$bl) { - return false; - } - } // we should have a source file to work with if (!$files_view->file_exists($filename)) { return false; } - // check filesize - if($files_view->filesize($filename)>\OCP\Config::getSystemValue('files_versionsmaxfilesize', Storage::DEFAULTMAXFILESIZE)) { - return false; - } - - - // check mininterval if the file is being modified by the owner (all shared files should be versioned despite mininterval) - if ($uid == \OCP\User::getUser()) { - $versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions'); - $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename); - $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath(''); - $matches=glob($versionsName.'.v*'); - sort($matches); - $parts=explode('.v', end($matches)); - if((end($parts)+Storage::DEFAULTMININTERVAL)>time()) { - return false; - } - } - - // create all parent folders $info=pathinfo($filename); + $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').$users_view->getAbsolutePath('files_versions/'); if(!file_exists($versionsFolderName.'/'.$info['dirname'])) { mkdir($versionsFolderName.'/'.$info['dirname'], 0750, true); } // store a new version of a file - $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.time()); - + $result = $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename)); + if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) {
+ $versionsSize = self::calculateSize($uid);
+ } + $versionsSize += $users_view->filesize('files'.$filename); + // expire old revisions if necessary - Storage::expire($filename); + $newSize = self::expire($filename, $versionsSize); + + if ( $newSize != $versionsSize ) { + \OCP\Config::setAppValue('files_versions', 'size', $versionsSize); + } } } /** + * Delete versions of a file + */ + public static function delete($filename) { + list($uid, $filename) = self::getUidAndFilename($filename);
+ $versions_fileview = new \OC_FilesystemView('/'.$uid .'/files_versions'); +
+ $abs_path = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$filename.'.v';
+ if( ($versions = self::getVersions($filename)) ) {
+ if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) {
+ $versionsSize = self::calculateSize($uid);
+ }
+ foreach ($versions as $v) {
+ unlink($abs_path . $v['version']);
+ $versionsSize -= $v['size'];
+ }
+ \OCP\Config::setAppValue('files_versions', 'size', $versionsSize);
+ } + } + + /**
+ * rename versions of a file
+ */
+ public static function rename($oldpath, $newpath) {
+ list($uid, $oldpath) = self::getUidAndFilename($oldpath); + list($uidn, $newpath) = self::getUidAndFilename($newpath);
+ $versions_view = new \OC_FilesystemView('/'.$uid .'/files_versions'); + $files_view = new \OC_FilesystemView('/'.$uid .'/files'); + $abs_newpath = \OCP\Config::getSystemValue('datadirectory').$versions_view->getAbsolutePath('').$newpath;
+
+ if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) { + $versions_view->rename($oldpath, $newpath); + } else if ( ($versions = Storage::getVersions($oldpath)) ) {
+ $info=pathinfo($abs_newpath);
+ if(!file_exists($info['dirname'])) mkdir($info['dirname'], 0750, true);
+ $versions = Storage::getVersions($oldpath);
+ foreach ($versions as $v) { + $versions_view->rename($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']);
+ }
+ }
+ } + + /** * rollback to an old version of a file. */ public static function rollback($filename, $revision) { @@ -129,45 +151,29 @@ class Storage { if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { list($uid, $filename) = self::getUidAndFilename($filename); $users_view = new \OC_FilesystemView('/'.$uid); - + $versionCreated = false; + + //first create a new version + $version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename); + if ( !$users_view->file_exists($version)) { + $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename)); + $versionCreated = true; + } + // rollback if( @$users_view->copy('files_versions'.$filename.'.v'.$revision, 'files'.$filename) ) { - + $users_view->touch('files'.$filename, $revision); + Storage::expire($filename); return true; - }else{ - - return false; - + }else if ( $versionCreated ) { + $users_view->unlink($version); } - } + return false; } - /** - * check if old versions of a file exist. - */ - public static function isversioned($filename) { - if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { - list($uid, $filename) = self::getUidAndFilename($filename); - $versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions'); - - $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename); - - // check for old versions - $matches=glob($versionsName.'.v*'); - if(count($matches)>0) { - return true; - }else{ - return false; - } - }else{ - return(false); - } - } - - /** * @brief get a list of all available versions of a file in descending chronological order @@ -187,92 +193,232 @@ class Storage { sort( $matches ); - $i = 0; - - $files_view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files'); + $files_view = new \OC_FilesystemView('/'.$uid.'/files'); $local_file = $files_view->getLocalFile($filename); - foreach( $matches as $ma ) { - $i++; - $versions[$i]['cur'] = 0; + foreach( $matches as $ma ) { $parts = explode( '.v', $ma ); - $versions[$i]['version'] = ( end( $parts ) ); + $version = ( end( $parts ) ); + $key = $version.'#'.$filename; + $versions[$key]['cur'] = 0; + $versions[$key]['version'] = $version; + $versions[$key]['path'] = $filename;
+ $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 ) == \md5_file( $local_file ) ? $versions[$i]['fileMatch'] = 1 : $versions[$i]['fileMatch'] = 0 ); + ( \md5_file( $ma ) == \md5_file( $local_file ) ? $versions[$key]['fileMatch'] = 1 : $versions[$key]['fileMatch'] = 0 ); } $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; - } - } $versions = array_reverse( $versions ); // only show the newest commits if( $count != 0 and ( count( $versions )>$count ) ) { - $versions = array_slice( $versions, count( $versions ) - $count ); - } return( $versions ); - } else { - // if versioning isn't enabled then return an empty array return( array() ); - } } + /**
+ * @brief get the size of all stored versions from a given user
+ * @param $uid id from the user
+ * @return size of vesions
+ */
+ private static function calculateSize($uid) {
+ if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {
+ $versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions');
+ $versionsRoot = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('');
+
+ $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($versionsRoot), \RecursiveIteratorIterator::CHILD_FIRST);
+
+ $size = 0; +
+ foreach ($iterator as $path) {
+ if ( preg_match('/^.+\.v(\d+)$/', $path, $match) ) {
+ $relpath = substr($path, strlen($versionsRoot)-1); + $size += $versions_fileview->filesize($relpath);
+ }
+ } + + return $size;
+ }
+ } + /** - * @brief Erase a file's versions which exceed the set quota + * @brief returns all stored file versions from a given user + * @param $uid id to the user + * @return array with contains two arrays 'all' which contains all versions sorted by age and 'by_file' which contains all versions sorted by filename */ - public static function expire($filename) { - if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { - list($uid, $filename) = self::getUidAndFilename($filename); + private static function getAllVersions($uid) { + if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {
$versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions'); - - $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename); - - // check for old versions - $matches = glob( $versionsName.'.v*' ); - - if( count( $matches ) > \OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS ) ) { - - $numberToDelete = count($matches) - \OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS ); - - // delete old versions of a file - $deleteItems = array_slice( $matches, 0, $numberToDelete ); - - foreach( $deleteItems as $de ) { - - unlink( $versionsName.'.v'.$de ); - + $versionsRoot = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath(''); + + $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($versionsRoot), \RecursiveIteratorIterator::CHILD_FIRST);
+ + $versions = array(); + + 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]); } + }
+ + ksort($versions); + + $i = 0; + + $result = array(); + + foreach( $versions as $key => $value ) {
+ $i++; + $size = $versions_fileview->filesize($value['path']); + $filename = substr($value['path'], 0, -strlen($value['timestamp'])-2); +
+ $result['all'][$key]['version'] = $value['timestamp']; + $result['all'][$key]['path'] = $filename;
+ $result['all'][$key]['size'] = $size; + + $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; +
} + + return $result; } } /** - * @brief Erase all old versions of all user files - * @return true/false + * @brief Erase a file's versions which exceed the set quota */ - public function expireAll() { - $view = \OCP\Files::getStorage('files_versions'); - return $view->deleteAll('', true); + private static function expire($filename, $versionsSize = null) { + if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { + list($uid, $filename) = self::getUidAndFilename($filename); + $versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions'); + + // get available disk space for user + $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($uid, 'files', 'quota')); + if ( $quota == null ) { + $quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota')); + } + if ( $quota == null ) { + $quota = \OC_Filesystem::free_space('/'); + } + + // make sure that we have the current size of the version history + if ( $versionsSize === null ) { + if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) { + $versionsSize = self::calculateSize($uid); + } + } + + // calculate available space for version history
+ $rootInfo = \OC_FileCache::get('', '/'. $uid . '/files'); + $free = $quota-$rootInfo['size']; // remaining free space for user + if ( $free > 0 ) { + $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $versionsSize; // how much space can be used for versions + } else { + $availableSpace = $free-$versionsSize; + } + + // after every 1000s run reduce the number of all versions not only for the current file + $random = rand(0, 1000); + if ($random == 0) { + $result = Storage::getAllVersions($uid); + $versions_by_file = $result['by_file']; + $all_versions = $result['all']; + } else { + $all_versions = Storage::getVersions($filename); + $versions_by_file[$filename] = $all_versions; + } + + $time = time(); + + // it is possible to expire versions from more than one file + // iterate through all given files + foreach ($versions_by_file as $filename => $versions) { + $versions = array_reverse($versions); // newest version first + + $interval = 1; + $step = Storage::$max_versions_per_interval[$interval]['step']; + if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] == -1) { + $nextInterval = -1; + } else { + $nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter']; + } + + $firstVersion = reset($versions); + $firstKey = key($versions); + $prevTimestamp = $firstVersion['version']; + $nextVersion = $firstVersion['version'] - $step; + $remaining_versions[$firstKey] = $firstVersion; + unset($versions[$firstKey]); + + foreach ($versions as $key => $version) { + $newInterval = true; + while ( $newInterval ) { + if ( $nextInterval == -1 || $version['version'] >= $nextInterval ) { + if ( $version['version'] > $nextVersion ) { + //distance between two version too small, delete version + $versions_fileview->unlink($version['path'].'.v'.$version['version']); + $availableSpace += $version['size']; + $versionsSize -= $version['size']; + unset($all_versions[$key]); // update array with all versions + } else { + $nextVersion = $version['version'] - $step; + } + $newInterval = false; // version checked so we can move to the next one + } else { // time to move on to the next interval + $interval++; + $step = Storage::$max_versions_per_interval[$interval]['step']; + $nextVersion = $prevTimestamp - $step; + if ( Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] == -1 ) { + $nextInterval = -1; + } else {
+ $nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter']; + } + $newInterval = true; // we changed the interval -> check same version with new interval + } + } + $prevTimestamp = $version['version']; + } + } + + // check if enough space is available after versions are rearranged. + // if not we delete the oldest versions until we meet the size limit for versions + $numOfVersions = count($all_versions); + $i = 0; + while ($availableSpace < 0) { + if ($i = $numOfVersions-2) break; // keep at least the last version + $versions_fileview->unlink($all_versions[$i]['path'].'.v'.$all_versions[$i]['version']); + $versionsSize -= $all_versions[$i]['size']; + $availableSpace += $all_versions[$i]['size']; + $i++; + } + + return $versionsSize; // finally return the new size of the version history + } + + return false; } } diff --git a/apps/files_versions/settings-personal.php b/apps/files_versions/settings-personal.php deleted file mode 100644 index 6555bc99c3e..00000000000 --- a/apps/files_versions/settings-personal.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -$tmpl = new OCP\Template( 'files_versions', 'settings-personal'); - -OCP\Util::addscript('files_versions', 'settings-personal'); - -return $tmpl->fetchPage(); diff --git a/apps/files_versions/templates/settings-personal.php b/apps/files_versions/templates/settings-personal.php deleted file mode 100644 index 2b313a07c88..00000000000 --- a/apps/files_versions/templates/settings-personal.php +++ /dev/null @@ -1,12 +0,0 @@ -<form id="versions"> - <fieldset class="personalblock"> - <legend> - <strong><?php echo $l->t('Versions'); ?></strong> - </legend> - <button id="expireAllBtn"> - <?php echo $l->t('Expire all versions'); ?> - <img style="display: none;" class="expireAllLoading" src="<?php echo OCP\Util::imagePath('core', 'loading.gif'); ?>" /> - </button> - <br /><em><?php echo $l->t('This will delete all existing backup versions of your files'); ?></em> - </fieldset> -</form> diff --git a/apps/files_versions/templates/settings.php b/apps/files_versions/templates/settings.php index 88063cb075b..bfca8366f5d 100644 --- a/apps/files_versions/templates/settings.php +++ b/apps/files_versions/templates/settings.php @@ -1,6 +1,6 @@ <form id="versionssettings"> - <fieldset class="personalblock"> - <legend><strong><?php echo $l->t('Files Versioning');?></strong></legend> - <input type="checkbox" name="versions" id="versions" value="1" <?php if (OCP\Config::getSystemValue('versions', 'true')=='true') echo ' checked="checked"'; ?> /> <label for="versions"><?php echo $l->t('Enable'); ?></label> <br/> - </fieldset> + <fieldset class="personalblock"> + <legend><strong><?php echo $l->t('Files Versioning');?></strong></legend> + <input type="checkbox" name="versions" id="versions" value="1" <?php if (OCP\Config::getSystemValue('versions', 'true')=='true') echo ' checked="checked"'; ?> /> <label for="versions"><?php echo $l->t('Enable'); ?></label> <br/> + </fieldset> </form> |