remove deleted files on update of extension

Resolves #1192

`/lib/plugins/<plugin>/deleted.files`
which list files that can be removed e.g.
```
# This is a list of files that were present in previous plugin releases
# but were removed later. An up to date plugin should not have any of
# the files installed
action.php
folder/file.txt
```
This commit is contained in:
Gerrit Uitslag 2015-07-16 22:14:13 +02:00
parent 82246f10eb
commit 1afa9ba84a
1 changed files with 40 additions and 1 deletions

View File

@ -578,6 +578,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
try {
$installed = $this->installArchive("$tmp/upload.archive", true, $basename);
$this->updateManagerData('', $installed);
$this->removeDeletedfiles($installed);
// purge cache
$this->purgeCache();
}catch (Exception $e){
@ -598,6 +599,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
$path = $this->download($url);
$installed = $this->installArchive($path, true);
$this->updateManagerData($url, $installed);
$this->removeDeletedfiles($installed);
// purge cache
$this->purgeCache();
@ -623,6 +625,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
if (!isset($installed[$this->getID()])) {
throw new Exception('Error, the requested extension hasn\'t been installed or updated');
}
$this->removeDeletedfiles($installed);
$this->setExtension($this->getID());
$this->purgeCache();
return $installed;
@ -918,7 +921,9 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
if($this->dircopy($item['tmp'], $target)) {
// return info
$id = $item['base'];
if($item['type'] == 'template') $id = 'template:'.$id;
if($item['type'] == 'template') {
$id = 'template:'.$id;
}
$installed_extensions[$id] = array(
'base' => $item['base'],
'type' => $item['type'],
@ -1117,6 +1122,40 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
return true;
}
/**
* Delete outdated files from updated plugins
*
* @param array $installed
*/
private function removeDeletedfiles($installed) {
foreach($installed as $id => $extension) {
// only on update
if($extension['action'] == 'install') continue;
// get definition file
if($extension['type'] == 'template') {
$extensiondir = DOKU_TPLLIB;
}else{
$extensiondir = DOKU_PLUGIN;
}
$extensiondir = $extensiondir . $extension['base'] .'/';
$definitionfile = $extensiondir . 'deleted.files';
if(!file_exists($definitionfile)) continue;
// delete the old files
$list = file($definitionfile);
foreach($list as $line) {
$line = trim(preg_replace('/#.*$/', '', $line));
if(!$line) continue;
$file = $extensiondir . $line;
if(!file_exists($file)) continue;
io_rmdir($file, true);
}
}
}
}
// vim:ts=4:sw=4:et: