Skip to content

Commit

Permalink
$model::convertTo() also for changes version
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Feb 20, 2025
1 parent a12b003 commit b313f12
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/Cms/NewModelFixes.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,31 @@ public function content(string|null $languageCode = null): Content
*/
protected function convertTo(string $blueprint): static
{
// first close object with new blueprint as template
// first clone object with new blueprint as template
$new = $this->clone(['template' => $blueprint]);

// get versions
$latest = $this->version(VersionId::latest());
$changes = $this->version(VersionId::changes());
// loop through all versions
foreach (['latest', 'changes'] as $versionId) {
// get version
$version = $this->version($versionId);

foreach (Languages::ensure() as $language) {
// delete changes
$changes->delete($language);
// for all languages
foreach (Languages::ensure() as $language) {
// skip non-existing versions
if ($version->exists($language) === false) {
continue;
}

// skip non-existing versions
if ($latest->exists($language) === false) {
continue;
}

// convert the content to the new blueprint
$content = $latest->content($language)->convertTo($blueprint);
// convert the content to the new blueprint
$content = $version->content($language)->convertTo($blueprint);

// delete the old text file
$latest->delete($language);
// save to re-create the content file
// with the converted/updated content
$new->version($versionId)->save($content, $language);

// save to re-create the content file
// with the converted/updated content
$new->version()->save($content, $language);
// delete the old text file
$version->delete($language);
}
}

return $new;
Expand Down

0 comments on commit b313f12

Please sign in to comment.