/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to classes/cache/cachedb.php

  • Committer: Suren A. Chilingaryan
  • Date: 2018-07-12 03:28:35 UTC
  • Revision ID: csa@suren.me-20180712032835-a2hzd4gadlgoiokj
Log newly created cache tables and provide service to get this information

Show diffs side-by-side

added added

removed removed

Lines of Context:
759
759
        throw new ADEIException(translate("Unlucky, the MD5 checksums of two groups (\"%s\" and \"%s\") are coinciding. This is not handled automaticaly yet. Please, add/alter md5 suffix to the newly added group.", $row[0], $postfix));
760
760
 }
761
761
 
 
762
 function CacheLogCreateTable() {
 
763
    if (!@mysql_query("CREATE TABLE IF NOT EXISTS `cachelog`(
 
764
                        `id` INT NOT NULL AUTO_INCREMENT,
 
765
                        `time` DATETIME,
 
766
                        `postfix` VARCHAR(4096) NOT NULL,
 
767
                        `resolution` INT,
 
768
                        `action` CHAR(64),
 
769
                        `ack` INT,
 
770
                        PRIMARY KEY (`id`),
 
771
                        INDEX (`time`)
 
772
                    )", $this->dbh)) {
 
773
        throw new ADEIException(translate("Creation of system tables (cachelog) within CACHE database is failed") . " (" . mysql_error($this->dbh) . ")");
 
774
    }
 
775
 }
 
776
 
 
777
 function CacheLogAdd($action, $postfix, $resolution) {
 
778
    if (!$postfix) $postfix = $this->default_postfix;
 
779
    $time = $this->SQLTime(time());
 
780
 
 
781
    $query = "INSERT INTO `cachelog` VALUES(NULL, '{$time}', '" . mysql_real_escape_string($postfix) . "', $resolution, '$action', 0)";
 
782
    if (!@mysql_query($query, $this->dbh)) {
 
783
        switch (mysql_errno($this->dbh)) {
 
784
            case CACHE::MYSQL_ER_NO_SUCH_TABLE:
 
785
                $this->CacheLogCreateTable();
 
786
                if (@mysql_query($query, $this->dbh))
 
787
                    break;
 
788
            default:
 
789
                throw new ADEIException(translate("Error logging info on %s:%s to CacheLog, error",  $postfix, $resolution) . ": " . mysql_error($this->dbh));
 
790
        }
 
791
    }
 
792
 }
 
793
 
 
794
 
 
795
 function CacheLogGet($filters = false) {
 
796
    $archive = false;
 
797
        
 
798
    if ($filters) {
 
799
        $where = "";
 
800
        if (isset($filters['archive'])) {
 
801
            $archive = $filters['archive'];
 
802
            unset($filters['archive']);
 
803
        }
 
804
        
 
805
        if (isset($filters['interval'])) {
 
806
            $from = $this->SQLTime($filters['interval'][0]);
 
807
            $to = $this->SQLTime($filters['interval'][1]);
 
808
            $where .= " `time` BETWEEN  $from AND $to";
 
809
            unset($filters['interval']);
 
810
        }
 
811
        
 
812
        foreach ($filters as $flt => $val) {
 
813
            if ($where) $where .= " AND ";
 
814
            if ($flt == "id")
 
815
                $where .= "`$flt` >= \"$val\"";
 
816
            else
 
817
                $where .= "`$flt` = \"$val\"";
 
818
        }
 
819
    }
 
820
    
 
821
    $query = "SELECT * FROM `cachelog`";
 
822
    if ($where) $query .= " WHERE $where";
 
823
    $res = @mysql_query($query, $this->dbh);
 
824
    if (!$res) {
 
825
        switch (mysql_errno($this->dbh)) {
 
826
            case CACHE::MYSQL_ER_NO_SUCH_TABLE:
 
827
                return array();
 
828
            default:
 
829
                throw new ADEIException(translate("Error querying CacheLog, error: %s, query: %s", mysql_error($this->dbh), $query));
 
830
        }
 
831
    }
 
832
    
 
833
    $list = array();
 
834
    while ($item = mysql_fetch_array($res, MYSQL_ASSOC)) {
 
835
        $info = $this->ParsePostfix($item['postfix']);
 
836
        foreach ($info as $key => $val) {
 
837
            $item[$key] = $val;
 
838
        }
 
839
        if ($archive !== false) {
 
840
            if (preg_match("/_\d{4,8}$/", $item['db_name'])) {
 
841
                if (!$archive) continue;
 
842
            } else {
 
843
                if ($archive) continue;
 
844
            }
 
845
        }
 
846
        array_push($list, $item);
 
847
    }
 
848
    
 
849
    return $list;
 
850
 }
 
851
 
 
852
 
762
853
 function GetPostfixType($db_group = false, $db_name = false, $db_server = false) {
763
854
        if ((!$db_server)||(!$db_name)||(!$db_group)) {
764
855
            if ($db_server === false) $db_server = $this->default_db_server;
1022
1113
    if ($ADEI_DELAYED_KEYS) {
1023
1114
        mysql_query("ALTER TABLE `$name` DELAY_KEY_WRITE = 1;");
1024
1115
    }
 
1116
 
 
1117
    $this->CacheLogAdd("create", $postfix, $resolution);
1025
1118
 }
1026
1119
 
1027
1120
 function Query($query) {