mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 02:27:34 -07:00
Перенос классов в файлы
Классы работы с базой данных, кеша, датастора переносим в отдельные файлы. Обычный require, но надо добавить require только при выбранности данного вида кеширования.
This commit is contained in:
parent
66455f879d
commit
80c99e7c8e
20 changed files with 1734 additions and 1652 deletions
66
library/includes/datastore/sqlite.php
Normal file
66
library/includes/datastore/sqlite.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
class datastore_sqlite extends datastore_common
|
||||
{
|
||||
var $engine = 'SQLite';
|
||||
var $db = null;
|
||||
var $prefix = null;
|
||||
var $cfg = array(
|
||||
'db_file_path' => '/path/to/datastore.db.sqlite',
|
||||
'table_name' => 'datastore',
|
||||
'table_schema' => 'CREATE TABLE datastore (
|
||||
ds_title VARCHAR(255),
|
||||
ds_data TEXT,
|
||||
PRIMARY KEY (ds_title)
|
||||
)',
|
||||
'pconnect' => true,
|
||||
'con_required' => true,
|
||||
'log_name' => 'DATASTORE',
|
||||
);
|
||||
|
||||
function datastore_sqlite ($cfg, $prefix = null)
|
||||
{
|
||||
$this->cfg = array_merge($this->cfg, $cfg);
|
||||
$this->db = new sqlite_common($this->cfg);
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
function store ($item_name, $item_data)
|
||||
{
|
||||
$this->data[$item_name] = $item_data;
|
||||
|
||||
$ds_title = sqlite_escape_string($this->prefix . $item_name);
|
||||
$ds_data = sqlite_escape_string(serialize($item_data));
|
||||
|
||||
$result = $this->db->query("REPLACE INTO ". $this->cfg['table_name'] ." (ds_title, ds_data) VALUES ('$ds_title', '$ds_data')");
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
function clean ()
|
||||
{
|
||||
$this->db->query("DELETE FROM ". $this->cfg['table_name']);
|
||||
}
|
||||
|
||||
function _fetch_from_store ()
|
||||
{
|
||||
if (!$items = $this->queued_items) return;
|
||||
|
||||
$prefix_len = strlen($this->prefix);
|
||||
$prefix_sql = sqlite_escape_string($this->prefix);
|
||||
|
||||
array_deep($items, 'sqlite_escape_string');
|
||||
$items_list = $prefix_sql . join("','$prefix_sql", $items);
|
||||
|
||||
$rowset = $this->db->fetch_rowset("SELECT ds_title, ds_data FROM ". $this->cfg['table_name'] ." WHERE ds_title IN ('$items_list')");
|
||||
|
||||
$this->db->debug('start', "unserialize()");
|
||||
foreach ($rowset as $row)
|
||||
{
|
||||
$this->data[substr($row['ds_title'], $prefix_len)] = unserialize($row['ds_data']);
|
||||
}
|
||||
$this->db->debug('stop');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue