Support-Forum

jDownloads for Joomla 3.x => jDownloads 3.9 => Bugs => Topic started by: dr236 on 17.12.2020 19:34:02

Title: Batch move not actually moving files - [Fixed in 3.9.8]
Post by: dr236 on 17.12.2020 19:34:02
Hello

(For jd3.9.7.2) The "Batch Move" on the backend doesn't seem to be moving the files to the target folder (the category ids for the downloads are being changed ok).

In administrator/components/com_jdownloads/models/download.php, method batchMove, there doesn't seem to be any code to move the files.

I assume batchMove _should_ be moving files (as it used to). I've applied an emergency patch (basically copying code from batchCopy), but haven't tested it carefully:

Code: [Select]
diff --git a/htdocs/administrator/components/com_jdownloads/models/download.php b/htdocs/administrator/components/com_jdownloads/models/download.php
index c66604df..18fc75fd 100644
--- a/htdocs/administrator/components/com_jdownloads/models/download.php
+++ b/htdocs/administrator/components/com_jdownloads/models/download.php
@@ -886,6 +886,14 @@ class jdownloadsModelDownload extends JModelAdmin
                     return false;
                 }
             }
+
+            // Build the file path from the Downloads target category
+            if ($categoryTable->cat_dir_parent != ''){
+                $target_path = $categoryTable->cat_dir_parent.'/'.$categoryTable->cat_dir;
+            } else {
+                $target_path = $categoryTable->cat_dir;
+            }
+
         }
 
         if (empty($categoryId)) {
@@ -923,6 +931,50 @@ class jdownloadsModelDownload extends JModelAdmin
                 }
             }
 
+            // Move file
+            $source_path = '';
+           
+            if ($categoryId > 1 && $table->url_download != ''){
+                $copy_filename       = $table->url_download;
+                $source_cat_id       = $table->catid;
+                $target_cat_id       = $categoryId;
+               
+                // We must only move when we have a different cat id.
+                if ($source_cat_id != $target_cat_id){
+         
+                    // Get the data from the source category
+                    $sourceCategoryTable = JTable::getInstance('category', 'jdownloadsTable');
+                    if (!$sourceCategoryTable->load($source_cat_id)){
+                        if ($error = $sourceCategoryTable->getError()){
+                            // Fatal error
+                            $this->setError($error);
+                            return false;
+                        } else {
+                            // Category not found
+                            $this->setError(JText::_('COM_JDOWNLOADS_BATCH_MOVE_ROW_NOT_FOUND'));
+                            return false;
+                        }
+                    }
+                   
+                    // Build the file path from the Downloads source category
+                    if ($sourceCategoryTable->cat_dir_parent != ''){
+                        $source_path = $sourceCategoryTable->cat_dir_parent.'/'.$sourceCategoryTable->cat_dir.'/'.$copy_filename;
+                    } else {
+                        $source_path = $sourceCategoryTable->cat_dir.'/'.$copy_filename;
+                    }
+                   
+                    if ($source_path && $target_path){
+                        if (!JFile::exists($params->get('files_uploaddir') . '/'. $source_path)){
+                            $this->setError(JText::sprintf('COM_JDOWNLOADS_BATCH_CANNOT_FIND_COPY_FILE', $source_path));
+                        }
+
+                        if (!JFile::move($params->get('files_uploaddir') . '/' . $source_path, $params->get('files_uploaddir') . '/' . $target_path.'/'.$copy_filename)){
+                            $this->setError(JText::sprintf('COM_JDOWNLOADS_BATCH_CANNOT_COPY_FILES', $source_path));
+                        }
+                    }
+                }   
+            }   
+
             // Set the new category ID
             $table->catid = $categoryId;

Thanks, David
Title: Re: Batch move not actually moving files
Post by: ColinM on 18.12.2020 22:24:16
DavidI confirm that the batch move does not move the actual files as it should do!! :(   It does create what appears to be Downloads in the target category.

For refererence a simple recovery is to delete the apparently moved Downloads from the target directory.  Then use the control panel to check the Download area for new files.  The missing files are still in the original directory so Downloads will be recreated.  This however will loose any other information in the original Download.
Colin





Title: Re: Batch move not actually moving files
Post by: Arno on 19.12.2020 19:06:56
Hi,
okay I will fix it shortly.  :-[
Title: Re: Batch move not actually moving files
Post by: Arno on 19.12.2020 19:51:09
Hi,
I hope I could fix it. Please test the unzipped file below and copy it to your jdownloads admin subfolder /models. Overwrite the old file.
Please post here your result. Thanks.
Title: Re: Batch move not actually moving files
Post by: dr236 on 20.12.2020 21:25:02
That looks ok, now. Thank you.

David
Title: Re: Batch move not actually moving files - [Fixed in 3.9.8]
Post by: ColinM on 28.12.2020 11:19:16
Hi
Have also checked and all OK

Colin