diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Phorkie/Repository.php | 17 | ||||
| -rw-r--r-- | src/Phorkie/Tools.php | 26 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/Phorkie/Repository.php b/src/Phorkie/Repository.php index d9fc234..bcaf3e1 100644 --- a/src/Phorkie/Repository.php +++ b/src/Phorkie/Repository.php @@ -102,6 +102,17 @@ class Repository return true; } + /** + * Permanently deletes the paste repository without any way to get + * it back. + * + * @return boolean True if all went well, false if not + */ + public function delete() + { + return Tools::recursiveDelete($this->repoDir); + } + public function getDescription() { if (!is_readable($this->repoDir . '/.git/description')) { @@ -133,8 +144,12 @@ class Repository return '/' . $this->id; } else if ($type == 'fork') { return '/' . $this->id . '/fork'; + } else if ($type == 'delete') { + return '/' . $this->id . '/delete'; + } else if ($type == 'delete-confirm') { + return '/' . $this->id . '/delete/confirm'; } - throw new Exception('Unknown type'); + throw new Exception('Unknown link type'); } } diff --git a/src/Phorkie/Tools.php b/src/Phorkie/Tools.php new file mode 100644 index 0000000..8e67fe2 --- /dev/null +++ b/src/Phorkie/Tools.php @@ -0,0 +1,26 @@ +<?php +namespace Phorkie; + + +class Tools +{ + public static function recursiveDelete($path) + { + if (!is_dir($path) || is_link($path)) { + return unlink($path); + } + foreach (scandir($path) as $file) { + if ($file == '.' || $file == '..') { + continue; + } + $filepath = $path . DIRECTORY_SEPARATOR . $file; + if (!static::recursiveDelete($filepath)) { + return false; + }; + } + return rmdir($path); + } + +} + +?>
\ No newline at end of file |
