Hello Lefteris,
We've stumbled on an odd case where our editors try to do a 'Save as Copy' and encounter an error which than causes Econa to copy the entire JPATH_SITE to a new images/econa/'.$fieldName.'/'.$itemId. I believe the error is in one of our own extensions but the Econa FieldTrait class doesn't seem to do proper data validation in this case. I am having trouble recreating the scenario where this happens but even so the massive copy is not making our sys admin very happy.
this is the code block is in the FiledTrait afterSave method that seems to create the problem
// Handle copy
if ($itemId && $itemId != $item->id) {
$path = $this->getImagePath($field->name, $item->id);
$sourceFolder = JPATH_SITE.'/'.$data['com_fields'][$field->name]['path'];
$targetFolder = JPATH_SITE.'/'.$path;
if (Folder::exists($sourceFolder)) {
Folder::copy($sourceFolder, $targetFolder);
}
}
if $data['com_fields'][$field->name]['path'] is not set properly this will cause the whole JPATH_SITE tree to copy to $targetFolder. I noticed that above this block is a much tighter way of grabbing the $path
$path = isset($data['com_fields'][$field->name]['path']) && $data['com_fields'][$field->name]['path'] ? $data['com_fields'][$field->name]['path'] : $this->getImagePath($field->name, $item->id);
using the same approach could yield something safer if i understand the issue properly.
$sourcePath = isset($data['com_fields'][$field->name]['path']) && $data['com_fields'][$field->name]['path'] ? $data['com_fields'][$field->name]['path'] : $this->getImagePath($field->name, $itemId);
$targetPath = $this->getImagePath($field->name, $item->id);
$sourceFolder = JPATH_SITE.'/'.$sourcePath;
$targetFolder = JPATH_SITE.'/'.$targetPath;
Since, again, I'm having trouble recreating this issue in my IDE I've only been able to test this by manually breaking the incoming $data values.
Let me know if I'm incorrect in how this outlier case should be handled.
Thanks,
Oliver