mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Remove last vestiges of PDO accomodation
This commit is contained in:
parent
f19f683e38
commit
337b2cf90c
5 changed files with 10 additions and 19 deletions
|
@ -22,8 +22,8 @@ class Database {
|
||||||
|
|
||||||
public function __construct(RuntimeData $data) {
|
public function __construct(RuntimeData $data) {
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$this->driver = $data->conf->dbDriver;
|
$this->driver = $driver = $data->conf->dbDriver;
|
||||||
$this->db = $this->driver::create($data, INSTALL);
|
$this->db = new $driver($data, INSTALL);
|
||||||
$ver = $this->db->schemaVersion();
|
$ver = $this->db->schemaVersion();
|
||||||
if(!INSTALL && $ver < self::SCHEMA_VERSION) {
|
if(!INSTALL && $ver < self::SCHEMA_VERSION) {
|
||||||
$this->db->update(self::SCHEMA_VERSION);
|
$this->db->update(self::SCHEMA_VERSION);
|
||||||
|
@ -298,6 +298,7 @@ class Database {
|
||||||
(new PicoFeed\Reader\Favicon)->find($url),
|
(new PicoFeed\Reader\Favicon)->find($url),
|
||||||
$feed->siteUrl,
|
$feed->siteUrl,
|
||||||
// Convert the date formats to SQL date format before inserting.
|
// Convert the date formats to SQL date format before inserting.
|
||||||
|
// FIXME: Dates should be formatted transparently by the driver's Statement wrapper, not here
|
||||||
$this->driver::formatDate($feed->date),
|
$this->driver::formatDate($feed->date),
|
||||||
$this->driver::formatDate($resource->getLastModified()),
|
$this->driver::formatDate($resource->getLastModified()),
|
||||||
$resource->getEtag(),
|
$resource->getEtag(),
|
||||||
|
|
|
@ -3,8 +3,7 @@ declare(strict_types=1);
|
||||||
namespace JKingWeb\NewsSync\Db;
|
namespace JKingWeb\NewsSync\Db;
|
||||||
|
|
||||||
interface Driver {
|
interface Driver {
|
||||||
// returns an instance of a class implementing this interface. Implemented as a static method so that classes may return their PDO equivalents instead of themselves
|
function __construct(\JKingWeb\NewsSync\RuntimeData $data, bool $install = false);
|
||||||
static function create(\JKingWeb\NewsSync\RuntimeData $data, bool $install = false): Driver;
|
|
||||||
// returns a human-friendly name for the driver (for display in installer, for example)
|
// returns a human-friendly name for the driver (for display in installer, for example)
|
||||||
static function driverName(): string;
|
static function driverName(): string;
|
||||||
// returns the version of the scheme of the opened database; if uninitialized should return 0
|
// returns the version of the scheme of the opened database; if uninitialized should return 0
|
||||||
|
|
|
@ -9,6 +9,8 @@ class DriverSQLite3 implements Driver {
|
||||||
protected $data;
|
protected $data;
|
||||||
|
|
||||||
private function __construct(\JKingWeb\NewsSync\RuntimeData $data, bool $install = false) {
|
private function __construct(\JKingWeb\NewsSync\RuntimeData $data, bool $install = false) {
|
||||||
|
// check to make sure required extension is loaded
|
||||||
|
if(!class_exists("SQLite3")) throw new Exception("extMissing", self::driverName());
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$file = $data->conf->dbSQLite3File;
|
$file = $data->conf->dbSQLite3File;
|
||||||
// if the file exists (or we're initializing the database), try to open it and set initial options
|
// if the file exists (or we're initializing the database), try to open it and set initial options
|
||||||
|
@ -32,21 +34,10 @@ class DriverSQLite3 implements Driver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct() {
|
public function __destruct() {
|
||||||
$this->db->close();
|
try{$this->db->close();} catch(\Exception $e) {}
|
||||||
unset($this->db);
|
unset($this->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function create(\JKingWeb\NewsSync\RuntimeData $data, bool $install = false): Driver {
|
|
||||||
// check to make sure required extensions are loaded
|
|
||||||
if(class_exists("SQLite3")) {
|
|
||||||
return new self($data, $install);
|
|
||||||
} else if(class_exists("PDO") && in_array("sqlite",\PDO::getAvailableDrivers())) {
|
|
||||||
return new DriverSQLite3PDO($data, $install);
|
|
||||||
} else {
|
|
||||||
throw new Exception("extMissing", self::driverName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static public function driverName(): string {
|
static public function driverName(): string {
|
||||||
return "SQLite 3";
|
return "SQLite 3";
|
||||||
|
|
|
@ -28,7 +28,7 @@ class User {
|
||||||
public function __construct(\JKingWeb\NewsSync\RuntimeData $data) {
|
public function __construct(\JKingWeb\NewsSync\RuntimeData $data) {
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$driver = $data->conf->userDriver;
|
$driver = $data->conf->userDriver;
|
||||||
$this->u = $driver::create($data);
|
$this->u = new $driver($data);
|
||||||
$this->authzSupported = $this->u->driverFunctions("authorize");
|
$this->authzSupported = $this->u->driverFunctions("authorize");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ Interface Driver {
|
||||||
const RIGHTS_GLOBAL_ADMIN = 100; // is completely unrestricted
|
const RIGHTS_GLOBAL_ADMIN = 100; // is completely unrestricted
|
||||||
|
|
||||||
// returns an instance of a class implementing this interface. Implemented as a static method for consistency with database classes
|
// returns an instance of a class implementing this interface. Implemented as a static method for consistency with database classes
|
||||||
static function create(\JKingWeb\NewsSync\RuntimeData $data): Driver;
|
function __construct(\JKingWeb\NewsSync\RuntimeData $data);
|
||||||
// returns a human-friendly name for the driver (for display in installer, for example)
|
// returns a human-friendly name for the driver (for display in installer, for example)
|
||||||
static function driverName(): string;
|
static function driverName(): string;
|
||||||
// returns an array (or single queried member of same) of methods defined by this interface and whether the class implements the internal function or a custom version
|
// returns an array (or single queried member of same) of methods defined by this interface and whether the class implements the internal function or a custom version
|
||||||
|
|
Loading…
Reference in a new issue