Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboards: no data being returned/requested by the player #2064

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/Connector/ConnectorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -174,7 +174,13 @@ public function getClient(): Client
return new Client($this->httpOptions);
}

public function getLayoutPreviewUrl($token)
/**
* Return a layout preview URL for the provided connector token
* this can be used in a data request and is decorated by the previewing function.
* @param string $token
* @return string
*/
public function getTokenUrl(string $token): string
{
return '[[connector='.$token.']]';
}
Expand Down
12 changes: 2 additions & 10 deletions lib/Connector/XiboDashboardConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use Xibo\Support\Exception\InvalidArgumentException;
use Xibo\Support\Exception\NotFoundException;
use Xibo\Support\Sanitizer\SanitizerInterface;
use Xibo\Xmds\Wsdl;

/**
* Xibo Dashboard Service connector.
Expand Down Expand Up @@ -532,16 +531,9 @@ public function onDataRequest(DashboardDataRequestEvent $event, $eventName, Even
return;
}

if ($event->getDataProvider()->isPreview()) {
$url = $this->getLayoutPreviewUrl($token);
} else {
// This is fallback HTML for the player.
// so output a link to the XMDS file request.
$url = Wsdl::getRoot() . '?connector=true&token=' . $token;
}

// We return a single data item which contains our URL, token and whether we're a preview
$item = [];
$item['url'] = $url;
$item['url'] = $this->getTokenUrl($token);
$item['token'] = $token;
$item['isPreview'] = $event->getDataProvider()->isPreview();

Expand Down
1 change: 1 addition & 0 deletions lib/Controller/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ public function getData(Request $request, Response $response, $regionId, $id)
$this->getConfig()->getSetting('DEFAULT_LAT'),
$this->getConfig()->getSetting('DEFAULT_LONG')
);
$dataProvider->setIsPreview(true);

$widgetInterface = $module->getWidgetProviderOrNull();
$widgetDataProviderCache = $this->moduleFactory->createWidgetDataProviderCache();
Expand Down
6 changes: 5 additions & 1 deletion lib/Factory/ModuleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ public function determineCacheKey(
// Determinthe cache key from the setting in XML.
if (empty($module->dataCacheKey)) {
// Best we can do here is a cache per widget, but we should log this as an error.
$this->getLog()->debug('getData: module without dataCacheKey: ' . $module->moduleId);
$this->getLog()->debug('determineCacheKey: module without dataCacheKey: ' . $module->moduleId);
$cacheKey = $widget->widgetId;
} else {
// Start with the one provided
$this->getLog()->debug('determineCacheKey: module dataCacheKey: ' . $module->dataCacheKey);

$cacheKey = $module->dataCacheKey;

// Properties
Expand All @@ -183,6 +185,8 @@ public function determineCacheKey(
}
}

$this->getLog()->debug('determineCacheKey: cache key is : ' . $cacheKey);

return $cacheKey;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Widget/DashboardProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -50,7 +50,7 @@ public function fetchDuration(DurationProviderInterface $durationProvider): Widg

public function getDataCacheKey(DataProviderInterface $dataProvider): ?string
{
return $dataProvider->getWidgetId() . '_' . $dataProvider->getDisplayId();
return null;
}

public function getDataModifiedDt(DataProviderInterface $dataProvider): ?Carbon
Expand Down
16 changes: 15 additions & 1 deletion lib/Widget/Provider/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class DataProvider implements DataProviderInterface
/** @var float the display longitude */
private $longitude;

/** @var bool Is this data provider in preview mode? */
private $isPreview = false;

/** @var \GuzzleHttp\Client */
private $client;

Expand Down Expand Up @@ -121,6 +124,17 @@ public function setMediaFactory(MediaFactory $mediaFactory): DataProviderInterfa
return $this;
}

/**
* Set whether this data provider is in preview mode
* @param bool $isPreview
* @return DataProviderInterface
*/
public function setIsPreview(bool $isPreview): DataProviderInterface
{
$this->isPreview = $isPreview;
return $this;
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -166,7 +180,7 @@ public function getDisplayLongitude(): float
*/
public function isPreview(): bool
{
return empty($this->displayId);
return $this->isPreview;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions lib/Widget/Render/WidgetDataProviderCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Xibo\Support\Exception\GeneralException;
use Xibo\Widget\Provider\DataProvider;
use Xibo\Widget\Provider\DataProviderInterface;
use Xibo\Xmds\Wsdl;

/**
* Acts as a cache for the Widget data cache.
Expand Down Expand Up @@ -288,6 +289,8 @@ public function decorateForPlayer(
array $data,
array $storedAs
): array {
$this->getLog()->debug('decorateForPlayer');

foreach ($data as $row => $item) {
// Each data item can be an array or an object
if (is_array($item)) {
Expand Down Expand Up @@ -329,6 +332,14 @@ private function decorateMediaForPlayer(array $storedAs, ?string $data): ?string
} else {
$data = str_replace('[[' . $match . ']]', '', $data);
}
} else if (Str::startsWith($match, 'connector')) {
// We have WSDL here because this is only called from XMDS.
$value = explode('=', $match);
$data = str_replace(
'[[' . $match . ']]',
Wsdl::getRoot() . '?connector=true&token=' . $value[1],
$data
);
}
}
return $data;
Expand Down
2 changes: 2 additions & 0 deletions lib/XTR/WidgetSyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ private function cache(
?WidgetProviderInterface $widgetInterface,
?int $displayId
): array {
$this->getLogger()->debug('cache: ' . $widget->widgetId . ' for display: ' . ($displayId ?? 0));

$mediaIds = [];

// Each time we call this we use a new provider
Expand Down
4 changes: 3 additions & 1 deletion lib/Xmds/Soap.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,9 @@ protected function doRequiredFiles(
// Does this also have an associated data file?
// we add this for < XMDS v7 as well, because the record is used by the widget sync task
// the player shouldn't receive it.
if ($modules[$widget->type]->isDataProviderExpected()) {
if ($modules[$widget->type]->isDataProviderExpected()
|| $modules[$widget->type]->isWidgetProviderAvailable()
) {
// A node specifically for the widget data.
if ($isSupportsDataUrl) {
$dataFile = $requiredFilesXml->createElement('file');
Expand Down
7 changes: 6 additions & 1 deletion lib/Xmds/Soap7.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,16 @@ public function GetData($serverKey, $hardwareKey, $widgetId)
throw new NotFoundException('Cache not ready');
}

$this->getLog()->debug('Cache ready and populated');

// Get media references
$media = [];
$requiredFiles = [];
$mediaIds = $widgetDataProviderCache->getCachedMediaIds();

if (count($mediaIds) > 0) {
// Process media links.
$this->getLog()->debug('Processing media links');

$sql = '
SELECT `media`.`mediaId`,
`media`.`storedAs`,
Expand Down Expand Up @@ -212,6 +215,8 @@ public function GetData($serverKey, $hardwareKey, $widgetId)
),
];
}
} else {
$this->getLog()->debug('No media links');
}

$resource = json_encode([
Expand Down