diff --git a/core/components/com_resources/helpers/html.php b/core/components/com_resources/helpers/html.php
index 0f0900e330e..2c2113c1e45 100644
--- a/core/components/com_resources/helpers/html.php
+++ b/core/components/com_resources/helpers/html.php
@@ -824,7 +824,24 @@ public static function primary_child($option, $resource, $firstChild, $xact='')
//} else {
$pop = (User::isGuest()) ? '
' . Lang::txt('COM_RESOURCES_TOOL_LOGIN_REQUIRED_TO_RUN') . '
' : '';
$pop = ($resource->revision =='dev') ? '' . Lang::txt('COM_RESOURCES_TOOL_VERSION_UNDER_DEVELOPMENT') . '
' : $pop;
- $html .= self::primaryButton('launchtool', $lurl, Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 0, $pop);
+
+ $existingSession = self::findExistingToolSession($resource);
+ if ($existingSession)
+ {
+ $resumeUrl = Route::url(
+ 'index.php?option=com_tools&task=session'
+ . '&app=' . $existingSession->appname
+ . '&sess=' . $existingSession->sessnum
+ );
+ $routedLurl = Route::url($lurl);
+ $newUrl = $routedLurl . (strpos($routedLurl, '?') !== false ? '&newinstance=1' : '?newinstance=1');
+ $html .= self::primaryButton('resumetool', $resumeUrl, Lang::txt('COM_RESOURCES_RESUME_TOOL'), '', Lang::txt('COM_RESOURCES_RESUME_TOOL_TITLE'), '', 0, $pop);
+ $html .= '' . Lang::txt('COM_RESOURCES_LAUNCH_NEW_INSTANCE') . '
';
+ }
+ else
+ {
+ $html .= self::primaryButton('launchtool', $lurl, Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 0, $pop);
+ }
//}
}
else
@@ -1095,6 +1112,71 @@ public static function primary_child($option, $resource, $firstChild, $xact='')
return $html;
}
+ /**
+ * Look for an existing middleware session for the current user that matches
+ * this tool resource (any version). Returns the most recently accessed one,
+ * or null when none exist / middleware is unavailable.
+ *
+ * @param object $resource Tool resource
+ * @return object|null
+ */
+ protected static function findExistingToolSession($resource)
+ {
+ if (User::isGuest())
+ {
+ return null;
+ }
+
+ if (!$resource->alias)
+ {
+ return null;
+ }
+
+ // The session appname is the attached revision: alias_r, or "_dev" for the dev version.
+ $appname = (!isset($resource->revision) || $resource->revision == 'dev')
+ ? $resource->alias . '_dev'
+ : $resource->alias . '_r' . $resource->revision;
+
+ try
+ {
+ require_once \Component::path('com_tools') . DS . 'helpers' . DS . 'utils.php';
+
+ $mwdb = \Components\Tools\Helpers\Utils::getMWDBO();
+ if (!$mwdb)
+ {
+ return null;
+ }
+
+ $toolsTables = \Component::path('com_tools') . DS . 'tables';
+ require_once $toolsTables . DS . 'viewperm.php';
+ require_once $toolsTables . DS . 'session.php';
+
+ $ms = new \Components\Tools\Tables\Session($mwdb);
+ $records = $ms->getRecords(User::get('username'), $appname, false);
+ }
+ catch (\Exception $e)
+ {
+ return null;
+ }
+
+ if (!$records)
+ {
+ return null;
+ }
+
+ // Records are already filtered to this appname; pick the most recently accessed.
+ $match = null;
+ foreach ($records as $row)
+ {
+ if (!$match || strtotime($row->accesstime) > strtotime($match->accesstime))
+ {
+ $match = $row;
+ }
+ }
+
+ return $match;
+ }
+
/**
* Generate the primary resources button
*
diff --git a/core/components/com_resources/site/assets/css/resources.css b/core/components/com_resources/site/assets/css/resources.css
index 92033b0d517..850ee1405d4 100644
--- a/core/components/com_resources/site/assets/css/resources.css
+++ b/core/components/com_resources/site/assets/css/resources.css
@@ -409,6 +409,14 @@
display: block;
}
+ .launch-new-instance {
+ margin: -1em 0 1.5em 0;
+ }
+ .launch-new-instance .btn {
+ display: block;
+ text-align: center;
+ }
+
#primary-document_pop {
display: none;
position: absolute;
diff --git a/core/components/com_resources/site/language/en-GB/en-GB.com_resources.ini b/core/components/com_resources/site/language/en-GB/en-GB.com_resources.ini
index 3753f58a17d..a046a305a31 100644
--- a/core/components/com_resources/site/language/en-GB/en-GB.com_resources.ini
+++ b/core/components/com_resources/site/language/en-GB/en-GB.com_resources.ini
@@ -172,6 +172,9 @@ COM_RESOURCES_LICENSE="License"
COM_RESOURCES_AVAILABLE_VERSIONS="Available Versions"
COM_RESOURCES_TOOL_IS_CLOSED_SOURCE="This tool is closed source."
COM_RESOURCES_LAUNCH_TOOL="Launch Tool"
+COM_RESOURCES_RESUME_TOOL="Resume Tool"
+COM_RESOURCES_RESUME_TOOL_TITLE="Resume your existing session for this tool"
+COM_RESOURCES_LAUNCH_NEW_INSTANCE="launch a new instance"
COM_RESOURCES_TOOL_IS_RESTRICTED="WARNING: This tool is currently restricted to authorized members of the hub. If you need access, please submit a ticket to that effect and include the reason for your request."
COM_RESOURCES_TOOL_VERSION_UNDER_DEVELOPMENT="Warning: This tool version is under development and may not be run until it is installed."
COM_RESOURCES_TOOL_LOGIN_REQUIRED_TO_RUN="You must login before you can run this tool."