MetadataLiveEvent.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\FilesMetadata\Event;
  8. use OCP\FilesMetadata\AMetadataEvent;
  9. /**
  10. * MetadataLiveEvent is an event initiated when a file is created or updated.
  11. * The app contains the Node related to the created/updated file, and a FilesMetadata that already
  12. * contains the currently known metadata.
  13. *
  14. * Setting new metadata, or modifying already existing metadata with different value, will trigger
  15. * the save of the metadata in the database.
  16. *
  17. * @see AMetadataEvent::getMetadata()
  18. * @see AMetadataEvent::getNode()
  19. * @see MetadataLiveEvent::requestBackgroundJob()
  20. * @since 28.0.0
  21. */
  22. class MetadataLiveEvent extends AMetadataEvent {
  23. private bool $runAsBackgroundJob = false;
  24. /**
  25. * For heavy process, call this method if your app prefers to update metadata on a
  26. * background/cron job, instead of the live process.
  27. * A similar MetadataBackgroundEvent will be broadcast on next cron tick.
  28. *
  29. * @return void
  30. * @since 28.0.0
  31. */
  32. public function requestBackgroundJob(): void {
  33. $this->runAsBackgroundJob = true;
  34. }
  35. /**
  36. * return true if any app that catch this event requested a re-run as background job
  37. *
  38. * @return bool
  39. * @since 28.0.0
  40. */
  41. public function isRunAsBackgroundJobRequested(): bool {
  42. return $this->runAsBackgroundJob;
  43. }
  44. }