diff --git a/src/crontab/import/feed.php b/src/crontab/import/feed.php index f8c5e57..510892c 100644 --- a/src/crontab/import/feed.php +++ b/src/crontab/import/feed.php @@ -87,6 +87,15 @@ try // Remember user ID for this host $aliasUserId[$remoteUser->userId] = $localUser->userId; + // Update time added if newer + if ($localUser->timeAdded < $remoteUser->timeAdded) + { + $db->updateUserTimeAdded( + $localUser->userId, + $remoteUser->timeAdded + ); + } + // Update user info if newer if ($localUser->timeUpdated < $remoteUser->timeUpdated) { @@ -155,7 +164,7 @@ try !isset($remoteMagnet->dn) || mb_strlen($remoteMagnet->dn) < MAGNET_TITLE_MIN_LENGTH || mb_strlen($remoteMagnet->dn) > MAGNET_TITLE_MAX_LENGTH || - !isset($remoteMagnet->xl) || !is_int($remoteMagnet->xl) || + !isset($remoteMagnet->xl) || !(is_int($remoteMagnet->xl) || is_float($remoteMagnet->xl)) || !isset($remoteMagnet->xt) || !is_object($remoteMagnet->xt) || !isset($remoteMagnet->kt) || !is_object($remoteMagnet->kt) || @@ -187,6 +196,15 @@ try // Add magnet alias for this host $aliasMagnetId[$remoteMagnet->magnetId] = $localMagnet->magnetId; + // Update time added if newer + if ($localMagnet->timeAdded < $remoteMagnet->timeAdded) + { + $db->updateMagnetTimeAdded( + $localUser->userId, + $remoteMagnet->timeAdded + ); + } + // Update info if remote newer if ($localMagnet->timeUpdated < $remoteMagnet->timeUpdated) { diff --git a/src/library/database.php b/src/library/database.php index cb11dc3..4b1addc 100644 --- a/src/library/database.php +++ b/src/library/database.php @@ -575,6 +575,17 @@ class Database { return $query->rowCount(); } + public function updateUserTimeAdded(int $userId, int $timeAdded) : int { + + $this->_debug->query->update->total++; + + $query = $this->_db->prepare('UPDATE `user` SET `timeAdded` = ? WHERE `userId` = ?'); + + $query->execute([$timeAdded, $userId]); + + return $query->rowCount(); + } + public function updateUserTimeUpdated(int $userId, int $timeUpdated) : int { $this->_debug->query->update->total++; @@ -807,6 +818,28 @@ class Database { return $query->rowCount(); } + public function updateMagnetTimeUpdated(int $magnetId, int $timeUpdated) : int { + + $this->_debug->query->update->total++; + + $query = $this->_db->prepare('UPDATE `magnet` SET `timeUpdated` = ? WHERE `magnetId` = ?'); + + $query->execute([$timeUpdated, $magnetId]); + + return $query->rowCount(); + } + + public function updateMagnetTimeAdded(int $magnetId, int $timeAdded) : int { + + $this->_debug->query->update->total++; + + $query = $this->_db->prepare('UPDATE `magnet` SET `timeAdded` = ? WHERE `magnetId` = ?'); + + $query->execute([$timeAdded, $magnetId]); + + return $query->rowCount(); + } + // Magnet to Info Hash public function addMagnetToInfoHash(int $magnetId, int $infoHashId) : int {