You need to be logged in to post in the forum - Log In

An active JCE Pro Subscription is required to post in the forum - Buy a Subscription

  • Support
  • Forum
  • MediaBox
  • Is it possible to move files into new folders without loosing the links on the website?

Support is currently Offline

Official support hours:
Monday To Friday
From 09:00 To 17:00 Europe/London (BST)

Please post your question in the Forum and we will get back to you as soon as we can.

  Wednesday, 14 July 2021
  7 Replies
  2.8K Visits
Hi,

I would love to reorganize the library without loosing all the links to the webpage.
Is there any efficient way to do that?

Kind Regards
more than a month ago
·
#108296
Accepted Answer
This could technically be done, but it would not be a feature of JCE, as JCE does not update or alter any database content except it's own.

The best way to do this would be with a plugin, that responds to a JCE Filesystem Event, and then searches database content, eg: the Article Manager #__content table, for url values to replace. For example:


public function onWfFileSystemAfterRename($result)
{
$db = JFactory::getDBO();

if ($result->state) {
$before = $result->source;
$after = $result->path;

// make the paths relative, eg: images/forest.jpg
$before = mb_substr($before, mb_strlen(JPATH_SITE));
// trim leading slash
$before = ltrim($before, '/');

$after = mb_substr($after, mb_strlen(JPATH_SITE));
// trim leading slash
$after = ltrim($after, '/');

$query = $db->getQuery(true);

$word = $db->quote('%="' . $db->escape($before, true) . '"%', false);

$query->select('id, introtext')->from('#__content')->where('introtext LIKE ' . $word . '');
$db->setQuery($query);

$rows = $db->loadObjectList();

$table = JTable::getInstance('Content', 'JTable');

foreach($rows as $row) {
$row->introtext = str_replace('="' . $before . '"', '="' . $after . '"', $row->introtext);

if ($table->load($row->id)) {
$table->introtext = $row->introtext;
$table->store();
}
}
}
}


As you can see this is quite complex (and untested!!), and this is for only renaming a single file, so doing this for multiple files, in a cut/paste operation for example, might be quite intensive.

Just because you're not paranoid doesn't mean everybody isn't out to get you.

more than a month ago
·
#108296
Accepted Answer
This could technically be done, but it would not be a feature of JCE, as JCE does not update or alter any database content except it's own.

The best way to do this would be with a plugin, that responds to a JCE Filesystem Event, and then searches database content, eg: the Article Manager #__content table, for url values to replace. For example:


public function onWfFileSystemAfterRename($result)
{
$db = JFactory::getDBO();

if ($result->state) {
$before = $result->source;
$after = $result->path;

// make the paths relative, eg: images/forest.jpg
$before = mb_substr($before, mb_strlen(JPATH_SITE));
// trim leading slash
$before = ltrim($before, '/');

$after = mb_substr($after, mb_strlen(JPATH_SITE));
// trim leading slash
$after = ltrim($after, '/');

$query = $db->getQuery(true);

$word = $db->quote('%="' . $db->escape($before, true) . '"%', false);

$query->select('id, introtext')->from('#__content')->where('introtext LIKE ' . $word . '');
$db->setQuery($query);

$rows = $db->loadObjectList();

$table = JTable::getInstance('Content', 'JTable');

foreach($rows as $row) {
$row->introtext = str_replace('="' . $before . '"', '="' . $after . '"', $row->introtext);

if ($table->load($row->id)) {
$table->introtext = $row->introtext;
$table->store();
}
}
}
}


As you can see this is quite complex (and untested!!), and this is for only renaming a single file, so doing this for multiple files, in a cut/paste operation for example, might be quite intensive.

Just because you're not paranoid doesn't mean everybody isn't out to get you.

elian selected the reply #108296 as the answer for this post — 10 months ago
more than a month ago
·
#108297
Thanks for the insight!
more than a month ago
·
#108299
I have made this into a plugin for testing - https://github.com/widgetfactory/wf-filesystem-sync-content

It works with renaming files and folders, and cut/paste of files and folders. It currently only supports Joomla Articles (com_content) and has only been tested in Joomla 3.x

Just because you're not paranoid doesn't mean everybody isn't out to get you.

more than a month ago
·
#108302
Thats amazing, i'll give this a try as soon as i find the time for it!
Thank you!
more than a month ago
·
#109249
Hi Ryan,

is this (https://github.com/widgetfactory/wf-filesystem-sync-content/releases/) already implemented in the Pro Version?
How is the workflow in the JCE Editor then? Just Cut and paste (e.g. into another folder)?

Thanks a lot,
Dennis
more than a month ago
·
#109250
is this (https://github.com/widgetfactory/wf-filesystem-sync-content/releases/) already implemented in the Pro Version?

This is an optional plugin because it is expermiental. It also only works with com_content (Article Manager).

How is the workflow in the JCE Editor then? Just Cut and paste (e.g. into another folder)?


It is triggered from JCE Filesystem Events - move and rename - and updates the database with the changed path/name.

JCE Pro does now include something similar or the current editor content (introduced in 2.9.11) see URL Sync - https://www.joomlacontenteditor.net/news/jce-pro-2-9-11-released

Just because you're not paranoid doesn't mean everybody isn't out to get you.

more than a month ago
·
#109251
How is the workflow in the JCE Editor then? Just Cut and paste (e.g. into another folder)?


You just do what you usually do, and it fixes the urls in the backend.

Just because you're not paranoid doesn't mean everybody isn't out to get you.

  • Page :
  • 1
There are no replies made for this post yet.
Be one of the first to reply to this post!