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

Revert not change data #84

Open
SirajCse opened this issue Aug 17, 2024 · 0 comments
Open

Revert not change data #84

SirajCse opened this issue Aug 17, 2024 · 0 comments

Comments

@SirajCse
Copy link
Contributor

Revert not work
$post->getVersion(3)->revert();
$post->revertToVersion(3);

without comment out when VersionStrategy::DIFF

// if (! empty($this->contents)) {
// $this->versionable->setRawAttributes(array_merge($original, $this->contents));
// }

public function revertWithoutSaving(): ?Model
 {
     $original = $this->versionable->getRawOriginal();
     switch ($this->versionable->getVersionStrategy()) {
         case VersionStrategy::DIFF:
             // v1 + ... + vN
             $versionsBeforeThis = $this->previousVersions()->orderOldestFirst()->get();

             foreach ($versionsBeforeThis as $version) {
                 if (! empty($version->contents)) {
                     $this->versionable->setRawAttributes(array_merge($original, $version->contents));
                 }
             }
             break;
         case VersionStrategy::SNAPSHOT:
             // v1 + vN
             /** @var \Overtrue\LaravelVersionable\Version $initVersion */
             $initVersion = $this->versionable->versions()->first();
             if (! empty($initVersion->contents)) {
                 $this->versionable->setRawAttributes(array_merge($original, $initVersion->contents));
             }
     }

//        if (! empty($this->contents)) {
//            $this->versionable->setRawAttributes(array_merge($original, $this->contents));
//        }

     return $this->versionable;
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant