Permalink
Browse files

Fix ShutdownScheduler: if some events are triggered defered during an…

… already defered callback, they can be ignored.
  • Loading branch information...
1 parent 41a6949 commit 8086b007557f2e7e8c733d499aae5551c50af45a @cdujeu cdujeu committed Jun 2, 2016
@@ -344,6 +344,9 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
}
$repoObject = ConfService::getRepository();
+ if(empty($repoObject)){
+ $repoObject = ConfService::getRepositoryById($currentRepositoryId);
+ }
$clearEnv = false;
if($repoObject->getOption("USE_SESSION_CREDENTIALS")){
$encodedCreds = AJXP_Safe::getEncodedCredentialString();
@@ -84,24 +84,32 @@ public function registerShutdownEvent()
$this->callbacks[] = $callback;
return true;
}
- public function callRegisteredShutdown()
- {
- session_write_close();
+
+ public function callRegisteredShutdown()
+ {
+ session_write_close();
if (!headers_sent()) {
- $size = ob_get_length();
- header("Connection: close\r\n");
- //header("Content-Encoding: none\r\n");
- header("Content-Length: $size");
- }
+ $size = ob_get_length();
+ header("Connection: close\r\n");
+ //header("Content-Encoding: none\r\n");
+ header("Content-Length: $size");
+ }
ob_end_flush();
- flush();
- foreach ($this->callbacks as $arguments) {
- $callback = array_shift($arguments);
- try {
- call_user_func_array($callback, $arguments);
- } catch (\Exception $e) {
- AJXP_Logger::error(__CLASS__, __FUNCTION__, array("context"=>"Applying hook ".get_class($callback[0])."::".$callback[1], "message" => $e->getMessage()));
- }
- }
- }
+ flush();
+ $index = 0;
+ while (count($this->callbacks)) {
+ $arguments = array_shift($this->callbacks);
+ $callback = array_shift($arguments);
+ try {
+ call_user_func_array($callback, $arguments);
+ } catch (\Exception $e) {
+ AJXP_Logger::error(__CLASS__, __FUNCTION__, array("context" => "Applying hook " . get_class($callback[0]) . "::" . $callback[1], "message" => $e->getMessage()));
+ }
+ $index++;
+ if($index > 200) {
+ AJXP_Logger::error(__CLASS__, __FUNCTION__, "Breaking ShutdownScheduler loop, seems too big (200)");
+ break;
+ }
+ }
+ }
}

0 comments on commit 8086b00

Please sign in to comment.