FIX: fix unassigning related files

This commit is contained in:
Michal Kváček
2017-02-23 18:24:35 +01:00
parent 507e186713
commit f90df0f4bc
2 changed files with 3 additions and 7 deletions
+2 -6
View File
@@ -22,9 +22,7 @@ trait Content
$changed = 0;
// check if any file was removed
if ($revisionId) {
$changed += $this->removeRelatedFiles($revisionId, $assignedFiles);
}
$changed += $this->removeRelatedFiles($revisionId, $assignedFiles);
// allow uploading only on created pages
if (!$this->id || !$files[0]) {
@@ -73,12 +71,10 @@ trait Content
private function removeRelatedFiles($revisionId, $assignedFiles)
{
$allFiles = $this->files()
->whereNotIn('id', $assignedFiles)
->whereNotIn('id', array_keys($assignedFiles))
->get();
foreach ($allFiles as $file) {
$this->saveHistory($revisionId, 'file', $file->original_filename, ['file' => null]);
ContentHasFile::where('content_id', $this->id)
->where('file_id', $file->id)
->delete();