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
  4 Replies
  1.1K 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 — 2 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!
  • Page :
  • 1
There are no replies made for this post yet.
Be one of the first to reply to this post!