mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
Clean up merging stuff
This commit is contained in:
6
src copy/Core/Support/MergeableInterface.php
Normal file
6
src copy/Core/Support/MergeableInterface.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php namespace Flarum\Core\Models;
|
||||
|
||||
interface MergeableInterface
|
||||
{
|
||||
public function saveAfter(Model $previous);
|
||||
}
|
23
src copy/Core/Support/MergeableTrait.php
Normal file
23
src copy/Core/Support/MergeableTrait.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php namespace Flarum\Core\Models;
|
||||
|
||||
trait MergeableTrait
|
||||
{
|
||||
public function saveAfter(Model $previous)
|
||||
{
|
||||
if ($previous instanceof static) {
|
||||
if ($merged = $this->mergeInto($previous)) {
|
||||
$merged->save();
|
||||
return $merged;
|
||||
} else {
|
||||
$previous->delete();
|
||||
return $previous;
|
||||
}
|
||||
}
|
||||
|
||||
$this->save();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
abstract protected function mergeInto(Model $previous);
|
||||
}
|
Reference in New Issue
Block a user