mirror of
https://github.com/processwire/processwire.git
synced 2025-08-18 20:41:16 +02:00
Fix issue processwire/processwire-issues#1033
This commit is contained in:
@@ -590,10 +590,12 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
|
|||||||
$variations = $this->find($options);
|
$variations = $this->find($options);
|
||||||
if(!empty($options['dryrun'])) $defaults['dryRun'] = $options['dryrun']; // case insurance
|
if(!empty($options['dryrun'])) $defaults['dryRun'] = $options['dryrun']; // case insurance
|
||||||
$options = array_merge($defaults, $options); // placement after getVariations() intended
|
$options = array_merge($defaults, $options); // placement after getVariations() intended
|
||||||
$deletedFiles = array();
|
|
||||||
|
|
||||||
/** @var WireFileTools $files */
|
/** @var WireFileTools $files */
|
||||||
$files = $this->wire('files');
|
$files = $this->wire('files');
|
||||||
|
$deletedFiles = array();
|
||||||
|
|
||||||
|
$this->removeExtras($this->pageimage, $deletedFiles, $options);
|
||||||
|
|
||||||
foreach($variations as $variation) {
|
foreach($variations as $variation) {
|
||||||
/** @var Pageimage $variation */
|
/** @var Pageimage $variation */
|
||||||
@@ -605,19 +607,31 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
|
|||||||
$success = $files->unlink($filename, true);
|
$success = $files->unlink($filename, true);
|
||||||
}
|
}
|
||||||
if($success) $deletedFiles[] = $filename;
|
if($success) $deletedFiles[] = $filename;
|
||||||
|
$this->removeExtras($variation, $deletedFiles, $options);
|
||||||
foreach($variation->extras() as $extra) {
|
|
||||||
if(!$extra->exists()) continue;
|
|
||||||
if($options['dryRun']) {
|
|
||||||
$deletedFiles[] = $extra->filename();
|
|
||||||
} else if($extra->unlink()) {
|
|
||||||
$deletedFiles[] = $extra->filename();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$options['dryRun']) $this->variations = null;
|
if(!$options['dryRun']) $this->variations = null;
|
||||||
|
|
||||||
return ($options['dryRun'] || $options['getFiles'] ? $deletedFiles : $this);
|
return ($options['dryRun'] || $options['getFiles'] ? $deletedFiles : $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove extras
|
||||||
|
*
|
||||||
|
* @param Pageimage $pageimage
|
||||||
|
* @param array $deletedFiles
|
||||||
|
* @param array $options See options for remove() method
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function removeExtras(Pageimage $pageimage, array &$deletedFiles, array $options) {
|
||||||
|
foreach($pageimage->extras() as $extra) {
|
||||||
|
if(!$extra->exists()) {
|
||||||
|
// nothing to do
|
||||||
|
} else if(!empty($options['dryRun'])) {
|
||||||
|
$deletedFiles[] = $extra->filename();
|
||||||
|
} else if($extra->unlink()) {
|
||||||
|
$deletedFiles[] = $extra->filename();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user