diff --git a/cronjobs/findblock.php b/cronjobs/findblock.php index 64d32914..2f978eed 100755 --- a/cronjobs/findblock.php +++ b/cronjobs/findblock.php @@ -87,7 +87,11 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { continue; } // Fetch share information - $iPreviousShareId = @$aAllBlocks[$iIndex - 1]['share_id'] ? $aAllBlocks[$iIndex - 1]['share_id'] : 0; + if (!$iPreviousShareId = $block->getLastShareId()) { + $iPreviousShareId = 0; + verbose("\nUnable to find highest share ID found so far\n"); + verbose("If this is your first block, this is normal\n\n"); + } $iRoundShares = $share->getRoundShares($iPreviousShareId, $iCurrentUpstreamId); // Store new information diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index aad32c08..743ce67e 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -43,6 +43,18 @@ class Block { return false; } + /** + * Get our last, highest share ID inserted for a block + * @param none + * @return int data Share ID + **/ + public function getLastShareId() { + $stmt = $this->mysqli->prepare("SELECT MAX(share_id) AS share_id FROM $this->table LIMIT 1"); + if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result()) + return $result->fetch_object()->share_id; + return false; + } + /** * Fetch all unaccounted blocks * @param order string Sort order, default ASC