Skip to content

Commit 6639c07

Browse files
wilsongerichard67alikon
authored
Action logs fix for media manager upload urls (#31836)
Co-authored-by: Richard Fath <[email protected]> Co-authored-by: Nicola Galgano <[email protected]>
1 parent 2b7a904 commit 6639c07

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

administrator/components/com_actionlogs/helpers/actionlogs.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,13 @@ public static function getHumanReadableLogMessage($log, $generateLinks = true)
246246
* @param string $contentType
247247
* @param integer $id
248248
* @param string $urlVar
249+
* @param JObject $object
249250
*
250251
* @return string Link to the content item
251252
*
252253
* @since 3.9.0
253254
*/
254-
public static function getContentTypeLink($component, $contentType, $id, $urlVar = 'id')
255+
public static function getContentTypeLink($component, $contentType, $id, $urlVar = 'id', $object = null)
255256
{
256257
// Try to find the component helper.
257258
$eName = str_replace('com_', '', $component);
@@ -266,7 +267,7 @@ public static function getContentTypeLink($component, $contentType, $id, $urlVar
266267

267268
if (class_exists($cName) && is_callable(array($cName, 'getContentTypeLink')))
268269
{
269-
return $cName::getContentTypeLink($contentType, $id);
270+
return $cName::getContentTypeLink($contentType, $id, $object);
270271
}
271272
}
272273

administrator/components/com_media/helpers/media.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
defined('_JEXEC') or die;
1111

12+
use Joomla\CMS\Object\CMSObject;
13+
1214
/**
1315
* Media helper class.
1416
*
@@ -197,4 +199,40 @@ public static function countFiles($dir)
197199

198200
return $mediaHelper->countFiles($dir);
199201
}
202+
203+
/**
204+
* Generates the URL to the object in the action logs component
205+
*
206+
* @param string $contentType The content type
207+
* @param integer $id The integer id
208+
* @param CMSObject $mediaObject The media object being uploaded
209+
*
210+
* @return string The link for the action log
211+
*
212+
* @since __DEPLOY_VERSION__
213+
*/
214+
public static function getContentTypeLink($contentType, $id, CMSObject $mediaObject)
215+
{
216+
if ($contentType === 'com_media.file')
217+
{
218+
return '';
219+
}
220+
221+
$link = 'index.php?option=com_media&view=media';
222+
$uploadedPath = substr($mediaObject->get('filepath'), strlen(COM_MEDIA_BASE) + 1);
223+
224+
// Now remove the filename
225+
$uploadedBasePath = substr_replace(
226+
$uploadedPath,
227+
'',
228+
(strlen(DIRECTORY_SEPARATOR . $mediaObject->get('name')) * -1)
229+
);
230+
231+
if (!empty($uploadedBasePath))
232+
{
233+
$link = $link . '&folder=' . $uploadedBasePath;
234+
}
235+
236+
return $link;
237+
}
200238
}

plugins/actionlog/joomla/joomla.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function onContentAfterSave($context, $article, $isNew)
119119
'type' => $params->text_prefix . '_TYPE_' . $params->type_title,
120120
'id' => $id,
121121
'title' => $article->get($params->title_holder),
122-
'itemlink' => ActionlogsHelper::getContentTypeLink($option, $contentType, $id, $params->id_holder)
122+
'itemlink' => ActionlogsHelper::getContentTypeLink($option, $contentType, $id, $params->id_holder, $article),
123123
);
124124

125125
$this->addLog(array($message), $messageLanguageKey, $context);
@@ -268,7 +268,7 @@ public function onContentChangeState($context, $pks, $value)
268268
'type' => $params->text_prefix . '_TYPE_' . $params->type_title,
269269
'id' => $pk,
270270
'title' => $items[$pk]->{$params->title_holder},
271-
'itemlink' => ActionlogsHelper::getContentTypeLink($option, $contentType, $pk, $params->id_holder)
271+
'itemlink' => ActionlogsHelper::getContentTypeLink($option, $contentType, $pk, $params->id_holder, null)
272272
);
273273

274274
$messages[] = $message;
@@ -528,7 +528,7 @@ public function onExtensionAfterSave($context, $table, $isNew)
528528
'id' => $table->get($params->id_holder),
529529
'title' => $table->get($params->title_holder),
530530
'extension_name' => $table->get($params->title_holder),
531-
'itemlink' => ActionlogsHelper::getContentTypeLink($option, $contentType, $table->get($params->id_holder), $params->id_holder)
531+
'itemlink' => ActionlogsHelper::getContentTypeLink($option, $contentType, $table->get($params->id_holder), $params->id_holder, $article)
532532
);
533533

534534
$this->addLog(array($message), $messageLanguageKey, $context);

0 commit comments

Comments
 (0)