Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#8975 Fixed argument reflection handling #8983

Merged
merged 2 commits into from
May 25, 2023

Conversation

jonasraoni
Copy link
Contributor

No description provided.

if ($type instanceof ReflectionNamedType) {
return [$type->getName()];
}
if ($type instanceof ReflectionUnionType || $type instanceof ReflectionIntersectionType) {
Copy link
Collaborator

@Vitaliy-1 Vitaliy-1 May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the top of my head, Mailables can support intersection types but not union types, except cases, like in ORCID Plugin, where classes belong to different applications (but nevertheless, I'd check if it works as expected)

Constructor arguments are identified before Mailable instantiation to forecast which email template variables are going to be available when sending an email. E.g., say class1 is a associated with email template variable1 and class2 with variable2, then using the union

public function __construct(class1|class2 $object)

would mean that both template variables, 1 and 2, are available, which isn't true.

As a workaround we can ensure that both class names in the union don't exist in the application at the same time and exclude the one that isn't defined. Or forbid union types and deal with it on the plugin side. Or maybe there is a cleaner way...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, I forgot to answer 😅

I thought about this case, and it will work out of the box for our main case Server|Journal|Preprint (only one of the classes will exist, and the is_a() will skip the other variants properly).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the other cases (where the class might actually exist), like let's say an email that might receive a Failure|Success... I think we have the following options:

  • A. Build a separate email class for each variant
    This is the simplest for us and users, so that would be my choice. It will become unmaintainable just if we had many of such "intersection" variables in a single email, but then we can revisit this topic.
  • B. Add "Smarty" capabilities to the template, so the users can setup loops/conditions/etc (We {if Failure)failed{else}succeeded{/if})
    This would require adding a "view code" / building a powerful and intuitive editor 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if you don't have anything against, I think it's ok to merge it this way, and use the option A 🤔

Copy link
Contributor Author

@jonasraoni jonasraoni May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And for future updates, I think that maybe it's better to have a method/interface, like errrrrr, public static function getVariables(), then we can call it and the class will still have a chance to customize its variables. It will release the constructor to be used for other things (e.g. it might make sense to pass a Journal when building the email, but perhaps I don't want it to be part of the variables).

Take my comments with a grain of salt as I've just skimmed fast through the code =]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonasraoni, thanks for double checking that it works. Can you also add an exception to unsure that both classes in the union don't exist at the same time? It's easy to forget it, especially for someone who haven't worked with mailables before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there's more than one active class in the union type, I've updated the code to retrieve only the first class and emit a warning.
Anyway, I think it's worth to open an issue to revisit how these variables are retrieved later.

@jonasraoni jonasraoni force-pushed the bugfix/main/8975-fix-template-editor branch from 6db5f9d to 2d80590 Compare May 18, 2023 08:12
@jonasraoni jonasraoni requested a review from Vitaliy-1 May 22, 2023 10:12
Copy link
Collaborator

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @jonasraoni. I left a comment but feel free to merge as is if you don't have a time for it right now, in this case please open an issue to not forget to return to it after the release.

if ($type instanceof ReflectionNamedType) {
return [$type->getName()];
}
if ($type instanceof ReflectionUnionType || $type instanceof ReflectionIntersectionType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonasraoni, thanks for double checking that it works. Can you also add an exception to unsure that both classes in the union don't exist at the same time? It's easy to forget it, especially for someone who haven't worked with mailables before.

@jonasraoni jonasraoni force-pushed the bugfix/main/8975-fix-template-editor branch from 2d80590 to 2c96456 Compare May 24, 2023 20:55
@jonasraoni jonasraoni merged commit c3c65e1 into pkp:main May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(OJS-3.4rc3) On click Add and edit templates (email) HTTP ERROR 500 appeared.
2 participants