Skip to content

Commit

Permalink
ChromeOS: Upload player version, switch to active.
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner committed Oct 3, 2024
1 parent 35f66f8 commit 3f9c404
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 14 deletions.
30 changes: 26 additions & 4 deletions lib/Controller/DisplayProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ public function editForm(Request $request, Response $response, $id)
}

// Player Version Setting
$versionId = $displayProfile->getSetting('versionMediaId');
$versionId = $displayProfile->type === 'chromeOS'
? $displayProfile->getSetting('playerVersionId')
: $displayProfile->getSetting('versionMediaId');

$playerVersions = [];

// Daypart - Operating Hours
Expand All @@ -358,8 +361,9 @@ public function editForm(Request $request, Response $response, $id)
if ($versionId !== null) {
try {
$playerVersions[] = $this->playerVersionFactory->getById($versionId);
} catch (NotFoundException $e) {
$this->getLog()->debug('Unknown versionId set on Display Profile. ' . $displayProfile->displayProfileId);
} catch (NotFoundException) {
$this->getLog()->debug('Unknown versionId set on Display Profile. '
. $displayProfile->displayProfileId);
}
}

Expand Down Expand Up @@ -456,12 +460,14 @@ public function edit(Request $request, Response $response, $id)
$displayProfile->name = $parsedParams->getString('name');
$displayProfile->isDefault = $parsedParams->getCheckbox('isDefault');

// Track changes to versionMediaId
$originalPlayerVersionId = $displayProfile->getSetting('playerVersionId');

// Different fields for each client type
$this->editConfigFields($displayProfile, $parsedParams);

// Capture and update commands
foreach ($this->commandFactory->query() as $command) {
/* @var \Xibo\Entity\Command $command */
if ($parsedParams->getString('commandString_' . $command->commandId) != null) {
// Set and assign the command
$command->commandString = $parsedParams->getString('commandString_' . $command->commandId);
Expand All @@ -474,6 +480,22 @@ public function edit(Request $request, Response $response, $id)
}
}

// If we are chromeOS and the default profile, has the player version changed?
if ($displayProfile->type === 'chromeOS'
&& ($displayProfile->isDefault || $displayProfile->hasPropertyChanged('isDefault'))
&& ($originalPlayerVersionId !== $displayProfile->getSetting('playerVersionId'))
) {
$this->getLog()->debug('edit: updating symlink to the latest chromeOS version');

// Update a symlink to the new player version.
try {
$version = $this->playerVersionFactory->getById($displayProfile->getSetting('playerVersionId'));
$version->setActive();
} catch (NotFoundException) {
$this->getLog()->error('edit: Player version does not exist');
}
}

// Save the changes
$displayProfile->save();

