You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hooks.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Sam Tuke <samtuke@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. /**
  9. * This class contains all hooks.
  10. */
  11. namespace OCA\Files_Versions;
  12. class Hooks {
  13. /**
  14. * listen to write event.
  15. */
  16. public static function write_hook( $params ) {
  17. if (\OCP\App::isEnabled('files_versions')) {
  18. $path = $params[\OC\Files\Filesystem::signal_param_path];
  19. if($path<>'') {
  20. Storage::store($path);
  21. }
  22. }
  23. }
  24. /**
  25. * @brief Erase versions of deleted file
  26. * @param array
  27. *
  28. * This function is connected to the delete signal of OC_Filesystem
  29. * cleanup the versions directory if the actual file gets deleted
  30. */
  31. public static function remove_hook($params) {
  32. if (\OCP\App::isEnabled('files_versions')) {
  33. $path = $params[\OC\Files\Filesystem::signal_param_path];
  34. if($path<>'') {
  35. Storage::delete($path);
  36. }
  37. }
  38. }
  39. /**
  40. * @brief mark file as "deleted" so that we can clean up the versions if the file is gone
  41. * @param array $params
  42. */
  43. public static function pre_remove_hook($params) {
  44. $path = $params[\OC\Files\Filesystem::signal_param_path];
  45. if($path<>'') {
  46. Storage::markDeletedFile($path);
  47. }
  48. }
  49. /**
  50. * @brief rename/move versions of renamed/moved files
  51. * @param array with oldpath and newpath
  52. *
  53. * This function is connected to the rename signal of OC_Filesystem and adjust the name and location
  54. * of the stored versions along the actual file
  55. */
  56. public static function rename_hook($params) {
  57. if (\OCP\App::isEnabled('files_versions')) {
  58. $oldpath = $params['oldpath'];
  59. $newpath = $params['newpath'];
  60. if($oldpath<>'' && $newpath<>'') {
  61. Storage::rename( $oldpath, $newpath );
  62. }
  63. }
  64. }
  65. /**
  66. * @brief clean up user specific settings if user gets deleted
  67. * @param array with uid
  68. *
  69. * This function is connected to the pre_deleteUser signal of OC_Users
  70. * to remove the used space for versions stored in the database
  71. */
  72. public static function deleteUser_hook($params) {
  73. if (\OCP\App::isEnabled('files_versions')) {
  74. $uid = $params['uid'];
  75. Storage::deleteUser($uid);
  76. }
  77. }
  78. }