Skip to content

Commit

Permalink
#25785 include in 22.03.9
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Aug 15, 2023
1 parent c079432 commit ee0b05f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
3 changes: 2 additions & 1 deletion HOTFIX_TRACKING.md
Expand Up @@ -161,4 +161,5 @@ This maintenance release includes the following code fixes:
**Release-22.03.9**

134. https://github.com/dotCMS/core/issues/20400 : Using 'select all' on categories before deleting will delete even deselected items #20400
135. https://github.com/dotCMS/core/issues/25775 : OPTIONS requests to /api/* return HTTP 500, causing CORS failures #25775
135. https://github.com/dotCMS/core/issues/25775 : OPTIONS requests to /api/* return HTTP 500, causing CORS failures #25775
136. https://github.com/dotCMS/core/issues/25785 : Edit/Preview Mode not showing Draft changes #25785
Expand Up @@ -51,15 +51,20 @@ public ContentUtils getInstance()
}


/**
* Will pull a single piece of content for you based on the inode or identifier. It will always
* try to retrieve the live content unless in EDIT_MODE in the backend of dotCMS when passing in an
* identifier. If it is an inode this is ignored.
* Will return NULL if not found
* @param inodeOrIdentifier Can be either an Inode or Indentifier of content.
* @return NULL if not found
*/
public static Contentlet find(String inodeOrIdentifier, User user, boolean EDIT_OR_PREVIEW_MODE, long sessionLang){
/**
* Pulls a single piece of content based on its Inode or Identifier. It will always try to retrieve the live
* content unless the process calling this method is in EDIT or PREVIEW Mode in the back-end of dotCMS when
* passing in an Identifier. If it is an Inode, this is ignored. This method will return {@code null} if the
* Contentlet is not found.
*
* @param inodeOrIdentifier The Inode or Identifier of the {@link Contentlet} being requested.
* @param user The {@link User} used to retrieve the Contentlet's data.
* @param EDIT_OR_PREVIEW_MODE If the current access mode is EDIT or PREVIEW, set this to {@code true}.
* @param sessionLang The language ID of the current session.
*
* @return The requested {@link Contentlet} object.
*/
public static Contentlet find(final String inodeOrIdentifier, final User user, final boolean EDIT_OR_PREVIEW_MODE, final long sessionLang){
return find(inodeOrIdentifier,user,null,EDIT_OR_PREVIEW_MODE, sessionLang);
}

Expand All @@ -74,11 +79,24 @@ private static Contentlet fixRecurringDates(Contentlet contentlet, String[] recD

return contentlet;
}



public static Contentlet find(final String inodeOrIdentifierIn, User user, String tmDate, boolean EDIT_OR_PREVIEW_MODE,
long sessionLang) {


/**
* Pulls a single piece of content based on its Inode or Identifier. It will always try to retrieve the live
* content unless the process calling this method is in EDIT or PREVIEW Mode in the back-end of dotCMS when
* passing in an Identifier. If it is an Inode, this is ignored. This method will return {@code null} if the
* Contentlet is not found.
*
* @param inodeOrIdentifierIn The Inode or Identifier of the {@link Contentlet} being requested.
* @param user The {@link User} used to retrieve the Contentlet's data.
* @param tmDate Optional, the specific date for retrieving a specific Time Machine version.
* @param EDIT_OR_PREVIEW_MODE If the current access mode is EDIT or PREVIEW, set this to {@code true}.
* @param sessionLang The language ID of the current session.
*
* @return The requested {@link Contentlet} object.
*/
public static Contentlet find(final String inodeOrIdentifierIn, final User user, final String tmDate, final boolean EDIT_OR_PREVIEW_MODE,
final long sessionLang) {
final String inodeOrIdentifier = RecurrenceUtil.getBaseEventIdentifier(inodeOrIdentifierIn);
final String[] recDates = RecurrenceUtil.getRecurrenceDates(inodeOrIdentifier);
try {
Expand All @@ -104,22 +122,26 @@ public static Contentlet find(final String inodeOrIdentifierIn, User user, Strin

// timemachine content to be published in the future, return the working version
if (UtilMethods.isSet(ident.getSysPublishDate()) && ffdate.after(ident.getSysPublishDate())) {
return APILocator.getContentletAPI()
.findContentletByIdentifierOrFallback(inodeOrIdentifier, false, sessionLang, user, true)
return conAPI.findContentletByIdentifierOrFallback(inodeOrIdentifier, false, sessionLang, user, true)
.orElse(null);
}
}

contentlet = APILocator.getContentletAPI().findContentletByIdentifierOrFallback(inodeOrIdentifier,
EDIT_OR_PREVIEW_MODE, sessionLang, user, true).orElse(null);
// If content is being viewed in EDIT_OR_PREVIEW_MODE, we need to get the working version. Otherwise, we
// need the live version. That's why we're negating it when calling the API
contentlet = conAPI.findContentletByIdentifierOrFallback(inodeOrIdentifier,
!EDIT_OR_PREVIEW_MODE, sessionLang, user, true).orElse(null);

return fixRecurringDates(contentlet, recDates);

} catch (Exception e) {
} catch (final Exception e) {
String msg = e.getMessage();
msg = (msg.contains("\n")) ? msg.substring(0, msg.indexOf("\n")) : msg;
Logger.warn(ContentUtils.class, msg);
Logger.debug(ContentUtils.class, e.getMessage(), e);
final String errorMsg = String.format("An error occurred when User '%s' attempted to find Contentlet " +
"with Inode/ID '%s' [lang=%s, tmDate=%s]: %s",
user.getUserId(), inodeOrIdentifier, sessionLang, tmDate, msg);
Logger.warn(ContentUtils.class, errorMsg);
Logger.debug(ContentUtils.class, errorMsg, e);
return null;
}

Expand Down

0 comments on commit ee0b05f

Please sign in to comment.