Skip to content

Commit

Permalink
update dirty method for get/set
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Cansado Solà authored and Albert Cansado Solà committed Jun 23, 2017
1 parent ff5b828 commit 3d9e873
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 142 deletions.
6 changes: 3 additions & 3 deletions src/ORM/Association/BelongsToMany.php
Expand Up @@ -817,7 +817,7 @@ protected function _saveLinks(EntityInterface $sourceEntity, $targetEntities, $o
}

$e->set($jointProperty, $joint);
$e->dirty($jointProperty, false);
$e->setDirty($jointProperty, false);
}

return true;
Expand Down Expand Up @@ -942,7 +942,7 @@ function () use ($sourceEntity, $targetEntities, $options) {
}

$sourceEntity->set($property, array_values($existing));
$sourceEntity->dirty($property, false);
$sourceEntity->setDirty($property, false);

return true;
}
Expand Down Expand Up @@ -1199,7 +1199,7 @@ function () use ($sourceEntity, $targetEntities, $primaryValue, $options) {

ksort($targetEntities);
$sourceEntity->set($property, array_values($targetEntities));
$sourceEntity->dirty($property, false);
$sourceEntity->setDirty($property, false);

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Association/HasMany.php
Expand Up @@ -274,7 +274,7 @@ public function link(EntityInterface $sourceEntity, array $targetEntities, array

if ($ok) {
$sourceEntity->set($property, $savedEntity->get($property));
$sourceEntity->dirty($property, false);
$sourceEntity->setDirty($property, false);
}

return $ok;
Expand Down Expand Up @@ -361,7 +361,7 @@ function ($assoc) use ($targetEntities) {
);
}

$sourceEntity->dirty($property, false);
$sourceEntity->setDirty($property, false);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/AssociationCollection.php
Expand Up @@ -250,7 +250,7 @@ protected function _saveAssociations($table, $entity, $associations, $options, $
*/
protected function _save($association, $entity, $nested, $options)
{
if (!$entity->dirty($association->getProperty())) {
if (!$entity->isDirty($association->getProperty())) {
return true;
}
if (!empty($nested)) {
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Behavior/CounterCacheBehavior.php
Expand Up @@ -132,7 +132,7 @@ public function beforeSave(Event $event, EntityInterface $entity, $options)
if (!is_callable($config) &&
isset($config['ignoreDirty']) &&
$config['ignoreDirty'] === true &&
$entity->$entityAlias->dirty($field)
$entity->$entityAlias->isDirty($field)
) {
$this->_ignoreDirty[$registryAlias][$field] = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Behavior/TimestampBehavior.php
Expand Up @@ -172,7 +172,7 @@ public function touch(EntityInterface $entity, $eventName = 'Model.beforeSave')
foreach ($events[$eventName] as $field => $when) {
if (in_array($when, ['always', 'existing'])) {
$return = true;
$entity->dirty($field, false);
$entity->setDirty($field, false);
$this->_updateField($entity, $field, $refresh);
}
}
Expand All @@ -190,7 +190,7 @@ public function touch(EntityInterface $entity, $eventName = 'Model.beforeSave')
*/
protected function _updateField($entity, $field, $refreshTimestamp)
{
if ($entity->dirty($field)) {
if ($entity->isDirty($field)) {
return;
}
$entity->set($field, $this->timestamp(null, $refreshTimestamp));
Expand Down
10 changes: 5 additions & 5 deletions src/ORM/Behavior/TranslateBehavior.php
Expand Up @@ -308,7 +308,7 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o
// entity persists.
if ($noFields && $bundled && !$key) {
foreach ($this->_config['fields'] as $field) {
$entity->dirty($field, true);
$entity->setDirty($field, true);
}

return;
Expand Down Expand Up @@ -346,10 +346,10 @@ public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $o

$entity->set('_i18n', array_merge($bundled, array_values($modified + $new)));
$entity->set('_locale', $locale, ['setter' => false]);
$entity->dirty('_locale', false);
$entity->setDirty('_locale', false);

foreach ($fields as $field) {
$entity->dirty($field, false);
$entity->setDirty($field, false);
}
}

Expand Down Expand Up @@ -602,7 +602,7 @@ protected function _bundleTranslatedFields($entity)
{
$translations = (array)$entity->get('_translations');

if (empty($translations) && !$entity->dirty('_translations')) {
if (empty($translations) && !$entity->isDirty('_translations')) {
return;
}

Expand All @@ -614,7 +614,7 @@ protected function _bundleTranslatedFields($entity)

foreach ($translations as $lang => $translation) {
foreach ($fields as $field) {
if (!$translation->dirty($field)) {
if (!$translation->isDirty($field)) {
continue;
}
$find[] = ['locale' => $lang, 'field' => $field, 'foreign_key' => $key];
Expand Down
14 changes: 7 additions & 7 deletions src/ORM/Behavior/TreeBehavior.php
Expand Up @@ -100,7 +100,7 @@ public function beforeSave(Event $event, EntityInterface $entity)
$config = $this->getConfig();
$parent = $entity->get($config['parent']);
$primaryKey = $this->_getPrimaryKey();
$dirty = $entity->dirty($config['parent']);
$dirty = $entity->isDirty($config['parent']);
$level = $config['level'];

if ($parent && $entity->get($primaryKey) == $parent) {
Expand Down Expand Up @@ -585,7 +585,7 @@ protected function _removeFromTree($node)
$this->_table->updateAll($node->extract($fields), [$primary => $node->get($primary)]);

foreach ($fields as $field) {
$node->dirty($field, false);
$node->setDirty($field, false);
}

return $node;
Expand Down Expand Up @@ -675,8 +675,8 @@ protected function _moveUp($node, $number)
$node->set($left, $targetLeft);
$node->set($right, $targetLeft + ($nodeRight - $nodeLeft));

$node->dirty($left, false);
$node->dirty($right, false);
$node->setDirty($left, false);
$node->setDirty($right, false);

return $node;
}
Expand Down Expand Up @@ -765,8 +765,8 @@ protected function _moveDown($node, $number)
$node->set($left, $targetRight - ($nodeRight - $nodeLeft));
$node->set($right, $targetRight);

$node->dirty($left, false);
$node->dirty($right, false);
$node->setDirty($left, false);
$node->setDirty($right, false);

return $node;
}
Expand Down Expand Up @@ -960,7 +960,7 @@ protected function _ensureFields($entity)
$entity->set($fresh->extract($fields), ['guard' => false]);

foreach ($fields as $field) {
$entity->dirty($field, false);
$entity->setDirty($field, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ORM/LazyEagerLoader.php
Expand Up @@ -155,7 +155,7 @@ protected function _injectResults($objects, $results, $associations, $source)
foreach ($associations as $assoc) {
$property = $properties[$assoc];
$object->set($property, $loaded->get($property), ['useSetters' => false]);
$object->dirty($property, false);
$object->setDirty($property, false);
}
$injected[$k] = $object;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Marshaller.php
Expand Up @@ -578,7 +578,7 @@ public function merge(EntityInterface $entity, array $data, array $options = [])

foreach ($properties as $field => $value) {
if ($value instanceof EntityInterface) {
$entity->dirty($field, $value->dirty());
$entity->setDirty($field, $value->isDirty());
}
}

Expand All @@ -589,7 +589,7 @@ public function merge(EntityInterface $entity, array $data, array $options = [])
if (array_key_exists($field, $properties)) {
$entity->set($field, $properties[$field]);
if ($properties[$field] instanceof EntityInterface) {
$entity->dirty($field, $properties[$field]->dirty());
$entity->isDirty($field, $properties[$field]->isDirty());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Table.php
Expand Up @@ -1715,7 +1715,7 @@ public function save(EntityInterface $entity, $options = [])
return false;
}

if ($entity->isNew() === false && !$entity->dirty()) {
if ($entity->isNew() === false && !$entity->isDirty()) {
return $entity;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/ORM/Association/BelongsToManyTest.php
Expand Up @@ -687,7 +687,7 @@ public function testReplaceLinksUpdateToEmptySet()

$assoc->replaceLinks($entity, []);
$this->assertSame([], $entity->tags, 'Property should be empty');
$this->assertFalse($entity->dirty('tags'), 'Property should be cleaned');
$this->assertFalse($entity->isDirty('tags'), 'Property should be cleaned');

$new = $articles->get(1, ['contain' => 'Tags']);
$this->assertSame([], $entity->tags, 'Should not be data in db');
Expand Down Expand Up @@ -724,7 +724,7 @@ public function testReplaceLinkSuccess()
$result = $assoc->replaceLinks($entity, $tagData, ['associated' => false]);
$this->assertTrue($result);
$this->assertSame($tagData, $entity->tags, 'Tags should match replaced objects');
$this->assertFalse($entity->dirty('tags'), 'Should be clean');
$this->assertFalse($entity->isDirty('tags'), 'Should be clean');

$fresh = $articles->get(1, ['contain' => 'Tags']);
$this->assertCount(3, $fresh->tags, 'Records should be in db');
Expand Down Expand Up @@ -759,7 +759,7 @@ public function testReplaceLinkWithConditions()
$result = $assoc->replaceLinks($entity, [], ['associated' => false]);
$this->assertTrue($result);
$this->assertSame([], $entity->tags, 'Tags should match replaced objects');
$this->assertFalse($entity->dirty('tags'), 'Should be clean');
$this->assertFalse($entity->isDirty('tags'), 'Should be clean');

$fresh = $articles->get(1, ['contain' => 'Tags']);
$this->assertCount(0, $fresh->tags, 'Association should be empty');
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/ORM/Behavior/Translate/TranslateTraitTest.php
Expand Up @@ -40,7 +40,7 @@ public function testTranslationCreate()
$entity->translation('eng')->set('title', 'My Title');
$this->assertEquals('My Title', $entity->translation('eng')->get('title'));

$this->assertTrue($entity->dirty('_translations'));
$this->assertTrue($entity->isDirty('_translations'));

$entity->translation('spa')->set('body', 'Contenido');
$this->assertEquals('My Title', $entity->translation('eng')->get('title'));
Expand Down Expand Up @@ -95,6 +95,6 @@ public function testTranslationDirty()
]);
$entity->clean();
$this->assertEquals('My Title', $entity->translation('eng')->get('title'));
$this->assertTrue($entity->dirty('_translations'));
$this->assertTrue($entity->isDirty('_translations'));
}
}
18 changes: 9 additions & 9 deletions tests/TestCase/ORM/EntityTest.php
Expand Up @@ -531,9 +531,9 @@ public function testUnset()
public function testUnsetMakesClean()
{
$entity = new Entity(['id' => 1, 'name' => 'bar']);
$this->assertTrue($entity->dirty('name'));
$this->assertTrue($entity->isDirty('name'));
$entity->unsetProperty('name');
$this->assertFalse($entity->dirty('name'), 'Removed properties are not dirty.');
$this->assertFalse($entity->isDirty('name'), 'Removed properties are not dirty.');
}

/**
Expand Down Expand Up @@ -873,14 +873,14 @@ public function testClean()
'title' => 'Foo',
'author_id' => 3
]);
$this->assertTrue($entity->dirty('id'));
$this->assertTrue($entity->dirty('title'));
$this->assertTrue($entity->dirty('author_id'));
$this->assertTrue($entity->isDirty('id'));
$this->assertTrue($entity->isDirty('title'));
$this->assertTrue($entity->isDirty('author_id'));

$entity->clean();
$this->assertFalse($entity->dirty('id'));
$this->assertFalse($entity->dirty('title'));
$this->assertFalse($entity->dirty('author_id'));
$this->assertFalse($entity->isDirty('id'));
$this->assertFalse($entity->isDirty('title'));
$this->assertFalse($entity->isDirty('author_id'));
}

/**
Expand Down Expand Up @@ -1472,7 +1472,7 @@ public function testDebugInfo()
$entity->accessible('id', false);
$entity->accessible('name', true);
$entity->virtualProperties(['baz']);
$entity->dirty('foo', true);
$entity->setDirty('foo', true);
$entity->errors('foo', ['An error']);
$entity->invalid('foo', 'a value');
$entity->source('foos');
Expand Down

0 comments on commit 3d9e873

Please sign in to comment.