From ef005987a1ed1ed0774ae7ae88772e3ca4654cbd Mon Sep 17 00:00:00 2001
From: Mikael Nordfeldth <mmn@hethane.se>
Date: Mon, 11 Jan 2016 13:35:29 +0100
Subject: [PATCH] Did the OpportunisticQM fixes in the wrong order

---
 plugins/OpportunisticQM/lib/opportunisticqueuemanager.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugins/OpportunisticQM/lib/opportunisticqueuemanager.php b/plugins/OpportunisticQM/lib/opportunisticqueuemanager.php
index 7100ab7296..2834b9a0ee 100644
--- a/plugins/OpportunisticQM/lib/opportunisticqueuemanager.php
+++ b/plugins/OpportunisticQM/lib/opportunisticqueuemanager.php
@@ -18,7 +18,7 @@ class OpportunisticQueueManager extends DBQueueManager
 {
     protected $qmkey = false;
     protected $max_execution_time = null;
-    protected $max_execution_margin = null; // margin to execution time, including timeouts etc.
+    protected $max_execution_margin = null; // margin to PHP's max_execution_time
     protected $max_queue_items = null;
 
     protected $started_at = null;
@@ -65,7 +65,7 @@ class OpportunisticQueueManager extends DBQueueManager
             return false;
         }
         // If too much time has passed, stop
-        if ($time_passed >= $this->max_execution_time - $this->max_execution_margin) {
+        if ($time_passed >= $this->max_execution_time || $time_passed > ini_get('max_execution_time') - $this->max_execution_margin) {
             return false;
         }
         // If we have a max-item-limit, check if it has been passed
-- 
2.39.5