From 253d4b48ec708eb42033862dc15c8576f44a48ed Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 15:32:05 +0200 Subject: more PHPDocs, unused var, small bit code reformatting --- lib/plugins/extension/helper/extension.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/plugins/extension/helper/extension.php') diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index 2aca0e218..dfa624907 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -799,7 +799,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * The directory is registered for cleanup when the class is destroyed * - * @return bool|string + * @return false|string */ protected function mkTmpDir(){ $dir = io_mktmpdir(); @@ -1079,7 +1079,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { * * @author Andreas Gohr * @param string $file The file to analyze - * @return string|bool false if the file can't be read, otherwise an "extension" + * @return string|false false if the file can't be read, otherwise an "extension" */ private function guess_archive($file) { $fh = fopen($file, 'rb'); @@ -1095,6 +1095,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { /** * Copy with recursive sub-directory support + * + * @param string $src filename path to file + * @param string $dst filename path to file + * @return bool|int|string */ private function dircopy($src, $dst) { global $conf; -- cgit v1.2.3 From 79e79377626799a77c11aa7849cb9c64305590c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:47:45 +0100 Subject: Remove error supression for file_exists() In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost. --- lib/plugins/extension/helper/extension.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/plugins/extension/helper/extension.php') diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index dfa624907..6c0946b09 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -707,7 +707,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { $plugin = null; foreach($plugin_types as $type) { - if(@file_exists($path.$type.'.php')) { + if(file_exists($path.$type.'.php')) { $plugin = plugin_load($type, $this->base); if ($plugin) break; } @@ -907,12 +907,12 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { // check to make sure we aren't overwriting anything $target = $target_base_dir.$item['base']; - if(!$overwrite && @file_exists($target)) { + if(!$overwrite && file_exists($target)) { // TODO remember our settings, ask the user to confirm overwrite continue; } - $action = @file_exists($target) ? 'update' : 'install'; + $action = file_exists($target) ? 'update' : 'install'; // copy action if($this->dircopy($item['tmp'], $target)) { @@ -1117,7 +1117,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { return $ok; } else { - $exists = @file_exists($dst); + $exists = file_exists($dst); if(!@copy($src, $dst)) return false; if(!$exists && !empty($conf['fperm'])) chmod($dst, $conf['fperm']); -- cgit v1.2.3 From 605f8e8d0e501057749c50581087ce05089c1af3 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 15 May 2015 15:17:39 +0200 Subject: added composer setup and the first composer package php-archive --- lib/plugins/extension/helper/extension.php | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'lib/plugins/extension/helper/extension.php') diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index 6c0946b09..d089245b5 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -1035,33 +1035,24 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { $ext = $this->guess_archive($file); if(in_array($ext, array('tar', 'bz', 'gz'))) { - switch($ext) { - case 'bz': - $compress_type = Tar::COMPRESS_BZIP; - break; - case 'gz': - $compress_type = Tar::COMPRESS_GZIP; - break; - default: - $compress_type = Tar::COMPRESS_NONE; - } - $tar = new Tar(); try { - $tar->open($file, $compress_type); + $tar = new \splitbrain\PHPArchive\Tar(); + $tar->open($file); $tar->extract($target); - } catch (Exception $e) { + } catch (\splitbrain\PHPArchive\ArchiveIOException $e) { throw new Exception($this->getLang('error_decompress').' '.$e->getMessage()); } return true; } elseif($ext == 'zip') { - $zip = new ZipLib(); - $ok = $zip->Extract($file, $target); - - if($ok == -1){ - throw new Exception($this->getLang('error_decompress').' Error extracting the zip archive'); + try { + $zip = new \splitbrain\PHPArchive\Zip(); + $zip->open($file); + $zip->extract($target); + } catch (\splitbrain\PHPArchive\ArchiveIOException $e) { + throw new Exception($this->getLang('error_decompress').' '.$e->getMessage()); } return true; -- cgit v1.2.3 From 18f4ec973d8b711f6687adb71ce03e77e5ab1f41 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 25 May 2015 10:41:49 +0200 Subject: fixed isBundled() check when remote info is unavailable --- lib/plugins/extension/helper/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/plugins/extension/helper/extension.php') diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index d089245b5..719249fbe 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -105,7 +105,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { */ public function isBundled() { if (!empty($this->remoteInfo['bundled'])) return $this->remoteInfo['bundled']; - return in_array($this->base, + return in_array($this->id, array( 'authad', 'authldap', 'authmysql', 'authpgsql', 'authplain', 'acl', 'info', 'extension', 'revert', 'popularity', 'config', 'safefnrecode', 'testing', 'template:dokuwiki' -- cgit v1.2.3 From 1afa9ba84a2a44f66944dfc754dd8b8662c987fb Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 16 Jul 2015 22:14:13 +0200 Subject: remove deleted files on update of extension Resolves #1192 `/lib/plugins//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 ``` --- lib/plugins/extension/helper/extension.php | 41 +++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'lib/plugins/extension/helper/extension.php') diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index 719249fbe..7d723490e 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: -- cgit v1.2.3 From b28801bc7f36b024f1051c1e7afd9be8a4c5171e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 18 Jul 2015 12:51:25 +0200 Subject: added plugin to list of bundled extensions --- lib/plugins/extension/helper/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/plugins/extension/helper/extension.php') diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php index 719249fbe..c23840805 100644 --- a/lib/plugins/extension/helper/extension.php +++ b/lib/plugins/extension/helper/extension.php @@ -108,7 +108,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin { return in_array($this->id, array( 'authad', 'authldap', 'authmysql', 'authpgsql', 'authplain', 'acl', 'info', 'extension', - 'revert', 'popularity', 'config', 'safefnrecode', 'testing', 'template:dokuwiki' + 'revert', 'popularity', 'config', 'safefnrecode', 'styling', 'testing', 'template:dokuwiki' ) ); } -- cgit v1.2.3