Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deleted files on update of extension #1240

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 40 additions & 1 deletion lib/plugins/extension/helper/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ public function installFromUpload($field){
try {
$installed = $this->installArchive("$tmp/upload.archive", true, $basename);
$this->updateManagerData('', $installed);
$this->removeDeletedfiles($installed);
// purge cache
$this->purgeCache();
}catch (Exception $e){
Expand All @@ -598,6 +599,7 @@ public function installFromURL($url){
$path = $this->download($url);
$installed = $this->installArchive($path, true);
$this->updateManagerData($url, $installed);
$this->removeDeletedfiles($installed);

// purge cache
$this->purgeCache();
Expand All @@ -623,6 +625,7 @@ public function installOrUpdate() {
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;
Expand Down Expand Up @@ -918,7 +921,9 @@ public function installArchive($file, $overwrite=false, $base = '') {
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'],
Expand Down Expand Up @@ -1117,6 +1122,40 @@ private function dircopy($src, $dst) {

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: