Skip to content

Commit

Permalink
Merge pull request #133 from Raudius/backport/fix_activity
Browse files Browse the repository at this point in the history
[stable27] Fix Activity app dependency in `get_activity` function
  • Loading branch information
Raudius authored Dec 18, 2023
2 parents 0607d99 + 3053ba8 commit 22dfbd4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
13 changes: 4 additions & 9 deletions docs/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ tags({id= 21, parent_id= 13}) -- Finds comment with ID 21 or (if comment 21

Returns a table of activity data for the given object. Currently only `File` objects may be used for retrieving activity.

The function returns a table of `Event` objects.
If the activity app is not installed or enabled, this function returns an empty table.

Example:
```lua
Expand Down Expand Up @@ -607,16 +607,11 @@ Returns the output file's node object, or `nil` if operation failed.
## Template
### html_to_pdf

`html_to_pdf(String html, [Table config]={}, [Table position]={}): string|nil`
~~`html_to_pdf(String html, [Table config]={}, [Table position]={}): string|nil`~~

⚠ Deprecated, will be removed with release 4.0.0. Unfortunately the dependency that enables this function is too large to justify. Removing this function will allow us to reduce the app package size by over 90%.
This function has been removed. The dependency that makes this function work is excessively large, and it is unnecessary to package it with the `file_scripts` app.

Renders the HTML onto a PDF file.

A configuration table can be passed to configure various aspects of PDF generation. For more information see the [MPDF documentation](https://mpdf.github.io/reference/mpdf-variables/overview.html).
The position (x, y, w, h) of where to render the HTML onto the page can also be provided. For more information see the [MPDF documentation](https://mpdf.github.io/reference/mpdf-functions/writefixedposhtml.html)

Returns the PDF as a string (or `nil` if PDF generation failed).
You can continue using the function by manually installing the [`files_scripts_deprecated`](https://github.com/Raudius/files_scripts_deprecated) app, which bundles all the removed functions.
### mustache

`mustache(String template, [Table variables]={}): String`
Expand Down
54 changes: 29 additions & 25 deletions lib/Interpreter/Functions/Nextcloud/Get_Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
namespace OCA\FilesScripts\Interpreter\Functions\Nextcloud;

use OCA\FilesScripts\Interpreter\RegistrableFunction;
use OCA\Activity\Data;
use OCA\Activity\GroupHelper;
use OCA\Activity\UserSettings;
use OCA\Activity\ViewInfoCache;
use OCP\Activity\IEvent;
use OCP\Files\IMimeTypeDetector;
use OCP\IPreview;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;


/**
* `get_activity(object): Event[]`
*
* Returns a table of activity data for the given object. Currently only `File` objects may be used for retrieving activity.
*
* The function returns a table of `Event` objects.
* If the activity app is not installed or enabled, this function returns an empty table.
*
* Example:
* ```lua
Expand All @@ -32,44 +29,51 @@
class Get_Activity extends RegistrableFunction {
use EventSerializerTrait;
private ?IUserSession $userSession;

// FIXME: If Nextcloud includes a nice interface for fetching IEvents this property should be replaced
private ?Data $activityData;
private ?GroupHelper $helper;
private ?UserSettings $settings;
private ?ViewInfoCache $infoCache;
private IURLGenerator $urlGenerator;
private IPreview $preview;
private IMimeTypeDetector $mimeTypeDetector;
private IUserManager $userManager;
private ContainerInterface $container;
private LoggerInterface $logger;

public function __construct(
LoggerInterface $logger,
ContainerInterface $container,
IUserSession $userSession,
IUserManager $userManager,
?Data $data,
?GroupHelper $helper,
?UserSettings $settings,
?ViewInfoCache $infoCache,
IURLGenerator $urlGenerator,
IPreview $preview,
IMimeTypeDetector $mimeTypeDetector
) {
$this->logger = $logger;
$this->container = $container;
$this->userSession = $userSession;
$this->userManager = $userManager;
$this->activityData = $data;
$this->helper = $helper;
$this->settings = $settings;
$this->urlGenerator = $urlGenerator;
$this->preview = $preview;
$this->mimeTypeDetector = $mimeTypeDetector;
$this->infoCache = $infoCache;
}

public function run($object=[]): array {
if (!class_exists(\OCA\Activity\Data::class)) {
if (
!class_exists(\OCA\Activity\Data::class)
|| !class_exists(\OCA\Activity\UserSettings::class)
|| !class_exists(\OCA\Activity\GroupHelper::class)
) {
return [];
}


try {
$activityData = $this->container->get(\OCA\Activity\Data::class);
$groupHelper = $this->container->get(\OCA\Activity\GroupHelper::class);
$userSettings = $this->container->get(\OCA\Activity\UserSettings::class);
} catch (\Throwable $e) {
$this->logger->error("[files_scripts] Failed to initialise activity app Data class ");
return [];
}


$objectType = $this->getObjectType($object);
if (!$objectType) {
return [];
Expand All @@ -83,10 +87,10 @@ public function run($object=[]): array {
$user = $this->userSession->getUser();
$userId = $user ? $user->getUID() : null;

/** @var IEvent[] $activityEvents */
$activityEvents = $this->activityData->get(
$this->helper,
$this->settings,
/** @var \OCP\Activity\IEvent[] $activityEvents */
$activityEvents = $activityData->get(
$groupHelper,
$userSettings,
$userId,
0,
200,
Expand Down

0 comments on commit 22dfbd4

Please sign in to comment.