summaryrefslogtreecommitdiff
path: root/update.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-06-20 08:40:02 +0300
committerAndrew Dolgov <[email protected]>2019-06-20 08:40:02 +0300
commit088fcf8131a0d5b612362c2fecf337df6ef754bb (patch)
tree3e5e415be8e411bb6a8eeac2e5a62e926f103c72 /update.php
parent4fa9aee4e7d187ed0f87d0dc9b88a86ba625c58f (diff)
move more globals to more appropriate places
set libxml to always use internal errors
Diffstat (limited to 'update.php')
-rwxr-xr-xupdate.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/update.php b/update.php
index 3817c7e26..5b723277f 100755
--- a/update.php
+++ b/update.php
@@ -14,6 +14,51 @@
require_once "db.php";
require_once "db-prefs.php";
+ function cleanup_tags($days = 14, $limit = 1000) {
+
+ $days = (int) $days;
+
+ if (DB_TYPE == "pgsql") {
+ $interval_query = "date_updated < NOW() - INTERVAL '$days days'";
+ } else if (DB_TYPE == "mysql") {
+ $interval_query = "date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)";
+ }
+
+ $tags_deleted = 0;
+
+ $pdo = Db::pdo();
+
+ while ($limit > 0) {
+ $limit_part = 500;
+
+ $sth = $pdo->prepare("SELECT ttrss_tags.id AS id
+ FROM ttrss_tags, ttrss_user_entries, ttrss_entries
+ WHERE post_int_id = int_id AND $interval_query AND
+ ref_id = ttrss_entries.id AND tag_cache != '' LIMIT ?");
+ $sth->bindValue(1, $limit_part, PDO::PARAM_INT);
+ $sth->execute();
+
+ $ids = array();
+
+ while ($line = $sth->fetch()) {
+ array_push($ids, $line['id']);
+ }
+
+ if (count($ids) > 0) {
+ $ids = join(",", $ids);
+
+ $usth = $pdo->query("DELETE FROM ttrss_tags WHERE id IN ($ids)");
+ $tags_deleted = $usth->rowCount();
+ } else {
+ break;
+ }
+
+ $limit -= $limit_part;
+ }
+
+ return $tags_deleted;
+ }
+
if (!defined('PHP_EXECUTABLE'))
define('PHP_EXECUTABLE', '/usr/bin/php');