數據。 我有一個簡單的實體Gedmo 可記錄的日誌我使用Symfony2.2與StofDoctrineExtensionsBundle(等Gedmo DoctrineExtensions)不發生變化
/**
* @ORM\Entity
* @Gedmo\Loggable
* @ORM\Table(name="person")
*/
class Person {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
[...]
/**
* @ORM\Column(type="datetime", nullable=true)
* @Assert\NotBlank()
* @Assert\Date()
* @Gedmo\Versioned
*/
protected $birthdate;
}
當更改現有對象的屬性,一個日誌條目表ext_log_entries
完成。此日誌表中的條目僅包含更改的列。我可以通過讀取日誌:
$em = $this->getManager();
$repo = $em->getRepository('Gedmo\Loggable\Entity\LogEntry');
$person_repo = $em->getRepository('Acme\MainBundle\Entity\Person');
$person = $person_repo->find(1);
$log = $repo->findBy(array('objectId' => $person->getId()));
foreach ($log as $log_entry) { var_dump($log_entry->getData()); }
但我不明白的是,爲什麼場birthdate
總是包含在一個日誌條目,即使它沒有改變。這裏有三個日誌條目的例子:
array(9) {
["salutation"]=>
string(4) "Herr"
["firstname"]=>
string(3) "Max"
["lastname"]=>
string(6) "Muster"
["street"]=>
string(14) "Musterstraße 1"
["zipcode"]=>
string(5) "00000"
["city"]=>
string(12) "Musterhausen"
["birthdate"]=>
object(DateTime)#655 (3) {
["date"]=>
string(19) "1893-01-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
["email"]=>
string(17) "[email protected]"
["phone"]=>
NULL
}
array(2) {
["birthdate"]=>
object(DateTime)#659 (3) {
["date"]=>
string(19) "1893-01-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
["phone"]=>
string(9) "123456789"
}
array(2) {
["birthdate"]=>
object(DateTime)#662 (3) {
["date"]=>
string(19) "1893-01-01 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
["phone"]=>
NULL
}
我想只記錄真正改變的數據。我還沒有看到任何選擇嗎?這似乎與事實有關,即birthdate
是DateTime
對象,不是嗎?
編輯 它與DateTime
對象無關。即使在其他實體中也會發生這種情況我已經包含另一個實體的簡單值:
/**
* @ORM\Entity
* @Gedmo\Loggable
* @ORM\Entity(repositoryClass="Acme\MainBundle\Repository\ApplicationRepository")
* @ORM\Table(name="application")
*/
class Application {
[...]
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank(groups={"FormStepOne", "UserEditApplication"})
* @Gedmo\Versioned
*/
protected $insurance_number;
}
當打開瀏覽器中編輯表單的儲蓄不加修飾,日誌表包含:
update 2013-04-26 11:32:42 Acme\MainBundle\Entity\Application a:1:{s:16:"insurance_number";s:7:"1234567";}
update 2013-04-26 11:33:17 Acme\MainBundle\Entity\Application a:1:{s:16:"insurance_number";s:7:"1234567";}
爲什麼?
即使這是一個老問題,我決定不實施我自己的通知功能,並讓這個蹩腳的行爲布萊恩:( – rabudde 2013-09-21 19:24:38
@rabudde不是真的教條的錯 - 但PHP的蹩腳的對象比較 – calumbrodie 2013-09-23 12:42:20
哦,當然,這可能也可能是PHP的錯,但是我不能想象,如果我爲基於PHP的應用程序編寫一個bundle /插件,我自己來比較對象會很困難,但我不會破解Gedmo bundle但是,謝謝你的回答。 – rabudde 2013-09-23 13:22:46