Revert "plugins/import_export: use PDO"
This reverts commit 785ffca622
.
This commit is contained in:
parent
e888879a42
commit
82152bdc34
1 changed files with 41 additions and 59 deletions
|
@ -4,7 +4,6 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
|
|
||||||
function init($host) {
|
function init($host) {
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
$this->pdo = Db::pdo();
|
|
||||||
|
|
||||||
$host->add_hook($host::HOOK_PREFS_TAB, $this);
|
$host->add_hook($host::HOOK_PREFS_TAB, $this);
|
||||||
$host->add_command("xml-import", "import articles from XML", $this, ":", "FILE");
|
$host->add_command("xml-import", "import articles from XML", $this, ":", "FILE");
|
||||||
|
@ -35,15 +34,14 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
|
|
||||||
_debug("importing $filename for user $username...\n");
|
_debug("importing $filename for user $username...\n");
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT id FROM ttrss_users WHERE login = ?");
|
$result = db_query("SELECT id FROM ttrss_users WHERE login = '$username'");
|
||||||
$sth->execute([$username]);
|
|
||||||
|
|
||||||
if ($sth->rowCount() == 0) {
|
if (db_num_rows($result) == 0) {
|
||||||
print "error: could not find user $username.\n";
|
print "error: could not find user $username.\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$owner_uid = $sth->fetchColumn(0);
|
$owner_uid = db_fetch_result($result, 0, "id");
|
||||||
|
|
||||||
$this->perform_data_import($filename, $owner_uid);
|
$this->perform_data_import($filename, $owner_uid);
|
||||||
}
|
}
|
||||||
|
@ -133,12 +131,12 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportrun() {
|
function exportrun() {
|
||||||
$offset = (int) $_REQUEST['offset'];
|
$offset = (int) db_escape_string($_REQUEST['offset']);
|
||||||
$exported = 0;
|
$exported = 0;
|
||||||
$limit = 250;
|
$limit = 250;
|
||||||
|
|
||||||
if ($offset < 10000 && is_writable(CACHE_DIR . "/export")) {
|
if ($offset < 10000 && is_writable(CACHE_DIR . "/export")) {
|
||||||
$sth = $this->pdo->prepare("SELECT
|
$result = db_query("SELECT
|
||||||
ttrss_entries.guid,
|
ttrss_entries.guid,
|
||||||
ttrss_entries.title,
|
ttrss_entries.title,
|
||||||
content,
|
content,
|
||||||
|
@ -158,9 +156,8 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
WHERE
|
WHERE
|
||||||
(marked = true OR feed_id IS NULL) AND
|
(marked = true OR feed_id IS NULL) AND
|
||||||
ref_id = ttrss_entries.id AND
|
ref_id = ttrss_entries.id AND
|
||||||
ttrss_user_entries.owner_uid = ?
|
ttrss_user_entries.owner_uid = " . $_SESSION['uid'] . "
|
||||||
ORDER BY ttrss_entries.id LIMIT ? OFFSET ?");
|
ORDER BY ttrss_entries.id LIMIT $limit OFFSET $offset");
|
||||||
$sth->execute([$_SESSION['uid'], $limit, $offset]);
|
|
||||||
|
|
||||||
$exportname = sha1($_SESSION['uid'] . $_SESSION['login']);
|
$exportname = sha1($_SESSION['uid'] . $_SESSION['login']);
|
||||||
|
|
||||||
|
@ -173,7 +170,7 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
|
|
||||||
if ($fp) {
|
if ($fp) {
|
||||||
|
|
||||||
while ($line = $sth->fetch(PDO::FETCH_ASSOC)) {
|
while ($line = db_fetch_assoc($result)) {
|
||||||
fputs($fp, "<article>");
|
fputs($fp, "<article>");
|
||||||
|
|
||||||
foreach ($line as $k => $v) {
|
foreach ($line as $k => $v) {
|
||||||
|
@ -184,7 +181,7 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
fputs($fp, "</article>");
|
fputs($fp, "</article>");
|
||||||
}
|
}
|
||||||
|
|
||||||
$exported = $sth->rowCount();
|
$exported = db_num_rows($result);
|
||||||
|
|
||||||
if ($exported < $limit && $exported > 0) {
|
if ($exported < $limit && $exported > 0) {
|
||||||
fputs($fp, "</articles>");
|
fputs($fp, "</articles>");
|
||||||
|
@ -273,13 +270,12 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
|
|
||||||
//print 'GUID:' . $article['guid'] . "\n";
|
//print 'GUID:' . $article['guid'] . "\n";
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT id FROM ttrss_entries
|
$result = db_query("SELECT id FROM ttrss_entries
|
||||||
WHERE guid = ?");
|
WHERE guid = '".$article['guid']."'");
|
||||||
$sth->execute([$article['guid']]);
|
|
||||||
|
|
||||||
if ($sth->rowCount() == 0) {
|
if (db_num_rows($result) == 0) {
|
||||||
|
|
||||||
$sth = $this->pdo->prepare(
|
$result = db_query(
|
||||||
"INSERT INTO ttrss_entries
|
"INSERT INTO ttrss_entries
|
||||||
(title,
|
(title,
|
||||||
guid,
|
guid,
|
||||||
|
@ -294,37 +290,28 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
num_comments,
|
num_comments,
|
||||||
author)
|
author)
|
||||||
VALUES
|
VALUES
|
||||||
(?,
|
('".$article['title']."',
|
||||||
?,
|
'".$article['guid']."',
|
||||||
?,
|
'".$article['link']."',
|
||||||
?,
|
'".$article['updated']."',
|
||||||
?,
|
'".$article['content']."',
|
||||||
?,
|
'".sha1($article['content'])."',
|
||||||
false,
|
false,
|
||||||
NOW(),
|
NOW(),
|
||||||
NOW(),
|
NOW(),
|
||||||
'',
|
'',
|
||||||
'0',
|
'0',
|
||||||
'')");
|
'')");
|
||||||
$sth->execute([
|
|
||||||
$article['title'],
|
|
||||||
$article['guid'],
|
|
||||||
$article['link'],
|
|
||||||
$article['updated'],
|
|
||||||
$article['content'],
|
|
||||||
sha1($article['content'])
|
|
||||||
]);
|
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT id FROM ttrss_entries
|
$result = db_query("SELECT id FROM ttrss_entries
|
||||||
WHERE guid = ?");
|
WHERE guid = '".$article['guid']."'");
|
||||||
$sth->execute([$article['guid']]);
|
|
||||||
|
|
||||||
if ($sth->rowCount() != 0) {
|
if (db_num_rows($result) != 0) {
|
||||||
$ref_id = $sth->fetchColumn(0);
|
$ref_id = db_fetch_result($result, 0, "id");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$ref_id = $sth->fetchColumn(0);
|
$ref_id = db_fetch_result($result, 0, "id");
|
||||||
}
|
}
|
||||||
|
|
||||||
//print "Got ref ID: $ref_id\n";
|
//print "Got ref ID: $ref_id\n";
|
||||||
|
@ -337,27 +324,24 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
$feed = 'NULL';
|
$feed = 'NULL';
|
||||||
|
|
||||||
if ($feed_url && $feed_title) {
|
if ($feed_url && $feed_title) {
|
||||||
$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
|
$result = db_query("SELECT id FROM ttrss_feeds
|
||||||
WHERE feed_url = ? AND owner_uid = ?");
|
WHERE feed_url = '$feed_url' AND owner_uid = '$owner_uid'");
|
||||||
$sth->execute([$feed_url, $owner_uid]);
|
|
||||||
|
|
||||||
if ($sth->rowCount() != 0) {
|
if (db_num_rows($result) != 0) {
|
||||||
$feed = $sth->fetchColumn(0);
|
$feed = db_fetch_result($result, 0, "id");
|
||||||
} else {
|
} else {
|
||||||
// try autocreating feed in Uncategorized...
|
// try autocreating feed in Uncategorized...
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("INSERT INTO ttrss_feeds (owner_uid,
|
$result = db_query("INSERT INTO ttrss_feeds (owner_uid,
|
||||||
feed_url, title) VALUES (?, ?, ?)");
|
feed_url, title) VALUES ($owner_uid, '$feed_url', '$feed_title')");
|
||||||
$sth->execute([$owner_uid, $feed_url, $feed_title]);
|
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
|
$result = db_query("SELECT id FROM ttrss_feeds
|
||||||
WHERE feed_url = ? AND owner_uid = ?");
|
WHERE feed_url = '$feed_url' AND owner_uid = '$owner_uid'");
|
||||||
$sth->execute([$feed_url, $owner_uid]);
|
|
||||||
|
|
||||||
if ($sth->rowCount() != 0) {
|
if (db_num_rows($result) != 0) {
|
||||||
++$num_feeds_created;
|
++$num_feeds_created;
|
||||||
|
|
||||||
$feed = $sth->fetchColumn(0);
|
$feed = db_fetch_result($result, 0, "id");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,11 +353,10 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
|
|
||||||
//print "$ref_id / $feed / " . $article['title'] . "\n";
|
//print "$ref_id / $feed / " . $article['title'] . "\n";
|
||||||
|
|
||||||
$sth = $this->pdo->prepare("SELECT int_id FROM ttrss_user_entries
|
$result = db_query("SELECT int_id FROM ttrss_user_entries
|
||||||
WHERE ref_id = ? AND owner_uid = ? AND ?");
|
WHERE ref_id = '$ref_id' AND owner_uid = '$owner_uid' AND $feed_qpart");
|
||||||
$sth->execute([$ref_id, $owner_uid, $feed_qpart]);
|
|
||||||
|
|
||||||
if ($sth->rowCount() == 0) {
|
if (db_num_rows($result) == 0) {
|
||||||
|
|
||||||
$marked = $this->bool_to_sql_bool(sql_bool_to_bool($article['marked']));
|
$marked = $this->bool_to_sql_bool(sql_bool_to_bool($article['marked']));
|
||||||
$published = $this->bool_to_sql_bool(sql_bool_to_bool($article['published']));
|
$published = $this->bool_to_sql_bool(sql_bool_to_bool($article['published']));
|
||||||
|
@ -386,14 +369,13 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
|
|
||||||
++$num_imported;
|
++$num_imported;
|
||||||
|
|
||||||
$sth = $this->pdo->prepare(
|
$result = db_query(
|
||||||
"INSERT INTO ttrss_user_entries
|
"INSERT INTO ttrss_user_entries
|
||||||
(ref_id, owner_uid, feed_id, unread, last_read, marked,
|
(ref_id, owner_uid, feed_id, unread, last_read, marked,
|
||||||
published, score, tag_cache, label_cache, uuid, note)
|
published, score, tag_cache, label_cache, uuid, note)
|
||||||
VALUES (?, ?, ?, false,
|
VALUES ($ref_id, $owner_uid, $feed, false,
|
||||||
NULL, ?, ?, ?, ?,
|
NULL, $marked, $published, $score, '$tag_cache',
|
||||||
'', '', ?)");
|
'', '', '$note')");
|
||||||
$sth->execute([$ref_id, $owner_uid, $feed, $marked, $published, $score, $tag_cache, $note]);
|
|
||||||
|
|
||||||
$label_cache = json_decode($article['label_cache'], true);
|
$label_cache = json_decode($article['label_cache'], true);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue