Skip to content

Commit

Permalink
Merge pull request #392 from xibosignage/release18
Browse files Browse the repository at this point in the history
1.8.11 pre-release (will updated latest tag)
  • Loading branch information
dasgarner authored Jul 9, 2018
2 parents b3f84ed + 0dbbc65 commit 64be3d6
Show file tree
Hide file tree
Showing 11 changed files with 282 additions and 147 deletions.
2 changes: 1 addition & 1 deletion bin/run.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
* Spring Signage Ltd - http://www.springsignage.com
* Copyright (C) 2016 Spring Signage Ltd
* Copyright (C) 2016-2018 Spring Signage Ltd
* (run.php)
*
* Xibo is free software: you can redistribute it and/or modify
Expand Down
18 changes: 16 additions & 2 deletions lib/Controller/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,17 @@ function editForm($displayId)
$timeZones[] = ['id' => $key, 'value' => $value];
}

// Get the currently assigned default layout
try {
$layouts = (($display->defaultLayoutId != null) ? [$this->layoutFactory->getById($display->defaultLayoutId)] : []);
} catch (NotFoundException $notFoundException) {
$layouts = [];
}

$this->getState()->template = 'display-form-edit';
$this->getState()->setData([
'display' => $display,
'layouts' => (($display->defaultLayoutId != null) ? [$this->layoutFactory->getById($display->defaultLayoutId)] : []),
'layouts' => $layouts,
'profiles' => $this->displayProfileFactory->query(NULL, array('type' => $display->clientType)),
'settings' => $profile,
'timeZones' => $timeZones,
Expand Down Expand Up @@ -1486,10 +1493,17 @@ public function defaultLayoutForm($displayId)
if (!$this->getUser()->checkEditable($display))
throw new AccessDeniedException();

// Get the currently assigned default layout
try {
$layouts = (($display->defaultLayoutId != null) ? [$this->layoutFactory->getById($display->defaultLayoutId)] : []);
} catch (NotFoundException $notFoundException) {
$layouts = [];
}

$this->getState()->template = 'display-form-defaultlayout';
$this->getState()->setData([
'display' => $display,
'layouts' => [$this->layoutFactory->getById($display->defaultLayoutId)]
'layouts' => $layouts
]);
}

Expand Down
77 changes: 35 additions & 42 deletions lib/Controller/Task.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
<?php
/*
* Spring Signage Ltd - http://www.springsignage.com
* Copyright (C) 2016 Spring Signage Ltd
* (Task.php)
/**
* Copyright (C) 2016-2018 Spring Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/


namespace Xibo\Controller;
use Stash\Interfaces\PoolInterface;
use Xibo\Exception\NotFoundException;
Expand Down Expand Up @@ -434,32 +448,20 @@ public function poll()
{
$this->getLog()->debug('XTR poll started');

// Process timeouts
$this->pollProcessTimeouts();

// The getting/updating of tasks runs in a separate DB connection
// Query for a list of tasks to run.
$db = $this->store->getConnection('xtr');

// This queries for all enabled tasks, because we need to assess the schedule in code
$pollSth = $db->prepare('SELECT taskId, `schedule`, runNow, lastRunDt FROM `task` WHERE isActive = 1 AND `status` <> :status ORDER BY lastRunDuration');
$sqlForActiveTasks = 'SELECT taskId, `schedule`, runNow, lastRunDt FROM `task` WHERE isActive = 1 AND `status` <> :status ORDER BY lastRunDuration';

// Update statements
$updateSth = $db->prepare('UPDATE `task` SET status = :status WHERE taskId = :taskId');
if (DBVERSION < 133)
$updateStartSth = null;
else
$updateStartSth = $db->prepare('UPDATE `task` SET status = :status, lastRunStartDt = :lastRunStartDt WHERE taskId = :taskId');

$updateFatalErrorSth = $db->prepare('UPDATE `task` SET status = :status, isActive = :isActive, lastRunMessage = :lastRunMessage WHERE taskId = :taskId');
$updateSth = 'UPDATE `task` SET status = :status WHERE taskId = :taskId';

// We loop until we have gone through without running a task
// we select new tasks each time
while (true) {
// Get tasks that aren't running currently
$pollSth->execute(['status' => \Xibo\Entity\Task::$STATUS_RUNNING]);
$this->store->incrementStat('xtr', 'select');

$tasks = $pollSth->fetchAll(\PDO::FETCH_ASSOC);
$tasks = $this->store->select($sqlForActiveTasks, ['status' => \Xibo\Entity\Task::$STATUS_RUNNING], 'xtr', true);

// Assume we wont run anything
$taskRun = false;
Expand All @@ -478,53 +480,44 @@ public function poll()

// Set to running
if (DBVERSION < 133) {
$updateSth->execute([
$this->store->update($updateSth, [
'taskId' => $taskId,
'status' => \Xibo\Entity\Task::$STATUS_RUNNING
]);
], 'xtr');
} else {
$updateStartSth->execute([
$this->store->update('UPDATE `task` SET status = :status, lastRunStartDt = :lastRunStartDt WHERE taskId = :taskId', [
'taskId' => $taskId,
'status' => \Xibo\Entity\Task::$STATUS_RUNNING,
'lastRunStartDt' => $this->getDate()->getLocalDate(null, 'U')
]);
], 'xtr');
}
$this->store->incrementStat('xtr', 'update');
$this->store->commitIfNecessary('xtr');

// Pass to run.
try {
// Run is isolated
$this->run($taskId);

// Set to idle
try {
$updateSth->execute(['taskId' => $taskId, 'status' => \Xibo\Entity\Task::$STATUS_IDLE]);
} catch (\PDOException $PDOException) {
$this->getLog()->info('PDO error updating task status for taskId ' . $taskId . '. E = ' . $PDOException->getMessage());

// Re-connect and prepare new SQL statements.
$db = $this->store->getConnection('xtr');
$updateSth = $db->prepare('UPDATE `task` SET status = :status WHERE taskId = :taskId');
$updateFatalErrorSth = $db->prepare('UPDATE `task` SET status = :status, isActive = :isActive, lastRunMessage = :lastRunMessage WHERE taskId = :taskId');

// retry (if this fails we will throw out to the lower catch block).
$updateSth->execute(['taskId' => $taskId, 'status' => \Xibo\Entity\Task::$STATUS_IDLE]);
}
$this->store->update($updateSth, ['taskId' => $taskId, 'status' => \Xibo\Entity\Task::$STATUS_IDLE], 'xtr', true);

} catch (\Exception $exception) {
// This is a completely unexpected exception, and we should disable the task
$this->getLog()->error('Task run error for taskId ' . $taskId . '. E = ' . $exception->getMessage());

// Set to error
$updateFatalErrorSth->execute([
$this->store->update('
UPDATE `task` SET status = :status, isActive = :isActive, lastRunMessage = :lastRunMessage
WHERE taskId = :taskId
', [
'taskId' => $taskId,
'status' => \Xibo\Entity\Task::$STATUS_ERROR,
'isActive' => 0,
'lastRunMessage' => 'Fatal Error: ' . $exception->getMessage()
]);
], 'xtr', true);
}

$this->store->incrementStat('xtr', 'update');
$this->store->commitIfNecessary('xtr');

// We have run a task
$taskRun = true;
Expand Down
9 changes: 9 additions & 0 deletions lib/Helper/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,13 @@ public static function isDevMode()
{
return (isset($_SERVER['CMS_DEV_MODE']) && $_SERVER['CMS_DEV_MODE'] === 'true');
}

/**
* Is debugging forced ON for this request?
* @return bool
*/
public static function isForceDebugging()
{
return (isset($_SERVER['CMS_FORCE_DEBUG']) && $_SERVER['CMS_FORCE_DEBUG'] === 'true');
}
}
5 changes: 3 additions & 2 deletions lib/Middleware/State.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Copyright (C) 2015 Spring Signage Ltd
* Copyright (C) 2015-2018 Spring Signage Ltd
*
* This file (State.php) is part of Xibo.
*
Expand Down Expand Up @@ -30,6 +30,7 @@
use Xibo\Exception\InstanceSuspendedException;
use Xibo\Exception\UpgradePendingException;
use Xibo\Helper\ApplicationState;
use Xibo\Helper\Environment;
use Xibo\Helper\NullSession;
use Xibo\Helper\Session;
use Xibo\Helper\Translate;
Expand Down Expand Up @@ -221,7 +222,7 @@ public static function setState($app)
$app->logService->setMode($mode);

// Configure logging
if (strtolower($mode) == 'test') {
if (Environment::isForceDebugging() || strtolower($mode) == 'test') {
error_reporting(E_ALL);
ini_set('display_errors', 1);
$app->getLog()->setLevel(\Slim\Log::DEBUG);
Expand Down
Loading

0 comments on commit 64be3d6

Please sign in to comment.