Changeset 17862
- Timestamp:
- Sep 11, 2012, 3:27:24 PM (12 years ago)
- Location:
- extensions/EStat
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/EStat/admin/estat_admin.tpl
r17758 r17862 107 107 url:'{$plugin.urlRequest}', 108 108 urlExport:'{$plugin.urlRequestExport}', 109 token:'{$plugin.token}' 109 token:'{$plugin.token}', 110 itemPerPage:{$plugin.itemPerPage} 110 111 {literal} 111 112 } -
extensions/EStat/estat_aip.class.inc.php
r17737 r17862 107 107 'urlRequest' => $this->getAdminLink('ajax'), 108 108 'urlRequestExport' => $this->getAdminLink('ajaxExport'), 109 'token' => get_pwg_token() 109 'token' => get_pwg_token(), 110 'itemPerPage' => $this->config['global.itemPerPage'] 110 111 ); 111 112 … … 116 117 117 118 118 $this->checkBuildStatPeriod(true );119 $this->checkBuildStatPeriod(true, $this->config['compress.method']=='gz'); 119 120 } 120 121 -
extensions/EStat/estat_ajax.php
r17760 r17862 443 443 $monthStatFile->close(); 444 444 445 // if imported data are from a previous period , pack it446 if($nbLogs<self::MAX_LOAD_LOG and $period!=date('Y-m') )447 { 448 /*if($monthStatFile->pack()===true)449 $monthStatFile->delete(ASDF_DELETE_UNPACKED); */445 // if imported data are from a previous period and compression method is set, pack it 446 if($nbLogs<self::MAX_LOAD_LOG and $period!=date('Y-m') and $this->config['compress.method']=='gz') 447 { 448 if($monthStatFile->pack()===true) 449 $monthStatFile->delete(ASDF_DELETE_UNPACKED); 450 450 } 451 451 } -
extensions/EStat/estat_pip.class.inc.php
r17737 r17862 68 68 } 69 69 70 $this->checkBuildStatPeriod(false, $this->config['compress.public']=='y');70 $this->checkBuildStatPeriod(false, ($this->config['compress.public']=='y' and $this->config['compress.method']=='gz')); 71 71 } 72 72 return($do_log); -
extensions/EStat/estat_root.class.inc.php
r17758 r17862 107 107 'build.end' => '6:30:00', // build.start hour to build.end hour 108 108 'compress.public' => 'n', // compress file in public session 109 'compress.method' => ' none', // none, gz110 111 'global.itemPerPage' => 250,109 'compress.method' => 'gz', // none, gz 110 111 'global.itemPerPage' => 150, 112 112 113 113 'export.csv.separator' => $csvExport['export.csv.separator'], -
extensions/EStat/js/estatPM.js
r17758 r17862 28 28 urlExport:'', 29 29 token:'', 30 itemPerPage:50, 30 31 currentPage:'Stats_by_period', 31 32 initPhase:false, … … 170 171 properties.token=values.token; 171 172 173 if(values.itemPerPage) 174 properties.itemPerPage=values.itemPerPage; 175 172 176 if(values.currentPage) 173 177 properties.currentPage=values.currentPage; … … 338 342 minHeight:350, 339 343 maxHeight:350, 344 nbItemsPage:properties.itemPerPage, 340 345 footerString: 341 346 { … … 662 667 minHeight:350, 663 668 maxHeight:350, 669 nbItemsPage:properties.itemPerPage, 664 670 sortBoxTitle:translateString.sortBy, 665 671 footerString: … … 936 942 minHeight:350, 937 943 maxHeight:350, 944 nbItemsPage:properties.itemPerPage, 938 945 sortBoxTitle:translateString.sortBy, 939 946 footerString: … … 1047 1054 { 1048 1055 displayPopupThumb(false); 1049 1050 1056 } 1051 1057 ); … … 1107 1113 minHeight:350, 1108 1114 maxHeight:350, 1115 nbItemsPage:properties.itemPerPage, 1109 1116 sortBoxTitle:translateString.sortBy, 1110 1117 footerString: … … 1218 1225 { 1219 1226 displayPopupThumb(false); 1220 1221 1227 } 1222 1228 ); … … 1390 1396 minHeight:150, 1391 1397 maxHeight:350, 1398 nbItemsPage:properties.itemPerPage, 1392 1399 sortBoxTitle:translateString.sortBy, 1393 1400 footerString: … … 1498 1505 { 1499 1506 displayPopupThumb(false); 1500 1501 1507 } 1502 1508 ); … … 2746 2752 url=''; 2747 2753 } 2748 2749 2754 if(visible) 2750 2755 { 2751 2756 $('#iPopupThumb') 2757 .unbind('load') 2752 2758 .bind('load', {geometry:geometry}, function (e) 2753 2759 { … … 2765 2771 else 2766 2772 { 2767 $('#iPopupThumb'). css('display', 'none');2773 $('#iPopupThumb').unbind('load').css('display', 'none'); 2768 2774 } 2769 2775 }, -
extensions/EStat/lib/statDB.class.inc.php
r17760 r17862 9 9 define('ASDF_EXIST_PACKED', 0x01); 10 10 define('ASDF_EXIST_UNPACKED', 0x02); 11 define('ASDF_EXIST_LOCK', 0x04); 11 12 define('ASDF_EXIST_ALL', ASDF_EXIST_PACKED|ASDF_EXIST_UNPACKED); 12 13 13 14 define('ASDF_FILE_EXT', '.db'); 14 15 define('ASDF_FILE_EXT_ZIP', ASDF_FILE_EXT.'.gz'); 16 define('ASDF_FILE_EXT_LOCK', '.lock'); 15 17 define('ASDF_FILE_ROOT_MONTH', 'M'); 16 18 define('ASDF_FILE_ROOT_GLOBAL', 'G'); … … 55 57 protected $transacOpen=false; 56 58 protected $ipCountryFile=''; 57 59 protected $lckFileNumber=0; 60 //protected $logs=''; for debug 58 61 private $deleteUnpackedWhenClose=ASDF_CLOSE_DO_NOTHING; 59 62 … … 218 221 * if $mode=ASDF_OPEN_WRITE and file doesn't exist, create it; if a packed file 219 222 * exist, try to unpack the packed file; in this case the unpacked file will be 220 * packed and removed automatically when the process will close .223 * packed and removed automatically when the process will close 221 224 * 222 225 * if $mode=ASDF_OPEN_READ, and unpacked file doesn't exist, try to unpack 223 226 * packed file (if exists); in this case the unpacked file will be removed 224 * automatically when the process will close. 227 * automatically when the process will close (if there's no lock 228 * files linked to the uncompressed file); a new lock file is created 225 229 * 226 230 * @param Integer $mode: READ or WRITE … … 230 234 { 231 235 $dbFile=$this->getFileName(ASDF_EXIST_UNPACKED, true); 236 $this->createLockFile(); 237 $this->waitForUnpackedFile(); 232 238 233 239 /* … … 252 258 $this->deleteUnpackedWhenClose=ASDF_CLOSE_DO_DELETE; // the unpacked file will be deleted when the process will close 253 259 } 260 } 261 else 262 { 263 if($this->lckFileNumber>1 and $this->getFileName(ASDF_EXIST_PACKED, true)!='' and $mode==ASDF_OPEN_READ) 264 $this->deleteUnpackedWhenClose=ASDF_CLOSE_DO_DELETE; 254 265 } 255 266 … … 293 304 } 294 305 295 if(($this->deleteUnpackedWhenClose&ASDF_CLOSE_DO_DELETE)==ASDF_CLOSE_DO_DELETE) 306 $this->deleteLockFile(); 307 if(($this->deleteUnpackedWhenClose&ASDF_CLOSE_DO_DELETE)==ASDF_CLOSE_DO_DELETE and 308 !$this->fileIsLocked()) 296 309 { 297 310 $this->delete(ASDF_DELETE_UNPACKED); … … 330 343 if($this->fileExist() & ASDF_EXIST_PACKED==ASDF_EXIST_PACKED) 331 344 { 332 $returned=GPCCompress::gunzip($this->getFileName(ASDF_EXIST_PACKED), $this->getFileName(ASDF_EXIST_UNPACKED)); 333 /* 334 $dir=dirName(dirName($this->getFileName(ASDF_EXIST_UNPACKED))); 335 $tH=fopen($dir.'/logs.log', 'a'); 336 if($tH) 337 { 338 $dest=$this->getFileName(ASDF_EXIST_UNPACKED); 339 fwrite($tH, sprintf("%s - %30s - %10d - %s\n", date('Y-m-d H:i:s'), $dest, filesize($dest), $returned?'y':'n')); 340 fclose($tH); 341 } 342 */ 345 $unpackedFile=$this->getFileName(ASDF_EXIST_UNPACKED); 346 347 // create a temp file 348 $fHandle=fopen($unpackedFile, 'w'); 349 fclose($fHandle); 350 351 $returned=GPCCompress::gunzip($this->getFileName(ASDF_EXIST_PACKED), $unpackedFile.'.tmp'); 352 353 unlink($unpackedFile); 354 if($returned) 355 { 356 rename($unpackedFile.'.tmp', $unpackedFile); 357 } 358 343 359 return($returned); 344 360 } … … 422 438 case ASDF_EXIST_UNPACKED: 423 439 $fileName=$this->fileDir.$this->fileName.$this->fileRootName.ASDF_FILE_EXT; 440 break; 441 case ASDF_EXIST_LOCK: 442 $fileName=$this->fileDir.$this->fileName.$this->fileRootName.'-'.$this->lckFileNumber.ASDF_FILE_EXT_LOCK; 424 443 break; 425 444 } … … 517 536 if($returned==null) $returned=$value; 518 537 return($returned); 538 } 539 540 /** 541 * how the file lock system works: 542 * 543 * the lock system is used only when for uncompressed files, allowing to know 544 * if an uncompressed file can be deleted or not; locks function are called only 545 * in READ mode by function open() and close() 546 * 547 * createLockFile() 548 * 1/ Search for existing lock files 549 * 2/ If files are found, increase the $lckFileNumber with number of existing files + 1 550 * 3/ Create the lock file 551 * 552 * deleteLockFile() 553 * delete the lock file associated with the current $lckFileNumber 554 * 555 * fileIsLocked() 556 * return true if at least, one lock exists 557 * 558 * ...................................... 559 * ...................................... 560 * .............. 561 * -+-------+--------+------------+------+-------+--> 562 * (A) (B) (C) (D) (E) (F) 563 * ^ ^ ^ ^ ^ ^ 564 * p1 p2 p3 p3 p1 p2 565 * start start start end end end 566 * 567 * (A) process 1 start: createLockFile() => lock file '1' is created 568 * (B) process 2 start: createLockFile() => lock file '2' is created 569 * (C) process 3 start: createLockFile() => lock file '3' is created 570 * (D) process 3 end: deleteLockFile() => lock file '3' is deleted 571 * lock files '1' & '2' still exist (uncompressed SQLite file can't be deleted) 572 * (E) process 1 end: deleteLockFile() => lock file '1' is deleted 573 * lock file '2' still exist (uncompressed SQLite file can't be deleted) 574 * (F) process 2 end: deleteLockFile() => lock file '2' is deleted 575 * there's no lock files (uncompressed SQLite file can be deleted) 576 * 577 * @return Boolean: true if the lock file was created, otherwise false 578 */ 579 protected function createLockFile() 580 { 581 $this->lckFileNumber=$this->getNumberOfLockFiles()+1; 582 $fHandle=fopen($this->getFileName(ASDF_EXIST_LOCK), 'w'); 583 if($fHandle) 584 { 585 fclose($fHandle); 586 return(true); 587 } 588 $this->lckFileNumber=0; 589 return(false); 590 } 591 592 /** 593 * delete the current lock file 594 * return true if file is deleted (or file doesn't exists => there's no more file to delete...), otherwise return false 595 * 596 * the function also delete all lock files older than current timestamp+max_execution_time (if 597 * the file still exist, it means that a problem has occured at a moment) 598 * 599 * @return Boolean 600 */ 601 protected function deleteLockFile() 602 { 603 $returned=true; 604 $file=$this->getFileName(ASDF_EXIST_LOCK); 605 if(file_exists($file)) $returned=unlink($file); 606 607 if($returned) $this->lckFileNumber=0; 608 609 $regExp="/\\".ASDF_FILE_EXT_LOCK.'/i'; 610 scandir(dirName($this->fileDir)); 611 $files=scandir($this->fileDir); 612 $timeOut=time()-ini_get('max_execution_time'); 613 614 foreach($files as $file) 615 { 616 if(preg_match($regExp, $file, $result)>0) 617 { 618 if(filemtime($this->fileDir.$file)<$timeOut) 619 { 620 unlink($this->fileDir.$file); 621 } 622 } 623 } 624 625 626 627 return($returned); 628 } 629 630 /** 631 * return true if a lock file exists 632 * 633 * @return Boolean 634 */ 635 protected function fileIsLocked() 636 { 637 if($this->getNumberOfLockFiles()>0) return(true); 638 return(false); 639 } 640 641 /** 642 * return true the number of existing lock files 643 * 644 * @return Integer: number of existing lock files 645 */ 646 protected function getNumberOfLockFiles() 647 { 648 $returned=0; 649 $regExp='/'.$this->fileName.$this->fileRootName."-(\d+)\\".ASDF_FILE_EXT_LOCK.'/i'; 650 $files=scandir($this->fileDir); 651 foreach($files as $file) 652 { 653 if(preg_match($regExp, $file, $result)>0) 654 { 655 $tmp=$result[1]*1; 656 if($tmp>$returned) $returned=$tmp; 657 } 658 } 659 return($returned); 660 } 661 662 /** 663 * if the unpacked exist with a '.tmp' extension, assume that an unpacking process 664 * is running and loop until the file doesn't exist anymore 665 * 666 * @param Integer $maxWait: maximum wait time in millisecond... 667 * @return Boolean: true if file was unpacked in the waiting time, otherwise false 668 */ 669 protected function waitForUnpackedFile($maxWait=2000) 670 { 671 $tmpFile=$this->getFileName(ASDF_EXIST_UNPACKED).'.tmp'; 672 $maxTimer=microtime(true)+$maxWait/1000; 673 while(file_exists($tmpFile)) 674 { 675 if(microtime(true)>=$maxTimer) return(false); 676 usleep(5000); //wait 5milliseconds before next check 677 } 678 return(true); 519 679 } 520 680 … … 1190 1350 1191 1351 1192 } 1352 /* 1353 for debug 1354 1355 private function log($data) 1356 { 1357 if($this->logs=='') return(false); 1358 $tH=fopen(dirName($this->fileDir).'/logs.log', 'a'); 1359 if($tH) 1360 { 1361 $time=microtime(true); 1362 fwrite($tH, sprintf("%s %f - %s\n", $this->logs, $time, $data)); 1363 1364 fclose($tH); 1365 } 1366 } 1367 */ 1368 1369 1370 } // StatDB 1193 1371 1194 1372 … … 1213 1391 1214 1392 1215 1216 1393 ?> -
extensions/EStat/lib/statDBGlobal.class.inc.php
r17758 r17862 240 240 if($packed!='') 241 241 { 242 // packed file was unpacked, pack file only if file was already packed 242 243 if($fmPeriod->pack()) 243 $fmPeriod->delete(ASDF_DELETE_UNPACKED); //packed file was unpacked, keep only packed file244 $fmPeriod->delete(ASDF_DELETE_UNPACKED); 244 245 } 245 246 return($returned);
Note: See TracChangeset
for help on using the changeset viewer.