Ejemplo n.º 1
0
 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;
 }