1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 16:36:47 +02:00

Clean up merging stuff

This commit is contained in:
Toby Zerner
2015-07-01 16:31:06 +09:30
parent 3f32236379
commit d44b101373
7 changed files with 162 additions and 118 deletions

View 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);
}