]>
git.wh0rd.org - tt-rss.git/blob - classes/dbupdater.php
8 function __construct($pdo, $db_type, $need_version) {
9 $this->pdo
= Db
::pdo(); //$pdo;
10 $this->db_type
= $db_type;
11 $this->need_version
= (int) $need_version;
14 function getSchemaVersion() {
15 $row = $this->pdo
->query("SELECT schema_version FROM ttrss_version")->fetch();
16 return (int) $row['schema_version'];
19 function isUpdateRequired() {
20 return $this->getSchemaVersion() < $this->need_version
;
23 function getSchemaLines($version) {
24 $filename = "schema/versions/".$this->db_type
."/$version.sql";
26 if (file_exists($filename)) {
27 return explode(";", preg_replace("/[\r\n]/", "", file_get_contents($filename)));
29 user_error("DB Updater: schema file for version $version is not found.");
34 function performUpdateTo($version, $html_output = true) {
35 if ($this->getSchemaVersion() == $version - 1) {
37 $lines = $this->getSchemaLines($version);
39 if (is_array($lines)) {
41 $this->pdo
->beginTransaction();
43 foreach ($lines as $line) {
44 if (strpos($line, "--") !== 0 && $line) {
45 if (!$this->pdo
->query($line)) {
47 print_notice("Query: $line");
48 print_error("Error: " . implode(", ", $this->pdo
->errorInfo()));
50 _debug("Query: $line");
51 _debug("Error: " . implode(", ", $this->pdo
->errorInfo()));
59 $db_version = $this->getSchemaVersion();
61 if ($db_version == $version) {
65 $this->pdo
->rollBack();