summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2015-07-27 10:52:03 +0200
committerAndreas Gohr <andi@splitbrain.org>2015-07-27 10:52:03 +0200
commit874f411fe89f29339082730a4dd0a874729ea486 (patch)
tree25c770e1249efac4d5faabc1afbcf9ccf84e49fb /lib
parentfcf2eb0eee7dc56b5ef5ef429b54a504ca229f41 (diff)
parent1afa9ba84a2a44f66944dfc754dd8b8662c987fb (diff)
downloadrpg-874f411fe89f29339082730a4dd0a874729ea486.tar.gz
rpg-874f411fe89f29339082730a4dd0a874729ea486.tar.bz2
Merge pull request #1240 from splitbrain/plugindeletedfiles
remove deleted files on update of extension
Diffstat (limited to 'lib')
-rw-r--r--lib/plugins/extension/helper/extension.php41
1 files changed, 40 insertions, 1 deletions
diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php
index c23840805..2f44f55ba 100644
--- a/lib/plugins/extension/helper/extension.php
+++ b/lib/plugins/extension/helper/extension.php
@@ -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: