]>
git.wh0rd.org - tt-rss.git/blob - classes/dbupdater.php
5 private $
$this->dbh
->type
;
8 function __construct($dbh, $
$this->dbh
->type
, $need_version) {
10 $this->$this->dbh
->type
= $db_type;
11 $this->need_version
= (int) $need_version;
14 function getSchemaVersion() {
15 $result = $this->dbh
->query("SELECT schema_version FROM ttrss_version");
16 return (int) $this->dbh
->fetch_result($result, 0, "schema_version");
19 function isUpdateRequired() {
20 return $this->getSchemaVersion() < $this->need_version
;
23 function getSchemaLines($version) {
24 $filename = "schema/versions/".$this->$this->dbh
->type
."/$version.sql";
26 if (file_exists($filename)) {
27 return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename)));
33 function performUpdateTo($version) {
34 if ($this->getSchemaVersion() == $version - 1) {
36 $lines = $this->getSchemaLines($version);
38 if (is_array($lines)) {
40 $this->dbh
->query("BEGIN");
42 foreach ($lines as $line) {
43 if (strpos($line, "--") !== 0 && $line) {
44 $this->dbh
->query($line);
48 $
$this->dbh
->version
= $this->getSchemaVersion();
50 if ($
$this->dbh
->version
== $version) {
51 $this->dbh
->query("COMMIT");
54 $this->dbh
->query("ROLLBACK");