From b08c6284fab39a54f9722ec6d6bfe4c42caa68cc Mon Sep 17 00:00:00 2001 From: Bui Sy Nguyen Date: Wed, 27 Apr 2016 19:28:15 +0700 Subject: [PATCH] Use DateTimeHelper to serialize ISO8601 UTC --- fproject/amqp/ActivityNoticeManager.php | 7 ++++--- fproject/amqp/ActivityNoticeSerializer.php | 3 ++- tests/ActivityNoticeSerializerTest.php | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/fproject/amqp/ActivityNoticeManager.php b/fproject/amqp/ActivityNoticeManager.php index 6d04e4a..0ebd0e2 100644 --- a/fproject/amqp/ActivityNoticeManager.php +++ b/fproject/amqp/ActivityNoticeManager.php @@ -18,6 +18,7 @@ /////////////////////////////////////////////////////////////////////////////// namespace fproject\amqp; +use fproject\common\utils\DateTimeHelper; use fproject\common\utils\JsonHelper; use PhpAmqpLib\Connection\AMQPStreamConnection; use PhpAmqpLib\Message\AMQPMessage; @@ -122,7 +123,7 @@ public function getSerializer() * @param array $modelList1 if $action is "batchSave", this will be the inserted models, if action is "batchDelete" and * there's multiple deletion executed, this will be the deleted models * @param array $modelList2 if $action is "batchSave", this will be the updated models, if action is "batchDelete", this parameter is ignored. - * @return ActivityNotice The activity notice data that sent to AMQP Server + * @return ActivityNotice The activity notice data that sent to AMQP Server. If the notification action is failed, FALSE will be returned. */ public function noticeAfterModelAction($data, $configType, $action, $attributeNames=null, $modelList1=null, $modelList2=null) { @@ -138,13 +139,13 @@ public function noticeAfterModelAction($data, $configType, $action, $attributeNa $config = $serializer->getActivityNoticeConfig($classId, $noticeAction, $attributeNames); if(!isset($config)) - return; + return false; $a=explode('\\', $classId); $shortClassId = array_pop($a); $notice = new ActivityNotice([ 'kind'=>lcfirst($shortClassId).'AUD', - 'dispatchTime'=>date(DATE_ISO8601, time()), + 'dispatchTime'=>DateTimeHelper::currentDateTime(), 'dispatcher'=>$this->getDispatcher(), 'contentUpdatedFields'=>$attributeNames ]); diff --git a/fproject/amqp/ActivityNoticeSerializer.php b/fproject/amqp/ActivityNoticeSerializer.php index af32365..98e6f6e 100644 --- a/fproject/amqp/ActivityNoticeSerializer.php +++ b/fproject/amqp/ActivityNoticeSerializer.php @@ -17,6 +17,7 @@ // /////////////////////////////////////////////////////////////////////////////// namespace fproject\amqp; +use fproject\common\utils\DateTimeHelper; use ReflectionClass; use ReflectionProperty; use Exception; @@ -366,7 +367,7 @@ public function getSerializeData($data, $config) if($sd[$att] instanceof \DateTime) { /** @var \DateTime $date */ $date = $sd[$att]; - $sd[$att] = $date->format(DATE_ISO8601); + $sd[$att] = DateTimeHelper::toISO8601UTC($date); } } } diff --git a/tests/ActivityNoticeSerializerTest.php b/tests/ActivityNoticeSerializerTest.php index 4103667..c808f31 100644 --- a/tests/ActivityNoticeSerializerTest.php +++ b/tests/ActivityNoticeSerializerTest.php @@ -52,7 +52,7 @@ public function testGetSerializeData01() $this->assertArrayNotHasKey('field3',$data); $this->assertArrayHasKey('field2',$data); $this->assertArrayHasKey('field1',$data); - $this->assertEquals($model->field1->format(DATE_ISO8601),$data['field1']); + $this->assertEquals($model->field1->format(\fproject\common\utils\DateTimeHelper::DATE_ISO8601_UTC),$data['field1']); } public function testGetSerializeData02() @@ -184,7 +184,7 @@ public function testGetSerializeData05() $this->assertArrayHasKey('field1',$data); /** @var DateTime $tmpDate */ $tmpDate = $model['field1']; - $this->assertEquals($tmpDate->format(DATE_ISO8601),$data['field1']); + $this->assertEquals($tmpDate->format(\fproject\common\utils\DateTimeHelper::DATE_ISO8601_UTC),$data['field1']); } public function testGetSerializeData06()