1
0
Fork 0

Removed old functions

This commit is contained in:
Michael 2017-04-24 21:02:51 +00:00
parent 9959da5a1c
commit 82f13441bc
4 changed files with 55 additions and 112 deletions

View 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();

View 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");
}

View 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);
}
?>

View 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')
$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), true);
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);
}
?>