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

Migration fixes #2046

Merged
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
14 changes: 10 additions & 4 deletions db/migrations/20220915100902_add_fonts_table_migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public function change()
foreach ($this->fetchAll('SELECT mediaId, name, type, createdDt, modifiedDt, storedAs, md5, fileSize, originalFileName FROM `media` WHERE media.type = \'font\'') as $fontMedia) {//phpcs:ignore
$table
->insert([
'createdAt' => $fontMedia['createdDt'],
'modifiedAt' => $fontMedia['modifiedDt'],
'createdAt' => $fontMedia['createdDt'] ?: null,
'modifiedAt' => $fontMedia['modifiedDt'] ?: null,
'name' => $fontMedia['name'],
'fileName' => $fontMedia['originalFileName'],
'familyName' => strtolower(preg_replace(
Expand All @@ -91,11 +91,17 @@ public function change()
);

// remove any potential widget links (there shouldn't be any)
$this->execute('DELETE FROM `lkwidgetmedia` WHERE `lkwidgetmedia`.`mediaId` = ' . $fontMedia['mediaId']);
$this->execute('DELETE FROM `lkwidgetmedia` WHERE `lkwidgetmedia`.`mediaId` = '
. $fontMedia['mediaId']);

// remove any potential tagLinks from font media files
// otherwise we risk failing the migration on the next step when we remove records from media table.
$this->execute('DELETE FROM `lktagmedia` WHERE `lktagmedia`.`mediaId` = ' . $fontMedia['mediaId']);
$this->execute('DELETE FROM `lktagmedia` WHERE `lktagmedia`.`mediaId` = '
. $fontMedia['mediaId']);

// font files assigned directly to the Display.
$this->execute('DELETE FROM `lkmediadisplaygroup` WHERE `lkmediadisplaygroup`.mediaId = '
. $fontMedia['mediaId']);
}

// delete font records from media table
Expand Down
96 changes: 77 additions & 19 deletions db/migrations/20220928091249_player_software_refactor_migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ public function change()
->addColumn('modifiedAt', 'datetime', ['null' => true, 'default' => null])
->addColumn('modifiedBy', 'string', ['null' => true, 'default' => null])
->addColumn('fileName', 'string')
->addColumn('size', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_BIG, 'default' => null, 'null' => true])
->addColumn(
'size',
'integer',
['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_BIG, 'default' => null, 'null' => true]
)
->addColumn('md5', 'string', ['limit' => 32, 'default' => null, 'null' => true])
->save();

// create playersoftware sub-folder in the library location
$libraryLocation = $this->fetchRow('
SELECT `setting`.value
SELECT `setting`.`value`
FROM `setting`
WHERE `setting`.setting = \'LIBRARY_LOCATION\'')[0] ?? null;
WHERE `setting`.`setting` = \'LIBRARY_LOCATION\'')[0] ?? null;

// New installs won't have a library location yet (if they are non-docker).
if (!empty($libraryLocation)) {
Expand All @@ -56,23 +60,58 @@ public function change()
}

// get all existing playersoftware records in media table and convert them
foreach ($this->fetchAll('SELECT mediaId, name, type, createdDt, modifiedDt, storedAs, md5, fileSize, originalFileName FROM `media` WHERE media.type = \'playersoftware\'') as $playersoftwareMedia) {
$this->execute('UPDATE `player_software` SET createdAt = \'' . $playersoftwareMedia['createdDt'] . '\',
modifiedAt = \'' . $playersoftwareMedia['modifiedDt'] . '\',
fileName = \'' . $playersoftwareMedia['originalFileName'] . '\',
size = ' . $playersoftwareMedia['fileSize'] . ',
md5 = \'' . $playersoftwareMedia['md5'] . '\'
WHERE `player_software`.mediaId = ' . $playersoftwareMedia['mediaId']);
$sql = '
SELECT `mediaId`,
`name`,
`type`,
`createdDt`,
`modifiedDt`,
`storedAs`,
`md5`,
`fileSize`,
`originalFileName`
FROM `media`
WHERE `media`.`type` = \'playersoftware\'
';

$updateSql = '
UPDATE `player_software`
SET `createdAt` = :createdAt,
`modifiedAt` = :modifiedAt,
`fileName` = :fileName,
`size` = :size,
`md5` = :md5
WHERE `mediaId` = :mediaId
';

foreach ($this->fetchAll($sql) as $playersoftwareMedia) {
$this->execute($updateSql, [
'mediaId' => $playersoftwareMedia['mediaId'],
'createdAt' => $playersoftwareMedia['createdDt'] ?: null,
'modifiedAt' => $playersoftwareMedia['modifiedDt'] ?: null,
'fileName' => $playersoftwareMedia['originalFileName'],
'size' => $playersoftwareMedia['fileSize'],
'md5' => $playersoftwareMedia['md5']
]);

// move the stored files with new id to fonts folder
rename($libraryLocation . $playersoftwareMedia['storedAs'], $libraryLocation . 'playersoftware/' . $playersoftwareMedia['originalFileName']);
rename(
$libraryLocation . $playersoftwareMedia['storedAs'],
$libraryLocation . 'playersoftware/' . $playersoftwareMedia['originalFileName']
);

// remove any potential widget links (there shouldn't be any)
$this->execute('DELETE FROM `lkwidgetmedia` WHERE `lkwidgetmedia`.`mediaId` = ' . $playersoftwareMedia['mediaId']);
$this->execute('DELETE FROM `lkwidgetmedia` WHERE `lkwidgetmedia`.`mediaId` = '
. $playersoftwareMedia['mediaId']);

// remove any potential tagLinks from playersoftware media files
// unlikely that there will be any, but just in case.
$this->execute('DELETE FROM `lktagmedia` WHERE `lktagmedia`.mediaId = ' . $playersoftwareMedia['mediaId']);
$this->execute('DELETE FROM `lktagmedia` WHERE `lktagmedia`.mediaId = '
. $playersoftwareMedia['mediaId']);

// player software files assigned directly to the Display.
$this->execute('DELETE FROM `lkmediadisplaygroup` WHERE `lkmediadisplaygroup`.mediaId = '
. $playersoftwareMedia['mediaId']);
}

// update versionMediaId in displayProfiles config
Expand All @@ -81,10 +120,20 @@ public function change()
if (!empty($displayProfile['config']) && $displayProfile['config'] !== '[]') {
$config = json_decode($displayProfile['config'], true);
for ($i = 0; $i < count($config); $i++) {
if ($config[$i]['name'] === 'versionMediaId') {
$row = $this->fetchRow('SELECT mediaId, versionId FROM `player_software` WHERE `player_software`.mediaId =' . $config[$i]['value']);
$configValue = $config[$i]['value'] ?? 0;

if (!empty($configValue) && $config[$i]['name'] === 'versionMediaId') {
$row = $this->fetchRow(
'SELECT mediaId, versionId
FROM `player_software`
WHERE `player_software`.mediaId =' . $configValue
);
$config[$i]['value'] = $row['versionId'];
$this->execute('UPDATE `displayprofile` SET config = \'' . json_encode($config) . '\' WHERE `displayprofile`.displayProfileId =' . $displayProfile['displayProfileId']);
$this->execute(
'UPDATE `displayprofile`
SET config = \'' . json_encode($config) . '\'
WHERE `displayprofile`.displayProfileId =' . $displayProfile['displayProfileId']
);
}
}
}
Expand All @@ -96,10 +145,19 @@ public function change()
if (!empty($display['overrideConfig']) && $display['overrideConfig'] !== '[]') {
$overrideConfig = json_decode($display['overrideConfig'], true);
for ($i = 0; $i < count($overrideConfig); $i++) {
if ($overrideConfig[$i]['name'] === 'versionMediaId') {
$row = $this->fetchRow('SELECT mediaId, versionId FROM `player_software` WHERE `player_software`.mediaId =' . $overrideConfig[$i]['value']);
$overrideConfigValue = $overrideConfig[$i]['value'] ?? 0;
if (!empty($overrideConfigValue) && $overrideConfig[$i]['name'] === 'versionMediaId') {
$row = $this->fetchRow(
'SELECT mediaId, versionId
FROM `player_software`
WHERE `player_software`.mediaId =' . $overrideConfigValue
);
$overrideConfig[$i]['value'] = $row['versionId'];
$this->execute('UPDATE `display` SET overrideConfig = \'' . json_encode($overrideConfig) . '\' WHERE `display`.displayId =' . $display['displayId']);
$this->execute(
'UPDATE `display`
SET overrideConfig = \'' . json_encode($overrideConfig) . '\'
WHERE `display`.displayId =' . $display['displayId']
);
}
}
}
Expand Down
Loading