Skip to content

Commit

Permalink
Don't remove static files if automated static files are turned off
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Jakobi committed Dec 31, 2018
1 parent d4818aa commit 79e8c21
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions core/model/modx/processors/element/remove.class.php
Expand Up @@ -16,6 +16,9 @@
* @subpackage processors.element
*/
abstract class modElementRemoveProcessor extends modObjectRemoveProcessor {
public $staticFilePath;
public $staticFile;

public function cleanup() {
$this->clearCache();
}
Expand All @@ -24,18 +27,42 @@ public function clearCache() {
}

public function cleanupStaticFiles() {
/* Remove file. */
$count = $this->modx->getCount($this->classKey, array('static_file' => $this->staticFile));
if ($this->staticFilePath && $count === 0) {
@unlink($this->staticFilePath);
if ($this->isStaticFilesAutomated()) {
/* Remove file. */
$count = $this->modx->getCount($this->classKey, array('static_file' => $this->staticFile));
if ($this->staticFilePath && $count === 0) {
@unlink($this->staticFilePath);
}

/* Check if parent directory is empty, if so remove parent directory. */
$pathinfo = pathinfo($this->staticFilePath);

if (!empty($pathinfo['dirname'])) {
$this->cleanupStaticDirectories($pathinfo['dirname']);
}
}
}

/* Check if parent directory is empty, if so remove parent directory. */
$pathinfo = pathinfo($this->staticFilePath);
/**
* Determine if static files should be automated for current element class.
*
* @return bool
*/
protected function isStaticFilesAutomated()
{
$elements = array(
'modTemplate' => 'templates',
'modTemplateVar' => 'tvs',
'modChunk' => 'chunks',
'modSnippet' => 'snippets',
'modPlugin' => 'plugins'
);

if (!empty($pathinfo['dirname'])) {
$this->cleanupStaticDirectories($pathinfo['dirname']);
if (!array_key_exists($this->classKey, $elements)) {
return false;
}

return (bool) $this->modx->getOption('static_elements_automate_' . $elements[$this->classKey], null, false);
}

public function cleanupStaticDirectories($dirname) {
Expand Down

0 comments on commit 79e8c21

Please sign in to comment.