From 6a797015cb1ff056e0b1313f23b9efbd995ef23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 6 Jul 2014 15:45:52 +0200 Subject: [PATCH] Delete Descriptions when deleting program (+ more) --- .idea/workspace.xml | 441 +++++++++--------- www/css/styles.css | 2 + www/protected/components/MsHelper.php | 18 + www/protected/controllers/LogController.php | 9 +- .../controllers/ProgramsController.php | 15 +- www/protected/models/Program.php | 4 + www/protected/views/programs/_form.php | 35 +- 7 files changed, 282 insertions(+), 242 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d990ae7..a265cdc 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,11 +4,11 @@ - - - + + + @@ -63,48 +63,28 @@ - - + + - + - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - + @@ -123,8 +103,6 @@ @@ -270,6 +250,20 @@ + + + + + + + + + + @@ -368,6 +362,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - @@ -573,11 +575,11 @@ + - @@ -646,10 +648,10 @@ - - - - + + + + @@ -718,7 +720,7 @@ - + @@ -726,12 +728,12 @@ - + - + @@ -759,31 +761,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - @@ -823,26 +800,11 @@ - - - - - - - - - - - - - - - @@ -880,11 +842,6 @@ - - - - - @@ -900,16 +857,9 @@ - - - - - - - - + @@ -921,152 +871,191 @@ - - - - - - - - - - + - - - + - - - + - - - + - - - + - - - + - - - - - - - - - - - - - - - - - - - - + - - - + - - - + - - - - - - - - - - + - - - + - - - - + + - + - - - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/www/css/styles.css b/www/css/styles.css index 13e3951..7a425bf 100644 --- a/www/css/styles.css +++ b/www/css/styles.css @@ -14,6 +14,8 @@ body { #fullbodywrapper { min-height:100%; position:relative; + + padding-bottom: 120px; } .footer { diff --git a/www/protected/components/MsHelper.php b/www/protected/components/MsHelper.php index cc5a6eb..86c866e 100644 --- a/www/protected/components/MsHelper.php +++ b/www/protected/components/MsHelper.php @@ -36,4 +36,22 @@ class MsHelper { return (substr($haystack, -$length) === $needle); } + + public static function deleteDir($dirPath) { + if (! is_dir($dirPath)) { + throw new InvalidArgumentException("$dirPath must be a directory"); + } + if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { + $dirPath .= '/'; + } + $files = glob($dirPath . '*', GLOB_MARK); + foreach ($files as $file) { + if (is_dir($file)) { + self::deleteDir($file); + } else { + unlink($file); + } + } + rmdir($dirPath); + } } \ No newline at end of file diff --git a/www/protected/controllers/LogController.php b/www/protected/controllers/LogController.php index 07c350a..85e9935 100644 --- a/www/protected/controllers/LogController.php +++ b/www/protected/controllers/LogController.php @@ -13,7 +13,6 @@ class LogController extends MsController { return array( 'accessControl', // perform access control for CRUD operations - 'postOnly + delete', // we only allow deletion via POST request ); } @@ -137,7 +136,7 @@ class LogController extends MsController */ public function actionDelete($id) { - if (Yii::app()->request->isPostRequest) { +// if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $this->loadModel($id)->delete(); @@ -145,9 +144,9 @@ class LogController extends MsController if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } - } else { - throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); - } +// } else { +// throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); +// } } /** diff --git a/www/protected/controllers/ProgramsController.php b/www/protected/controllers/ProgramsController.php index c18da37..4a78119 100644 --- a/www/protected/controllers/ProgramsController.php +++ b/www/protected/controllers/ProgramsController.php @@ -16,7 +16,6 @@ class ProgramsController extends MSController { return array( 'accessControl', // perform access control for CRUD operations - 'postOnly + delete', // we only allow deletion via POST request ); } @@ -128,17 +127,21 @@ class ProgramsController extends MSController */ public function actionDelete($id) { - if (Yii::app()->request->isPostRequest) { +// if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request - $this->loadModelByID($id)->delete(); + + $model = $this->loadModelByID($id); + + $model->deleteDescriptions(); + $model->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } - } else { - throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); - } +// } else { +// throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); +// } } /** diff --git a/www/protected/models/Program.php b/www/protected/models/Program.php index b09b8cd..6f8659f 100644 --- a/www/protected/models/Program.php +++ b/www/protected/models/Program.php @@ -246,4 +246,8 @@ class Program extends CActiveRecord return $result; } + + public function deleteDescriptions() { + MsHelper::deleteDir("data/programs/desc/" . $this->Name . "/"); + } } diff --git a/www/protected/views/programs/_form.php b/www/protected/views/programs/_form.php index 36c2f5e..f2e7cd2 100644 --- a/www/protected/views/programs/_form.php +++ b/www/protected/views/programs/_form.php @@ -23,15 +23,30 @@ textFieldControlGroup($model,'Thumbnailname',array('rows'=>6,'span'=>8)); ?> - textFieldControlGroup($model,'Downloads',array('span'=>5)); ?> + isNewRecord) + echo $form->textFieldControlGroup($model,'Downloads',array('span'=>5, 'value' => '0')); + else + echo $form->textFieldControlGroup($model,'Downloads',array('span'=>5, )); + ?> textFieldControlGroup($model,'Kategorie',array('rows'=>6,'span'=>8)); ?> textFieldControlGroup($model,'Sterne',array('span'=>5)); ?> - textFieldControlGroup($model,'enabled',array('span'=>5)); ?> + isNewRecord) + echo $form->textFieldControlGroup($model,'enabled',array('span'=>5, 'value' => '0')); + else + echo $form->textFieldControlGroup($model,'enabled',array('span'=>5, )); + ?> - textFieldControlGroup($model,'visible',array('span'=>5)); ?> + isNewRecord) + echo $form->textFieldControlGroup($model,'visible',array('span'=>5, 'value' => '0')); + else + echo $form->textFieldControlGroup($model,'visible',array('span'=>5, )); + ?> textFieldControlGroup($model,'Language',array('rows'=>6,'span'=>8)); ?> @@ -39,7 +54,12 @@ textFieldControlGroup($model,'programming_lang',array('rows'=>6,'span'=>8)); ?> - textFieldControlGroup($model,'add_date',array('span'=>5)); ?> + isNewRecord) + echo $form->textFieldControlGroup($model,'add_date',array('span'=>5, 'value' => date('Y-m-d'))); + else + echo $form->textFieldControlGroup($model,'add_date',array('span'=>5, )); + ?> textFieldControlGroup($model,'download_url',array('rows'=>6,'span'=>8)); ?> @@ -49,7 +69,12 @@ textFieldControlGroup($model,'github_url',array('rows'=>6,'span'=>8)); ?> - textFieldControlGroup($model,'uses_absCanv',array('span'=>5)); ?> + isNewRecord) + echo $form->textFieldControlGroup($model,'uses_absCanv',array('span'=>5, 'value' => date('Y-m-d'))); + else + echo $form->textFieldControlGroup($model,'uses_absCanv',array('span'=>5, )); + ?> textFieldControlGroup($model,'update_identifier',array('span'=>5,'maxlength'=>28)); ?>