Example #1
0
    public function update($event, $value = null)
    {
        switch ($event) {
            case Render::CHUNK:
                $this->flags = $value;
                break;
            case Render::STANDALONE:
                if ($value) {
                    $this->registerElementMap(static::getDefaultElementMap());
                    $this->registerTextMap(static::getDefaultTextMap());
                    $this->registerPIHandlers($this->pihandlers);
                }
                break;
            case Render::INIT:
                if ($value) {
                    if (Config::memoryindex()) {
                        $db = new \SQLite3(":memory:");
                    } else {
                        $db = new \SQLite3(Config::output_dir() . 'index.sqlite');
                        $db->exec('DROP TABLE IF EXISTS ids');
                        $db->exec('DROP TABLE IF EXISTS indexing');
                        $db->exec('DROP TABLE IF EXISTS changelogs');
                    }
                    $create = <<<SQL
CREATE TABLE ids (
    docbook_id TEXT,
    filename TEXT,
    parent_id TEXT,
    sdesc TEXT,
    ldesc TEXT,
    element TEXT,
    previous TEXT,
    next TEXT,
    chunk INTEGER
);
CREATE TABLE changelogs (
    membership TEXT, -- How the extension in distributed (pecl, core, bundled with/out external dependencies..)
    docbook_id TEXT,
    parent_id TEXT,
    version TEXT,
    description TEXT
);
CREATE TABLE indexing (
    time INTEGER PRIMARY KEY
);
SQL;
                    $db->exec('PRAGMA default_synchronous=OFF');
                    $db->exec('PRAGMA count_changes=OFF');
                    $db->exec('PRAGMA cache_size=100000');
                    $db->exec($create);
                    if (Config::memoryindex()) {
                        Config::set_indexcache($db);
                    }
                    $this->db = $db;
                    $this->chunks = array();
                } else {
                    print_r($this->chunks);
                }
                break;
            case Render::FINALIZE:
                $retval = $this->db->exec("BEGIN TRANSACTION; INSERT INTO indexing (time) VALUES ('" . time() . "'); COMMIT");
                $this->commit();
                if ($this->db->lastErrorCode()) {
                    trigger_error($this->db->lastErrorMsg(), E_USER_WARNING);
                }
                break;
        }
    }