]> git.mxchange.org Git - friendica.git/commitdiff
Removed old functions
authorMichael <heluecht@pirati.ca>
Mon, 24 Apr 2017 21:02:51 +0000 (21:02 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 24 Apr 2017 21:02:51 +0000 (21:02 +0000)
include/dba.php
include/dbclean.php
include/tags.php
include/threads.php

index c8c9ecc60d43e7c9e15f8f607c7feb90191b3440..cf1c962b1dd367909be505d3b30907f5792d1d10 100644 (file)
@@ -134,30 +134,6 @@ class dba {
                return $r[0]['db'];
        }
 
-       /**
-        * @brief Returns the number of rows
-        *
-        * @return integer
-        */
-       public function num_rows() {
-               if (!$this->result) {
-                       return 0;
-               }
-
-               switch ($this->driver) {
-                       case 'pdo':
-                               $rows = $this->result->rowCount();
-                               break;
-                       case 'mysqli':
-                               $rows = $this->result->num_rows;
-                               break;
-                       case 'mysql':
-                               $rows = mysql_num_rows($this->result);
-                               break;
-               }
-               return $rows;
-       }
-
        /**
         * @brief Analyze a database query and log this if some conditions are met.
         *
@@ -382,41 +358,6 @@ class dba {
                return($r);
        }
 
-       public function qfetch() {
-               $x = false;
-
-               if ($this->result) {
-                       switch ($this->driver) {
-                               case 'pdo':
-                                       $x = $this->result->fetch(PDO::FETCH_ASSOC);
-                                       break;
-                               case 'mysqli':
-                                       $x = $this->result->fetch_array(MYSQLI_ASSOC);
-                                       break;
-                               case 'mysql':
-                                       $x = mysql_fetch_array($this->result, MYSQL_ASSOC);
-                                       break;
-                       }
-               }
-               return($x);
-       }
-
-       public function qclose() {
-               if ($this->result) {
-                       switch ($this->driver) {
-                               case 'pdo':
-                                       $this->result->closeCursor();
-                                       break;
-                               case 'mysqli':
-                                       $this->result->free_result();
-                                       break;
-                               case 'mysql':
-                                       mysql_free_result($this->result);
-                                       break;
-                       }
-               }
-       }
-
        public function dbg($dbg) {
                $this->debug = $dbg;
        }
@@ -691,7 +632,7 @@ class dba {
         * @param object Statement object
         * @return int Number of rows
         */
-       static public function rows($stmt) {
+       static public function num_rows($stmt) {
                switch (self::$dbo->driver) {
                        case 'pdo':
                                return $stmt->rowCount();
index bff4ff2a24946a9246513306add33c8fdedafe72..64ceb51d37bc58060c29f53b06ad1b9457e86345 100644 (file)
@@ -43,96 +43,103 @@ function remove_orphans($stage = 0) {
 
        if (($stage == 1) OR ($stage == 0)) {
                logger("Deleting old global item entries from item table without user copy");
-               if ($db->q("SELECT `id` FROM `item` WHERE `uid` = 0
+               $r = dba::p("SELECT `id` FROM `item` WHERE `uid` = 0
                                AND NOT EXISTS (SELECT `guid` FROM `item` AS `i` WHERE `item`.`guid` = `i`.`guid` AND `i`.`uid` != 0)
-                               AND `received` < UTC_TIMESTAMP() - INTERVAL 90 DAY LIMIT ".intval($limit), true)) {
-                       $count = $db->num_rows();
+                               AND `received` < UTC_TIMESTAMP() - INTERVAL 90 DAY LIMIT ".intval($limit));
+               $count = dba::num_rows($r);
+               if ($count > 0) {
                        logger("found global item orphans: ".$count);
-                       while ($orphan = $db->qfetch()) {
+                       while ($orphan = dba::fetch($r)) {
                                q("DELETE FROM `item` WHERE `id` = %d", intval($orphan["id"]));
                        }
                }
-               $db->qclose();
+               dba::close($r);
                logger("Done deleting old global item entries from item table without user copy");
        }
 
        if (($stage == 2) OR ($stage == 0)) {
                logger("Deleting items without parents");
-               if ($db->q("SELECT `id` FROM `item` WHERE NOT EXISTS (SELECT `id` FROM `item` AS `i` WHERE `item`.`parent` = `i`.`id`) LIMIT ".intval($limit), true)) {
-                       $count = $db->num_rows();
+               $r = dba::p("SELECT `id` FROM `item` WHERE NOT EXISTS (SELECT `id` FROM `item` AS `i` WHERE `item`.`parent` = `i`.`id`) LIMIT ".intval($limit));
+               $count = dba::num_rows($r);
+               if ($count > 0) {
                        logger("found item orphans without parents: ".$count);
-                       while ($orphan = $db->qfetch()) {
+                       while ($orphan = dba::fetch($r)) {
                                q("DELETE FROM `item` WHERE `id` = %d", intval($orphan["id"]));
                        }
                }
-               $db->qclose();
+               dba::close($r);
                logger("Done deleting items without parents");
        }
 
        if (($stage == 3) OR ($stage == 0)) {
                logger("Deleting orphaned data from thread table");
-               if ($db->q("SELECT `iid` FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`) LIMIT ".intval($limit), true)) {
-                       $count = $db->num_rows();
+               $r = dba::p("SELECT `iid` FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`) LIMIT ".intval($limit));
+               $count = dba::num_rows($r);
+               if ($count > 0) {
                        logger("found thread orphans: ".$count);
-                       while ($orphan = $db->qfetch()) {
+                       while ($orphan = dba::fetch($r)) {
                                q("DELETE FROM `thread` WHERE `iid` = %d", intval($orphan["iid"]));
                        }
                }
-               $db->qclose();
+               dba::close($r);
                logger("Done deleting orphaned data from thread table");
        }
 
        if (($stage == 4) OR ($stage == 0)) {
                logger("Deleting orphaned data from notify table");
-               if ($db->q("SELECT `iid` FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`) LIMIT ".intval($limit), true)) {
-                       $count = $db->num_rows();
+               $r = dba::p("SELECT `iid` FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`) LIMIT ".intval($limit));
+               $count = dba::num_rows($r);
+               if ($count > 0) {
                        logger("found notify orphans: ".$count);
-                       while ($orphan = $db->qfetch()) {
+                       while ($orphan = dba::fetch($r)) {
                                q("DELETE FROM `notify` WHERE `iid` = %d", intval($orphan["iid"]));
                        }
                }
-               $db->qclose();
+               dba::close($r);
                logger("Done deleting orphaned data from notify table");
        }
 
        if (($stage == 5) OR ($stage == 0)) {
                logger("Deleting orphaned data from notify-threads table");
-               if ($db->q("SELECT `id` FROM `notify-threads` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `notify-threads`.`master-parent-item`) LIMIT ".intval($limit), true)) {
-                       $count = $db->num_rows();
+               $r = dba::p("SELECT `id` FROM `notify-threads` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `notify-threads`.`master-parent-item`) LIMIT ".intval($limit));
+               $count = dba::num_rows($r);
+               if ($count > 0) {
                        logger("found notify-threads orphans: ".$count);
-                       while ($orphan = $db->qfetch()) {
+                       while ($orphan = dba::fetch($r)) {
                                q("DELETE FROM `notify-threads` WHERE `id` = %d", intval($orphan["id"]));
                        }
                }
-               $db->qclose();
+               dba::close($r);
                logger("Done deleting orphaned data from notify-threads table");
        }
 
 
        if (($stage == 6) OR ($stage == 0)) {
                logger("Deleting orphaned data from sign table");
-               if ($db->q("SELECT `iid` FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`) LIMIT ".intval($limit), true)) {
-                       $count = $db->num_rows();
+               $r = dba::p("SELECT `iid` FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`) LIMIT ".intval($limit));
+               $count = dba::num_rows($r);
+               if ($count > 0) {
                        logger("found sign orphans: ".$count);
-                       while ($orphan = $db->qfetch()) {
+                       while ($orphan = dba::fetch($r)) {
                                q("DELETE FROM `sign` WHERE `iid` = %d", intval($orphan["iid"]));
                        }
                }
-               $db->qclose();
+               dba::close($r);
                logger("Done deleting orphaned data from sign table");
        }
 
 
        if (($stage == 7) OR ($stage == 0)) {
                logger("Deleting orphaned data from term table");
-               if ($db->q("SELECT `oid` FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`) LIMIT ".intval($limit), true)) {
-                       $count = $db->num_rows();
+               $r = dba::p("SELECT `oid` FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`) LIMIT ".intval($limit));
+               $count = dba::num_rows($r);
+               if ($count > 0) {
                        logger("found term orphans: ".$count);
-                       while ($orphan = $db->qfetch()) {
+                       while ($orphan = dba::fetch($r)) {
                                q("DELETE FROM `term` WHERE `oid` = %d", intval($orphan["oid"]));
                        }
                }
-               $db->qclose();
+               dba::close($r);
                logger("Done deleting orphaned data from term table");
        }
 
index 0a094384782bb4358af16ac28811182ade537a84..d809da2bf5e0115c2f4ce36fc503ae9bd33fec62 100644 (file)
@@ -111,12 +111,11 @@ function create_tags_from_itemuri($itemuri, $uid) {
 }
 
 function update_items() {
-       global $db;
 
-        $messages = $db->q("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1 AND `term`.`guid` = ''", true);
+       $messages = dba::p("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1 AND `term`.`guid` = ''");
 
-        logger("fetched messages: ".count($messages));
-        while ($message = $db->qfetch()) {
+       logger("fetched messages: ".dba::num_rows($messages));
+       while ($message = dba::fetch($messages)) {
 
                if ($message["uid"] == 0) {
                        $global = true;
@@ -135,15 +134,15 @@ function update_items() {
                        intval($global), intval(TERM_OBJ_POST), intval($message["oid"]));
        }
 
-        $db->qclose();
+       dba::close($messages);
 
-       $messages = $db->q("SELECT `guid` FROM `item` WHERE `uid` = 0", true);
+       $messages = dba::p("SELECT `guid` FROM `item` WHERE `uid` = 0");
 
-       logger("fetched messages: ".count($messages));
-       while ($message = $db->qfetch()) {
+       logger("fetched messages: ".dba::num_rows($messages));
+       while ($message = dba::fetch(messages)) {
                q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($message["guid"]));
        }
 
-       $db->qclose();
+       dba::close($messages);
 }
 ?>
index c214cf264487a6f89ddecab8248e7b81909ed5b8..3d0aa05c3c08646abbd9031894a1817d0d9f7f8a 100644 (file)
@@ -251,19 +251,17 @@ function delete_thread($itemid, $itemuri = "") {
 }
 
 function update_threads() {
-       global $db;
-
        logger("update_threads: start");
 
-       $messages = $db->q("SELECT `id` FROM `item` WHERE `id` = `parent`", true);
+       $messages = dba::p("SELECT `id` FROM `item` WHERE `id` = `parent`");
 
-       logger("update_threads: fetched messages: ".count($messages));
+       logger("update_threads: fetched messages: ".dba::num_rows($messages));
 
-       while ($message = $db->qfetch()) {
+       while ($message = dba::fetch($messages)) {
                add_thread($message["id"]);
                add_shadow_thread($message["id"]);
        }
-       $db->qclose();
+       dba::close($messages);
 }
 
 function update_threads_mention() {
@@ -283,18 +281,16 @@ function update_threads_mention() {
 
 
 function update_shadow_copy() {
-       global $db;
-
        logger("start");
 
-       $messages = $db->q(sprintf("SELECT `iid` FROM `thread` WHERE `uid` != 0 AND `network` IN ('', '%s', '%s', '%s')
-                                       AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private` ORDER BY `created`",
-                               NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS), true);
+       $messages = dba::p("SELECT `iid` FROM `thread` WHERE `uid` != 0 AND `network` IN ('', ?, ?, ?)
+                               AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private` ORDER BY `created`",
+                               NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS);
 
-       logger("fetched messages: ".count($messages));
-       while ($message = $db->qfetch())
+       logger("fetched messages: ".dba::num_rows($messages));
+       while ($message = dba::fetch($messages))
                add_shadow_thread($message["iid"]);
 
-       $db->qclose();
+       dba::close($messages);
 }
 ?>