From 8086b007557f2e7e8c733d499aae5551c50af45a Mon Sep 17 00:00:00 2001 From: cdujeu Date: Thu, 2 Jun 2016 09:36:57 +0200 Subject: [PATCH] Fix ShutdownScheduler: if some events are triggered defered during an already defered callback, they can be ignored. --- .../src/pydio/Core/Controller/Controller.php | 3 ++ .../Core/Controller/ShutdownScheduler.php | 44 +++++++++++-------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/core/src/core/src/pydio/Core/Controller/Controller.php b/core/src/core/src/pydio/Core/Controller/Controller.php index 395b0615a0..1bab48fce3 100644 --- a/core/src/core/src/pydio/Core/Controller/Controller.php +++ b/core/src/core/src/pydio/Core/Controller/Controller.php @@ -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(); diff --git a/core/src/core/src/pydio/Core/Controller/ShutdownScheduler.php b/core/src/core/src/pydio/Core/Controller/ShutdownScheduler.php index 1b2caec64a..813d5f1cb9 100644 --- a/core/src/core/src/pydio/Core/Controller/ShutdownScheduler.php +++ b/core/src/core/src/pydio/Core/Controller/ShutdownScheduler.php @@ -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; + } + } + } }