1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-26 18:58:21 +02:00
This commit is contained in:
Laurent Cozic 2017-01-08 00:11:47 +01:00
parent 794ede1e4c
commit 4e91446619
3 changed files with 9 additions and 11 deletions

View File

@ -11,15 +11,13 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
public $timestamps = false; public $timestamps = false;
public $useUuid = false; public $useUuid = false;
protected $changedVersionedFieldValues = array(); protected $changedVersionedFieldValues = array();
protected $versionedFields = array(); protected $diffableFields = array();
protected $isVersioned = false; protected $isVersioned = false;
private $isNew = null; private $isNew = null;
private $revId = 0; private $revId = 0;
static private $clientId = null; static private $clientId = null;
static protected $enums = array( static protected $enums = array();
'field' => array('title', 'body', 'completed'),
);
static protected $defaultValidationRules = array(); static protected $defaultValidationRules = array();
static protected $defaultValidationMessages = array( static protected $defaultValidationMessages = array(
'required' => '{key} is required', 'required' => '{key} is required',
@ -133,7 +131,7 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
foreach ($array as $k => $v) { foreach ($array as $k => $v) {
if ($k == 'rev_id') { if ($k == 'rev_id') {
$this->revId = $v; $this->revId = $v;
} else if (in_array($k, $this->versionedFields)) { } else if (in_array($k, $this->diffableFields)) {
$this->changedVersionedFieldValues[$k] = $v; $this->changedVersionedFieldValues[$k] = $v;
} else { } else {
$this->{$k} = $v; $this->{$k} = $v;
@ -164,7 +162,7 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
} }
$maxRevId = 0; $maxRevId = 0;
foreach ($this->versionedFields as $field) { foreach ($this->diffableFields as $field) {
$r = $this->versionedFieldValue($field, true); $r = $this->versionedFieldValue($field, true);
$output[$field] = $r['text']; $output[$field] = $r['text'];
$maxRevId = max($maxRevId, $r['revId']); $maxRevId = max($maxRevId, $r['revId']);
@ -343,7 +341,7 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
public function delete() { public function delete() {
$output = parent::delete(); $output = parent::delete();
if (count($this->versionedFields)) { if (count($this->isVersioned)) {
$this->recordChanges('delete'); $this->recordChanges('delete');
} }
@ -361,11 +359,11 @@ class BaseModel extends \Illuminate\Database\Eloquent\Model {
// //
// When recording an "update" event, all the modified fields are recorded. // When recording an "update" event, all the modified fields are recorded.
foreach ($changedFields as $field => $value) { foreach ($changedFields as $field => $value) {
if ($type == 'create' && !in_array($field, $this->versionedFields)) continue; if ($type == 'create' && !in_array($field, $this->diffableFields)) continue;
$change = $this->newChange($type); $change = $this->newChange($type);
$change->item_field = $field; $change->item_field = $field;
if (in_array($field, $this->versionedFields)) $change->createDelta($changedFields[$field]); if (in_array($field, $this->diffableFields)) $change->createDelta($changedFields[$field]);
$change->save(); $change->save();
} }
} else { } else {

View File

@ -4,7 +4,7 @@ namespace AppBundle\Model;
class Folder extends BaseItem { class Folder extends BaseItem {
protected $versionedFields = array('title'); protected $diffableFields = array('title');
protected $isVersioned = true; protected $isVersioned = true;
public function add($ids) { public function add($ids) {

View File

@ -4,7 +4,7 @@ namespace AppBundle\Model;
class Note extends BaseItem { class Note extends BaseItem {
protected $versionedFields = array('title', 'body'); protected $diffableFields = array('title', 'body');
protected $isVersioned = true; protected $isVersioned = true;
} }