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 is currently Offline

Official support hours
Monday to Friday
09:00 - 17:00 Europe/London (BST)

Please create a new Ticket and we will get back to you as soon as we can.

#108293 Is it possible to move files into new folders without loosing the links on the website?

Posted in ‘Mediabox’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Latest post by Ryan on Friday, 29 October 2021 14:58 BST

elian
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

Ryan
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.

Ryan Demmer

Lead Developer / CEO / CTO

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

elian
Thanks for the insight!

Ryan
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

Ryan Demmer

Lead Developer / CEO / CTO

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

elian
Thats amazing, i'll give this a try as soon as i find the time for it!
Thank you!

elian
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

Ryan
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

Ryan Demmer

Lead Developer / CEO / CTO

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

Ryan
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.

Ryan Demmer

Lead Developer / CEO / CTO

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