aboutsummaryrefslogtreecommitdiff
path: root/p/api/greader.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2019-09-29 16:22:50 +0200
committerGravatar GitHub <noreply@github.com> 2019-09-29 16:22:50 +0200
commite3e5954394f4523850c78e80e496f1b916622677 (patch)
tree2e20d9091735e1da1de85e273e19635f58111e0f /p/api/greader.php
parentec4307c1a64a0f60648fdd7d0a2eb819bbf12965 (diff)
PDO refactoring for code simplification (#2522)
* PDO refactor * Automatic prefix when using the syntax `_tableName` * Uniformity: MySQL is now PDO::ATTR_EMULATE_PREPARES = false just like SQLite and PostgreSQL, with consequences such as only one statement per query * Use PDO methods exec(), query(), prepare() + execute() in a more efficient way * Remove auto-update SQL code for versions older than FreshRSS 1.5 (3 years old) * The name of the default category is set in PHP instead of in the DB (simplies SQL and allows changing the name according to the FreshRSS language) * Rename `->bd` to `->pdo` (less of a frenshism, and more informative) * Fix some requests, which were not compatible with MySQL prepared statements * Whitespace * Fix syntax for PostgreSQL sequences + MySQL install * Minor formatting * Fix lastInsertId for PostgreSQL * Use PHP 5.6+ const Take advantage of https://github.com/FreshRSS/FreshRSS/pull/2527 https://www.php.net/manual/en/migration56.new-features.php * A bit of forgotten PHP 5.6 simplification for cURL * Forgotten $s * Mini fix custom user config https://github.com/FreshRSS/FreshRSS/pull/2490/files#r326290346 * More work on install.php but not finished * install.php working * More cleaning of PDO in install * Even more simplification Take advantage of PDO->exec() to run multiple statements * Disallow changing the name of the default category https://github.com/FreshRSS/FreshRSS/pull/2522#discussion_r326967724
Diffstat (limited to 'p/api/greader.php')
-rw-r--r--p/api/greader.php20
1 files changed, 7 insertions, 13 deletions
diff --git a/p/api/greader.php b/p/api/greader.php
index b6777796a..77e498524 100644
--- a/p/api/greader.php
+++ b/p/api/greader.php
@@ -76,12 +76,6 @@ function multiplePosts($name) { //https://bugs.php.net/bug.php?id=51633
return $result;
}
-class MyPDO extends Minz_ModelPdo {
- function prepare($sql) {
- return $this->bd->prepare(str_replace('%_', $this->prefix, $sql));
- }
-}
-
function debugInfo() {
if (function_exists('getallheaders')) {
$ALL_HEADERS = getallheaders();
@@ -239,9 +233,8 @@ function userInfo() { //https://github.com/theoldreader/api#user-info
function tagList() {
header('Content-Type: application/json; charset=UTF-8');
- $pdo = new MyPDO();
- $stm = $pdo->prepare('SELECT c.name FROM `%_category` c');
- $stm->execute();
+ $model = new Minz_ModelPdo();
+ $stm = $model->pdo->query('SELECT c.name FROM `_category` c');
$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
$tags = array(
@@ -277,10 +270,11 @@ function tagList() {
function subscriptionList() {
header('Content-Type: application/json; charset=UTF-8');
- $pdo = new MyPDO();
- $stm = $pdo->prepare('SELECT f.id, f.name, f.url, f.website, c.id as c_id, c.name as c_name FROM `%_feed` f
- INNER JOIN `%_category` c ON c.id = f.category AND f.priority >= :priority_normal');
- $stm->execute(array(':priority_normal' => FreshRSS_Feed::PRIORITY_NORMAL));
+ $model = new Minz_ModelPdo();
+ $stm = $model->pdo->prepare('SELECT f.id, f.name, f.url, f.website, c.id as c_id, c.name as c_name FROM `_feed` f
+ INNER JOIN `_category` c ON c.id = f.category AND f.priority >= :priority_normal');
+ $stm->bindValue(':priority_normal', FreshRSS_Feed::PRIORITY_NORMAL, PDO::PARAM_INT);
+ $stm->execute();
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
$salt = FreshRSS_Context::$system_conf->salt;