Skip to content

Commit

Permalink
Delete operation fixed
Browse files Browse the repository at this point in the history
Delete operation fixed
  • Loading branch information
spanjeta committed Apr 15, 2015
1 parent b121f38 commit c1fd82e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
65 changes: 27 additions & 38 deletions controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use yii\web\Controller;
use spanjeta\modules\backup\models\UploadForm;
use yii\data\ArrayDataProvider;
use yii\web\HttpException;

class DefaultController extends Controller
{
Expand Down Expand Up @@ -219,17 +220,19 @@ public function actionClean($redirect = true)
Yii::$app->session->setFlash('success', $message);
return $this->redirect(array('index'));
}
public function actionDelete($file = null)
public function actionDelete($id)
{
$list = $this->getFileList();
$file = $list[$id];
$this->updateMenuItems();
if ( isset($file))
{
$sqlFile = $this->path . basename($file);
if ( file_exists($sqlFile))
unlink($sqlFile);
}
else throw new CHttpException(404, Yii::t('app', 'File not found'));
$this->actionIndex();
else throw new HttpException(404, Yii::t('app', 'File not found'));
return $this->actionIndex();
}

public function actionDownload($file = null)
Expand All @@ -244,61 +247,47 @@ public function actionDownload($file = null)
$request->sendFile(basename($sqlFile),file_get_contents($sqlFile));
}
}
throw new CHttpException(404, Yii::t('app', 'File not found'));
throw new HttpException(404, Yii::t('app', 'File not found'));
}

protected function getFileList()
{
$path = $this->path;
$dataArray = array();
$list = array();
$list_files = glob($path .'*.sql');
if ($list_files )
{
$list = array_map('basename',$list_files);
sort($list);
}
return $list;
}
public function actionIndex()
{
//$this->layout = 'column1';
$this->updateMenuItems();
$path = $this->path;
$dataArray = array();

$list_files = glob($path .'*.sql');
if ($list_files )
{
$list = array_map('basename',$list_files);
sort($list);

$list = $this->getFileList();
foreach ( $list as $id=>$filename )
{
$columns = array();
$columns['id'] = $id;
$columns['name'] = basename ( $filename);
$columns['size'] = filesize ( $path. $filename);
$columns['size'] = filesize ( $this->path. $filename);

$columns['create_time'] = date( 'Y-m-d H:i:s', filectime($path .$filename) );
$columns['modified_time'] = date( 'Y-m-d H:i:s', filemtime($path .$filename) );
$columns['create_time'] = date( 'Y-m-d H:i:s', filectime($this->path .$filename) );
$columns['modified_time'] = date( 'Y-m-d H:i:s', filemtime($this->path .$filename) );

$dataArray[] = $columns;
}
}

$dataProvider = new ArrayDataProvider(['allModels'=>$dataArray]);
return $this->render('index', array(
'dataProvider' => $dataProvider,
));
}
public function actionSyncdown()
{
$tables = $this->getTables();

if(!$this->StartBackup())
{
//render error
return $this->render('index');

}

foreach($tables as $tableName)
{
$this->getColumns($tableName);
}
foreach($tables as $tableName)
{
$this->getData($tableName);
}
$this->EndBackup();
return $this->actionDownload(basename($this->file_name));
}

public function actionRestore($file = null)
{
Expand Down Expand Up @@ -357,7 +346,7 @@ protected function updateMenuItems($model = null)
$this->menu[] = array('label'=>Yii::t('app', 'List Backup') , 'url'=>array('index'));
$this->menu[] = array('label'=>Yii::t('app', 'Create Backup') , 'url'=>array('create'));
$this->menu[] = array('label'=>Yii::t('app', 'Upload Backup') , 'url'=>array('upload'));
$this->menu[] = array('label'=>Yii::t('app', 'Restore Backup') , 'url'=>array('restore'));
// $this->menu[] = array('label'=>Yii::t('app', 'Restore Backup') , 'url'=>array('restore'));
$this->menu[] = array('label'=>Yii::t('app', 'Clean Database') , 'url'=>array('clean'));
$this->menu[] = array('label'=>Yii::t('app', 'View Site') , 'url'=>Yii::$app->HomeUrl);
}
Expand Down
4 changes: 3 additions & 1 deletion views/default/restore.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
use yii\helpers\Html;

$this->params ['breadcrumbs'] [] = [
'label' => 'Manage',
'url' => array (
Expand Down Expand Up @@ -26,5 +28,5 @@
<?php if(isset($error)) echo $error; else echo 'Done';?>
</p>
<p>
<?php echo CHtml::link('View Site',Yii::app()->HomeUrl)?>
<?php echo Html::link('View Site',Yii::app()->HomeUrl)?>
</p>

0 comments on commit c1fd82e

Please sign in to comment.