Expand Down
65 changes: 65 additions & 0 deletions lib/Controller/DisplayProfileConfigFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,71 @@ public function editConfigFields($displayProfile, $sanitizedParams, $config = nu

break;

case 'chromeOS':
if ($sanitizedParams->hasParam('licenceCode')) {
$this->handleChangedSettings('licenceCode', ($ownConfig) ? $displayProfile->getSetting('licenceCode') : $display->getSetting('licenceCode'), $sanitizedParams->getString('licenceCode'), $changedSettings);
$displayProfile->setSetting('licenceCode', $sanitizedParams->getString('licenceCode'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('collectInterval')) {
$this->handleChangedSettings('collectInterval', ($ownConfig) ? $displayProfile->getSetting('collectInterval') : $display->getSetting('collectInterval'), $sanitizedParams->getInt('collectInterval'), $changedSettings);
$displayProfile->setSetting('collectInterval', $sanitizedParams->getInt('collectInterval'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('dayPartId')) {
$this->handleChangedSettings('dayPartId', ($ownConfig) ? $displayProfile->getSetting('dayPartId') : $display->getSetting('dayPartId'), $sanitizedParams->getInt('dayPartId'), $changedSettings);
$displayProfile->setSetting('dayPartId', $sanitizedParams->getInt('dayPartId'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('xmrNetworkAddress')) {
$this->handleChangedSettings('xmrNetworkAddress',($ownConfig) ? $displayProfile->getSetting('xmrNetworkAddress') : $display->getSetting('xmrNetworkAddress'), $sanitizedParams->getString('xmrNetworkAddress'), $changedSettings);
$displayProfile->setSetting('xmrNetworkAddress', $sanitizedParams->getString('xmrNetworkAddress'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('statsEnabled')) {
$this->handleChangedSettings('statsEnabled', ($ownConfig) ? $displayProfile->getSetting('statsEnabled') : $display->getSetting('statsEnabled'), $sanitizedParams->getCheckbox('statsEnabled'), $changedSettings);
$displayProfile->setSetting('statsEnabled', $sanitizedParams->getCheckbox('statsEnabled'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('aggregationLevel')) {
$this->handleChangedSettings('aggregationLevel', ($ownConfig) ? $displayProfile->getSetting('aggregationLevel') : $display->getSetting('aggregationLevel'), $sanitizedParams->getString('aggregationLevel'), $changedSettings);
$displayProfile->setSetting('aggregationLevel', $sanitizedParams->getString('aggregationLevel'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('logLevel')) {
$this->handleChangedSettings('logLevel', ($ownConfig) ? $displayProfile->getSetting('logLevel') : $display->getSetting('logLevel'), $sanitizedParams->getString('logLevel'), $changedSettings);
$displayProfile->setSetting('logLevel', $sanitizedParams->getString('logLevel'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('elevateLogsUntil')) {
$this->handleChangedSettings(
'elevateLogsUntil',
($ownConfig)
? $displayProfile->getSetting('elevateLogsUntil')
: $display->getSetting('elevateLogsUntil'),
$sanitizedParams->getDate('elevateLogsUntil')?->format('U'),
$changedSettings
);
$displayProfile->setSetting(
'elevateLogsUntil',
$sanitizedParams->getDate('elevateLogsUntil')?->format('U'),
$ownConfig,
$config
);
}

if ($sanitizedParams->hasParam('playerVersionId')) {
$this->handleChangedSettings('playerVersionId', ($ownConfig) ? $displayProfile->getSetting('playerVersionId') : $display->getSetting('playerVersionId'), $sanitizedParams->getInt('playerVersionId'), $changedSettings);
$displayProfile->setSetting('playerVersionId', $sanitizedParams->getInt('playerVersionId'), $ownConfig, $config);
}

if ($sanitizedParams->hasParam('screenShotSize')) {
$this->handleChangedSettings('screenShotSize', ($ownConfig) ? $displayProfile->getSetting('screenShotSize') : $display->getSetting('screenShotSize'), $sanitizedParams->getInt('screenShotSize'), $changedSettings);
$displayProfile->setSetting('screenShotSize', $sanitizedParams->getInt('screenShotSize'), $ownConfig, $config);
}

break;

default:
if ($displayProfile->isCustom()) {
$this->getLog()->info('Edit for custom Display profile type ' . $displayProfile->getClientType());
Expand Down
9 changes: 8 additions & 1 deletion lib/Controller/PlayerSoftware.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,20 @@ public function delete(Request $request, Response $response, $id)
$displayProfiles = $this->displayProfileFactory->query();

foreach ($displayProfiles as $displayProfile) {
if (in_array($displayProfile->type, ['android', 'lg', 'sssp', 'chromeOS'])) {
if (in_array($displayProfile->type, ['android', 'lg', 'sssp'])) {
$currentVersionId = $displayProfile->getSetting('versionMediaId');

if ($currentVersionId === $version->versionId) {
$displayProfile->setSetting('versionMediaId', null);
$displayProfile->save();
}
} else if ($displayProfile->type === 'chromeOS') {
$currentVersionId = $displayProfile->getSetting('playerVersionId');

if ($currentVersionId === $version->versionId) {
$displayProfile->setSetting('playerVersionId', null);
$displayProfile->save();
}
}
}

Expand Down
23 changes: 20 additions & 3 deletions lib/Entity/PlayerVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ public function delete()
}

// delete unpacked file
if (is_dir($libraryLocation . 'playersoftware/chromeOS/' . $this->versionId)) {
(new Filesystem())->remove($libraryLocation . 'playersoftware/chromeOS/' . $this->versionId);
if (is_dir($libraryLocation . 'playersoftware/chromeos/' . $this->versionId)) {
(new Filesystem())->remove($libraryLocation . 'playersoftware/chromeos/' . $this->versionId);
}
}

Expand All @@ -222,13 +222,15 @@ public function unpack(string $libraryFolder): static
if ($this->type === 'chromeOS') {
$this->getLog()->debug('add: handling chromeOS upload');

// TODO: check the signature of the file to make sure it comes from a verified source.

$zip = new \ZipArchive();
if (!$zip->open($libraryFolder . 'playersoftware/' . $this->fileName)) {
throw new InvalidArgumentException(__('Unable to open ZIP'));
}

// Make a folder for this
$folder = $libraryFolder . 'playersoftware/chromeOS/' . $this->versionId;
$folder = $libraryFolder . 'playersoftware/chromeos/' . $this->versionId;
if (is_dir($folder)) {
unlink($folder);
}
Expand All @@ -242,6 +244,21 @@ public function unpack(string $libraryFolder): static
return $this;
}

public function setActive(): static
{
if ($this->type === 'chromeOS') {
$this->getLog()->debug('setActive: set this version to be the latest');

$chromeLocation = $this->config->getSetting('LIBRARY_LOCATION') . 'playersoftware/chromeos';
if (is_link($chromeLocation . '/latest')) {
unlink($chromeLocation . '/latest');
}
symlink($chromeLocation . '/' . $this->versionId, $chromeLocation . '/latest');
}

return $this;
}

/**
* Load
*/
Expand Down
6 changes: 3 additions & 3 deletions lib/Factory/DisplayProfileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,8 @@ public function loadForType($type)
['name' => 'serverPort', 'default' => 9696],
],
'chromeOS' => [
['name' => 'emailAddress', 'default' => ''],
['name' => 'licenceCode', 'default' => ''],
['name' => 'collectInterval', 'default' => 300],
['name' => 'dayPartId', 'default' => null],
['name' => 'xmrNetworkAddress', 'default' => ''],
[
'name' => 'statsEnabled',
Expand All @@ -395,9 +394,10 @@ public function loadForType($type)
'default' => $this->config->getSetting('DISPLAY_PROFILE_AGGREGATION_LEVEL_DEFAULT'),
'type' => 'string',
],
['name' => 'playerVersionId', 'default' => null],
['name' => 'dayPartId', 'default' => null],
['name' => 'logLevel', 'default' => 'error'],
['name' => 'elevateLogsUntil', 'default' => 0, 'type' => 'int'],
['name' => 'versionMediaId', 'default' => null],
['name' => 'screenShotRequestInterval', 'default' => 0, 'type' => 'int'],
[
'name' => 'screenShotSize',
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/MediaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ public static function ensureLibraryExists($libraryFolder)
mkdir($libraryFolder . '/playersoftware', 0777, true);
}

if (!file_exists($libraryFolder . '/playersoftware/chromeOS')) {
mkdir($libraryFolder . '/playersoftware/chromeOS', 0777, true);
if (!file_exists($libraryFolder . '/playersoftware/chromeos')) {
mkdir($libraryFolder . '/playersoftware/chromeos', 0777, true);
}

if (!file_exists($libraryFolder . '/savedreport')) {
Expand Down
Loading

0 comments on commit 3f9c404

Please sign in to comment.