public function actionAjaxImport()
 {
     @ini_set("max_execution_time", 18000);
     try {
         $timeStart = time();
         $fileId = Yii::app()->request->getParam('fileId', 0);
         $log = new KLogger('LOG_IMPORT_FILE_SONG_PNV', KLogger::INFO);
         $log->LogInfo("Start Ajax Import", false);
         $model = new AdminImportSongModel();
         $result = ImportSongModel::getSongsAll($fileId);
         $totalRow = count($result);
         //echo '<pre>';print_r($result);die();
         $path = Yii::app()->params['importsong']['store_path'];
         $is_error = 0;
         $imported = array();
         $notImport = array();
         $data = "";
         $success = 0;
         if ($totalRow > 0) {
             $song = $result[0];
             $log->LogInfo("Start import | " . CJSON::encode($song), false);
             $status = 0;
             $insert_id = $model->importSong($song, $path);
             $insert_id = !$insert_id ? -1 : $insert_id;
             // save inserted id to a string, for updating Updated_time column when finish
             if ($insert_id > 0 && !in_array($insert_id, array(2, 3, 4))) {
                 $this->updateTime($insert_id, $song['updated_time']);
                 $imported = array('stt' => $song['stt'], 'name' => $song['name'], 'path' => $song['path'], 'songId' => $insert_id);
                 $this->updateSongImportSource($song['id'], 1, 0, 'Success', $insert_id, $timeStart);
             } else {
                 $errorDesc = array(-1 => 'File không tồn tại', 2 => 'Không save được vào song', 3 => 'Hết quyền upload bài hát', 4 => 'File mp3 trống');
                 $this->updateSongImportSource($song['id'], 2, $insert_id, $errorDesc[$insert_id], 0, $timeStart);
                 $is_error = 1;
                 $notImport = array('stt' => $song['stt'], 'name' => $song['name'], 'path' => $song['path'], 'errorDesc' => $errorDesc[$insert_id]);
                 //$log->LogInfo('Not import > (' . $song['stt'] . ')' . $song['path'] . $song['file'], false);
             }
             $data = $this->renderPartial('ajaxResultRow', array('imported' => $imported, 'notImport' => $notImport), true, true);
         } else {
             //completed
             $success = 1;
             $log->LogError("Error | " . CJSON::encode($result), false);
         }
         $dataJson = array('is_error' => $is_error, 'success' => $success, 'data' => $data);
         echo CJSON::encode($dataJson);
         Yii::app()->end();
     } catch (Exception $e) {
         $log->LogError("actionAjaxImport | Exception Error: " . $e->getMessage(), false);
         $dataJson = array('is_error' => 1, 'success' => 0, 'data' => "actionAjaxImport | Exception Error: " . $e->getMessage());
         echo CJSON::encode($dataJson);
         Yii::app()->end();
     }
     exit;
 }
 public function actionCheckSong()
 {
     @ini_set("max_execution_time", 180000);
     $completed = $error = 0;
     $data = time();
     $fileId = Yii::app()->request->getParam('fileId', 0);
     $result = ImportSongModel::getSongsAll($fileId);
     if ($result) {
         $song = $result[0];
         $check = $this->isExistsSong($song['name'], $song['album']);
         $status = !$check ? 2 : 1;
         $check = !$check ? 0 : $check;
         $this->updateSongImportSource($song['id'], $check, $status);
     } else {
         $completed = 1;
     }
     $data = $this->getPerCompleted($fileId);
     $dataJson = array('error' => $error, 'completed' => $completed, 'data' => $data . '%');
     echo CJSON::encode($dataJson);
     Yii::app()->end();
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         $deletedFile = $this->loadModel($id)->delete();
         if ($deletedFile) {
             ImportSongModel::model()->deleteAll("file_id=:fileId", array(':fileId' => $id));
         }
         // 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('index'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }