Mercurial > hg > extraction-interface
comparison develop/models/extractapp.php @ 27:4a29bccb6c59
modify the SmartRegexSave method to prevent duplicated records in topic_regex_relation table and provide better promting to user to force saving regex file or not
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Tue, 03 Mar 2015 11:47:41 +0100 |
| parents | 579f03f8bee5 |
| children | e6e9bdc4f256 |
comparison
equal
deleted
inserted
replaced
| 26:579f03f8bee5 | 27:4a29bccb6c59 |
|---|---|
| 194 | 194 |
| 195 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, | 195 $data['info'] = array('file_id'=>$this->file_id, 'user_id'=>$this->user_id, |
| 196 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, | 196 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, |
| 197 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, | 197 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, |
| 198 'current_fileId'=>$this->current_fileId); | 198 'current_fileId'=>$this->current_fileId); |
| 199 | 199 |
| 200 $data['messages'] = $this->messages; | 200 $data['messages'] = $this->messages; |
| 201 | 201 |
| 202 return $data; | 202 return $data; |
| 203 | 203 |
| 204 } | 204 } |
| 375 } | 375 } |
| 376 | 376 |
| 377 | 377 |
| 378 public function SmartRegexSave($_postdata) { | 378 public function SmartRegexSave($_postdata) { |
| 379 if ($_postdata['text']){ | 379 if ($_postdata['text']){ |
| 380 | |
| 381 // --- update topic_regex_relation table --- | |
| 382 $topic_id = $_postdata['topic_id']; | |
| 383 $filename = $_postdata['filename'].'.txt'; | |
| 384 | |
| 385 // check if already existing a record for this regex file | |
| 386 $query = "SELECT * FROM topic_regex_relation WHERE topic_id=".$topic_id." AND regex_filename='".$filename."'"; | |
| 387 $result = mysql_query($query); | |
| 388 if (!$result) { | |
| 389 echo json_encode("ErrorDB"); | |
| 390 } | |
| 391 while ($row = mysql_fetch_assoc($result)) { | |
| 392 if ($row && !$_postdata['forcesave']) { | |
| 393 // promt user a comfirm to force saving or not | |
| 394 echo json_encode("ForceSave"); | |
| 395 return; | |
| 396 } | |
| 397 } | |
| 398 | |
| 399 | |
| 400 if (!$_postdata['forcesave']) { | |
| 401 $query = "INSERT INTO topic_regex_relation (topic_id, regex_filename) VALUES (".$topic_id.",'".$filename."')"; | |
| 402 $result = mysql_query($query); | |
| 403 if (!$result) { | |
| 404 echo json_encode("ErrorDB"); | |
| 405 } | |
| 406 } | |
| 407 // --- write to filesystem --- | |
| 408 | |
| 380 /* | 409 /* |
| 381 $date = date('Y_m_d_H_i_s', time()); | 410 $date = date('Y_m_d_H_i_s', time()); |
| 382 if ( file_exists("regex_files/".$_POST['filename'].".txt") ) { | 411 if ( file_exists("regex_files/".$_POST['filename'].".txt") ) { |
| 383 $oldFile = file_get_contents("regex_files/".$_POST['filename'].".txt"); | 412 $oldFile = file_get_contents("regex_files/".$_POST['filename'].".txt"); |
| 384 file_put_contents("regex_files/".$_POST['filename']."_".$date.".txt", $oldFile); | 413 file_put_contents("regex_files/".$_POST['filename']."_".$date.".txt", $oldFile); |
| 392 $require = $_postdata['text']; | 421 $require = $_postdata['text']; |
| 393 } | 422 } |
| 394 | 423 |
| 395 file_put_contents( $data_path."regex_files/".$_postdata['filename'].".txt", $require); | 424 file_put_contents( $data_path."regex_files/".$_postdata['filename'].".txt", $require); |
| 396 | 425 |
| 397 // update topic_regex_relation table | |
| 398 $topic_id = $_postdata['topic_id']; | |
| 399 $filename = $_postdata['filename'].'.txt'; | |
| 400 $query = "INSERT INTO topic_regex_relation (topic_id, regex_filename) VALUES (".$topic_id.",'".$filename."')"; | |
| 401 $result = mysql_query($query); | |
| 402 if (!$result) { | |
| 403 echo json_encode("error"); | |
| 404 } | |
| 405 | 426 |
| 406 } | 427 } |
| 407 } | 428 } |
| 408 | 429 |
| 409 | 430 |
