20
20
*/
21
21
namespace Pydio \Core \Controller ;
22
22
23
+ use Pydio \Core \Exception \PydioException ;
24
+ use Pydio \Core \Services \ApplicationState ;
23
25
use Pydio \Log \Core \Logger ;
26
+ use Symfony \Component \Console \Output \OutputInterface ;
24
27
25
28
defined ('AJXP_EXEC ' ) or die ('Access not allowed ' );
26
29
/**
@@ -53,23 +56,23 @@ public static function getInstance()
53
56
public function __construct ()
54
57
{
55
58
$ this ->callbacks = array ();
56
- register_shutdown_function (array ($ this , 'callRegisteredShutdown ' ));
57
- ob_start ();
59
+ // register_shutdown_function(array($this, 'callRegisteredShutdown'));
60
+ // ob_start();
58
61
}
59
62
60
63
/**
61
64
* @return bool
62
- * @throws \Exception
65
+ * @throws PydioException
63
66
*/
64
67
public function registerShutdownEventArray ()
65
68
{
66
69
$ callback = func_get_args ();
67
70
68
71
if (empty ($ callback )) {
69
- throw new \ Exception ('No callback passed to ' .__FUNCTION__ .' method ' );
72
+ throw new PydioException ('No callback passed to ' .__FUNCTION__ .' method ' );
70
73
}
71
74
if (!is_callable ($ callback [0 ])) {
72
- throw new \ Exception ('Invalid callback ( ' .$ callback [0 ].') passed to the ' .__FUNCTION__ .' method ' );
75
+ throw new PydioException ('Invalid callback ( ' .$ callback [0 ].') passed to the ' .__FUNCTION__ .' method ' );
73
76
}
74
77
$ flattenArray = array ();
75
78
$ flattenArray [0 ] = $ callback [0 ];
@@ -82,43 +85,41 @@ public function registerShutdownEventArray()
82
85
83
86
/**
84
87
* @return bool
85
- * @throws \Exception
88
+ * @throws PydioException
86
89
*/
87
90
public function registerShutdownEvent ()
88
91
{
89
92
$ callback = func_get_args ();
90
93
91
94
if (empty ($ callback )) {
92
- throw new \ Exception ('No callback passed to ' .__FUNCTION__ .' method ' );
95
+ throw new PydioException ('No callback passed to ' .__FUNCTION__ .' method ' );
93
96
}
94
97
if (!is_callable ($ callback [0 ])) {
95
- throw new \ Exception ('Invalid callback ( ' .$ callback [0 ].') passed to the ' .__FUNCTION__ .' method ' );
98
+ throw new PydioException ('Invalid callback ( ' .$ callback [0 ].') passed to the ' .__FUNCTION__ .' method ' );
96
99
}
97
100
$ this ->callbacks [] = $ callback ;
98
101
return true ;
99
102
}
100
103
101
104
/**
102
105
* Trigger the schedulers
106
+ * @param OutputInterface $cliOutput
103
107
*/
104
- public function callRegisteredShutdown ()
108
+ public function callRegisteredShutdown ($ cliOutput = null )
105
109
{
106
110
session_write_close ();
107
- if (!headers_sent ()) {
108
- $ size = ob_get_length ();
109
- header ("Connection: close \r\n" );
110
- //header("Content-Encoding: none\r\n");
111
- header ("Content-Length: $ size " );
112
- }
113
111
ob_end_flush ();
114
112
flush ();
115
113
$ index = 0 ;
116
114
while (count ($ this ->callbacks )) {
117
115
$ arguments = array_shift ($ this ->callbacks );
118
116
$ callback = array_shift ($ arguments );
119
117
try {
118
+ if ($ cliOutput !== null ){
119
+ $ cliOutput ->writeln ("<comment>--> Applying Shutdown Hook: " . get_class ($ callback [0 ]) .":: " .$ callback [1 ]."</comment> " );
120
+ }
120
121
call_user_func_array ($ callback , $ arguments );
121
- } catch (\ Exception $ e ) {
122
+ } catch (PydioException $ e ) {
122
123
Logger::error (__CLASS__ , __FUNCTION__ , array ("context " => "Applying hook " . get_class ($ callback [0 ]) . ":: " . $ callback [1 ], "message " => $ e ->getMessage ()));
123
124
}
124
125
$ index ++;
0 commit comments