]> git.wh0rd.org - tt-rss.git/commitdiff
xml import/export tools, UPGRADING, update README
authorAndrew Dolgov <fox@madoka.spb.ru>
Wed, 30 Nov 2005 08:05:43 +0000 (09:05 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Wed, 30 Nov 2005 08:05:43 +0000 (09:05 +0100)
NEWS
README
UPGRADING [new file with mode: 0644]
xml-export.php [new file with mode: 0644]
xml-import.php [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1a527c336b507d234a6ea1c8aa9dc564bb890a37..01d1a89d52b4348dade541dbe1e22cac10e71c7c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,6 @@
 v1.1           (Dec xy, 2005)
 
-       Note: there is no update path from 1.0.7, the schema is just too
-       different. Sorry about that.
+       ! Please read UPGRADING for upgrade instructions from version 1.0.7 !
 
        * Multi-user support (yay!)
        * Per-feed purge preferences (0 means default, negative numbers disable purging)
diff --git a/README b/README
index 55ce000e67aab70f3355da64bcbd8b2d8373ed6f..01bb0d26b180b277b6e4544ff30dabbadd062301 100644 (file)
--- a/README
+++ b/README
@@ -1,6 +1,8 @@
 Tiny Tiny RSS
 =============
 
+! Please read UPGRADING for upgrade instructions from version 1.0.7 !
+
 Web-based news feed aggregator, designed to allow you to read news from 
 any location, while feeling as close to a real desktop application as possible.
 
diff --git a/UPGRADING b/UPGRADING
new file mode 100644 (file)
index 0000000..968acf6
--- /dev/null
+++ b/UPGRADING
@@ -0,0 +1,19 @@
+= Upgrading from TT-RSS 1.0.7 =
+
+There is, unfortunately, no direct database schema upgrade script. Starred articles
+and feed subscriptions may be transferred the following way:
+
+== 1.0.7 ==
+
+ * Export your feed subscriptions to OPML
+ * Copy xml-export.php from TT-RSS 1.1 tarball to your 1.0.7 directory and run it. This script exports your starred articles in neutral XML format.
+ * Save resulting XML file somewhere
+
+Unpack and configure TT-RSS 1.1. You may need to remove old tables manualy 
+(or choose the different database, etc.)
+
+== 1.1 ==
+
+ * Import your feeds OPML
+ * Run xml-import.php and import your old starred articles
+
diff --git a/xml-export.php b/xml-export.php
new file mode 100644 (file)
index 0000000..13ab65b
--- /dev/null
@@ -0,0 +1,82 @@
+<?
+       /*
+               Exports your starred articles in schema-neutral XML format.
+       */
+
+       require_once "config.php";
+       require_once "functions.php";
+       require_once "db.php";
+
+       define('SCHEMA_VERSION', 1);
+       
+       header("Content-Type: application/xml");
+?>
+
+<xmldb>
+
+<?
+       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
+
+       if (!$link) {
+               if (DB_TYPE == "mysql") {
+                       print mysql_error();
+               }
+               // PG seems to display its own errors just fine by default.             
+               return;
+       }
+
+       if (DB_TYPE == "pgsql") {
+               pg_query("set client_encoding = 'utf-8'");
+       }
+
+       $result = db_query($link, "SELECT schema_version FROM ttrss_version");
+
+       $schema_version = db_fetch_result($result, 0, "schema_version");
+
+       if ($schema_version != SCHEMA_VERSION) {
+               print "Error: database schema is invalid
+                       (got version $schema_version; expected ".SCHEMA_VERSION.")";
+               return;
+       }
+
+       print "<schema_version>$schema_version</schema_version>";
+
+?>
+
+<articles>
+
+<?
+       $result = db_query($link, "SELECT
+                       ttrss_entries.title AS title,
+                       content,
+                       marked,
+                       unread,
+                       updated,
+                       guid,
+                       link,
+                       date_entered,
+                       last_read,
+                       comments,
+                       ttrss_feeds.feed_url AS feed_url,
+                       ttrss_feeds.title AS feed_title
+               FROM 
+                       ttrss_entries,ttrss_feeds
+               WHERE
+                       feed_id = ttrss_feeds.id AND marked = true");
+
+
+       while ($line = db_fetch_assoc($result)) {
+               print "<article>";
+
+               foreach (array_keys($line) as $key) {
+                       print "<$key><![CDATA[".$line[$key]."]]></$key>";
+
+               }
+
+               print "</article>";
+       }
+
+?>
+</articles>
+
+</xmldb>
diff --git a/xml-import.php b/xml-import.php
new file mode 100644 (file)
index 0000000..aacdd60
--- /dev/null
@@ -0,0 +1,184 @@
+<?
+       require_once "config.php";
+       require_once "functions.php";
+       require_once "db.php";
+
+       define('SOURCE_SCHEMA_VERSION', 1);
+       define('TARGET_SCHEMA_VERSION', 2);
+
+       $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
+
+       login_sequence($link);
+
+       if (!$link) {
+               if (DB_TYPE == "mysql") {
+                       print mysql_error();
+               }
+               // PG seems to display its own errors just fine by default.             
+               return;
+       }
+
+       if (DB_TYPE == "pgsql") {
+               pg_query("set client_encoding = 'utf-8'");
+       }
+
+       $result = db_query($link, "SELECT schema_version FROM ttrss_version");
+
+       $schema_version = db_fetch_result($result, 0, "schema_version");
+
+       if ($schema_version != TARGET_SCHEMA_VERSION) {
+               print "Error: database schema is invalid
+                       (got version $schema_version; expected ".TARGET_SCHEMA_VERSION.")";
+               return;
+       }
+
+       function import_article($link, $data) {
+
+               print "Processing article " . $data["title"] . "<br>";
+
+               $owner_uid = $_SESSION["uid"];
+
+               db_query($link, "BEGIN");
+
+               $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE feed_url = '".
+                       $data["feed_url"] . "' AND owner_uid = '$owner_uid'");
+
+               if (db_num_rows($result) == 0) {
+                       return false;
+               }
+
+               $feed_id = db_fetch_result($result, 0, "id");           
+
+               $result = db_query($link, "SELECT id FROM ttrss_entries WHERE
+                       guid = '".$data["guid"]."'");
+
+               if (db_num_rows($result) == 0) {
+
+                       print "Not found, adding base entry...<br>";
+
+                       $entry_title = $data["title"];
+                       $entry_guid = $data["guid"];
+                       $entry_link = $data["link"];
+                       $updated = $data["updated"];
+                       $date_entered = $data["date_entered"];
+                       $entry_content = $data["content"];
+                       $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
+                       $entry_comments = $data["comments"];
+
+                       $result = db_query($link,
+                               "INSERT INTO ttrss_entries 
+                                       (title,
+                                       guid,
+                                       link,
+                                       updated,
+                                       content,
+                                       content_hash,
+                                       no_orig_date,
+                                       date_entered,
+                                       comments)
+                               VALUES
+                                       ('$entry_title', 
+                                       '$entry_guid', 
+                                       '$entry_link',
+                                       '$updated', 
+                                       '$entry_content', 
+                                       '$content_hash',
+                                       false, 
+                                       '$date_entered', 
+                                       '$entry_comments')");
+               }
+
+               $result = db_query($link, "SELECT id FROM ttrss_entries WHERE
+                       guid = '".$data["guid"]."'");
+
+               if (db_num_rows($result) == 0) { return false; }
+
+               $entry_id = db_fetch_result($result, 0, "id");
+
+               print "Found base ID: $entry_id<br>";
+
+               $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE
+                       ref_id = '$entry_id'");
+
+               if (db_num_rows($result) == 0) {
+                       print "User table entry not found, creating...<br>";
+
+                       $unread = $data["unread"];
+                       $marked = $data["marked"];
+                       $last_read = $data["last_read"];
+
+                       if (!$last_read) {
+                               $last_read_qpart = 'NULL';
+                       } else {
+                               $last_read_qpart = "'$last_read'";
+                       }
+
+                       $result = db_query($link,
+                               "INSERT INTO ttrss_user_entries 
+                                       (ref_id, owner_uid, feed_id, unread, marked, last_read) 
+                               VALUES ('$entry_id', '$owner_uid', '$feed_id', '$unread', '$marked',
+                                       $last_read_qpart)");
+
+               } else {
+                       print "User table entry already exists, nothing to do.<br>";
+               }
+
+               db_query($link, "COMMIT");
+
+       }
+
+?>
+<html>
+<body>
+
+       <? if ($_REQUEST["op"] != "Import") { ?>
+
+       <h1>Import XMLDB (your login is <?= $_SESSION["login"] ?>)</h1>
+
+       <form   enctype="multipart/form-data" method="POST" action="xml-import.php">
+       File: <input name="xmldb" type="file">&nbsp;
+       <input class="button" name="op" type="submit" value="Import">
+       </form>
+
+       <? } else {
+
+               print "<h1>Importing data (your login is ".$_SESSION["name"].")</h1>";
+
+               if (is_file($_FILES['xmldb']['tmp_name'])) {
+                       $dom = domxml_open_file($_FILES['xmldb']['tmp_name']);
+//                     $dom = domxml_open_file('xmldb.xml');
+
+                       if ($dom) {
+                               $root = $dom->document_element();
+
+                               $schema_version = $root->get_elements_by_tagname('schema_version');
+                               $schema_version = $schema_version[0]->get_content();
+
+                               if ($schema_version != SOURCE_SCHEMA_VERSION) {
+                                       die("Incorrect source schema version");
+                               }
+
+                               $articles = $root->get_elements_by_tagname("article");
+
+                               foreach ($articles as $article) {
+                                       $child_nodes = $article->child_nodes();
+
+                                       $article_data = array();
+
+                                       foreach ($child_nodes as $child) {
+                                               $article_data[$child->tagname()] = $child->get_content();
+                                       }
+
+                                       import_article($link, $article_data);
+                               }
+                       } else {
+                               print "Error: could not parse document.";
+                       }
+               } else {
+                       print "<p>Error: please upload XMLDB.</p>";
+               }
+
+       } ?>
+</body>
+</html>
+