Delete Descriptions when deleting program (+ more)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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.');
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.');
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -246,4 +246,8 @@ class Program extends CActiveRecord
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function deleteDescriptions() {
|
||||
MsHelper::deleteDir("data/programs/desc/" . $this->Name . "/");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,30 @@
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'Thumbnailname',array('rows'=>6,'span'=>8)); ?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'Downloads',array('span'=>5)); ?>
|
||||
<?php
|
||||
if ($model->isNewRecord)
|
||||
echo $form->textFieldControlGroup($model,'Downloads',array('span'=>5, 'value' => '0'));
|
||||
else
|
||||
echo $form->textFieldControlGroup($model,'Downloads',array('span'=>5, ));
|
||||
?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'Kategorie',array('rows'=>6,'span'=>8)); ?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'Sterne',array('span'=>5)); ?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'enabled',array('span'=>5)); ?>
|
||||
<?php
|
||||
if ($model->isNewRecord)
|
||||
echo $form->textFieldControlGroup($model,'enabled',array('span'=>5, 'value' => '0'));
|
||||
else
|
||||
echo $form->textFieldControlGroup($model,'enabled',array('span'=>5, ));
|
||||
?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'visible',array('span'=>5)); ?>
|
||||
<?php
|
||||
if ($model->isNewRecord)
|
||||
echo $form->textFieldControlGroup($model,'visible',array('span'=>5, 'value' => '0'));
|
||||
else
|
||||
echo $form->textFieldControlGroup($model,'visible',array('span'=>5, ));
|
||||
?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'Language',array('rows'=>6,'span'=>8)); ?>
|
||||
|
||||
@@ -39,7 +54,12 @@
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'programming_lang',array('rows'=>6,'span'=>8)); ?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'add_date',array('span'=>5)); ?>
|
||||
<?php
|
||||
if ($model->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, ));
|
||||
?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'download_url',array('rows'=>6,'span'=>8)); ?>
|
||||
|
||||
@@ -49,7 +69,12 @@
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'github_url',array('rows'=>6,'span'=>8)); ?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'uses_absCanv',array('span'=>5)); ?>
|
||||
<?php
|
||||
if ($model->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, ));
|
||||
?>
|
||||
|
||||
<?php echo $form->textFieldControlGroup($model,'update_identifier',array('span'=>5,'maxlength'=>28)); ?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user