diff --git a/backend/controllers/BookController.php b/backend/controllers/BookController.php index d86d711..e67c239 100644 --- a/backend/controllers/BookController.php +++ b/backend/controllers/BookController.php @@ -103,4 +103,25 @@ throw new NotFoundHttpException('The requested page does not exist.'); } } + + public function actionDelete($id) + { + if (file_exists(\Yii::getAlias('@storage/books/') . $id)) { + $this->removeDirectory(\Yii::getAlias('@storage/books/') . $id); + } + $this->findModel($id) + ->delete(); + + return $this->redirect([ 'index' ]); + } + + public static function removeDirectory($dir) + { + if ($objs = glob($dir . "/*")) { + foreach ($objs as $obj) { + is_dir($obj) ? self::removeDirectory($obj) : unlink($obj); + } + } + rmdir($dir); + } } \ No newline at end of file -- libgit2 0.21.4