Merge pull request #1240 from splitbrain/plugindeletedfiles

remove deleted files on update of extension
This commit is contained in:
Andreas Gohr 2015-07-27 10:52:03 +02:00
commit 874f411fe8
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: