From git://github.com/Buesing-Sebastian/Drupal---Media-Browser-Plus.git
This is nice, if directory structure is movable. But after moving, need to batched update all of media objects in directory. The phisical move is ok, but the $file->uri and $file->field_folder values leave original after moving.

Comments

Sebastian.Buesing’s picture

Status: Active » Needs work

I'll have a look at this tomorrow ;-)

Sebastian.Buesing’s picture

Assigned: Unassigned » Sebastian.Buesing
Priority: Normal » Major
Status: Needs work » Needs review

Patched it on github. Update your rep and change the name of the top folder. This does update all files of the subfolders as well ;-).

I tested it a couple of times, but if you run into any problems please post them here immediatly ;-)

szantog’s picture

Great, thanks! I've tested a lot, and it works when edit the folder. But when move in tables admin/content/media/folder_list not yet.
I fixed it. I moved the batch pocess set method to own function as media_browser_plus_folder_update_set_batch($folder), and call it in media_browser_plus_folder_save_folder() and media_browser_plus_folder_list_submit() too

szantog’s picture

Yeepp I've created some shit..

gregbeat’s picture

First off, this is an AWESOME improvement to the default library. Hats off to Sebastian.

I am having a similar issue. In addition, I've added ALT and TITLE tags for my images with media edit fields, and if I attach an image to a node, and then go into the admin/content/media interface and move an image between folders or update the ALT/Title tags, and then go back to my node I have to re-save the node to get the new location URI or ALT/Title Tags. (Or I can go to performance/clear cache to refresh values).

I tried sznatog's path at #4, but it did not fix it for me... but maybe this is a bit different?

UPDATE

after checking the DB directly after making changes, the DB values are all updating as expected. I'm going to look into another method to get my page values to update. This module is working for everything I need it to do.. Good Job!

Sebastian.Buesing’s picture

I'm not sure how you attach the image to your node, but usually it's done by just adding the fid (file id) and on display it loads the file and the correct URI.

Can you explain what you have used, please?

gregbeat’s picture

Sure thing. I just created an image field for my content type via built in D7 cck. Then I modified my node tpl like so:

$image = image_style_url('banner', $node->field_mediaimage['und'][0]['uri']);
$imagealt = $node->field_mediaimage['und'][0]['field_media_alt']['und'][0]['safe_value'];
$imagetitle = $node->field_mediaimage['und'][0]['field_media_title']['und'][0]['safe_value'];

So I'm just grabbing the image, the alt, and the title tags by checking the node variables before I display. Perhaps I need to use a preprocess function to "refresh" the node?

chaloalvarezj’s picture

I just applied the patch manually and it seems to be working! Thank you!

camdarley’s picture

I have the same issue than gregbeat in #5.
I have nodes with an image field. When i move the image previously added to the node between folders, the node display still use the old uri and cannot display the image.
What i have to do is clear the cache or re-save the node.
It's annoying if I have a lot of nodes...

camdarley’s picture

I think we have a problem in the way media_folder_plus move physical directory and files.
With #4, all file object are updated after directory has been moved with FileTransferLocal in media_browser_plus_move_physical_folder.
That mean if there is a problem during file transfer, file object are updated anyway and files appear broken.
In my thought, moving folder should move all files one by one with a batch process, verify for each file that copy is fine, then update uri. It is nonsense to separate the updating of the database and the physical move.
It's a longer process but I actually think it's a compulsory way to avoid broken uri.
Maybe i'm wrong and maybe there's a better solution, what do you think about it?

camdarley’s picture

StatusFileSize
new4.16 KB

Here is a first try, it seems to be working well:

camdarley’s picture

Any update on this? I use #11 on a production site and i'ts working very well: no complains from my clients about broken files anymore.
Is there something wrong with this way of moving files?

camdarley’s picture

I just realize that we can use file_prepare_directory instead of drupal_mkdir :

      // if destination doesn't exist, create folder:
      if(file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
        // store previous path before media update:
        $previous_path = drupal_dirname($media->uri);
        
        // move file
        if (file_move($media, $path . '/' . array_pop(explode('/', $media->uri)))) {
          drupal_set_message(t('Successfully moved @file to @path', array('@file' => $media->uri, '@path' => $path)));
        }
        
        // if parent folder is empty, remove it
        if (drupal_rmdir(drupal_realpath($previous_path))) {
          drupal_set_message(t('Successfully removed folder @folder', array('@folder' => $previous_path)));
        };
      } 
camdarley’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
StatusFileSize
new4.16 KB

Patch for 7.x-2.x version

camdarley’s picture

StatusFileSize
new4.15 KB

Same patch with #13 (I forgot to implement it before posting the preview's one)

kirilius’s picture

I am using the latest 2.x-dev version of this module. I just moved a folder and although all images in it got physically moved, the paths to the images did not get updated. As a result anywhere on the site where I refer to an image style (former ImageCache), I get a broken link and no image is displayed.

Based on the comments above, the latest patch seems to be working. Is there any chance that it is rolled into a release soon? I don't really know how to apply a patch to the code. I am managing my site through cPanel and I don't have shell access to the server.

In the meantime does aybody know how to recover from the situation (moved folder and brken links)?

Thanks!

camdarley’s picture

Hi Kirilius,
As you can see, I got no answer about my patch...
It's working for the 1.x version of MBP... I didn't have enough time to dive into 2.x and check if it could be working with it.
I am very surprised that no one reviewed my patch, because I still think that the way the files are moved now is nonsense.

camdarley’s picture

Status: Needs review » Needs work
dimitriseng’s picture

Any chance to provide a patch for 2.x? Happy to test, thanks.

das-peter’s picture

+++ b/includes/media_browser_plus.folders.inc
@@ -495,6 +477,34 @@ function media_browser_plus_folder_theme_folder_weight_column($weight, $folder_i
+ * Set batch to update media objects of folder and its children, when folder is moved.
...
+ * The term object of folder
...
+    // update files in folder and subfolders
+    // get folders
...
+    // add subfolders if found
...
+    // set batch

The comments should follow the standards: http://drupal.org/node/1354#general

media_browser_plus_folder_update_file_locations_batch() contains locations with trailing whitespaces according to the coding standards they should be removed. I'd suggest to configure your IDE to do that for you automatically.

+++ b/includes/media_browser_plus.folders.inc
@@ -537,8 +547,22 @@ function media_browser_plus_folder_update_file_locations_batch($folders, &$conte
+        if (drupal_rmdir(drupal_realpath($previous_path))) {

I'm not sure if we not should really check first if the folder is empty before call rmdir. The point is that I think we shouldn't assume that a folder is used by MBP only and thus could contain files / folders that can't be moved. Further I'm not sure if we can be sure that the order of the files returned by the query will provide the correct order for processing. This means there could be attempts to delete parent folders before the children are even processed. And since rmdir will throw an E_WARNING this could lead to some ugly output.
How about collecting the folder paths, and handle them once all files are moved?
Sorting could be done using path length, which should be sufficient to have the right child / parent order.

jamesharv’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new11.15 KB

This is a feature which is essential for a client of mine, who is using 7.x-1.0-beta3. So I have written a new patch against 7.x-1.x, based on the work from camdarley, and incorporating the feedback from das-peter.

This is working well for me in a Vanilla Drupal site, and with my client's website (which is still under development and not yet in production use).