Skip to content

Commit

Permalink
Merge pull request #650 from muis/develop
Browse files Browse the repository at this point in the history
Sanity checks
  • Loading branch information
Sweepr committed Jan 17, 2021
2 parents 2948bd2 + e726bf3 commit 7f79d82
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 30 deletions.
4 changes: 4 additions & 0 deletions lib/dao/Base/Dao_Base_Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ public function getMassCacheRecords($resourceIdList)
$idList = [];
$msgIdList = $this->_conn->arrayValToIn($resourceIdList, 'Message-ID');

if (!isset($msgIdList) || $msgIdList == '') {
return [];
} // if

$rs = $this->_conn->arrayQuery(
'SELECT resourceid, cachetype
FROM cache
Expand Down
34 changes: 26 additions & 8 deletions lib/dao/Base/Dao_Base_Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ public function matchCommentMessageIds($hdrList)
/*
* When no messageid's are given, bail out immediatly
*/
if (count($hdrList) == 0) {
if (!is_array($hdrList) || count($hdrList) == 0) {
return $idList;
} // if

/*
* Prepare the list of messageid's we want to match
*/
$msgIdList = $this->_conn->arrayValToIn($hdrList, 'Message-ID');

if (!isset($msgIdList) || $msgIdList == '') {
return $idList;
} // if

$rs = $this->_conn->arrayQuery("SELECT messageid AS comment, '' AS fullcomment FROM commentsxover WHERE messageid IN (".$msgIdList.")
UNION
SELECT '' as comment, messageid AS fullcomment FROM commentsfull WHERE messageid IN (".$msgIdList.')');
Expand Down Expand Up @@ -199,6 +204,10 @@ public function getCommentsFull($userId, $nntpRefs)
SpotTiming::start(__CLASS__.'::'.__FUNCTION__);

$refs = $this->_conn->arrayKeyToIn($nntpRefs);

if (!isset($refs) || $refs == '') {
return [];
} // if

// eactually retrieve the comment
$commentList = $this->_conn->arrayQuery(
Expand Down Expand Up @@ -245,7 +254,14 @@ public function getCommentsFull($userId, $nntpRefs)
*/
public function getNewCommentCountFor($nntpRefList, $ourUserId)
{
if (count($nntpRefList) == 0) {
if (!is_array($nntpRefList) || count($nntpRefList) == 0) {
return [];
} // if

// prepare a list of IN values
$msgIdList = $this->_conn->arrayKeyToIn($nntpRefList, 'messageid');

if (!isset($msgIdList) || $msgIdList == '') {
return [];
} // if

Expand All @@ -256,7 +272,7 @@ public function getNewCommentCountFor($nntpRefList, $ourUserId)
'SELECT COUNT(nntpref) AS ccount, nntpref FROM commentsxover AS cx
LEFT JOIN spotstatelist sl ON (sl.messageid = cx.nntpref)
AND (sl.ouruserid = :ouruserid)
WHERE nntpref IN ('.$this->_conn->arrayKeyToIn($nntpRefList, 'messageid').')
WHERE nntpref IN ('.$msgIdList.')
AND (cx.stamp > sl.seen)
GROUP BY nntpref',
[
Expand All @@ -279,7 +295,7 @@ public function getNewCommentCountFor($nntpRefList, $ourUserId)
*/
public function removeComments($commentMsgIdList)
{
if (count($commentMsgIdList) == 0) {
if (!is_array($commentMsgIdList) || count($commentMsgIdList) == 0) {
return;
} // if

Expand All @@ -298,14 +314,16 @@ public function removeComments($commentMsgIdList)
*/
public function markCommentsModerated($commentMsgIdList)
{
if (count($commentMsgIdList) == 0) {
if (!is_array($commentMsgIdList) || count($commentMsgIdList) == 0) {
return;
} // if

$tmplist = $this->_conn->arrayKeyToInForComments($commentMsgIdList);
if (strlen($tmplist) > 0) {
// prepare a list of IN values
$msgIdList = $this->_conn->arrayKeyToInForComments($commentMsgIdList);

if (strlen($msgIdList) > 0) {
$this->_conn->modify(
'UPDATE commentsxover SET moderated = :moderated WHERE messageid IN ('.$tmplist.')',
'UPDATE commentsxover SET moderated = :moderated WHERE messageid IN ('.$msgIdList.')',
[
':moderated' => [true, PDO::PARAM_BOOL],
]
Expand Down
14 changes: 12 additions & 2 deletions lib/dao/Base/Dao_Base_ModeratedRingBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ public function __construct(dbeng_abs $conn)
public function addToRingBuffer(array $messageIds)
{
// Empty list provided? Exit
if (count($messageIds) == 0) {
if (!is_array($messageIds) || count($messageIds) == 0) {
return;
} // if

// match the ones we are going to add with these
$msgIdList = $this->_conn->arrayKeyToIn($messageIds);

if (!isset($msgIdList) || $msgIdList == '') {
return;
} // if

$alreadyAddedList = $this->_conn->arrayQuery('SELECT messageid FROM moderatedringbuffer WHERE messageid IN ('.$msgIdList.')');

// remove the messageid's we already have
Expand Down Expand Up @@ -63,14 +68,19 @@ public function addToRingBuffer(array $messageIds)
public function matchAgainst(array $messageIds)
{
// Empty list provided? Exit
if (count($messageIds) == 0) {
if (!is_array($messageIds) || count($messageIds) == 0) {
return;
} // if

/*
* Prepare the list of messageid's we want to match
*/
$msgIdList = $this->_conn->arrayValToIn($messageIds, 'Message-ID');

if (!isset($msgIdList) || $msgIdList == '') {
return [];
} // if

$rs = $this->_conn->arrayQuery('SELECT messageid FROM moderatedringbuffer WHERE messageid IN ('.$msgIdList.')');

/*
Expand Down
76 changes: 59 additions & 17 deletions lib/dao/Base/Dao_Base_Spot.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,14 @@ public function getFullSpot($messageId, $ourUserId)
public function updateSpotRating($spotMsgIdList)
{
// Empty list provided? Exit
if (count($spotMsgIdList) == 0) {
if (!is_array($spotMsgIdList) || count($spotMsgIdList) == 0) {
return;
} // if

// prepare a list of IN values
$msgIdList = $this->_conn->arrayKeyToIn($spotMsgIdList);

if (!isset($msgIdList) || $msgIdList == '') {
return;
} // if

Expand All @@ -285,7 +292,7 @@ public function updateSpotRating($spotMsgIdList)
spots.messageid = commentsxover.nntpref
AND spotrating BETWEEN 1 AND 10
GROUP BY nntpref)
WHERE spots.messageid IN ('.$this->_conn->arrayKeyToIn($spotMsgIdList).')
WHERE spots.messageid IN ('.$msgIdList.')
');
SpotTiming::stop(__CLASS__.'::'.__FUNCTION__, [$spotMsgIdList]);
}
Expand All @@ -298,7 +305,14 @@ public function updateSpotRating($spotMsgIdList)
public function updateSpotCommentCount($spotMsgIdList)
{
// Empty list provided? Exit
if (count($spotMsgIdList) == 0) {
if (!is_array($spotMsgIdList) || count($spotMsgIdList) == 0) {
return;
} // if

// prepare a list of IN values
$msgIdList = $this->_conn->arrayKeyToIn($spotMsgIdList);

if (!isset($msgIdList) || $msgIdList == '') {
return;
} // if

Expand All @@ -310,7 +324,7 @@ public function updateSpotCommentCount($spotMsgIdList)
WHERE
spots.messageid = commentsxover.nntpref
GROUP BY nntpref)
WHERE spots.messageid IN ('.$this->_conn->arrayKeyToIn($spotMsgIdList).')
WHERE spots.messageid IN ('.$msgIdList.')
');
SpotTiming::stop(__CLASS__.'::'.__FUNCTION__, [$spotMsgIdList]);
}
Expand All @@ -323,7 +337,14 @@ public function updateSpotCommentCount($spotMsgIdList)
public function updateSpotReportCount($spotMsgIdList)
{
// Empty list provided? Exit
if (count($spotMsgIdList) == 0) {
if (!is_array($spotMsgIdList) || count($spotMsgIdList) == 0) {
return;
} // if

// prepare a list of IN values
$msgIdList = $this->_conn->arrayKeyToIn($spotMsgIdList);

if (!isset($msgIdList) || $msgIdList == '') {
return;
} // if

Expand All @@ -335,7 +356,7 @@ public function updateSpotReportCount($spotMsgIdList)
WHERE
spots.messageid = reportsxover.nntpref
GROUP BY nntpref)
WHERE spots.messageid IN ('.$this->_conn->arrayKeyToIn($spotMsgIdList).')
WHERE spots.messageid IN ('.$msgIdList.')
');
SpotTiming::stop(__CLASS__.'::'.__FUNCTION__, [$spotMsgIdList]);
}
Expand All @@ -347,15 +368,22 @@ public function updateSpotReportCount($spotMsgIdList)
*/
public function getDisposedSpots($spotMsgIdList)
{
SpotTiming::start(__CLASS__.'::'.__FUNCTION__);
$tmparray = [];

// Empty list provided? Exit
if (count($spotMsgIdList) == 0) {
if (!is_array($spotMsgIdList) || count($spotMsgIdList) == 0) {
return $tmparray;
} // if

// prepare a list of IN values
$msgIdList = $this->_conn->arrayKeyToIn($spotMsgIdList);

if (!isset($msgIdList) || $msgIdList == '') {
return $tmparray;
} // if

SpotTiming::start(__CLASS__.'::'.__FUNCTION__);

$msgIdList = '('.$msgIdList.')';

$tmpArray = $this->_conn->arrayQuery('SELECT s.messageid AS messageid, s.spotterid AS spotterid, s.stamp AS stamp
Expand All @@ -372,15 +400,19 @@ public function getDisposedSpots($spotMsgIdList)
public function removeSpots($spotMsgIdList)
{
// Empty list provided? Exit
if (count($spotMsgIdList) == 0) {
if (!is_array($spotMsgIdList) || count($spotMsgIdList) == 0) {
return;
} // if

SpotTiming::start(__CLASS__.'::'.__FUNCTION__);

// prepare a list of IN values
$msgIdList = $this->_conn->arrayKeyToIn($spotMsgIdList);

if (!isset($msgIdList) || $msgIdList == '') {
return;
} // if

SpotTiming::start(__CLASS__.'::'.__FUNCTION__);

$this->_conn->modify('DELETE FROM spots WHERE messageid IN ('.$msgIdList.')');
$this->_conn->modify('DELETE FROM spotsfull WHERE messageid IN ('.$msgIdList.')');
// Comments are deleted in a seperate routine
Expand All @@ -400,14 +432,20 @@ public function removeSpots($spotMsgIdList)
public function markSpotsModerated($spotMsgIdList)
{
// Empty list provided? Exit
if (count($spotMsgIdList) == 0) {
if (!is_array($spotMsgIdList) || count($spotMsgIdList) == 0) {
return;
} // if

// prepare a list of IN values
$msgIdList = $this->_conn->arrayKeyToIn($spotMsgIdList);

if (!isset($msgIdList) || $msgIdList == '') {
return;
} // if

SpotTiming::start(__CLASS__.'::'.__FUNCTION__);
$this->_conn->modify(
'UPDATE spots SET moderated = :moderated WHERE messageid IN ('.
$this->_conn->arrayKeyToIn($spotMsgIdList).')',
'UPDATE spots SET moderated = :moderated WHERE messageid IN ('.$msgIdList.')',
[
':moderated' => [true, PDO::PARAM_BOOL],
]
Expand Down Expand Up @@ -658,15 +696,19 @@ public function matchSpotMessageIds($hdrList)
$idList = ['spot' => [], 'fullspot' => []];

// Empty list, exit
if (count($hdrList) == 0) {
if (!is_array($hdrList) || count($hdrList) == 0) {
return $idList;
} // if

SpotTiming::start(__CLASS__.'::'.__FUNCTION__);

// Prepare a list of values
$msgIdList = $this->_conn->arrayValToIn($hdrList, 'Message-ID');

if (!isset($msgIdList) || $msgIdList == '') {
return $idList;
} // if

SpotTiming::start(__CLASS__.'::'.__FUNCTION__);

// Because MySQL doesn't know anything about full joins, we use this trick
$rs = $this->_conn->arrayQuery("SELECT messageid AS spot, '' AS fullspot FROM spots WHERE messageid IN (".$msgIdList.")
UNION
Expand Down
9 changes: 8 additions & 1 deletion lib/dao/Base/Dao_Base_SpotReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ public function matchReportMessageIds($hdrList)
return $idList;
} // if

// prepare a list of IN values
$msgIdList = $this->_conn->arrayValToIn($hdrList, 'Message-ID');

if (!isset($msgIdList) || $msgIdList == '') {
return;
} // if

// en vraag alle comments op die we kennen
$rs = $this->_conn->arrayQuery('SELECT messageid FROM reportsxover WHERE messageid IN ('.$this->_conn->arrayValToIn($hdrList, 'Message-ID').')');
$rs = $this->_conn->arrayQuery('SELECT messageid FROM reportsxover WHERE messageid IN ('.$msgIdList.')');

// geef hier een array terug die kant en klaar is voor isset()
foreach ($rs as $msgids) {
Expand Down
11 changes: 9 additions & 2 deletions lib/dao/Mysql/Dao_Mysql_Spot.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ public function addFullSpots($fullSpots)
*/
public function removeSpots($spotMsgIdList)
{
if (count($spotMsgIdList) == 0) {
if (!is_array($spotMsgIdList) || count($spotMsgIdList) == 0) {
return;
} // if

// prepare a list of IN values
$msgIdList = $this->_conn->arrayKeyToIn($spotMsgIdList);

if (!isset($msgIdList) || $msgIdList == '') {
return;
} // if

Expand All @@ -45,7 +52,7 @@ public function removeSpots($spotMsgIdList)
LEFT JOIN reportsxover ON spots.messageid=reportsxover.nntpref
LEFT JOIN spotstatelist ON spots.messageid=spotstatelist.messageid
LEFT JOIN reportsposted ON spots.messageid=reportsposted.inreplyto
WHERE spots.messageid IN ('.$this->_conn->arrayKeyToIn($spotMsgIdList).')');
WHERE spots.messageid IN ('.$msgIdList.')');
}

// removeSpots
Expand Down
13 changes: 13 additions & 0 deletions lib/dbeng/dbeng_abs.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public function arrayKeyToIn($ar)
{
$tmpList = '';

if (!is_array($ar) || count($ar) == 0) {
return $tmpList;
} // if

foreach ($ar as $k => $v) {
$tmpList .= $this->safe((string) $k).',';
} // foreach
Expand All @@ -125,6 +129,11 @@ public function arrayKeyToIn($ar)
public function arrayKeyToInForComments($ar)
{
$tmpList = '';

if (!is_array($ar) || count($ar) == 0) {
return $tmpList;
} // if

foreach ($ar as $k => $v) {
// Exclude messageid's from spots which are disposed by the owner, only process real disposes
if ($v['spotterid'] == '') {
Expand All @@ -145,6 +154,10 @@ public function arrayValToIn($ar, $val)
{
$tmpList = '';

if (!is_array($ar) || count($ar) == 0) {
return $tmpList;
} // if

foreach ($ar as $v) {
$tmpList .= $this->safe((string) $v[$val]).',';
} // foreach
Expand Down

0 comments on commit 7f79d82

Please sign in to comment.