diff --git a/composer.json b/composer.json index db1a18a6d7..ea23ec674d 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "silex/web-profiler" : "~1.0.0", "swiftmailer/swiftmailer" : "~4.3.0", "symfony/symfony" : "2.4.x-dev@dev", - "tecnick.com/tcpdf" : "~6.0", + "alchemy-fr/tcpdf" : "~6.0", "themattharris/tmhoauth" : "~0.7", "twig/twig" : "~1.12", "twig/extensions" : "~1.0", @@ -52,6 +52,12 @@ "behat/mink-selenium2-driver" : "~1.0", "fabpot/goutte" : "~1.0" }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/alchemy-fr/tcpdf-clone" + } + ], "autoload": { "psr-0": { "" : "lib/classes", diff --git a/lib/classes/task/Scheduler.php b/lib/classes/task/Scheduler.php index ebed3c4acc..1b0cb6b667 100644 --- a/lib/classes/task/Scheduler.php +++ b/lib/classes/task/Scheduler.php @@ -34,11 +34,14 @@ class task_Scheduler private $method; private $dependencyContainer; + private $schedstatus; + public function __construct(Application $application, Logger $logger) { declare(ticks = 1); $this->dependencyContainer = $application; $this->logger = $logger; + $this->schedstatus = ''; } protected function log($message) @@ -47,6 +50,7 @@ class task_Scheduler return $this; } + protected function sleep($nsec) { $nsec = (integer) $nsec; @@ -66,10 +70,21 @@ class task_Scheduler */ public function sigHandler($signal) { - $status = null; - $pid = pcntl_wait($status); - $exitstatus = pcntl_wexitstatus($status); - $this->log(sprintf("sigchild %s received from pid=%s, status=%s, exitstatus=%s\n", $signal, $pid, var_export($status, true), $exitstatus)); + switch ($signal) { + case SIGCHLD: + $status = null; + $pid = pcntl_wait($status); + $exitstatus = pcntl_wexitstatus($status); + $this->log(sprintf("SIGCHLD (%s) received from pid=%s, status=%s, exitstatus=%s", $signal, $pid, var_export($status, true), $exitstatus)); + break; + case SIGINT: // ctrl C + $this->log(sprintf("SIGINT (%s) Ctrl-C received, schedstatus='tostop'", $signal)); + $this->schedstatus = 'tostop'; + break; + case SIGTERM: + $this->log(sprintf("SIGTERM (%s) received but ignored, http timeout ?", $signal)); + break; + } } public function run() @@ -99,6 +114,8 @@ class task_Scheduler // pcntl_signal(SIGCHLD, SIG_IGN); // no zombies but no returnValue // pcntl_signal(SIGCHLD, SIG_DFL); // with "declare(ticks=1)" returnValue ok but zombies pcntl_signal(SIGCHLD, array($this, 'sigHandler')); // ok + pcntl_signal(SIGINT, array($this, 'sigHandler')); + pcntl_signal(SIGTERM, array($this, 'sigHandler')); $this->method = self::METHOD_FORK; } @@ -159,11 +176,11 @@ class task_Scheduler } } - $schedstatus = 'started'; + $this->schedstatus = 'started'; $runningtask = 0; $connwaslost = false; - while ($schedstatus == 'started' || $runningtask > 0) { + while ($this->schedstatus == 'started' || $runningtask > 0) { while (1) { try { assert(is_object($conn)); @@ -199,23 +216,25 @@ class task_Scheduler $connwaslost = false; } - $schedstatus = ''; - $row = NULL; - try { - $sql = "SELECT schedstatus FROM sitepreff"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - } catch (ErrorException $e) { - continue; + if ($this->schedstatus == "started") { + $this->schedstatus = ''; + $row = NULL; + try { + $sql = "SELECT schedstatus FROM sitepreff"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + } catch (ErrorException $e) { + continue; + } + + if ($row) { + $this->schedstatus = $row["schedstatus"]; + } } - if ($row) { - $schedstatus = $row["schedstatus"]; - } - - if ($schedstatus == 'tostop') { + if ($this->schedstatus == 'tostop') { $sql = 'UPDATE sitepreff SET schedstatus = "stopping"'; $stmt = $conn->prepare($sql); $stmt->execute(); @@ -337,7 +356,7 @@ class task_Scheduler } } - if ($schedstatus == 'started') { + if ($this->schedstatus == 'started') { $taskPoll[$tkey]["task"]->setState(task_abstract::STATE_TOSTART); } // trick to start the task immediatly : DON'T break if ending with 'tostart' @@ -348,7 +367,7 @@ class task_Scheduler case task_abstract::STATE_TOSTART: // if scheduler is 'tostop', don't launch a new task ! - if ($schedstatus != 'started') { + if ($this->schedstatus != 'started') { break; } @@ -584,8 +603,16 @@ class task_Scheduler break; } } - - $this->sleep($sleeptime); + if(function_exists('pcntl_sigprocmask')) { + @pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD)); + } + $this->sleep(1); + for ($i = 0; $this->schedstatus=='started' && $i < $sleeptime; $i++) { + $this->sleep(1); + } + if(function_exists('pcntl_sigprocmask')) { + @pcntl_sigprocmask(SIG_UNBLOCK, array(SIGCHLD)); + } } $sql = "UPDATE sitepreff SET schedstatus='stopped', schedpid='0'"; diff --git a/lib/classes/task/manager.php b/lib/classes/task/manager.php index 1c02eb1541..2c38f1d37d 100644 --- a/lib/classes/task/manager.php +++ b/lib/classes/task/manager.php @@ -161,6 +161,13 @@ class task_manager if (!in_array($status, $av_status)) throw new Exception(sprintf('unknown status `%s` ', $status)); + if ($status == self::STATE_TOSTOP && function_exists('posix_kill')) { + $gs = $this->getSchedulerState(); + if ($gs['pid'] !== NULL) { + @posix_kill($gs['pid'], 2); // 2 = SIGINT + } + } + $sql = "UPDATE sitepreff SET schedstatus = :schedstatus, schedqtime=NOW()"; $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':schedstatus' => $status)); diff --git a/templates/mobile/common/index.html.twig b/templates/mobile/common/index.html.twig index d405170cfc..812ef8b4c7 100644 --- a/templates/mobile/common/index.html.twig +++ b/templates/mobile/common/index.html.twig @@ -15,23 +15,6 @@ margin: 0px; padding: 0px; } - - .ui-content{ - height: 85%; - width: 100%; - margin: 0px; - padding: 0px; - display:table; - } - - #map { - height: 100%; - width: 100%; - padding: 0px; - display:table-cell; - vertical-align: middle; - text-align: center - } {% block stylesheet %}{% endblock %} {% block icon %}{% endblock %} diff --git a/templates/mobile/common/thumbnail.html.twig b/templates/mobile/common/thumbnail.html.twig index b8d676b229..537e608cef 100644 --- a/templates/mobile/common/thumbnail.html.twig +++ b/templates/mobile/common/thumbnail.html.twig @@ -72,7 +72,6 @@ {% macro format100percent(thumbnail, extraclass)%} {% set record_type = thumbnail.get_type() %} -