File: Freezer.php

package info (click to toggle)
dojo 1.10.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 97,980 kB
  • ctags: 10,348
  • sloc: php: 10,616; xml: 3,429; java: 3,098; sql: 928; sh: 484; pascal: 205; perl: 182; makefile: 77; python: 45; sed: 37; ruby: 10
file content (47 lines) | stat: -rw-r--r-- 1,401 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

require_once('lib/generator/common/db.php');

final class Freezer
{
  private $namespace = '';

  public static function clean($directory, $namespace) {
    db_query("TRUNCATE freezer");
  }

  function __construct($directory, $namespace) {
    $this->namespace = $namespace;
  }

  public function ids($flush = TRUE) {
    $ids = array();

    $query = db_query("SELECT id FROM freezer WHERE namespace = '%s'", $this->namespace);
    while ($row = db_fetch_assoc($query)) {
      $ids[] = $row['id'];
    }

    return $ids;
  }

  public function open($key, $default) {
    $query = db_query("SELECT value FROM freezer WHERE namespace = '%s' AND id = '%s' AND BINARY id = '%s'", $this->namespace, $key, $key);
    if ($row = db_fetch_assoc($query)) {
      return unserialize($row['value']);
    }
    return $default;
  }

  public function save($key, $content) {
    $content = mysql_escape_string(serialize($content));

    $query = db_query("SELECT 1 FROM freezer WHERE namespace = '%s' AND id = '%s' AND BINARY id = '%s'", $this->namespace, $key, $key);
    if (db_fetch_assoc($query)) {
      db_query("UPDATE freezer SET value = '%s' WHERE namespace = '%s' AND id = '%s' AND BINARY id = '%s'", $content, $this->namespace, $key, $key);
    }
    else {
      db_query("INSERT INTO freezer (namespace, id, value) VALUES ('%s', '%s', '%s')", $this->namespace, $key, $content);
    }
  }
}