Permalink
Browse files

Fix ShutdownScheduler trigger, do not use output_buffering anymore.

  • Loading branch information...
1 parent cdacb3d commit 76bbd82907521d3f47b68d1fc4585359e803ba5a @cdujeu cdujeu committed Oct 6, 2016
@@ -20,7 +20,10 @@
*/
namespace Pydio\Core\Controller;
+use Pydio\Core\Exception\PydioException;
+use Pydio\Core\Services\ApplicationState;
use Pydio\Log\Core\Logger;
+use Symfony\Component\Console\Output\OutputInterface;
defined('AJXP_EXEC') or die('Access not allowed');
/**
@@ -53,23 +56,23 @@ public static function getInstance()
public function __construct()
{
$this->callbacks = array();
- register_shutdown_function(array($this, 'callRegisteredShutdown'));
- ob_start();
+// register_shutdown_function(array($this, 'callRegisteredShutdown'));
+// ob_start();
}
/**
* @return bool
- * @throws \Exception
+ * @throws PydioException
*/
public function registerShutdownEventArray()
{
$callback = func_get_args();
if (empty($callback)) {
- throw new \Exception('No callback passed to '.__FUNCTION__.' method');
+ throw new PydioException('No callback passed to '.__FUNCTION__.' method');
}
if (!is_callable($callback[0])) {
- throw new \Exception('Invalid callback ('.$callback[0].') passed to the '.__FUNCTION__.' method');
+ throw new PydioException('Invalid callback ('.$callback[0].') passed to the '.__FUNCTION__.' method');
}
$flattenArray = array();
$flattenArray[0] = $callback[0];
@@ -82,43 +85,41 @@ public function registerShutdownEventArray()
/**
* @return bool
- * @throws \Exception
+ * @throws PydioException
*/
public function registerShutdownEvent()
{
$callback = func_get_args();
if (empty($callback)) {
- throw new \Exception('No callback passed to '.__FUNCTION__.' method');
+ throw new PydioException('No callback passed to '.__FUNCTION__.' method');
}
if (!is_callable($callback[0])) {
- throw new \Exception('Invalid callback ('.$callback[0].') passed to the '.__FUNCTION__.' method');
+ throw new PydioException('Invalid callback ('.$callback[0].') passed to the '.__FUNCTION__.' method');
}
$this->callbacks[] = $callback;
return true;
}
/**
* Trigger the schedulers
+ * @param OutputInterface $cliOutput
*/
- public function callRegisteredShutdown()
+ public function callRegisteredShutdown($cliOutput = null)
{
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");
- }
ob_end_flush();
flush();
$index = 0;
while (count($this->callbacks)) {
$arguments = array_shift($this->callbacks);
$callback = array_shift($arguments);
try {
+ if($cliOutput !== null){
+ $cliOutput->writeln("<comment>--> Applying Shutdown Hook: ". get_class($callback[0]) ."::".$callback[1]."</comment>");
+ }
call_user_func_array($callback, $arguments);
- } catch (\Exception $e) {
+ } catch (PydioException $e) {
Logger::error(__CLASS__, __FUNCTION__, array("context" => "Applying hook " . get_class($callback[0]) . "::" . $callback[1], "message" => $e->getMessage()));
}
$index++;
@@ -22,6 +22,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
+use Pydio\Core\Controller\ShutdownScheduler;
use Pydio\Core\Exception\AuthRequiredException;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Exception\WorkspaceNotFoundException;
@@ -64,6 +65,9 @@ public function handleRequest(ServerRequestInterface $requestInterface, Response
$this->emitResponse($requestInterface, $responseInterface);
+ $logHooks = isSet($requestInterface->getParsedBody()["cli-show-hooks"]) ? $output: null;
+ ShutdownScheduler::getInstance()->callRegisteredShutdown($logHooks);
+
} catch (AuthRequiredException $e){
$output->writeln("<error>Authentication Failed</error>");
@@ -22,6 +22,7 @@
use \Psr\Http\Message\ServerRequestInterface;
use \Psr\Http\Message\ResponseInterface;
+use Pydio\Core\Controller\ShutdownScheduler;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Http\Response\SerializableResponseStream;
@@ -125,7 +126,9 @@ public function emitResponse(ServerRequestInterface $request, ResponseInterface
if($response !== false && ($response->getBody()->getSize() || $response instanceof \Zend\Diactoros\Response\EmptyResponse) || $response->getStatusCode() != 200) {
$emitter = new \Zend\Diactoros\Response\SapiEmitter();
+ $response = $response->withHeader("Connection", "close");
$emitter->emit($response);
+ ShutdownScheduler::getInstance()->callRegisteredShutdown();
}
}

0 comments on commit 76bbd82

Please sign in to comment.