Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Commit

Permalink
apply configured default filters
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Nov 21, 2018
1 parent 62f25ea commit 9803824
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 26 additions & 5 deletions admin.php
Expand Up @@ -10,10 +10,8 @@
*/
class admin_plugin_backup extends DokuWiki_Admin_Plugin
{
var $state = 0;
var $backup = '';

protected $prefFile = DOKU_CONF . 'backup.json';
protected $filters = null;

/** @inheritdoc */
public function handle()
Expand Down Expand Up @@ -231,13 +229,36 @@ protected function addDirectoryToTar(Tar $tar, $dir, $as, $logger = null, $filte

// custom filter:
if ($filter !== null && !$filter($file)) continue;
// default filter:
// FIXME $this->getConf('filterdirs');
if (!$this->defaultFilter($file)) continue;

if ($logger !== null) $logger($file);
$tar->addFile($path, $file);
}
}

/**
* Checks the default filters against the given backup path
*
* We also filter .git directories
*
* @param string $path the backup path
* @return bool true if the file should be backed up, false if not
*/
protected function defaultFilter($path)
{
if ($this->filters === null) {
$this->filters = explode("\n", $this->getConf('filterdirs'));
$this->filters = array_map('trim', $this->filters);
$this->filters = array_filter($this->filters);
}

if (strpos($path, '/.git') !== false) return false;

foreach ($this->filters as $filter) {
if (strpos($path, $filter) === 0) return false;
}

return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion conf/default.php
@@ -1,5 +1,5 @@
<?php

$conf['backupnamespace'] = 'wiki:backup';
$conf['filterdirs'] = '/path/to/my/dokuwiki/data/media/latex';
$conf['filterdirs'] = 'data/media/latex/';
$conf['filterbackups'] = true;

0 comments on commit 9803824

Please sign in to comment.