Changeset 17862


Ignore:
Timestamp:
Sep 11, 2012, 3:27:24 PM (8 years ago)
Author:
grum
Message:

version 0.1.0b
. fix bug on thumb view
. fix SQLite compression managment & 'compress.method' config
. manage number of items per page by config

Location:
extensions/EStat
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/EStat/admin/estat_admin.tpl

    r17758 r17862  
    107107          url:'{$plugin.urlRequest}',
    108108          urlExport:'{$plugin.urlRequestExport}',
    109           token:'{$plugin.token}'
     109          token:'{$plugin.token}',
     110          itemPerPage:{$plugin.itemPerPage}
    110111          {literal}
    111112        }
  • extensions/EStat/estat_aip.class.inc.php

    r17737 r17862  
    107107      'urlRequest' => $this->getAdminLink('ajax'),
    108108      'urlRequestExport' => $this->getAdminLink('ajaxExport'),
    109       'token' => get_pwg_token()
     109      'token' => get_pwg_token(),
     110      'itemPerPage' => $this->config['global.itemPerPage']
    110111    );
    111112
     
    116117
    117118
    118     $this->checkBuildStatPeriod(true);
     119    $this->checkBuildStatPeriod(true, $this->config['compress.method']=='gz');
    119120  }
    120121
  • extensions/EStat/estat_ajax.php

    r17760 r17862  
    443443        $monthStatFile->close();
    444444
    445         // if imported data are from a previous period, pack it
    446         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);
    450450        }
    451451      }
  • extensions/EStat/estat_pip.class.inc.php

    r17737 r17862  
    6868      }
    6969
    70       $this->checkBuildStatPeriod(false, $this->config['compress.public']=='y');
     70      $this->checkBuildStatPeriod(false, ($this->config['compress.public']=='y' and $this->config['compress.method']=='gz'));
    7171    }
    7272    return($do_log);
  • extensions/EStat/estat_root.class.inc.php

    r17758 r17862  
    107107        'build.end' => '6:30:00',        // build.start hour to build.end hour
    108108        'compress.public' => 'n',        // compress file in public session
    109         'compress.method' => 'none',     // none, gz
    110 
    111         'global.itemPerPage' => 250,
     109        'compress.method' => 'gz',     // none, gz
     110
     111        'global.itemPerPage' => 150,
    112112
    113113        'export.csv.separator' => $csvExport['export.csv.separator'],
  • extensions/EStat/js/estatPM.js

    r17758 r17862  
    2828        urlExport:'',
    2929        token:'',
     30        itemPerPage:50,
    3031        currentPage:'Stats_by_period',
    3132        initPhase:false,
     
    170171          properties.token=values.token;
    171172
     173        if(values.itemPerPage)
     174          properties.itemPerPage=values.itemPerPage;
     175
    172176        if(values.currentPage)
    173177          properties.currentPage=values.currentPage;
     
    338342            minHeight:350,
    339343            maxHeight:350,
     344            nbItemsPage:properties.itemPerPage,
    340345            footerString:
    341346              {
     
    662667            minHeight:350,
    663668            maxHeight:350,
     669            nbItemsPage:properties.itemPerPage,
    664670            sortBoxTitle:translateString.sortBy,
    665671            footerString:
     
    936942            minHeight:350,
    937943            maxHeight:350,
     944            nbItemsPage:properties.itemPerPage,
    938945            sortBoxTitle:translateString.sortBy,
    939946            footerString:
     
    10471054                                {
    10481055                                  displayPopupThumb(false);
    1049 
    10501056                                }
    10511057                            );
     
    11071113            minHeight:350,
    11081114            maxHeight:350,
     1115            nbItemsPage:properties.itemPerPage,
    11091116            sortBoxTitle:translateString.sortBy,
    11101117            footerString:
     
    12181225                                {
    12191226                                  displayPopupThumb(false);
    1220 
    12211227                                }
    12221228                            );
     
    13901396            minHeight:150,
    13911397            maxHeight:350,
     1398            nbItemsPage:properties.itemPerPage,
    13921399            sortBoxTitle:translateString.sortBy,
    13931400            footerString:
     
    14981505                                {
    14991506                                  displayPopupThumb(false);
    1500 
    15011507                                }
    15021508                            );
     
    27462752          url='';
    27472753        }
    2748 
    27492754        if(visible)
    27502755        {
    27512756          $('#iPopupThumb')
     2757            .unbind('load')
    27522758            .bind('load', {geometry:geometry}, function (e)
    27532759                    {
     
    27652771        else
    27662772        {
    2767           $('#iPopupThumb').css('display', 'none');
     2773          $('#iPopupThumb').unbind('load').css('display', 'none');
    27682774        }
    27692775      },
  • extensions/EStat/lib/statDB.class.inc.php

    r17760 r17862  
    99define('ASDF_EXIST_PACKED',   0x01);
    1010define('ASDF_EXIST_UNPACKED', 0x02);
     11define('ASDF_EXIST_LOCK',     0x04);
    1112define('ASDF_EXIST_ALL', ASDF_EXIST_PACKED|ASDF_EXIST_UNPACKED);
    1213
    1314define('ASDF_FILE_EXT', '.db');
    1415define('ASDF_FILE_EXT_ZIP', ASDF_FILE_EXT.'.gz');
     16define('ASDF_FILE_EXT_LOCK', '.lock');
    1517define('ASDF_FILE_ROOT_MONTH', 'M');
    1618define('ASDF_FILE_ROOT_GLOBAL', 'G');
     
    5557  protected $transacOpen=false;
    5658  protected $ipCountryFile='';
    57 
     59  protected $lckFileNumber=0;
     60  //protected $logs=''; for debug
    5861  private $deleteUnpackedWhenClose=ASDF_CLOSE_DO_NOTHING;
    5962
     
    218221   * if $mode=ASDF_OPEN_WRITE and file doesn't exist, create it; if a packed file
    219222   * 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
    221224   *
    222225   * if $mode=ASDF_OPEN_READ, and unpacked file doesn't exist, try to unpack
    223226   * 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
    225229   *
    226230   * @param Integer $mode: READ or WRITE
     
    230234  {
    231235    $dbFile=$this->getFileName(ASDF_EXIST_UNPACKED, true);
     236    $this->createLockFile();
     237    $this->waitForUnpackedFile();
    232238
    233239    /*
     
    252258        $this->deleteUnpackedWhenClose=ASDF_CLOSE_DO_DELETE; // the unpacked file will be deleted when the process will close
    253259      }
     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;
    254265    }
    255266
     
    293304      }
    294305
    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())
    296309      {
    297310        $this->delete(ASDF_DELETE_UNPACKED);
     
    330343    if($this->fileExist() & ASDF_EXIST_PACKED==ASDF_EXIST_PACKED)
    331344    {
    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
    343359      return($returned);
    344360    }
     
    422438      case ASDF_EXIST_UNPACKED:
    423439        $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;
    424443        break;
    425444    }
     
    517536    if($returned==null) $returned=$value;
    518537    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);
    519679  }
    520680
     
    11901350
    11911351
    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
    11931371
    11941372
     
    12131391
    12141392
    1215 
    12161393?>
  • extensions/EStat/lib/statDBGlobal.class.inc.php

    r17758 r17862  
    240240    if($packed!='')
    241241    {
     242      // packed file was unpacked, pack file only if file was already packed
    242243      if($fmPeriod->pack())
    243         $fmPeriod->delete(ASDF_DELETE_UNPACKED); //packed file was unpacked, keep only packed file
     244        $fmPeriod->delete(ASDF_DELETE_UNPACKED);
    244245    }
    245246    return($returned);
Note: See TracChangeset for help on using the changeset viewer.